Bug 1346256 Part 4: Change GetCSSStyleRules to pull servo style data directly from the element. draft
authorBrad Werth <bwerth@mozilla.com>
Mon, 27 Mar 2017 13:13:26 -0700
changeset 552063 616ed1506ab6409addc1189f10236cb0a4273a22
parent 552062 d1cf13d8f78bc4c2eb826e835ac682784a27b88a
child 621715 ccc07b43ef0f0b6c11c6da89f28cccd8c9fd1e3c
push id51235
push userbwerth@mozilla.com
push dateMon, 27 Mar 2017 22:28:44 +0000
bugs1346256
milestone55.0a1
Bug 1346256 Part 4: Change GetCSSStyleRules to pull servo style data directly from the element. MozReview-Commit-ID: 9cNOSziJ52d
layout/inspector/inDOMUtils.cpp
layout/inspector/inIDOMUtils.idl
--- a/layout/inspector/inDOMUtils.cpp
+++ b/layout/inspector/inDOMUtils.cpp
@@ -47,16 +47,18 @@
 #include "nsCSSParser.h"
 #include "nsCSSProps.h"
 #include "nsCSSValue.h"
 #include "nsColor.h"
 #include "mozilla/StyleSetHandle.h"
 #include "mozilla/StyleSetHandleInlines.h"
 #include "nsStyleUtil.h"
 #include "nsQueryObject.h"
+#include "mozilla/ServoBindings.h"
+#include "mozilla/ServoStyleRule.h"
 
 using namespace mozilla;
 using namespace mozilla::css;
 using namespace mozilla::dom;
 
 ///////////////////////////////////////////////////////////////////////////////
 
 inDOMUtils::inDOMUtils()
@@ -238,17 +240,21 @@ inDOMUtils::GetCSSStyleRules(nsIDOMEleme
     GetCleanStyleContextForElement(element, pseudoElt);
   if (!styleContext) {
     // This can fail for elements that are not in the document or
     // if the document they're in doesn't have a presshell.  Bail out.
     return NS_OK;
   }
 
   NonOwningStyleContextSource source = styleContext->StyleSource();
-  if (!source.IsNull() && source.IsGeckoRuleNodeOrNull()) {
+  if (source.IsNull()) {
+    return NS_OK;
+  }
+
+  if (source.IsGeckoRuleNodeOrNull()) {
     nsRuleNode* ruleNode = source.AsGeckoRuleNode();
 
     AutoTArray<nsRuleNode*, 16> ruleNodes;
     while (!ruleNode->IsRoot()) {
       ruleNodes.AppendElement(ruleNode);
       ruleNode = ruleNode->GetParent();
     }
 
@@ -259,16 +265,42 @@ inDOMUtils::GetCSSStyleRules(nsIDOMEleme
         css::Rule* owningRule = decl->GetOwningRule();
         if (owningRule) {
           rules->AppendElement(owningRule, /*weak =*/ false);
         }
       }
     }
 
     rules.forget(_retval);
+  } else {
+    // element may contain a ServoStyleSourceList
+    ServoStyleSourceList* styleSourceList = Servo_Element_GetStyleSourceList(element);
+    if (!styleSourceList) {
+      return NS_OK;
+    }
+
+    nsCOMPtr<nsIMutableArray> rules = nsArray::Create();
+
+    size_t length = Servo_StyleSourceList_Length(styleSourceList);
+    for (size_t i = 0; i < length; i++) {
+      RawServoStyleRuleStrong strongRule = Servo_StyleSourceList_GetStyleRuleAt(styleSourceList, i);
+      if (strongRule.mPtr) {
+        RefPtr<css::Rule> ruleObj = new ServoStyleRule(strongRule.Consume());
+        rules->AppendElement(ruleObj, false);
+      }
+
+      // If not a style rule, then it is a declaration block. But any
+      // declaration blocks that have an owning rule would already be captured
+      // by the call to Servo_StyleSourceList_GetStyleRuleAt. So no rule =
+      // no object added to the result.
+    }
+
+    Servo_StyleSourceList_Drop(styleSourceList);
+
+    rules.forget(_retval);
   }
 
   return NS_OK;
 }
 
 static already_AddRefed<StyleRule>
 GetRuleFromDOMRule(nsIDOMCSSStyleRule *aRule, ErrorResult& rv)
 {
--- a/layout/inspector/inIDOMUtils.idl
+++ b/layout/inspector/inIDOMUtils.idl
@@ -19,16 +19,18 @@ interface nsIDOMCSSStyleSheet;
 
 [scriptable, uuid(362e98c3-82c2-4ad8-8dcb-00e8e4eab497)]
 interface inIDOMUtils : nsISupports
 {
   // CSS utilities
   void getAllStyleSheets (in nsIDOMDocument aDoc,
                           [optional] out unsigned long aLength,
                           [array, size_is (aLength), retval] out nsISupports aSheets);
+  // The array of rules returned by this method may not be the same objects
+  // returned by CSSOM methods.
   nsIArrayExtensions getCSSStyleRules(in nsIDOMElement aElement, [optional] in DOMString aPseudo);
 
   /**
    * Get the line number of a rule.
    *
    * @param nsIDOMCSSRule aRule The rule.
    * @return The rule's line number.  Line numbers are 1-based.
    */