diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index bff29251830d..1a520af83449 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -8,14 +8,18 @@ %> <%def name="predefined_type(name, type, initial_value, parse_method='parse', - needs_context=True, vector=False, initial_specified_value=None, **kwargs)"> + needs_context=True, vector=False, computed_type=None, initial_specified_value=None, **kwargs)"> <%def name="predefined_type_inner(name, type, initial_value, parse_method)"> #[allow(unused_imports)] use app_units::Au; use cssparser::{Color as CSSParserColor, RGBA}; pub use values::specified::${type} as SpecifiedValue; pub mod computed_value { + % if computed_type: + pub use ${computed_type} as T; + % else: pub use values::computed::${type} as T; + % endif } #[inline] pub fn get_initial_value() -> computed_value::T { ${initial_value} } % if initial_specified_value: @@ -36,10 +40,16 @@ % if vector: <%call expr="vector_longhand(name, predefined_type=type, **kwargs)"> ${predefined_type_inner(name, type, initial_value, parse_method)} + % if caller: + ${caller.body()} + % endif % else: <%call expr="longhand(name, predefined_type=type, **kwargs)"> ${predefined_type_inner(name, type, initial_value, parse_method)} + % if caller: + ${caller.body()} + % endif % endif diff --git a/components/style/properties/longhand/background.mako.rs b/components/style/properties/longhand/background.mako.rs index 0f4a5e663042..726003f95716 100644 --- a/components/style/properties/longhand/background.mako.rs +++ b/components/style/properties/longhand/background.mako.rs @@ -89,42 +89,13 @@ ${helpers.predefined_type("background-color", "CSSColor", } -<%helpers:vector_longhand name="background-position-x" animation_value_type="ComputedValue" +<%helpers:predefined_type name="background-position-x" type="position::HorizontalPosition" + initial_value="computed::position::HorizontalPosition::zero()" + initial_specified_value="specified::position::HorizontalPosition::left()" spec="https://drafts.csswg.org/css-backgrounds-4/#propdef-background-position-x" - delegate_animate="True"> - use std::fmt; - use style_traits::ToCss; - use values::HasViewportPercentage; - use values::specified::position::HorizontalPosition; - - #[allow(missing_docs)] - pub mod computed_value { - use values::computed::position::HorizontalPosition; - use properties::animated_properties::{Interpolate, RepeatableListInterpolate}; - - pub type T = HorizontalPosition; - } - - #[allow(missing_docs)] - pub type SpecifiedValue = HorizontalPosition; - + animation_value_type="ComputedValue" vector="True" delegate_animate="True"> #[inline] - #[allow(missing_docs)] - pub fn get_initial_value() -> computed_value::T { - use values::generics::position::HorizontalPosition; - HorizontalPosition(computed::LengthOrPercentage::Percentage(0.0)) - } - #[inline] - #[allow(missing_docs)] - pub fn get_initial_specified_value() -> SpecifiedValue { - use values::generics::position::{HorizontalPosition, Keyword, PositionValue}; - HorizontalPosition(PositionValue { - keyword: Some(Keyword::Left), - position: None, - }) - } - #[inline] - #[allow(missing_docs)] + /// Get the initial value for horizontal position. pub fn get_initial_position_value() -> SpecifiedValue { use values::generics::position::{HorizontalPosition, PositionValue}; use values::specified::{LengthOrPercentage, Percentage}; @@ -133,66 +104,23 @@ ${helpers.predefined_type("background-color", "CSSColor", position: Some(LengthOrPercentage::Percentage(Percentage(0.0))), }) } + - #[allow(missing_docs)] - pub fn parse(context: &ParserContext, input: &mut Parser) - -> Result { - HorizontalPosition::parse(context, input) - } - - -<%helpers:vector_longhand name="background-position-y" animation_value_type="ComputedValue" +<%helpers:predefined_type name="background-position-y" type="position::VerticalPosition" + initial_value="computed::position::VerticalPosition::zero()" + initial_specified_value="specified::position::VerticalPosition::top()" spec="https://drafts.csswg.org/css-backgrounds-4/#propdef-background-position-y" - delegate_animate="True"> - use std::fmt; - use style_traits::ToCss; - use values::HasViewportPercentage; - use values::specified::position::VerticalPosition; - - #[allow(missing_docs)] - pub mod computed_value { - use values::computed::position::VerticalPosition; - use properties::animated_properties::{Interpolate, RepeatableListInterpolate}; - - pub type T = VerticalPosition; - } - - #[allow(missing_docs)] - pub type SpecifiedValue = VerticalPosition; - - #[inline] - #[allow(missing_docs)] - pub fn get_initial_value() -> computed_value::T { - use values::generics::position::VerticalPosition; - VerticalPosition(computed::LengthOrPercentage::Percentage(0.0)) - } - #[inline] - #[allow(missing_docs)] - pub fn get_initial_specified_value() -> SpecifiedValue { - use values::generics::position::{Keyword, PositionValue, VerticalPosition}; - VerticalPosition(PositionValue { - keyword: Some(Keyword::Top), - position: None, - }) - } - #[inline] - #[allow(missing_docs)] + animation_value_type="ComputedValue" vector="True" delegate_animate="True"> + /// Get the initial value for vertical position. pub fn get_initial_position_value() -> SpecifiedValue { - use values::generics::position::{PositionValue, VerticalPosition}; + use values::generics::position::{VerticalPosition, PositionValue}; use values::specified::{LengthOrPercentage, Percentage}; VerticalPosition(PositionValue { keyword: None, position: Some(LengthOrPercentage::Percentage(Percentage(0.0))), }) } - - #[inline] - #[allow(missing_docs)] - pub fn parse(context: &ParserContext, input: &mut Parser) - -> Result { - VerticalPosition::parse(context, input) - } - + <%helpers:vector_longhand name="background-repeat" animation_value_type="none" spec="https://drafts.csswg.org/css-backgrounds/#the-background-repeat"> diff --git a/components/style/properties/longhand/border.mako.rs b/components/style/properties/longhand/border.mako.rs index 64c64c700fb8..df5cb06f1cc0 100644 --- a/components/style/properties/longhand/border.mako.rs +++ b/components/style/properties/longhand/border.mako.rs @@ -21,47 +21,24 @@ alias=maybe_moz_logical_alias(product, side, "-moz-border-%s-color"), spec=maybe_logical_spec(side, "color"), animation_value_type="IntermediateColor", logical = side[1])} -% endfor -% for side in ALL_SIDES: ${helpers.predefined_type("border-%s-style" % side[0], "BorderStyle", "specified::BorderStyle::none", need_clone=True, alias=maybe_moz_logical_alias(product, side, "-moz-border-%s-style"), spec=maybe_logical_spec(side, "style"), - animation_value_type="none", logical = side[1])} + animation_value_type="none", logical=side[1])} + + ${helpers.predefined_type("border-%s-width" % side[0], "BorderWidth", "Au::from_px(3)", + computed_type="::app_units::Au", + alias=maybe_moz_logical_alias(product, side, "-moz-border-%s-width"), + spec=maybe_logical_spec(side, "width"), + animation_value_type="ComputedValue", logical=side[1])} % endfor ${helpers.gecko_keyword_conversion(Keyword('border-style', "none solid double dotted dashed hidden groove ridge inset outset"), type="::values::specified::BorderStyle")} -% for side in ALL_SIDES: - <%helpers:longhand name="border-${side[0]}-width" animation_value_type="ComputedValue" logical="${side[1]}" - alias="${maybe_moz_logical_alias(product, side, '-moz-border-%s-width')}" - spec="${maybe_logical_spec(side, 'width')}"> - use app_units::Au; - use std::fmt; - use style_traits::ToCss; - use values::HasViewportPercentage; - use values::specified::BorderWidth; - - pub type SpecifiedValue = BorderWidth; - - #[inline] - pub fn parse(context: &ParserContext, input: &mut Parser) - -> Result { - BorderWidth::parse(context, input) - } - - pub mod computed_value { - use app_units::Au; - pub type T = Au; - } - #[inline] pub fn get_initial_value() -> computed_value::T { - Au::from_px(3) // medium - } - -% endfor // FIXME(#4126): when gfx supports painting it, make this Size2D % for corner in ["top-left", "top-right", "bottom-right", "bottom-left"]: diff --git a/components/style/properties/longhand/column.mako.rs b/components/style/properties/longhand/column.mako.rs index 64d8c86b7f42..91b42fa53506 100644 --- a/components/style/properties/longhand/column.mako.rs +++ b/components/style/properties/longhand/column.mako.rs @@ -40,36 +40,11 @@ ${helpers.single_keyword("column-fill", "balance auto", extra_prefixes="moz", products="gecko", animation_value_type="none", spec="https://drafts.csswg.org/css-multicol/#propdef-column-fill")} -// https://drafts.csswg.org/css-multicol-1/#propdef-column-rule-width -<%helpers:longhand name="column-rule-width" products="gecko" animation_value_type="ComputedValue" extra_prefixes="moz" - spec="https://drafts.csswg.org/css-multicol/#propdef-column-rule-width"> - use app_units::Au; - use std::fmt; - use style_traits::ToCss; - use values::HasViewportPercentage; - use values::specified::BorderWidth; - - pub mod computed_value { - use app_units::Au; - pub type T = Au; - } - - pub type SpecifiedValue = BorderWidth; - - #[inline] - pub fn get_initial_value() -> computed_value::T { - Au::from_px(3) // medium - } - - #[inline] - pub fn get_initial_specified_value() -> SpecifiedValue { - BorderWidth::Medium - } - - pub fn parse(context: &ParserContext, input: &mut Parser) -> Result { - BorderWidth::parse(context, input) - } - +${helpers.predefined_type("column-rule-width", "BorderWidth", "Au::from_px(3)", + initial_specified_value="specified::BorderWidth::Medium", + products="gecko", computed_type="::app_units::Au", + spec="https://drafts.csswg.org/css-multicol/#propdef-column-rule-width", + animation_value_type="ComputedValue", extra_prefixes="moz")} // https://drafts.csswg.org/css-multicol-1/#crc ${helpers.predefined_type("column-rule-color", "CSSColor", diff --git a/components/style/properties/longhand/inherited_text.mako.rs b/components/style/properties/longhand/inherited_text.mako.rs index f47178e9c76e..e40791293286 100644 --- a/components/style/properties/longhand/inherited_text.mako.rs +++ b/components/style/properties/longhand/inherited_text.mako.rs @@ -1236,33 +1236,11 @@ ${helpers.predefined_type( complex_color=True, need_clone=True, spec="https://compat.spec.whatwg.org/#the-webkit-text-stroke-color")} -<%helpers:longhand products="gecko" name="-webkit-text-stroke-width" animation_value_type="none" - spec="https://compat.spec.whatwg.org/#the-webkit-text-stroke-width"> - use app_units::Au; - use std::fmt; - use style_traits::ToCss; - use values::HasViewportPercentage; - use values::specified::{BorderWidth, Length}; - - pub type SpecifiedValue = BorderWidth; - - #[inline] - pub fn parse(context: &ParserContext, input: &mut Parser) -> Result { - BorderWidth::parse(context, input) - } - - pub mod computed_value { - use app_units::Au; - pub type T = Au; - } - #[inline] pub fn get_initial_value() -> computed_value::T { - Au::from_px(0) - } - #[inline] - pub fn get_initial_specified_value() -> SpecifiedValue { - BorderWidth::from_length(Length::zero()) - } - +${helpers.predefined_type("-webkit-text-stroke-width", "BorderWidth", "Au::from_px(0)", + initial_specified_value="specified::BorderWidth::from_length(specified::Length::zero())", + computed_type="::app_units::Au", products="gecko", + spec="https://compat.spec.whatwg.org/#the-webkit-text-stroke-width", + animation_value_type="none")} // CSS Ruby Layout Module Level 1 diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index 4de5184d1b91..85a8ba193689 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -4,7 +4,6 @@ //! Computed values. -use app_units::Au; use euclid::size::Size2D; use font_metrics::FontMetricsProvider; use media_queries::Device; @@ -16,6 +15,7 @@ use super::generics::BorderRadiusSize as GenericBorderRadiusSize; use super::specified; use super::specified::grid::{TrackBreadth as GenericTrackBreadth, TrackSize as GenericTrackSize}; +pub use app_units::Au; pub use cssparser::Color as CSSColor; pub use self::image::{AngleOrCorner, EndingShape as GradientShape, Gradient, GradientKind, Image, ImageRect}; pub use self::image::{LengthOrKeyword, LengthOrPercentageOrKeyword}; diff --git a/components/style/values/computed/position.rs b/components/style/values/computed/position.rs index eed9c0971986..d30e911f9fa8 100644 --- a/components/style/values/computed/position.rs +++ b/components/style/values/computed/position.rs @@ -59,7 +59,23 @@ pub type HorizontalPosition = GenericHorizontalPosition; impl Copy for HorizontalPosition {} +impl HorizontalPosition { + #[inline] + /// Create a zero position value. + pub fn zero() -> HorizontalPosition { + GenericHorizontalPosition(LengthOrPercentage::Percentage(0.0)) + } +} + /// The computed value of a vertical `` pub type VerticalPosition = GenericVerticalPosition; impl Copy for VerticalPosition {} + +impl VerticalPosition { + #[inline] + /// Create a zero position value. + pub fn zero() -> VerticalPosition { + GenericVerticalPosition(LengthOrPercentage::Percentage(0.0)) + } +} diff --git a/components/style/values/specified/position.rs b/components/style/values/specified/position.rs index 2289df4871b4..f8501e870c22 100644 --- a/components/style/values/specified/position.rs +++ b/components/style/values/specified/position.rs @@ -219,6 +219,18 @@ impl ToComputedValue for HorizontalPosition { } } +impl HorizontalPosition { + #[inline] + /// Initial specified value for vertical position (`top` keyword). + pub fn left() -> HorizontalPosition { + GenericHorizontalPosition(PositionValue { + keyword: Some(Keyword::Left), + position: None, + }) + } +} + + /// The specified value of vertical `` pub type VerticalPosition = GenericVerticalPosition>; @@ -238,3 +250,14 @@ impl ToComputedValue for VerticalPosition { }) } } + +impl VerticalPosition { + #[inline] + /// Initial specified value for vertical position (`top` keyword). + pub fn top() -> VerticalPosition { + GenericVerticalPosition(PositionValue { + keyword: Some(Keyword::Top), + position: None, + }) + } +}