mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
style: Introduce PropertyDeclaration::to_physical.
Bug: 1309752 Reviewed-by: heycam MozReview-Commit-ID: FAL04K5G948
This commit is contained in:
parent
89880727ec
commit
be9acba801
2 changed files with 79 additions and 2 deletions
|
@ -237,6 +237,21 @@ class Longhand(object):
|
||||||
def type():
|
def type():
|
||||||
return "longhand"
|
return "longhand"
|
||||||
|
|
||||||
|
# For a given logical property return all the physical
|
||||||
|
# property names corresponding to it.
|
||||||
|
def all_physical_mapped_properties(self):
|
||||||
|
assert self.logical
|
||||||
|
logical_side = None
|
||||||
|
for s in LOGICAL_SIDES + LOGICAL_SIZES:
|
||||||
|
if s in self.name:
|
||||||
|
assert not logical_side
|
||||||
|
logical_side = s
|
||||||
|
assert logical_side
|
||||||
|
physical = PHYSICAL_SIDES if logical_side in LOGICAL_SIDES else PHYSICAL_SIZES
|
||||||
|
return [self.name.replace(logical_side, physical_side).replace("inset-", "") \
|
||||||
|
for physical_side in physical]
|
||||||
|
|
||||||
|
|
||||||
def experimental(self, product):
|
def experimental(self, product):
|
||||||
if product == "gecko":
|
if product == "gecko":
|
||||||
return bool(self.gecko_pref)
|
return bool(self.gecko_pref)
|
||||||
|
|
|
@ -1497,7 +1497,7 @@ impl UnparsedValue {
|
||||||
|
|
||||||
/// An identifier for a given property declaration, which can be either a
|
/// An identifier for a given property declaration, which can be either a
|
||||||
/// longhand or a custom property.
|
/// longhand or a custom property.
|
||||||
#[derive(Clone, Copy, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
#[cfg_attr(feature = "servo", derive(MallocSizeOf))]
|
#[cfg_attr(feature = "servo", derive(MallocSizeOf))]
|
||||||
pub enum PropertyDeclarationId<'a> {
|
pub enum PropertyDeclarationId<'a> {
|
||||||
/// A longhand.
|
/// A longhand.
|
||||||
|
@ -1903,7 +1903,7 @@ impl PropertyDeclaration {
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
// This is just fine because PropertyDeclarationId and LonghandId
|
// This is just fine because PropertyDeclaration and LonghandId
|
||||||
// have corresponding discriminants.
|
// have corresponding discriminants.
|
||||||
let id = unsafe { *(self as *const _ as *const LonghandId) };
|
let id = unsafe { *(self as *const _ as *const LonghandId) };
|
||||||
debug_assert_eq!(id, match *self {
|
debug_assert_eq!(id, match *self {
|
||||||
|
@ -1915,6 +1915,68 @@ impl PropertyDeclaration {
|
||||||
PropertyDeclarationId::Longhand(id)
|
PropertyDeclarationId::Longhand(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Given a declaration, convert it into a declaration for a corresponding
|
||||||
|
/// physical property.
|
||||||
|
#[inline]
|
||||||
|
pub fn to_physical(&self, wm: WritingMode) -> Self {
|
||||||
|
match *self {
|
||||||
|
PropertyDeclaration::WithVariables(VariableDeclaration {
|
||||||
|
id,
|
||||||
|
ref value,
|
||||||
|
}) => {
|
||||||
|
return PropertyDeclaration::WithVariables(VariableDeclaration {
|
||||||
|
id: id.to_physical(wm),
|
||||||
|
value: value.clone(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
PropertyDeclaration::CSSWideKeyword(WideKeywordDeclaration {
|
||||||
|
id,
|
||||||
|
keyword,
|
||||||
|
}) => {
|
||||||
|
return PropertyDeclaration::CSSWideKeyword(WideKeywordDeclaration {
|
||||||
|
id: id.to_physical(wm),
|
||||||
|
keyword,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
PropertyDeclaration::Custom(..) => return self.clone(),
|
||||||
|
% for prop in data.longhands:
|
||||||
|
PropertyDeclaration::${prop.camel_case}(..) => {},
|
||||||
|
% endfor
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut ret = self.clone();
|
||||||
|
|
||||||
|
% for prop in data.longhands:
|
||||||
|
% if prop.logical:
|
||||||
|
% for physical_property in prop.all_physical_mapped_properties():
|
||||||
|
% if data.longhands_by_name[physical_property].specified_type() != prop.specified_type():
|
||||||
|
<% raise "Logical property %s should share specified value with physical property %s" % (prop.name, physical_property) %>
|
||||||
|
% endif
|
||||||
|
% endfor
|
||||||
|
% endif
|
||||||
|
% endfor
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
let longhand_id = *(&mut ret as *mut _ as *mut LonghandId);
|
||||||
|
|
||||||
|
debug_assert_eq!(
|
||||||
|
PropertyDeclarationId::Longhand(longhand_id),
|
||||||
|
ret.id()
|
||||||
|
);
|
||||||
|
|
||||||
|
// This is just fine because PropertyDeclaration and LonghandId
|
||||||
|
// have corresponding discriminants.
|
||||||
|
*(&mut ret as *mut _ as *mut LonghandId) = longhand_id.to_physical(wm);
|
||||||
|
|
||||||
|
debug_assert_eq!(
|
||||||
|
PropertyDeclarationId::Longhand(longhand_id.to_physical(wm)),
|
||||||
|
ret.id()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret
|
||||||
|
}
|
||||||
|
|
||||||
fn with_variables_from_shorthand(&self, shorthand: ShorthandId) -> Option< &str> {
|
fn with_variables_from_shorthand(&self, shorthand: ShorthandId) -> Option< &str> {
|
||||||
match *self {
|
match *self {
|
||||||
PropertyDeclaration::WithVariables(ref declaration) => {
|
PropertyDeclaration::WithVariables(ref declaration) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue