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

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

Issue 1252683002: CSSValue Immediates: Change RefPtr<CSSValue> to store tagged pointers (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
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 | « no previous file | 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 13 matching lines...) Expand all
24 24
25 #include "core/CSSPropertyNames.h" 25 #include "core/CSSPropertyNames.h"
26 #include "core/CSSValueKeywords.h" 26 #include "core/CSSValueKeywords.h"
27 #include "core/CoreExport.h" 27 #include "core/CoreExport.h"
28 #include "core/css/CSSValue.h" 28 #include "core/css/CSSValue.h"
29 #include "platform/graphics/Color.h" 29 #include "platform/graphics/Color.h"
30 #include "wtf/BitVector.h" 30 #include "wtf/BitVector.h"
31 #include "wtf/Forward.h" 31 #include "wtf/Forward.h"
32 #include "wtf/MathExtras.h" 32 #include "wtf/MathExtras.h"
33 #include "wtf/PassRefPtr.h" 33 #include "wtf/PassRefPtr.h"
34 #include "wtf/RefCounted.h"
34 #include "wtf/text/StringHash.h" 35 #include "wtf/text/StringHash.h"
35 36
36 namespace blink { 37 namespace blink {
37 38
38 class CSSBasicShape; 39 class CSSBasicShape;
39 class CSSCalcValue; 40 class CSSCalcValue;
40 class CSSToLengthConversionData; 41 class CSSToLengthConversionData;
41 class Counter; 42 class Counter;
42 class Length; 43 class Length;
43 class LengthSize; 44 class LengthSize;
(...skipping 19 matching lines...) Expand all
63 if (proximityToNextInt <= 0.01 && value > 0) 64 if (proximityToNextInt <= 0.01 && value > 0)
64 return static_cast<float>(ceiledValue); 65 return static_cast<float>(ceiledValue);
65 if (proximityToNextInt >= 0.99 && value < 0) 66 if (proximityToNextInt >= 0.99 && value < 0)
66 return static_cast<float>(floor(value)); 67 return static_cast<float>(floor(value));
67 return static_cast<float>(value); 68 return static_cast<float>(value);
68 } 69 }
69 70
70 // CSSPrimitiveValues are immutable. This class has manual ref-counting 71 // CSSPrimitiveValues are immutable. This class has manual ref-counting
71 // of unioned types and does not have the code necessary 72 // of unioned types and does not have the code necessary
72 // to handle any kind of mutations. 73 // to handle any kind of mutations.
74 // In some cases, CSSPrimitiveValue is a tagged pointer. If isTaggedPtr() return s
75 // true, |this| is an invalid pointer and member variables should not be accesse d.
73 class CORE_EXPORT CSSPrimitiveValue : public CSSValue { 76 class CORE_EXPORT CSSPrimitiveValue : public CSSValue {
74 public: 77 public:
75 enum UnitType { 78 enum UnitType {
76 CSS_UNKNOWN = 0, 79 CSS_UNKNOWN,
77 CSS_NUMBER = 1, 80 CSS_NUMBER,
78 CSS_PERCENTAGE = 2, 81 CSS_PERCENTAGE,
79 CSS_EMS = 3, 82 CSS_EMS,
80 CSS_EXS = 4, 83 CSS_EXS,
81 CSS_PX = 5, 84 CSS_PX,
82 CSS_CM = 6, 85 CSS_CM,
83 CSS_MM = 7, 86 CSS_MM,
84 CSS_IN = 8, 87 CSS_IN,
85 CSS_PT = 9, 88 CSS_PT,
86 CSS_PC = 10, 89 CSS_PC,
87 CSS_DEG = 11, 90 CSS_DEG,
88 CSS_RAD = 12, 91 CSS_RAD,
89 CSS_GRAD = 13, 92 CSS_GRAD,
90 CSS_MS = 14, 93 CSS_MS,
91 CSS_S = 15, 94 CSS_S,
92 CSS_HZ = 16, 95 CSS_HZ,
93 CSS_KHZ = 17, 96 CSS_KHZ,
94 CSS_CUSTOM_IDENT = 19, 97 CSS_CUSTOM_IDENT,
95 CSS_URI = 20, 98 CSS_URI,
96 CSS_IDENT = 21, 99 CSS_IDENT,
97 CSS_ATTR = 22, 100 CSS_ATTR,
98 CSS_COUNTER = 23, 101 CSS_COUNTER,
99 CSS_RECT = 24, 102 CSS_RECT,
100 CSS_RGBCOLOR = 25, 103 CSS_RGBCOLOR,
101 CSS_VW = 26, 104 CSS_VW,
102 CSS_VH = 27, 105 CSS_VH,
103 CSS_VMIN = 28, 106 CSS_VMIN,
104 CSS_VMAX = 29, 107 CSS_VMAX,
105 CSS_DPPX = 30, 108 CSS_DPPX,
106 CSS_DPI = 31, 109 CSS_DPI,
107 CSS_DPCM = 32, 110 CSS_DPCM,
108 CSS_FR = 33, 111 CSS_FR,
109 CSS_INTEGER = 34, 112 CSS_INTEGER,
110 CSS_PAIR = 100, 113 CSS_PAIR,
111 CSS_TURN = 107, 114 CSS_TURN,
112 CSS_REMS = 108, 115 CSS_REMS,
113 CSS_CHS = 109, 116 CSS_CHS,
114 CSS_SHAPE = 111, 117 CSS_SHAPE,
115 CSS_QUAD = 112, 118 CSS_QUAD,
116 CSS_CALC = 113, 119 CSS_CALC,
117 CSS_CALC_PERCENTAGE_WITH_NUMBER = 114, 120 CSS_CALC_PERCENTAGE_WITH_NUMBER,
118 CSS_CALC_PERCENTAGE_WITH_LENGTH = 115, 121 CSS_CALC_PERCENTAGE_WITH_LENGTH,
119 CSS_STRING = 116, 122 CSS_STRING,
120 CSS_PROPERTY_ID = 117, 123 CSS_PROPERTY_ID,
121 CSS_VALUE_ID = 118, 124 CSS_VALUE_ID,
122 CSS_QEM = 119 125 CSS_QEM
123 }; 126 };
124 127
125 enum LengthUnitType { 128 enum LengthUnitType {
126 UnitTypePixels = 0, 129 UnitTypePixels = 0,
127 UnitTypePercentage, 130 UnitTypePercentage,
128 UnitTypeFontSize, 131 UnitTypeFontSize,
129 UnitTypeFontXSize, 132 UnitTypeFontXSize,
130 UnitTypeRootFontSize, 133 UnitTypeRootFontSize,
131 UnitTypeZeroCharacterWidth, 134 UnitTypeZeroCharacterWidth,
132 UnitTypeViewportWidth, 135 UnitTypeViewportWidth,
133 UnitTypeViewportHeight, 136 UnitTypeViewportHeight,
134 UnitTypeViewportMin, 137 UnitTypeViewportMin,
135 UnitTypeViewportMax, 138 UnitTypeViewportMax,
136 139
137 // This value must come after the last length unit type to enable iterat ion over the length unit types. 140 // This value must come after the last length unit type to enable iterat ion over the length unit types.
138 LengthUnitTypeCount, 141 LengthUnitTypeCount,
139 }; 142 };
140 143
144 union CSSPrimitiveValueData {
145 CSSPropertyID propertyID;
146 CSSValueID valueID;
147 double num;
148 StringImpl* string;
149 RGBA32 rgbcolor;
150 // FIXME: oilpan: Should be members, but no support for members in union s. Just trace the raw ptr for now.
151 CSSBasicShape* shape;
152 CSSCalcValue* calc;
153 Counter* counter;
154 Pair* pair;
155 Rect* rect;
156 Quad* quad;
157 };
158
141 typedef Vector<double, CSSPrimitiveValue::LengthUnitTypeCount> CSSLengthArra y; 159 typedef Vector<double, CSSPrimitiveValue::LengthUnitTypeCount> CSSLengthArra y;
142 typedef BitVector CSSLengthTypeArray; 160 typedef BitVector CSSLengthTypeArray;
143 161
144 void accumulateLengthArray(CSSLengthArray&, double multiplier = 1) const; 162 void accumulateLengthArray(CSSLengthArray&, double multiplier = 1) const;
145 void accumulateLengthArray(CSSLengthArray&, CSSLengthTypeArray&, double mult iplier = 1) const; 163 void accumulateLengthArray(CSSLengthArray&, CSSLengthTypeArray&, double mult iplier = 1) const;
146 164
147 enum UnitCategory { 165 enum UnitCategory {
148 UNumber, 166 UNumber,
149 UPercent, 167 UPercent,
150 ULength, 168 ULength,
151 UAngle, 169 UAngle,
152 UTime, 170 UTime,
153 UFrequency, 171 UFrequency,
154 UResolution, 172 UResolution,
155 UOther 173 UOther
156 }; 174 };
157 static UnitCategory unitCategory(UnitType); 175 static UnitCategory unitCategory(UnitType);
158 static float clampToCSSLengthRange(double); 176 static float clampToCSSLengthRange(double);
159 177
160 static void initUnitTable(); 178 static void initUnitTable();
161 179
162 static UnitType fromName(const String& unit); 180 static UnitType fromName(const String& unit);
163 181
164 bool isAngle() const 182 bool isAngle() const
165 { 183 {
166 return m_primitiveUnitType == CSS_DEG 184 return type() == CSS_DEG
167 || m_primitiveUnitType == CSS_RAD 185 || type() == CSS_RAD
168 || m_primitiveUnitType == CSS_GRAD 186 || type() == CSS_GRAD
169 || m_primitiveUnitType == CSS_TURN; 187 || type() == CSS_TURN;
170 } 188 }
171 bool isAttr() const { return m_primitiveUnitType == CSS_ATTR; } 189 bool isAttr() const { return type() == CSS_ATTR; }
172 bool isCounter() const { return m_primitiveUnitType == CSS_COUNTER; } 190 bool isCounter() const { return type() == CSS_COUNTER; }
173 bool isCustomIdent() const { return m_primitiveUnitType == CSS_CUSTOM_IDENT; } 191 bool isCustomIdent() const { return type() == CSS_CUSTOM_IDENT; }
174 bool isFontRelativeLength() const 192 bool isFontRelativeLength() const
175 { 193 {
176 return m_primitiveUnitType == CSS_EMS 194 return type() == CSS_EMS
177 || m_primitiveUnitType == CSS_EXS 195 || type() == CSS_EXS
178 || m_primitiveUnitType == CSS_REMS 196 || type() == CSS_REMS
179 || m_primitiveUnitType == CSS_CHS; 197 || type() == CSS_CHS;
180 } 198 }
181 bool isViewportPercentageLength() const { return isViewportPercentageLength( static_cast<UnitType>(m_primitiveUnitType)); } 199 bool isViewportPercentageLength() const { return isViewportPercentageLength( type()); }
182 static bool isViewportPercentageLength(UnitType type) { return type >= CSS_V W && type <= CSS_VMAX; } 200 static bool isViewportPercentageLength(UnitType type) { return type >= CSS_V W && type <= CSS_VMAX; }
183 static bool isLength(UnitType type) 201 static bool isLength(UnitType type)
184 { 202 {
185 return (type >= CSS_EMS && type <= CSS_PC) || type == CSS_REMS || type = = CSS_CHS || isViewportPercentageLength(type); 203 return (type >= CSS_EMS && type <= CSS_PC) || type == CSS_REMS || type = = CSS_CHS || isViewportPercentageLength(type);
186 } 204 }
187 bool isLength() const { return isLength(primitiveType()); } 205 bool isLength() const { return isLength(primitiveType()); }
188 bool isNumber() const { return primitiveType() == CSS_NUMBER || primitiveTyp e() == CSS_INTEGER; } 206 bool isNumber() const { return primitiveType() == CSS_NUMBER || primitiveTyp e() == CSS_INTEGER; }
189 bool isPercentage() const { return primitiveType() == CSS_PERCENTAGE; } 207 bool isPercentage() const { return primitiveType() == CSS_PERCENTAGE; }
190 bool isPx() const { return primitiveType() == CSS_PX; } 208 bool isPx() const { return primitiveType() == CSS_PX; }
191 bool isRect() const { return m_primitiveUnitType == CSS_RECT; } 209 bool isRect() const { return type() == CSS_RECT; }
192 bool isRGBColor() const { return m_primitiveUnitType == CSS_RGBCOLOR; } 210 bool isRGBColor() const { return type() == CSS_RGBCOLOR; }
193 bool isShape() const { return m_primitiveUnitType == CSS_SHAPE; } 211 bool isShape() const { return type() == CSS_SHAPE; }
194 bool isString() const { return m_primitiveUnitType == CSS_STRING; } 212 bool isString() const { return type() == CSS_STRING; }
195 bool isTime() const { return m_primitiveUnitType == CSS_S || m_primitiveUnit Type == CSS_MS; } 213 bool isTime() const { return type() == CSS_S || type() == CSS_MS; }
196 bool isURI() const { return m_primitiveUnitType == CSS_URI; } 214 bool isURI() const { return type() == CSS_URI; }
197 bool isCalculated() const { return m_primitiveUnitType == CSS_CALC; } 215 bool isCalculated() const { return type() == CSS_CALC; }
198 bool isCalculatedPercentageWithNumber() const { return primitiveType() == CS S_CALC_PERCENTAGE_WITH_NUMBER; } 216 bool isCalculatedPercentageWithNumber() const { return primitiveType() == CS S_CALC_PERCENTAGE_WITH_NUMBER; }
199 bool isCalculatedPercentageWithLength() const { return primitiveType() == CS S_CALC_PERCENTAGE_WITH_LENGTH; } 217 bool isCalculatedPercentageWithLength() const { return primitiveType() == CS S_CALC_PERCENTAGE_WITH_LENGTH; }
200 static bool isDotsPerInch(UnitType type) { return type == CSS_DPI; } 218 static bool isDotsPerInch(UnitType type) { return type == CSS_DPI; }
201 static bool isDotsPerPixel(UnitType type) { return type == CSS_DPPX; } 219 static bool isDotsPerPixel(UnitType type) { return type == CSS_DPPX; }
202 static bool isDotsPerCentimeter(UnitType type) { return type == CSS_DPCM; } 220 static bool isDotsPerCentimeter(UnitType type) { return type == CSS_DPCM; }
203 static bool isResolution(UnitType type) { return type >= CSS_DPPX && type <= CSS_DPCM; } 221 static bool isResolution(UnitType type) { return type >= CSS_DPPX && type <= CSS_DPCM; }
204 bool isFlex() const { return primitiveType() == CSS_FR; } 222 bool isFlex() const { return primitiveType() == CSS_FR; }
205 bool isValueID() const { return m_primitiveUnitType == CSS_VALUE_ID; } 223 bool isValueID() const { return type() == CSS_VALUE_ID; }
206 bool colorIsDerivedFromElement() const; 224 bool colorIsDerivedFromElement() const;
207 225
208 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createIdentifier(CSSValueID valueID) 226 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createIdentifier(CSSValueID valueID)
209 { 227 {
210 return adoptRefWillBeNoop(new CSSPrimitiveValue(valueID)); 228 CSSTaggedPtrValue taggedPtr;
229 taggedPtr.flag = 1;
230 taggedPtr.type = static_cast<uintptr_t>(CSSPrimitiveValue::CSS_VALUE_ID) ;
231 taggedPtr.value = static_cast<uintptr_t>(valueID);
232 return adoptRefWillBeNoop(toPtr(taggedPtr));
211 } 233 }
212 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createIdentifier(CSSPropert yID propertyID) 234 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createIdentifier(CSSPropert yID propertyID)
213 { 235 {
214 return adoptRefWillBeNoop(new CSSPrimitiveValue(propertyID)); 236 CSSTaggedPtrValue taggedPtr;
237 taggedPtr.flag = 1;
238 taggedPtr.type = static_cast<uintptr_t>(CSSPrimitiveValue::CSS_PROPERTY_ ID);
239 taggedPtr.value = static_cast<uintptr_t>(propertyID);
240 return adoptRefWillBeNoop(toPtr(taggedPtr));
215 } 241 }
216 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createColor(RGBA32 rgbValue ) 242 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createColor(RGBA32 rgbValue )
217 { 243 {
218 return adoptRefWillBeNoop(new CSSPrimitiveValue(rgbValue)); 244 bool canFitColor;
245 #if CPU(32BIT)
246 canFitColor = alphaChannel(rgbValue) == 0 || alphaChannel(rgbValue) == 2 55;
247 #elif CPU(64BIT)
248 canFitColor = true;
249 #endif
250 if (!canFitColor)
251 return adoptRefWillBeNoop(new CSSPrimitiveValue(rgbValue));
252
253 CSSTaggedPtrValue taggedPtr;
254 taggedPtr.flag = 1;
255 taggedPtr.type = static_cast<uintptr_t>(CSSPrimitiveValue::CSS_RGBCOLOR) ;
256
257 packedColor colorToStore;
258 colorToStore.red = static_cast<uintptr_t>(redChannel(rgbValue));
259 colorToStore.green = static_cast<uintptr_t>(greenChannel(rgbValue));
260 colorToStore.blue = static_cast<uintptr_t>(blueChannel(rgbValue));
261 #if CPU(32BIT)
262 colorToStore.alpha = static_cast<uintptr_t>(alphaChannel(rgbValue) == 25 5 ? 1 : 0);
263 #elif CPU(64BIT)
264 colorToStore.alpha = static_cast<uintptr_t>(alphaChannel(rgbValue));
265 #endif
266 taggedPtr.value = *reinterpret_cast<uintptr_t*>(&colorToStore);
267 return adoptRefWillBeNoop(toPtr(taggedPtr));
219 } 268 }
220 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(double value, UnitTy pe type) 269 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(double value, UnitTy pe type)
221 { 270 {
222 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, type)); 271 uint64_t& doubleAsBits = reinterpret_cast<uint64_t&>(value);
272 if ((doubleAsBits & mantissaTruncationMask) != 0)
273 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, type));
274
275 CSSTaggedPtrValue taggedPtr;
276 taggedPtr.flag = 1;
277 taggedPtr.type = static_cast<uintptr_t>(type);
278 taggedPtr.value = doubleAsBits >> doubleShiftAmount;
279 return adoptRefWillBeNoop(toPtr(taggedPtr));
223 } 280 }
224 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const String& value, UnitType type) 281 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const String& value, UnitType type)
225 { 282 {
226 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, type)); 283 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, type));
227 } 284 }
228 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const Length& value, float zoom) 285 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const Length& value, float zoom)
229 { 286 {
230 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, zoom)); 287 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, zoom));
231 } 288 }
232 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const LengthSize& va lue, const ComputedStyle& style) 289 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const LengthSize& va lue, const ComputedStyle& style)
(...skipping 24 matching lines...) Expand all
257 314
258 double computeDegrees() const; 315 double computeDegrees() const;
259 double computeSeconds(); 316 double computeSeconds();
260 317
261 // Computes a length in pixels, resolving relative lengths 318 // Computes a length in pixels, resolving relative lengths
262 template<typename T> T computeLength(const CSSToLengthConversionData&); 319 template<typename T> T computeLength(const CSSToLengthConversionData&);
263 320
264 // Converts to a Length (Fixed, Percent or Calculated) 321 // Converts to a Length (Fixed, Percent or Calculated)
265 Length convertToLength(const CSSToLengthConversionData&); 322 Length convertToLength(const CSSToLengthConversionData&);
266 323
267 double getDoubleValue() const; 324 double getDoubleValue() const
325 {
326 if (type() == CSS_CALC)
327 return getCalcDoubleValue();
328 return value().num;
329 }
330
331 double getCalcDoubleValue() const;
332
268 float getFloatValue() const { return getValue<float>(); } 333 float getFloatValue() const { return getValue<float>(); }
269 int getIntValue() const { return getValue<int>(); } 334 int getIntValue() const { return getValue<int>(); }
270 template<typename T> inline T getValue() const { return clampTo<T>(getDouble Value()); } 335 template<typename T> inline T getValue() const { return clampTo<T>(getDouble Value()); }
271 336
272 String getStringValue() const; 337 String getStringValue() const;
273 338
274 Counter* getCounterValue() const { return m_primitiveUnitType != CSS_COUNTER ? 0 : m_value.counter; } 339 Counter* getCounterValue() const { return type() != CSS_COUNTER ? 0 : value( ).counter; }
275 340
276 Rect* getRectValue() const { return m_primitiveUnitType != CSS_RECT ? 0 : m_ value.rect; } 341 Rect* getRectValue() const { return type() != CSS_RECT ? 0 : value().rect; }
277 342
278 Quad* getQuadValue() const { return m_primitiveUnitType != CSS_QUAD ? 0 : m_ value.quad; } 343 Quad* getQuadValue() const { return type() != CSS_QUAD ? 0 : value().quad; }
279 344
280 RGBA32 getRGBA32Value() const { return m_primitiveUnitType != CSS_RGBCOLOR ? 0 : m_value.rgbcolor; } 345 RGBA32 getRGBA32Value() const { return type() != CSS_RGBCOLOR ? 0 : value(). rgbcolor; }
281 346
282 Pair* getPairValue() const { return m_primitiveUnitType != CSS_PAIR ? 0 : m_ value.pair; } 347 Pair* getPairValue() const { return type() != CSS_PAIR ? 0 : value().pair; }
283 348
284 CSSBasicShape* getShapeValue() const { return m_primitiveUnitType != CSS_SHA PE ? 0 : m_value.shape; } 349 CSSBasicShape* getShapeValue() const { return type() != CSS_SHAPE ? 0 : valu e().shape; }
285 350
286 CSSCalcValue* cssCalcValue() const { return m_primitiveUnitType != CSS_CALC ? 0 : m_value.calc; } 351 CSSCalcValue* cssCalcValue() const { return type() != CSS_CALC ? 0 : value() .calc; }
287 352
288 CSSPropertyID getPropertyID() const { return m_primitiveUnitType == CSS_PROP ERTY_ID ? m_value.propertyID : CSSPropertyInvalid; } 353 CSSPropertyID getPropertyID() const { return type() == CSS_PROPERTY_ID ? val ue().propertyID : CSSPropertyInvalid; }
289 CSSValueID getValueID() const { return m_primitiveUnitType == CSS_VALUE_ID ? m_value.valueID : CSSValueInvalid; } 354 CSSValueID getValueID() const { return type() == CSS_VALUE_ID ? value().valu eID : CSSValueInvalid; }
290 355
291 template<typename T> inline operator T() const; // Defined in CSSPrimitiveVa lueMappings.h 356 template<typename T> inline operator T() const; // Defined in CSSPrimitiveVa lueMappings.h
292 357
293 static const char* unitTypeToString(UnitType); 358 static const char* unitTypeToString(UnitType);
294 String customCSSText() const; 359 String customCSSText() const;
295 360
296 bool isQuirkValue() { return m_isQuirkValue; } 361 inline bool isQuirkValue() const
362 {
363 if (isTaggedPtr())
364 return false;
365 return m_isQuirkValue;
366 }
297 367
298 bool equals(const CSSPrimitiveValue&) const; 368 bool equals(const CSSPrimitiveValue&) const;
299 369
300 DECLARE_TRACE_AFTER_DISPATCH(); 370 DECLARE_TRACE_AFTER_DISPATCH();
301 371
302 static UnitType canonicalUnitTypeForCategory(UnitCategory); 372 static UnitType canonicalUnitTypeForCategory(UnitCategory);
303 static double conversionToCanonicalUnitsScaleFactor(UnitType); 373 static double conversionToCanonicalUnitsScaleFactor(UnitType);
304 374
305 // Returns true and populates lengthUnitType, if unitType is a length unit. Otherwise, returns false. 375 // Returns true and populates lengthUnitType, if unitType is a length unit. Otherwise, returns false.
306 static bool unitTypeToLengthUnitType(UnitType, LengthUnitType&); 376 static bool unitTypeToLengthUnitType(UnitType, LengthUnitType&);
(...skipping 29 matching lines...) Expand all
336 void init(const LengthSize&, const ComputedStyle&); 406 void init(const LengthSize&, const ComputedStyle&);
337 void init(PassRefPtrWillBeRawPtr<Counter>); 407 void init(PassRefPtrWillBeRawPtr<Counter>);
338 void init(PassRefPtrWillBeRawPtr<Rect>); 408 void init(PassRefPtrWillBeRawPtr<Rect>);
339 void init(PassRefPtrWillBeRawPtr<Pair>); 409 void init(PassRefPtrWillBeRawPtr<Pair>);
340 void init(PassRefPtrWillBeRawPtr<Quad>); 410 void init(PassRefPtrWillBeRawPtr<Quad>);
341 void init(PassRefPtrWillBeRawPtr<CSSBasicShape>); 411 void init(PassRefPtrWillBeRawPtr<CSSBasicShape>);
342 void init(PassRefPtrWillBeRawPtr<CSSCalcValue>); 412 void init(PassRefPtrWillBeRawPtr<CSSCalcValue>);
343 413
344 double computeLengthDouble(const CSSToLengthConversionData&); 414 double computeLengthDouble(const CSSToLengthConversionData&);
345 415
346 union { 416 // Useful bit masks for dealing with tagged pointer doubles.
347 CSSPropertyID propertyID; 417 #if CPU(32BIT)
348 CSSValueID valueID; 418 static const unsigned doubleShiftAmount = 32 + 7;
349 double num; 419 static const uint64_t mantissaTruncationMask = 0x7fffffffff;
350 StringImpl* string; 420 #elif CPU(64BIT)
351 RGBA32 rgbcolor; 421 static const unsigned doubleShiftAmount = 7;
352 // FIXME: oilpan: Should be members, but no support for members in union s. Just trace the raw ptr for now. 422 static const uint64_t mantissaTruncationMask = 0x7f;
353 CSSBasicShape* shape; 423 #endif
354 CSSCalcValue* calc; 424
355 Counter* counter; 425 // Struct for storing RGB values.
356 Pair* pair; 426 typedef struct {
357 Rect* rect; 427 unsigned red : 8;
358 Quad* quad; 428 unsigned green : 8;
359 } m_value; 429 unsigned blue : 8;
430 #if CPU(32BIT)
431 unsigned alpha : 1;
432 #elif CPU(64BIT)
433 unsigned alpha : 8;
434 #endif
435 } packedColor;
436
437 // Getter/setter functions that account for tagged pointer optimization.
438 inline bool isTaggedPtr() const
439 {
440 return reinterpret_cast<uintptr_t>(this) & 1;
441 }
442
443 static inline CSSPrimitiveValue* toPtr(CSSTaggedPtrValue taggedPtr)
444 {
445 return reinterpret_cast<CSSPrimitiveValue*&>(taggedPtr);
446 }
447
448 inline CSSTaggedPtrValue toTaggedPtr() const
449 {
450 CSSPrimitiveValue* nonConstThis = const_cast<CSSPrimitiveValue*>(this);
451 return reinterpret_cast<CSSTaggedPtrValue&&>(nonConstThis);
452 }
453
454 inline UnitType type() const
455 {
456 if (!isTaggedPtr())
457 return static_cast<UnitType>(m_primitiveUnitType);
458 return static_cast<UnitType>(toTaggedPtr().type);
459 }
460
461 inline CSSPrimitiveValueData value() const
462 {
463 if (!isTaggedPtr())
464 return m_value;
465
466 CSSPrimitiveValueData data;
467 switch (type()) {
468 case CSSPrimitiveValue::CSS_PROPERTY_ID:
469 data.propertyID = static_cast<CSSPropertyID>(toTaggedPtr().value);
470 break;
471 case CSSPrimitiveValue::CSS_VALUE_ID:
472 data.valueID = static_cast<CSSValueID>(toTaggedPtr().value);
473 break;
474 case CSSPrimitiveValue::CSS_RGBCOLOR: {
475 uintptr_t valueRawVar = toTaggedPtr().value;
476 packedColor color = *reinterpret_cast<packedColor*>(&valueRawVar);
477 unsigned alpha;
478 #if CPU(32BIT)
479 alpha = color.alpha == 1 ? 255 : 0;
480 #elif CPU(64BIT)
481 alpha = color.alpha;
482 #endif
483 data.rgbcolor = makeRGBA(color.red, color.green, color.blue, alpha);
484 break;
485 }
486 default:
487 uint64_t shiftedValue = toTaggedPtr().value;
488 shiftedValue = shiftedValue << doubleShiftAmount;
489 data.num = *reinterpret_cast<double*>(&shiftedValue);
490 break;
491 }
492 return data;
493 }
494
495 CSSPrimitiveValueData m_value;
360 }; 496 };
361 497
362 typedef CSSPrimitiveValue::CSSLengthArray CSSLengthArray; 498 typedef CSSPrimitiveValue::CSSLengthArray CSSLengthArray;
363 typedef CSSPrimitiveValue::CSSLengthTypeArray CSSLengthTypeArray; 499 typedef CSSPrimitiveValue::CSSLengthTypeArray CSSLengthTypeArray;
364 500
365 DEFINE_CSS_VALUE_TYPE_CASTS(CSSPrimitiveValue, isPrimitiveValue()); 501 DEFINE_CSS_VALUE_TYPE_CASTS(CSSPrimitiveValue, isPrimitiveValue());
366 502
367 } // namespace blink 503 } // namespace blink
368 504
505 namespace WTF {
506
507 #if !ENABLE(OILPAN)
508 // Must be defined *after* CSSPrimitiveValue to compile with the correct adopted () method.
509 template<> inline PassRefPtr<blink::CSSPrimitiveValue> adoptRef<blink::CSSPrimit iveValue>(blink::CSSPrimitiveValue* p)
510 {
511 // Immediates (non-pointers) end in a 1.
512 if (!(reinterpret_cast<uintptr_t>(p) & 1))
513 adopted(p);
514 return PassRefPtr<blink::CSSPrimitiveValue>(p, PassRefPtr<blink::CSSPrimitiv eValue>::AdoptRef);
515 }
516 #endif
517
518 } // namespace WTF
519
369 #endif // CSSPrimitiveValue_h 520 #endif // CSSPrimitiveValue_h
OLDNEW
« no previous file with comments | « no previous file | Source/core/css/CSSPrimitiveValue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698