Bug 1324700 - Add ResolveServoTransientStyle to get servo's computed values instead of nsStyleContext. r=heycam
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Sat, 15 Apr 2017 07:37:34 +0900
changeset 563323 b116710343a71f0079382c8b704f649ac711a42c
parent 563322 73c495cad7d65d5c2608db12c4e8e66907524299
child 563324 b38bae9c02febd46891db88efb674fd9b5c11b66
push id54258
push usercpeterson@mozilla.com
push dateSun, 16 Apr 2017 05:52:14 +0000
reviewersheycam
bugs1324700
milestone55.0a1
Bug 1324700 - Add ResolveServoTransientStyle to get servo's computed values instead of nsStyleContext. r=heycam Also this patch add nsIAtom as an argument to ResolveTransientStyle() to call the new function ResolveServoTransientStyle easier. The only call site of the ResolveTransientStyle() has already nsIAtom* there. MozReview-Commit-ID: IwxqZbaCSpB
layout/style/ServoStyleSet.cpp
layout/style/ServoStyleSet.h
layout/style/nsComputedDOMStyle.cpp
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -415,30 +415,36 @@ ServoStyleSet::ResolvePseudoElementStyle
 
   bool isBeforeOrAfter = aType == CSSPseudoElementType::before ||
                          aType == CSSPseudoElementType::after;
   return GetContext(computedValues.forget(), aParentContext, pseudoTag, aType,
                     isBeforeOrAfter ? aOriginatingElement : nullptr);
 }
 
 already_AddRefed<nsStyleContext>
-ServoStyleSet::ResolveTransientStyle(Element* aElement, CSSPseudoElementType aType)
+ServoStyleSet::ResolveTransientStyle(Element* aElement,
+                                     nsIAtom* aPseudoTag,
+                                     CSSPseudoElementType aPseudoType)
+{
+  RefPtr<ServoComputedValues> computedValues =
+    ResolveTransientServoStyle(aElement, aPseudoTag);
+
+  return GetContext(computedValues.forget(),
+                    nullptr,
+                    aPseudoTag,
+                    aPseudoType, nullptr);
+}
+
+already_AddRefed<ServoComputedValues>
+ServoStyleSet::ResolveTransientServoStyle(Element* aElement,
+                                          nsIAtom* aPseudoTag)
 {
   PreTraverseSync();
 
-  nsIAtom* pseudoTag = nullptr;
-  if (aType != CSSPseudoElementType::NotPseudo) {
-    pseudoTag = nsCSSPseudoElements::GetPseudoAtom(aType);
-  }
-
-  RefPtr<ServoComputedValues> computedValues =
-    ResolveStyleLazily(aElement, pseudoTag);
-
-  return GetContext(computedValues.forget(), nullptr, pseudoTag, aType,
-                    nullptr);
+  return ResolveStyleLazily(aElement, aPseudoTag);
 }
 
 // aFlags is an nsStyleSet flags bitfield
 already_AddRefed<nsStyleContext>
 ServoStyleSet::ResolveInheritingAnonymousBoxStyle(nsIAtom* aPseudoTag,
                                                   nsStyleContext* aParentContext,
                                                   uint32_t aFlags)
 {
--- a/layout/style/ServoStyleSet.h
+++ b/layout/style/ServoStyleSet.h
@@ -156,19 +156,26 @@ public:
   ResolvePseudoElementStyle(dom::Element* aOriginatingElement,
                             mozilla::CSSPseudoElementType aType,
                             nsStyleContext* aParentContext,
                             dom::Element* aPseudoElement);
 
   // Resolves style for a (possibly-pseudo) Element without assuming that the
   // style has been resolved, and without worrying about setting the style
   // context up to live in the style context tree (a null parent is used).
+  // |aPeudoTag| and |aPseudoType| must match.
   already_AddRefed<nsStyleContext>
   ResolveTransientStyle(dom::Element* aElement,
-                        mozilla::CSSPseudoElementType aPseudoType);
+                        nsIAtom* aPseudoTag,
+                        CSSPseudoElementType aPseudoType);
+
+  // Similar to ResolveTransientStyle() but returns ServoComputedValues.
+  // Unlike ResolveServoStyle() this function calls PreTraverseSync().
+  already_AddRefed<ServoComputedValues>
+  ResolveTransientServoStyle(dom::Element* aElement, nsIAtom* aPseudoTag);
 
   // Get a style context for an anonymous box.  aPseudoTag is the pseudo-tag to
   // use and must be non-null.  It must be an anon box, and must be one that
   // inherits style from the given aParentContext.  aFlags is an nsStyleSet
   // flags bitfield.
   already_AddRefed<nsStyleContext>
   ResolveInheritingAnonymousBoxStyle(nsIAtom* aPseudoTag,
                                      nsStyleContext* aParentContext,
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -615,17 +615,17 @@ nsComputedDOMStyle::DoGetStyleContextNoF
     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()) {
-    return servoSet->ResolveTransientStyle(aElement, type);
+    return servoSet->ResolveTransientStyle(aElement, aPseudo, type);
   }
 
   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);