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

Side by Side Diff: Source/core/css/CSSPrimitiveValue.cpp

Issue 1192983003: CSS Custom Properties (Variables) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 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 * (C) 1999-2003 Lars Knoll (knoll@kde.org) 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2012 Apple Inc. All rights reserv ed. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2012 Apple Inc. All rights reserv ed.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details. 13 * Library General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU Library General Public License 15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to 16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA. 18 * Boston, MA 02110-1301, USA.
19 */ 19 */
20 20
21 #include "config.h" 21 #include "config.h"
22 #include "core/css/CSSPrimitiveValue.h" 22 #include "core/css/CSSPrimitiveValue.h"
23 23
24 #include "core/css/CSSBasicShapes.h" 24 #include "core/css/CSSBasicShapes.h"
25 #include "core/css/CSSCalculationValue.h" 25 #include "core/css/CSSCalculationValue.h"
26 #include "core/css/CSSHelper.h" 26 #include "core/css/CSSHelper.h"
27 #include "core/css/CSSMarkup.h" 27 #include "core/css/CSSMarkup.h"
28 #include "core/css/CSSToLengthConversionData.h" 28 #include "core/css/CSSToLengthConversionData.h"
29 #include "core/css/CSSVariableData.h"
29 #include "core/css/Counter.h" 30 #include "core/css/Counter.h"
30 #include "core/css/Pair.h" 31 #include "core/css/Pair.h"
31 #include "core/css/Rect.h" 32 #include "core/css/Rect.h"
32 #include "core/css/StyleSheetContents.h" 33 #include "core/css/StyleSheetContents.h"
33 #include "core/dom/Node.h" 34 #include "core/dom/Node.h"
34 #include "core/style/ComputedStyle.h" 35 #include "core/style/ComputedStyle.h"
35 #include "platform/LayoutUnit.h" 36 #include "platform/LayoutUnit.h"
36 #include "platform/fonts/FontMetrics.h" 37 #include "platform/fonts/FontMetrics.h"
37 #include "wtf/StdLibExtras.h" 38 #include "wtf/StdLibExtras.h"
38 #include "wtf/ThreadSpecific.h" 39 #include "wtf/ThreadSpecific.h"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 case CalcPercent: 184 case CalcPercent:
184 return CSS_PERCENTAGE; 185 return CSS_PERCENTAGE;
185 case CalcLength: 186 case CalcLength:
186 return CSS_PX; 187 return CSS_PX;
187 case CalcPercentNumber: 188 case CalcPercentNumber:
188 return CSS_CALC_PERCENTAGE_WITH_NUMBER; 189 return CSS_CALC_PERCENTAGE_WITH_NUMBER;
189 case CalcPercentLength: 190 case CalcPercentLength:
190 return CSS_CALC_PERCENTAGE_WITH_LENGTH; 191 return CSS_CALC_PERCENTAGE_WITH_LENGTH;
191 case CalcTime: 192 case CalcTime:
192 return CSS_MS; 193 return CSS_MS;
194 case CalcVariable: // The type of a calculation containing a variable cannot be known until the value of the variable is determined.
193 case CalcOther: 195 case CalcOther:
194 return CSS_UNKNOWN; 196 return CSS_UNKNOWN;
195 } 197 }
196 return CSS_UNKNOWN; 198 return CSS_UNKNOWN;
197 } 199 }
198 200
199 static const AtomicString& propertyName(CSSPropertyID propertyID) 201 static const AtomicString& propertyName(CSSPropertyID propertyID)
200 { 202 {
201 return getPropertyNameAtomicString(propertyID); 203 return getPropertyNameAtomicString(propertyID);
202 } 204 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 242
241 CSSPrimitiveValue::CSSPrimitiveValue(const String& str, UnitType type) 243 CSSPrimitiveValue::CSSPrimitiveValue(const String& str, UnitType type)
242 : CSSValue(PrimitiveClass) 244 : CSSValue(PrimitiveClass)
243 { 245 {
244 m_primitiveUnitType = type; 246 m_primitiveUnitType = type;
245 m_value.string = str.impl(); 247 m_value.string = str.impl();
246 if (m_value.string) 248 if (m_value.string)
247 m_value.string->ref(); 249 m_value.string->ref();
248 } 250 }
249 251
252 CSSPrimitiveValue::CSSPrimitiveValue(CSSVariableData* variableData)
253 : CSSValue(PrimitiveClass)
254 {
255 m_primitiveUnitType = CSSPrimitiveValue::CSS_VARIABLE_REFERENCE;
256 m_value.variableData = variableData;
257 if (m_value.variableData)
258 m_value.variableData->ref();
259 }
260
250 CSSPrimitiveValue::CSSPrimitiveValue(const LengthSize& lengthSize, const Compute dStyle& style) 261 CSSPrimitiveValue::CSSPrimitiveValue(const LengthSize& lengthSize, const Compute dStyle& style)
251 : CSSValue(PrimitiveClass) 262 : CSSValue(PrimitiveClass)
252 { 263 {
253 init(lengthSize, style); 264 init(lengthSize, style);
254 } 265 }
255 266
256 CSSPrimitiveValue::CSSPrimitiveValue(RGBA32 color) 267 CSSPrimitiveValue::CSSPrimitiveValue(RGBA32 color)
257 : CSSValue(PrimitiveClass) 268 : CSSValue(PrimitiveClass)
258 { 269 {
259 m_primitiveUnitType = CSS_RGBCOLOR; 270 m_primitiveUnitType = CSS_RGBCOLOR;
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 void CSSPrimitiveValue::cleanup() 400 void CSSPrimitiveValue::cleanup()
390 { 401 {
391 switch (static_cast<UnitType>(m_primitiveUnitType)) { 402 switch (static_cast<UnitType>(m_primitiveUnitType)) {
392 case CSS_CUSTOM_IDENT: 403 case CSS_CUSTOM_IDENT:
393 case CSS_STRING: 404 case CSS_STRING:
394 case CSS_URI: 405 case CSS_URI:
395 case CSS_ATTR: 406 case CSS_ATTR:
396 if (m_value.string) 407 if (m_value.string)
397 m_value.string->deref(); 408 m_value.string->deref();
398 break; 409 break;
410 case CSS_VARIABLE_REFERENCE:
411 if (m_value.variableData)
412 m_value.variableData->deref();
413 break;
399 case CSS_COUNTER: 414 case CSS_COUNTER:
400 // We must not call deref() when oilpan is enabled because m_value.count er is traced. 415 // We must not call deref() when oilpan is enabled because m_value.count er is traced.
401 #if !ENABLE(OILPAN) 416 #if !ENABLE(OILPAN)
402 m_value.counter->deref(); 417 m_value.counter->deref();
403 #endif 418 #endif
404 break; 419 break;
405 case CSS_RECT: 420 case CSS_RECT:
406 // We must not call deref() when oilpan is enabled because m_value.rect is traced. 421 // We must not call deref() when oilpan is enabled because m_value.rect is traced.
407 #if !ENABLE(OILPAN) 422 #if !ENABLE(OILPAN)
408 m_value.rect->deref(); 423 m_value.rect->deref();
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 switch (m_primitiveUnitType) { 825 switch (m_primitiveUnitType) {
811 case CSS_CUSTOM_IDENT: 826 case CSS_CUSTOM_IDENT:
812 case CSS_STRING: 827 case CSS_STRING:
813 case CSS_ATTR: 828 case CSS_ATTR:
814 case CSS_URI: 829 case CSS_URI:
815 return m_value.string; 830 return m_value.string;
816 case CSS_VALUE_ID: 831 case CSS_VALUE_ID:
817 return valueName(m_value.valueID); 832 return valueName(m_value.valueID);
818 case CSS_PROPERTY_ID: 833 case CSS_PROPERTY_ID:
819 return propertyName(m_value.propertyID); 834 return propertyName(m_value.propertyID);
835 case CSS_VARIABLE_REFERENCE:
836 return m_value.variableData->string();
820 default: 837 default:
821 break; 838 break;
822 } 839 }
823 840
824 return String(); 841 return String();
825 } 842 }
826 843
827 static String formatNumber(double number, const char* suffix, unsigned suffixLen gth) 844 static String formatNumber(double number, const char* suffix, unsigned suffixLen gth)
828 { 845 {
829 #if OS(WIN) && _MSC_VER < 1900 846 #if OS(WIN) && _MSC_VER < 1900
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 case CSS_COUNTER: 934 case CSS_COUNTER:
918 case CSS_RECT: 935 case CSS_RECT:
919 case CSS_QUAD: 936 case CSS_QUAD:
920 case CSS_RGBCOLOR: 937 case CSS_RGBCOLOR:
921 case CSS_PAIR: 938 case CSS_PAIR:
922 case CSS_CALC: 939 case CSS_CALC:
923 case CSS_SHAPE: 940 case CSS_SHAPE:
924 case CSS_IDENT: 941 case CSS_IDENT:
925 case CSS_CALC_PERCENTAGE_WITH_NUMBER: 942 case CSS_CALC_PERCENTAGE_WITH_NUMBER:
926 case CSS_CALC_PERCENTAGE_WITH_LENGTH: 943 case CSS_CALC_PERCENTAGE_WITH_LENGTH:
944 case CSS_VARIABLE_REFERENCE:
927 break; 945 break;
928 }; 946 };
929 ASSERT_NOT_REACHED(); 947 ASSERT_NOT_REACHED();
930 return ""; 948 return "";
931 } 949 }
932 950
933 String CSSPrimitiveValue::customCSSText() const 951 String CSSPrimitiveValue::customCSSText() const
934 { 952 {
935 if (m_hasCachedCSSText) { 953 if (m_hasCachedCSSText) {
936 ASSERT(cssTextCache().contains(this)); 954 ASSERT(cssTextCache().contains(this));
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 } 1052 }
1035 case CSS_PAIR: 1053 case CSS_PAIR:
1036 text = getPairValue()->cssText(); 1054 text = getPairValue()->cssText();
1037 break; 1055 break;
1038 case CSS_CALC: 1056 case CSS_CALC:
1039 text = m_value.calc->cssText(); 1057 text = m_value.calc->cssText();
1040 break; 1058 break;
1041 case CSS_SHAPE: 1059 case CSS_SHAPE:
1042 text = m_value.shape->cssText(); 1060 text = m_value.shape->cssText();
1043 break; 1061 break;
1062 case CSS_VARIABLE_REFERENCE:
1063 text = "var(" + String(m_value.string) + ")";
1064 break;
1044 } 1065 }
1045 1066
1046 ASSERT(!cssTextCache().contains(this)); 1067 ASSERT(!cssTextCache().contains(this));
1047 cssTextCache().set(this, text); 1068 cssTextCache().set(this, text);
1048 m_hasCachedCSSText = true; 1069 m_hasCachedCSSText = true;
1049 return text; 1070 return text;
1050 } 1071 }
1051 1072
1052 bool CSSPrimitiveValue::equals(const CSSPrimitiveValue& other) const 1073 bool CSSPrimitiveValue::equals(const CSSPrimitiveValue& other) const
1053 { 1074 {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 case CSS_FR: 1107 case CSS_FR:
1087 return m_value.num == other.m_value.num; 1108 return m_value.num == other.m_value.num;
1088 case CSS_PROPERTY_ID: 1109 case CSS_PROPERTY_ID:
1089 return m_value.propertyID == other.m_value.propertyID; 1110 return m_value.propertyID == other.m_value.propertyID;
1090 case CSS_VALUE_ID: 1111 case CSS_VALUE_ID:
1091 return m_value.valueID == other.m_value.valueID; 1112 return m_value.valueID == other.m_value.valueID;
1092 case CSS_CUSTOM_IDENT: 1113 case CSS_CUSTOM_IDENT:
1093 case CSS_STRING: 1114 case CSS_STRING:
1094 case CSS_URI: 1115 case CSS_URI:
1095 case CSS_ATTR: 1116 case CSS_ATTR:
1117 case CSS_VARIABLE_REFERENCE:
1096 return equal(m_value.string, other.m_value.string); 1118 return equal(m_value.string, other.m_value.string);
1097 case CSS_COUNTER: 1119 case CSS_COUNTER:
1098 return m_value.counter && other.m_value.counter && m_value.counter->equa ls(*other.m_value.counter); 1120 return m_value.counter && other.m_value.counter && m_value.counter->equa ls(*other.m_value.counter);
1099 case CSS_RECT: 1121 case CSS_RECT:
1100 return m_value.rect && other.m_value.rect && m_value.rect->equals(*other .m_value.rect); 1122 return m_value.rect && other.m_value.rect && m_value.rect->equals(*other .m_value.rect);
1101 case CSS_QUAD: 1123 case CSS_QUAD:
1102 return m_value.quad && other.m_value.quad && m_value.quad->equals(*other .m_value.quad); 1124 return m_value.quad && other.m_value.quad && m_value.quad->equals(*other .m_value.quad);
1103 case CSS_RGBCOLOR: 1125 case CSS_RGBCOLOR:
1104 return m_value.rgbcolor == other.m_value.rgbcolor; 1126 return m_value.rgbcolor == other.m_value.rgbcolor;
1105 case CSS_PAIR: 1127 case CSS_PAIR:
(...skipping 29 matching lines...) Expand all
1135 visitor->trace(m_value.shape); 1157 visitor->trace(m_value.shape);
1136 break; 1158 break;
1137 default: 1159 default:
1138 break; 1160 break;
1139 } 1161 }
1140 #endif 1162 #endif
1141 CSSValue::traceAfterDispatch(visitor); 1163 CSSValue::traceAfterDispatch(visitor);
1142 } 1164 }
1143 1165
1144 } // namespace blink 1166 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698