From 55fc6c831d2df563233c6b157907e483058401cf Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Wed, 27 Apr 2016 02:20:17 -0700 Subject: [PATCH] servo: Merge #10848 - Add Servo_GetStyleFoo functions to get style structs from GeckoComputedValues (from heycam:struct-accessor); r=bholley r?@bholley Source-Repo: https://github.com/servo/servo Source-Revision: e079e01320cf4b0f80c7d6307cf6d53fe7703ec4 --- servo/components/style/properties/data.py | 5 ++-- .../properties/longhand/background.mako.rs | 2 +- .../style/properties/longhand/border.mako.rs | 2 +- .../style/properties/longhand/box.mako.rs | 2 +- .../style/properties/longhand/color.mako.rs | 2 +- .../style/properties/longhand/column.mako.rs | 2 +- .../properties/longhand/counters.mako.rs | 2 +- .../style/properties/longhand/effects.mako.rs | 2 +- .../style/properties/longhand/font.mako.rs | 1 - .../properties/longhand/inherited_box.mako.rs | 2 +- .../longhand/inherited_table.mako.rs | 2 +- .../longhand/inherited_text.mako.rs | 2 +- .../style/properties/longhand/list.mako.rs | 2 +- .../style/properties/longhand/margin.mako.rs | 2 +- .../style/properties/longhand/outline.mako.rs | 1 - .../style/properties/longhand/padding.mako.rs | 2 +- .../properties/longhand/pointing.mako.rs | 2 +- .../properties/longhand/position.mako.rs | 2 +- .../style/properties/longhand/svg.mako.rs | 2 +- .../properties/longhand/svg_inherited.mako.rs | 2 +- .../style/properties/longhand/table.mako.rs | 2 +- .../style/properties/longhand/text.mako.rs | 2 +- .../style/properties/longhand/ui.mako.rs | 13 ++++++++++ .../style/properties/longhand/xul.mako.rs | 12 ++++++++++ .../style/properties/properties.mako.rs | 2 ++ servo/ports/geckolib/glue.rs | 12 +++++----- servo/ports/geckolib/properties.mako.rs | 24 ++++++++++++------- 27 files changed, 71 insertions(+), 37 deletions(-) create mode 100644 servo/components/style/properties/longhand/ui.mako.rs create mode 100644 servo/components/style/properties/longhand/xul.mako.rs diff --git a/servo/components/style/properties/data.py b/servo/components/style/properties/data.py index 14ec494bfba5..d8327955fd5e 100644 --- a/servo/components/style/properties/data.py +++ b/servo/components/style/properties/data.py @@ -98,7 +98,7 @@ class Method(object): class StyleStruct(object): - def __init__(self, name, inherited, gecko_ffi_name=None, additional_methods=None): + def __init__(self, name, inherited, gecko_name=None, additional_methods=None): self.servo_struct_name = "Servo" + name self.gecko_struct_name = "Gecko" + name self.trait_name = name @@ -106,7 +106,8 @@ class StyleStruct(object): self.ident = to_rust_ident(self.trait_name_lower) self.longhands = [] self.inherited = inherited - self.gecko_ffi_name = gecko_ffi_name + self.gecko_name = gecko_name or name + self.gecko_ffi_name = "nsStyle" + self.gecko_name self.additional_methods = additional_methods or [] diff --git a/servo/components/style/properties/longhand/background.mako.rs b/servo/components/style/properties/longhand/background.mako.rs index 65a2e857db79..d2e6a090a3b6 100644 --- a/servo/components/style/properties/longhand/background.mako.rs +++ b/servo/components/style/properties/longhand/background.mako.rs @@ -4,7 +4,7 @@ <%namespace name="helpers" file="/helpers.mako.rs" /> -<% data.new_style_struct("Background", inherited=False, gecko_ffi_name="nsStyleBackground") %> +<% data.new_style_struct("Background", inherited=False) %> ${helpers.predefined_type( "background-color", "CSSColor", "::cssparser::Color::RGBA(::cssparser::RGBA { red: 0., green: 0., blue: 0., alpha: 0. }) /* transparent */")} diff --git a/servo/components/style/properties/longhand/border.mako.rs b/servo/components/style/properties/longhand/border.mako.rs index e36266b2a3c2..b62d1210480b 100644 --- a/servo/components/style/properties/longhand/border.mako.rs +++ b/servo/components/style/properties/longhand/border.mako.rs @@ -5,7 +5,7 @@ <%namespace name="helpers" file="/helpers.mako.rs" /> <% from data import Method %> -<% data.new_style_struct("Border", inherited=False, gecko_ffi_name="nsStyleBorder", +<% data.new_style_struct("Border", inherited=False, additional_methods=[Method("border_" + side + "_has_nonzero_width", "bool") for side in ["top", "right", "bottom", "left"]]) %> diff --git a/servo/components/style/properties/longhand/box.mako.rs b/servo/components/style/properties/longhand/box.mako.rs index ec158c0d9fac..f1e3cfb5be5c 100644 --- a/servo/components/style/properties/longhand/box.mako.rs +++ b/servo/components/style/properties/longhand/box.mako.rs @@ -7,7 +7,7 @@ <% data.new_style_struct("Box", inherited=False, - gecko_ffi_name="nsStyleDisplay", + gecko_name="Display", additional_methods=[Method("transition_count", "usize")]) %> // TODO(SimonSapin): don't parse `inline-table`, since we don't support it diff --git a/servo/components/style/properties/longhand/color.mako.rs b/servo/components/style/properties/longhand/color.mako.rs index dc9555e79991..fa19eab07262 100644 --- a/servo/components/style/properties/longhand/color.mako.rs +++ b/servo/components/style/properties/longhand/color.mako.rs @@ -4,7 +4,7 @@ <%namespace name="helpers" file="/helpers.mako.rs" /> -<% data.new_style_struct("Color", inherited=True, gecko_ffi_name="nsStyleColor") %> +<% data.new_style_struct("Color", inherited=True) %> <%helpers:raw_longhand name="color" need_clone="True"> use cssparser::Color as CSSParserColor; diff --git a/servo/components/style/properties/longhand/column.mako.rs b/servo/components/style/properties/longhand/column.mako.rs index 2e6618e37454..b040b9bd41e7 100644 --- a/servo/components/style/properties/longhand/column.mako.rs +++ b/servo/components/style/properties/longhand/column.mako.rs @@ -4,7 +4,7 @@ <%namespace name="helpers" file="/helpers.mako.rs" /> -<% data.new_style_struct("Column", inherited=False, gecko_ffi_name="nsStyleColumn") %> +<% data.new_style_struct("Column", inherited=False) %> <%helpers:longhand name="column-width" experimental="True"> use cssparser::ToCss; diff --git a/servo/components/style/properties/longhand/counters.mako.rs b/servo/components/style/properties/longhand/counters.mako.rs index 9af2ca8aa9c8..1f881b8e9ce1 100644 --- a/servo/components/style/properties/longhand/counters.mako.rs +++ b/servo/components/style/properties/longhand/counters.mako.rs @@ -4,7 +4,7 @@ <%namespace name="helpers" file="/helpers.mako.rs" /> -<% data.new_style_struct("Counters", inherited=False, gecko_ffi_name="nsStyleContent") %> +<% data.new_style_struct("Counters", inherited=False, gecko_name="Content") %> <%helpers:longhand name="content"> use cssparser::Token; diff --git a/servo/components/style/properties/longhand/effects.mako.rs b/servo/components/style/properties/longhand/effects.mako.rs index 3424debe2b89..0852ef5dd4e4 100644 --- a/servo/components/style/properties/longhand/effects.mako.rs +++ b/servo/components/style/properties/longhand/effects.mako.rs @@ -5,7 +5,7 @@ <%namespace name="helpers" file="/helpers.mako.rs" /> // Box-shadow, etc. -<% data.new_style_struct("Effects", inherited=False, gecko_ffi_name="nsStyleEffects") %> +<% data.new_style_struct("Effects", inherited=False) %> <%helpers:longhand name="opacity"> use cssparser::ToCss; diff --git a/servo/components/style/properties/longhand/font.mako.rs b/servo/components/style/properties/longhand/font.mako.rs index b12acc6ccc7e..59523c5a2a0c 100644 --- a/servo/components/style/properties/longhand/font.mako.rs +++ b/servo/components/style/properties/longhand/font.mako.rs @@ -7,7 +7,6 @@ <% data.new_style_struct("Font", inherited=True, - gecko_ffi_name="nsStyleFont", additional_methods=[Method("compute_font_hash", is_mut=True)]) %> <%helpers:longhand name="font-family"> use self::computed_value::FontFamily; diff --git a/servo/components/style/properties/longhand/inherited_box.mako.rs b/servo/components/style/properties/longhand/inherited_box.mako.rs index 4c8dd202596e..6dc6f05c2e76 100644 --- a/servo/components/style/properties/longhand/inherited_box.mako.rs +++ b/servo/components/style/properties/longhand/inherited_box.mako.rs @@ -4,7 +4,7 @@ <%namespace name="helpers" file="/helpers.mako.rs" /> -<% data.new_style_struct("InheritedBox", inherited=True, gecko_ffi_name="nsStyleVisibility") %> +<% data.new_style_struct("InheritedBox", inherited=True, gecko_name="Visibility") %> ${helpers.single_keyword("direction", "ltr rtl", need_clone=True)} diff --git a/servo/components/style/properties/longhand/inherited_table.mako.rs b/servo/components/style/properties/longhand/inherited_table.mako.rs index 5ec6a2e19820..2a45b2fd43ae 100644 --- a/servo/components/style/properties/longhand/inherited_table.mako.rs +++ b/servo/components/style/properties/longhand/inherited_table.mako.rs @@ -4,7 +4,7 @@ <%namespace name="helpers" file="/helpers.mako.rs" /> -<% data.new_style_struct("InheritedTable", inherited=True, gecko_ffi_name="nsStyleTableBorder") %> +<% data.new_style_struct("InheritedTable", inherited=True, gecko_name="TableBorder") %> ${helpers.single_keyword("border-collapse", "separate collapse", gecko_constant_prefix="NS_STYLE_BORDER")} ${helpers.single_keyword("empty-cells", "show hide", gecko_constant_prefix="NS_STYLE_TABLE_EMPTY_CELLS")} diff --git a/servo/components/style/properties/longhand/inherited_text.mako.rs b/servo/components/style/properties/longhand/inherited_text.mako.rs index 32fef25c68ae..cca68b120f91 100644 --- a/servo/components/style/properties/longhand/inherited_text.mako.rs +++ b/servo/components/style/properties/longhand/inherited_text.mako.rs @@ -4,7 +4,7 @@ <%namespace name="helpers" file="/helpers.mako.rs" /> -<% data.new_style_struct("InheritedText", inherited=True, gecko_ffi_name="nsStyleText") %> +<% data.new_style_struct("InheritedText", inherited=True, gecko_name="Text") %> <%helpers:longhand name="line-height"> use cssparser::ToCss; diff --git a/servo/components/style/properties/longhand/list.mako.rs b/servo/components/style/properties/longhand/list.mako.rs index 764a50617a63..98edb3ab23b7 100644 --- a/servo/components/style/properties/longhand/list.mako.rs +++ b/servo/components/style/properties/longhand/list.mako.rs @@ -4,7 +4,7 @@ <%namespace name="helpers" file="/helpers.mako.rs" /> -<% data.new_style_struct("List", inherited=True, gecko_ffi_name="nsStyleList") %> +<% data.new_style_struct("List", inherited=True) %> ${helpers.single_keyword("list-style-position", "outside inside")} diff --git a/servo/components/style/properties/longhand/margin.mako.rs b/servo/components/style/properties/longhand/margin.mako.rs index 39411f1cff1a..a9e4e477bbd5 100644 --- a/servo/components/style/properties/longhand/margin.mako.rs +++ b/servo/components/style/properties/longhand/margin.mako.rs @@ -4,7 +4,7 @@ <%namespace name="helpers" file="/helpers.mako.rs" /> -<% data.new_style_struct("Margin", inherited=False, gecko_ffi_name="nsStyleMargin") %> +<% data.new_style_struct("Margin", inherited=False) %> % for side in ["top", "right", "bottom", "left"]: ${helpers.predefined_type("margin-" + side, "LengthOrPercentageOrAuto", diff --git a/servo/components/style/properties/longhand/outline.mako.rs b/servo/components/style/properties/longhand/outline.mako.rs index 3df026263b4e..2eab90ce5569 100644 --- a/servo/components/style/properties/longhand/outline.mako.rs +++ b/servo/components/style/properties/longhand/outline.mako.rs @@ -7,7 +7,6 @@ <% data.new_style_struct("Outline", inherited=False, - gecko_ffi_name="nsStyleOutline", additional_methods=[Method("outline_has_nonzero_width", "bool")]) %> // TODO(pcwalton): `invert` diff --git a/servo/components/style/properties/longhand/padding.mako.rs b/servo/components/style/properties/longhand/padding.mako.rs index fda8265e13fe..f5448e393deb 100644 --- a/servo/components/style/properties/longhand/padding.mako.rs +++ b/servo/components/style/properties/longhand/padding.mako.rs @@ -4,7 +4,7 @@ <%namespace name="helpers" file="/helpers.mako.rs" /> -<% data.new_style_struct("Padding", inherited=False, gecko_ffi_name="nsStylePadding") %> +<% data.new_style_struct("Padding", inherited=False) %> % for side in ["top", "right", "bottom", "left"]: ${helpers.predefined_type("padding-" + side, "LengthOrPercentage", diff --git a/servo/components/style/properties/longhand/pointing.mako.rs b/servo/components/style/properties/longhand/pointing.mako.rs index 1d7f4a4040b3..a00b2b8207d6 100644 --- a/servo/components/style/properties/longhand/pointing.mako.rs +++ b/servo/components/style/properties/longhand/pointing.mako.rs @@ -4,7 +4,7 @@ <%namespace name="helpers" file="/helpers.mako.rs" /> -<% data.new_style_struct("Pointing", inherited=True, gecko_ffi_name="nsStyleUserInterface") %> +<% data.new_style_struct("Pointing", inherited=True, gecko_name="UserInterface") %> <%helpers:longhand name="cursor"> pub use self::computed_value::T as SpecifiedValue; diff --git a/servo/components/style/properties/longhand/position.mako.rs b/servo/components/style/properties/longhand/position.mako.rs index b3d35516b794..bd82f09519c5 100644 --- a/servo/components/style/properties/longhand/position.mako.rs +++ b/servo/components/style/properties/longhand/position.mako.rs @@ -4,7 +4,7 @@ <%namespace name="helpers" file="/helpers.mako.rs" /> -<% data.new_style_struct("Position", inherited=False, gecko_ffi_name="nsStylePosition") %> +<% data.new_style_struct("Position", inherited=False) %> % for side in ["top", "right", "bottom", "left"]: ${helpers.predefined_type(side, "LengthOrPercentageOrAuto", diff --git a/servo/components/style/properties/longhand/svg.mako.rs b/servo/components/style/properties/longhand/svg.mako.rs index 759ac3fe2f67..16e884d82270 100644 --- a/servo/components/style/properties/longhand/svg.mako.rs +++ b/servo/components/style/properties/longhand/svg.mako.rs @@ -4,7 +4,7 @@ <%namespace name="helpers" file="/helpers.mako.rs" /> -<% data.new_style_struct("SVG", inherited=False, gecko_ffi_name="nsStyleSVGReset") %> +<% data.new_style_struct("SVG", inherited=False, gecko_name="SVGReset") %> ${helpers.single_keyword("dominant-baseline", """auto use-script no-change reset-size ideographic alphabetic hanging diff --git a/servo/components/style/properties/longhand/svg_inherited.mako.rs b/servo/components/style/properties/longhand/svg_inherited.mako.rs index 2a0c68849740..a2c2be61fb48 100644 --- a/servo/components/style/properties/longhand/svg_inherited.mako.rs +++ b/servo/components/style/properties/longhand/svg_inherited.mako.rs @@ -8,7 +8,7 @@ // https://www.w3.org/TR/SVG/ <% data.new_style_struct("SVGInherited", inherited=True, - gecko_ffi_name="nsStyleSVG") %> + gecko_name="SVG") %> // Section 10 - Text diff --git a/servo/components/style/properties/longhand/table.mako.rs b/servo/components/style/properties/longhand/table.mako.rs index 0abe7b2ce1a0..cfb3050c06d4 100644 --- a/servo/components/style/properties/longhand/table.mako.rs +++ b/servo/components/style/properties/longhand/table.mako.rs @@ -4,6 +4,6 @@ <%namespace name="helpers" file="/helpers.mako.rs" /> -<% data.new_style_struct("Table", inherited=False, gecko_ffi_name="nsStyleTable") %> +<% data.new_style_struct("Table", inherited=False) %> ${helpers.single_keyword("table-layout", "auto fixed", gecko_ffi_name="mLayoutStrategy")} diff --git a/servo/components/style/properties/longhand/text.mako.rs b/servo/components/style/properties/longhand/text.mako.rs index b6d30dd01316..1fedba7d6cc6 100644 --- a/servo/components/style/properties/longhand/text.mako.rs +++ b/servo/components/style/properties/longhand/text.mako.rs @@ -7,7 +7,7 @@ <% data.new_style_struct("Text", inherited=False, - gecko_ffi_name="nsStyleTextReset", + gecko_name="TextReset", additional_methods=[Method("has_underline", "bool"), Method("has_overline", "bool"), Method("has_line_through", "bool")]) %> diff --git a/servo/components/style/properties/longhand/ui.mako.rs b/servo/components/style/properties/longhand/ui.mako.rs new file mode 100644 index 000000000000..cb86d43bc2b4 --- /dev/null +++ b/servo/components/style/properties/longhand/ui.mako.rs @@ -0,0 +1,13 @@ +/* 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/. */ + +<%namespace name="helpers" file="/helpers.mako.rs" /> +<% from data import Method %> + +// CSS Basic User Interface Module Level 1 +// https://drafts.csswg.org/css-ui-3/ +<% data.new_style_struct("UI", inherited=False, gecko_name="UIReset") %> + +${helpers.single_keyword("ime-mode", "normal auto active disabled inactive", products="gecko", + gecko_ffi_name="mIMEMode")} diff --git a/servo/components/style/properties/longhand/xul.mako.rs b/servo/components/style/properties/longhand/xul.mako.rs new file mode 100644 index 000000000000..84e874849eb4 --- /dev/null +++ b/servo/components/style/properties/longhand/xul.mako.rs @@ -0,0 +1,12 @@ +/* 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/. */ + +<%namespace name="helpers" file="/helpers.mako.rs" /> +<% from data import Method %> + +// Non-standard properties that Gecko uses for XUL elements. +<% data.new_style_struct("XUL", inherited=False) %> + +${helpers.single_keyword("-moz-box-align", "stretch start center baseline end", products="gecko", + gecko_ffi_name="mBoxAlign", gecko_constant_prefix="NS_STYLE_BOX_ALIGN")} diff --git a/servo/components/style/properties/properties.mako.rs b/servo/components/style/properties/properties.mako.rs index ab71f3047aab..c49e210567bd 100644 --- a/servo/components/style/properties/properties.mako.rs +++ b/servo/components/style/properties/properties.mako.rs @@ -66,8 +66,10 @@ pub mod longhands { <%include file="/longhand/position.mako.rs" /> <%include file="/longhand/table.mako.rs" /> <%include file="/longhand/text.mako.rs" /> + <%include file="/longhand/ui.mako.rs" /> <%include file="/longhand/svg_inherited.mako.rs" /> <%include file="/longhand/svg.mako.rs" /> + <%include file="/longhand/xul.mako.rs" /> } diff --git a/servo/ports/geckolib/glue.rs b/servo/ports/geckolib/glue.rs index be5263ef430b..8a3294afc554 100644 --- a/servo/ports/geckolib/glue.rs +++ b/servo/ports/geckolib/glue.rs @@ -92,29 +92,29 @@ pub extern "C" fn Servo_StylesheetFromUTF8Bytes(bytes: *const u8, } } -struct ArcHelpers { +pub struct ArcHelpers { phantom1: PhantomData, phantom2: PhantomData, } impl ArcHelpers { - fn with(raw: *mut GeckoType, cb: F) -> Output - where F: FnOnce(&Arc) -> Output { + pub fn with(raw: *mut GeckoType, cb: F) -> Output + where F: FnOnce(&Arc) -> Output { let owned = unsafe { Self::into(raw) }; let result = cb(&owned); forget(owned); result } - unsafe fn into(ptr: *mut GeckoType) -> Arc { + pub unsafe fn into(ptr: *mut GeckoType) -> Arc { transmute(ptr) } - unsafe fn addref(ptr: *mut GeckoType) { + pub unsafe fn addref(ptr: *mut GeckoType) { Self::with(ptr, |arc| forget(arc.clone())); } - unsafe fn release(ptr: *mut GeckoType) { + pub unsafe fn release(ptr: *mut GeckoType) { let _ = Self::into(ptr); } } diff --git a/servo/ports/geckolib/properties.mako.rs b/servo/ports/geckolib/properties.mako.rs index ae7e9469aa6e..8bfe9cba5f64 100644 --- a/servo/ports/geckolib/properties.mako.rs +++ b/servo/ports/geckolib/properties.mako.rs @@ -11,14 +11,13 @@ use app_units::Au; % for style_struct in data.style_structs: -%if style_struct.gecko_ffi_name: use gecko_style_structs::${style_struct.gecko_ffi_name}; use bindings::Gecko_Construct_${style_struct.gecko_ffi_name}; use bindings::Gecko_CopyConstruct_${style_struct.gecko_ffi_name}; use bindings::Gecko_Destroy_${style_struct.gecko_ffi_name}; -% endif % endfor use gecko_style_structs; +use glue::ArcHelpers; use heapsize::HeapSizeOf; use std::fmt::{self, Debug}; use std::mem::{transmute, zeroed}; @@ -103,13 +102,9 @@ impl ComputedValues for GeckoComputedValues { <%def name="declare_style_struct(style_struct)"> #[derive(Clone, HeapSizeOf, Debug)] -% if style_struct.gecko_ffi_name: pub struct ${style_struct.gecko_struct_name} { gecko: ${style_struct.gecko_ffi_name}, } -% else: -pub struct ${style_struct.gecko_struct_name}; -% endif <%def name="impl_simple_copy(ident, gecko_ffi_name)"> @@ -192,8 +187,10 @@ impl ${style_struct.gecko_struct_name} { } result } + pub fn get_gecko(&self) -> &${style_struct.gecko_ffi_name} { + &self.gecko + } } -%if style_struct.gecko_ffi_name: impl Drop for ${style_struct.gecko_struct_name} { fn drop(&mut self) { unsafe { @@ -227,7 +224,6 @@ impl Debug for ${style_struct.gecko_ffi_name} { } } %endif -%endif <%def name="raw_impl_trait(style_struct, skip_longhands='', skip_additionals='')"> @@ -406,12 +402,24 @@ for side in SIDES: +<%def name="define_ffi_struct_accessor(style_struct)"> +#[no_mangle] +#[allow(non_snake_case, unused_variables)] +pub extern "C" fn Servo_GetStyle${style_struct.gecko_name}(computed_values: *mut ServoComputedValues) + -> *const ${style_struct.gecko_ffi_name} { + type Helpers = ArcHelpers; + Helpers::with(computed_values, |values| values.get_${style_struct.trait_name_lower}().get_gecko() + as *const ${style_struct.gecko_ffi_name}) +} + + % for style_struct in data.style_structs: ${declare_style_struct(style_struct)} ${impl_style_struct(style_struct)} % if not style_struct.trait_name in data.manual_style_structs: <%self:raw_impl_trait style_struct="${style_struct}"> % endif +${define_ffi_struct_accessor(style_struct)} % endfor lazy_static! {