blob: ad0005371b1540b5440494561a2d54279b2c0585 [file] [log] [blame]
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +01001/*
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
4 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22#ifndef CSSPrimitiveValue_h
23#define CSSPrimitiveValue_h
24
Torne (Richard Coles)5267f702013-06-11 10:57:24 +010025#include "CSSPropertyNames.h"
26#include "CSSValueKeywords.h"
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010027#include "core/css/CSSValue.h"
Torne (Richard Coles)f79f16f2013-10-31 11:16:44 +000028#include "platform/graphics/Color.h"
Torne (Richard Coles)5267f702013-06-11 10:57:24 +010029#include "wtf/Forward.h"
30#include "wtf/MathExtras.h"
31#include "wtf/PassRefPtr.h"
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010032
33namespace WebCore {
34
Ben Murdochdf957042013-08-06 11:01:27 +010035class CSSBasicShape;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010036class CSSCalcValue;
Torne (Richard Coles)a854de02013-12-18 16:25:25 +000037class CSSToLengthConversionData;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010038class Counter;
Ben Murdochdf957042013-08-06 11:01:27 +010039class ExceptionState;
Torne (Richard Coles)bfe35902013-10-22 16:41:51 +010040class Length;
Torne (Richard Coles)09380292014-02-21 12:17:33 +000041class LengthSize;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010042class Pair;
43class Quad;
44class RGBColor;
45class Rect;
46class RenderStyle;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010047
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010048// Dimension calculations are imprecise, often resulting in values of e.g.
49// 44.99998. We need to go ahead and round if we're really close to the next
50// integer value.
51template<typename T> inline T roundForImpreciseConversion(double value)
52{
53 value += (value < 0) ? -0.01 : +0.01;
54 return ((value > std::numeric_limits<T>::max()) || (value < std::numeric_limits<T>::min())) ? 0 : static_cast<T>(value);
55}
56
57template<> inline float roundForImpreciseConversion(double value)
58{
59 double ceiledValue = ceil(value);
60 double proximityToNextInt = ceiledValue - value;
61 if (proximityToNextInt <= 0.01 && value > 0)
62 return static_cast<float>(ceiledValue);
63 if (proximityToNextInt >= 0.99 && value < 0)
64 return static_cast<float>(floor(value));
65 return static_cast<float>(value);
66}
67
68class CSSPrimitiveValue : public CSSValue {
69public:
70 enum UnitTypes {
71 CSS_UNKNOWN = 0,
72 CSS_NUMBER = 1,
73 CSS_PERCENTAGE = 2,
74 CSS_EMS = 3,
75 CSS_EXS = 4,
76 CSS_PX = 5,
77 CSS_CM = 6,
78 CSS_MM = 7,
79 CSS_IN = 8,
80 CSS_PT = 9,
81 CSS_PC = 10,
82 CSS_DEG = 11,
83 CSS_RAD = 12,
84 CSS_GRAD = 13,
85 CSS_MS = 14,
86 CSS_S = 15,
87 CSS_HZ = 16,
88 CSS_KHZ = 17,
89 CSS_DIMENSION = 18,
90 CSS_STRING = 19,
91 CSS_URI = 20,
92 CSS_IDENT = 21,
93 CSS_ATTR = 22,
94 CSS_COUNTER = 23,
95 CSS_RECT = 24,
96 CSS_RGBCOLOR = 25,
97 // From CSS Values and Units. Viewport-percentage Lengths (vw/vh/vmin/vmax).
98 CSS_VW = 26,
99 CSS_VH = 27,
100 CSS_VMIN = 28,
101 CSS_VMAX = 29,
102 CSS_DPPX = 30,
103 CSS_DPI = 31,
104 CSS_DPCM = 32,
105 CSS_FR = 33,
106 CSS_PAIR = 100, // We envision this being exposed as a means of getting computed style values for pairs (border-spacing/radius, background-position, etc.)
107 CSS_UNICODE_RANGE = 102,
108
109 // These next types are just used internally to allow us to translate back and forth from CSSPrimitiveValues to CSSParserValues.
110 CSS_PARSER_OPERATOR = 103,
111 CSS_PARSER_INTEGER = 104,
112 CSS_PARSER_HEXCOLOR = 105,
113
114 // This is used internally for unknown identifiers
115 CSS_PARSER_IDENTIFIER = 106,
116
117 // These are from CSS3 Values and Units, but that isn't a finished standard yet
118 CSS_TURN = 107,
119 CSS_REMS = 108,
120 CSS_CHS = 109,
121
122 // This is used internally for counter names (as opposed to counter values)
123 CSS_COUNTER_NAME = 110,
124
Ben Murdoch591b9582013-07-10 11:41:44 +0100125 // This is used by the CSS Shapes draft
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100126 CSS_SHAPE = 111,
127
128 // Used by border images.
129 CSS_QUAD = 112,
130
131 CSS_CALC = 113,
132 CSS_CALC_PERCENTAGE_WITH_NUMBER = 114,
133 CSS_CALC_PERCENTAGE_WITH_LENGTH = 115,
Torne (Richard Coles)5267f702013-06-11 10:57:24 +0100134
135 CSS_PROPERTY_ID = 117,
136 CSS_VALUE_ID = 118
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100137 };
138
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000139 // This enum follows the BisonCSSParser::Units enum augmented with UNIT_FREQUENCY for frequencies.
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100140 enum UnitCategory {
141 UNumber,
142 UPercent,
143 ULength,
144 UAngle,
145 UTime,
146 UFrequency,
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100147 UResolution,
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100148 UOther
149 };
Torne (Richard Coles)521d96e2013-06-19 11:58:24 +0100150 static UnitCategory unitCategory(CSSPrimitiveValue::UnitTypes);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100151
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +0000152 typedef HashMap<String, CSSPrimitiveValue::UnitTypes> UnitTable;
153 static UnitTable& getUnitTable();
154
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100155 bool isAngle() const
156 {
157 return m_primitiveUnitType == CSS_DEG
158 || m_primitiveUnitType == CSS_RAD
159 || m_primitiveUnitType == CSS_GRAD
160 || m_primitiveUnitType == CSS_TURN;
161 }
162 bool isAttr() const { return m_primitiveUnitType == CSS_ATTR; }
163 bool isCounter() const { return m_primitiveUnitType == CSS_COUNTER; }
164 bool isFontIndependentLength() const { return m_primitiveUnitType >= CSS_PX && m_primitiveUnitType <= CSS_PC; }
165 bool isFontRelativeLength() const
166 {
167 return m_primitiveUnitType == CSS_EMS
168 || m_primitiveUnitType == CSS_EXS
169 || m_primitiveUnitType == CSS_REMS
170 || m_primitiveUnitType == CSS_CHS;
171 }
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100172 bool isLength() const
173 {
174 unsigned short type = primitiveType();
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000175 return (type >= CSS_EMS && type <= CSS_PC) || type == CSS_REMS || type == CSS_CHS || isViewportPercentageLength();
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100176 }
177 bool isNumber() const { return primitiveType() == CSS_NUMBER; }
178 bool isPercentage() const { return primitiveType() == CSS_PERCENTAGE; }
179 bool isPx() const { return primitiveType() == CSS_PX; }
180 bool isRect() const { return m_primitiveUnitType == CSS_RECT; }
181 bool isRGBColor() const { return m_primitiveUnitType == CSS_RGBCOLOR; }
182 bool isShape() const { return m_primitiveUnitType == CSS_SHAPE; }
183 bool isString() const { return m_primitiveUnitType == CSS_STRING; }
184 bool isTime() const { return m_primitiveUnitType == CSS_S || m_primitiveUnitType == CSS_MS; }
185 bool isURI() const { return m_primitiveUnitType == CSS_URI; }
186 bool isCalculated() const { return m_primitiveUnitType == CSS_CALC; }
187 bool isCalculatedPercentageWithNumber() const { return primitiveType() == CSS_CALC_PERCENTAGE_WITH_NUMBER; }
188 bool isCalculatedPercentageWithLength() const { return primitiveType() == CSS_CALC_PERCENTAGE_WITH_LENGTH; }
189 bool isDotsPerInch() const { return primitiveType() == CSS_DPI; }
190 bool isDotsPerPixel() const { return primitiveType() == CSS_DPPX; }
191 bool isDotsPerCentimeter() const { return primitiveType() == CSS_DPCM; }
Torne (Richard Coles)e5249552013-05-15 11:35:13 +0100192 bool isResolution() const
193 {
194 unsigned short type = primitiveType();
195 return type >= CSS_DPPX && type <= CSS_DPCM;
196 }
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100197 bool isViewportPercentageLength() const { return m_primitiveUnitType >= CSS_VW && m_primitiveUnitType <= CSS_VMAX; }
198 bool isFlex() const { return primitiveType() == CSS_FR; }
Torne (Richard Coles)5267f702013-06-11 10:57:24 +0100199 bool isValueID() const { return m_primitiveUnitType == CSS_VALUE_ID; }
Ben Murdoch591b9582013-07-10 11:41:44 +0100200 bool colorIsDerivedFromElement() const;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100201
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000202 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createIdentifier(CSSValueID valueID)
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100203 {
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +0000204 return adoptRefWillBeRefCountedGarbageCollected(new CSSPrimitiveValue(valueID));
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000205 }
206 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createIdentifier(CSSPropertyID propertyID)
207 {
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +0000208 return adoptRefWillBeRefCountedGarbageCollected(new CSSPrimitiveValue(propertyID));
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000209 }
210 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createParserOperator(int parserOperator)
211 {
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +0000212 return adoptRefWillBeRefCountedGarbageCollected(new CSSPrimitiveValue(parserOperator));
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000213 }
214 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createColor(unsigned rgbValue)
215 {
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +0000216 return adoptRefWillBeRefCountedGarbageCollected(new CSSPrimitiveValue(rgbValue));
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000217 }
218 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(double value, UnitTypes type)
219 {
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +0000220 return adoptRefWillBeRefCountedGarbageCollected(new CSSPrimitiveValue(value, type));
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000221 }
222 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const String& value, UnitTypes type)
223 {
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +0000224 return adoptRefWillBeRefCountedGarbageCollected(new CSSPrimitiveValue(value, type));
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000225 }
226 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const Length& value, float zoom)
227 {
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +0000228 return adoptRefWillBeRefCountedGarbageCollected(new CSSPrimitiveValue(value, zoom));
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000229 }
230 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const LengthSize& value)
231 {
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +0000232 return adoptRefWillBeRefCountedGarbageCollected(new CSSPrimitiveValue(value));
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000233 }
234 template<typename T> static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(T value)
235 {
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +0000236 return adoptRefWillBeRefCountedGarbageCollected(new CSSPrimitiveValue(value));
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100237 }
238
239 // This value is used to handle quirky margins in reflow roots (body, td, and th) like WinIE.
240 // The basic idea is that a stylesheet can use the value __qem (for quirky em) instead of em.
241 // When the quirky value is used, if you're in quirks mode, the margin will collapse away
242 // inside a table cell.
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000243 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createAllowingMarginQuirk(double value, UnitTypes type)
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100244 {
245 CSSPrimitiveValue* quirkValue = new CSSPrimitiveValue(value, type);
246 quirkValue->m_isQuirkValue = true;
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +0000247 return adoptRefWillBeRefCountedGarbageCollected(quirkValue);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100248 }
249
250 ~CSSPrimitiveValue();
251
252 void cleanup();
253
254 unsigned short primitiveType() const;
255
256 double computeDegrees();
257
258 enum TimeUnit { Seconds, Milliseconds };
259 template <typename T, TimeUnit timeUnit> T computeTime()
260 {
261 if (timeUnit == Seconds && m_primitiveUnitType == CSS_S)
262 return getValue<T>();
263 if (timeUnit == Seconds && m_primitiveUnitType == CSS_MS)
264 return getValue<T>() / 1000;
265 if (timeUnit == Milliseconds && m_primitiveUnitType == CSS_MS)
266 return getValue<T>();
267 if (timeUnit == Milliseconds && m_primitiveUnitType == CSS_S)
268 return getValue<T>() * 1000;
269 ASSERT_NOT_REACHED();
270 return 0;
271 }
272
273 /*
Torne (Richard Coles)a854de02013-12-18 16:25:25 +0000274 * Computes a length in pixels out of the given CSSValue
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100275 *
276 * The metrics have to be a bit different for screen and printer output.
277 * For screen output we assume 1 inch == 72 px, for printer we assume 300 dpi
278 *
279 * this is screen/printer dependent, so we probably need a config option for this,
280 * and some tool to calibrate.
281 */
Torne (Richard Coles)a854de02013-12-18 16:25:25 +0000282 template<typename T> T computeLength(const CSSToLengthConversionData&);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100283
284 // Converts to a Length, mapping various unit types appropriately.
Torne (Richard Coles)a854de02013-12-18 16:25:25 +0000285 template<int> Length convertToLength(const CSSToLengthConversionData&);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100286
287 // use with care!!!
288 void setPrimitiveType(unsigned short type) { m_primitiveUnitType = type; }
289
Ben Murdochdf957042013-08-06 11:01:27 +0100290 double getDoubleValue(unsigned short unitType, ExceptionState&) const;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100291 double getDoubleValue(unsigned short unitType) const;
292 double getDoubleValue() const;
293
Ben Murdochdf957042013-08-06 11:01:27 +0100294 void setFloatValue(unsigned short unitType, double floatValue, ExceptionState&);
Torne (Richard Coles)51b29062013-11-28 11:56:03 +0000295 float getFloatValue(unsigned short unitType, ExceptionState& exceptionState) const { return getValue<float>(unitType, exceptionState); }
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100296 float getFloatValue(unsigned short unitType) const { return getValue<float>(unitType); }
297 float getFloatValue() const { return getValue<float>(); }
298
Torne (Richard Coles)51b29062013-11-28 11:56:03 +0000299 int getIntValue(unsigned short unitType, ExceptionState& exceptionState) const { return getValue<int>(unitType, exceptionState); }
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100300 int getIntValue(unsigned short unitType) const { return getValue<int>(unitType); }
301 int getIntValue() const { return getValue<int>(); }
302
Torne (Richard Coles)51b29062013-11-28 11:56:03 +0000303 template<typename T> inline T getValue(unsigned short unitType, ExceptionState& exceptionState) const { return clampTo<T>(getDoubleValue(unitType, exceptionState)); }
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100304 template<typename T> inline T getValue(unsigned short unitType) const { return clampTo<T>(getDoubleValue(unitType)); }
305 template<typename T> inline T getValue() const { return clampTo<T>(getDoubleValue()); }
306
Ben Murdochdf957042013-08-06 11:01:27 +0100307 void setStringValue(unsigned short stringType, const String& stringValue, ExceptionState&);
308 String getStringValue(ExceptionState&) const;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100309 String getStringValue() const;
310
Ben Murdochdf957042013-08-06 11:01:27 +0100311 Counter* getCounterValue(ExceptionState&) const;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100312 Counter* getCounterValue() const { return m_primitiveUnitType != CSS_COUNTER ? 0 : m_value.counter; }
313
Ben Murdochdf957042013-08-06 11:01:27 +0100314 Rect* getRectValue(ExceptionState&) const;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100315 Rect* getRectValue() const { return m_primitiveUnitType != CSS_RECT ? 0 : m_value.rect; }
316
Ben Murdochdf957042013-08-06 11:01:27 +0100317 Quad* getQuadValue(ExceptionState&) const;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100318 Quad* getQuadValue() const { return m_primitiveUnitType != CSS_QUAD ? 0 : m_value.quad; }
319
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +0000320 PassRefPtrWillBeRawPtr<RGBColor> getRGBColorValue(ExceptionState&) const;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100321 RGBA32 getRGBA32Value() const { return m_primitiveUnitType != CSS_RGBCOLOR ? 0 : m_value.rgbcolor; }
322
Ben Murdochdf957042013-08-06 11:01:27 +0100323 Pair* getPairValue(ExceptionState&) const;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100324 Pair* getPairValue() const { return m_primitiveUnitType != CSS_PAIR ? 0 : m_value.pair; }
325
326 CSSBasicShape* getShapeValue() const { return m_primitiveUnitType != CSS_SHAPE ? 0 : m_value.shape; }
Ben Murdoch02772c62013-07-26 10:21:05 +0100327
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100328 CSSCalcValue* cssCalcValue() const { return m_primitiveUnitType != CSS_CALC ? 0 : m_value.calc; }
329
Torne (Richard Coles)5267f702013-06-11 10:57:24 +0100330 CSSPropertyID getPropertyID() const { return m_primitiveUnitType == CSS_PROPERTY_ID ? m_value.propertyID : CSSPropertyInvalid; }
331 CSSValueID getValueID() const { return m_primitiveUnitType == CSS_VALUE_ID ? m_value.valueID : CSSValueInvalid; }
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100332
333 template<typename T> inline operator T() const; // Defined in CSSPrimitiveValueMappings.h
334
Torne (Richard Coles)bfe35902013-10-22 16:41:51 +0100335 String customCSSText(CSSTextFormattingFlags = QuoteCSSStringIfNeeded) const;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100336
337 bool isQuirkValue() { return m_isQuirkValue; }
338
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000339 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> cloneForCSSOM() const;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100340 void setCSSOMSafe() { m_isCSSOMSafe = true; }
341
342 bool equals(const CSSPrimitiveValue&) const;
343
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000344 void traceAfterDispatch(Visitor*);
345
Torne (Richard Coles)521d96e2013-06-19 11:58:24 +0100346 static UnitTypes canonicalUnitTypeForCategory(UnitCategory);
347 static double conversionToCanonicalUnitsScaleFactor(unsigned short unitType);
348
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100349private:
Torne (Richard Coles)5267f702013-06-11 10:57:24 +0100350 CSSPrimitiveValue(CSSValueID);
351 CSSPrimitiveValue(CSSPropertyID);
352 // FIXME: int vs. unsigned overloading is too subtle to distinguish the color and operator cases.
353 CSSPrimitiveValue(int parserOperator);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100354 CSSPrimitiveValue(unsigned color); // RGB value
Torne (Richard Coles)c0e19a62013-08-30 15:15:11 +0100355 CSSPrimitiveValue(const Length& length)
356 : CSSValue(PrimitiveClass)
357 {
358 init(length);
359 }
Torne (Richard Coles)1e202182013-10-18 15:46:42 +0100360 CSSPrimitiveValue(const Length&, float zoom);
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000361 CSSPrimitiveValue(const LengthSize&);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100362 CSSPrimitiveValue(const String&, UnitTypes);
363 CSSPrimitiveValue(double, UnitTypes);
364
365 template<typename T> CSSPrimitiveValue(T); // Defined in CSSPrimitiveValueMappings.h
366 template<typename T> CSSPrimitiveValue(T* val)
367 : CSSValue(PrimitiveClass)
368 {
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +0000369 init(PassRefPtrWillBeRawPtr<T>(val));
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100370 }
371
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +0000372 template<typename T> CSSPrimitiveValue(PassRefPtrWillBeRawPtr<T> val)
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100373 : CSSValue(PrimitiveClass)
374 {
375 init(val);
376 }
377
378 static void create(int); // compile-time guard
379 static void create(unsigned); // compile-time guard
380 template<typename T> operator T*(); // compile-time guard
381
Torne (Richard Coles)c0e19a62013-08-30 15:15:11 +0100382 void init(const Length&);
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000383 void init(const LengthSize&);
384 void init(PassRefPtrWillBeRawPtr<Counter>);
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +0000385 void init(PassRefPtrWillBeRawPtr<Rect>);
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000386 void init(PassRefPtrWillBeRawPtr<Pair>);
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +0000387 void init(PassRefPtrWillBeRawPtr<Quad>);
388 void init(PassRefPtrWillBeRawPtr<CSSBasicShape>);
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000389 void init(PassRefPtrWillBeRawPtr<CSSCalcValue>);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100390 bool getDoubleValueInternal(UnitTypes targetUnitType, double* result) const;
391
Torne (Richard Coles)a854de02013-12-18 16:25:25 +0000392 double computeLengthDouble(const CSSToLengthConversionData&);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100393
394 union {
Torne (Richard Coles)5267f702013-06-11 10:57:24 +0100395 CSSPropertyID propertyID;
396 CSSValueID valueID;
397 int parserOperator;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100398 double num;
399 StringImpl* string;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100400 unsigned rgbcolor;
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000401 // FIXME: oilpan: Should be members, but no support for members in unions. Just trace the raw ptr for now.
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +0000402 CSSBasicShape* shape;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100403 CSSCalcValue* calc;
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000404 Counter* counter;
405 Pair* pair;
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +0000406 Rect* rect;
407 Quad* quad;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100408 } m_value;
409};
410
Torne (Richard Coles)bfe35902013-10-22 16:41:51 +0100411DEFINE_CSS_VALUE_TYPE_CASTS(CSSPrimitiveValue, isPrimitiveValue());
Torne (Richard Coles)e5249552013-05-15 11:35:13 +0100412
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100413} // namespace WebCore
414
415#endif // CSSPrimitiveValue_h