diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index 41f3eff772f..aa5381d3fb7 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -5,7 +5,7 @@ <%! from data import Keyword, to_rust_ident, to_camel_case, LOGICAL_SIDES, PHYSICAL_SIDES, LOGICAL_SIZES %> <%def name="predefined_type(name, type, initial_value, parse_method='parse', - needs_context=True, vector=False, **kwargs)"> + needs_context=True, vector=False, initial_specified_value=None, **kwargs)"> <%def name="predefined_type_inner(name, type, initial_value, parse_method)"> #[allow(unused_imports)] use app_units::Au; @@ -15,6 +15,9 @@ pub use values::computed::${type} as T; } #[inline] pub fn get_initial_value() -> computed_value::T { ${initial_value} } + % if initial_specified_value: + #[inline] pub fn get_initial_specified_value() -> SpecifiedValue { ${initial_specified_value} } + % endif #[allow(unused_variables)] #[inline] pub fn parse(context: &ParserContext, input: &mut Parser) -> Result { diff --git a/components/style/properties/longhand/background.mako.rs b/components/style/properties/longhand/background.mako.rs index 6aa537b269a..429731b8158 100644 --- a/components/style/properties/longhand/background.mako.rs +++ b/components/style/properties/longhand/background.mako.rs @@ -8,6 +8,7 @@ ${helpers.predefined_type("background-color", "CSSColor", "::cssparser::Color::RGBA(::cssparser::RGBA::transparent())", + initial_specified_value="SpecifiedValue::transparent()", spec="https://drafts.csswg.org/css-backgrounds/#background-color", animatable=True, complex_color=True)} diff --git a/components/style/properties/longhand/column.mako.rs b/components/style/properties/longhand/column.mako.rs index f55524f5201..b3c782e5c2e 100644 --- a/components/style/properties/longhand/column.mako.rs +++ b/components/style/properties/longhand/column.mako.rs @@ -10,6 +10,7 @@ ${helpers.predefined_type("column-width", "length::LengthOrAuto", "Either::Second(Auto)", + initial_specified_value="Either::Second(Auto)", parse_method="parse_non_negative_length", extra_prefixes="moz", animatable=False, @@ -62,6 +63,11 @@ ${helpers.predefined_type("column-width", computed_value::T(None) } + #[inline] + pub fn get_initial_specified_value() -> SpecifiedValue { + SpecifiedValue::Auto + } + impl ToComputedValue for SpecifiedValue { type ComputedValue = computed_value::T; @@ -146,6 +152,7 @@ ${helpers.single_keyword("column-fill", "auto balance", extra_prefixes="moz", // https://drafts.csswg.org/css-multicol-1/#crc ${helpers.predefined_type("column-rule-color", "CSSColor", "::cssparser::Color::CurrentColor", + initial_specified_value="specified::CSSColor::currentcolor()", products="gecko", animatable=True, extra_prefixes="moz", complex_color=True, need_clone=True, spec="https://drafts.csswg.org/css-multicol/#propdef-column-rule-color")} diff --git a/components/style/properties/longhand/font.mako.rs b/components/style/properties/longhand/font.mako.rs index 4b05c50b970..37c467b242f 100644 --- a/components/style/properties/longhand/font.mako.rs +++ b/components/style/properties/longhand/font.mako.rs @@ -326,6 +326,11 @@ ${helpers.single_keyword("font-variant-caps", computed_value::T::Weight400 // normal } + #[inline] + pub fn get_initial_specified_value() -> SpecifiedValue { + SpecifiedValue::Normal + } + impl ToComputedValue for SpecifiedValue { type ComputedValue = computed_value::T; @@ -407,6 +412,11 @@ ${helpers.single_keyword("font-variant-caps", Au::from_px(FONT_MEDIUM_PX) } + #[inline] + pub fn get_initial_specified_value() -> SpecifiedValue { + SpecifiedValue(specified::LengthOrPercentage::Length(NoCalcLength::medium())) + } + impl ToComputedValue for SpecifiedValue { type ComputedValue = computed_value::T; @@ -502,6 +512,11 @@ ${helpers.single_keyword("font-variant-caps", computed_value::T::None } + #[inline] + pub fn get_initial_specified_value() -> SpecifiedValue { + SpecifiedValue::None + } + /// none | pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result { use values::specified::Number; @@ -750,6 +765,11 @@ ${helpers.single_keyword("font-variant-position", computed_value::T::Normal } + #[inline] + pub fn get_initial_specified_value() -> SpecifiedValue { + SpecifiedValue::Normal + } + pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result { if input.try(|input| input.expect_ident_matching("normal")).is_ok() { Ok(SpecifiedValue::Normal) diff --git a/components/style/properties/longhand/inherited_text.mako.rs b/components/style/properties/longhand/inherited_text.mako.rs index 60ca0ee5194..637c2776aa3 100644 --- a/components/style/properties/longhand/inherited_text.mako.rs +++ b/components/style/properties/longhand/inherited_text.mako.rs @@ -101,6 +101,11 @@ #[inline] pub fn get_initial_value() -> computed_value::T { computed_value::T::Normal } + #[inline] + pub fn get_initial_specified_value() -> SpecifiedValue { + SpecifiedValue::Normal + } + impl ToComputedValue for SpecifiedValue { type ComputedValue = computed_value::T; @@ -1031,6 +1036,7 @@ ${helpers.single_keyword("text-align-last", ${helpers.predefined_type("text-emphasis-color", "CSSColor", "::cssparser::Color::CurrentColor", + initial_specified_value="specified::CSSColor::currentcolor()", products="gecko", animatable=True, complex_color=True, need_clone=True, spec="https://drafts.csswg.org/css-text-decor/#propdef-text-emphasis-color")} @@ -1056,6 +1062,7 @@ ${helpers.predefined_type( ${helpers.predefined_type( "-webkit-text-stroke-color", "CSSColor", "CSSParserColor::CurrentColor", + initial_specified_value="specified::CSSColor::currentcolor()", products="gecko", animatable=True, complex_color=True, need_clone=True, spec="https://compat.spec.whatwg.org/#the-webkit-text-stroke-color")} @@ -1066,7 +1073,7 @@ ${helpers.predefined_type( use std::fmt; use style_traits::ToCss; use values::HasViewportPercentage; - use values::specified::BorderWidth; + use values::specified::{BorderWidth, Length}; pub type SpecifiedValue = BorderWidth; @@ -1082,6 +1089,10 @@ ${helpers.predefined_type( #[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()) + } diff --git a/components/style/properties/longhand/list.mako.rs b/components/style/properties/longhand/list.mako.rs index 5f1bf103d7f..81ce62a32e1 100644 --- a/components/style/properties/longhand/list.mako.rs +++ b/components/style/properties/longhand/list.mako.rs @@ -38,7 +38,7 @@ ${helpers.single_keyword("list-style-type", """ spec="https://drafts.csswg.org/css-lists/#propdef-list-style-type")} ${helpers.predefined_type("list-style-image", "UrlOrNone", "Either::Second(None_)", - animatable=False, + initial_specified_value="Either::Second(None_)", animatable=False, spec="https://drafts.csswg.org/css-lists/#propdef-list-style-image")} <%helpers:longhand name="quotes" animatable="False" diff --git a/components/style/properties/longhand/outline.mako.rs b/components/style/properties/longhand/outline.mako.rs index 8b2f51ef2ed..65be748c187 100644 --- a/components/style/properties/longhand/outline.mako.rs +++ b/components/style/properties/longhand/outline.mako.rs @@ -11,6 +11,7 @@ // TODO(pcwalton): `invert` ${helpers.predefined_type("outline-color", "CSSColor", "::cssparser::Color::CurrentColor", + initial_specified_value="specified::CSSColor::currentcolor()", animatable=True, complex_color=True, need_clone=True, spec="https://drafts.csswg.org/css-ui/#propdef-outline-color")} @@ -39,6 +40,11 @@ ${helpers.predefined_type("outline-color", "CSSColor", "::cssparser::Color::Curr Either::Second(BorderStyle::none) } + #[inline] + pub fn get_initial_specified_value() -> SpecifiedValue { + Either::Second(BorderStyle::none) + } + pub mod computed_value { pub type T = super::SpecifiedValue; } @@ -88,7 +94,13 @@ ${helpers.predefined_type("outline-color", "CSSColor", "::cssparser::Color::Curr use app_units::Au; pub type T = Au; } + pub use super::border_top_width::get_initial_value; + #[inline] + pub fn get_initial_specified_value() -> SpecifiedValue { + SpecifiedValue(specified::Length::NoCalc(specified::NoCalcLength::medium())) + } + impl ToComputedValue for SpecifiedValue { type ComputedValue = computed_value::T; diff --git a/components/style/properties/longhand/text.mako.rs b/components/style/properties/longhand/text.mako.rs index 9b2a851bc6f..654eac072ae 100644 --- a/components/style/properties/longhand/text.mako.rs +++ b/components/style/properties/longhand/text.mako.rs @@ -169,6 +169,10 @@ ${helpers.single_keyword("unicode-bidi", #[inline] pub fn get_initial_value() -> computed_value::T { computed_value::none } + #[inline] + pub fn get_initial_specified_value() -> SpecifiedValue { + SpecifiedValue::empty() + } /// none | [ underline || overline || line-through || blink ] pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result { let mut result = SpecifiedValue::empty(); @@ -219,7 +223,8 @@ ${helpers.single_keyword("text-decoration-style", ${helpers.predefined_type( "text-decoration-color", "CSSColor", - "CSSParserColor::RGBA(RGBA::new(0, 0, 0, 255))", + "::cssparser::Color::CurrentColor", + initial_specified_value="specified::CSSColor::currentcolor()", complex_color=True, products="gecko", animatable=True, diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs index 8293622cbe5..97ef54845ab 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -344,6 +344,12 @@ impl NoCalcLength { *self == NoCalcLength::Absolute(Au(0)) } + #[inline] + /// Returns a `medium` length. + pub fn medium() -> NoCalcLength { + NoCalcLength::Absolute(Au::from_px(FONT_MEDIUM_PX)) + } + /// Get an absolute length from a px value. #[inline] pub fn from_px(px_value: CSSFloat) -> NoCalcLength { diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 4dc93972554..7584ec7bee8 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -78,6 +78,27 @@ impl ToCss for CSSColor { } } +impl CSSColor { + #[inline] + /// Returns currentcolor value. + pub fn currentcolor() -> CSSColor { + CSSColor { + parsed: cssparser::Color::CurrentColor, + authored: None, + } + } + + #[inline] + /// Returns transparent value. + pub fn transparent() -> CSSColor { + CSSColor { + parsed: cssparser::Color::RGBA(cssparser::RGBA::transparent()), + // This should probably be "transparent", but maybe it doesn't matter. + authored: None, + } + } +} + #[derive(Clone, PartialEq, Debug)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[allow(missing_docs)]