OLD | NEW |
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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 case CalcPercent: | 185 case CalcPercent: |
185 return CSS_PERCENTAGE; | 186 return CSS_PERCENTAGE; |
186 case CalcLength: | 187 case CalcLength: |
187 return CSS_PX; | 188 return CSS_PX; |
188 case CalcPercentNumber: | 189 case CalcPercentNumber: |
189 return CSS_CALC_PERCENTAGE_WITH_NUMBER; | 190 return CSS_CALC_PERCENTAGE_WITH_NUMBER; |
190 case CalcPercentLength: | 191 case CalcPercentLength: |
191 return CSS_CALC_PERCENTAGE_WITH_LENGTH; | 192 return CSS_CALC_PERCENTAGE_WITH_LENGTH; |
192 case CalcTime: | 193 case CalcTime: |
193 return CSS_MS; | 194 return CSS_MS; |
| 195 case CalcVariable: // The type of a calculation containing a variable cannot
be known until the value of the variable is determined. |
194 case CalcOther: | 196 case CalcOther: |
195 return CSS_UNKNOWN; | 197 return CSS_UNKNOWN; |
196 } | 198 } |
197 return CSS_UNKNOWN; | 199 return CSS_UNKNOWN; |
198 } | 200 } |
199 | 201 |
200 static const AtomicString& propertyName(CSSPropertyID propertyID) | 202 static const AtomicString& propertyName(CSSPropertyID propertyID) |
201 { | 203 { |
202 return getPropertyNameAtomicString(propertyID); | 204 return getPropertyNameAtomicString(propertyID); |
203 } | 205 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 243 |
242 CSSPrimitiveValue::CSSPrimitiveValue(const String& str, UnitType type) | 244 CSSPrimitiveValue::CSSPrimitiveValue(const String& str, UnitType type) |
243 : CSSValue(PrimitiveClass) | 245 : CSSValue(PrimitiveClass) |
244 { | 246 { |
245 m_primitiveUnitType = type; | 247 m_primitiveUnitType = type; |
246 m_value.string = str.impl(); | 248 m_value.string = str.impl(); |
247 if (m_value.string) | 249 if (m_value.string) |
248 m_value.string->ref(); | 250 m_value.string->ref(); |
249 } | 251 } |
250 | 252 |
| 253 CSSPrimitiveValue::CSSPrimitiveValue(CSSVariableData* variableData) |
| 254 : CSSValue(PrimitiveClass) |
| 255 { |
| 256 m_primitiveUnitType = CSSPrimitiveValue::CSS_VARIABLE_REFERENCE; |
| 257 m_value.variableData = variableData; |
| 258 if (m_value.variableData) |
| 259 m_value.variableData->ref(); |
| 260 } |
| 261 |
251 CSSPrimitiveValue::CSSPrimitiveValue(const LengthSize& lengthSize, const Compute
dStyle& style) | 262 CSSPrimitiveValue::CSSPrimitiveValue(const LengthSize& lengthSize, const Compute
dStyle& style) |
252 : CSSValue(PrimitiveClass) | 263 : CSSValue(PrimitiveClass) |
253 { | 264 { |
254 init(lengthSize, style); | 265 init(lengthSize, style); |
255 } | 266 } |
256 | 267 |
257 CSSPrimitiveValue::CSSPrimitiveValue(RGBA32 color) | 268 CSSPrimitiveValue::CSSPrimitiveValue(RGBA32 color) |
258 : CSSValue(PrimitiveClass) | 269 : CSSValue(PrimitiveClass) |
259 { | 270 { |
260 m_primitiveUnitType = CSS_RGBCOLOR; | 271 m_primitiveUnitType = CSS_RGBCOLOR; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 void CSSPrimitiveValue::cleanup() | 401 void CSSPrimitiveValue::cleanup() |
391 { | 402 { |
392 switch (static_cast<UnitType>(m_primitiveUnitType)) { | 403 switch (static_cast<UnitType>(m_primitiveUnitType)) { |
393 case CSS_CUSTOM_IDENT: | 404 case CSS_CUSTOM_IDENT: |
394 case CSS_STRING: | 405 case CSS_STRING: |
395 case CSS_URI: | 406 case CSS_URI: |
396 case CSS_ATTR: | 407 case CSS_ATTR: |
397 if (m_value.string) | 408 if (m_value.string) |
398 m_value.string->deref(); | 409 m_value.string->deref(); |
399 break; | 410 break; |
| 411 case CSS_VARIABLE_REFERENCE: |
| 412 if (m_value.variableData) |
| 413 m_value.variableData->deref(); |
| 414 break; |
400 case CSS_COUNTER: | 415 case CSS_COUNTER: |
401 // We must not call deref() when oilpan is enabled because m_value.count
er is traced. | 416 // We must not call deref() when oilpan is enabled because m_value.count
er is traced. |
402 #if !ENABLE(OILPAN) | 417 #if !ENABLE(OILPAN) |
403 m_value.counter->deref(); | 418 m_value.counter->deref(); |
404 #endif | 419 #endif |
405 break; | 420 break; |
406 case CSS_RECT: | 421 case CSS_RECT: |
407 // We must not call deref() when oilpan is enabled because m_value.rect
is traced. | 422 // We must not call deref() when oilpan is enabled because m_value.rect
is traced. |
408 #if !ENABLE(OILPAN) | 423 #if !ENABLE(OILPAN) |
409 m_value.rect->deref(); | 424 m_value.rect->deref(); |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 switch (m_primitiveUnitType) { | 827 switch (m_primitiveUnitType) { |
813 case CSS_CUSTOM_IDENT: | 828 case CSS_CUSTOM_IDENT: |
814 case CSS_STRING: | 829 case CSS_STRING: |
815 case CSS_ATTR: | 830 case CSS_ATTR: |
816 case CSS_URI: | 831 case CSS_URI: |
817 return m_value.string; | 832 return m_value.string; |
818 case CSS_VALUE_ID: | 833 case CSS_VALUE_ID: |
819 return valueName(m_value.valueID); | 834 return valueName(m_value.valueID); |
820 case CSS_PROPERTY_ID: | 835 case CSS_PROPERTY_ID: |
821 return propertyName(m_value.propertyID); | 836 return propertyName(m_value.propertyID); |
| 837 case CSS_VARIABLE_REFERENCE: |
| 838 return m_value.variableData->string(); |
822 default: | 839 default: |
823 break; | 840 break; |
824 } | 841 } |
825 | 842 |
826 return String(); | 843 return String(); |
827 } | 844 } |
828 | 845 |
829 static String formatNumber(double number, const char* suffix, unsigned suffixLen
gth) | 846 static String formatNumber(double number, const char* suffix, unsigned suffixLen
gth) |
830 { | 847 { |
831 #if OS(WIN) && _MSC_VER < 1900 | 848 #if OS(WIN) && _MSC_VER < 1900 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
920 case CSS_RECT: | 937 case CSS_RECT: |
921 case CSS_QUAD: | 938 case CSS_QUAD: |
922 case CSS_RGBCOLOR: | 939 case CSS_RGBCOLOR: |
923 case CSS_PAIR: | 940 case CSS_PAIR: |
924 case CSS_CALC: | 941 case CSS_CALC: |
925 case CSS_SHAPE: | 942 case CSS_SHAPE: |
926 case CSS_IDENT: | 943 case CSS_IDENT: |
927 case CSS_CALC_PERCENTAGE_WITH_NUMBER: | 944 case CSS_CALC_PERCENTAGE_WITH_NUMBER: |
928 case CSS_CALC_PERCENTAGE_WITH_LENGTH: | 945 case CSS_CALC_PERCENTAGE_WITH_LENGTH: |
929 case CSS_QEM: | 946 case CSS_QEM: |
| 947 case CSS_VARIABLE_REFERENCE: |
930 break; | 948 break; |
931 }; | 949 }; |
932 ASSERT_NOT_REACHED(); | 950 ASSERT_NOT_REACHED(); |
933 return ""; | 951 return ""; |
934 } | 952 } |
935 | 953 |
936 String CSSPrimitiveValue::customCSSText() const | 954 String CSSPrimitiveValue::customCSSText() const |
937 { | 955 { |
938 if (m_hasCachedCSSText) { | 956 if (m_hasCachedCSSText) { |
939 ASSERT(cssTextCache().contains(this)); | 957 ASSERT(cssTextCache().contains(this)); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1037 } | 1055 } |
1038 case CSS_PAIR: | 1056 case CSS_PAIR: |
1039 text = getPairValue()->cssText(); | 1057 text = getPairValue()->cssText(); |
1040 break; | 1058 break; |
1041 case CSS_CALC: | 1059 case CSS_CALC: |
1042 text = m_value.calc->cssText(); | 1060 text = m_value.calc->cssText(); |
1043 break; | 1061 break; |
1044 case CSS_SHAPE: | 1062 case CSS_SHAPE: |
1045 text = m_value.shape->cssText(); | 1063 text = m_value.shape->cssText(); |
1046 break; | 1064 break; |
| 1065 case CSS_VARIABLE_REFERENCE: |
| 1066 text = "var(" + String(m_value.string) + ")"; |
| 1067 break; |
1047 } | 1068 } |
1048 | 1069 |
1049 ASSERT(!cssTextCache().contains(this)); | 1070 ASSERT(!cssTextCache().contains(this)); |
1050 cssTextCache().set(this, text); | 1071 cssTextCache().set(this, text); |
1051 m_hasCachedCSSText = true; | 1072 m_hasCachedCSSText = true; |
1052 return text; | 1073 return text; |
1053 } | 1074 } |
1054 | 1075 |
1055 bool CSSPrimitiveValue::equals(const CSSPrimitiveValue& other) const | 1076 bool CSSPrimitiveValue::equals(const CSSPrimitiveValue& other) const |
1056 { | 1077 { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1089 case CSS_FR: | 1110 case CSS_FR: |
1090 return m_value.num == other.m_value.num; | 1111 return m_value.num == other.m_value.num; |
1091 case CSS_PROPERTY_ID: | 1112 case CSS_PROPERTY_ID: |
1092 return m_value.propertyID == other.m_value.propertyID; | 1113 return m_value.propertyID == other.m_value.propertyID; |
1093 case CSS_VALUE_ID: | 1114 case CSS_VALUE_ID: |
1094 return m_value.valueID == other.m_value.valueID; | 1115 return m_value.valueID == other.m_value.valueID; |
1095 case CSS_CUSTOM_IDENT: | 1116 case CSS_CUSTOM_IDENT: |
1096 case CSS_STRING: | 1117 case CSS_STRING: |
1097 case CSS_URI: | 1118 case CSS_URI: |
1098 case CSS_ATTR: | 1119 case CSS_ATTR: |
| 1120 case CSS_VARIABLE_REFERENCE: |
1099 return equal(m_value.string, other.m_value.string); | 1121 return equal(m_value.string, other.m_value.string); |
1100 case CSS_COUNTER: | 1122 case CSS_COUNTER: |
1101 return m_value.counter && other.m_value.counter && m_value.counter->equa
ls(*other.m_value.counter); | 1123 return m_value.counter && other.m_value.counter && m_value.counter->equa
ls(*other.m_value.counter); |
1102 case CSS_RECT: | 1124 case CSS_RECT: |
1103 return m_value.rect && other.m_value.rect && m_value.rect->equals(*other
.m_value.rect); | 1125 return m_value.rect && other.m_value.rect && m_value.rect->equals(*other
.m_value.rect); |
1104 case CSS_QUAD: | 1126 case CSS_QUAD: |
1105 return m_value.quad && other.m_value.quad && m_value.quad->equals(*other
.m_value.quad); | 1127 return m_value.quad && other.m_value.quad && m_value.quad->equals(*other
.m_value.quad); |
1106 case CSS_RGBCOLOR: | 1128 case CSS_RGBCOLOR: |
1107 return m_value.rgbcolor == other.m_value.rgbcolor; | 1129 return m_value.rgbcolor == other.m_value.rgbcolor; |
1108 case CSS_PAIR: | 1130 case CSS_PAIR: |
(...skipping 29 matching lines...) Expand all Loading... |
1138 visitor->trace(m_value.shape); | 1160 visitor->trace(m_value.shape); |
1139 break; | 1161 break; |
1140 default: | 1162 default: |
1141 break; | 1163 break; |
1142 } | 1164 } |
1143 #endif | 1165 #endif |
1144 CSSValue::traceAfterDispatch(visitor); | 1166 CSSValue::traceAfterDispatch(visitor); |
1145 } | 1167 } |
1146 | 1168 |
1147 } // namespace blink | 1169 } // namespace blink |
OLD | NEW |