mirror of
https://github.com/servo/servo.git
synced 2025-07-14 02:43:42 +01:00
style: Don't keep a separate list of ignored-when-colors-disabled longhands.
Most of the change is moving sets around to be static functions on LonghandIdSet. I think I like that pattern, but I can also make the new set a global static and add mako code to be `pub` or something. Though I think the LonghandIdSet::foo().contains(..) pattern is nice to read :) Differential Revision: https://phabricator.services.mozilla.com/D10653
This commit is contained in:
parent
33fed65597
commit
d035d02517
2 changed files with 56 additions and 36 deletions
|
@ -758,6 +758,41 @@ impl<'a> Iterator for LonghandIdSetIterator<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LonghandIdSet {
|
impl LonghandIdSet {
|
||||||
|
#[inline]
|
||||||
|
fn reset() -> &'static Self {
|
||||||
|
${static_longhand_id_set("RESET", lambda p: not p.style_struct.inherited)}
|
||||||
|
&RESET
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn animatable() -> &'static Self {
|
||||||
|
${static_longhand_id_set("ANIMATABLE", lambda p: p.animatable)}
|
||||||
|
&ANIMATABLE
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn discrete_animatable() -> &'static Self {
|
||||||
|
${static_longhand_id_set("DISCRETE_ANIMATABLE", lambda p: p.animation_value_type == "discrete")}
|
||||||
|
&DISCRETE_ANIMATABLE
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn logical() -> &'static Self {
|
||||||
|
${static_longhand_id_set("LOGICAL", lambda p: p.logical)}
|
||||||
|
&LOGICAL
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the set of longhands that are ignored when document colors are
|
||||||
|
/// disabled.
|
||||||
|
#[inline]
|
||||||
|
pub fn ignored_when_colors_disabled() -> &'static Self {
|
||||||
|
${static_longhand_id_set(
|
||||||
|
"IGNORED_WHEN_COLORS_DISABLED",
|
||||||
|
lambda p: p.ignored_when_colors_disabled
|
||||||
|
)}
|
||||||
|
&IGNORED_WHEN_COLORS_DISABLED
|
||||||
|
}
|
||||||
|
|
||||||
/// Iterate over the current longhand id set.
|
/// Iterate over the current longhand id set.
|
||||||
pub fn iter(&self) -> LonghandIdSetIterator {
|
pub fn iter(&self) -> LonghandIdSetIterator {
|
||||||
LonghandIdSetIterator { longhands: self, cur: 0, }
|
LonghandIdSetIterator { longhands: self, cur: 0, }
|
||||||
|
@ -784,6 +819,14 @@ impl LonghandIdSet {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Remove all the given properties from the set.
|
||||||
|
#[inline]
|
||||||
|
pub fn remove_all(&mut self, other: &Self) {
|
||||||
|
for (self_cell, other_cell) in self.storage.iter_mut().zip(other.storage.iter()) {
|
||||||
|
*self_cell &= !*other_cell;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Create an empty set
|
/// Create an empty set
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new() -> LonghandIdSet {
|
pub fn new() -> LonghandIdSet {
|
||||||
|
@ -800,8 +843,7 @@ impl LonghandIdSet {
|
||||||
/// Return whether this set contains any reset longhand.
|
/// Return whether this set contains any reset longhand.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn contains_any_reset(&self) -> bool {
|
pub fn contains_any_reset(&self) -> bool {
|
||||||
${static_longhand_id_set("RESET", lambda p: not p.style_struct.inherited)}
|
self.contains_any(Self::reset())
|
||||||
self.contains_any(&RESET)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add the given property to the set
|
/// Add the given property to the set
|
||||||
|
@ -961,9 +1003,8 @@ impl LonghandId {
|
||||||
|
|
||||||
/// Returns whether the longhand property is inherited by default.
|
/// Returns whether the longhand property is inherited by default.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn inherited(&self) -> bool {
|
pub fn inherited(self) -> bool {
|
||||||
${static_longhand_id_set("INHERITED", lambda p: p.style_struct.inherited)}
|
!LonghandIdSet::reset().contains(self)
|
||||||
INHERITED.contains(*self)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn shorthands(&self) -> NonCustomPropertyIterator<ShorthandId> {
|
fn shorthands(&self) -> NonCustomPropertyIterator<ShorthandId> {
|
||||||
|
@ -1034,15 +1075,13 @@ impl LonghandId {
|
||||||
/// Returns whether this property is animatable.
|
/// Returns whether this property is animatable.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_animatable(self) -> bool {
|
pub fn is_animatable(self) -> bool {
|
||||||
${static_longhand_id_set("ANIMATABLE", lambda p: p.animatable)}
|
LonghandIdSet::animatable().contains(self)
|
||||||
ANIMATABLE.contains(self)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether this property is animatable in a discrete way.
|
/// Returns whether this property is animatable in a discrete way.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_discrete_animatable(self) -> bool {
|
pub fn is_discrete_animatable(self) -> bool {
|
||||||
${static_longhand_id_set("DISCRETE_ANIMATABLE", lambda p: p.animation_value_type == "discrete")}
|
LonghandIdSet::discrete_animatable().contains(self)
|
||||||
DISCRETE_ANIMATABLE.contains(self)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts from a LonghandId to an adequate nsCSSPropertyID.
|
/// Converts from a LonghandId to an adequate nsCSSPropertyID.
|
||||||
|
@ -1065,9 +1104,8 @@ impl LonghandId {
|
||||||
|
|
||||||
/// Return whether this property is logical.
|
/// Return whether this property is logical.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_logical(&self) -> bool {
|
pub fn is_logical(self) -> bool {
|
||||||
${static_longhand_id_set("LOGICAL", lambda p: p.logical)}
|
LonghandIdSet::logical().contains(self)
|
||||||
LOGICAL.contains(*self)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If this is a logical property, return the corresponding physical one in
|
/// If this is a logical property, return the corresponding physical one in
|
||||||
|
@ -1157,12 +1195,7 @@ impl LonghandId {
|
||||||
/// colors are disabled.
|
/// colors are disabled.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn ignored_when_document_colors_disabled(self) -> bool {
|
fn ignored_when_document_colors_disabled(self) -> bool {
|
||||||
${static_longhand_id_set(
|
LonghandIdSet::ignored_when_colors_disabled().contains(self)
|
||||||
"IGNORED_WHEN_COLORS_DISABLED",
|
|
||||||
lambda p: p.ignored_when_colors_disabled
|
|
||||||
)}
|
|
||||||
|
|
||||||
IGNORED_WHEN_COLORS_DISABLED.contains(self)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The computed value of some properties depends on the (sometimes
|
/// The computed value of some properties depends on the (sometimes
|
||||||
|
|
|
@ -1288,25 +1288,12 @@ impl StrongRuleNode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If author colors are not allowed, only claim to have author-specified
|
// If author colors are not allowed, don't look at those properties
|
||||||
// rules if we're looking at a non-color property, a border image, or if
|
// (except for background-color which is special and we handle below).
|
||||||
// we're looking at the background color and it's set to transparent.
|
|
||||||
const IGNORED_WHEN_COLORS_DISABLED: &'static [LonghandId] = &[
|
|
||||||
LonghandId::BackgroundImage,
|
|
||||||
LonghandId::BorderImageSource,
|
|
||||||
LonghandId::BorderTopColor,
|
|
||||||
LonghandId::BorderRightColor,
|
|
||||||
LonghandId::BorderBottomColor,
|
|
||||||
LonghandId::BorderLeftColor,
|
|
||||||
LonghandId::BorderInlineStartColor,
|
|
||||||
LonghandId::BorderInlineEndColor,
|
|
||||||
LonghandId::BorderBlockStartColor,
|
|
||||||
LonghandId::BorderBlockEndColor,
|
|
||||||
];
|
|
||||||
|
|
||||||
if !author_colors_allowed {
|
if !author_colors_allowed {
|
||||||
for id in IGNORED_WHEN_COLORS_DISABLED {
|
properties.remove_all(LonghandIdSet::ignored_when_colors_disabled());
|
||||||
properties.remove(*id);
|
if rule_type_mask & NS_AUTHOR_SPECIFIED_BACKGROUND != 0 {
|
||||||
|
properties.insert(LonghandId::BackgroundColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue