From f195b247c0caeef68fddd851446eac1ee857db68 Mon Sep 17 00:00:00 2001 From: Stefano Chiodino Date: Thu, 9 Mar 2017 13:51:04 +0000 Subject: [PATCH] #15842 Add gecko glue for caret-color. Implement from(StyleComplexColor) for ColorOrAuto. Thanks @emilio. (+4 squashed commits) Squashed commits: [baf7cc0] Add clone to caret-color [9cb82ca] Correctly call methods to copy a color in a SympleComplexColor and getting its auto [c483f07] Add set and copy functions for caret_color [0aa20be] Move caret-color and set its product property to gecko --- .../sugar/style_complex_color.rs | 25 ++++++++++++++++--- components/style/properties/gecko.mako.rs | 24 ++++++++++++++++-- .../properties/longhand/pointing.mako.rs | 7 ++++++ .../style/properties/longhand/ui.mako.rs | 7 ------ 4 files changed, 50 insertions(+), 13 deletions(-) diff --git a/components/style/gecko_bindings/sugar/style_complex_color.rs b/components/style/gecko_bindings/sugar/style_complex_color.rs index cd861b1c0bc..47d9046e874 100644 --- a/components/style/gecko_bindings/sugar/style_complex_color.rs +++ b/components/style/gecko_bindings/sugar/style_complex_color.rs @@ -4,9 +4,10 @@ //! Rust helpers to interact with Gecko's StyleComplexColor. -use cssparser::Color; +use cssparser; use gecko::values::{convert_nscolor_to_rgba, convert_rgba_to_nscolor}; use gecko_bindings::structs::{nscolor, StyleComplexColor}; +use values; impl From for StyleComplexColor { fn from(other: nscolor) -> Self { @@ -38,8 +39,10 @@ impl StyleComplexColor { } } -impl From for StyleComplexColor { - fn from(other: Color) -> Self { +impl From for StyleComplexColor { + fn from(other: cssparser::Color) -> Self { + use cssparser::Color; + match other { Color::RGBA(rgba) => convert_rgba_to_nscolor(&rgba).into(), Color::CurrentColor => StyleComplexColor::current_color(), @@ -47,8 +50,22 @@ impl From for StyleComplexColor { } } -impl From for Color { +impl From for values::computed::ColorOrAuto { + fn from(color: StyleComplexColor) -> Self { + use values::{Auto, Either}; + + if color.mIsAuto { + return Either::Second(Auto); + } + + Either::First(color.into()) + } +} + +impl From for cssparser::Color { fn from(other: StyleComplexColor) -> Self { + use cssparser::Color; + if other.mForegroundRatio == 0 { Color::RGBA(convert_nscolor_to_rgba(other.mColor)) } else if other.mForegroundRatio == 255 { diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 8d6ceeeb59c..b14f243b949 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -43,7 +43,7 @@ use gecko_bindings::bindings::Gecko_SetNullImageValue; use gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull; use gecko_bindings::bindings::{Gecko_ResetFilters, Gecko_CopyFiltersFrom}; use gecko_bindings::bindings::RawGeckoPresContextBorrowed; -use gecko_bindings::structs; +use gecko_bindings::structs::{self, StyleComplexColor}; use gecko_bindings::structs::nsStyleVariables; use gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordData, CoordDataMut}; use gecko_bindings::sugar::ownership::HasArcFFI; @@ -3095,7 +3095,7 @@ clip-path <%self:impl_trait style_struct_name="Pointing" - skip_longhands="cursor"> + skip_longhands="cursor caret-color"> pub fn set_cursor(&mut self, v: longhands::cursor::computed_value::T) { use properties::longhands::cursor::computed_value::Keyword; use style_traits::cursor::Cursor; @@ -3162,6 +3162,26 @@ clip-path Gecko_CopyCursorArrayFrom(&mut self.gecko, &other.gecko); } } + + pub fn set_caret_color(&mut self, v: longhands::caret_color::computed_value::T){ + use values::Either; + + match v { + Either::First(color) => { + self.gecko.mCaretColor = StyleComplexColor::from(color); + } + Either::Second(_auto) => { + self.gecko.mCaretColor = StyleComplexColor::auto(); + } + } + } + + pub fn copy_caret_color_from(&mut self, other: &Self){ + self.gecko.mCaretColor = other.gecko.mCaretColor; + } + + <%call expr="impl_color_clone('caret_color', 'mCaretColor')"> + <%self:impl_trait style_struct_name="Column" diff --git a/components/style/properties/longhand/pointing.mako.rs b/components/style/properties/longhand/pointing.mako.rs index b661ec457eb..e3f00d333f9 100644 --- a/components/style/properties/longhand/pointing.mako.rs +++ b/components/style/properties/longhand/pointing.mako.rs @@ -170,3 +170,10 @@ ${helpers.single_keyword("-moz-user-focus", gecko_inexhaustive=True, animatable=False, spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-user-focus)")} + +${helpers.predefined_type("caret-color", + "ColorOrAuto", + "Either::Second(Auto)", + spec="https://drafts.csswg.org/css-ui/#caret-color", + animatable="True", + products="gecko")} diff --git a/components/style/properties/longhand/ui.mako.rs b/components/style/properties/longhand/ui.mako.rs index b6d7bcd11e4..391bb291a30 100644 --- a/components/style/properties/longhand/ui.mako.rs +++ b/components/style/properties/longhand/ui.mako.rs @@ -30,10 +30,3 @@ ${helpers.single_keyword("-moz-window-dragging", "default drag no-drag", product gecko_enum_prefix="StyleWindowDragging", animatable=False, spec="None (Nonstandard Firefox-only property)")} - -${helpers.predefined_type("caret-color", - "ColorOrAuto", - "Either::Second(Auto)", - spec="https://drafts.csswg.org/css-ui/#caret-color", - animatable="True", - products="none")}