Bug 1386865 part 2 - Collect style rule maps for XBL bindings. r?heycam draft
authorXidorn Quan <me@upsuper.org>
Thu, 03 Aug 2017 16:59:17 +1000
changeset 620280 d902a98bad7bc040cfa2edc967ac4fd3fa8f52df
parent 620175 c0aba3ee494cc39c595bbecb148a30bad728bef4
child 640644 c8997a33ddce0b24571dbf038e3ee8a13282e9a0
push id71980
push userxquan@mozilla.com
push dateThu, 03 Aug 2017 08:52:53 +0000
reviewersheycam
bugs1386865
milestone57.0a1
Bug 1386865 part 2 - Collect style rule maps for XBL bindings. r?heycam MozReview-Commit-ID: HPmZopu1L7Z
layout/inspector/inDOMUtils.cpp
--- a/layout/inspector/inDOMUtils.cpp
+++ b/layout/inspector/inDOMUtils.cpp
@@ -269,23 +269,51 @@ inDOMUtils::GetCSSStyleRules(nsIDOMEleme
     if (!shell) {
       return NS_OK;
     }
 
     ServoStyleContext* servo = styleContext->AsServo();
     nsTArray<const RawServoStyleRule*> rawRuleList;
     Servo_ComputedValues_GetStyleRuleList(servo, &rawRuleList);
 
-    ServoStyleSet* styleSet = shell->StyleSet()->AsServo();
-    ServoStyleRuleMap* map = styleSet->StyleRuleMap();
-    map->EnsureTable();
+    AutoTArray<ServoStyleRuleMap*, 1> maps;
+    {
+      ServoStyleSet* styleSet = shell->StyleSet()->AsServo();
+      ServoStyleRuleMap* map = styleSet->StyleRuleMap();
+      map->EnsureTable();
+      maps.AppendElement(map);
+    }
+
+    // Collect style rule maps for bindings.
+    for (nsIContent* bindingContent = element; bindingContent;
+         bindingContent = bindingContent->GetBindingParent()) {
+      if (nsXBLBinding* binding = bindingContent->GetXBLBinding()) {
+        if (ServoStyleSet* styleSet = binding->GetServoStyleSet()) {
+          ServoStyleRuleMap* map = styleSet->StyleRuleMap();
+          map->EnsureTable();
+          maps.AppendElement(map);
+        }
+      }
+      // Note that we intentionally don't cut off here, unlike when we
+      // do styling, because even if style rules from parent binding
+      // do not apply to the element directly in those cases, their
+      // rules may still show up in the list we get above due to the
+      // inheritance in cascading.
+    }
 
     // Find matching rules in the table.
     for (const RawServoStyleRule* rawRule : Reversed(rawRuleList)) {
-      if (ServoStyleRule* rule = map->Lookup(rawRule)) {
+      ServoStyleRule* rule = nullptr;
+      for (ServoStyleRuleMap* map : maps) {
+        rule = map->Lookup(rawRule);
+        if (rule) {
+          break;
+        }
+      }
+      if (rule) {
         rules->AppendElement(static_cast<css::Rule*>(rule), false);
       } else {
         MOZ_ASSERT_UNREACHABLE("We should be able to map a raw rule to a rule");
       }
     }
   }
 
   rules.forget(_retval);