Bug 1244068 - Part 3: Factor out nsStyleSet getting in RestyleManager/ElementRestyler. r=dholbert
authorCameron McCormack <cam@mcc.id.au>
Wed, 24 Feb 2016 18:01:10 +1100
changeset 321688 af6b36331895828a387492db7f43d4d106eb4078
parent 321687 64552d361e5ebcc40e74f1f7929f5a9b8b61a8f2
child 321689 a2a7c4cc94dca9adc3329bd8f7d0670d5f8be3df
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1244068
milestone47.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 1244068 - Part 3: Factor out nsStyleSet getting in RestyleManager/ElementRestyler. r=dholbert
layout/base/RestyleManager.cpp
layout/base/RestyleManager.h
--- a/layout/base/RestyleManager.cpp
+++ b/layout/base/RestyleManager.cpp
@@ -13,16 +13,17 @@
 #include "mozilla/EventStates.h"
 #include "nsLayoutUtils.h"
 #include "AnimationCommon.h" // For GetLayerAnimationInfo
 #include "FrameLayerBuilder.h"
 #include "GeckoProfiler.h"
 #include "LayerAnimationInfo.h" // For LayerAnimationInfo::sRecords
 #include "nsStyleChangeList.h"
 #include "nsRuleProcessorData.h"
+#include "nsStyleSet.h"
 #include "nsStyleUtil.h"
 #include "nsCSSFrameConstructor.h"
 #include "nsSVGEffects.h"
 #include "nsCSSPseudoElements.h"
 #include "nsCSSRendering.h"
 #include "nsAnimationManager.h"
 #include "nsTransitionManager.h"
 #include "nsViewManager.h"
@@ -1024,17 +1025,17 @@ RestyleManager::RestyleElement(Element* 
                "frame/content mismatch");
 
   // If we're restyling the root element and there are 'rem' units in
   // use, handle dynamic changes to the definition of a 'rem' here.
   if (mPresContext->UsesRootEMUnits() && aPrimaryFrame &&
       !mInRebuildAllStyleData) {
     nsStyleContext *oldContext = aPrimaryFrame->StyleContext();
     if (!oldContext->GetParent()) { // check that we're the root element
-      RefPtr<nsStyleContext> newContext = mPresContext->StyleSet()->
+      RefPtr<nsStyleContext> newContext = StyleSet()->
         ResolveStyleFor(aElement, nullptr /* == oldContext->GetParent() */);
       if (oldContext->StyleFont()->mFont.size !=
           newContext->StyleFont()->mFont.size) {
         // The basis for 'rem' units has changed.
         mRebuildAllRestyleHint |= aRestyleHint;
         if (aRestyleHint & eRestyle_SomeDescendants) {
           mRebuildAllRestyleHint |= eRestyle_Subtree;
         }
@@ -1141,17 +1142,17 @@ RestyleManager::ContentStateChanged(nsIC
   // XXXbz it would be good if this function only took Elements, but
   // we'd have to make ESM guarantee that usefully.
   if (!aContent->IsElement()) {
     return NS_OK;
   }
 
   Element* aElement = aContent->AsElement();
 
-  nsStyleSet* styleSet = mPresContext->StyleSet();
+  nsStyleSet* styleSet = StyleSet();
   NS_ASSERTION(styleSet, "couldn't get style set");
 
   nsChangeHint hint = NS_STYLE_HINT_NONE;
   // Any change to a content state that affects which frames we construct
   // must lead to a frame reconstruct here if we already have a frame.
   // Note that we never decide through non-CSS means to not create frames
   // based on content states, so if we already don't have a frame we don't
   // need to force a reframe -- if it's needed, the HasStateDependentStyle
@@ -1223,23 +1224,23 @@ void
 RestyleManager::AttributeWillChange(Element* aElement,
                                     int32_t aNameSpaceID,
                                     nsIAtom* aAttribute,
                                     int32_t aModType,
                                     const nsAttrValue* aNewValue)
 {
   RestyleHintData rsdata;
   nsRestyleHint rshint =
-    mPresContext->StyleSet()->HasAttributeDependentStyle(aElement,
-                                                         aNameSpaceID,
-                                                         aAttribute,
-                                                         aModType,
-                                                         false,
-                                                         aNewValue,
-                                                         rsdata);
+    StyleSet()->HasAttributeDependentStyle(aElement,
+                                           aNameSpaceID,
+                                           aAttribute,
+                                           aModType,
+                                           false,
+                                           aNewValue,
+                                           rsdata);
   PostRestyleEvent(aElement, rshint, NS_STYLE_HINT_NONE, &rsdata);
 }
 
 // Forwarded nsIMutationObserver method, to handle restyling (and
 // passing the notification to the frame).
 void
 RestyleManager::AttributeChanged(Element* aElement,
                                  int32_t aNameSpaceID,
@@ -1315,23 +1316,23 @@ RestyleManager::AttributeChanged(Element
     // them, as well. Currently, inline frames don't do anything on
     // this notification, so it's not that big a deal.
   }
 
   // See if we can optimize away the style re-resolution -- must be called after
   // the frame's AttributeChanged() in case it does something that affects the style
   RestyleHintData rsdata;
   nsRestyleHint rshint =
-    mPresContext->StyleSet()->HasAttributeDependentStyle(aElement,
-                                                         aNameSpaceID,
-                                                         aAttribute,
-                                                         aModType,
-                                                         true,
-                                                         aOldValue,
-                                                         rsdata);
+    StyleSet()->HasAttributeDependentStyle(aElement,
+                                           aNameSpaceID,
+                                           aAttribute,
+                                           aModType,
+                                           true,
+                                           aOldValue,
+                                           rsdata);
   PostRestyleEvent(aElement, rshint, hint, &rsdata);
 }
 
 /* static */ uint64_t
 RestyleManager::GetAnimationGenerationForFrame(nsIFrame* aFrame)
 {
   EffectSet* effectSet = EffectSet::GetEffectSet(aFrame);
   return effectSet ? effectSet->GetAnimationGeneration() : 0;
@@ -1650,17 +1651,17 @@ RestyleManager::StartRebuildAllStyleData
     // No need to do anything.
     return;
   }
 
   mInRebuildAllStyleData = true;
 
   // Tell the style set to get the old rule tree out of the way
   // so we can recalculate while maintaining rule tree immutability
-  nsresult rv = mPresContext->StyleSet()->BeginReconstruct();
+  nsresult rv = StyleSet()->BeginReconstruct();
   if (NS_FAILED(rv)) {
     MOZ_CRASH("unable to rebuild style data");
   }
 
   nsRestyleHint restyleHint = mRebuildAllRestyleHint;
   nsChangeHint changeHint = mRebuildAllExtraHint;
   mRebuildAllExtraHint = nsChangeHint(0);
   mRebuildAllRestyleHint = nsRestyleHint(0);
@@ -1703,17 +1704,17 @@ RestyleManager::FinishRebuildAllStyleDat
 {
   MOZ_ASSERT(mInRebuildAllStyleData, "bad caller");
 
   // Tell the style set it's safe to destroy the old rule tree.  We
   // must do this after the ProcessRestyledFrames call in case the
   // change list has frame reconstructs in it (since frames to be
   // reconstructed will still have their old style context pointers
   // until they are destroyed).
-  mPresContext->StyleSet()->EndReconstruct();
+  StyleSet()->EndReconstruct();
 
   mInRebuildAllStyleData = false;
 }
 
 void
 RestyleManager::ProcessPendingRestyles()
 {
   NS_PRECONDITION(mPresContext->Document(), "No document?  Pshaw!");
@@ -2407,17 +2408,17 @@ RestyleManager::ReparentStyleContext(nsI
     // continuation).
     newContext = prevContinuationContext;
   } else {
     nsIFrame* parentFrame = aFrame->GetParent();
     Element* element =
       ElementForStyleContext(parentFrame ? parentFrame->GetContent() : nullptr,
                              aFrame,
                              oldContext->GetPseudoType());
-    newContext = mPresContext->StyleSet()->
+    newContext = StyleSet()->
                    ReparentStyleContext(oldContext, newParentContext, element);
   }
 
   if (newContext) {
     if (newContext != oldContext) {
       // We probably don't want to initiate transitions from
       // ReparentStyleContext, since we call it during frame
       // construction rather than in response to dynamic changes.
@@ -2486,17 +2487,17 @@ RestyleManager::ReparentStyleContext(nsI
       }
 
       // do additional contexts
       int32_t contextIndex = 0;
       for (nsStyleContext* oldExtraContext;
            (oldExtraContext = aFrame->GetAdditionalStyleContext(contextIndex));
            ++contextIndex) {
         RefPtr<nsStyleContext> newExtraContext;
-        newExtraContext = mPresContext->StyleSet()->
+        newExtraContext = StyleSet()->
                             ReparentStyleContext(oldExtraContext,
                                                  newContext, nullptr);
         if (newExtraContext) {
           if (newExtraContext != oldExtraContext) {
             // Make sure to call CalcStyleDifference so that the new
             // context ends up resolving all the structs the old context
             // resolved.
             uint32_t equalStructs;
@@ -3683,17 +3684,17 @@ ElementRestyler::CanReparentStyleContext
   // If we had any restyle hints other than the ones listed below,
   // which don't control whether the current frame/element needs
   // a new style context by looking up a new rule node, or if
   // we are reconstructing the entire rule tree, then we can't
   // use ReparentStyleContext.
   return !(aRestyleHint & ~(eRestyle_Force |
                             eRestyle_ForceDescendants |
                             eRestyle_SomeDescendants)) &&
-         !mPresContext->StyleSet()->IsInRuleTreeReconstruct();
+         !StyleSet()->IsInRuleTreeReconstruct();
 }
 
 // Returns true iff any rule node that is an ancestor-or-self of the
 // two specified rule nodes, but which is not an ancestor of both,
 // has any inherited style data.  If false is returned, then we know
 // that a change from one rule node to the other must not result in
 // any change in inherited style data.
 static bool
@@ -3831,17 +3832,17 @@ ElementRestyler::RestyleSelf(nsIFrame* a
   }
 
   // Look at the frame and its current style context for conditions
   // that would change our RestyleResult.
   ComputeRestyleResultFromFrame(aSelf, result, canStopWithStyleChange);
 
   nsChangeHint assumeDifferenceHint = NS_STYLE_HINT_NONE;
   RefPtr<nsStyleContext> oldContext = aSelf->StyleContext();
-  nsStyleSet* styleSet = mPresContext->StyleSet();
+  nsStyleSet* styleSet = StyleSet();
 
 #ifdef ACCESSIBILITY
   mWasFrameVisible = nsIPresShell::IsAccessibilityActive() ?
     oldContext->StyleVisibility()->IsVisible() : false;
 #endif
 
   nsIAtom* const pseudoTag = oldContext->GetPseudo();
   const CSSPseudoElementType pseudoType = oldContext->GetPseudoType();
@@ -4592,17 +4593,17 @@ ElementRestyler::RestyleUndisplayedNodes
     nsAutoPtr<RestyleTracker::RestyleData> undisplayedRestyleData;
     Element* element = undisplayed->mContent->AsElement();
     if (mRestyleTracker.GetRestyleData(element,
                                        undisplayedRestyleData)) {
       thisChildHint =
         nsRestyleHint(thisChildHint | undisplayedRestyleData->mRestyleHint);
     }
     RefPtr<nsStyleContext> undisplayedContext;
-    nsStyleSet* styleSet = mPresContext->StyleSet();
+    nsStyleSet* styleSet = StyleSet();
     if (MustRestyleSelf(thisChildHint, element)) {
       undisplayedContext =
         styleSet->ResolveStyleFor(element, aParentContext, mTreeMatchContext);
     } else if (CanReparentStyleContext(thisChildHint)) {
       undisplayedContext =
         styleSet->ReparentStyleContext(undisplayed->mStyle,
                                        aParentContext,
                                        element);
@@ -4964,16 +4965,28 @@ RestyleManager::ComputeAndProcessStyleCh
                     swappedStructOwners);
   r.RestyleChildrenOfDisplayContentsElement(frame, aNewContext, aMinChange,
                                             aRestyleTracker,
                                             aRestyleHint, aRestyleHintData);
   ProcessRestyledFrames(changeList);
   ClearCachedInheritedStyleDataOnDescendants(contextsToClear);
 }
 
+nsStyleSet*
+RestyleManager::StyleSet() const
+{
+  return mPresContext->StyleSet();
+}
+
+nsStyleSet*
+ElementRestyler::StyleSet() const
+{
+  return mPresContext->StyleSet();
+}
+
 AutoDisplayContentsAncestorPusher::AutoDisplayContentsAncestorPusher(
   TreeMatchContext& aTreeMatchContext, nsPresContext* aPresContext,
   nsIContent* aParent)
   : mTreeMatchContext(aTreeMatchContext)
   , mPresContext(aPresContext)
 {
   if (aParent) {
     nsFrameManager* fm = mPresContext->FrameManager();
--- a/layout/base/RestyleManager.h
+++ b/layout/base/RestyleManager.h
@@ -483,16 +483,18 @@ public:
   // environment variable.
   static uint32_t StructsToLog();
 
   static nsCString StructNamesToString(uint32_t aSIDs);
   int32_t& LoggingDepth() { return mLoggingDepth; }
 #endif
 
 private:
+  inline nsStyleSet* StyleSet() const;
+
   /* aMinHint is the minimal change that should be made to the element */
   // XXXbz do we really need the aPrimaryFrame argument here?
   void RestyleElement(Element*        aElement,
                       nsIFrame*       aPrimaryFrame,
                       nsChangeHint    aMinHint,
                       RestyleTracker& aRestyleTracker,
                       nsRestyleHint   aRestyleHint,
                       const RestyleHintData& aRestyleHintData);
@@ -677,16 +679,18 @@ public:
 
 #ifdef RESTYLE_LOGGING
   bool ShouldLogRestyle() {
     return RestyleManager::ShouldLogRestyle(mPresContext);
   }
 #endif
 
 private:
+  inline nsStyleSet* StyleSet() const;
+
   // Enum for the result of RestyleSelf, which indicates whether the
   // restyle procedure should continue to the children, and how.
   //
   // These values must be ordered so that later values imply that all
   // the work of the earlier values is also done.
   enum RestyleResult {
 
     // we left the old style context on the frame; do not restyle children