From 5d2724994cd25b717618b6ea792ee51ea12a6da4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 6 Apr 2019 17:47:58 +0000 Subject: [PATCH] style: Remove the last usage of lossy currentcolor. We don't have lossy currentcolor in the style system anymore, except for a single property -moz-font-smoothing-background-color. I could've converted it into a proper StyleColor and thread down all the necessary information to the font metrics code. But it doesn't really seem worth it given it's not exposed to the web, so I just did the simplest thing, which is making currentcolor compute to transparent to that specific property. This patch also removes the stores_complex_colors_lossily code and related, since now we always can cache computed colors. Differential Revision: https://phabricator.services.mozilla.com/D26187 --- components/style/properties/gecko.mako.rs | 18 +-------- .../properties/longhands/background.mako.rs | 2 +- .../style/properties/longhands/font.mako.rs | 6 +-- .../style/properties/properties.mako.rs | 26 ------------- components/style/values/computed/color.rs | 8 ++-- components/style/values/computed/mod.rs | 2 +- components/style/values/specified/color.rs | 38 +++++++------------ components/style/values/specified/mod.rs | 2 +- 8 files changed, 24 insertions(+), 78 deletions(-) diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 44b76f28b5a..837a295fb60 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -40,8 +40,6 @@ use crate::gecko_bindings::structs::nsCSSPropertyID; use crate::gecko_bindings::structs::mozilla::PseudoStyleType; use crate::gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordData, CoordDataMut}; use crate::gecko_bindings::sugar::refptr::RefPtr; -use crate::gecko::values::convert_nscolor_to_rgba; -use crate::gecko::values::convert_rgba_to_nscolor; use crate::gecko::values::GeckoStyleCoordConvertible; use crate::gecko::values::round_border_to_device_pixels; use crate::logical_geometry::WritingMode; @@ -421,18 +419,6 @@ def set_gecko_property(ffi_name, expr): } -<%def name="impl_rgba_color(ident, gecko_ffi_name)"> - #[allow(non_snake_case)] - pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) { - ${set_gecko_property(gecko_ffi_name, "convert_rgba_to_nscolor(&v)")} - } - <%call expr="impl_simple_copy(ident, gecko_ffi_name)"> - #[allow(non_snake_case)] - pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T { - convert_nscolor_to_rgba(${get_gecko_property(gecko_ffi_name)}) - } - - <%def name="impl_svg_length(ident, gecko_ffi_name)"> // When context-value is used on an SVG length, the corresponding flag is // set on mContextFlags, and the length field is set to the initial value. @@ -1206,7 +1192,6 @@ impl Clone for ${style_struct.gecko_struct_name} { predefined_types = { "length::NonNegativeLengthPercentageOrNormal": impl_style_coord, "MozScriptMinSize": impl_absolute_length, - "RGBAColor": impl_rgba_color, "SVGLength": impl_svg_length, "SVGOpacity": impl_svg_opacity, "SVGPaint": impl_svg_paint, @@ -4343,8 +4328,7 @@ clip-path } -<%self:impl_trait style_struct_name="Color" skip_longhands="color"> - ${impl_rgba_color("color", "mColor")} +<%self:impl_trait style_struct_name="Color"> <%self:impl_trait style_struct_name="InheritedUI" skip_longhands="cursor"> diff --git a/components/style/properties/longhands/background.mako.rs b/components/style/properties/longhands/background.mako.rs index c6a25be53c1..42344a18cb9 100644 --- a/components/style/properties/longhands/background.mako.rs +++ b/components/style/properties/longhands/background.mako.rs @@ -9,7 +9,7 @@ ${helpers.predefined_type( "background-color", "Color", - "computed_value::T::transparent()", + "computed::Color::transparent()", initial_specified_value="SpecifiedValue::transparent()", spec="https://drafts.csswg.org/css-backgrounds/#background-color", animation_value_type="AnimatedColor", diff --git a/components/style/properties/longhands/font.mako.rs b/components/style/properties/longhands/font.mako.rs index b253fde0b8d..7f7b66c3572 100644 --- a/components/style/properties/longhands/font.mako.rs +++ b/components/style/properties/longhands/font.mako.rs @@ -521,9 +521,9 @@ ${helpers.single_keyword( ${helpers.predefined_type( "-moz-font-smoothing-background-color", - "RGBAColor", - "RGBA::transparent()", - animation_value_type="AnimatedRGBA", + "color::MozFontSmoothingBackgroundColor", + "computed::color::MozFontSmoothingBackgroundColor::transparent()", + animation_value_type="none", products="gecko", gecko_ffi_name="mFont.fontSmoothingBackgroundColor", enabled_in="chrome", diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 5390c8e8270..99a91179150 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -1287,32 +1287,6 @@ impl LonghandId { LonghandId::Direction ) } - - /// Whether computed values of this property lossily convert any complex - /// colors into RGBA colors. - /// - /// In Gecko, there are some properties still that compute currentcolor - /// down to an RGBA color at computed value time, instead of as - /// `StyleColor`s. For these properties, we must return `false`, - /// so that we correctly avoid caching style data in the rule tree. - pub fn stores_complex_colors_lossily(&self) -> bool { - % if product == "gecko": - matches!(*self, - % for property in data.longhands: - % if property.predefined_type == "RGBAColor": - LonghandId::${property.camel_case} | - % endif - % endfor - LonghandId::BackgroundImage | - LonghandId::BorderImageSource | - LonghandId::BoxShadow | - LonghandId::MaskImage | - LonghandId::TextShadow - ) - % else: - false - % endif - } } /// An iterator over all the property ids that are enabled for a given diff --git a/components/style/values/computed/color.rs b/components/style/values/computed/color.rs index ade384a99ad..6098ea4590e 100644 --- a/components/style/values/computed/color.rs +++ b/components/style/values/computed/color.rs @@ -11,14 +11,14 @@ use cssparser::{Color as CSSParserColor, RGBA}; use std::fmt; use style_traits::{CssWriter, ToCss}; -/// Computed value type for the specified RGBAColor. -pub type RGBAColor = RGBA; - /// The computed value of the `color` property. pub type ColorPropertyValue = RGBA; +/// The computed value of `-moz-font-smoothing-background-color`. +pub type MozFontSmoothingBackgroundColor = RGBA; + /// A computed value for ``. -pub type Color = GenericColor; +pub type Color = GenericColor; impl Color { /// Returns a complex color value representing transparent. diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index 4c92218e69b..95a9806f359 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -43,7 +43,7 @@ pub use self::box_::{Appearance, BreakBetween, BreakWithin, Clear, Float}; pub use self::box_::{Display, Overflow, OverflowAnchor, TransitionProperty}; pub use self::box_::{OverflowClipBox, OverscrollBehavior, Perspective, Resize}; pub use self::box_::{ScrollSnapAlign, ScrollSnapType, TouchAction, VerticalAlign, WillChange}; -pub use self::color::{Color, ColorOrAuto, ColorPropertyValue, RGBAColor}; +pub use self::color::{Color, ColorOrAuto, ColorPropertyValue}; pub use self::column::ColumnCount; pub use self::counters::{Content, ContentItem, CounterIncrement, CounterSetOrReset}; pub use self::easing::TimingFunction; diff --git a/components/style/values/specified/color.rs b/components/style/values/specified/color.rs index 00a2033ef2a..25e7af6b98b 100644 --- a/components/style/values/specified/color.rs +++ b/components/style/values/specified/color.rs @@ -373,15 +373,7 @@ impl ToComputedValue for Color { type ComputedValue = ComputedColor; fn to_computed_value(&self, context: &Context) -> ComputedColor { - let result = self.to_computed_color(Some(context)).unwrap(); - if !result.is_numeric() { - if let Some(longhand) = context.for_non_inherited_property { - if longhand.stores_complex_colors_lossily() { - context.rule_cache_conditions.borrow_mut().set_uncacheable(); - } - } - } - result + self.to_computed_color(Some(context)).unwrap() } fn from_computed_value(computed: &ComputedColor) -> Self { @@ -393,37 +385,33 @@ impl ToComputedValue for Color { } } -/// Specified color value, but resolved to just RGBA for computed value -/// with value from color property at the same context. +/// Specified color value for `-moz-font-smoothing-background-color`. +/// +/// This property does not support `currentcolor`. We could drop it at +/// parse-time, but it's not exposed to the web so it doesn't really matter. +/// +/// We resolve it to `transparent` instead. #[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)] -pub struct RGBAColor(pub Color); +pub struct MozFontSmoothingBackgroundColor(pub Color); -impl Parse for RGBAColor { +impl Parse for MozFontSmoothingBackgroundColor { fn parse<'i, 't>( context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - Color::parse(context, input).map(RGBAColor) + Color::parse(context, input).map(MozFontSmoothingBackgroundColor) } } -impl ToComputedValue for RGBAColor { +impl ToComputedValue for MozFontSmoothingBackgroundColor { type ComputedValue = RGBA; fn to_computed_value(&self, context: &Context) -> RGBA { - self.0 - .to_computed_value(context) - .to_rgba(context.style().get_color().clone_color()) + self.0.to_computed_value(context).to_rgba(RGBA::transparent()) } fn from_computed_value(computed: &RGBA) -> Self { - RGBAColor(Color::rgba(*computed)) - } -} - -impl From for RGBAColor { - fn from(color: Color) -> RGBAColor { - RGBAColor(color) + MozFontSmoothingBackgroundColor(Color::rgba(*computed)) } } diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 30f80fd44c2..93f9eca23b6 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -42,7 +42,7 @@ pub use self::box_::{Clear, Float, Overflow, OverflowAnchor}; pub use self::box_::{OverflowClipBox, OverscrollBehavior, Perspective, Resize}; pub use self::box_::{ScrollSnapAlign, ScrollSnapType}; pub use self::box_::{TouchAction, TransitionProperty, VerticalAlign, WillChange}; -pub use self::color::{Color, ColorOrAuto, ColorPropertyValue, RGBAColor}; +pub use self::color::{Color, ColorOrAuto, ColorPropertyValue}; pub use self::column::ColumnCount; pub use self::counters::{Content, ContentItem, CounterIncrement, CounterSetOrReset}; pub use self::easing::TimingFunction;