From c76e382d80150694e1f15106539386be4f32d8d2 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sat, 1 Oct 2016 23:03:18 +0530 Subject: [PATCH] Update glue for StyleComplexColor values --- components/style/gecko_bindings/sugar/mod.rs | 1 + .../sugar/style_complex_color.rs | 47 +++++++ components/style/properties/gecko.mako.rs | 116 +++++++----------- 3 files changed, 90 insertions(+), 74 deletions(-) create mode 100644 components/style/gecko_bindings/sugar/style_complex_color.rs diff --git a/components/style/gecko_bindings/sugar/mod.rs b/components/style/gecko_bindings/sugar/mod.rs index a451d67a06d..7bb7012118c 100644 --- a/components/style/gecko_bindings/sugar/mod.rs +++ b/components/style/gecko_bindings/sugar/mod.rs @@ -7,3 +7,4 @@ mod ns_style_auto_array; pub mod ns_style_coord; mod ns_t_array; pub mod ownership; +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 new file mode 100644 index 00000000000..288d395b1ac --- /dev/null +++ b/components/style/gecko_bindings/sugar/style_complex_color.rs @@ -0,0 +1,47 @@ +/* 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 http://mozilla.org/MPL/2.0/. */ + +use cssparser::Color; +use gecko::values::{convert_nscolor_to_rgba, convert_rgba_to_nscolor}; +use gecko_bindings::structs::{nscolor, StyleComplexColor}; + +impl From for StyleComplexColor { + fn from(other: nscolor) -> Self { + StyleComplexColor { + mColor: other, + mForegroundRatio: 0, + } + } +} + +impl StyleComplexColor { + pub fn current_color() -> Self { + StyleComplexColor { + mColor: 0, + mForegroundRatio: 255, + } + } +} + +impl From for StyleComplexColor { + fn from(other: Color) -> Self { + match other { + Color::RGBA(rgba) => convert_rgba_to_nscolor(&rgba).into(), + Color::CurrentColor => StyleComplexColor::current_color(), + } + } +} + +impl From for Color { + fn from(other: StyleComplexColor) -> Self { + if other.mForegroundRatio == 0 { + Color::RGBA(convert_nscolor_to_rgba(other.mColor)) + } else if other.mForegroundRatio == 255 { + Color::CurrentColor + } else { + // FIXME #13546 handle interpolation values + Color::CurrentColor + } + } +} diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index bd5d2647f51..99f6c0cdda3 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -195,20 +195,20 @@ pub struct ${style_struct.gecko_struct_name} { <%! -def is_border_style_masked(ffi_name): - return ffi_name.split("[")[0] in ["mBorderStyle", "mOutlineStyle", "mTextDecorationStyle"] - -def get_gecko_property(ffi_name): - if is_border_style_masked(ffi_name): - return "(self.gecko.%s & (structs::BORDER_STYLE_MASK as u8))" % ffi_name - return "self.gecko.%s" % ffi_name +def get_gecko_property(ffi_name, self_param = "self"): + if "mBorderColor" in ffi_name: + return ffi_name.replace("mBorderColor", + "unsafe { *%s.gecko.__bindgen_anon_1.mBorderColor.as_ref() }" + % self_param) + return "%s.gecko.%s" % (self_param, ffi_name) def set_gecko_property(ffi_name, expr): - if is_border_style_masked(ffi_name): - return "self.gecko.%s &= !(structs::BORDER_STYLE_MASK as u8);" % ffi_name + \ - "self.gecko.%s |= %s as u8;" % (ffi_name, expr) - elif ffi_name == "__LIST_STYLE_TYPE__": + if ffi_name == "__LIST_STYLE_TYPE__": return "unsafe { Gecko_SetListStyleType(&mut self.gecko, %s as u32); }" % expr + if "mBorderColor" in ffi_name: + ffi_name = ffi_name.replace("mBorderColor", + "*self.gecko.__bindgen_anon_1.mBorderColor.as_mut()") + return "unsafe { %s = %s };" % (ffi_name, expr) return "self.gecko.%s = %s;" % (ffi_name, expr) %> @@ -240,71 +240,41 @@ def set_gecko_property(ffi_name, expr): } -<%def name="clear_color_flags(color_flags_ffi_name)"> - % if color_flags_ffi_name: - self.gecko.${color_flags_ffi_name} &= !(structs::BORDER_COLOR_SPECIAL as u8); - % endif - - -<%def name="set_current_color_flag(color_flags_ffi_name)"> - % if color_flags_ffi_name: - self.gecko.${color_flags_ffi_name} |= structs::BORDER_COLOR_FOREGROUND as u8; - % else: - // FIXME(heycam): This is a Gecko property that doesn't store currentColor - // as a computed value. These are currently handled by converting - // currentColor to the current value of the color property at computed - // value time, but we don't have access to the Color struct here. - // In the longer term, Gecko should store currentColor as a computed - // value, so that we don't need to do this: - // https://bugzilla.mozilla.org/show_bug.cgi?id=760345 - warn!("stylo: mishandling currentColor"); - % endif - - -<%def name="get_current_color_flag_from(field)"> - (${field} & (structs::BORDER_COLOR_FOREGROUND as u8)) != 0 - - -<%def name="impl_color_setter(ident, gecko_ffi_name, color_flags_ffi_name=None)"> +<%def name="impl_color_setter(ident, gecko_ffi_name, complex_color=True)"> #[allow(unreachable_code)] #[allow(non_snake_case)] pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) { - use cssparser::Color; - ${clear_color_flags(color_flags_ffi_name)} - let result = match v { - Color::CurrentColor => { - ${set_current_color_flag(color_flags_ffi_name)} - 0 - }, - Color::RGBA(rgba) => convert_rgba_to_nscolor(&rgba), - }; + % if complex_color: + let result = v.into(); + % else: + use cssparser::Color; + let result = match v { + Color::RGBA(rgba) => convert_rgba_to_nscolor(&rgba), + // FIXME #13547 + Color::CurrentColor => 0, + }; + % endif ${set_gecko_property(gecko_ffi_name, "result")} } -<%def name="impl_color_copy(ident, gecko_ffi_name, color_flags_ffi_name=None)"> +<%def name="impl_color_copy(ident, gecko_ffi_name, complex_color=True)"> #[allow(non_snake_case)] pub fn copy_${ident}_from(&mut self, other: &Self) { - % if color_flags_ffi_name: - ${clear_color_flags(color_flags_ffi_name)} - if ${get_current_color_flag_from("other.gecko." + color_flags_ffi_name)} { - ${set_current_color_flag(color_flags_ffi_name)} - } - % endif - self.gecko.${gecko_ffi_name} = other.gecko.${gecko_ffi_name} + let color = ${get_gecko_property(gecko_ffi_name, self_param = "other")}; + ${set_gecko_property(gecko_ffi_name, "color")}; } -<%def name="impl_color_clone(ident, gecko_ffi_name, color_flags_ffi_name=None)"> +<%def name="impl_color_clone(ident, gecko_ffi_name, complex_color=True)"> #[allow(non_snake_case)] pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T { - use cssparser::Color; - % if color_flags_ffi_name: - if ${get_current_color_flag_from("self.gecko." + color_flags_ffi_name)} { - return Color::CurrentColor - } + % if complex_color: + ${get_gecko_property(gecko_ffi_name)}.into() + % else: + use cssparser::Color; + Color::RGBA(convert_nscolor_to_rgba(${get_gecko_property(gecko_ffi_name)})) % endif - Color::RGBA(convert_nscolor_to_rgba(${get_gecko_property(gecko_ffi_name)})) } @@ -324,11 +294,11 @@ def set_gecko_property(ffi_name, expr): % endif -<%def name="impl_color(ident, gecko_ffi_name, color_flags_ffi_name=None, need_clone=False)"> -<%call expr="impl_color_setter(ident, gecko_ffi_name, color_flags_ffi_name)"> -<%call expr="impl_color_copy(ident, gecko_ffi_name, color_flags_ffi_name)"> +<%def name="impl_color(ident, gecko_ffi_name, need_clone=False, complex_color=True)"> +<%call expr="impl_color_setter(ident, gecko_ffi_name, complex_color)"> +<%call expr="impl_color_copy(ident, gecko_ffi_name, complex_color)"> % if need_clone: - <%call expr="impl_color_clone(ident, gecko_ffi_name, color_flags_ffi_name)"> + <%call expr="impl_color_clone(ident, gecko_ffi_name, complex_color)"> % endif @@ -645,8 +615,7 @@ fn static_assert() { <% impl_keyword("border_%s_style" % side.ident, "mBorderStyle[%s]" % side.index, border_style_keyword, need_clone=True) %> - <% impl_color("border_%s_color" % side.ident, "mBorderColor[%s]" % side.index, - color_flags_ffi_name="mBorderStyle[%s]" % side.index, need_clone=True) %> + <% impl_color("border_%s_color" % side.ident, "(mBorderColor)[%s]" % side.index, need_clone=True) %> <% impl_app_units("border_%s_width" % side.ident, "mComputedBorder.%s" % side.ident, need_clone=True, round_to_pixels=True) %> @@ -752,7 +721,7 @@ fn static_assert() { <% impl_keyword("outline_style", "mOutlineStyle", border_style_keyword, need_clone=True) %> - <% impl_color("outline_color", "mOutlineColor", color_flags_ffi_name="mOutlineStyle", need_clone=True) %> + <% impl_color("outline_color", "mOutlineColor", need_clone=True) %> <% impl_app_units("outline_width", "mActualOutlineWidth", need_clone=True, round_to_pixels=True) %> @@ -1365,7 +1334,7 @@ fn static_assert() { skip_longhands="${skip_background_longhands}" skip_additionals="*"> - <% impl_color("background_color", "mBackgroundColor", need_clone=True) %> + <% impl_color("background_color", "mBackgroundColor", need_clone=True, complex_color=False) %> <% impl_common_image_layer_properties("background") %> @@ -1569,8 +1538,7 @@ fn static_assert() { skip_longhands="text-decoration-color text-decoration-line" skip_additionals="*"> - ${impl_color("text_decoration_color", "mTextDecorationColor", - color_flags_ffi_name="mTextDecorationStyle", need_clone=True)} + ${impl_color("text_decoration_color", "mTextDecorationColor", need_clone=True)} pub fn set_text_decoration_line(&mut self, v: longhands::text_decoration_line::computed_value::T) { let mut bits: u8 = 0; @@ -1614,11 +1582,11 @@ clip-path skip_longhands="${skip_svg_longhands}" skip_additionals="*"> - <% impl_color("flood_color", "mFloodColor") %> + <% impl_color("flood_color", "mFloodColor", complex_color=False) %> - <% impl_color("lighting_color", "mLightingColor") %> + <% impl_color("lighting_color", "mLightingColor", complex_color=False) %> - <% impl_color("stop_color", "mStopColor") %> + <% impl_color("stop_color", "mStopColor", complex_color=False) %> <% impl_common_image_layer_properties("mask") %>