Bug 1352968 part 7 - Make RuleHasPendingChildSheet a static method of StyleSheet. r=heycam draft
authorXidorn Quan <me@upsuper.org>
Tue, 02 May 2017 11:33:30 +0800
changeset 586232 1895bd31f6c88e1be8c710910dec6e773d1a233d
parent 586231 3f7f683b64f42d22a09138cfe01d8ca42d435aa3
child 586233 cedc65c6376373d54e623dc5cfadaa2de92909cb
push id61334
push userxquan@mozilla.com
push dateTue, 30 May 2017 01:07:29 +0000
reviewersheycam
bugs1352968
milestone55.0a1
Bug 1352968 part 7 - Make RuleHasPendingChildSheet a static method of StyleSheet. r=heycam MozReview-Commit-ID: HPJgsFftT6f
layout/style/CSSStyleSheet.cpp
layout/style/StyleSheet.cpp
layout/style/StyleSheet.h
--- a/layout/style/CSSStyleSheet.cpp
+++ b/layout/style/CSSStyleSheet.cpp
@@ -657,27 +657,16 @@ CSSRuleList*
 CSSStyleSheet::GetCssRulesInternal(ErrorResult& aRv)
 {
   if (!mRuleCollection) {
     mRuleCollection = new CSSRuleListImpl(this);
   }
   return mRuleCollection;
 }
 
-static bool
-RuleHasPendingChildSheet(css::Rule *cssRule)
-{
-  nsCOMPtr<nsIDOMCSSImportRule> importRule(do_QueryInterface(cssRule));
-  NS_ASSERTION(importRule, "Rule which has type IMPORT_RULE and does not implement nsIDOMCSSImportRule!");
-  nsCOMPtr<nsIDOMCSSStyleSheet> childSheet;
-  importRule->GetStyleSheet(getter_AddRefs(childSheet));
-  RefPtr<CSSStyleSheet> cssSheet = do_QueryObject(childSheet);
-  return cssSheet != nullptr && !cssSheet->IsComplete();
-}
-
 uint32_t
 CSSStyleSheet::InsertRuleInternal(const nsAString& aRule,
                                   uint32_t aIndex,
                                   ErrorResult& aRv)
 {
   MOZ_ASSERT(mInner->mComplete);
 
   WillDirty();
--- a/layout/style/StyleSheet.cpp
+++ b/layout/style/StyleSheet.cpp
@@ -796,9 +796,20 @@ StyleSheet::Media()
 // nsWrapperCache
 
 JSObject*
 StyleSheet::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
 {
   return dom::CSSStyleSheetBinding::Wrap(aCx, this, aGivenProto);
 }
 
+/* static */ bool
+StyleSheet::RuleHasPendingChildSheet(css::Rule* aRule)
+{
+  MOZ_ASSERT(aRule->GetType() == css::Rule::IMPORT_RULE);
+  auto rule = static_cast<dom::CSSImportRule*>(aRule);
+  if (StyleSheet* childSheet = rule->GetStyleSheet()) {
+    return !childSheet->IsComplete();
+  }
+  return false;
+}
+
 } // namespace mozilla
--- a/layout/style/StyleSheet.h
+++ b/layout/style/StyleSheet.h
@@ -295,16 +295,19 @@ protected:
   // Unlink our inner, if needed, for cycle collection
   virtual void UnlinkInner();
   // Traverse our inner, if needed, for cycle collection
   virtual void TraverseInner(nsCycleCollectionTraversalCallback &);
 
   void ClearRuleCascades();
   virtual void ClearRuleCascadesInternal() {}
 
+  // Return whether the given @import rule has pending child sheet.
+  static bool RuleHasPendingChildSheet(css::Rule* aRule);
+
   StyleSheet*           mParent;    // weak ref
 
   nsString              mTitle;
   nsIDocument*          mDocument; // weak ref; parents maintain this for their children
   nsINode*              mOwningNode; // weak ref
   dom::CSSImportRule*   mOwnerRule; // weak ref
 
   RefPtr<dom::MediaList> mMedia;