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
--- 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,