Bug 1324700 - Add ResolveServoTransientStyle to get servo's computed values instead of nsStyleContext. r?heycam draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Sat, 15 Apr 2017 07:37:34 +0900
changeset 563185 fe5d6f10d70658e691ae3e6514f5e81142a4697d
parent 563184 1eebf5ce5bbd04787d2323c3e38e77714055814e
child 563186 56965ec0bea6a324ba39eecdcf89680bea21574d
push id54220
push userhikezoe@mozilla.com
push dateSat, 15 Apr 2017 04:25:00 +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);