Skip to content

Commit

Permalink
servo: Merge #19956 - Generate some PropertyDeclaration methods by ha…
Browse files Browse the repository at this point in the history
…nd 🐉🐲 (from servo:derive-all-the-things); r=emilio

We rely on rust-lang/rfcs#2195 to make some enums share the same discriminants by definition.

This fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1428285.

Source-Repo: /~https://github.com/servo/servo
Source-Revision: 9faf0cdce50379dfb8125d7a9c913babd56382e2

UltraBlame original commit: 8bd0a2507ccbb5fad4588e43bbca20eead87a2bb
  • Loading branch information
marco-c committed Oct 2, 2019
1 parent 7813899 commit 08e173a
Show file tree
Hide file tree
Showing 6 changed files with 347 additions and 156 deletions.
2 changes: 2 additions & 0 deletions servo/components/style/properties/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def __init__(self, style_struct, name, spec=None, animation_value_type=None, key
predefined_type=None, servo_pref=None, gecko_pref=None,
enabled_in="content", need_index=False,
gecko_ffi_name=None,
is_gecko_size_type_hack=False,
allowed_in_keyframe_block=True, cast_type='u8',
logical=False, alias=None, extra_prefixes=None, boxed=False,
flags=None, allowed_in_page_rule=False, allow_quirks=False, ignored_when_colors_disabled=False,
Expand Down Expand Up @@ -185,6 +186,7 @@ def __init__(self, style_struct, name, spec=None, animation_value_type=None, key
self.allow_quirks = allow_quirks
self.ignored_when_colors_disabled = ignored_when_colors_disabled
self.is_vector = vector
self.is_gecko_size_type_hack = is_gecko_size_type_hack



Expand Down
25 changes: 15 additions & 10 deletions servo/components/style/properties/declaration_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,9 @@ impl PropertyDeclarationBlock {
AllShorthand::NotSet => {}
AllShorthand::CSSWideKeyword(keyword) => {
for &id in ShorthandId::All.longhands() {
let decl = PropertyDeclaration::CSSWideKeyword(id, keyword);
let decl = PropertyDeclaration::CSSWideKeyword(
WideKeywordDeclaration { id, keyword },
);
changed |= self.push(
decl,
importance,
Expand All @@ -440,7 +442,9 @@ impl PropertyDeclarationBlock {
}
AllShorthand::WithVariables(unparsed) => {
for &id in ShorthandId::All.longhands() {
let decl = PropertyDeclaration::WithVariables(id, unparsed.clone());
let decl = PropertyDeclaration::WithVariables(
VariableDeclaration { id, value: unparsed.clone() },
);
changed |= self.push(
decl,
importance,
Expand Down Expand Up @@ -639,14 +643,15 @@ impl PropertyDeclarationBlock {



(&PropertyDeclaration::WithVariables(id, ref unparsed),
Some(ref _computed_values)) => {
unparsed.substitute_variables(
id,
(
&PropertyDeclaration::WithVariables(ref declaration),
Some(ref _computed_values),
) => {
declaration.value.substitute_variables(
declaration.id,
custom_properties.as_ref(),
QuirksMode::NoQuirks,
)
.to_css(dest)
).to_css(dest)
},
(ref d, _) => d.to_css(dest),
}
Expand Down Expand Up @@ -726,8 +731,8 @@ impl PropertyDeclarationBlock {
let mut builder = CustomPropertiesBuilder::new(inherited_custom_properties);

for declaration in self.normal_declaration_iter() {
if let PropertyDeclaration::Custom(ref name, ref value) = *declaration {
builder.cascade(name, value.borrow());
if let PropertyDeclaration::Custom(ref declaration) = *declaration {
builder.cascade(&declaration.name, declaration.value.borrow());
}
}

Expand Down
7 changes: 4 additions & 3 deletions servo/components/style/properties/helpers.mako.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@
PropertyDeclaration::${property.camel_case}(ref value) => {
DeclaredValue::Value(value)
},
PropertyDeclaration::CSSWideKeyword(id, value) => {
debug_assert!(id == LonghandId::${property.camel_case});
DeclaredValue::CSSWideKeyword(value)
PropertyDeclaration::CSSWideKeyword(ref declaration) => {
debug_assert!(declaration.id == LonghandId::${property.camel_case});
DeclaredValue::CSSWideKeyword(declaration.keyword)
},
PropertyDeclaration::WithVariables(..) => {
panic!("variables should already have been substituted")
Expand Down Expand Up @@ -903,6 +903,7 @@
<%call expr="longhand(name,
predefined_type=length_type,
logical=logical,
is_gecko_size_type_hack=True,
**kwargs)">
% if not logical:
use values::specified::AllowQuirks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,14 +435,14 @@ impl AnimationValue {
},
% endif
% endfor
PropertyDeclaration::CSSWideKeyword(id, keyword) => {
match id {
PropertyDeclaration::CSSWideKeyword(ref declaration) => {
match declaration.id {
// We put all the animatable properties first in the hopes
// that it might increase match locality.
% for prop in data.longhands:
% if prop.animatable:
LonghandId::${prop.camel_case} => {
let style_struct = match keyword {
let style_struct = match declaration.keyword {
% if not prop.style_struct.inherited:
CSSWideKeyword::Unset |
% endif
Expand Down Expand Up @@ -472,15 +472,15 @@ impl AnimationValue {
% endfor
}
},
PropertyDeclaration::WithVariables(id, ref unparsed) => {
PropertyDeclaration::WithVariables(ref declaration) => {
let substituted = {
let custom_properties =
extra_custom_properties.or_else(|| context.style().custom_properties());

unparsed.substitute_variables(
id,
declaration.value.substitute_variables(
declaration.id,
custom_properties,
context.quirks_mode
context.quirks_mode,
)
};
return AnimationValue::from_declaration(
Expand Down
Loading

0 comments on commit 08e173a

Please sign in to comment.