Support logical properties

This commit is contained in:
Manish Goregaokar 2016-11-07 14:34:22 -08:00
parent f1c3e97fb4
commit e34eb13d65
6 changed files with 146 additions and 40 deletions

View file

@ -4,6 +4,11 @@
import re
PHYSICAL_SIDES = ["top", "left", "bottom", "right"]
LOGICAL_SIDES = ["block-start", "block-end", "inline-start", "inline-end"]
# bool is True when logical
ALL_SIDES = [(side, False) for side in PHYSICAL_SIDES] + [(side, True) for side in LOGICAL_SIDES]
def to_rust_ident(name):
name = name.replace("-", "_")
@ -63,12 +68,19 @@ class Keyword(object):
return "as " + type_str if self.needs_cast() else ""
def arg_to_bool(arg):
if isinstance(arg, bool):
return arg
assert arg in ["True", "False"]
return arg == "True"
class Longhand(object):
def __init__(self, style_struct, name, animatable=None, derived_from=None, keyword=None,
predefined_type=None, custom_cascade=False, experimental=False, internal=False,
need_clone=False, need_index=False, gecko_ffi_name=None, depend_on_viewport_size=False,
allowed_in_keyframe_block=True, complex_color=False, cast_type='u8',
has_uncacheable_values=False):
has_uncacheable_values=False, logical=False):
self.name = name
self.keyword = keyword
self.predefined_type = predefined_type
@ -85,6 +97,7 @@ class Longhand(object):
self.derived_from = (derived_from or "").split()
self.complex_color = complex_color
self.cast_type = cast_type
self.logical = arg_to_bool(logical)
# https://drafts.csswg.org/css-animations/#keyframes
# > The <declaration-list> inside of <keyframe-block> accepts any CSS property
@ -97,12 +110,10 @@ class Longhand(object):
# really random.
if animatable is None:
raise TypeError("animatable should be specified for " + name + ")")
if isinstance(animatable, bool):
self.animatable = animatable
else:
assert animatable == "True" or animatable == "False"
self.animatable = animatable == "True"
self.animatable = arg_to_bool(animatable)
if self.logical:
# Logical properties don't animate separately
self.animatable = False
# NB: Animatable implies clone because a property animation requires a
# copy of the computed value.
#