Bug 1363640 Part 1 - Move IsContentDocument() and IsTopLevelContentDocument() from nsDocument to nsIDocument. draft
authorTing-Yu Lin <tlin@mozilla.com>
Tue, 09 May 2017 18:28:36 -0700
changeset 583790 09f034b8b9b9cc8647c322c9866691cf0dbc5ed9
parent 583751 1a735bdbbfa9a11e78b7e977d45cf00af85e7b66
child 583791 aea94616d571fa3726c52bf026d222b4ef7ea6ac
push id60548
push userbmo:tlin@mozilla.com
push dateWed, 24 May 2017 17:00:28 +0000
bugs1363640
milestone55.0a1
Bug 1363640 Part 1 - Move IsContentDocument() and IsTopLevelContentDocument() from nsDocument to nsIDocument. In this way, the callers who have nsIDocument don't need to cast to nsDocument. MozReview-Commit-ID: 8zVUjkbrlaG
dom/base/nsDocument.cpp
dom/base/nsDocument.h
dom/base/nsIDocument.h
layout/base/nsLayoutUtils.cpp
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -1337,16 +1337,18 @@ nsIDocument::nsIDocument()
     mDidDocumentOpen(false),
     mHasDisplayDocument(false),
     mFontFaceSetDirty(true),
     mGetUserFontSetCalled(false),
     mPostedFlushUserFontSet(false),
     mDidFireDOMContentLoaded(true),
     mHasScrollLinkedEffect(false),
     mFrameRequestCallbacksScheduled(false),
+    mIsTopLevelContentDocument(false),
+    mIsContentDocument(false),
     mCompatMode(eCompatibility_FullStandards),
     mReadyState(ReadyState::READYSTATE_UNINITIALIZED),
     mStyleBackendType(StyleBackendType::None),
 #ifdef MOZILLA_INTERNAL_API
     mVisibilityState(dom::VisibilityState::Hidden),
 #else
     mDummy(0),
 #endif
@@ -1375,18 +1377,16 @@ nsIDocument::nsIDocument()
     mNotifiedPageForUseCounter(0),
     mUserHasInteracted(false)
 {
   SetIsInDocument();
 }
 
 nsDocument::nsDocument(const char* aContentType)
   : nsIDocument()
-  , mIsTopLevelContentDocument(false)
-  , mIsContentDocument(false)
   , mSubDocuments(nullptr)
   , mFlashClassification(FlashClassification::Unclassified)
   , mHeaderData(nullptr)
   , mIsGoingAway(false)
   , mInDestructor(false)
   , mMayHaveTitleElement(false)
   , mHasWarnedAboutBoxObjects(false)
   , mDelayFrameLoaderInitialization(false)
@@ -4965,40 +4965,16 @@ nsDocument::SetScriptHandlingObject(nsIS
                mScriptGlobalObject == aScriptObject,
                "Wrong script object!");
   if (aScriptObject) {
     SetScopeObject(aScriptObject);
     mHasHadDefaultView = false;
   }
 }
 
-bool
-nsDocument::IsTopLevelContentDocument()
-{
-  return mIsTopLevelContentDocument;
-}
-
-void
-nsDocument::SetIsTopLevelContentDocument(bool aIsTopLevelContentDocument)
-{
-  mIsTopLevelContentDocument = aIsTopLevelContentDocument;
-}
-
-bool
-nsDocument::IsContentDocument() const
-{
-  return mIsContentDocument;
-}
-
-void
-nsDocument::SetIsContentDocument(bool aIsContentDocument)
-{
-  mIsContentDocument = aIsContentDocument;
-}
-
 nsPIDOMWindowOuter*
 nsDocument::GetWindowInternal() const
 {
   MOZ_ASSERT(!mWindow, "This should not be called when mWindow is not null!");
   // Let's use mScriptGlobalObject. Even if the document is already removed from
   // the docshell, the outer window might be still obtainable from the it.
   nsCOMPtr<nsPIDOMWindowOuter> win;
   if (mRemovedFromDocShell) {
@@ -12540,27 +12516,27 @@ nsDocument::Evaluate(const nsAString& aE
 {
   return XPathEvaluator()->Evaluate(aExpression, aContextNode, aResolver, aType,
                                     aInResult, aResult);
 }
 
 nsIDocument*
 nsIDocument::GetTopLevelContentDocument()
 {
-  nsDocument* parent;
+  nsIDocument* parent;
 
   if (!mLoadedAsData) {
-    parent = static_cast<nsDocument*>(this);
+    parent = this;
   } else {
     nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(GetScopeObject());
     if (!window) {
       return nullptr;
     }
 
-    parent = static_cast<nsDocument*>(window->GetExtantDoc());
+    parent = window->GetExtantDoc();
     if (!parent) {
       return nullptr;
     }
   }
 
   do {
     if (parent->IsTopLevelContentDocument()) {
       break;
--- a/dom/base/nsDocument.h
+++ b/dom/base/nsDocument.h
@@ -1338,25 +1338,16 @@ protected:
   Element* GetTitleElement();
 
 public:
   // Get our title
   virtual void GetTitle(nsString& aTitle) override;
   // Set our title
   virtual void SetTitle(const nsAString& aTitle, mozilla::ErrorResult& rv) override;
 
-  bool mIsTopLevelContentDocument: 1;
-  bool mIsContentDocument: 1;
-
-  bool IsTopLevelContentDocument();
-  void SetIsTopLevelContentDocument(bool aIsTopLevelContentDocument);
-
-  bool IsContentDocument() const;
-  void SetIsContentDocument(bool aIsContentDocument);
-
   js::ExpandoAndGeneration mExpandoAndGeneration;
 
   bool ContainsEMEContent();
 
   bool ContainsMSEContent();
 
 protected:
   void RemoveDocStyleSheetsFromStyleSets();
--- a/dom/base/nsIDocument.h
+++ b/dom/base/nsIDocument.h
@@ -1657,16 +1657,28 @@ public:
   }
   bool LoadsFullXULStyleSheetUpFront()
   {
     return IsXULDocument() || AllowXULXBL();
   }
 
   virtual bool IsScriptEnabled() = 0;
 
+  bool IsTopLevelContentDocument() const { return mIsTopLevelContentDocument; }
+  void SetIsTopLevelContentDocument(bool aIsTopLevelContentDocument)
+  {
+    mIsTopLevelContentDocument = aIsTopLevelContentDocument;
+  }
+
+  bool IsContentDocument() const { return mIsContentDocument; }
+  void SetIsContentDocument(bool aIsContentDocument)
+  {
+    mIsContentDocument = aIsContentDocument;
+  }
+
   /**
    * Create an element with the specified name, prefix and namespace ID.
    * Returns null if element name parsing failed.
    */
   virtual already_AddRefed<Element> CreateElem(const nsAString& aName,
                                                nsIAtom* aPrefix,
                                                int32_t aNamespaceID,
                                                const nsAString* aIs = nullptr) = 0;
@@ -3233,16 +3245,20 @@ protected:
   // True if ReportHasScrollLinkedEffect() has been called.
   bool mHasScrollLinkedEffect : 1;
 
   // True if we have frame request callbacks scheduled with the refresh driver.
   // This should generally be updated only via
   // UpdateFrameRequestCallbackSchedulingState.
   bool mFrameRequestCallbacksScheduled : 1;
 
+  bool mIsTopLevelContentDocument : 1;
+
+  bool mIsContentDocument : 1;
+
   // Compatibility mode
   nsCompatibility mCompatMode;
 
   // Our readyState
   ReadyState mReadyState;
 
   // Whether this document has (or will have, once we have a pres shell) a
   // Gecko- or Servo-backed style system.
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -9342,17 +9342,17 @@ nsLayoutUtils::ComputePartialPrerenderAr
 }
 
 
 /* static */ bool
 nsLayoutUtils::SupportsServoStyleBackend(nsIDocument* aDocument)
 {
   return StyloEnabled() &&
          (aDocument->IsHTMLOrXHTML() || aDocument->IsSVGDocument()) &&
-         static_cast<nsDocument*>(aDocument)->IsContentDocument();
+         aDocument->IsContentDocument();
 }
 
 static
 bool
 LineHasNonEmptyContentWorker(nsIFrame* aFrame)
 {
   // Look for non-empty frames, but ignore inline and br frames.
   // For inline frames, descend into the children, if any.