mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Use enum BorderWidth as SpecifiedValue
Use enum BorderWidth instead of a tuple-like struct to store the specified value. BorderWidth is needed to be used in both longhand and shorthand border width properties, so I put it in `specified` module. Fixed #13869.
This commit is contained in:
parent
2b236c20cd
commit
0fc38f79d6
6 changed files with 122 additions and 79 deletions
|
@ -27,27 +27,14 @@
|
|||
use cssparser::ToCss;
|
||||
use std::fmt;
|
||||
use values::HasViewportPercentage;
|
||||
use values::specified::BorderWidth;
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
self.0.to_css(dest)
|
||||
}
|
||||
}
|
||||
pub type SpecifiedValue = BorderWidth;
|
||||
|
||||
#[inline]
|
||||
pub fn parse(_context: &ParserContext, input: &mut Parser)
|
||||
-> Result<SpecifiedValue, ()> {
|
||||
specified::parse_border_width(input).map(SpecifiedValue)
|
||||
}
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct SpecifiedValue(pub specified::Length);
|
||||
|
||||
impl HasViewportPercentage for SpecifiedValue {
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
let &SpecifiedValue(length) = self;
|
||||
length.has_viewport_percentage()
|
||||
}
|
||||
-> Result<SpecifiedValue, ()> {
|
||||
BorderWidth::parse(input)
|
||||
}
|
||||
|
||||
pub mod computed_value {
|
||||
|
@ -57,20 +44,6 @@
|
|||
#[inline] pub fn get_initial_value() -> computed_value::T {
|
||||
Au::from_px(3) // medium
|
||||
}
|
||||
|
||||
impl ToComputedValue for SpecifiedValue {
|
||||
type ComputedValue = computed_value::T;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> computed_value::T {
|
||||
self.0.to_computed_value(context)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &computed_value::T) -> Self {
|
||||
SpecifiedValue(ToComputedValue::from_computed_value(computed))
|
||||
}
|
||||
}
|
||||
</%helpers:longhand>
|
||||
% endfor
|
||||
|
||||
|
|
|
@ -16,22 +16,19 @@ ${helpers.four_sides_shorthand("border-style", "border-%s-style",
|
|||
|
||||
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
|
||||
let _unused = context;
|
||||
let (top, right, bottom, left) = try!(parse_four_sides(input, specified::parse_border_width));
|
||||
let (top, right, bottom, left) = try!(parse_four_sides(input, specified::BorderWidth::parse));
|
||||
Ok(Longhands {
|
||||
% for side in ["top", "right", "bottom", "left"]:
|
||||
${to_rust_ident('border-%s-width' % side)}:
|
||||
Some(longhands::${to_rust_ident('border-%s-width' % side)}::SpecifiedValue(${side})),
|
||||
${to_rust_ident('border-%s-width' % side)}: Some(${side}),
|
||||
% endfor
|
||||
})
|
||||
}
|
||||
|
||||
impl<'a> LonghandsToSerialize<'a> {
|
||||
fn to_css_declared<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
// extract tuple container values so that the different border widths
|
||||
// can be compared via partial eq
|
||||
% for side in ["top", "right", "bottom", "left"]:
|
||||
let ${side} = match self.border_${side}_width {
|
||||
&DeclaredValue::Value(ref value) => DeclaredValue::Value(value.0),
|
||||
&DeclaredValue::Value(ref value) => DeclaredValue::Value(*value),
|
||||
&DeclaredValue::WithVariables {
|
||||
css: ref a, first_token_type: ref b, base_url: ref c, from_shorthand: ref d
|
||||
} => DeclaredValue::WithVariables {
|
||||
|
@ -52,7 +49,7 @@ ${helpers.four_sides_shorthand("border-style", "border-%s-style",
|
|||
pub fn parse_border(context: &ParserContext, input: &mut Parser)
|
||||
-> Result<(Option<specified::CSSColor>,
|
||||
Option<specified::BorderStyle>,
|
||||
Option<specified::Length>), ()> {
|
||||
Option<specified::BorderWidth>), ()> {
|
||||
use values::specified;
|
||||
let _unused = context;
|
||||
let mut color = None;
|
||||
|
@ -75,7 +72,7 @@ pub fn parse_border(context: &ParserContext, input: &mut Parser)
|
|||
}
|
||||
}
|
||||
if width.is_none() {
|
||||
if let Ok(value) = input.try(specified::parse_border_width) {
|
||||
if let Ok(value) = input.try(specified::BorderWidth::parse) {
|
||||
width = Some(value);
|
||||
any = true;
|
||||
continue
|
||||
|
@ -97,8 +94,7 @@ pub fn parse_border(context: &ParserContext, input: &mut Parser)
|
|||
Ok(Longhands {
|
||||
border_${side}_color: color,
|
||||
border_${side}_style: style,
|
||||
border_${side}_width:
|
||||
width.map(longhands::${to_rust_ident('border-%s-width' % side)}::SpecifiedValue),
|
||||
border_${side}_width: width
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -128,8 +124,7 @@ pub fn parse_border(context: &ParserContext, input: &mut Parser)
|
|||
% for side in ["top", "right", "bottom", "left"]:
|
||||
border_${side}_color: color.clone(),
|
||||
border_${side}_style: style,
|
||||
border_${side}_width:
|
||||
width.map(longhands::${to_rust_ident('border-%s-width' % side)}::SpecifiedValue),
|
||||
border_${side}_width: width,
|
||||
% endfor
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue