Bug 1047928 patch 9 - Don't rerun selector matching for viewport units. r=bzbarsky
authorL. David Baron <dbaron@dbaron.org>
Wed, 08 Oct 2014 14:27:03 -0700
changeset 209476 7b05dc3f7ae97518addba6fa3c26e1a1410b83de
parent 209475 6e95d6d112f3b7a93a3b4e12db61db6d1a54cff2
child 209477 14e9ff2f94f7aa28057275ca78466a7f8efcd01b
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersbzbarsky
bugs1047928
milestone35.0a1
Bug 1047928 patch 9 - Don't rerun selector matching for viewport units. r=bzbarsky
layout/base/nsPresContext.cpp
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -1880,29 +1880,37 @@ nsPresContext::PostRebuildAllStyleDataEv
   }
   RestyleManager()->PostRebuildAllStyleDataEvent(aExtraHint, aRestyleHint);
 }
 
 void
 nsPresContext::MediaFeatureValuesChanged(StyleRebuildType aShouldRebuild,
                                          nsChangeHint aChangeHint)
 {
-  NS_ASSERTION(aShouldRebuild == eAlwaysRebuildStyle || aChangeHint == 0,
-               "If you don't know if we need a rebuild, how can you provide a hint?");
-
   mPendingMediaFeatureValuesChanged = false;
 
+  nsRestyleHint aRestyleHint = nsRestyleHint(0);
+
+  if (aShouldRebuild == eAlwaysRebuildStyle) {
+    // FIXME: Pass restyle hint from caller.
+    aRestyleHint |= eRestyle_Subtree;
+  }
+
   // MediumFeaturesChanged updates the applied rules, so it always gets called.
-  bool mediaFeaturesDidChange = mShell ? mShell->StyleSet()->MediumFeaturesChanged(this)
-                                       : false;
-
-  if (aShouldRebuild == eAlwaysRebuildStyle ||
-      mediaFeaturesDidChange ||
-      (mUsesViewportUnits && mPendingViewportChange)) {
-    RebuildAllStyleData(aChangeHint, eRestyle_Subtree);
+  if (mShell && mShell->StyleSet()->MediumFeaturesChanged(this)) {
+    aRestyleHint |= eRestyle_Subtree;
+  }
+
+  if (mUsesViewportUnits && mPendingViewportChange) {
+    // Rebuild all style data without rerunning selector matching.
+    aRestyleHint |= eRestyle_ForceDescendants;
+  }
+
+  if (aRestyleHint || aChangeHint) {
+    RebuildAllStyleData(aChangeHint, aRestyleHint);
   }
 
   mPendingViewportChange = false;
 
   if (mDocument->IsBeingUsedAsImage()) {
     MOZ_ASSERT(PR_CLIST_IS_EMPTY(&mDOMMediaQueryLists));
     return;
   }