Bug 1355349 - Move calculation of pseudo type in nsComputedDOMStyle::DoGetStyleContextNoFlush; r?hiro draft
authorBrian Birtles <birtles@gmail.com>
Fri, 02 Jun 2017 14:21:32 +0900
changeset 588793 2aab746d53a88b843f8704f4c07e8fdf9b5b07aa
parent 588783 8a3aa1701537ea6b8334f432cd030d260d492fa3
child 588794 2c2938beac021b43986ef43fe92c82b42c754b31
push id62159
push userbbirtles@mozilla.com
push dateMon, 05 Jun 2017 03:26:35 +0000
reviewershiro
bugs1355349
milestone55.0a1
Bug 1355349 - Move calculation of pseudo type in nsComputedDOMStyle::DoGetStyleContextNoFlush; r?hiro This patch just moves the calculation of the pseudo type earlier in the method so we can re-use it in the next patch in this series to get the style context from the Servo backend for the case where we don't need to resolve style. This patch also renames the local variable from 'type' to 'pseudoType' since that seems less ambiguous. MozReview-Commit-ID: 6pi2F1vZYHJ
layout/style/nsComputedDOMStyle.cpp
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -593,16 +593,25 @@ nsComputedDOMStyle::DoGetStyleContextNoF
   bool inDocWithShell = true;
   if (!presShell) {
     inDocWithShell = false;
     presShell = aPresShell;
     if (!presShell)
       return nullptr;
   }
 
+  auto pseudoType = CSSPseudoElementType::NotPseudo;
+  if (aPseudo) {
+    pseudoType = nsCSSPseudoElements::
+      GetPseudoType(aPseudo, CSSEnabledState::eIgnoreEnabledState);
+    if (pseudoType >= CSSPseudoElementType::Count) {
+      return nullptr;
+    }
+  }
+
   // XXX the !aElement->IsHTMLElement(nsGkAtoms::area)
   // check is needed due to bug 135040 (to avoid using
   // mPrimaryFrame). Remove it once that's fixed.
   if (inDocWithShell &&
       aStyleType == eAll &&
       !aElement->IsHTMLElement(nsGkAtoms::area)) {
     nsIFrame* frame = nullptr;
     if (aPseudo == nsCSSPseudoElements::before) {
@@ -645,54 +654,45 @@ nsComputedDOMStyle::DoGetStyleContextNoF
   // for the default style, so resolve the style ourselves.
 
   nsPresContext* presContext = presShell->GetPresContext();
   if (!presContext)
     return nullptr;
 
   StyleSetHandle styleSet = presShell->StyleSet();
 
-  auto type = CSSPseudoElementType::NotPseudo;
-  if (aPseudo) {
-    type = nsCSSPseudoElements::
-      GetPseudoType(aPseudo, CSSEnabledState::eIgnoreEnabledState);
-    if (type >= CSSPseudoElementType::Count) {
-      return nullptr;
-    }
-  }
-
   // For Servo, compute the result directly without recursively building up
   // a throwaway style context chain.
   if (ServoStyleSet* servoSet = styleSet->GetAsServo()) {
     StyleRuleInclusion rules = aStyleType == eDefaultOnly
                                ? StyleRuleInclusion::DefaultOnly
                                : StyleRuleInclusion::All;
-    return servoSet->ResolveTransientStyle(aElement, aPseudo, type, rules);
+    return servoSet->ResolveTransientStyle(aElement, aPseudo, pseudoType, rules);
   }
 
   RefPtr<nsStyleContext> parentContext;
   nsIContent* parent = aPseudo ? aElement : aElement->GetParent();
   // Don't resolve parent context for document fragments.
   if (parent && parent->IsElement()) {
     parentContext = GetStyleContextNoFlush(parent->AsElement(), nullptr,
                                            aPresShell, aStyleType);
   }
 
   StyleResolver styleResolver(presContext, aAnimationFlag);
 
   if (aAnimationFlag == eWithAnimation) {
     return styleResolver.ResolveWithAnimation(styleSet,
-                                              aElement, type,
+                                              aElement, pseudoType,
                                               parentContext,
                                               aStyleType,
                                               inDocWithShell);
   }
 
   return styleResolver.ResolveWithoutAnimation(styleSet,
-                                               aElement, type,
+                                               aElement, pseudoType,
                                                parentContext,
                                                inDocWithShell);
 }
 
 nsMargin
 nsComputedDOMStyle::GetAdjustedValuesForBoxSizing()
 {
   // We want the width/height of whatever parts 'width' or 'height' controls,