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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 3 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
4 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) 4 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
5 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) 5 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. 6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
7 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 7 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
8 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> 8 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
9 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 9 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
10 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. 10 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
(...skipping 26 matching lines...) Expand all
37 */ 37 */
38 38
39 #include "config.h" 39 #include "config.h"
40 40
41 #include "core/CSSPropertyNames.h" 41 #include "core/CSSPropertyNames.h"
42 #include "core/CSSValueKeywords.h" 42 #include "core/CSSValueKeywords.h"
43 #include "core/StyleBuilderFunctions.h" 43 #include "core/StyleBuilderFunctions.h"
44 #include "core/StylePropertyShorthand.h" 44 #include "core/StylePropertyShorthand.h"
45 #include "core/css/BasicShapeFunctions.h" 45 #include "core/css/BasicShapeFunctions.h"
46 #include "core/css/CSSCursorImageValue.h" 46 #include "core/css/CSSCursorImageValue.h"
47 #include "core/css/CSSCustomVariableValue.h"
47 #include "core/css/CSSGradientValue.h" 48 #include "core/css/CSSGradientValue.h"
48 #include "core/css/CSSGridTemplateAreasValue.h" 49 #include "core/css/CSSGridTemplateAreasValue.h"
49 #include "core/css/CSSHelper.h" 50 #include "core/css/CSSHelper.h"
50 #include "core/css/CSSImageSetValue.h" 51 #include "core/css/CSSImageSetValue.h"
51 #include "core/css/CSSLineBoxContainValue.h" 52 #include "core/css/CSSLineBoxContainValue.h"
52 #include "core/css/CSSPathValue.h" 53 #include "core/css/CSSPathValue.h"
53 #include "core/css/CSSPrimitiveValueMappings.h" 54 #include "core/css/CSSPrimitiveValueMappings.h"
54 #include "core/css/CSSPropertyMetadata.h" 55 #include "core/css/CSSPropertyMetadata.h"
56 #include "core/css/CSSReflectValue.h"
Timothy Loh 2015/07/23 08:11:47 unused include?
55 #include "core/css/Counter.h" 57 #include "core/css/Counter.h"
56 #include "core/css/Pair.h" 58 #include "core/css/Pair.h"
57 #include "core/css/StylePropertySet.h" 59 #include "core/css/StylePropertySet.h"
58 #include "core/css/StyleRule.h" 60 #include "core/css/StyleRule.h"
61 #include "core/css/parser/CSSParser.h"
62 #include "core/css/parser/CSSParserTokenRange.h"
63 #include "core/css/parser/CSSPropertyParser.h"
64 #include "core/css/resolver/CSSVariableResolver.h"
59 #include "core/css/resolver/ElementStyleResources.h" 65 #include "core/css/resolver/ElementStyleResources.h"
60 #include "core/css/resolver/FilterOperationResolver.h" 66 #include "core/css/resolver/FilterOperationResolver.h"
61 #include "core/css/resolver/FontBuilder.h" 67 #include "core/css/resolver/FontBuilder.h"
62 #include "core/css/resolver/StyleBuilder.h" 68 #include "core/css/resolver/StyleBuilder.h"
63 #include "core/css/resolver/TransformBuilder.h" 69 #include "core/css/resolver/TransformBuilder.h"
64 #include "core/frame/LocalFrame.h" 70 #include "core/frame/LocalFrame.h"
65 #include "core/frame/Settings.h" 71 #include "core/frame/Settings.h"
66 #include "core/style/CounterContent.h" 72 #include "core/style/CounterContent.h"
67 #include "core/style/ComputedStyle.h" 73 #include "core/style/ComputedStyle.h"
68 #include "core/style/ComputedStyleConstants.h" 74 #include "core/style/ComputedStyleConstants.h"
(...skipping 28 matching lines...) Expand all
97 case CSSPropertyWebkitTextFillColor: 103 case CSSPropertyWebkitTextFillColor:
98 case CSSPropertyWebkitTextStrokeColor: 104 case CSSPropertyWebkitTextStrokeColor:
99 return true; 105 return true;
100 default: 106 default:
101 return false; 107 return false;
102 } 108 }
103 } 109 }
104 110
105 } // namespace 111 } // namespace
106 112
113 static bool hasVariableReference(CSSValue* value)
114 {
115 return value->isPrimitiveValue() && toCSSPrimitiveValue(value)->primitiveTyp e() == CSSPrimitiveValue::CSS_VARIABLE_REFERENCE;
116 }
117
107 void StyleBuilder::applyProperty(CSSPropertyID id, StyleResolverState& state, CS SValue* value) 118 void StyleBuilder::applyProperty(CSSPropertyID id, StyleResolverState& state, CS SValue* value)
108 { 119 {
120 if (RuntimeEnabledFeatures::cssVariablesEnabled() /*&& state.documentUsesCSS Variables()*/ && id != CSSPropertyVariable && hasVariableReference(value)) {
121 CSSVariableResolver::resolveAndApplyVariableReferences(state, id, toCSSP rimitiveValue(value));
122 return;
123 }
124
109 ASSERT_WITH_MESSAGE(!isShorthandProperty(id), "Shorthand property id = %d wa sn't expanded at parsing time", id); 125 ASSERT_WITH_MESSAGE(!isShorthandProperty(id), "Shorthand property id = %d wa sn't expanded at parsing time", id);
110 126
111 bool isInherit = state.parentNode() && value->isInheritedValue(); 127 bool isInherit = state.parentNode() && value->isInheritedValue();
112 bool isInitial = value->isInitialValue() || (!state.parentNode() && value->i sInheritedValue()); 128 bool isInitial = value->isInitialValue() || (!state.parentNode() && value->i sInheritedValue());
113 129
114 ASSERT(!isInherit || !isInitial); // isInherit -> !isInitial && isInitial -> !isInherit 130 ASSERT(!isInherit || !isInitial); // isInherit -> !isInitial && isInitial -> !isInherit
115 ASSERT(!isInherit || (state.parentNode() && state.parentStyle())); // isInhe rit -> (state.parentNode() && state.parentStyle()) 131 ASSERT(!isInherit || (state.parentNode() && state.parentStyle())); // isInhe rit -> (state.parentNode() && state.parentStyle())
116 132
117 if (!state.applyPropertyToRegularStyle() && (!state.applyPropertyToVisitedLi nkStyle() || !isValidVisitedLinkProperty(id))) { 133 if (!state.applyPropertyToRegularStyle() && (!state.applyPropertyToVisitedLi nkStyle() || !isValidVisitedLinkProperty(id))) {
118 // Limit the properties that can be applied to only the ones honored by :visited. 134 // Limit the properties that can be applied to only the ones honored by :visited.
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 void StyleBuilderFunctions::applyValueCSSPropertyWebkitWritingMode(StyleResolver State& state, CSSValue* value) 807 void StyleBuilderFunctions::applyValueCSSPropertyWebkitWritingMode(StyleResolver State& state, CSSValue* value)
792 { 808 {
793 state.setWritingMode(*toCSSPrimitiveValue(value)); 809 state.setWritingMode(*toCSSPrimitiveValue(value));
794 } 810 }
795 811
796 void StyleBuilderFunctions::applyValueCSSPropertyWebkitTextOrientation(StyleReso lverState& state, CSSValue* value) 812 void StyleBuilderFunctions::applyValueCSSPropertyWebkitTextOrientation(StyleReso lverState& state, CSSValue* value)
797 { 813 {
798 state.setTextOrientation(*toCSSPrimitiveValue(value)); 814 state.setTextOrientation(*toCSSPrimitiveValue(value));
799 } 815 }
800 816
817 void StyleBuilderFunctions::applyValueCSSPropertyVariable(StyleResolverState& st ate, CSSValue* value)
818 {
819 CSSCustomVariableValue* varVal = toCSSCustomVariableValue(value);
820 if (state.style()->variables()) {
Timothy Loh 2015/07/23 08:11:47 It doesn't seem like this'll work correctly with i
821 switch (varVal->id()) {
822 case CSSValueUnset:
823 case CSSValueInitial:
824 state.style()->variables()->removeVariable(varVal->name());
825 break;
826 case CSSValueInherit: {
827 StyleVariableData* parentVariables = state.parentStyle()->variables( );
828 if (!parentVariables)
829 return;
Timothy Loh 2015/07/23 08:11:47 The two nothing-to-do cases here should call remov
830 CSSVariableData* value = parentVariables->getVariable(varVal->name() );
831 if (!value)
832 return;
833 state.style()->variables()->setVariable(varVal->name(), value);
834 break;
835 }
836 case CSSValueInternalVariableValue:
837 state.style()->variables()->setVariable(varVal->name(), varVal->valu e());
838 break;
Timothy Loh 2015/07/23 08:11:47 indentation is off
839 default:
840 ASSERT_NOT_REACHED();
841 }
842 } else if (varVal->id() == CSSValueInternalVariableValue) {
843 RefPtr<StyleVariableData> variableData = state.parentStyle()->variables( ) ? state.parentStyle()->variables()->copy() : StyleVariableData::create();
844 variableData->setVariable(varVal->name(), varVal->value());
845 state.style()->setVariables(variableData.release());
846 }
847 }
848
849 void StyleBuilderFunctions::applyInheritCSSPropertyVariable(StyleResolverState& state)
850 {
851 ASSERT_NOT_REACHED();
852 }
853
854 void StyleBuilderFunctions::applyInitialCSSPropertyVariable(StyleResolverState& state)
855 {
856 ASSERT_NOT_REACHED();
857 }
858
801 void StyleBuilderFunctions::applyInheritCSSPropertyBaselineShift(StyleResolverSt ate& state) 859 void StyleBuilderFunctions::applyInheritCSSPropertyBaselineShift(StyleResolverSt ate& state)
802 { 860 {
803 const SVGComputedStyle& parentSvgStyle = state.parentStyle()->svgStyle(); 861 const SVGComputedStyle& parentSvgStyle = state.parentStyle()->svgStyle();
804 EBaselineShift baselineShift = parentSvgStyle.baselineShift(); 862 EBaselineShift baselineShift = parentSvgStyle.baselineShift();
805 SVGComputedStyle& svgStyle = state.style()->accessSVGStyle(); 863 SVGComputedStyle& svgStyle = state.style()->accessSVGStyle();
806 svgStyle.setBaselineShift(baselineShift); 864 svgStyle.setBaselineShift(baselineShift);
807 if (baselineShift == BS_LENGTH) 865 if (baselineShift == BS_LENGTH)
808 svgStyle.setBaselineShiftValue(parentSvgStyle.baselineShiftValue()); 866 svgStyle.setBaselineShiftValue(parentSvgStyle.baselineShiftValue());
809 } 867 }
810 868
(...skipping 16 matching lines...) Expand all
827 return; 885 return;
828 case CSSValueSuper: 886 case CSSValueSuper:
829 svgStyle.setBaselineShift(BS_SUPER); 887 svgStyle.setBaselineShift(BS_SUPER);
830 return; 888 return;
831 default: 889 default:
832 ASSERT_NOT_REACHED(); 890 ASSERT_NOT_REACHED();
833 } 891 }
834 } 892 }
835 893
836 } // namespace blink 894 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698