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
This commit is contained in:
Cameron McCormack 2016-04-27 02:20:17 -07:00
Родитель 497a8b7fd3
Коммит 55fc6c831d
27 изменённых файлов: 71 добавлений и 37 удалений

Просмотреть файл

@ -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 []

Просмотреть файл

@ -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 */")}

Просмотреть файл

@ -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"]]) %>

Просмотреть файл

@ -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

Просмотреть файл

@ -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;

Просмотреть файл

@ -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;

Просмотреть файл

@ -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;

Просмотреть файл

@ -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;

Просмотреть файл

@ -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;

Просмотреть файл

@ -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)}

Просмотреть файл

@ -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")}

Просмотреть файл

@ -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;

Просмотреть файл

@ -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")}

Просмотреть файл

@ -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",

Просмотреть файл

@ -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`

Просмотреть файл

@ -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",

Просмотреть файл

@ -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;

Просмотреть файл

@ -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",

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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")}

Просмотреть файл

@ -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")]) %>

Просмотреть файл

@ -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")}

Просмотреть файл

@ -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")}

Просмотреть файл

@ -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" />
}

Просмотреть файл

@ -92,29 +92,29 @@ pub extern "C" fn Servo_StylesheetFromUTF8Bytes(bytes: *const u8,
}
}
struct ArcHelpers<GeckoType, ServoType> {
pub struct ArcHelpers<GeckoType, ServoType> {
phantom1: PhantomData<GeckoType>,
phantom2: PhantomData<ServoType>,
}
impl<GeckoType, ServoType> ArcHelpers<GeckoType, ServoType> {
fn with<F, Output>(raw: *mut GeckoType, cb: F) -> Output
where F: FnOnce(&Arc<ServoType>) -> Output {
pub fn with<F, Output>(raw: *mut GeckoType, cb: F) -> Output
where F: FnOnce(&Arc<ServoType>) -> Output {
let owned = unsafe { Self::into(raw) };
let result = cb(&owned);
forget(owned);
result
}
unsafe fn into(ptr: *mut GeckoType) -> Arc<ServoType> {
pub unsafe fn into(ptr: *mut GeckoType) -> Arc<ServoType> {
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);
}
}

Просмотреть файл

@ -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>
<%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>
<%def name="raw_impl_trait(style_struct, skip_longhands='', skip_additionals='')">
@ -406,12 +402,24 @@ for side in SIDES:
</%self:impl_trait>
<%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<ServoComputedValues, GeckoComputedValues>;
Helpers::with(computed_values, |values| values.get_${style_struct.trait_name_lower}().get_gecko()
as *const ${style_struct.gecko_ffi_name})
}
</%def>
% 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}"></%self:raw_impl_trait>
% endif
${define_ffi_struct_accessor(style_struct)}
% endfor
lazy_static! {