From e05058d2b9b9a7fcf849418d83293ada19991de0 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 21 Jul 2017 14:09:41 -0400 Subject: [PATCH 1/3] Add property flags for which properties apply to certain pseudo-elements. r=emilio These flags can be used to flag properties that apply to ::first-letter, ::first-line, and ::placeholder Part 1 of the fix for Gecko bug 1382786 . --- components/style/properties/properties.mako.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 5db0ec71ed4..6eeeb33f913 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -442,6 +442,12 @@ bitflags! { const ABSPOS_CB = 1 << 2, /// This shorthand property is an alias of another property. const SHORTHAND_ALIAS_PROPERTY = 1 << 3, + /// This longhand property applies to ::first-letter. + const APPLIES_TO_FIRST_LETTER = 1 << 4, + /// This longhand property applies to ::first-line. + const APPLIES_TO_FIRST_LINE = 1 << 5, + /// This longhand property applies to ::placeholder. + const APPLIES_TO_PLACEHOLDER = 1 << 6, } } From 592a96fc06cc8011b2588c444f64b58fcc0f216b Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 21 Jul 2017 14:15:42 -0400 Subject: [PATCH 2/3] Flag properties that apply to ::first-letter/::first-line/::placeholder. r=emilio Part 2 of the fix for Gecko bug 1382786 . --- .../properties/longhand/background.mako.rs | 23 +++++++++++++------ .../style/properties/longhand/border.mako.rs | 10 ++++++++ .../style/properties/longhand/box.mako.rs | 15 ++++++++++++ .../style/properties/longhand/color.mako.rs | 1 + .../style/properties/longhand/effects.mako.rs | 3 ++- .../style/properties/longhand/font.mako.rs | 18 +++++++++++++++ .../longhand/inherited_text.mako.rs | 13 +++++++++++ .../style/properties/longhand/margin.mako.rs | 1 + .../style/properties/longhand/padding.mako.rs | 3 +++ .../properties/longhand/pointing.mako.rs | 1 + .../style/properties/longhand/text.mako.rs | 5 ++++ 11 files changed, 85 insertions(+), 8 deletions(-) diff --git a/components/style/properties/longhand/background.mako.rs b/components/style/properties/longhand/background.mako.rs index 2c75d43dd05..5c252e15e9b 100644 --- a/components/style/properties/longhand/background.mako.rs +++ b/components/style/properties/longhand/background.mako.rs @@ -12,7 +12,8 @@ ${helpers.predefined_type("background-color", "Color", spec="https://drafts.csswg.org/css-backgrounds/#background-color", animation_value_type="IntermediateColor", ignored_when_colors_disabled=True, - allow_quirks=True)} + allow_quirks=True, + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER")} ${helpers.predefined_type("background-image", "ImageLayer", initial_value="Either::First(None_)", @@ -21,7 +22,8 @@ ${helpers.predefined_type("background-image", "ImageLayer", vector="True", animation_value_type="discrete", has_uncacheable_values="True" if product == "gecko" else "False", - ignored_when_colors_disabled="True")} + ignored_when_colors_disabled="True", + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER")} % for (axis, direction, initial) in [("x", "Horizontal", "left"), ("y", "Vertical", "top")]: ${helpers.predefined_type( @@ -32,11 +34,13 @@ ${helpers.predefined_type("background-image", "ImageLayer", spec="https://drafts.csswg.org/css-backgrounds-4/#propdef-background-position-" + axis, animation_value_type="ComputedValue", vector=True, + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", )} % endfor <%helpers:vector_longhand name="background-repeat" animation_value_type="discrete" - spec="https://drafts.csswg.org/css-backgrounds/#the-background-repeat"> + spec="https://drafts.csswg.org/css-backgrounds/#the-background-repeat" + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER"> use std::fmt; use style_traits::ToCss; @@ -138,7 +142,8 @@ ${helpers.single_keyword("background-attachment", vector=True, gecko_constant_prefix="NS_STYLE_IMAGELAYER_ATTACHMENT", spec="https://drafts.csswg.org/css-backgrounds/#the-background-attachment", - animation_value_type="discrete")} + animation_value_type="discrete", + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER")} ${helpers.single_keyword("background-clip", "border-box padding-box content-box", @@ -146,14 +151,16 @@ ${helpers.single_keyword("background-clip", vector=True, extra_prefixes="webkit", gecko_enum_prefix="StyleGeometryBox", spec="https://drafts.csswg.org/css-backgrounds/#the-background-clip", - animation_value_type="discrete")} + animation_value_type="discrete", + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER")} ${helpers.single_keyword("background-origin", "padding-box border-box content-box", vector=True, extra_prefixes="webkit", gecko_enum_prefix="StyleGeometryBox", spec="https://drafts.csswg.org/css-backgrounds/#the-background-origin", - animation_value_type="discrete")} + animation_value_type="discrete", + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER")} ${helpers.predefined_type("background-size", "BackgroundSize", initial_value="computed::LengthOrPercentageOrAuto::Auto.into()", @@ -161,6 +168,7 @@ ${helpers.predefined_type("background-size", "BackgroundSize", spec="https://drafts.csswg.org/css-backgrounds/#the-background-size", vector=True, animation_value_type="ComputedValue", + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", extra_prefixes="webkit")} // https://drafts.fxtf.org/compositing/#background-blend-mode @@ -170,4 +178,5 @@ ${helpers.single_keyword("background-blend-mode", saturation color luminosity""", gecko_constant_prefix="NS_STYLE_BLEND", vector=True, products="gecko", animation_value_type="discrete", - spec="https://drafts.fxtf.org/compositing/#background-blend-mode")} + spec="https://drafts.fxtf.org/compositing/#background-blend-mode", + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER")} diff --git a/components/style/properties/longhand/border.mako.rs b/components/style/properties/longhand/border.mako.rs index 8a3558436a5..c4f6aa888b1 100644 --- a/components/style/properties/longhand/border.mako.rs +++ b/components/style/properties/longhand/border.mako.rs @@ -27,12 +27,14 @@ animation_value_type="IntermediateColor", logical=is_logical, allow_quirks=not is_logical, + flags="APPLIES_TO_FIRST_LETTER", ignored_when_colors_disabled=True)} ${helpers.predefined_type("border-%s-style" % side_name, "BorderStyle", "specified::BorderStyle::none", alias=maybe_moz_logical_alias(product, side, "-moz-border-%s-style"), spec=maybe_logical_spec(side, "style"), + flags="APPLIES_TO_FIRST_LETTER", animation_value_type="discrete" if not is_logical else "none", logical=is_logical)} @@ -44,6 +46,7 @@ spec=maybe_logical_spec(side, "width"), animation_value_type="ComputedValue", logical=is_logical, + flags="APPLIES_TO_FIRST_LETTER", allow_quirks=not is_logical)} % endfor @@ -58,6 +61,7 @@ ${helpers.gecko_keyword_conversion(Keyword('border-style', "parse", extra_prefixes="webkit", spec="https://drafts.csswg.org/css-backgrounds/#border-%s-radius" % corner, boxed=True, + flags="APPLIES_TO_FIRST_LETTER", animation_value_type="ComputedValue")} % endfor @@ -67,6 +71,7 @@ ${helpers.gecko_keyword_conversion(Keyword('border-style', <%helpers:longhand name="-moz-border-${side}-colors" animation_value_type="discrete" spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-border-*-colors)" products="gecko" + flags="APPLIES_TO_FIRST_LETTER" ignored_when_colors_disabled="True"> use std::fmt; use style_traits::ToCss; @@ -206,6 +211,7 @@ ${helpers.predefined_type("border-image-source", "ImageLayer", vector=False, animation_value_type="discrete", has_uncacheable_values=False, + flags="APPLIES_TO_FIRST_LETTER", boxed="True")} ${helpers.predefined_type("border-image-outset", "LengthOrNumberRect", @@ -214,9 +220,11 @@ ${helpers.predefined_type("border-image-outset", "LengthOrNumberRect", initial_specified_value="specified::LengthOrNumber::zero().into()", spec="https://drafts.csswg.org/css-backgrounds/#border-image-outset", animation_value_type="discrete", + flags="APPLIES_TO_FIRST_LETTER", boxed=True)} <%helpers:longhand name="border-image-repeat" animation_value_type="discrete" + flags="APPLIES_TO_FIRST_LETTER" spec="https://drafts.csswg.org/css-backgrounds/#border-image-repeat"> use style_traits::ToCss; @@ -278,6 +286,7 @@ ${helpers.predefined_type("border-image-width", "BorderImageWidth", initial_specified_value="specified::BorderImageSideWidth::one().into()", spec="https://drafts.csswg.org/css-backgrounds/#border-image-width", animation_value_type="discrete", + flags="APPLIES_TO_FIRST_LETTER", boxed=True)} ${helpers.predefined_type("border-image-slice", "BorderImageSlice", @@ -285,6 +294,7 @@ ${helpers.predefined_type("border-image-slice", "BorderImageSlice", initial_specified_value="specified::NumberOrPercentage::Percentage(specified::Percentage::new(1.)).into()", spec="https://drafts.csswg.org/css-backgrounds/#border-image-slice", animation_value_type="discrete", + flags="APPLIES_TO_FIRST_LETTER", boxed=True)} #[cfg(feature = "gecko")] diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index 54b79481c81..3738032491c 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -10,10 +10,14 @@ gecko_name="Display") %> // TODO(SimonSapin): don't parse `inline-table`, since we don't support it +// +// We allow "display" to apply to placeholders because we need to make the +// placeholder pseudo-element an inline-block in the UA stylesheet in Gecko. <%helpers:longhand name="display" need_clone="True" animation_value_type="discrete" custom_cascade="${product == 'servo'}" + flags="APPLIES_TO_PLACEHOLDER" spec="https://drafts.csswg.org/css-display/#propdef-display"> <% values = """inline block inline-block @@ -216,6 +220,7 @@ ${helpers.single_keyword("position", "static absolute relative fixed", gecko_inexhaustive="True" gecko_ffi_name="mFloat" gecko_pref_ident="float_" + flags="APPLIES_TO_FIRST_LETTER" spec="https://drafts.csswg.org/css-box/#propdef-float"> no_viewport_percentage!(SpecifiedValue); impl ToComputedValue for SpecifiedValue { @@ -306,6 +311,7 @@ ${helpers.single_keyword("position", "static absolute relative fixed", <%helpers:longhand name="vertical-align" animation_value_type="ComputedValue" + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", spec="https://www.w3.org/TR/CSS2/visudet.html#propdef-vertical-align"> use std::fmt; use style_traits::ToCss; @@ -432,6 +438,7 @@ ${helpers.single_keyword("-servo-overflow-clip-box", "padding-box content-box", ${helpers.single_keyword("overflow-clip-box", "padding-box content-box", products="gecko", animation_value_type="discrete", internal=True, + flags="APPLIES_TO_PLACEHOLDER", spec="Internal, not web-exposed, \ may be standardized in the future (https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-clip-box)")} @@ -445,10 +452,12 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", extra_gecko_values="-moz-hidden-unscrollable", custom_consts=overflow_custom_consts, gecko_constant_prefix="NS_STYLE_OVERFLOW", + flags="APPLIES_TO_PLACEHOLDER", spec="https://drafts.csswg.org/css-overflow/#propdef-overflow-x")} // FIXME(pcwalton, #2742): Implement scrolling for `scroll` and `auto`. <%helpers:longhand name="overflow-y" need_clone="True" animation_value_type="discrete" + flags="APPLIES_TO_PLACEHOLDER", spec="https://drafts.csswg.org/css-overflow/#propdef-overflow-y"> pub use super::overflow_x::{SpecifiedValue, parse, get_initial_value, computed_value}; @@ -1618,10 +1627,15 @@ ${helpers.single_keyword("page-break-inside", // CSS Basic User Interface Module Level 3 // http://dev.w3.org/csswg/css-ui // FIXME support logical values `block` and `inline` (https://drafts.csswg.org/css-logical-props/#resize) +// +// This is APPLIES_TO_PLACEHOLDER so we can override, in the UA sheet, the +// 'resize' property we'd inherit from textarea otherwise. Basically, just +// makes the UA rules easier to write. ${helpers.single_keyword("resize", "none both horizontal vertical", products="gecko", spec="https://drafts.csswg.org/css-ui/#propdef-resize", + flags="APPLIES_TO_PLACEHOLDER", animation_value_type="discrete")} @@ -1888,6 +1902,7 @@ ${helpers.predefined_type("shape-outside", "basic_shape::FloatAreaShape", "generics::basic_shape::ShapeSource::None", products="gecko", boxed="True", animation_value_type="none", + flags="APPLIES_TO_FIRST_LETTER", spec="https://drafts.csswg.org/css-shapes/#shape-outside-property")} <%helpers:longhand name="touch-action" diff --git a/components/style/properties/longhand/color.mako.rs b/components/style/properties/longhand/color.mako.rs index 6fdd33156d5..76b5ca18aea 100644 --- a/components/style/properties/longhand/color.mako.rs +++ b/components/style/properties/longhand/color.mako.rs @@ -11,6 +11,7 @@ <%helpers:longhand name="color" need_clone="True" animation_value_type="IntermediateRGBA" ignored_when_colors_disabled="True" + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER" spec="https://drafts.csswg.org/css-color/#color"> use cssparser::RGBA; use values::specified::{AllowQuirks, Color}; diff --git a/components/style/properties/longhand/effects.mako.rs b/components/style/properties/longhand/effects.mako.rs index e66d9324eda..bec6cae249b 100644 --- a/components/style/properties/longhand/effects.mako.rs +++ b/components/style/properties/longhand/effects.mako.rs @@ -11,7 +11,7 @@ ${helpers.predefined_type("opacity", "Opacity", "1.0", animation_value_type="ComputedValue", - flags="CREATES_STACKING_CONTEXT", + flags="CREATES_STACKING_CONTEXT APPLIES_TO_PLACEHOLDER", spec="https://drafts.csswg.org/css-color/#opacity")} ${helpers.predefined_type( @@ -22,6 +22,7 @@ ${helpers.predefined_type( animation_value_type="AnimatedBoxShadowList", extra_prefixes="webkit", ignored_when_colors_disabled=True, + flags="APPLIES_TO_FIRST_LETTER", spec="https://drafts.csswg.org/css-backgrounds/#box-shadow", )} diff --git a/components/style/properties/longhand/font.mako.rs b/components/style/properties/longhand/font.mako.rs index 538ffe3b043..c83f60b26e5 100644 --- a/components/style/properties/longhand/font.mako.rs +++ b/components/style/properties/longhand/font.mako.rs @@ -69,6 +69,7 @@ macro_rules! impl_gecko_keyword_conversions { <%helpers:longhand name="font-family" animation_value_type="discrete" need_index="True" boxed="${product == 'gecko'}" + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER" spec="https://drafts.csswg.org/css-fonts/#propdef-font-family"> use properties::longhands::system_font::SystemFont; use self::computed_value::{FontFamily, FamilyName}; @@ -379,6 +380,7 @@ ${helpers.single_keyword_system("font-style", gecko_constant_prefix="NS_FONT_STYLE", gecko_ffi_name="mFont.style", spec="https://drafts.csswg.org/css-fonts/#propdef-font-style", + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", animation_value_type="discrete")} @@ -395,9 +397,11 @@ ${helpers.single_keyword_system("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" spec="https://drafts.csswg.org/css-fonts/#propdef-font-weight"> use properties::longhands::system_font::SystemFont; @@ -559,6 +563,7 @@ ${helpers.single_keyword_system("font-variant-caps", <%helpers:longhand name="font-size" need_clone="True" animation_value_type="ComputedValue" + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER" allow_quirks="True" spec="https://drafts.csswg.org/css-fonts/#propdef-font-size"> use app_units::Au; use properties::longhands::system_font::SystemFont; @@ -1020,6 +1025,7 @@ ${helpers.single_keyword_system("font-variant-caps", <%helpers:longhand products="gecko" name="font-size-adjust" animation_value_type="ComputedValue" + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER" spec="https://drafts.csswg.org/css-fonts/#propdef-font-size-adjust"> use properties::longhands::system_font::SystemFont; @@ -1141,6 +1147,7 @@ ${helpers.single_keyword_system("font-variant-caps", <%helpers:longhand products="gecko" name="font-synthesis" animation_value_type="discrete" + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER" spec="https://drafts.csswg.org/css-fonts/#propdef-font-synthesis"> use std::fmt; use style_traits::ToCss; @@ -1238,6 +1245,7 @@ ${helpers.single_keyword_system("font-stretch", gecko_constant_prefix="NS_FONT_STRETCH", cast_type='i16', spec="https://drafts.csswg.org/css-fonts/#propdef-font-stretch", + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", animation_value_type="ComputedValue")} ${helpers.single_keyword_system("font-kerning", @@ -1246,9 +1254,11 @@ ${helpers.single_keyword_system("font-kerning", gecko_ffi_name="mFont.kerning", gecko_constant_prefix="NS_FONT_KERNING", spec="https://drafts.csswg.org/css-fonts/#propdef-font-kerning", + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", animation_value_type="discrete")} <%helpers:longhand name="font-variant-alternates" products="gecko" animation_value_type="none" + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER" spec="https://drafts.csswg.org/css-fonts/#propdef-font-variant-alternates"> use properties::longhands::system_font::SystemFont; use std::fmt; @@ -1458,6 +1468,7 @@ macro_rules! exclusive_value { } <%helpers:longhand name="font-variant-east-asian" products="gecko" animation_value_type="discrete" + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER" spec="https://drafts.csswg.org/css-fonts/#propdef-font-variant-east-asian"> use properties::longhands::system_font::SystemFont; use std::fmt; @@ -1603,6 +1614,7 @@ macro_rules! exclusive_value { <%helpers:longhand name="font-variant-ligatures" products="gecko" animation_value_type="discrete" + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER" spec="https://drafts.csswg.org/css-fonts/#propdef-font-variant-ligatures"> use properties::longhands::system_font::SystemFont; use std::fmt; @@ -1762,6 +1774,7 @@ macro_rules! exclusive_value { <%helpers:longhand name="font-variant-numeric" products="gecko" animation_value_type="discrete" + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER" spec="https://drafts.csswg.org/css-fonts/#propdef-font-variant-numeric"> use properties::longhands::system_font::SystemFont; use std::fmt; @@ -1915,10 +1928,12 @@ ${helpers.single_keyword_system("font-variant-position", gecko_ffi_name="mFont.variantPosition", gecko_constant_prefix="NS_FONT_VARIANT_POSITION", spec="https://drafts.csswg.org/css-fonts/#propdef-font-variant-position", + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", animation_value_type="discrete")} <%helpers:longhand name="font-feature-settings" products="gecko" animation_value_type="discrete" extra_prefixes="moz" boxed="True" + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER" spec="https://drafts.csswg.org/css-fonts/#propdef-font-feature-settings"> use properties::longhands::system_font::SystemFont; use values::generics::FontSettings; @@ -1961,6 +1976,7 @@ https://drafts.csswg.org/css-fonts-4/#low-level-font-variation-settings-control- """ %> <%helpers:longhand name="font-variation-settings" products="gecko" animation_value_type="none" + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER" spec="${variation_spec}"> use values::computed::ComputedValueAsSpecified; use values::generics::FontSettings; @@ -1991,6 +2007,7 @@ https://drafts.csswg.org/css-fonts-4/#low-level-font-variation-settings-control- <%helpers:longhand name="font-language-override" products="gecko" animation_value_type="discrete" extra_prefixes="moz" boxed="True" + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER" spec="https://drafts.csswg.org/css-fonts-3/#propdef-font-language-override"> use properties::longhands::system_font::SystemFont; use std::fmt; @@ -2550,6 +2567,7 @@ ${helpers.single_keyword("-moz-osx-font-smoothing", gecko_ffi_name="mFont.smoothing", products="gecko", spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/font-smooth)", + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", animation_value_type="discrete")} ${helpers.predefined_type("-moz-min-font-size-ratio", diff --git a/components/style/properties/longhand/inherited_text.mako.rs b/components/style/properties/longhand/inherited_text.mako.rs index f114344ae52..3f2a5ab02a1 100644 --- a/components/style/properties/longhand/inherited_text.mako.rs +++ b/components/style/properties/longhand/inherited_text.mako.rs @@ -10,6 +10,7 @@ ${helpers.predefined_type("line-height", "LineHeight", "computed::LineHeight::normal()", animation_value_type="ComputedValue", + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", spec="https://drafts.csswg.org/css2/visudet.html#propdef-line-height")} // CSS Text Module Level 3 @@ -19,6 +20,7 @@ ${helpers.single_keyword("text-transform", "none capitalize uppercase lowercase", extra_gecko_values="full-width", animation_value_type="discrete", + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", spec="https://drafts.csswg.org/css-text/#propdef-text-transform")} ${helpers.single_keyword("hyphens", "manual none auto", @@ -66,6 +68,7 @@ ${helpers.single_keyword("word-break", gecko_enum_prefix="StyleTextJustify" gecko_inexhaustive="True" animation_value_type="discrete" + flags="APPLIES_TO_PLACEHOLDER", spec="https://drafts.csswg.org/css-text/#propdef-text-justify"> no_viewport_percentage!(SpecifiedValue); @@ -109,6 +112,7 @@ ${helpers.single_keyword("text-align-last", // TODO make this a shorthand and implement text-align-last/text-align-all <%helpers:longhand name="text-align" animation_value_type="discrete" + flags="APPLIES_TO_PLACEHOLDER" spec="https://drafts.csswg.org/css-text/#propdef-text-align"> no_viewport_percentage!(SpecifiedValue); pub mod computed_value { @@ -267,12 +271,14 @@ ${helpers.predefined_type("letter-spacing", "LetterSpacing", "computed::LetterSpacing::normal()", animation_value_type="ComputedValue", + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", spec="https://drafts.csswg.org/css-text/#propdef-letter-spacing")} ${helpers.predefined_type("word-spacing", "WordSpacing", "computed::WordSpacing::normal()", animation_value_type="ComputedValue", + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", spec="https://drafts.csswg.org/css-text/#propdef-word-spacing")} <%helpers:longhand name="-servo-text-decorations-in-effect" @@ -367,6 +373,9 @@ ${helpers.predefined_type("word-spacing", needs_conversion="True" gecko_inexhaustive="True" animation_value_type="discrete" + // Only allowed for UA sheets, which set it + // !important. + flags="APPLIES_TO_PLACEHOLDER" spec="https://drafts.csswg.org/css-text/#propdef-white-space"> use values::computed::ComputedValueAsSpecified; impl ComputedValueAsSpecified for SpecifiedValue {} @@ -414,6 +423,7 @@ ${helpers.predefined_type( vector=True, animation_value_type="AnimatedTextShadowList", ignored_when_colors_disabled=True, + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", spec="https://drafts.csswg.org/css-text-decor-3/#text-shadow-property", )} @@ -718,6 +728,7 @@ ${helpers.predefined_type( "computed_value::T::currentcolor()", products="gecko", animation_value_type="IntermediateColor", need_clone=True, ignored_when_colors_disabled=True, + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", spec="https://compat.spec.whatwg.org/#the-webkit-text-fill-color")} ${helpers.predefined_type( @@ -726,6 +737,7 @@ ${helpers.predefined_type( initial_specified_value="specified::Color::currentcolor()", products="gecko", animation_value_type="IntermediateColor", need_clone=True, ignored_when_colors_disabled=True, + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", spec="https://compat.spec.whatwg.org/#the-webkit-text-stroke-color")} ${helpers.predefined_type("-webkit-text-stroke-width", @@ -734,6 +746,7 @@ ${helpers.predefined_type("-webkit-text-stroke-width", initial_specified_value="specified::BorderSideWidth::Length(specified::Length::zero())", computed_type="::app_units::Au", products="gecko", + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", spec="https://compat.spec.whatwg.org/#the-webkit-text-stroke-width", animation_value_type="none")} diff --git a/components/style/properties/longhand/margin.mako.rs b/components/style/properties/longhand/margin.mako.rs index 5c8a62aa01f..243adcafe5f 100644 --- a/components/style/properties/longhand/margin.mako.rs +++ b/components/style/properties/longhand/margin.mako.rs @@ -17,5 +17,6 @@ alias=maybe_moz_logical_alias(product, side, "-moz-margin-%s"), allow_quirks=not side[1], animation_value_type="ComputedValue", logical = side[1], spec = spec, + flags="APPLIES_TO_FIRST_LETTER", allowed_in_page_rule=True)} % endfor diff --git a/components/style/properties/longhand/padding.mako.rs b/components/style/properties/longhand/padding.mako.rs index ce74320f220..53035c32efb 100644 --- a/components/style/properties/longhand/padding.mako.rs +++ b/components/style/properties/longhand/padding.mako.rs @@ -6,6 +6,8 @@ <% from data import ALL_SIDES, maybe_moz_logical_alias %> <% data.new_style_struct("Padding", inherited=False) %> +// APPLIES_TO_PLACEHOLDER so we can set it in UA stylesheets. But we use a +// !important value there, so pages can't set it. % for side in ALL_SIDES: <% spec = "https://drafts.csswg.org/css-box/#propdef-padding-%s" % side[0] @@ -19,5 +21,6 @@ animation_value_type="ComputedValue", logical = side[1], spec = spec, + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_PLACEHOLDER", allow_quirks=not side[1])} % endfor diff --git a/components/style/properties/longhand/pointing.mako.rs b/components/style/properties/longhand/pointing.mako.rs index 9bf7e43446f..77a7426d6cb 100644 --- a/components/style/properties/longhand/pointing.mako.rs +++ b/components/style/properties/longhand/pointing.mako.rs @@ -152,6 +152,7 @@ // TODO(pcwalton): SVG-only values. ${helpers.single_keyword("pointer-events", "auto none", animation_value_type="discrete", extra_gecko_values="visiblepainted visiblefill visiblestroke visible painted fill stroke all", + flags="APPLIES_TO_PLACEHOLDER", spec="https://www.w3.org/TR/SVG11/interact.html#PointerEventsProperty")} ${helpers.single_keyword("-moz-user-input", "auto none enabled disabled", diff --git a/components/style/properties/longhand/text.mako.rs b/components/style/properties/longhand/text.mako.rs index 721fd2ad6f1..7279cc6770b 100644 --- a/components/style/properties/longhand/text.mako.rs +++ b/components/style/properties/longhand/text.mako.rs @@ -13,6 +13,7 @@ Method("has_line_through", "bool")]) %> <%helpers:longhand name="text-overflow" animation_value_type="discrete" boxed="True" + flags="APPLIES_TO_PLACEHOLDER" spec="https://drafts.csswg.org/css-ui/#propdef-text-overflow"> use std::fmt; use style_traits::ToCss; @@ -142,6 +143,7 @@ ${helpers.single_keyword("unicode-bidi", custom_cascade="${product == 'servo'}" need_clone=True animation_value_type="discrete" + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", spec="https://drafts.csswg.org/css-text-decor/#propdef-text-decoration-line"> use std::fmt; use style_traits::ToCss; @@ -262,6 +264,7 @@ ${helpers.single_keyword("text-decoration-style", "solid double dotted dashed wavy -moz-none", products="gecko", animation_value_type="discrete", + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", spec="https://drafts.csswg.org/css-text-decor/#propdef-text-decoration-style")} ${helpers.predefined_type( @@ -271,6 +274,7 @@ ${helpers.predefined_type( products="gecko", animation_value_type="IntermediateColor", ignored_when_colors_disabled=True, + flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", spec="https://drafts.csswg.org/css-text-decor/#propdef-text-decoration-color")} ${helpers.predefined_type( @@ -280,4 +284,5 @@ ${helpers.predefined_type( initial_specified_value="specified::InitialLetter::normal()", animation_value_type="discrete", products="gecko", + flags="APPLIES_TO_FIRST_LETTER", spec="https://drafts.csswg.org/css-inline/#sizing-drop-initials")} From 86b3b6a32f2f1e1064ec0bdd70f37bddf44b377c Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 21 Jul 2017 14:16:06 -0400 Subject: [PATCH 3/3] Filter out non-applying properties when cascading style for ::first-letter/::first-line/::placeholder. r=emilio Part 3 of the fix for Gecko bug 1382786 . --- components/style/gecko/pseudo_element.rs | 13 +++++++++++++ components/style/properties/properties.mako.rs | 15 +++++++++++++++ components/style/servo/selector_parser.rs | 13 +++++++++++++ 3 files changed, 41 insertions(+) diff --git a/components/style/gecko/pseudo_element.rs b/components/style/gecko/pseudo_element.rs index 97ce0f4e5a1..7765122bd61 100644 --- a/components/style/gecko/pseudo_element.rs +++ b/components/style/gecko/pseudo_element.rs @@ -10,6 +10,8 @@ use cssparser::{ToCss, serialize_identifier}; use gecko_bindings::structs::{self, CSSPseudoElementType}; +use properties::{PropertyFlags, APPLIES_TO_FIRST_LETTER, APPLIES_TO_FIRST_LINE}; +use properties::APPLIES_TO_PLACEHOLDER; use selector_parser::{NonTSPseudoClass, PseudoElementCascadeType, SelectorImpl}; use std::fmt; use string_cache::Atom; @@ -119,4 +121,15 @@ impl PseudoElement { _ => self.clone(), } } + + /// Property flag that properties must have to apply to this pseudo-element. + #[inline] + pub fn property_restriction(&self) -> Option { + match *self { + PseudoElement::FirstLetter => Some(APPLIES_TO_FIRST_LETTER), + PseudoElement::FirstLine => Some(APPLIES_TO_FIRST_LINE), + PseudoElement::Placeholder => Some(APPLIES_TO_PLACEHOLDER), + _ => None, + } + } } diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 6eeeb33f913..6e1bf5e7477 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -2872,11 +2872,26 @@ pub fn cascade( &[] }; let node_importance = node.importance(); + + let property_restriction = pseudo.and_then(|p| p.property_restriction()); + declarations .iter() // Yield declarations later in source order (with more precedence) first. .rev() .filter_map(move |&(ref declaration, declaration_importance)| { + if let Some(property_restriction) = property_restriction { + // declaration.id() is either a longhand or a custom + // property. Custom properties are always allowed, but + // longhands are only allowed if they have our + // property_restriction flag set. + if let PropertyDeclarationId::Longhand(id) = declaration.id() { + if !id.flags().contains(property_restriction) { + return None + } + } + } + if declaration_importance == node_importance { Some((declaration, cascade_level)) } else { diff --git a/components/style/servo/selector_parser.rs b/components/style/servo/selector_parser.rs index e2dfc46f74d..b231265775a 100644 --- a/components/style/servo/selector_parser.rs +++ b/components/style/servo/selector_parser.rs @@ -13,6 +13,7 @@ use dom::{OpaqueNode, TElement, TNode}; use element_state::ElementState; use fnv::FnvHashMap; use invalidation::element::element_wrapper::ElementSnapshot; +use properties::PropertyFlags; use selector_parser::{AttrValue as SelectorAttrValue, ElementExt, PseudoElementCascadeType, SelectorParser}; use selectors::Element; use selectors::attr::{AttrSelectorOperation, NamespaceConstraint, CaseSensitivity}; @@ -39,6 +40,12 @@ pub enum PseudoElement { Before, Selection, // If/when :first-letter is added, update is_first_letter accordingly. + + // If/when ::first-letter, ::first-line, or ::placeholder are added, adjust + // our property_restriction implementation to do property filtering for + // them. Also, make sure the UA sheet has the !important rules some of the + // APPLIES_TO_PLACEHOLDER properties expect! + // Non-eager pseudos. DetailsSummary, DetailsContent, @@ -169,6 +176,12 @@ impl PseudoElement { /// Stub, only Gecko needs this pub fn pseudo_info(&self) { () } + + /// Property flag that properties must have to apply to this pseudo-element. + #[inline] + pub fn property_restriction(&self) -> Option { + None + } } /// The type used for storing pseudo-class string arguments.