Bug 1349651 - Implement author_colors_allowed in has_author_specified_rules. r=bholley
MozReview-Commit-ID: IWaSpplJQ4r
--- a/servo/components/style/rule_tree/mod.rs
+++ b/servo/components/style/rule_tree/mod.rs
@@ -795,24 +795,27 @@ impl StrongRuleNode {
/// Implementation of `nsRuleNode::HasAuthorSpecifiedRules` for Servo rule nodes.
///
/// Returns true if any properties specified by `rule_type_mask` was set by an author rule.
#[cfg(feature = "gecko")]
pub fn has_author_specified_rules<E>(&self,
mut element: E,
guards: &StylesheetGuards,
rule_type_mask: u32,
- _author_colors_allowed: bool)
+ author_colors_allowed: bool)
-> bool
where E: ::dom::TElement
{
- use properties::{CSSWideKeyword, LonghandId, LonghandIdSet, PropertyDeclarationId};
+ use cssparser::RGBA;
+ use properties::{CSSWideKeyword, LonghandId, LonghandIdSet};
+ use properties::{PropertyDeclaration, PropertyDeclarationId};
use std::borrow::Cow;
use gecko_bindings::structs::{NS_AUTHOR_SPECIFIED_BACKGROUND, NS_AUTHOR_SPECIFIED_BORDER};
use gecko_bindings::structs::{NS_AUTHOR_SPECIFIED_PADDING, NS_AUTHOR_SPECIFIED_TEXT_SHADOW};
+ use values::specified::Color;
// Reset properties:
const BACKGROUND_PROPS: &'static [LonghandId] = &[
LonghandId::BackgroundColor,
LonghandId::BackgroundImage,
];
const BORDER_PROPS: &'static [LonghandId] = &[
@@ -869,16 +872,34 @@ impl StrongRuleNode {
}
}
if rule_type_mask & NS_AUTHOR_SPECIFIED_TEXT_SHADOW != 0 {
for id in TEXT_SHADOW_PROPS {
properties.insert(*id);
}
}
+ // If author colors are not allowed, only claim to have author-specified rules if we're
+ // looking at a non-color property or if we're looking at the background color and it's
+ // set to transparent.
+ const IGNORED_WHEN_COLORS_DISABLED: &'static [LonghandId] = &[
+ LonghandId::BackgroundImage,
+ LonghandId::BorderTopColor,
+ LonghandId::BorderRightColor,
+ LonghandId::BorderBottomColor,
+ LonghandId::BorderLeftColor,
+ LonghandId::TextShadow,
+ ];
+
+ if !author_colors_allowed {
+ for id in IGNORED_WHEN_COLORS_DISABLED {
+ properties.remove(*id);
+ }
+ }
+
let mut element_rule_node = Cow::Borrowed(self);
loop {
// We need to be careful not to count styles covered up by user-important or
// UA-important declarations. But we do want to catch explicit inherit styling in
// those and check our parent element to see whether we have user styling for
// those properties. Note that we don't care here about inheritance due to lack of
// a specified value, since all the properties we care about are reset properties.
@@ -937,18 +958,23 @@ impl StrongRuleNode {
CascadeLevel::PresHints |
CascadeLevel::AuthorNormal |
CascadeLevel::StyleAttributeNormal |
CascadeLevel::SMILOverride |
CascadeLevel::Animations |
CascadeLevel::AuthorImportant |
CascadeLevel::StyleAttributeImportant |
CascadeLevel::Transitions => {
- for (id, _) in longhands {
+ for (id, declaration) in longhands {
if properties.contains(id) {
+ if !author_colors_allowed {
+ if let PropertyDeclaration::BackgroundColor(ref color) = *declaration {
+ return color.parsed == Color::RGBA(RGBA::transparent())
+ }
+ }
return true
}
}
}
}
}
if !have_explicit_ua_inherit { break }