Auto merge of #10697 - bholley:need_clone, r=SimonSapin

Implement enough of geckolib to cascade the first node

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10697)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-04-22 12:56:13 -07:00
commit c372dee6ca
9 changed files with 1091 additions and 552 deletions

View file

@ -20,7 +20,7 @@ class Keyword(object):
def __init__(self, name, values, gecko_constant_prefix=None,
extra_gecko_values=None, extra_servo_values=None):
self.name = name
self.values = values
self.values = values.split()
self.gecko_constant_prefix = gecko_constant_prefix or \
"NS_STYLE_" + self.name.upper().replace("-", "_")
self.extra_gecko_values = (extra_gecko_values or "").split()
@ -41,13 +41,13 @@ class Keyword(object):
raise Exception("Bad product: " + product)
def gecko_constant(self, value):
return self.gecko_constant_prefix + "_" + value.upper().replace("-", "_")
return self.gecko_constant_prefix + "_" + value.replace("-moz-", "").replace("-", "_").upper()
class Longhand(object):
def __init__(self, style_struct, name, derived_from=None, keyword=None,
custom_cascade=False, experimental=False, internal=False,
gecko_ffi_name=None):
need_clone=False, gecko_ffi_name=None):
self.name = name
self.keyword = keyword
self.ident = to_rust_ident(name)
@ -56,6 +56,7 @@ class Longhand(object):
self.experimental = ("layout.%s.enabled" % name) if experimental else None
self.custom_cascade = custom_cascade
self.internal = internal
self.need_clone = need_clone
self.gecko_ffi_name = gecko_ffi_name or "m" + self.camel_case
self.derived_from = (derived_from or "").split()

View file

@ -16,8 +16,8 @@
</%call>
</%def>
<%def name="predefined_type(name, type, initial_value, parse_method='parse', products='gecko servo')">
<%self:longhand name="${name}" products="${products}">
<%def name="predefined_type(name, type, initial_value, parse_method='parse', **kwargs)">
<%call expr="longhand(name, **kwargs)">
#[allow(unused_imports)]
use app_units::Au;
pub type SpecifiedValue = specified::${type};
@ -29,7 +29,7 @@
-> Result<SpecifiedValue, ()> {
specified::${type}::${parse_method}(input)
}
</%self:longhand>
</%call>
</%def>
<%def name="raw_longhand(*args, **kwargs)">
@ -170,7 +170,7 @@
'gecko_constant_prefix', 'extra_gecko_values', 'extra_servo_values'
]}
%>
<%call expr="longhand(name, keyword=Keyword(name, values.split(), **keyword_kwargs), **kwargs)">
<%call expr="longhand(name, keyword=Keyword(name, values, **keyword_kwargs), **kwargs)">
pub use self::computed_value::T as SpecifiedValue;
${caller.body()}
pub mod computed_value {

View file

@ -7,7 +7,7 @@
<% from data import Method %>
<% data.new_style_struct("Border", inherited=False, gecko_ffi_name="nsStyleBorder",
additional_methods=[Method("border_" + side + "_is_none_or_hidden_and_has_nonzero_width",
additional_methods=[Method("border_" + side + "_has_nonzero_width",
"bool") for side in ["top", "right", "bottom", "left"]]) %>
% for side in ["top", "right", "bottom", "left"]:
@ -15,7 +15,7 @@
% endfor
% for side in ["top", "right", "bottom", "left"]:
${helpers.predefined_type("border-%s-style" % side, "BorderStyle", "specified::BorderStyle::none")}
${helpers.predefined_type("border-%s-style" % side, "BorderStyle", "specified::BorderStyle::none", need_clone=True)}
% endfor
% for side in ["top", "right", "bottom", "left"]:

View file

@ -9,15 +9,10 @@
<% data.new_style_struct("Box",
inherited=False,
gecko_ffi_name="nsStyleDisplay",
additional_methods=[Method("clone_display", "longhands::display::computed_value::T"),
Method("clone_position", "longhands::position::computed_value::T"),
Method("is_floated", "bool"),
Method("overflow_x_is_visible", "bool"),
Method("overflow_y_is_visible", "bool"),
Method("transition_count", "usize")]) %>
additional_methods=[Method("transition_count", "usize")]) %>
// TODO(SimonSapin): don't parse `inline-table`, since we don't support it
<%helpers:longhand name="display" custom_cascade="${product == 'servo'}">
<%helpers:longhand name="display" need_clone="True" custom_cascade="${product == 'servo'}">
<%
values = """inline block inline-block
table inline-table table-row-group table-header-group table-footer-group
@ -89,9 +84,9 @@
</%helpers:longhand>
${helpers.single_keyword("position", "static absolute relative fixed", extra_gecko_values="sticky")}
${helpers.single_keyword("position", "static absolute relative fixed", need_clone=True, extra_gecko_values="sticky")}
<%helpers:single_keyword_computed name="float" values="none left right" gecko_ffi_name="mFloats">
<%helpers:single_keyword_computed name="float" values="none left right" need_clone="True" gecko_ffi_name="mFloats">
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;

View file

@ -9,12 +9,12 @@
<% data.new_style_struct("Outline",
inherited=False,
gecko_ffi_name="nsStyleOutline",
additional_methods=[Method("outline_is_none_or_hidden_and_has_nonzero_width", "bool")]) %>
additional_methods=[Method("outline_has_nonzero_width", "bool")]) %>
// TODO(pcwalton): `invert`
${helpers.predefined_type("outline-color", "CSSColor", "::cssparser::Color::CurrentColor")}
<%helpers:longhand name="outline-style">
<%helpers:longhand name="outline-style" need_clone="True">
pub use values::specified::BorderStyle as SpecifiedValue;
pub fn get_initial_value() -> SpecifiedValue { SpecifiedValue::none }
pub mod computed_value {

View file

@ -54,15 +54,9 @@ pub mod longhands {
<%include file="/longhand/padding.mako.rs" />
<%include file="/longhand/position.mako.rs" />
<% data.new_style_struct("InheritedBox", inherited=True, gecko_ffi_name="nsStyleVisibility",
additional_methods=[Method("clone_direction",
"longhands::direction::computed_value::T"),
Method("clone_writing_mode",
"longhands::writing_mode::computed_value::T"),
Method("clone_text_orientation",
"longhands::text_orientation::computed_value::T")]) %>
<% data.new_style_struct("InheritedBox", inherited=True, gecko_ffi_name="nsStyleVisibility") %>
${helpers.single_keyword("direction", "ltr rtl")}
${helpers.single_keyword("direction", "ltr rtl", need_clone=True)}
// CSS 2.1, Section 10 - Visual formatting model details
@ -92,10 +86,7 @@ pub mod longhands {
"computed::LengthOrPercentageOrNone::None",
"parse_non_negative")}
<% data.new_style_struct("InheritedText", inherited=True, gecko_ffi_name="nsStyleText",
additional_methods=([Method("clone__servo_text_decorations_in_effect",
"longhands::_servo_text_decorations_in_effect::computed_value::T")]
if product == "servo" else [])) %>
<% data.new_style_struct("InheritedText", inherited=True, gecko_ffi_name="nsStyleText") %>
<%helpers:longhand name="line-height">
use cssparser::ToCss;
@ -286,10 +277,11 @@ pub mod longhands {
internal=True)}
// FIXME(pcwalton, #2742): Implement scrolling for `scroll` and `auto`.
${helpers.single_keyword("overflow-x", "visible hidden scroll auto", gecko_constant_prefix="NS_STYLE_OVERFLOW")}
${helpers.single_keyword("overflow-x", "visible hidden scroll auto", need_clone=True,
gecko_constant_prefix="NS_STYLE_OVERFLOW")}
// FIXME(pcwalton, #2742): Implement scrolling for `scroll` and `auto`.
<%helpers:longhand name="overflow-y">
<%helpers:longhand name="overflow-y" need_clone="True">
use super::overflow_x;
use cssparser::ToCss;
@ -1076,11 +1068,9 @@ pub mod longhands {
}
</%helpers:longhand>
<% data.new_style_struct("Color", inherited=True, gecko_ffi_name="nsStyleColor",
additional_methods=[Method("clone_color",
"longhands::color::computed_value::T")]) %>
<% data.new_style_struct("Color", inherited=True, gecko_ffi_name="nsStyleColor") %>
<%helpers:raw_longhand name="color">
<%helpers:raw_longhand name="color" need_clone="True">
use cssparser::Color as CSSParserColor;
use cssparser::RGBA;
use values::specified::{CSSColor, CSSRGBA};
@ -1119,12 +1109,7 @@ pub mod longhands {
// CSS 2.1, Section 15 - Fonts
<% data.new_style_struct("Font", inherited=True, gecko_ffi_name="nsStyleFont",
additional_methods=[Method("clone_font_size",
"longhands::font_size::computed_value::T"),
Method("clone_font_weight",
"longhands::font_weight::computed_value::T"),
Method("compute_font_hash", is_mut=True)]) %>
additional_methods=[Method("compute_font_hash", is_mut=True)]) %>
<%helpers:longhand name="font-family">
use self::computed_value::FontFamily;
use values::computed::ComputedValueAsSpecified;
@ -1238,7 +1223,7 @@ pub mod longhands {
${helpers.single_keyword("font-style", "normal italic oblique")}
${helpers.single_keyword("font-variant", "normal small-caps")}
<%helpers:longhand name="font-weight">
<%helpers:longhand name="font-weight" need_clone="True">
use cssparser::ToCss;
use std::fmt;
@ -1356,7 +1341,7 @@ pub mod longhands {
}
</%helpers:longhand>
<%helpers:longhand name="font-size">
<%helpers:longhand name="font-size" need_clone="True">
use app_units::Au;
use cssparser::ToCss;
use std::fmt;
@ -1724,7 +1709,7 @@ pub mod longhands {
<% data.switch_to_style_struct("InheritedText") %>
<%helpers:longhand name="-servo-text-decorations-in-effect"
derived_from="display text-decoration" products="servo">
derived_from="display text-decoration" need_clone="True" products="servo">
use cssparser::{RGBA, ToCss};
use std::fmt;
@ -1970,11 +1955,16 @@ pub mod longhands {
// http://dev.w3.org/csswg/css-writing-modes/
<% data.switch_to_style_struct("InheritedBox") %>
${helpers.single_keyword("writing-mode", "horizontal-tb vertical-rl vertical-lr", experimental=True)}
${helpers.single_keyword("writing-mode", "horizontal-tb vertical-rl vertical-lr",
experimental=True, need_clone=True)}
// FIXME(SimonSapin): Add 'mixed' and 'upright' (needs vertical text support)
// FIXME(SimonSapin): initial (first) value should be 'mixed', when that's implemented
${helpers.single_keyword("text-orientation", "sideways sideways-left sideways-right", experimental=True)}
// FIXME(bholley): sideways-right is needed as an alias to sideways in gecko.
${helpers.single_keyword("text-orientation", "sideways",
experimental=True, need_clone=True,
extra_gecko_values="mixed upright",
extra_servo_values="sideways-right sideways-left")}
// CSS Color Module Level 4
// https://drafts.csswg.org/css-color/
@ -5678,6 +5668,10 @@ pub mod style_struct_traits {
fn set_${longhand.ident}(&mut self, v: longhands::${longhand.ident}::computed_value::T);
#[allow(non_snake_case)]
fn copy_${longhand.ident}_from(&mut self, other: &Self);
% if longhand.need_clone:
#[allow(non_snake_case)]
fn clone_${longhand.ident}(&self) -> longhands::${longhand.ident}::computed_value::T;
% endif
% endfor
% for additional in style_struct.additional_methods:
#[allow(non_snake_case)]
@ -5729,8 +5723,10 @@ pub mod style_structs {
% endfor
% if style_struct.trait_name == "Border":
% for side in ["top", "right", "bottom", "left"]:
fn border_${side}_is_none_or_hidden_and_has_nonzero_width(&self) -> bool {
self.border_${side}_style.none_or_hidden() &&
fn clone_border_${side}_style(&self) -> longhands::border_${side}_style::computed_value::T {
self.border_${side}_style.clone()
}
fn border_${side}_has_nonzero_width(&self) -> bool {
self.border_${side}_width != ::app_units::Au(0)
}
% endfor
@ -5741,14 +5737,14 @@ pub mod style_structs {
fn clone_position(&self) -> longhands::position::computed_value::T {
self.position.clone()
}
fn is_floated(&self) -> bool {
self.float != longhands::float::SpecifiedValue::none
fn clone_float(&self) -> longhands::float::computed_value::T {
self.float.clone()
}
fn overflow_x_is_visible(&self) -> bool {
self.overflow_x == longhands::overflow_x::computed_value::T::visible
fn clone_overflow_x(&self) -> longhands::overflow_x::computed_value::T {
self.overflow_x.clone()
}
fn overflow_y_is_visible(&self) -> bool {
self.overflow_y.0 == longhands::overflow_x::computed_value::T::visible
fn clone_overflow_y(&self) -> longhands::overflow_y::computed_value::T {
self.overflow_y.clone()
}
fn transition_count(&self) -> usize {
self.transition_property.0.len()
@ -5788,8 +5784,11 @@ pub mod style_structs {
self._servo_text_decorations_in_effect.clone()
}
% elif style_struct.trait_name == "Outline":
fn outline_is_none_or_hidden_and_has_nonzero_width(&self) -> bool {
self.outline_style.none_or_hidden() && self.outline_width != ::app_units::Au(0)
fn clone_outline_style(&self) -> longhands::outline_style::computed_value::T {
self.outline_style.clone()
}
fn outline_has_nonzero_width(&self) -> bool {
self.outline_width != ::app_units::Au(0)
}
% elif style_struct.trait_name == "Text":
fn has_underline(&self) -> bool {
@ -6131,10 +6130,17 @@ pub fn get_writing_mode<S: style_struct_traits::InheritedBox>(inheritedbox_style
},
}
match inheritedbox_style.clone_text_orientation() {
% if product == "servo":
computed_values::text_orientation::T::sideways_right => {},
computed_values::text_orientation::T::sideways_left => {
flags.insert(logical_geometry::FLAG_VERTICAL_LR);
},
% elif product == "gecko":
// FIXME(bholley): Need to make sure these are correct when we add
// full writing-mode support.
computed_values::text_orientation::T::mixed => {},
computed_values::text_orientation::T::upright => {},
% endif
computed_values::text_orientation::T::sideways => {
if flags.intersects(logical_geometry::FLAG_VERTICAL_LR) {
flags.insert(logical_geometry::FLAG_SIDEWAYS_LEFT);
@ -6448,7 +6454,7 @@ pub fn cascade<C: ComputedValues>(
let positioned = matches!(style.get_box().clone_position(),
longhands::position::SpecifiedValue::absolute |
longhands::position::SpecifiedValue::fixed);
let floated = style.get_box().is_floated();
let floated = style.get_box().clone_float() != longhands::float::SpecifiedValue::none;
if positioned || floated || is_root_element {
use computed_values::display::T;
@ -6482,7 +6488,8 @@ pub fn cascade<C: ComputedValues>(
{
use computed_values::overflow_x::T as overflow;
use computed_values::overflow_y;
match (style.get_box().overflow_x_is_visible(), style.get_box().overflow_y_is_visible()) {
match (style.get_box().clone_overflow_x() == longhands::overflow_x::computed_value::T::visible,
style.get_box().clone_overflow_y().0 == longhands::overflow_x::computed_value::T::visible) {
(true, true) => {}
(true, _) => {
style.mutate_box().set_overflow_x(overflow::auto);
@ -6497,13 +6504,15 @@ pub fn cascade<C: ComputedValues>(
// The initial value of border-*-width may be changed at computed value time.
% for side in ["top", "right", "bottom", "left"]:
// Like calling to_computed_value, which wouldn't type check.
if style.get_border().border_${side}_is_none_or_hidden_and_has_nonzero_width() {
if style.get_border().clone_border_${side}_style().none_or_hidden() &&
style.get_border().border_${side}_has_nonzero_width() {
style.mutate_border().set_border_${side}_width(Au(0));
}
% endfor
// The initial value of outline width may be changed at computed value time.
if style.get_outline().outline_is_none_or_hidden_and_has_nonzero_width() {
if style.get_outline().clone_outline_style().none_or_hidden() &&
style.get_outline().outline_has_nonzero_width() {
style.mutate_outline().set_outline_width(Au(0));
}

File diff suppressed because it is too large Load diff

View file

@ -6,6 +6,7 @@
<%!
from data import to_rust_ident
from data import Keyword
%>
use app_units::Au;
@ -20,7 +21,7 @@ use bindings::Gecko_Destroy_${style_struct.gecko_ffi_name};
use gecko_style_structs;
use heapsize::HeapSizeOf;
use std::fmt::{self, Debug};
use std::mem::zeroed;
use std::mem::{transmute, zeroed};
use std::sync::Arc;
use style::custom_properties::ComputedValuesMap;
use style::logical_geometry::WritingMode;
@ -95,13 +96,13 @@ impl ComputedValues for GeckoComputedValues {
fn set_root_font_size(&mut self, s: Au) { self.root_font_size = s; }
fn set_writing_mode(&mut self, mode: WritingMode) { self.writing_mode = mode; }
// FIXME(bholley): Implement this properly.
#[inline]
fn is_multicol(&self) -> bool { unimplemented!() }
fn is_multicol(&self) -> bool { false }
}
<%def name="declare_style_struct(style_struct)">
#[derive(Clone, HeapSizeOf, Debug)]
#[no_move]
% if style_struct.gecko_ffi_name:
pub struct ${style_struct.gecko_struct_name} {
gecko: ${style_struct.gecko_ffi_name},
@ -111,21 +112,82 @@ pub struct ${style_struct.gecko_struct_name};
% endif
</%def>
<%def name="impl_simple_copy(ident, gecko_ffi_name)">
fn copy_${ident}_from(&mut self, other: &Self) {
self.gecko.${gecko_ffi_name} = other.gecko.${gecko_ffi_name};
}
</%def>
<%!
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 & (gecko_style_structs::BORDER_STYLE_MASK as u8))" % ffi_name
else:
return "self.gecko.%s" % ffi_name
def set_gecko_property(ffi_name, expr):
if is_border_style_masked(ffi_name):
return "self.gecko.%s &= !(gecko_style_structs::BORDER_STYLE_MASK as u8);" % ffi_name + \
"self.gecko.%s |= %s as u8;" % (ffi_name, expr)
else:
return "self.gecko.%s = %s;" % (ffi_name, expr)
%>
<%def name="impl_keyword_setter(ident, gecko_ffi_name, keyword)">
fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
use gecko_style_structs as gss;
use style::properties::longhands::${ident}::computed_value::T as Keyword;
// FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts
let result = match v {
% for value in keyword.values_for('gecko'):
Keyword::${to_rust_ident(value)} => gss::${keyword.gecko_constant(value)} as u8,
% endfor
};
${set_gecko_property(gecko_ffi_name, "result")}
}
</%def>
<%def name="impl_keyword_clone(ident, gecko_ffi_name, keyword)">
fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
use gecko_style_structs as gss;
use style::properties::longhands::${ident}::computed_value::T as Keyword;
// FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts
match ${get_gecko_property(gecko_ffi_name)} as u32 {
% for value in keyword.values_for('gecko'):
gss::${keyword.gecko_constant(value)} => Keyword::${to_rust_ident(value)},
% endfor
x => panic!("Found unexpected value in style struct for ${ident} property: {}", x),
}
}
</%def>
<%def name="impl_keyword(ident, gecko_ffi_name, keyword, need_clone)">
<%call expr="impl_keyword_setter(ident, gecko_ffi_name, keyword)"></%call>
<%call expr="impl_simple_copy(ident, gecko_ffi_name)"></%call>
%if need_clone:
<%call expr="impl_keyword_clone(ident, gecko_ffi_name, keyword)"></%call>
% endif
</%def>
<%def name="impl_app_units(ident, gecko_ffi_name, need_clone)">
fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
self.gecko.${gecko_ffi_name} = v.0;
}
<%call expr="impl_simple_copy(ident, gecko_ffi_name)"></%call>
%if need_clone:
fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
Au(self.gecko.${gecko_ffi_name})
}
% endif
</%def>
<%def name="impl_style_struct(style_struct)">
impl ${style_struct.gecko_struct_name} {
#[allow(dead_code, unused_variables)]
fn initial() -> Arc<Self> {
// Some Gecko style structs have AutoTArray members, which have internal pointers and are
// thus MOZ_NON_MEMMOVABLE. Since Rust is generally a very move-happy language, we need to
// be very careful that nsStyle* structs are never moved after they are constructed.
//
// By annotating the structs [no_move], we can get the |rust-tenacious| linter to trigger
// an error on any semantic moves. But we don't have a great way of telling LLVM to
// allocate our new object directly on the heap without using a temporary. So to do that
// (and also please tenacious), we pass zeroed memory into the Arc constructor, and _then_
// use make_mut to get a reference to pass to the Gecko constructor. Since the refcount is
// guaranteed to be 1, make_mut will always pass us a direct reference instead of taking
// the copy-on-write path.
let mut result = Arc::new(${style_struct.gecko_struct_name} { gecko: unsafe { zeroed() } });
unsafe {
Gecko_Construct_${style_struct.gecko_ffi_name}(&mut Arc::make_mut(&mut result).gecko);
@ -156,6 +218,10 @@ impl HeapSizeOf for ${style_struct.gecko_ffi_name} {
// Not entirely accurate, but good enough for now.
fn heap_size_of_children(&self) -> usize { 0 }
}
// FIXME(bholley): Make bindgen generate Debug for all types.
%if style_struct.gecko_ffi_name in "nsStyleBorder nsStylePosition nsStyleDisplay nsStyleList nsStyleBackground "\
"nsStyleFont nsStyleEffects nsStyleSVGReset".split():
impl Debug for ${style_struct.gecko_ffi_name} {
// FIXME(bholley): Generate this.
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@ -163,12 +229,12 @@ impl Debug for ${style_struct.gecko_ffi_name} {
}
}
%endif
%endif
</%def>
<%def name="raw_impl_trait(style_struct, skip_longhands=None, skip_additionals=None)">
<%def name="raw_impl_trait(style_struct, skip_longhands='', skip_additionals='')">
<%
longhands = [x for x in style_struct.longhands
if not (skip_longhands and x.name in skip_longhands)]
longhands = [x for x in style_struct.longhands if not x.name in skip_longhands.split()]
#
# Make a list of types we can't auto-generate.
@ -186,11 +252,6 @@ impl Debug for ${style_struct.gecko_ffi_name} {
force_stub += ["box-sizing"]
# Inconsistent constant naming in gecko
force_stub += ["unicode-bidi", "text-transform"]
# Need to figure out why servo has sideways-left computed value and gecko doesn't
force_stub += ["text-orientation"]
# Automatic mapping generates NS_STYLE_TEXT_DECORATION_STYLE__MOZ_NONE instead of
# NS_STYLE_TEXT_DECORATION_STYLE__NONE
force_stub += ["text-decoration-style"]
# These are booleans.
force_stub += ["page-break-after", "page-break-before"]
@ -207,19 +268,7 @@ impl ${style_struct.trait_name} for ${style_struct.gecko_struct_name} {
* Auto-Generated Methods.
*/
% for longhand in keyword_longhands:
fn set_${longhand.ident}(&mut self, v: longhands::${longhand.ident}::computed_value::T) {
use gecko_style_structs as gss;
use style::properties::longhands::${longhand.ident}::computed_value::T as Keyword;
// FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts
self.gecko.${longhand.gecko_ffi_name} = match v {
% for value in longhand.keyword.values_for('gecko'):
Keyword::${to_rust_ident(value)} => gss::${longhand.keyword.gecko_constant(value)} as u8,
% endfor
};
}
fn copy_${longhand.ident}_from(&mut self, other: &Self) {
self.gecko.${longhand.gecko_ffi_name} = other.gecko.${longhand.gecko_ffi_name};
}
<%call expr="impl_keyword(longhand.ident, longhand.gecko_ffi_name, longhand.keyword, longhand.need_clone)"></%call>
% endfor
/*
@ -227,14 +276,19 @@ impl ${style_struct.trait_name} for ${style_struct.gecko_struct_name} {
*/
% for longhand in stub_longhands:
fn set_${longhand.ident}(&mut self, _: longhands::${longhand.ident}::computed_value::T) {
unimplemented!()
println!("stylo: Unimplemented property setter: ${longhand.name}");
}
fn copy_${longhand.ident}_from(&mut self, _: &Self) {
println!("stylo: Unimplemented property setter: ${longhand.name}");
}
% if longhand.need_clone:
fn clone_${longhand.ident}(&self) -> longhands::${longhand.ident}::computed_value::T {
unimplemented!()
}
% endif
% endfor
<% additionals = [x for x in style_struct.additional_methods
if not (skip_additionals and x.name in skip_additionals)] %>
if skip_additionals != "*" and not x.name in skip_additionals.split()] %>
% for additional in additionals:
${additional.stub()}
% endfor
@ -242,7 +296,7 @@ impl ${style_struct.trait_name} for ${style_struct.gecko_struct_name} {
</%def>
<% data.manual_style_structs = [] %>
<%def name="impl_trait(style_struct_name, skip_longhands=None, skip_additionals=None)">
<%def name="impl_trait(style_struct_name, skip_longhands='', skip_additionals='')">
<%self:raw_impl_trait style_struct="${next(x for x in data.style_structs if x.trait_name == style_struct_name)}"
skip_longhands="${skip_longhands}" skip_additionals="${skip_additionals}">
${caller.body()}
@ -250,28 +304,104 @@ ${caller.body()}
<% data.manual_style_structs.append(style_struct_name) %>
</%def>
// Proof-of-concept for a style struct with some manually-implemented methods. We add
// the manually-implemented methods to skip_longhands and skip_additionals, and the
// infrastructure auto-generates everything not in those lists. This allows us to
// iteratively implement more and more methods.
<%!
class Side(object):
def __init__(self, name, index):
self.name = name
self.ident = name.lower()
self.index = index
SIDES = [Side("Top", 0), Side("Right", 1), Side("Bottom", 2), Side("Left", 3)]
%>
#[allow(dead_code)]
fn static_assert() {
unsafe {
% for side in SIDES:
transmute::<_, [u32; ${side.index}]>([1; gecko_style_structs::Side::eSide${side.name} as usize]);
% endfor
}
}
<% border_style_keyword = Keyword("border-style",
"none solid double dotted dashed hidden groove ridge inset outset") %>
<%
skip_border_longhands = ""
for side in SIDES:
skip_border_longhands += "border-{0}-style border-{0}-width ".format(side.ident)
%>
<%self:impl_trait style_struct_name="Border"
skip_longhands="${['border-left-color', 'border-left-style']}"
skip_additionals="${['border_bottom_is_none_or_hidden_and_has_nonzero_width']}">
fn set_border_left_color(&mut self, _: longhands::border_left_color::computed_value::T) {
unimplemented!()
skip_longhands="${skip_border_longhands}"
skip_additionals="*">
% for side in SIDES:
<% impl_keyword("border_%s_style" % side.ident, "mBorderStyle[%s]" % side.index, border_style_keyword,
need_clone=True) %>
<% impl_app_units("border_%s_width" % side.ident, "mComputedBorder.%s" % side.ident, need_clone=False) %>
fn border_${side.ident}_has_nonzero_width(&self) -> bool {
self.gecko.mComputedBorder.${side.ident} != 0
}
fn copy_border_left_color_from(&mut self, _: &Self) {
unimplemented!()
% endfor
</%self:impl_trait>
<%self:impl_trait style_struct_name="Outline"
skip_longhands="outline-style"
skip_additionals="*">
<% impl_keyword("outline_style", "mOutlineStyle", border_style_keyword, need_clone=True) %>
fn outline_has_nonzero_width(&self) -> bool {
self.gecko.mCachedOutlineWidth != 0
}
fn set_border_left_style(&mut self, _: longhands::border_left_style::computed_value::T) {
unimplemented!()
</%self:impl_trait>
<%self:impl_trait style_struct_name="Font" skip_longhands="font-size">
// FIXME(bholley): This doesn't handle zooming properly.
<% impl_app_units("font_size", "mSize", need_clone=True) %>
</%self:impl_trait>
<%self:impl_trait style_struct_name="Box" skip_longhands="display overflow-y">
// We manually-implement the |display| property until we get general
// infrastructure for preffing certain values.
<% display_keyword = Keyword("display", "inline block inline-block table inline-table table-row-group " +
"table-header-group table-footer-group table-row table-column-group " +
"table-column table-cell table-caption list-item flex none") %>
<%call expr="impl_keyword('display', 'mDisplay', display_keyword, True)"></%call>
// overflow-y is implemented as a newtype of overflow-x, so we need special handling.
// We could generalize this if we run into other newtype keywords.
<% overflow_x = data.longhands_by_name["overflow-x"] %>
fn set_overflow_y(&mut self, v: longhands::overflow_y::computed_value::T) {
use gecko_style_structs as gss;
use style::properties::longhands::overflow_x::computed_value::T as BaseType;
// FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts
self.gecko.mOverflowY = match v.0 {
% for value in overflow_x.keyword.values_for('gecko'):
BaseType::${to_rust_ident(value)} => gss::${overflow_x.keyword.gecko_constant(value)} as u8,
% endfor
};
}
fn copy_border_left_style_from(&mut self, _: &Self) {
unimplemented!()
}
fn border_bottom_is_none_or_hidden_and_has_nonzero_width(&self) -> bool {
unimplemented!()
<%call expr="impl_simple_copy('overflow_y', 'mOverflowY')"></%call>
fn clone_overflow_y(&self) -> longhands::overflow_y::computed_value::T {
use gecko_style_structs as gss;
use style::properties::longhands::overflow_x::computed_value::T as BaseType;
use style::properties::longhands::overflow_y::computed_value::T as NewType;
// FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts
match self.gecko.mOverflowY as u32 {
% for value in overflow_x.keyword.values_for('gecko'):
gss::${overflow_x.keyword.gecko_constant(value)} => NewType(BaseType::${to_rust_ident(value)}),
% endfor
x => panic!("Found unexpected value in style struct for overflow_y property: {}", x),
}
}
</%self:impl_trait>
% for style_struct in data.style_structs:

View file

@ -109,12 +109,14 @@ fi
-match "nsIPrincipal.h" \
-match "nsDataHashtable.h" \
-match "nsCSSScanner.h" \
-match "Types.h" \
-blacklist-type "IsDestructibleFallbackImpl" \
-blacklist-type "IsDestructibleFallback" \
-opaque-type "nsIntMargin" \
-opaque-type "nsIntPoint" \
-opaque-type "nsIntRect" \
-opaque-type "nsTArray" \
-opaque-type "nsStyleAutoArray" \
-opaque-type "nsCOMArray" \
-opaque-type "nsDependentString" \
-opaque-type "EntryStore" \