mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Remove uses of parse_four_sides and serialize_four_sides
This commit is contained in:
parent
ca8fae91da
commit
6f3c46ca61
6 changed files with 41 additions and 141 deletions
|
@ -887,35 +887,34 @@
|
|||
<%call expr="self.shorthand(name, sub_properties=sub_properties, **kwargs)">
|
||||
#[allow(unused_imports)]
|
||||
use parser::Parse;
|
||||
use super::parse_four_sides;
|
||||
use values::generics::rect::Rect;
|
||||
use values::specified;
|
||||
|
||||
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
|
||||
let (top, right, bottom, left) =
|
||||
let rect = Rect::parse_with(context, input, |_c, i| {
|
||||
% if allow_quirks:
|
||||
try!(parse_four_sides(input, |i| ${parser_function}_quirky(context, i, specified::AllowQuirks::Yes)));
|
||||
${parser_function}_quirky(_c, i, specified::AllowQuirks::Yes)
|
||||
% elif needs_context:
|
||||
try!(parse_four_sides(input, |i| ${parser_function}(context, i)));
|
||||
${parser_function}(_c, i)
|
||||
% else:
|
||||
try!(parse_four_sides(input, ${parser_function}));
|
||||
let _unused = context;
|
||||
${parser_function}(i)
|
||||
% endif
|
||||
})?;
|
||||
Ok(expanded! {
|
||||
% for side in ["top", "right", "bottom", "left"]:
|
||||
${to_rust_ident(sub_property_pattern % side)}: ${side},
|
||||
${to_rust_ident(sub_property_pattern % side)}: rect.${side},
|
||||
% endfor
|
||||
})
|
||||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
super::serialize_four_sides(
|
||||
dest,
|
||||
self.${to_rust_ident(sub_property_pattern % 'top')},
|
||||
self.${to_rust_ident(sub_property_pattern % 'right')},
|
||||
self.${to_rust_ident(sub_property_pattern % 'bottom')},
|
||||
self.${to_rust_ident(sub_property_pattern % 'left')}
|
||||
)
|
||||
let rect = Rect::new(
|
||||
% for side in ["top", "right", "bottom", "left"]:
|
||||
&self.${to_rust_ident(sub_property_pattern % side)},
|
||||
% endfor
|
||||
);
|
||||
rect.to_css(dest)
|
||||
}
|
||||
}
|
||||
</%call>
|
||||
|
|
|
@ -134,55 +134,6 @@ pub mod shorthands {
|
|||
use parser::{Parse, ParserContext};
|
||||
use values::specified;
|
||||
|
||||
/// Parses a property for four different sides per CSS syntax.
|
||||
///
|
||||
/// * Zero or more than four values is invalid.
|
||||
/// * One value sets them all
|
||||
/// * Two values set (top, bottom) and (left, right)
|
||||
/// * Three values set top, (left, right) and bottom
|
||||
/// * Four values set them in order
|
||||
///
|
||||
/// returns the values in (top, right, bottom, left) order.
|
||||
pub fn parse_four_sides<F, T>(input: &mut Parser, parse_one: F) -> Result<(T, T, T, T), ()>
|
||||
where F: Fn(&mut Parser) -> Result<T, ()>,
|
||||
T: Clone,
|
||||
{
|
||||
let top = try!(parse_one(input));
|
||||
let right;
|
||||
let bottom;
|
||||
let left;
|
||||
match input.try(|i| parse_one(i)) {
|
||||
Err(()) => {
|
||||
right = top.clone();
|
||||
bottom = top.clone();
|
||||
left = top.clone();
|
||||
}
|
||||
Ok(value) => {
|
||||
right = value;
|
||||
match input.try(|i| parse_one(i)) {
|
||||
Err(()) => {
|
||||
bottom = top.clone();
|
||||
left = right.clone();
|
||||
}
|
||||
Ok(value) => {
|
||||
bottom = value;
|
||||
match input.try(|i| parse_one(i)) {
|
||||
Err(()) => {
|
||||
left = right.clone();
|
||||
}
|
||||
Ok(value) => {
|
||||
left = value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Ok((top, right, bottom, left))
|
||||
}
|
||||
|
||||
<%include file="/shorthand/serialize.mako.rs" />
|
||||
<%include file="/shorthand/background.mako.rs" />
|
||||
<%include file="/shorthand/border.mako.rs" />
|
||||
|
|
|
@ -17,27 +17,28 @@ ${helpers.four_sides_shorthand("border-style", "border-%s-style",
|
|||
' '.join('border-%s-width' % side
|
||||
for side in PHYSICAL_SIDES)}"
|
||||
spec="https://drafts.csswg.org/css-backgrounds/#border-width">
|
||||
use super::parse_four_sides;
|
||||
use values::generics::rect::Rect;
|
||||
use values::specified::{AllowQuirks, BorderWidth};
|
||||
|
||||
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
|
||||
let (top, right, bottom, left) = try!(parse_four_sides(input, |i| {
|
||||
let rect = Rect::parse_with(context, input, |_, i| {
|
||||
BorderWidth::parse_quirky(context, i, AllowQuirks::Yes)
|
||||
}));
|
||||
})?;
|
||||
Ok(expanded! {
|
||||
% for side in PHYSICAL_SIDES:
|
||||
${to_rust_ident('border-%s-width' % side)}: ${side},
|
||||
${to_rust_ident('border-%s-width' % side)}: rect.${side},
|
||||
% endfor
|
||||
})
|
||||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
% for side in PHYSICAL_SIDES:
|
||||
let ${side} = self.border_${side}_width.clone();
|
||||
% endfor
|
||||
|
||||
super::serialize_four_sides(dest, &top, &right, &bottom, &left)
|
||||
let rect = Rect::new(
|
||||
% for side in PHYSICAL_SIDES:
|
||||
&self.border_${side}_width,
|
||||
% endfor
|
||||
);
|
||||
rect.to_css(dest)
|
||||
}
|
||||
}
|
||||
</%helpers:shorthand>
|
||||
|
|
|
@ -6,57 +6,6 @@ use style_traits::ToCss;
|
|||
use values::specified::{BorderStyle, Color, CSSColor};
|
||||
use std::fmt;
|
||||
|
||||
#[allow(missing_docs)]
|
||||
pub fn serialize_four_sides<W, I>(dest: &mut W,
|
||||
top: &I,
|
||||
right: &I,
|
||||
bottom: &I,
|
||||
left: &I)
|
||||
-> fmt::Result
|
||||
where W: fmt::Write,
|
||||
I: ToCss + PartialEq,
|
||||
{
|
||||
|
||||
if left == right {
|
||||
let horizontal_value = left;
|
||||
|
||||
if top == bottom {
|
||||
let vertical_value = top;
|
||||
|
||||
if horizontal_value == vertical_value {
|
||||
let single_value = horizontal_value;
|
||||
try!(single_value.to_css(dest));
|
||||
} else {
|
||||
try!(vertical_value.to_css(dest));
|
||||
try!(write!(dest, " "));
|
||||
|
||||
try!(horizontal_value.to_css(dest));
|
||||
}
|
||||
} else {
|
||||
try!(top.to_css(dest));
|
||||
try!(write!(dest, " "));
|
||||
|
||||
try!(horizontal_value.to_css(dest));
|
||||
try!(write!(dest, " "));
|
||||
|
||||
try!(bottom.to_css(dest));
|
||||
}
|
||||
} else {
|
||||
try!(top.to_css(dest));
|
||||
try!(write!(dest, " "));
|
||||
|
||||
try!(right.to_css(dest));
|
||||
try!(write!(dest, " "));
|
||||
|
||||
try!(bottom.to_css(dest));
|
||||
try!(write!(dest, " "));
|
||||
|
||||
try!(left.to_css(dest));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn serialize_directional_border<W, I,>(dest: &mut W,
|
||||
width: &I,
|
||||
style: &BorderStyle,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue