From 95033e1c0d672cc52c85092fcd0f4398ee896f30 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Wed, 31 Aug 2016 13:41:38 +0200 Subject: [PATCH] Add any_important and any_normal methods to PropertyDeclarationBlock --- .../style/properties/properties.mako.rs | 20 +++++++++++++++++++ components/style/selector_matching.rs | 8 ++++---- ports/geckolib/wrapper.rs | 2 +- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index c8be3470ede..09809cdc113 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -292,6 +292,26 @@ pub struct PropertyDeclarationBlock { pub important_count: u32, } +impl PropertyDeclarationBlock { + /// Returns wheather this block contains any declaration with `!important`. + /// + /// This is based on the `important_count` counter, + /// which should be maintained whenever `declarations` is changed. + // FIXME: make fields private and maintain it here in methods? + pub fn any_important(&self) -> bool { + self.important_count > 0 + } + + /// Returns wheather this block contains any declaration without `!important`. + /// + /// This is based on the `important_count` counter, + /// which should be maintained whenever `declarations` is changed. + // FIXME: make fields private and maintain it here in methods? + pub fn any_normal(&self) -> bool { + self.declarations.len() > self.important_count as usize + } +} + impl ToCss for PropertyDeclarationBlock { // https://drafts.csswg.org/cssom/#serialize-a-css-declaration-block fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { diff --git a/components/style/selector_matching.rs b/components/style/selector_matching.rs index da056e68e22..0fd1d01453e 100644 --- a/components/style/selector_matching.rs +++ b/components/style/selector_matching.rs @@ -398,7 +398,7 @@ impl Stylist { // Step 4: Normal style attributes. if let Some(sa) = style_attribute { - if sa.declarations.len() > sa.important_count as usize { + if sa.any_normal() { relations |= AFFECTED_BY_STYLE_ATTRIBUTE; Push::push( applicable_declarations, @@ -419,7 +419,7 @@ impl Stylist { // Step 6: `!important` style attributes. if let Some(sa) = style_attribute { - if sa.important_count > 0 { + if sa.any_important() { relations |= AFFECTED_BY_STYLE_ATTRIBUTE; Push::push( applicable_declarations, @@ -764,9 +764,9 @@ impl SelectorMap { for rule in rules.iter() { let block = &rule.declarations.mixed_declarations; let any_declaration_for_importance = if importance.important() { - block.important_count > 0 + block.any_important() } else { - block.declarations.len() > block.important_count as usize + block.any_normal() }; if any_declaration_for_importance && matches_complex_selector(&*rule.selector, diff --git a/ports/geckolib/wrapper.rs b/ports/geckolib/wrapper.rs index 0c209c8b926..4d818c63db9 100644 --- a/ports/geckolib/wrapper.rs +++ b/ports/geckolib/wrapper.rs @@ -473,7 +473,7 @@ impl<'le> TElement for GeckoElement<'le> { None } else { let opt_ptr = GeckoDeclarationBlock::with(declarations, |declarations| { - // Use a raw poointer to extend the lifetime + // Use a raw pointer to extend the lifetime declarations.declarations.as_ref().map(|r| r as *const Arc<_>) }); opt_ptr.map(|ptr| unsafe { &*ptr })