Bug 1692356 - Switch properties to use a bitfield to determine validity in rules. r=emilio

This doesn't use a full bitmap for every single rule type, as we only expect
that keyframe, page, and style rules will be checked.

Differential Revision: https://phabricator.services.mozilla.com/D104949
This commit is contained in:
Emily McDonough 2021-02-16 21:36:57 +00:00
Родитель 7190ea756d
Коммит 5a53c4b892
6 изменённых файлов: 52 добавлений и 47 удалений

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

@ -37,6 +37,32 @@ SYSTEM_FONT_LONGHANDS = """font_family font_size font_style
font_feature_settings font_variation_settings
font_optical_sizing""".split()
# Bitfield values for all rule types which can have property declarations.
STYLE_RULE = 1 << 0
PAGE_RULE = 1 << 1
KEYFRAME_RULE = 1 << 2
ALL_RULES = STYLE_RULE | PAGE_RULE | KEYFRAME_RULE
DEFAULT_RULES = STYLE_RULE | KEYFRAME_RULE
DEFAULT_RULES_AND_PAGE = DEFAULT_RULES | PAGE_RULE
DEFAULT_RULES_EXCEPT_KEYFRAME = STYLE_RULE
# Rule name to value dict
RULE_VALUES = {
"Style": STYLE_RULE,
"Page": PAGE_RULE,
"Keyframe": KEYFRAME_RULE,
}
def rule_values_from_arg(that):
if isinstance(that, int):
return that
mask = 0
for rule in that.split():
mask |= RULE_VALUES[rule]
return mask
def maybe_moz_logical_alias(engine, side, prop):
if engine == "gecko" and side[1]:
@ -214,7 +240,7 @@ class Longhand(object):
need_index=False,
gecko_ffi_name=None,
has_effect_on_gecko_scrollbars=None,
allowed_in_keyframe_block=True,
rule_types_allowed=DEFAULT_RULES,
cast_type="u8",
logical=False,
logical_group=None,
@ -222,7 +248,6 @@ class Longhand(object):
extra_prefixes=None,
boxed=False,
flags=None,
allowed_in_page_rule=False,
allow_quirks="No",
ignored_when_colors_disabled=False,
simple_vector_bindings=False,
@ -253,6 +278,7 @@ class Longhand(object):
+ "specified, and must have a value of True or False, iff a "
+ "property is inherited and is behind a Gecko pref"
)
self.rule_types_allowed = rule_values_from_arg(rule_types_allowed)
# For enabled_in, the setup is as follows:
# It needs to be one of the four values: ["", "ua", "chrome", "content"]
# * "chrome" implies "ua", and implies that they're explicitly
@ -274,20 +300,11 @@ class Longhand(object):
self.extra_prefixes = parse_property_aliases(extra_prefixes)
self.boxed = arg_to_bool(boxed)
self.flags = flags.split() if flags else []
self.allowed_in_page_rule = arg_to_bool(allowed_in_page_rule)
self.allow_quirks = allow_quirks
self.ignored_when_colors_disabled = ignored_when_colors_disabled
self.is_vector = vector
self.simple_vector_bindings = simple_vector_bindings
# https://drafts.csswg.org/css-animations/#keyframes
# > The <declaration-list> inside of <keyframe-block> accepts any CSS property
# > except those defined in this specification,
# > but does accept the `animation-play-state` property and interprets it specially.
self.allowed_in_keyframe_block = (
allowed_in_keyframe_block and allowed_in_keyframe_block != "False"
)
# This is done like this since just a plain bool argument seemed like
# really random.
if animation_value_type is None:
@ -491,10 +508,9 @@ class Shorthand(object):
servo_2020_pref=None,
gecko_pref=None,
enabled_in="content",
allowed_in_keyframe_block=True,
rule_types_allowed=DEFAULT_RULES,
alias=None,
extra_prefixes=None,
allowed_in_page_rule=False,
flags=None,
):
self.name = name
@ -511,17 +527,9 @@ class Shorthand(object):
self.enabled_in = enabled_in
self.alias = parse_property_aliases(alias)
self.extra_prefixes = parse_property_aliases(extra_prefixes)
self.allowed_in_page_rule = arg_to_bool(allowed_in_page_rule)
self.rule_types_allowed = rule_values_from_arg(rule_types_allowed)
self.flags = flags.split() if flags else []
# https://drafts.csswg.org/css-animations/#keyframes
# > The <declaration-list> inside of <keyframe-block> accepts any CSS property
# > except those defined in this specification,
# > but does accept the `animation-play-state` property and interprets it specially.
self.allowed_in_keyframe_block = (
allowed_in_keyframe_block and allowed_in_keyframe_block != "False"
)
def get_animatable(self):
for sub in self.sub_properties:
if sub.animatable:
@ -579,8 +587,7 @@ class Alias(object):
self.servo_2020_pref = original.servo_2020_pref
self.gecko_pref = gecko_pref
self.transitionable = original.transitionable
self.allowed_in_page_rule = original.allowed_in_page_rule
self.allowed_in_keyframe_block = original.allowed_in_keyframe_block
self.rule_types_allowed = original.rule_types_allowed
@staticmethod
def type():

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

@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
<%namespace name="helpers" file="/helpers.mako.rs" />
<% from data import ALL_AXES, Keyword, Method, to_rust_ident, to_camel_case%>
<% from data import ALL_AXES, DEFAULT_RULES_EXCEPT_KEYFRAME, Keyword, Method, to_rust_ident, to_camel_case%>
<% data.new_style_struct("Box",
inherited=False,
@ -217,7 +217,7 @@ ${helpers.predefined_type(
need_index=True,
animation_value_type="none",
extra_prefixes=animation_extra_prefixes,
allowed_in_keyframe_block=False,
rule_types_allowed=DEFAULT_RULES_EXCEPT_KEYFRAME,
spec="https://drafts.csswg.org/css-animations/#propdef-animation-name",
)}
@ -247,7 +247,6 @@ ${helpers.predefined_type(
need_index=True,
animation_value_type="none",
extra_prefixes=animation_extra_prefixes,
allowed_in_keyframe_block=True,
spec="https://drafts.csswg.org/css-transitions/#propdef-animation-timing-function",
)}
@ -261,7 +260,7 @@ ${helpers.predefined_type(
need_index=True,
animation_value_type="none",
extra_prefixes=animation_extra_prefixes,
allowed_in_keyframe_block=False,
rule_types_allowed=DEFAULT_RULES_EXCEPT_KEYFRAME,
spec="https://drafts.csswg.org/css-animations/#propdef-animation-iteration-count",
)}
@ -278,7 +277,7 @@ ${helpers.single_keyword(
extra_prefixes=animation_extra_prefixes,
gecko_inexhaustive=True,
spec="https://drafts.csswg.org/css-animations/#propdef-animation-direction",
allowed_in_keyframe_block=False,
rule_types_allowed=DEFAULT_RULES_EXCEPT_KEYFRAME,
)}
${helpers.single_keyword(
@ -291,7 +290,7 @@ ${helpers.single_keyword(
extra_prefixes=animation_extra_prefixes,
gecko_enum_prefix="StyleAnimationPlayState",
spec="https://drafts.csswg.org/css-animations/#propdef-animation-play-state",
allowed_in_keyframe_block=False,
rule_types_allowed=DEFAULT_RULES_EXCEPT_KEYFRAME,
)}
${helpers.single_keyword(
@ -305,7 +304,7 @@ ${helpers.single_keyword(
extra_prefixes=animation_extra_prefixes,
gecko_inexhaustive=True,
spec="https://drafts.csswg.org/css-animations/#propdef-animation-fill-mode",
allowed_in_keyframe_block=False,
rule_types_allowed=DEFAULT_RULES_EXCEPT_KEYFRAME,
)}
${helpers.predefined_type(
@ -319,7 +318,7 @@ ${helpers.predefined_type(
animation_value_type="none",
extra_prefixes=animation_extra_prefixes,
spec="https://drafts.csswg.org/css-animations/#propdef-animation-delay",
allowed_in_keyframe_block=False,
rule_types_allowed=DEFAULT_RULES_EXCEPT_KEYFRAME,
)}
<% transform_extra_prefixes = "moz:layout.css.prefixes.transforms webkit" %>

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

@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
<%namespace name="helpers" file="/helpers.mako.rs" />
<% from data import ALL_SIDES, maybe_moz_logical_alias %>
<% from data import ALL_SIDES, DEFAULT_RULES_AND_PAGE, maybe_moz_logical_alias %>
<% data.new_style_struct("Margin", inherited=False) %>
% for side in ALL_SIDES:
@ -23,7 +23,7 @@
logical=side[1],
logical_group="margin",
spec=spec,
allowed_in_page_rule=True,
rule_types_allowed=DEFAULT_RULES_AND_PAGE,
servo_restyle_damage="reflow"
)}
% endfor

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

@ -54,7 +54,7 @@ pub use self::cascade::*;
<%!
from collections import defaultdict
from data import Method, PropertyRestrictions, Keyword, to_rust_ident, to_camel_case, SYSTEM_FONT_LONGHANDS
from data import Method, PropertyRestrictions, Keyword, to_rust_ident, to_camel_case, RULE_VALUES, SYSTEM_FONT_LONGHANDS
import os.path
%>
@ -553,17 +553,15 @@ impl NonCustomPropertyId {
"Declarations are only expected inside a keyframe, page, or style rule."
);
${static_non_custom_property_id_set(
"DISALLOWED_IN_KEYFRAME_BLOCK",
lambda p: not p.allowed_in_keyframe_block
)}
${static_non_custom_property_id_set(
"DISALLOWED_IN_PAGE_RULE",
lambda p: not p.allowed_in_page_rule
)}
static MAP: [u8; NON_CUSTOM_PROPERTY_ID_COUNT] = [
% for property in data.longhands + data.shorthands + data.all_aliases():
${property.rule_types_allowed},
% endfor
];
match rule_type {
CssRuleType::Keyframe => !DISALLOWED_IN_KEYFRAME_BLOCK.contains(self),
CssRuleType::Page => !DISALLOWED_IN_PAGE_RULE.contains(self),
% for name in RULE_VALUES:
CssRuleType::${name} => MAP[self.0] & ${RULE_VALUES[name]} != 0,
% endfor
_ => true
}
}

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

@ -190,7 +190,7 @@ macro_rules! try_parse_one {
animation-timing-function animation-delay
animation-iteration-count animation-direction
animation-fill-mode animation-play-state"
allowed_in_keyframe_block="False"
rule_types_allowed="Style"
spec="https://drafts.csswg.org/css-animations/#propdef-animation">
<%
props = "name duration timing_function delay iteration_count \

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

@ -3,6 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
<%namespace name="helpers" file="/helpers.mako.rs" />
<% from data import DEFAULT_RULES_AND_PAGE %>
${helpers.four_sides_shorthand(
"margin",
@ -10,7 +11,7 @@ ${helpers.four_sides_shorthand(
"specified::LengthPercentageOrAuto::parse",
engines="gecko servo-2013 servo-2020",
spec="https://drafts.csswg.org/css-box/#propdef-margin",
allowed_in_page_rule=True,
rule_types_allowed=DEFAULT_RULES_AND_PAGE,
allow_quirks="Yes",
)}