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

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

Issue 1226273002: CSSValue Immediates: Make CSSPrimitiveValue store a tagged pointer (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@cssvalue_patch_2_attempt_2
Patch Set: Rebase Created 5 years, 4 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
« no previous file with comments | « Source/core/core.gypi ('k') | Source/core/css/CSSPrimitiveValue.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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, 2008 Apple Inc. All rights reserved. 3 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
4 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 4 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 CSS_IN = 8, 102 CSS_IN = 8,
103 CSS_PT = 9, 103 CSS_PT = 9,
104 CSS_PC = 10, 104 CSS_PC = 10,
105 CSS_DEG = 11, 105 CSS_DEG = 11,
106 CSS_RAD = 12, 106 CSS_RAD = 12,
107 CSS_GRAD = 13, 107 CSS_GRAD = 13,
108 CSS_MS = 14, 108 CSS_MS = 14,
109 CSS_S = 15, 109 CSS_S = 15,
110 CSS_HZ = 16, 110 CSS_HZ = 16,
111 CSS_KHZ = 17, 111 CSS_KHZ = 17,
112 CSS_CUSTOM_IDENT = 19, 112 CSS_CUSTOM_IDENT = 18,
113 CSS_URI = 20, 113 CSS_URI = 19,
114 CSS_IDENT = 21, 114 CSS_IDENT = 20,
115 CSS_ATTR = 22, 115 CSS_ATTR = 21,
116 CSS_COUNTER = 23, 116 CSS_COUNTER = 22,
117 CSS_RECT = 24, 117 CSS_RECT = 23,
118 CSS_RGBCOLOR = 25, 118 CSS_RGBCOLOR = 24,
119 CSS_VW = 26, 119 CSS_VW = 25,
120 CSS_VH = 27, 120 CSS_VH = 26,
121 CSS_VMIN = 28, 121 CSS_VMIN = 27,
122 CSS_VMAX = 29, 122 CSS_VMAX = 28,
123 CSS_DPPX = 30, 123 CSS_DPPX = 29,
124 CSS_DPI = 31, 124 CSS_DPI = 30,
125 CSS_DPCM = 32, 125 CSS_DPCM = 31,
126 CSS_FR = 33, 126 CSS_FR = 32,
127 CSS_INTEGER = 34, 127 CSS_INTEGER = 33,
128 CSS_PAIR = 100, 128 CSS_PAIR = 34,
129 CSS_TURN = 107, 129 CSS_TURN = 35,
130 CSS_REMS = 108, 130 CSS_REMS = 36,
131 CSS_CHS = 109, 131 CSS_CHS = 37,
132 CSS_SHAPE = 111, 132 CSS_SHAPE = 38,
133 CSS_QUAD = 112, 133 CSS_QUAD = 39,
134 CSS_CALC = 113, 134 CSS_CALC = 40,
135 CSS_CALC_PERCENTAGE_WITH_NUMBER = 114, 135 CSS_CALC_PERCENTAGE_WITH_NUMBER = 41,
136 CSS_CALC_PERCENTAGE_WITH_LENGTH = 115, 136 CSS_CALC_PERCENTAGE_WITH_LENGTH = 42,
137 CSS_STRING = 116, 137 CSS_STRING = 43,
138 CSS_PROPERTY_ID = 117, 138 CSS_PROPERTY_ID = 44,
139 CSS_VALUE_ID = 118, 139 CSS_VALUE_ID = 45,
140 CSS_QEM = 119 140 CSS_QEM = 46
141 }; 141 };
142 142
143 enum LengthUnitType { 143 enum LengthUnitType {
144 UnitTypePixels = 0, 144 UnitTypePixels = 0,
145 UnitTypePercentage, 145 UnitTypePercentage,
146 UnitTypeFontSize, 146 UnitTypeFontSize,
147 UnitTypeFontXSize, 147 UnitTypeFontXSize,
148 UnitTypeRootFontSize, 148 UnitTypeRootFontSize,
149 UnitTypeZeroCharacterWidth, 149 UnitTypeZeroCharacterWidth,
150 UnitTypeViewportWidth, 150 UnitTypeViewportWidth,
151 UnitTypeViewportHeight, 151 UnitTypeViewportHeight,
152 UnitTypeViewportMin, 152 UnitTypeViewportMin,
153 UnitTypeViewportMax, 153 UnitTypeViewportMax,
154 154
155 // This value must come after the last length unit type to enable iterat ion over the length unit types. 155 // This value must come after the last length unit type to enable iterat ion over the length unit types.
156 LengthUnitTypeCount, 156 LengthUnitTypeCount,
157 }; 157 };
158 158
159 typedef Vector<double, CSSPrimitiveValue::LengthUnitTypeCount> CSSLengthArra y; 159 typedef Vector<double, CSSPrimitiveValue::LengthUnitTypeCount> CSSLengthArra y;
160 typedef BitVector CSSLengthTypeArray; 160 typedef BitVector CSSLengthTypeArray;
161 161
162 struct CSSTaggedPtrValue {
163 // Variables for accessing parts of the tagged pointer.
164 // 32 bits = <value 25 bits><type 6 bits><tag 1 bit>
165 // 64 bits = <value 57 bits><type 6 bits><tag 1 bit>
166 #if CPU(32BIT)
167 static const uint doubleShiftAmount = 32 + 7;
168 static const uint64_t mantissaTruncationMask = 0x7fffffffff;
169 #elif CPU(64BIT)
170 static const uint doubleShiftAmount = 7;
171 static const uint64_t mantissaTruncationMask = 0x7f;
172 #endif
173
174 unsigned flag : 1;
175 unsigned type : 6;
176 #if CPU(32BIT)
177 unsigned long long valueRaw : 25;
178 #elif CPU(64BIT)
179 unsigned long long valueRaw : 57;
180 #endif
181
182 typedef struct {
183 unsigned red : 8;
184 unsigned green : 8;
185 unsigned blue : 8;
186 #if CPU(32BIT)
187 unsigned alpha : 1;
188 #elif CPU(64BIT)
189 unsigned alpha : 8;
190 #endif
191 } packedColor;
192
193
194 // Returns true if value can be stored in the value field of the tagged pointer
195 // without losing information.
196 inline static bool fitsWithoutDataLoss(double value)
197 {
198 union {
199 double asDouble;
200 uint64_t asBits;
201 } interpretableValue;
202 interpretableValue.asDouble = value;
203 return (interpretableValue.asBits & mantissaTruncationMask) == 0;
204 }
205
206 inline static bool fitsWithoutDataLoss(RGBA32 color)
207 {
208 #if CPU(32BIT)
209 return alphaChannel(color) == 0 || alphaChannel(color) == 255;
210 #elif CPU(64BIT)
211 return true;
212 #endif
213 }
214
215 // Convenience methods for getting/setting the value field, which is tru ncated.
216 inline double getValue() const
217 {
218 uint64_t shiftedValue = valueRaw;
219 shiftedValue = shiftedValue << doubleShiftAmount;
220 return *reinterpret_cast<double*>(&shiftedValue);
221 }
222
223 inline RGBA32 getColorValue() const
224 {
225 uintptr_t valueRawVar = valueRaw;
226 packedColor color = *reinterpret_cast<packedColor*>(&valueRawVar);
227 int alpha = color.alpha;
228 #if CPU(32BIT)
229 alpha = color.alpha == 1 ? 255 : 0;
230 #endif
231 return makeRGBA(color.red, color.green, color.blue, alpha);
232 }
233
234 inline CSSPropertyID getPropertyIDValue() const
235 {
236 return static_cast<CSSPropertyID>(valueRaw);
237 }
238
239 inline CSSValueID getValueIDValue() const
240 {
241 return static_cast<CSSValueID>(valueRaw);
242 }
243
244 inline void setValue(double value)
245 {
246 union {
247 double asDouble;
248 uint64_t asBits;
249 } interpretableValue;
250 interpretableValue.asDouble = value;
251 valueRaw = interpretableValue.asBits >> doubleShiftAmount;
252 }
253
254 inline void setValue(RGBA32 value)
255 {
256 packedColor color;
257 color.red = static_cast<uintptr_t>(redChannel(value));
258 color.green = static_cast<uintptr_t>(greenChannel(value));
259 color.blue = static_cast<uintptr_t>(blueChannel(value));
260 #if CPU(32BIT)
261 color.alpha = static_cast<uintptr_t>(alphaChannel(value) == 255 ? 1 : 0);
262 #elif CPU(64BIT)
263 color.alpha = static_cast<uintptr_t>(alphaChannel(value));
264 #endif
265 valueRaw = *reinterpret_cast<uintptr_t*>(&color);
266 }
267
268 inline void setValue(CSSPropertyID propertyID)
269 {
270 valueRaw = static_cast<uintptr_t>(propertyID);
271 }
272
273 inline void setValue(CSSValueID valueID)
274 {
275 valueRaw = static_cast<uintptr_t>(valueID);
276 }
277 };
278
162 // No methods here, don't use this. It's just for large value storage. 279 // No methods here, don't use this. It's just for large value storage.
163 // IMPORTANT: You should never actually make one of these outside the parser . 280 // IMPORTANT: You should never actually make one of these outside the parser .
164 class CSSLargePrimitiveValue final : public CSSValueObject { 281 class CSSLargePrimitiveValue final : public CSSValueObject {
165 friend class CSSPrimitiveValue; 282 friend class CSSPrimitiveValue;
166 public: 283 public:
167 CSSLargePrimitiveValue(CSSValueID); 284 CSSLargePrimitiveValue(CSSValueID);
168 CSSLargePrimitiveValue(CSSPropertyID); 285 CSSLargePrimitiveValue(CSSPropertyID);
169 CSSLargePrimitiveValue(RGBA32 color); 286 CSSLargePrimitiveValue(RGBA32 color);
170 CSSLargePrimitiveValue(const Length&, float zoom); 287 CSSLargePrimitiveValue(const Length&, float zoom);
171 CSSLargePrimitiveValue(const LengthSize&, const ComputedStyle&); 288 CSSLargePrimitiveValue(const LengthSize&, const ComputedStyle&);
(...skipping 27 matching lines...) Expand all
199 void init(PassRefPtrWillBeRawPtr<Counter>); 316 void init(PassRefPtrWillBeRawPtr<Counter>);
200 void init(PassRefPtrWillBeRawPtr<Rect>); 317 void init(PassRefPtrWillBeRawPtr<Rect>);
201 void init(PassRefPtrWillBeRawPtr<Pair>); 318 void init(PassRefPtrWillBeRawPtr<Pair>);
202 void init(PassRefPtrWillBeRawPtr<Quad>); 319 void init(PassRefPtrWillBeRawPtr<Quad>);
203 void init(PassRefPtrWillBeRawPtr<CSSBasicShape>); 320 void init(PassRefPtrWillBeRawPtr<CSSBasicShape>);
204 void init(PassRefPtrWillBeRawPtr<CSSCalcValue>); 321 void init(PassRefPtrWillBeRawPtr<CSSCalcValue>);
205 322
206 CSSPrimitiveValueData m_value; 323 CSSPrimitiveValueData m_value;
207 }; 324 };
208 325
326 explicit CSSPrimitiveValue(CSSTaggedPtrValue taggedPtr)
327 : m_rawValue(taggedPtr)
328 {
329 ASSERT(!isObject());
330 }
331
209 explicit CSSPrimitiveValue(const CSSLargePrimitiveValue* object) 332 explicit CSSPrimitiveValue(const CSSLargePrimitiveValue* object)
210 : m_rawValue(const_cast<CSSLargePrimitiveValue*>(object)) 333 : m_rawValue(const_cast<CSSLargePrimitiveValue*>(object))
211 { 334 {
212 ref(); 335 ref();
213 } 336 }
214 337
215 CSSPrimitiveValue(PassRefPtrWillBeRawPtr<CSSLargePrimitiveValue> cssValue) 338 CSSPrimitiveValue(PassRefPtrWillBeRawPtr<CSSLargePrimitiveValue> cssValue)
216 : m_rawValue(cssValue.leakRef()) 339 : m_rawValue(cssValue.leakRef())
217 { 340 {
218 } 341 }
219 342
220 343
221 CSSPrimitiveValue(const CSSPrimitiveValue& other) 344 CSSPrimitiveValue(const CSSPrimitiveValue& other)
222 : m_rawValue(other.m_rawValue) 345 : m_rawValue(other.m_rawValue.asPtr)
223 { 346 {
224 ref(); 347 ref();
225 } 348 }
226 349
227 CSSPrimitiveValue& operator=(const CSSPrimitiveValue& rhs) 350 CSSPrimitiveValue& operator=(const CSSPrimitiveValue& rhs)
228 { 351 {
229 rhs.ref(); 352 rhs.ref();
230 deref(); 353 deref();
231 m_rawValue = rhs.m_rawValue; 354 m_rawValue = rhs.m_rawValue;
232 return *this; 355 return *this;
233 } 356 }
234 357
235 ~CSSPrimitiveValue() 358 ~CSSPrimitiveValue()
236 { 359 {
237 deref(); 360 deref();
238 } 361 }
239 362
240 363
241 CSSLargePrimitiveValue* get() const 364 CSSLargePrimitiveValue* get() const
242 { 365 {
243 return m_rawValue; 366 return m_rawValue.asPtr;
244 } 367 }
245 368
246 void accumulateLengthArray(CSSLengthArray&, double multiplier = 1) const; 369 void accumulateLengthArray(CSSLengthArray&, double multiplier = 1) const;
247 void accumulateLengthArray(CSSLengthArray&, CSSLengthTypeArray&, double mult iplier = 1) const; 370 void accumulateLengthArray(CSSLengthArray&, CSSLengthTypeArray&, double mult iplier = 1) const;
248 371
249 enum UnitCategory { 372 enum UnitCategory {
250 UNumber, 373 UNumber,
251 UPercent, 374 UPercent,
252 ULength, 375 ULength,
253 UAngle, 376 UAngle,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 static bool isDotsPerInch(UnitType type) { return type == CSS_DPI; } 425 static bool isDotsPerInch(UnitType type) { return type == CSS_DPI; }
303 static bool isDotsPerPixel(UnitType type) { return type == CSS_DPPX; } 426 static bool isDotsPerPixel(UnitType type) { return type == CSS_DPPX; }
304 static bool isDotsPerCentimeter(UnitType type) { return type == CSS_DPCM; } 427 static bool isDotsPerCentimeter(UnitType type) { return type == CSS_DPCM; }
305 static bool isResolution(UnitType type) { return type >= CSS_DPPX && type <= CSS_DPCM; } 428 static bool isResolution(UnitType type) { return type >= CSS_DPPX && type <= CSS_DPCM; }
306 bool isFlex() const { return primitiveType() == CSS_FR; } 429 bool isFlex() const { return primitiveType() == CSS_FR; }
307 bool isValueID() const { return type() == CSS_VALUE_ID; } 430 bool isValueID() const { return type() == CSS_VALUE_ID; }
308 bool colorIsDerivedFromElement() const; 431 bool colorIsDerivedFromElement() const;
309 432
310 static CSSPrimitiveValue createIdentifier(CSSValueID valueID) 433 static CSSPrimitiveValue createIdentifier(CSSValueID valueID)
311 { 434 {
312 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(v alueID))); 435 CSSTaggedPtrValue taggedPointer;
436 taggedPointer.flag = 1;
437 taggedPointer.type = CSS_VALUE_ID;
438 taggedPointer.setValue(valueID);
439 return CSSPrimitiveValue(taggedPointer);
313 } 440 }
441
314 static CSSPrimitiveValue createIdentifier(CSSPropertyID propertyID) 442 static CSSPrimitiveValue createIdentifier(CSSPropertyID propertyID)
315 { 443 {
316 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(p ropertyID))); 444 CSSTaggedPtrValue taggedPointer;
445 taggedPointer.flag = 1;
446 taggedPointer.type = CSS_PROPERTY_ID;
447 taggedPointer.setValue(propertyID);
448 return CSSPrimitiveValue(taggedPointer);
317 } 449 }
318 static CSSPrimitiveValue createColor(RGBA32 rgbValue) 450 static CSSPrimitiveValue createColor(RGBA32 rgbValue)
319 { 451 {
452 if (CSSTaggedPtrValue::fitsWithoutDataLoss(rgbValue)) {
453 CSSTaggedPtrValue taggedPointer;
454 taggedPointer.flag = 1;
455 taggedPointer.type = CSS_RGBCOLOR;
456 taggedPointer.setValue(rgbValue);
457 return CSSPrimitiveValue(taggedPointer);
458 }
320 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(r gbValue))); 459 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(r gbValue)));
321 } 460 }
322 static CSSPrimitiveValue create(double value, UnitType type) 461 static CSSPrimitiveValue create(double value, UnitType type)
323 { 462 {
463 if (CSSTaggedPtrValue::fitsWithoutDataLoss(value)) {
464 CSSTaggedPtrValue taggedPointer;
465 taggedPointer.flag = 1;
466 taggedPointer.type = type;
467 taggedPointer.setValue(value);
468 return CSSPrimitiveValue(taggedPointer);
469 }
324 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(v alue, type))); 470 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(v alue, type)));
325 } 471 }
326 static CSSPrimitiveValue create(const String& value, UnitType type) 472 static CSSPrimitiveValue create(const String& value, UnitType type)
327 { 473 {
328 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(v alue, type))); 474 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(v alue, type)));
329 } 475 }
330 static CSSPrimitiveValue create(const Length& value, float zoom) 476 static CSSPrimitiveValue create(const Length& value, float zoom)
331 { 477 {
332 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(v alue, zoom))); 478 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(v alue, zoom)));
333 } 479 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 CSSPropertyID getPropertyID() const { return type() == CSS_PROPERTY_ID ? val ue().propertyID : CSSPropertyInvalid; } 530 CSSPropertyID getPropertyID() const { return type() == CSS_PROPERTY_ID ? val ue().propertyID : CSSPropertyInvalid; }
385 CSSValueID getValueID() const { return type() == CSS_VALUE_ID ? value().valu eID : CSSValueInvalid; } 531 CSSValueID getValueID() const { return type() == CSS_VALUE_ID ? value().valu eID : CSSValueInvalid; }
386 532
387 template<typename T> inline operator T() const; // Defined in CSSPrimitiveVa lueMappings.h 533 template<typename T> inline operator T() const; // Defined in CSSPrimitiveVa lueMappings.h
388 534
389 static const char* unitTypeToString(UnitType); 535 static const char* unitTypeToString(UnitType);
390 // TODO(sashab): Remove customCSSText() once CSSValueObject uses vtables pro perly. 536 // TODO(sashab): Remove customCSSText() once CSSValueObject uses vtables pro perly.
391 String customCSSText() const; 537 String customCSSText() const;
392 String cssText() const { return customCSSText(); } 538 String cssText() const { return customCSSText(); }
393 539
394 bool isQuirkValue() const { return m_rawValue->m_isQuirkValue; } 540 bool isQuirkValue() const
541 {
542 if (!isObject())
543 return false;
544 return m_rawValue.asPtr->m_isQuirkValue;
545 }
395 546
396 bool equals(const CSSPrimitiveValue) const; 547 bool equals(const CSSPrimitiveValue) const;
397 548
398 static UnitType canonicalUnitTypeForCategory(UnitCategory); 549 static UnitType canonicalUnitTypeForCategory(UnitCategory);
399 static double conversionToCanonicalUnitsScaleFactor(UnitType); 550 static double conversionToCanonicalUnitsScaleFactor(UnitType);
400 551
401 // Returns true and populates lengthUnitType, if unitType is a length unit. Otherwise, returns false. 552 // Returns true and populates lengthUnitType, if unitType is a length unit. Otherwise, returns false.
402 static bool unitTypeToLengthUnitType(UnitType, LengthUnitType&); 553 static bool unitTypeToLengthUnitType(UnitType, LengthUnitType&);
403 static UnitType lengthUnitTypeToUnitType(LengthUnitType); 554 static UnitType lengthUnitTypeToUnitType(LengthUnitType);
404 555
405 DEFINE_INLINE_TRACE() 556 DEFINE_INLINE_TRACE()
406 { 557 {
407 visitor->trace(m_rawValue); 558 visitor->trace(m_rawValue);
408 m_rawValue->traceAfterDispatch(visitor);
409 } 559 }
410 560
411 private: 561 private:
412 void ref() const 562 void ref() const
413 { 563 {
414 #if !ENABLE(OILPAN) 564 #if !ENABLE(OILPAN)
415 m_rawValue->ref(); 565 if (isObject())
566 m_rawValue.asPtr->ref();
416 #endif 567 #endif
417 } 568 }
418 569
419 void deref() const 570 void deref() const
420 { 571 {
421 #if !ENABLE(OILPAN) 572 #if !ENABLE(OILPAN)
422 m_rawValue->deref(); 573 if (isObject())
574 m_rawValue.asPtr->deref();
423 #endif 575 #endif
424 } 576 }
425 577
426 static void create(int); // compile-time guard 578 static void create(int); // compile-time guard
427 static void create(unsigned); // compile-time guard 579 static void create(unsigned); // compile-time guard
428 template<typename T> operator T*(); // compile-time guard 580 template<typename T> operator T*(); // compile-time guard
429 581
430 double computeLengthDouble(const CSSToLengthConversionData&); 582 double computeLengthDouble(const CSSToLengthConversionData&);
431 583
432 RawPtrWillBeMember<CSSLargePrimitiveValue> m_rawValue; 584 union CSSPrimitivePointerValue {
585 CSSTaggedPtrValue asTaggedPtr;
586 RawPtrWillBeMember<CSSLargePrimitiveValue> asPtr;
587
588 CSSPrimitivePointerValue(CSSLargePrimitiveValue* ptr) : asPtr(ptr) { }
589 CSSPrimitivePointerValue(CSSTaggedPtrValue taggedPtr) : asTaggedPtr(tagg edPtr) { }
590
591 DEFINE_INLINE_TRACE()
592 {
593 if (!(reinterpret_cast<uintptr_t>(asPtr.get()) & 1)) {
594 visitor->trace(asPtr);
595 asPtr->traceAfterDispatch(visitor);
596 }
597 }
598 } m_rawValue;
599 static_assert(sizeof(m_rawValue) == sizeof(void*), "The tagged pointer field in CSSPrimitiveValue must be the size of a pointer");
600
601 bool isObject() const
602 {
603 return m_rawValue.asTaggedPtr.flag == 0;
604 }
433 605
434 // Getters/setters for inner class. 606 // Getters/setters for inner class.
435 CSSPrimitiveValueData value() const { return m_rawValue->m_value; } 607 CSSPrimitiveValueData value() const
436 UnitType type() const { return static_cast<UnitType>(m_rawValue->m_primitive UnitType); } 608 {
437 bool hasCachedCSSText() const { return m_rawValue->m_hasCachedCSSText; } 609 if (isObject())
610 return m_rawValue.asPtr->m_value;
438 611
439 void setValue(CSSPrimitiveValueData value) { m_rawValue->m_value = value; } 612 CSSPrimitiveValueData result;
440 void setType(UnitType primitiveUnitType) { m_rawValue->m_primitiveUnitType = static_cast<unsigned>(primitiveUnitType); } 613 if (m_rawValue.asTaggedPtr.type == CSS_RGBCOLOR)
441 void setHasCachedCSSText(bool hasCachedCSSText) const { m_rawValue->m_hasCac hedCSSText = hasCachedCSSText; } 614 result.rgbcolor = m_rawValue.asTaggedPtr.getColorValue();
442 void setIsQuirkValue(bool isQuirkValue) { m_rawValue->m_isQuirkValue = isQui rkValue; } 615 else if (m_rawValue.asTaggedPtr.type == CSS_PROPERTY_ID)
616 result.propertyID = m_rawValue.asTaggedPtr.getPropertyIDValue();
617 else if (m_rawValue.asTaggedPtr.type == CSS_VALUE_ID)
618 result.valueID = m_rawValue.asTaggedPtr.getValueIDValue();
619 else
620 result.num = m_rawValue.asTaggedPtr.getValue();
621 return result;
622 }
623
624 UnitType type() const
625 {
626 if (isObject())
627 return static_cast<UnitType>(m_rawValue.asPtr->m_primitiveUnitType);
628 return static_cast<UnitType>(m_rawValue.asTaggedPtr.type);
629 }
443 }; 630 };
444 631
445 typedef CSSPrimitiveValue::CSSLengthArray CSSLengthArray; 632 typedef CSSPrimitiveValue::CSSLengthArray CSSLengthArray;
446 typedef CSSPrimitiveValue::CSSLengthTypeArray CSSLengthTypeArray; 633 typedef CSSPrimitiveValue::CSSLengthTypeArray CSSLengthTypeArray;
447 634
635 static_assert(sizeof(CSSPrimitiveValue) == sizeof(void*), "CSSPrimitiveValue mus t be the size of a pointer");
636
448 } // namespace blink 637 } // namespace blink
449 638
450 #endif // CSSPrimitiveValue_h 639 #endif // CSSPrimitiveValue_h
OLDNEW
« no previous file with comments | « Source/core/core.gypi ('k') | Source/core/css/CSSPrimitiveValue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698