Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(564)

Unified Diff: Source/core/css/resolver/StyleBuilderCustom.cpp

Issue 1192983003: CSS Custom Properties (Variables) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: ToT-ed again... Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/css/resolver/StyleBuilderCustom.cpp
diff --git a/Source/core/css/resolver/StyleBuilderCustom.cpp b/Source/core/css/resolver/StyleBuilderCustom.cpp
index eefd6cc6d4ca7854247e16577902c80b892926b9..55530547b6b63cf943b9b754079eca5a2f64f6bc 100644
--- a/Source/core/css/resolver/StyleBuilderCustom.cpp
+++ b/Source/core/css/resolver/StyleBuilderCustom.cpp
@@ -44,6 +44,7 @@
#include "core/StylePropertyShorthand.h"
#include "core/css/BasicShapeFunctions.h"
#include "core/css/CSSCursorImageValue.h"
+#include "core/css/CSSCustomVariableValue.h"
#include "core/css/CSSGradientValue.h"
#include "core/css/CSSGridTemplateAreasValue.h"
#include "core/css/CSSHelper.h"
@@ -52,10 +53,15 @@
#include "core/css/CSSPathValue.h"
#include "core/css/CSSPrimitiveValueMappings.h"
#include "core/css/CSSPropertyMetadata.h"
+#include "core/css/CSSReflectValue.h"
Timothy Loh 2015/07/23 08:11:47 unused include?
#include "core/css/Counter.h"
#include "core/css/Pair.h"
#include "core/css/StylePropertySet.h"
#include "core/css/StyleRule.h"
+#include "core/css/parser/CSSParser.h"
+#include "core/css/parser/CSSParserTokenRange.h"
+#include "core/css/parser/CSSPropertyParser.h"
+#include "core/css/resolver/CSSVariableResolver.h"
#include "core/css/resolver/ElementStyleResources.h"
#include "core/css/resolver/FilterOperationResolver.h"
#include "core/css/resolver/FontBuilder.h"
@@ -104,8 +110,18 @@ static inline bool isValidVisitedLinkProperty(CSSPropertyID id)
} // namespace
+static bool hasVariableReference(CSSValue* value)
+{
+ return value->isPrimitiveValue() && toCSSPrimitiveValue(value)->primitiveType() == CSSPrimitiveValue::CSS_VARIABLE_REFERENCE;
+}
+
void StyleBuilder::applyProperty(CSSPropertyID id, StyleResolverState& state, CSSValue* value)
{
+ if (RuntimeEnabledFeatures::cssVariablesEnabled() /*&& state.documentUsesCSSVariables()*/ && id != CSSPropertyVariable && hasVariableReference(value)) {
+ CSSVariableResolver::resolveAndApplyVariableReferences(state, id, toCSSPrimitiveValue(value));
+ return;
+ }
+
ASSERT_WITH_MESSAGE(!isShorthandProperty(id), "Shorthand property id = %d wasn't expanded at parsing time", id);
bool isInherit = state.parentNode() && value->isInheritedValue();
@@ -798,6 +814,48 @@ void StyleBuilderFunctions::applyValueCSSPropertyWebkitTextOrientation(StyleReso
state.setTextOrientation(*toCSSPrimitiveValue(value));
}
+void StyleBuilderFunctions::applyValueCSSPropertyVariable(StyleResolverState& state, CSSValue* value)
+{
+ CSSCustomVariableValue* varVal = toCSSCustomVariableValue(value);
+ if (state.style()->variables()) {
Timothy Loh 2015/07/23 08:11:47 It doesn't seem like this'll work correctly with i
+ switch (varVal->id()) {
+ case CSSValueUnset:
+ case CSSValueInitial:
+ state.style()->variables()->removeVariable(varVal->name());
+ break;
+ case CSSValueInherit: {
+ StyleVariableData* parentVariables = state.parentStyle()->variables();
+ if (!parentVariables)
+ return;
Timothy Loh 2015/07/23 08:11:47 The two nothing-to-do cases here should call remov
+ CSSVariableData* value = parentVariables->getVariable(varVal->name());
+ if (!value)
+ return;
+ state.style()->variables()->setVariable(varVal->name(), value);
+ break;
+ }
+ case CSSValueInternalVariableValue:
+ state.style()->variables()->setVariable(varVal->name(), varVal->value());
+ break;
Timothy Loh 2015/07/23 08:11:47 indentation is off
+ default:
+ ASSERT_NOT_REACHED();
+ }
+ } else if (varVal->id() == CSSValueInternalVariableValue) {
+ RefPtr<StyleVariableData> variableData = state.parentStyle()->variables() ? state.parentStyle()->variables()->copy() : StyleVariableData::create();
+ variableData->setVariable(varVal->name(), varVal->value());
+ state.style()->setVariables(variableData.release());
+ }
+}
+
+void StyleBuilderFunctions::applyInheritCSSPropertyVariable(StyleResolverState& state)
+{
+ ASSERT_NOT_REACHED();
+}
+
+void StyleBuilderFunctions::applyInitialCSSPropertyVariable(StyleResolverState& state)
+{
+ ASSERT_NOT_REACHED();
+}
+
void StyleBuilderFunctions::applyInheritCSSPropertyBaselineShift(StyleResolverState& state)
{
const SVGComputedStyle& parentSvgStyle = state.parentStyle()->svgStyle();

Powered by Google App Engine
This is Rietveld 408576698