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

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: 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 * (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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 242
242 CSSPrimitiveValue::CSSPrimitiveValue(const String& str, UnitType type) 243 CSSPrimitiveValue::CSSPrimitiveValue(const String& str, UnitType type)
243 : CSSValue(PrimitiveClass) 244 : CSSValue(PrimitiveClass)
244 { 245 {
245 m_primitiveUnitType = type; 246 m_primitiveUnitType = type;
246 m_value.string = str.impl(); 247 m_value.string = str.impl();
247 if (m_value.string) 248 if (m_value.string)
248 m_value.string->ref(); 249 m_value.string->ref();
249 } 250 }
250 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)
Timothy Loh 2015/07/23 08:11:46 Is this ever null (here and in cleanup())?
258 m_value.variableData->ref();
259 }
260
251 CSSPrimitiveValue::CSSPrimitiveValue(const LengthSize& lengthSize, const Compute dStyle& style) 261 CSSPrimitiveValue::CSSPrimitiveValue(const LengthSize& lengthSize, const Compute dStyle& style)
252 : CSSValue(PrimitiveClass) 262 : CSSValue(PrimitiveClass)
253 { 263 {
254 init(lengthSize, style); 264 init(lengthSize, style);
255 } 265 }
256 266
257 CSSPrimitiveValue::CSSPrimitiveValue(RGBA32 color) 267 CSSPrimitiveValue::CSSPrimitiveValue(RGBA32 color)
258 : CSSValue(PrimitiveClass) 268 : CSSValue(PrimitiveClass)
259 { 269 {
260 m_primitiveUnitType = CSS_RGBCOLOR; 270 m_primitiveUnitType = CSS_RGBCOLOR;
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 void CSSPrimitiveValue::cleanup() 400 void CSSPrimitiveValue::cleanup()
391 { 401 {
392 switch (static_cast<UnitType>(m_primitiveUnitType)) { 402 switch (static_cast<UnitType>(m_primitiveUnitType)) {
393 case CSS_CUSTOM_IDENT: 403 case CSS_CUSTOM_IDENT:
394 case CSS_STRING: 404 case CSS_STRING:
395 case CSS_URI: 405 case CSS_URI:
396 case CSS_ATTR: 406 case CSS_ATTR:
397 if (m_value.string) 407 if (m_value.string)
398 m_value.string->deref(); 408 m_value.string->deref();
399 break; 409 break;
410 case CSS_VARIABLE_REFERENCE:
411 if (m_value.variableData)
412 m_value.variableData->deref();
413 break;
400 case CSS_COUNTER: 414 case CSS_COUNTER:
401 // 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.
402 #if !ENABLE(OILPAN) 416 #if !ENABLE(OILPAN)
403 m_value.counter->deref(); 417 m_value.counter->deref();
404 #endif 418 #endif
405 break; 419 break;
406 case CSS_RECT: 420 case CSS_RECT:
407 // 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.
408 #if !ENABLE(OILPAN) 422 #if !ENABLE(OILPAN)
409 m_value.rect->deref(); 423 m_value.rect->deref();
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 switch (m_primitiveUnitType) { 827 switch (m_primitiveUnitType) {
814 case CSS_CUSTOM_IDENT: 828 case CSS_CUSTOM_IDENT:
815 case CSS_STRING: 829 case CSS_STRING:
816 case CSS_ATTR: 830 case CSS_ATTR:
817 case CSS_URI: 831 case CSS_URI:
818 return m_value.string; 832 return m_value.string;
819 case CSS_VALUE_ID: 833 case CSS_VALUE_ID:
820 return valueName(m_value.valueID); 834 return valueName(m_value.valueID);
821 case CSS_PROPERTY_ID: 835 case CSS_PROPERTY_ID:
822 return propertyName(m_value.propertyID); 836 return propertyName(m_value.propertyID);
837 case CSS_VARIABLE_REFERENCE:
838 return m_value.variableData->string();
823 default: 839 default:
824 break; 840 break;
825 } 841 }
826 842
827 return String(); 843 return String();
828 } 844 }
829 845
830 static String formatNumber(double number, const char* suffix, unsigned suffixLen gth) 846 static String formatNumber(double number, const char* suffix, unsigned suffixLen gth)
831 { 847 {
832 #if OS(WIN) && _MSC_VER < 1900 848 #if OS(WIN) && _MSC_VER < 1900
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 case CSS_RECT: 938 case CSS_RECT:
923 case CSS_QUAD: 939 case CSS_QUAD:
924 case CSS_RGBCOLOR: 940 case CSS_RGBCOLOR:
925 case CSS_PAIR: 941 case CSS_PAIR:
926 case CSS_CALC: 942 case CSS_CALC:
927 case CSS_SHAPE: 943 case CSS_SHAPE:
928 case CSS_IDENT: 944 case CSS_IDENT:
929 case CSS_CALC_PERCENTAGE_WITH_NUMBER: 945 case CSS_CALC_PERCENTAGE_WITH_NUMBER:
930 case CSS_CALC_PERCENTAGE_WITH_LENGTH: 946 case CSS_CALC_PERCENTAGE_WITH_LENGTH:
931 case CSS_QEM: 947 case CSS_QEM:
948 case CSS_VARIABLE_REFERENCE:
932 break; 949 break;
933 }; 950 };
934 ASSERT_NOT_REACHED(); 951 ASSERT_NOT_REACHED();
935 return ""; 952 return "";
936 } 953 }
937 954
938 String CSSPrimitiveValue::customCSSText() const 955 String CSSPrimitiveValue::customCSSText() const
939 { 956 {
940 if (m_hasCachedCSSText) { 957 if (m_hasCachedCSSText) {
941 ASSERT(cssTextCache().contains(this)); 958 ASSERT(cssTextCache().contains(this));
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 } 1059 }
1043 case CSS_PAIR: 1060 case CSS_PAIR:
1044 text = getPairValue()->cssText(); 1061 text = getPairValue()->cssText();
1045 break; 1062 break;
1046 case CSS_CALC: 1063 case CSS_CALC:
1047 text = m_value.calc->cssText(); 1064 text = m_value.calc->cssText();
1048 break; 1065 break;
1049 case CSS_SHAPE: 1066 case CSS_SHAPE:
1050 text = m_value.shape->cssText(); 1067 text = m_value.shape->cssText();
1051 break; 1068 break;
1069 case CSS_VARIABLE_REFERENCE:
1070 text = "var(" + String(m_value.string) + ")";
Timothy Loh 2015/07/23 08:11:46 Looks wrong, we only have m_value.variableData, ri
1071 break;
1052 } 1072 }
1053 1073
1054 ASSERT(!cssTextCache().contains(this)); 1074 ASSERT(!cssTextCache().contains(this));
1055 cssTextCache().set(this, text); 1075 cssTextCache().set(this, text);
1056 m_hasCachedCSSText = true; 1076 m_hasCachedCSSText = true;
1057 return text; 1077 return text;
1058 } 1078 }
1059 1079
1060 bool CSSPrimitiveValue::equals(const CSSPrimitiveValue& other) const 1080 bool CSSPrimitiveValue::equals(const CSSPrimitiveValue& other) const
1061 { 1081 {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 case CSS_FR: 1114 case CSS_FR:
1095 return m_value.num == other.m_value.num; 1115 return m_value.num == other.m_value.num;
1096 case CSS_PROPERTY_ID: 1116 case CSS_PROPERTY_ID:
1097 return m_value.propertyID == other.m_value.propertyID; 1117 return m_value.propertyID == other.m_value.propertyID;
1098 case CSS_VALUE_ID: 1118 case CSS_VALUE_ID:
1099 return m_value.valueID == other.m_value.valueID; 1119 return m_value.valueID == other.m_value.valueID;
1100 case CSS_CUSTOM_IDENT: 1120 case CSS_CUSTOM_IDENT:
1101 case CSS_STRING: 1121 case CSS_STRING:
1102 case CSS_URI: 1122 case CSS_URI:
1103 case CSS_ATTR: 1123 case CSS_ATTR:
1124 case CSS_VARIABLE_REFERENCE:
1104 return equal(m_value.string, other.m_value.string); 1125 return equal(m_value.string, other.m_value.string);
Timothy Loh 2015/07/23 08:11:46 Like above, isn't m_value.string invalid for CSS_V
1105 case CSS_COUNTER: 1126 case CSS_COUNTER:
1106 return m_value.counter && other.m_value.counter && m_value.counter->equa ls(*other.m_value.counter); 1127 return m_value.counter && other.m_value.counter && m_value.counter->equa ls(*other.m_value.counter);
1107 case CSS_RECT: 1128 case CSS_RECT:
1108 return m_value.rect && other.m_value.rect && m_value.rect->equals(*other .m_value.rect); 1129 return m_value.rect && other.m_value.rect && m_value.rect->equals(*other .m_value.rect);
1109 case CSS_QUAD: 1130 case CSS_QUAD:
1110 return m_value.quad && other.m_value.quad && m_value.quad->equals(*other .m_value.quad); 1131 return m_value.quad && other.m_value.quad && m_value.quad->equals(*other .m_value.quad);
1111 case CSS_RGBCOLOR: 1132 case CSS_RGBCOLOR:
1112 return m_value.rgbcolor == other.m_value.rgbcolor; 1133 return m_value.rgbcolor == other.m_value.rgbcolor;
1113 case CSS_PAIR: 1134 case CSS_PAIR:
1114 return m_value.pair && other.m_value.pair && m_value.pair->equals(*other .m_value.pair); 1135 return m_value.pair && other.m_value.pair && m_value.pair->equals(*other .m_value.pair);
(...skipping 28 matching lines...) Expand all
1143 visitor->trace(m_value.shape); 1164 visitor->trace(m_value.shape);
1144 break; 1165 break;
1145 default: 1166 default:
1146 break; 1167 break;
1147 } 1168 }
1148 #endif 1169 #endif
1149 CSSValue::traceAfterDispatch(visitor); 1170 CSSValue::traceAfterDispatch(visitor);
1150 } 1171 }
1151 1172
1152 } // namespace blink 1173 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698