style: Replace "internal" properties with "enabled_in"

This allows enabling properties in ua sheets and chrome differently.

The setup is:

  * enabled_in needs to be one of the four values:
    ["", "ua", "chrome", "content"]

  * "chrome" implies "ua", and implies that they're explicitly enabled.

  * "" implies the property will never be parsed.

  * "content" implies the property is accessible unconditionally, modulo a pref.

Experimental still keeps trumping over those when the pref is enabled.

This PR replaces uses of internal="" by enabled_in="ua" or enabled_in="".

This may seem that it changes behavior, but since the properties where I added
enabled_in="" already unconditionally error from parse it's not.

Next step is annotating chrome-only properties.
This commit is contained in:
Emilio Cobos Álvarez 2017-11-17 17:52:28 +01:00
parent 07fd6155aa
commit 01e41d0439
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
6 changed files with 54 additions and 31 deletions

View file

@ -146,8 +146,9 @@ def arg_to_bool(arg):
class Longhand(object):
def __init__(self, style_struct, name, spec=None, animation_value_type=None, derived_from=None, keyword=None,
predefined_type=None, custom_cascade=False, servo_pref=None, gecko_pref=None, internal=False,
need_index=False, custom_cascade_function=None, gecko_ffi_name=None,
predefined_type=None, custom_cascade=False, servo_pref=None, gecko_pref=None,
enabled_in="content", need_index=False,
custom_cascade_function=None, gecko_ffi_name=None,
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,
@ -165,7 +166,15 @@ class Longhand(object):
self.gecko_pref = gecko_pref
self.custom_cascade = custom_cascade
self.custom_cascade_function = custom_cascade_function if custom_cascade else None
self.internal = internal
# 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
# enabled.
# * "" implies the property will never be parsed.
# * "content" implies the property is accessible unconditionally,
# modulo a pref, set via servo_pref / gecko_pref.
assert enabled_in in ["", "ua", "chrome", "content"]
self.enabled_in = enabled_in
self.need_index = need_index
self.gecko_ffi_name = gecko_ffi_name or "m" + self.camel_case
self.derived_from = (derived_from or "").split()
@ -212,16 +221,18 @@ class Longhand(object):
# FIXME(emilio): Shorthand and Longhand should really share a base class.
def explicitly_enabled_in_ua_sheets(self):
return self.internal
return self.enabled_in in ["ua", "chrome"]
# TODO(emilio): Change the `internal` field to something like `enabled_in`.
def explicitly_enabled_in_chrome(self):
return False
return self.enabled_in == "chrome"
def enabled_in_content(self):
return self.enabled_in == "content"
class Shorthand(object):
def __init__(self, name, sub_properties, spec=None, servo_pref=None, gecko_pref=None,
internal=False,
enabled_in="content",
allowed_in_keyframe_block=True, alias=None, extra_prefixes=None,
allowed_in_page_rule=False, flags=None):
self.name = name
@ -234,7 +245,8 @@ class Shorthand(object):
self.servo_pref = servo_pref
self.gecko_pref = gecko_pref
self.sub_properties = sub_properties
self.internal = internal
assert enabled_in in ["", "ua", "chrome", "content"]
self.enabled_in = enabled_in
self.alias = alias.split() if alias else []
self.extra_prefixes = extra_prefixes.split() if extra_prefixes else []
self.allowed_in_page_rule = arg_to_bool(allowed_in_page_rule)
@ -271,11 +283,15 @@ class Shorthand(object):
return bool(self.gecko_pref)
return bool(self.servo_pref)
# FIXME(emilio): Shorthand and Longhand should really share a base class.
def explicitly_enabled_in_ua_sheets(self):
return self.internal
return self.enabled_in in ["ua", "chrome"]
def explicitly_enabled_in_chrome(self):
return False
return self.enabled_in == "chrome"
def enabled_in_content(self):
return self.enabled_in == "content"
class Alias(object):
@ -283,7 +299,7 @@ class Alias(object):
self.name = name
self.ident = to_rust_ident(name)
self.camel_case = to_camel_case(self.ident)
self.internal = original.internal
self.enabled_in = original.enabled_in
self.servo_pref = original.servo_pref
self.gecko_pref = original.gecko_pref
self.allowed_in_page_rule = original.allowed_in_page_rule
@ -295,10 +311,13 @@ class Alias(object):
return bool(self.servo_pref)
def explicitly_enabled_in_ua_sheets(self):
return self.internal
return self.enabled_in in ["ua", "chrome"]
def explicitly_enabled_in_chrome(self):
return False
return self.enabled_in == "chrome"
def enabled_in_content(self):
return self.enabled_in == "content"
class Method(object):