Bug 1467722: Make nsComputedDOMStyle store an actual Element. r?heycam draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Fri, 08 Jun 2018 11:18:51 +0200
changeset 805712 4a3c6220c337fff962dc1020334a966a0d837851
parent 805711 8d6c47f51ca813967a5b196f2465857b633abb2b
child 805713 18fb4c326f63eded18976a90453af328291d0f6f
push id112752
push userbmo:emilio@crisal.io
push dateFri, 08 Jun 2018 12:08:30 +0000
reviewersheycam
bugs1467722
milestone62.0a1
Bug 1467722: Make nsComputedDOMStyle store an actual Element. r?heycam MozReview-Commit-ID: FdfXvPARilD
layout/style/nsComputedDOMStyle.cpp
layout/style/nsComputedDOMStyle.h
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -112,17 +112,17 @@ DocumentNeedsRestyle(
   nsIPresShell* shell = aDocument->GetShell();
   if (!shell) {
     return true;
   }
 
   nsPresContext* presContext = shell->GetPresContext();
   MOZ_ASSERT(presContext);
 
-  // Unfortunately we don't know if the sheet change affects mContent or not, so
+  // Unfortunately we don't know if the sheet change affects mElement or not, so
   // just assume it will and that we need to flush normally.
   ServoStyleSet* styleSet = shell->StyleSet();
   if (styleSet->StyleSheetsHaveChanged()) {
     return true;
   }
 
   // Pending media query updates can definitely change style on the element. For
   // example, if you change the zoom factor and then call getComputedStyle, you
@@ -322,35 +322,35 @@ nsComputedDOMStyle::nsComputedDOMStyle(d
   , mComputedStyleGeneration(0)
   , mExposeVisitedStyle(false)
   , mResolvedComputedStyle(false)
 {
   MOZ_ASSERT(aElement);
   // TODO(emilio, bug 548397, https://github.com/w3c/csswg-drafts/issues/2403):
   // Should use aElement->OwnerDoc() instead.
   mDocumentWeak = do_GetWeakReference(aDocument);
-  mContent = aElement;
+  mElement = aElement;
   mPseudo = nsCSSPseudoElements::GetPseudoAtom(aPseudoElt);
 }
 
 nsComputedDOMStyle::~nsComputedDOMStyle()
 {
   ClearComputedStyle();
 }
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsComputedDOMStyle)
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsComputedDOMStyle)
-  tmp->ClearComputedStyle();  // remove observer before clearing mContent
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mContent)
+  tmp->ClearComputedStyle();  // remove observer before clearing mElement
+  NS_IMPL_CYCLE_COLLECTION_UNLINK(mElement)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsComputedDOMStyle)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mContent)
+  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mElement)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(nsComputedDOMStyle)
 
 NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsComputedDOMStyle)
   return tmp->HasKnownLiveWrapper();
 NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END
 
@@ -792,28 +792,28 @@ nsComputedDOMStyle::GetParsingEnvironmen
   MOZ_CRASH("called nsComputedDOMStyle::GetParsingEnvironment");
 }
 
 void
 nsComputedDOMStyle::ClearComputedStyle()
 {
   if (mResolvedComputedStyle) {
     mResolvedComputedStyle = false;
-    mContent->RemoveMutationObserver(this);
+    mElement->RemoveMutationObserver(this);
   }
   mComputedStyle = nullptr;
 }
 
 void
 nsComputedDOMStyle::SetResolvedComputedStyle(RefPtr<ComputedStyle>&& aContext,
                                             uint64_t aGeneration)
 {
   if (!mResolvedComputedStyle) {
     mResolvedComputedStyle = true;
-    mContent->AddMutationObserver(this);
+    mElement->AddMutationObserver(this);
   }
   mComputedStyle = aContext;
   mComputedStyleGeneration = aGeneration;
 }
 
 void
 nsComputedDOMStyle::SetFrameComputedStyle(mozilla::ComputedStyle* aStyle,
                                          uint64_t aGeneration)
@@ -821,28 +821,28 @@ nsComputedDOMStyle::SetFrameComputedStyl
   ClearComputedStyle();
   mComputedStyle = aStyle;
   mComputedStyleGeneration = aGeneration;
 }
 
 bool
 nsComputedDOMStyle::NeedsToFlush(nsIDocument* aDocument) const
 {
-  // If mContent is not in the same document, we could do some checks to know if
+  // If mElement is not in the same document, we could do some checks to know if
   // there are some pending restyles can be ignored across documents (since we
   // will use the caller document's style), but it can be complicated and should
   // be an edge case, so we just don't bother to do the optimization in this
   // case.
   //
   // FIXME(emilio): This is likely to want GetComposedDoc() instead of
   // OwnerDoc().
-  if (aDocument != mContent->OwnerDoc()) {
+  if (aDocument != mElement->OwnerDoc()) {
     return true;
   }
-  if (DocumentNeedsRestyle(aDocument, mContent->AsElement(), mPseudo)) {
+  if (DocumentNeedsRestyle(aDocument, mElement, mPseudo)) {
     return true;
   }
   // If parent document is there, also needs to check if there is some change
   // that needs to flush this document (e.g. size change for iframe).
   while (nsIDocument* parentDocument = aDocument->GetParentDocument()) {
     Element* element = parentDocument->FindContentForSubDocument(aDocument);
     if (DocumentNeedsRestyle(parentDocument, element, nullptr)) {
       return true;
@@ -867,28 +867,28 @@ nsComputedDOMStyle::UpdateCurrentStyleSo
   //  * https://github.com/w3c/csswg-drafts/issues/1964
   //  * https://github.com/w3c/csswg-drafts/issues/1548
 
   // If the property we are computing relies on layout, then we must flush.
   const bool needsToFlush = aNeedsLayoutFlush || NeedsToFlush(document);
   if (needsToFlush) {
     // Flush _before_ getting the presshell, since that could create a new
     // presshell.  Also note that we want to flush the style on the document
-    // we're computing style in, not on the document mContent is in -- the two
+    // we're computing style in, not on the document mElement is in -- the two
     // may be different.
     document->FlushPendingNotifications(
       aNeedsLayoutFlush ? FlushType::Layout : FlushType::Style);
   }
 
 #ifdef DEBUG
   mFlushedPendingReflows = aNeedsLayoutFlush;
 #endif
 
   nsCOMPtr<nsIPresShell> presShellForContent =
-    nsContentUtils::GetPresShellForContent(mContent);
+    nsContentUtils::GetPresShellForContent(mElement);
   if (presShellForContent && presShellForContent->GetDocument() != document) {
     presShellForContent->GetDocument()->FlushPendingNotifications(FlushType::Style);
     if (presShellForContent->IsDestroying()) {
       presShellForContent = nullptr;
     }
   }
 
   mPresShell = document->GetShell();
@@ -905,45 +905,45 @@ nsComputedDOMStyle::UpdateCurrentStyleSo
   // undisplayed elements.
   // As for Gecko, GetUndisplayedRestyleGeneration is effectively equal to
   // GetRestyleGeneration, since the generation is incremented whenever we
   // process restyles.
   uint64_t currentGeneration =
     mPresShell->GetPresContext()->GetUndisplayedRestyleGeneration();
 
   if (mComputedStyle) {
-    // We can't rely on the undisplayed restyle generation if mContent is
+    // We can't rely on the undisplayed restyle generation if mElement is
     // out-of-document, since that generation is not incremented for DOM changes
     // on out-of-document elements.
     //
     // So we always need to update the style to ensure it it up-to-date.
-    if (mComputedStyleGeneration == currentGeneration
-        && mContent->IsInComposedDoc()) {
+    if (mComputedStyleGeneration == currentGeneration &&
+        mElement->IsInComposedDoc()) {
       // Our cached style is still valid.
       return;
     }
     // We've processed some restyles, so the cached style might be out of date.
     mComputedStyle = nullptr;
   }
 
-  // XXX the !mContent->IsHTMLElement(nsGkAtoms::area)
+  // XXX the !mElement->IsHTMLElement(nsGkAtoms::area)
   // check is needed due to bug 135040 (to avoid using
   // mPrimaryFrame). Remove it once that's fixed.
-  if (mStyleType == eAll && !mContent->IsHTMLElement(nsGkAtoms::area)) {
+  if (mStyleType == eAll && !mElement->IsHTMLElement(nsGkAtoms::area)) {
     mOuterFrame = nullptr;
 
     if (!mPseudo) {
-      mOuterFrame = mContent->GetPrimaryFrame();
+      mOuterFrame = mElement->GetPrimaryFrame();
     } else if (mPseudo == nsCSSPseudoElements::before ||
                mPseudo == nsCSSPseudoElements::after) {
       nsAtom* property = mPseudo == nsCSSPseudoElements::before
                             ? nsGkAtoms::beforePseudoProperty
                             : nsGkAtoms::afterPseudoProperty;
 
-      auto* pseudo = static_cast<Element*>(mContent->GetProperty(property));
+      auto* pseudo = static_cast<Element*>(mElement->GetProperty(property));
       mOuterFrame = pseudo ? pseudo->GetPrimaryFrame() : nullptr;
     }
 
     mInnerFrame = mOuterFrame;
     if (mOuterFrame) {
       LayoutFrameType type = mOuterFrame->Type();
       if (type == LayoutFrameType::TableWrapper) {
         // If the frame is a table wrapper frame then we should get the style
@@ -959,17 +959,17 @@ nsComputedDOMStyle::UpdateCurrentStyleSo
       NS_ASSERTION(mComputedStyle, "Frame without style?");
     }
   }
 
   if (!mComputedStyle || MustReresolveStyle(mComputedStyle)) {
     // Need to resolve a style.
     RefPtr<ComputedStyle> resolvedComputedStyle =
       DoGetComputedStyleNoFlush(
-          mContent->AsElement(),
+          mElement,
           mPseudo,
           presShellForContent ? presShellForContent.get() : mPresShell,
           mStyleType);
     if (!resolvedComputedStyle) {
       ClearComputedStyle();
       return;
     }
 
@@ -5687,17 +5687,17 @@ nsComputedDOMStyle::GetLineHeightCoord(n
       GetCBContentHeight(blockHeight);
     }
   }
 
   nsPresContext* presContext = mPresShell->GetPresContext();
 
   // lie about font size inflation since we lie about font size (since
   // the inflation only applies to text)
-  aCoord = ReflowInput::CalcLineHeight(mContent,
+  aCoord = ReflowInput::CalcLineHeight(mElement,
                                        mComputedStyle,
                                        presContext,
                                        blockHeight, 1.0f);
 
   // CalcLineHeight uses font->mFont.size, but we want to use
   // font->mSize as the font size.  Adjust for that.  Also adjust for
   // the text zoom, if any.
   const nsStyleFont* font = StyleFont();
@@ -7194,17 +7194,17 @@ nsComputedDOMStyle::DoGetCustomProperty(
   val->SetString(variableValue);
 
   return val.forget();
 }
 
 void
 nsComputedDOMStyle::ParentChainChanged(nsIContent* aContent)
 {
-  NS_ASSERTION(mContent == aContent, "didn't we register mContent?");
+  NS_ASSERTION(mElement == aContent, "didn't we register mElement?");
   NS_ASSERTION(mResolvedComputedStyle,
                "should have only registered an observer when "
                "mResolvedComputedStyle is true");
 
   ClearComputedStyle();
 }
 
 /* static */ ComputedStyleMap*
--- a/layout/style/nsComputedDOMStyle.h
+++ b/layout/style/nsComputedDOMStyle.h
@@ -78,19 +78,19 @@ public:
     eAll // Includes all stylesheets
   };
 
   nsComputedDOMStyle(mozilla::dom::Element* aElement,
                      const nsAString& aPseudoElt,
                      nsIDocument* aPresShell,
                      StyleType aStyleType);
 
-  virtual nsINode *GetParentObject() override
+  nsINode* GetParentObject() override
   {
-    return mContent;
+    return mElement;
   }
 
   static already_AddRefed<mozilla::ComputedStyle>
   GetComputedStyle(mozilla::dom::Element* aElement, nsAtom* aPseudo,
                    StyleType aStyleType = eAll);
 
   static already_AddRefed<mozilla::ComputedStyle>
   GetComputedStyleNoFlush(mozilla::dom::Element* aElement,
@@ -716,19 +716,19 @@ private:
   // restyles does not affect mContent).
   bool NeedsToFlush(nsIDocument* aDocument) const;
 
 
   static ComputedStyleMap* GetComputedStyleMap();
 
   // We don't really have a good immutable representation of "presentation".
   // Given the way GetComputedStyle is currently used, we should just grab the
-  // 0th presshell, if any, from the document.
+  // presshell, if any, from the document.
   nsWeakPtr mDocumentWeak;
-  nsCOMPtr<nsIContent> mContent;
+  nsCOMPtr<mozilla::dom::Element> mElement;
 
   /**
    * Strong reference to the ComputedStyle we access data from.  This can be
    * either a ComputedStyle we resolved ourselves or a ComputedStyle we got
    * from our frame.
    *
    * If we got the ComputedStyle from the frame, we clear out mComputedStyle
    * in ClearCurrentStyleSources.  If we resolved one ourselves, then