Bug 1349651 - Implement author_colors_allowed in has_author_specified_rules. r=bholley draft
authorMatt Brubeck <mbrubeck@mozilla.com>
Sun, 07 May 2017 17:41:50 -0700
changeset 574515 3ffd9bcb8e9cde10c362d0d40e3fea8d103ab0bb
parent 574514 f578337b6a0df7bd1fbe0ec2722e3bd311df6dfb
child 627625 07c3b2fd85a32af226c9909f5ec13fb583eebd75
push id57739
push userbmo:mbrubeck@mozilla.com
push dateTue, 09 May 2017 00:00:11 +0000
reviewersbholley
bugs1349651
milestone55.0a1
Bug 1349651 - Implement author_colors_allowed in has_author_specified_rules. r=bholley MozReview-Commit-ID: IWaSpplJQ4r
servo/components/style/rule_tree/mod.rs
--- 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 }