Bug 1252611 - Hoist IsComplete/SetComplete into StyleSheet. r=dholbert
authorBobby Holley <bobbyholley@gmail.com>
Tue, 01 Mar 2016 15:10:45 -0800
changeset 288173 7d0edeb440b70b63aff7dbf3db49d4bea9c822a7
parent 288172 c495729654274a86581f398402cb1cab65bb8dfb
child 288174 850adf08932f5e50f43a97f0fb47538de620b46e
push id73340
push userbobbyholley@gmail.com
push dateFri, 11 Mar 2016 06:19:35 +0000
treeherdermozilla-inbound@7d0edeb440b7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1252611
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1252611 - Hoist IsComplete/SetComplete into StyleSheet. r=dholbert
layout/style/CSSStyleSheet.cpp
layout/style/CSSStyleSheet.h
layout/style/Loader.cpp
layout/style/ServoStyleSheet.cpp
layout/style/ServoStyleSheet.h
layout/style/StyleSheet.cpp
layout/style/StyleSheet.h
layout/style/StyleSheetHandle.h
layout/style/StyleSheetHandleInlines.h
layout/style/StyleSheetInfo.h
layout/style/StyleSheetInlines.h
layout/style/nsLayoutStylesheetCache.cpp
--- a/layout/style/CSSStyleSheet.cpp
+++ b/layout/style/CSSStyleSheet.cpp
@@ -7,17 +7,16 @@
 /* representation of a CSS style sheet */
 
 #include "mozilla/CSSStyleSheet.h"
 
 #include "nsIAtom.h"
 #include "nsCSSRuleProcessor.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/dom/Element.h"
-#include "mozilla/dom/ShadowRoot.h"
 #include "mozilla/dom/MediaListBinding.h"
 #include "mozilla/css/NameSpaceRule.h"
 #include "mozilla/css/GroupRule.h"
 #include "mozilla/css/ImportRule.h"
 #include "nsCSSRules.h"
 #include "nsIMediaList.h"
 #include "nsIDocument.h"
 #include "nsPresContext.h"
@@ -1405,42 +1404,16 @@ CSSStyleSheet::SetEnabled(bool aEnabled)
     ClearRuleCascades();
 
     if (mDocument) {
       mDocument->SetStyleSheetApplicableState(this, !mDisabled);
     }
   }
 }
 
-bool
-CSSStyleSheet::IsComplete() const
-{
-  return mInner->mComplete;
-}
-
-void
-CSSStyleSheet::SetComplete()
-{
-  NS_ASSERTION(!mDirty, "Can't set a dirty sheet complete!");
-  mInner->mComplete = true;
-  if (mDocument && !mDisabled) {
-    // Let the document know
-    mDocument->BeginUpdate(UPDATE_STYLE);
-    mDocument->SetStyleSheetApplicableState(this, true);
-    mDocument->EndUpdate(UPDATE_STYLE);
-  }
-
-  if (mOwningNode && !mDisabled &&
-      mOwningNode->HasFlag(NODE_IS_IN_SHADOW_TREE) &&
-      mOwningNode->IsContent()) {
-    ShadowRoot* shadowRoot = mOwningNode->AsContent()->GetContainingShadow();
-    shadowRoot->StyleSheetChanged();
-  }
-}
-
 CSSStyleSheet*
 CSSStyleSheet::GetParentSheet() const
 {
   return mParent;
 }
 
 nsIDocument*
 CSSStyleSheet::GetOwningDocument() const
--- a/layout/style/CSSStyleSheet.h
+++ b/layout/style/CSSStyleSheet.h
@@ -144,22 +144,16 @@ public:
    * its new applicable state if the state changes but WILL NOT call
    * BeginUpdate() or EndUpdate() on the document -- calling those is
    * the caller's responsibility.  This allows use of SetEnabled when
    * batched updates are desired.  If you want updates handled for
    * you, see nsIDOMStyleSheet::SetDisabled().
    */
   void SetEnabled(bool aEnabled);
 
-  /**
-   * Whether the sheet is complete.
-   */
-  bool IsComplete() const;
-  void SetComplete();
-
   // style sheet owner info
   CSSStyleSheet* GetParentSheet() const;  // may be null
   nsIDocument* GetOwningDocument() const;  // may be null
   void SetOwningDocument(nsIDocument* aDocument);
 
   // Find the ID of the owner inner window.
   uint64_t FindOwningWindowInnerID() const;
 #ifdef DEBUG
--- a/layout/style/Loader.cpp
+++ b/layout/style/Loader.cpp
@@ -1873,17 +1873,17 @@ Loader::DoSheetComplete(SheetLoadData* a
   while (data) {
     if (!data->mSheetAlreadyComplete) {
       // If mSheetAlreadyComplete, then the sheet could well be modified between
       // when we posted the async call to SheetComplete and now, since the sheet
       // was page-accessible during that whole time.
       MOZ_ASSERT(!(data->mSheet->IsGecko() &&
                    data->mSheet->AsGecko()->IsModified()),
                  "should not get marked modified during parsing");
-      data->mSheet->SetComplete();
+      data->mSheet->AsStyleSheet()->SetComplete();
       data->ScheduleLoadEventIfNeeded(aStatus);
     }
     if (data->mMustNotify && (data->mObserver || !mObservers.IsEmpty())) {
       // Don't notify here so we don't trigger script.  Remember the
       // info we need to notify, then do it later when it's safe.
       aDatasToNotify.AppendElement(data);
 
       // On append failure, just press on.  We'll fail to notify the observer,
--- a/layout/style/ServoStyleSheet.cpp
+++ b/layout/style/ServoStyleSheet.cpp
@@ -23,27 +23,16 @@ ServoStyleSheet::~ServoStyleSheet()
 }
 
 bool
 ServoStyleSheet::IsApplicable() const
 {
   return !mDisabled && mComplete;
 }
 
-void
-ServoStyleSheet::SetComplete()
-{
-  MOZ_ASSERT(!mComplete);
-
-  mComplete = true;
-
-  NS_ERROR("stylo: ServoStyleSheet::SetComplete should do the things "
-           "CSSStyleSheet::SetComplete does");
-}
-
 bool
 ServoStyleSheet::HasRules() const
 {
   return Servo_StyleSheetHasRules(RawSheet());
 }
 
 nsIDocument*
 ServoStyleSheet::GetOwningDocument() const
--- a/layout/style/ServoStyleSheet.h
+++ b/layout/style/ServoStyleSheet.h
@@ -26,17 +26,16 @@ class ServoStyleSheet : public StyleShee
 public:
   ServoStyleSheet(CORSMode aCORSMode,
                   net::ReferrerPolicy aReferrerPolicy,
                   const dom::SRIMetadata& aIntegrity);
 
   NS_INLINE_DECL_REFCOUNTING(ServoStyleSheet)
 
   bool IsApplicable() const;
-  void SetComplete();
   bool HasRules() const;
 
   nsIDocument* GetOwningDocument() const;
   void SetOwningDocument(nsIDocument* aDocument);
 
   StyleSheetHandle GetParentSheet() const;
   void AppendStyleSheet(StyleSheetHandle aSheet);
 
--- a/layout/style/StyleSheet.cpp
+++ b/layout/style/StyleSheet.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/StyleSheet.h"
 
+#include "mozilla/dom/ShadowRoot.h"
 #include "mozilla/ServoStyleSheet.h"
 #include "mozilla/StyleSheetInlines.h"
 #include "mozilla/CSSStyleSheet.h"
 
 namespace mozilla {
 
 StyleSheet::StyleSheet(StyleBackendType aType)
   : mDocument(nullptr)
@@ -27,16 +28,42 @@ StyleSheet::StyleSheet(const StyleSheet&
   : mDocument(aDocumentToUse)
   , mOwningNode(aOwningNodeToUse)
   , mParsingMode(aCopy.mParsingMode)
   , mType(aCopy.mType)
   , mDisabled(aCopy.mDisabled)
 {
 }
 
+bool
+StyleSheet::IsComplete() const
+{
+  return SheetInfo().mComplete;
+}
+
+void
+StyleSheet::SetComplete()
+{
+  NS_ASSERTION(!IsGecko() || !AsGecko().mDirty, "Can't set a dirty sheet complete!");
+  SheetInfo().mComplete = true;
+  if (mDocument && !mDisabled) {
+    // Let the document know
+    mDocument->BeginUpdate(UPDATE_STYLE);
+    mDocument->SetStyleSheetApplicableState(AsHandle(), true);
+    mDocument->EndUpdate(UPDATE_STYLE);
+  }
+
+  if (mOwningNode && !mDisabled &&
+      mOwningNode->HasFlag(NODE_IS_IN_SHADOW_TREE) &&
+      mOwningNode->IsContent()) {
+    ShadowRoot* shadowRoot = mOwningNode->AsContent()->GetContainingShadow();
+    shadowRoot->StyleSheetChanged();
+  }
+}
+
 StyleSheetInfo&
 StyleSheet::SheetInfo()
 {
   if (IsServo()) {
     return AsServo();
   }
   return *AsGecko().mInner;
 }
--- a/layout/style/StyleSheet.h
+++ b/layout/style/StyleSheet.h
@@ -4,16 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_StyleSheet_h
 #define mozilla_StyleSheet_h
 
 #include "mozilla/css/SheetParsingMode.h"
 #include "mozilla/StyleBackendType.h"
+#include "mozilla/StyleSheetHandle.h"
 #include "mozilla/StyleSheetInfo.h"
 
 class nsIDocument;
 class nsINode;
 
 namespace mozilla {
 
 class CSSStyleSheet;
@@ -41,16 +42,22 @@ public:
     mParsingMode = aParsingMode;
   }
 
   nsINode* GetOwnerNode() const { return mOwningNode; }
 
   // The document this style sheet is associated with.  May be null
   nsIDocument* GetDocument() const { return mDocument; }
 
+  /**
+   * Whether the sheet is complete.
+   */
+  bool IsComplete() const;
+  void SetComplete();
+
   // Get a handle to the various stylesheet bits which live on the 'inner' for
   // gecko stylesheets and live on the StyleSheet for Servo stylesheets.
   StyleSheetInfo& SheetInfo();
   const StyleSheetInfo& SheetInfo() const { return const_cast<StyleSheet*>(this)->SheetInfo(); };
 
   bool IsGecko() const { return !IsServo(); }
   bool IsServo() const
   {
@@ -60,16 +67,17 @@ public:
     return false;
 #endif
   }
 
   // Only safe to call if the caller has verified that that |this| is of the
   // correct type.
   inline CSSStyleSheet& AsGecko();
   inline ServoStyleSheet& AsServo();
+  inline StyleSheetHandle AsHandle();
 
 protected:
   nsIDocument*          mDocument; // weak ref; parents maintain this for their children
   nsINode*              mOwningNode; // weak ref
   css::SheetParsingMode mParsingMode;
   StyleBackendType      mType;
   bool                  mDisabled;
 };
--- a/layout/style/StyleSheetHandle.h
+++ b/layout/style/StyleSheetHandle.h
@@ -14,16 +14,17 @@
 #include "mozilla/RefCountType.h"
 
 namespace mozilla {
 namespace dom {
 class SRIMetadata;
 } // namespace dom
 class CSSStyleSheet;
 class ServoStyleSheet;
+class StyleSheet;
 } // namespace mozilla
 class nsIDocument;
 class nsIPrincipal;
 class nsIURI;
 
 namespace mozilla {
 
 #define SERVO_BIT 0x1
@@ -52,16 +53,19 @@ public:
       MOZ_ASSERT(mValue);
 #ifdef MOZ_STYLO
       return mValue & SERVO_BIT;
 #else
       return false;
 #endif
     }
 
+    inline StyleSheet* AsStyleSheet();
+    inline const StyleSheet* AsStyleSheet() const;
+
     CSSStyleSheet* AsGecko()
     {
       MOZ_ASSERT(IsGecko());
       return reinterpret_cast<CSSStyleSheet*>(mValue);
     }
 
     ServoStyleSheet* AsServo()
     {
@@ -100,17 +104,16 @@ public:
     // CSSStyleSheet or ServoStyleSheet.  See corresponding comments in
     // CSSStyleSheet.h for descriptions of these methods.
 
     inline nsIURI* GetSheetURI() const;
     inline nsIURI* GetOriginalURI() const;
     inline nsIURI* GetBaseURI() const;
     inline void SetURIs(nsIURI* aSheetURI, nsIURI* aOriginalSheetURI, nsIURI* aBaseURI);
     inline bool IsApplicable() const;
-    inline void SetComplete();
     inline void SetParsingMode(css::SheetParsingMode aMode);
     inline bool HasRules() const;
     inline nsIDocument* GetOwningDocument() const;
     inline void SetOwningDocument(nsIDocument* aDocument);
     inline nsINode* GetOwnerNode() const;
     inline void SetOwningNode(nsINode* aNode);
     inline StyleSheetHandle GetParentSheet() const;
     inline void AppendStyleSheet(StyleSheetHandle aSheet);
--- a/layout/style/StyleSheetHandleInlines.h
+++ b/layout/style/StyleSheetHandleInlines.h
@@ -16,16 +16,31 @@
   } else { \
     return AsServo()->method_ servoargs_; \
   }
 
 #define FORWARD(method_, args_) FORWARD_CONCRETE(method_, args_, args_)
 
 namespace mozilla {
 
+StyleSheet*
+StyleSheetHandle::Ptr::AsStyleSheet()
+{
+  if (IsServo()) {
+    return AsServo();
+  }
+  return AsGecko();
+}
+
+const StyleSheet*
+StyleSheetHandle::Ptr::AsStyleSheet() const
+{
+  return const_cast<Ptr*>(this)->AsStyleSheet();
+}
+
 MozExternalRefCountType
 StyleSheetHandle::Ptr::AddRef()
 {
   FORWARD(AddRef, ());
 }
 
 MozExternalRefCountType
 StyleSheetHandle::Ptr::Release()
@@ -59,22 +74,16 @@ StyleSheetHandle::Ptr::SetURIs(nsIURI* a
 
 bool
 StyleSheetHandle::Ptr::IsApplicable() const
 {
   FORWARD(IsApplicable, ());
 }
 
 void
-StyleSheetHandle::Ptr::SetComplete()
-{
-  FORWARD(SetComplete, ());
-}
-
-void
 StyleSheetHandle::Ptr::SetParsingMode(css::SheetParsingMode aMode)
 {
   FORWARD(SetParsingMode, (aMode));
 }
 
 bool
 StyleSheetHandle::Ptr::HasRules() const
 {
--- a/layout/style/StyleSheetInfo.h
+++ b/layout/style/StyleSheetInfo.h
@@ -56,13 +56,15 @@ protected:
   // The Referrer Policy of a stylesheet is used for its child sheets, so it is
   // stored here.
   ReferrerPolicy         mReferrerPolicy;
   dom::SRIMetadata       mIntegrity;
   bool                   mComplete;
 #ifdef DEBUG
   bool                   mPrincipalSet;
 #endif
+
+  friend class StyleSheet;
 };
 
 } // namespace mozilla
 
 #endif // mozilla_StyleSheetInfo_h
--- a/layout/style/StyleSheetInlines.h
+++ b/layout/style/StyleSheetInlines.h
@@ -21,11 +21,20 @@ StyleSheet::AsGecko()
 
 ServoStyleSheet&
 StyleSheet::AsServo()
 {
   MOZ_ASSERT(IsServo());
   return *static_cast<ServoStyleSheet*>(this);
 }
 
+StyleSheetHandle
+StyleSheet::AsHandle()
+{
+  if (IsServo()) {
+    return &AsServo();
+  }
+  return &AsGecko();
+}
+
 }
 
 #endif // mozilla_StyleSheetInlines_h
--- a/layout/style/nsLayoutStylesheetCache.cpp
+++ b/layout/style/nsLayoutStylesheetCache.cpp
@@ -848,17 +848,17 @@ nsLayoutStylesheetCache::BuildPreference
 
   aSheet->SetParsingMode(eAgentSheetFeatures);
 
   nsCOMPtr<nsIURI> uri;
   NS_NewURI(getter_AddRefs(uri), "about:PreferenceStyleSheet", nullptr);
   MOZ_ASSERT(uri, "URI creation shouldn't fail");
 
   aSheet->SetURIs(uri, uri, uri);
-  aSheet->SetComplete();
+  aSheet->AsStyleSheet()->SetComplete();
 
   static const uint32_t kPreallocSize = 1024;
 
   nsString sheetText;
   sheetText.SetCapacity(kPreallocSize);
 
 #define NS_GET_R_G_B(color_) \
   NS_GET_R(color_), NS_GET_G(color_), NS_GET_B(color_)