Bug 1273706 - Part 28: Have nsComputedDOMStyle try to get a computed value first for variables. r?heycam draft
authorJonathan Chan <jyc@eqv.io>
Thu, 18 Aug 2016 15:30:38 -0700
changeset 402917 31fa95a2e1fc8add2ae5ebf3e5f1196ec0f127b7
parent 402916 f29749822533aa9721ba32612df7d17b4945f6a4
child 402918 ee6d7779fe92e3271bc2df5bafb2b1ba3ee75b80
push id26775
push userjchan@mozilla.com
push dateThu, 18 Aug 2016 22:38:41 +0000
reviewersheycam
bugs1273706
milestone51.0a1
Bug 1273706 - Part 28: Have nsComputedDOMStyle try to get a computed value first for variables. r?heycam Now that we can register custom properties that have computed values and are animatable, we should support getting their computed value through getComputedStyle and getPropertyValue the same way we do other properties. If CSSVariableValues::Compute returns true, that is, this is a registered custom property value that requires computation, we take the computed CSSComputedValue and serialize it. Otherwise, we return the variable's token stream, as before. MozReview-Commit-ID: XZ19WCPcvY
layout/style/nsComputedDOMStyle.cpp
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -46,16 +46,19 @@
 #include "nsDOMCSSDeclaration.h"
 #include "nsStyleTransformMatrix.h"
 #include "mozilla/dom/Element.h"
 #include "prtime.h"
 #include "nsWrapperCacheInlines.h"
 #include "mozilla/AppUnits.h"
 #include <algorithm>
 
+#include "mozilla/CSSComputedValue.h"
+#include "mozilla/CSSVariableValues.h"
+
 using namespace mozilla;
 using namespace mozilla::dom;
 
 #if defined(DEBUG_bzbarsky) || defined(DEBUG_caillon)
 #define DEBUG_ComputedDOMStyle
 #endif
 
 /*
@@ -6600,28 +6603,33 @@ MarkComputedStyleMapDirty(const char* aP
   static_cast<nsComputedStyleMap*>(aData)->MarkDirty();
 }
 
 already_AddRefed<CSSValue>
 nsComputedDOMStyle::DoGetCustomProperty(const nsAString& aPropertyName)
 {
   MOZ_ASSERT(nsCSSProps::IsCustomPropertyName(aPropertyName));
 
-  const nsStyleVariables* variables = StyleVariables();
-
-  nsString variableValue;
   const nsAString& name = Substring(aPropertyName,
                                     CSS_CUSTOM_NAME_PREFIX_LENGTH);
-  if (!variables->mVariables.Get(name, variableValue)) {
+
+  const CSSVariableValues& variables = StyleVariables()->mVariables;
+  if (!variables.Has(name)) {
     return nullptr;
   }
 
-  RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
-  val->SetString(variableValue);
-
+  nsString stringValue;
+  const CSSComputedValue* value;
+  if (variables.Compute(name, &value)) {
+    value->AppendToString(stringValue);
+  } else {
+    variables.Get(name, stringValue);
+  }
+  RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
+  val->SetString(stringValue);
   return val.forget();
 }
 
 void
 nsComputedDOMStyle::ParentChainChanged(nsIContent* aContent)
 {
   NS_ASSERTION(mContent == aContent, "didn't we register mContent?");
   NS_ASSERTION(mResolvedStyleContext,