diff --git a/components/style/gecko_bindings/sugar/mod.rs b/components/style/gecko_bindings/sugar/mod.rs index 642b5ad203a..de981bd289a 100644 --- a/components/style/gecko_bindings/sugar/mod.rs +++ b/components/style/gecko_bindings/sugar/mod.rs @@ -15,4 +15,3 @@ mod ns_t_array; pub mod origin_flags; pub mod ownership; pub mod refptr; -mod style_complex_color; diff --git a/components/style/gecko_bindings/sugar/style_complex_color.rs b/components/style/gecko_bindings/sugar/style_complex_color.rs deleted file mode 100644 index de1fad3bbab..00000000000 --- a/components/style/gecko_bindings/sugar/style_complex_color.rs +++ /dev/null @@ -1,111 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ - -//! Rust helpers to interact with Gecko's StyleComplexColor. - -use crate::gecko::values::{convert_nscolor_to_rgba, convert_rgba_to_nscolor}; -use crate::gecko_bindings::structs::StyleComplexColor; -use crate::gecko_bindings::structs::StyleComplexColor_Tag as Tag; -use crate::values::computed::{Color as ComputedColor, ColorOrAuto, RGBAColor as ComputedRGBA}; -use crate::values::generics::color::{ - Color as GenericColor, ColorOrAuto as GenericColorOrAuto, ComplexColorRatios, -}; - -impl StyleComplexColor { - /// Create a `StyleComplexColor` value that represents `currentColor`. - pub fn current_color() -> Self { - StyleComplexColor { - mColor: 0, - mBgRatio: 0., - mFgRatio: 1., - mTag: Tag::eForeground, - } - } - - /// Create a `StyleComplexColor` value that represents `auto`. - pub fn auto() -> Self { - StyleComplexColor { - mColor: 0, - mBgRatio: 0., - mFgRatio: 1., - mTag: Tag::eAuto, - } - } -} - -impl From for StyleComplexColor { - fn from(other: ComputedRGBA) -> Self { - StyleComplexColor { - mColor: convert_rgba_to_nscolor(&other), - mBgRatio: 1., - mFgRatio: 0., - mTag: Tag::eNumeric, - } - } -} - -impl From for StyleComplexColor { - fn from(other: ComputedColor) -> Self { - match other { - GenericColor::Numeric(color) => color.into(), - GenericColor::CurrentColor => Self::current_color(), - GenericColor::Complex { color, ratios } => { - debug_assert!(ratios != ComplexColorRatios::NUMERIC); - debug_assert!(ratios != ComplexColorRatios::FOREGROUND); - StyleComplexColor { - mColor: convert_rgba_to_nscolor(&color).into(), - mBgRatio: ratios.bg, - mFgRatio: ratios.fg, - mTag: Tag::eComplex, - } - }, - } - } -} - -impl From for ComputedColor { - fn from(other: StyleComplexColor) -> Self { - match other.mTag { - Tag::eNumeric => { - debug_assert!(other.mBgRatio == 1. && other.mFgRatio == 0.); - GenericColor::Numeric(convert_nscolor_to_rgba(other.mColor)) - }, - Tag::eForeground => { - debug_assert!(other.mBgRatio == 0. && other.mFgRatio == 1.); - GenericColor::CurrentColor - }, - Tag::eComplex => { - debug_assert!(other.mBgRatio != 1. || other.mFgRatio != 0.); - debug_assert!(other.mBgRatio != 0. || other.mFgRatio != 1.); - GenericColor::Complex { - color: convert_nscolor_to_rgba(other.mColor), - ratios: ComplexColorRatios { - bg: other.mBgRatio, - fg: other.mFgRatio, - }, - } - }, - Tag::eAuto => unreachable!("Unsupport StyleComplexColor with tag eAuto"), - } - } -} - -impl From for StyleComplexColor { - fn from(other: ColorOrAuto) -> Self { - match other { - GenericColorOrAuto::Color(color) => color.into(), - GenericColorOrAuto::Auto => StyleComplexColor::auto(), - } - } -} - -impl From for ColorOrAuto { - fn from(other: StyleComplexColor) -> Self { - if other.mTag != Tag::eAuto { - GenericColorOrAuto::Color(other.into()) - } else { - GenericColorOrAuto::Auto - } - } -} diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 3bb8264bf09..0eaab919110 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -397,34 +397,6 @@ def set_gecko_property(ffi_name, expr): } -<%def name="impl_color_setter(ident, gecko_ffi_name)"> - #[allow(unreachable_code)] - #[allow(non_snake_case)] - pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) { - ${set_gecko_property(gecko_ffi_name, "v.into()")} - } - - -<%def name="impl_color_copy(ident, gecko_ffi_name)"> - #[allow(non_snake_case)] - pub fn copy_${ident}_from(&mut self, other: &Self) { - let color = ${get_gecko_property(gecko_ffi_name, self_param = "other")}; - ${set_gecko_property(gecko_ffi_name, "color")}; - } - - #[allow(non_snake_case)] - pub fn reset_${ident}(&mut self, other: &Self) { - self.copy_${ident}_from(other) - } - - -<%def name="impl_color_clone(ident, gecko_ffi_name)"> - #[allow(non_snake_case)] - pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T { - ${get_gecko_property(gecko_ffi_name)}.into() - } - - <%def name="impl_keyword(ident, gecko_ffi_name, keyword, cast_type='u8', **kwargs)"> <%call expr="impl_keyword_setter(ident, gecko_ffi_name, keyword, cast_type, **kwargs)"> <%call expr="impl_simple_copy(ident, gecko_ffi_name, **kwargs)"> @@ -449,12 +421,6 @@ def set_gecko_property(ffi_name, expr): } -<%def name="impl_color(ident, gecko_ffi_name)"> -<%call expr="impl_color_setter(ident, gecko_ffi_name)"> -<%call expr="impl_color_copy(ident, gecko_ffi_name)"> -<%call expr="impl_color_clone(ident, gecko_ffi_name)"> - - <%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) { @@ -1238,8 +1204,6 @@ impl Clone for ${style_struct.gecko_struct_name} { # Types used with predefined_type()-defined properties that we can auto-generate. predefined_types = { - "Color": impl_color, - "ColorOrAuto": impl_color, "length::LengthOrAuto": impl_style_coord, "length::LengthOrNormal": impl_style_coord, "length::NonNegativeLengthOrAuto": impl_style_coord, @@ -1247,7 +1211,6 @@ impl Clone for ${style_struct.gecko_struct_name} { "Length": impl_absolute_length, "LengthOrNormal": impl_style_coord, "LengthPercentageOrAuto": impl_style_coord, - "MozListReversed": impl_simple, "MozScriptMinSize": impl_absolute_length, "RGBAColor": impl_rgba_color, "SVGLength": impl_svg_length, @@ -1379,7 +1342,7 @@ fn static_assert() { self.gecko.mBorderStyle[${side.index}] } - <% impl_color("border_%s_color" % side.ident, "mBorder%sColor" % side.name) %> + <% impl_simple("border_%s_color" % side.ident, "mBorder%sColor" % side.name) %> <% impl_non_negative_length("border_%s_width" % side.ident, "mComputedBorder.%s" % side.ident, @@ -4386,23 +4349,11 @@ clip-path } -<%self:impl_trait style_struct_name="Color" - skip_longhands="*"> - pub fn set_color(&mut self, v: longhands::color::computed_value::T) { - let result = convert_rgba_to_nscolor(&v); - ${set_gecko_property("mColor", "result")} - } - - <%call expr="impl_simple_copy('color', 'mColor')"> - - pub fn clone_color(&self) -> longhands::color::computed_value::T { - let color = ${get_gecko_property("mColor")} as u32; - convert_nscolor_to_rgba(color) - } +<%self:impl_trait style_struct_name="Color" skip_longhands="color"> + ${impl_rgba_color("color", "mColor")} -<%self:impl_trait style_struct_name="InheritedUI" - skip_longhands="cursor scrollbar-color"> +<%self:impl_trait style_struct_name="InheritedUI" skip_longhands="cursor"> pub fn set_cursor(&mut self, v: longhands::cursor::computed_value::T) { self.gecko.mCursor = v.keyword; unsafe { @@ -4464,48 +4415,6 @@ clip-path longhands::cursor::computed_value::T { images, keyword } } - - pub fn set_scrollbar_color(&mut self, v: longhands::scrollbar_color::computed_value::T) { - use crate::gecko_bindings::structs::StyleComplexColor; - use crate::values::generics::ui::ScrollbarColor; - match v { - ScrollbarColor::Auto => { - self.gecko.mScrollbarFaceColor = StyleComplexColor::auto(); - self.gecko.mScrollbarTrackColor = StyleComplexColor::auto(); - } - ScrollbarColor::Colors { thumb, track } => { - self.gecko.mScrollbarFaceColor = thumb.into(); - self.gecko.mScrollbarTrackColor = track.into(); - } - } - } - - pub fn copy_scrollbar_color_from(&mut self, other: &Self) { - self.gecko.mScrollbarFaceColor = other.gecko.mScrollbarFaceColor; - self.gecko.mScrollbarTrackColor = other.gecko.mScrollbarTrackColor; - } - - pub fn reset_scrollbar_color(&mut self, other: &Self) { - self.copy_scrollbar_color_from(other); - } - - pub fn clone_scrollbar_color(&self) -> longhands::scrollbar_color::computed_value::T { - use crate::gecko_bindings::structs::StyleComplexColor_Tag as Tag; - use crate::values::generics::ui::ScrollbarColor; - debug_assert!( - (self.gecko.mScrollbarFaceColor.mTag == Tag::eAuto) == - (self.gecko.mScrollbarTrackColor.mTag == Tag::eAuto), - "Whether the two colors are `auto` should match", - ); - if self.gecko.mScrollbarFaceColor.mTag == Tag::eAuto { - ScrollbarColor::Auto - } else { - ScrollbarColor::Colors { - thumb: self.gecko.mScrollbarFaceColor.into(), - track: self.gecko.mScrollbarTrackColor.into(), - } - } - } <%self:impl_trait style_struct_name="Column" diff --git a/components/style/values/computed/ui.rs b/components/style/values/computed/ui.rs index 0c37ea4f518..21914995951 100644 --- a/components/style/values/computed/ui.rs +++ b/components/style/values/computed/ui.rs @@ -19,4 +19,4 @@ pub type Cursor = generics::Cursor; pub type CursorImage = generics::CursorImage; /// A computed value for `scrollbar-color` property. -pub type ScrollbarColor = generics::ScrollbarColor; +pub type ScrollbarColor = generics::GenericScrollbarColor; diff --git a/components/style/values/generics/ui.rs b/components/style/values/generics/ui.rs index e6eed9afaa5..294a29d04af 100644 --- a/components/style/values/generics/ui.rs +++ b/components/style/values/generics/ui.rs @@ -86,7 +86,8 @@ impl ToCss for CursorImage { ToCss, ToShmem, )] -pub enum ScrollbarColor { +#[repr(C, u8)] +pub enum GenericScrollbarColor { /// `auto` Auto, /// `{2}` @@ -98,6 +99,8 @@ pub enum ScrollbarColor { }, } +pub use self::GenericScrollbarColor as ScrollbarColor; + impl Default for ScrollbarColor { #[inline] fn default() -> Self {