style: Make border-spacing serialization consistent, and move it to precomputed_type.

This commit is contained in:
Emilio Cobos Álvarez 2017-09-15 19:29:34 +02:00
parent f9c06d7932
commit 2ac1327e4b
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
21 changed files with 200 additions and 219 deletions

View file

@ -959,8 +959,8 @@ def set_gecko_property(ffi_name, expr):
<%def name="impl_corner_style_coord(ident, gecko_ffi_name, x_index, y_index, need_clone)">
#[allow(non_snake_case)]
pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
v.0.width.to_gecko_style_coord(&mut self.gecko.${gecko_ffi_name}.data_at_mut(${x_index}));
v.0.height.to_gecko_style_coord(&mut self.gecko.${gecko_ffi_name}.data_at_mut(${y_index}));
v.0.width().to_gecko_style_coord(&mut self.gecko.${gecko_ffi_name}.data_at_mut(${x_index}));
v.0.height().to_gecko_style_coord(&mut self.gecko.${gecko_ffi_name}.data_at_mut(${y_index}));
}
#[allow(non_snake_case)]
pub fn copy_${ident}_from(&mut self, other: &Self) {
@ -4605,8 +4605,8 @@ fn static_assert() {
skip_longhands="border-spacing">
pub fn set_border_spacing(&mut self, v: longhands::border_spacing::computed_value::T) {
self.gecko.mBorderSpacingCol = v.horizontal.0.to_i32_au();
self.gecko.mBorderSpacingRow = v.vertical.0.to_i32_au();
self.gecko.mBorderSpacingCol = v.horizontal().0;
self.gecko.mBorderSpacingRow = v.vertical().0;
}
pub fn copy_border_spacing_from(&mut self, other: &Self) {
@ -4619,10 +4619,10 @@ fn static_assert() {
}
pub fn clone_border_spacing(&self) -> longhands::border_spacing::computed_value::T {
longhands::border_spacing::computed_value::T {
horizontal: Au(self.gecko.mBorderSpacingCol).into(),
vertical: Au(self.gecko.mBorderSpacingRow).into()
}
longhands::border_spacing::computed_value::T::new(
Au(self.gecko.mBorderSpacingCol).into(),
Au(self.gecko.mBorderSpacingRow).into()
)
}
</%self:impl_trait>

View file

@ -489,12 +489,6 @@
}
}
impl From<computed_value::T> for SpecifiedValue {
fn from(other: computed_value::T) -> Self {
SpecifiedValue::Keyword(other)
}
}
#[inline]
pub fn get_initial_value() -> computed_value::T {
computed_value::T::${to_rust_ident(values.split()[0])}

View file

@ -59,7 +59,7 @@ ${helpers.gecko_keyword_conversion(Keyword('border-style',
// FIXME(#4126): when gfx supports painting it, make this Size2D<LengthOrPercentage>
% for corner in ["top-left", "top-right", "bottom-right", "bottom-left"]:
${helpers.predefined_type("border-" + corner + "-radius", "BorderCornerRadius",
"computed::LengthOrPercentage::zero().into()",
"computed::BorderCornerRadius::zero()",
"parse", extra_prefixes="webkit",
spec="https://drafts.csswg.org/css-backgrounds/#border-%s-radius" % corner,
boxed=True,

View file

@ -420,14 +420,14 @@ ${helpers.single_keyword_system("font-style",
"titling-caps": "TITLING" } %>
${helpers.single_keyword_system("font-variant-caps",
"normal small-caps",
extra_gecko_values="all-small-caps petite-caps all-petite-caps unicase titling-caps",
gecko_constant_prefix="NS_FONT_VARIANT_CAPS",
gecko_ffi_name="mFont.variantCaps",
spec="https://drafts.csswg.org/css-fonts/#propdef-font-variant-caps",
custom_consts=font_variant_caps_custom_consts,
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
animation_value_type="discrete")}
"normal small-caps",
extra_gecko_values="all-small-caps petite-caps all-petite-caps unicase titling-caps",
gecko_constant_prefix="NS_FONT_VARIANT_CAPS",
gecko_ffi_name="mFont.variantCaps",
spec="https://drafts.csswg.org/css-fonts/#propdef-font-variant-caps",
custom_consts=font_variant_caps_custom_consts,
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
animation_value_type="discrete")}
<%helpers:longhand name="font-weight" need_clone="True" animation_value_type="ComputedValue"
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER"

View file

@ -20,112 +20,9 @@ ${helpers.single_keyword("caption-side", "top bottom",
animation_value_type="discrete",
spec="https://drafts.csswg.org/css-tables/#propdef-caption-side")}
<%helpers:longhand name="border-spacing" animation_value_type="BorderSpacing" boxed="True"
spec="https://drafts.csswg.org/css-tables/#propdef-border-spacing">
use values::specified::{AllowQuirks, Length};
use values::specified::length::NonNegativeLength;
pub mod computed_value {
use values::animated::{ToAnimatedValue, ToAnimatedZero};
use values::computed::NonNegativeLength;
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, PartialEq, ToCss)]
pub struct T {
pub horizontal: NonNegativeLength,
pub vertical: NonNegativeLength,
}
impl ToAnimatedZero for T {
#[inline]
fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) }
}
impl ToAnimatedValue for T {
type AnimatedValue = Self;
#[inline]
fn to_animated_value(self) -> Self {
self
}
#[inline]
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
T {
horizontal: ToAnimatedValue::from_animated_value(animated.horizontal),
vertical: ToAnimatedValue::from_animated_value(animated.vertical)
}
}
}
}
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Debug, PartialEq, ToCss)]
pub struct SpecifiedValue {
pub horizontal: NonNegativeLength,
pub vertical: Option<NonNegativeLength>,
}
#[inline]
pub fn get_initial_value() -> computed_value::T {
use values::computed::NonNegativeLength as ComputedNonNegativeLength;
computed_value::T {
horizontal: ComputedNonNegativeLength::zero(),
vertical: ComputedNonNegativeLength::zero(),
}
}
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;
#[inline]
fn to_computed_value(&self, context: &Context) -> computed_value::T {
let horizontal = self.horizontal.to_computed_value(context);
computed_value::T {
horizontal: horizontal,
vertical: self.vertical.as_ref().map_or(horizontal, |v| v.to_computed_value(context)),
}
}
#[inline]
fn from_computed_value(computed: &computed_value::T) -> Self {
SpecifiedValue {
horizontal: ToComputedValue::from_computed_value(&computed.horizontal),
vertical: Some(ToComputedValue::from_computed_value(&computed.vertical)),
}
}
}
pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<SpecifiedValue,ParseError<'i>> {
let mut first = None;
let mut second = None;
match Length::parse_non_negative_quirky(context, input, AllowQuirks::Yes) {
Err(_) => (),
Ok(length) => {
first = Some(length);
if let Ok(len) = input.try(|i| Length::parse_non_negative_quirky(context, i, AllowQuirks::Yes)) {
second = Some(len);
}
}
}
match (first, second) {
(None, None) => Err(StyleParseError::UnspecifiedError.into()),
(Some(length), None) => {
Ok(SpecifiedValue {
horizontal: length.into(),
vertical: None,
})
}
(Some(horizontal), Some(vertical)) => {
Ok(SpecifiedValue {
horizontal: horizontal.into(),
vertical: Some(vertical.into()),
})
}
(None, Some(_)) => unreachable!(),
}
}
</%helpers:longhand>
${helpers.predefined_type("border-spacing",
"BorderSpacing",
"computed::BorderSpacing::zero()",
animation_value_type="BorderSpacing",
boxed="True",
spec="https://drafts.csswg.org/css-tables/#propdef-border-spacing")}

View file

@ -78,7 +78,7 @@ ${helpers.predefined_type("outline-width",
// The -moz-outline-radius-* properties are non-standard and not on a standards track.
% for corner in ["topleft", "topright", "bottomright", "bottomleft"]:
${helpers.predefined_type("-moz-outline-radius-" + corner, "BorderCornerRadius",
"computed::LengthOrPercentage::zero().into()",
"computed::BorderCornerRadius::zero()",
products="gecko",
boxed=True,
animation_value_type="BorderCornerRadius",

View file

@ -209,6 +209,7 @@ pub fn parse_border<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
for corner in ['top-left', 'top-right', 'bottom-right', 'bottom-left']
)}" extra_prefixes="webkit" spec="https://drafts.csswg.org/css-backgrounds/#border-radius">
use values::generics::rect::Rect;
use values::generics::border::BorderCornerRadius;
use values::specified::border::BorderRadius;
use parser::Parse;
@ -226,14 +227,15 @@ pub fn parse_border<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
let LonghandsToSerialize {
border_top_left_radius: ref tl,
border_top_right_radius: ref tr,
border_bottom_right_radius: ref br,
border_bottom_left_radius: ref bl,
border_top_left_radius: &BorderCornerRadius(ref tl),
border_top_right_radius: &BorderCornerRadius(ref tr),
border_bottom_right_radius: &BorderCornerRadius(ref br),
border_bottom_left_radius: &BorderCornerRadius(ref bl),
} = *self;
let widths = Rect::new(&tl.0.width, &tr.0.width, &br.0.width, &bl.0.width);
let heights = Rect::new(&tl.0.height, &tr.0.height, &br.0.height, &bl.0.height);
let widths = Rect::new(tl.width(), tr.width(), br.width(), bl.width());
let heights = Rect::new(tl.height(), tr.height(), br.height(), bl.height());
BorderRadius::serialize_rects(widths, heights, dest)
}

View file

@ -77,15 +77,17 @@
impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
use values::generics::border::BorderCornerRadius;
let LonghandsToSerialize {
_moz_outline_radius_topleft: ref tl,
_moz_outline_radius_topright: ref tr,
_moz_outline_radius_bottomright: ref br,
_moz_outline_radius_bottomleft: ref bl,
_moz_outline_radius_topleft: &BorderCornerRadius(ref tl),
_moz_outline_radius_topright: &BorderCornerRadius(ref tr),
_moz_outline_radius_bottomright: &BorderCornerRadius(ref br),
_moz_outline_radius_bottomleft: &BorderCornerRadius(ref bl),
} = *self;
let widths = Rect::new(&tl.0.width, &tr.0.width, &br.0.width, &bl.0.width);
let heights = Rect::new(&tl.0.height, &tr.0.height, &br.0.height, &bl.0.height);
let widths = Rect::new(tl.width(), tr.width(), br.width(), bl.width());
let heights = Rect::new(tl.height(), tr.height(), br.height(), bl.height());
BorderRadius::serialize_rects(widths, heights, dest)
}