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, 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 * |
11 * This library is distributed in the hope that it will be useful, | 11 * This library is distributed in the hope that it will be useful, |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 * Library General Public License for more details. | 14 * Library General Public License for more details. |
15 * | 15 * |
16 * You should have received a copy of the GNU Library General Public License | 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 | 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, | 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 * Boston, MA 02110-1301, USA. | 19 * Boston, MA 02110-1301, USA. |
20 */ | 20 */ |
21 | 21 |
22 #ifndef CSSPrimitiveValue_h | 22 #ifndef CSSPrimitiveValue_h |
23 #define CSSPrimitiveValue_h | 23 #define CSSPrimitiveValue_h |
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/CSSValueObject.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/text/StringHash.h" | 34 #include "wtf/text/StringHash.h" |
35 | 35 |
36 namespace blink { | 36 namespace blink { |
37 | 37 |
38 class CSSBasicShape; | 38 class CSSBasicShape; |
(...skipping 21 matching lines...) Expand all Loading... |
60 { | 60 { |
61 double ceiledValue = ceil(value); | 61 double ceiledValue = ceil(value); |
62 double proximityToNextInt = ceiledValue - value; | 62 double proximityToNextInt = ceiledValue - value; |
63 if (proximityToNextInt <= 0.01 && value > 0) | 63 if (proximityToNextInt <= 0.01 && value > 0) |
64 return static_cast<float>(ceiledValue); | 64 return static_cast<float>(ceiledValue); |
65 if (proximityToNextInt >= 0.99 && value < 0) | 65 if (proximityToNextInt >= 0.99 && value < 0) |
66 return static_cast<float>(floor(value)); | 66 return static_cast<float>(floor(value)); |
67 return static_cast<float>(value); | 67 return static_cast<float>(value); |
68 } | 68 } |
69 | 69 |
70 // CSSPrimitiveValues are immutable. This class has manual ref-counting | 70 // A type of unpacked CSSValue for CSSPrimitiveValue objects. Can only be stack-
allocated; |
71 // of unioned types and does not have the code necessary | 71 // pass these around by value. |
72 // to handle any kind of mutations. | 72 // Currently only supports CSSLargePrimitiveValues, but will later support tagge
d pointers |
73 class CORE_EXPORT CSSPrimitiveValue : public CSSValueObject { | 73 // stored as immediates in CSSValues. |
| 74 // TODO(sashab): Add tagged pointer support. |
| 75 class CORE_EXPORT CSSPrimitiveValue { |
| 76 STACK_ALLOCATED(); |
74 public: | 77 public: |
| 78 typedef union { |
| 79 CSSPropertyID propertyID; |
| 80 CSSValueID valueID; |
| 81 double num; |
| 82 StringImpl* string; |
| 83 RGBA32 rgbcolor; |
| 84 // FIXME: oilpan: Should be members, but no support for members in union
s. Just trace the raw ptr for now. |
| 85 CSSBasicShape* shape; |
| 86 CSSCalcValue* calc; |
| 87 Counter* counter; |
| 88 Pair* pair; |
| 89 Rect* rect; |
| 90 Quad* quad; |
| 91 } CSSPrimitiveValueData; |
| 92 |
75 enum UnitType { | 93 enum UnitType { |
76 CSS_UNKNOWN = 0, | 94 CSS_UNKNOWN = 0, |
77 CSS_NUMBER = 1, | 95 CSS_NUMBER = 1, |
78 CSS_PERCENTAGE = 2, | 96 CSS_PERCENTAGE = 2, |
79 CSS_EMS = 3, | 97 CSS_EMS = 3, |
80 CSS_EXS = 4, | 98 CSS_EXS = 4, |
81 CSS_PX = 5, | 99 CSS_PX = 5, |
82 CSS_CM = 6, | 100 CSS_CM = 6, |
83 CSS_MM = 7, | 101 CSS_MM = 7, |
84 CSS_IN = 8, | 102 CSS_IN = 8, |
85 CSS_PT = 9, | 103 CSS_PT = 9, |
86 CSS_PC = 10, | 104 CSS_PC = 10, |
87 CSS_DEG = 11, | 105 CSS_DEG = 11, |
88 CSS_RAD = 12, | 106 CSS_RAD = 12, |
89 CSS_GRAD = 13, | 107 CSS_GRAD = 13, |
90 CSS_MS = 14, | 108 CSS_MS = 14, |
91 CSS_S = 15, | 109 CSS_S = 15, |
92 CSS_HZ = 16, | 110 CSS_HZ = 16, |
93 CSS_KHZ = 17, | 111 CSS_KHZ = 17, |
94 CSS_CUSTOM_IDENT = 19, | 112 CSS_CUSTOM_IDENT = 18, |
95 CSS_URI = 20, | 113 CSS_URI = 19, |
96 CSS_IDENT = 21, | 114 CSS_IDENT = 20, |
97 CSS_ATTR = 22, | 115 CSS_ATTR = 21, |
98 CSS_COUNTER = 23, | 116 CSS_COUNTER = 22, |
99 CSS_RECT = 24, | 117 CSS_RECT = 23, |
100 CSS_RGBCOLOR = 25, | 118 CSS_RGBCOLOR = 24, |
101 CSS_VW = 26, | 119 CSS_VW = 25, |
102 CSS_VH = 27, | 120 CSS_VH = 26, |
103 CSS_VMIN = 28, | 121 CSS_VMIN = 27, |
104 CSS_VMAX = 29, | 122 CSS_VMAX = 28, |
105 CSS_DPPX = 30, | 123 CSS_DPPX = 29, |
106 CSS_DPI = 31, | 124 CSS_DPI = 30, |
107 CSS_DPCM = 32, | 125 CSS_DPCM = 31, |
108 CSS_FR = 33, | 126 CSS_FR = 32, |
109 CSS_INTEGER = 34, | 127 CSS_INTEGER = 33, |
110 CSS_PAIR = 100, | 128 CSS_PAIR = 34, |
111 CSS_TURN = 107, | 129 CSS_TURN = 35, |
112 CSS_REMS = 108, | 130 CSS_REMS = 36, |
113 CSS_CHS = 109, | 131 CSS_CHS = 37, |
114 CSS_SHAPE = 111, | 132 CSS_SHAPE = 38, |
115 CSS_QUAD = 112, | 133 CSS_QUAD = 39, |
116 CSS_CALC = 113, | 134 CSS_CALC = 40, |
117 CSS_CALC_PERCENTAGE_WITH_NUMBER = 114, | 135 CSS_CALC_PERCENTAGE_WITH_NUMBER = 41, |
118 CSS_CALC_PERCENTAGE_WITH_LENGTH = 115, | 136 CSS_CALC_PERCENTAGE_WITH_LENGTH = 42, |
119 CSS_STRING = 116, | 137 CSS_STRING = 43, |
120 CSS_PROPERTY_ID = 117, | 138 CSS_PROPERTY_ID = 44, |
121 CSS_VALUE_ID = 118, | 139 CSS_VALUE_ID = 45, |
122 CSS_QEM = 119 | 140 CSS_QEM = 46 |
123 }; | 141 }; |
124 | 142 |
125 enum LengthUnitType { | 143 enum LengthUnitType { |
126 UnitTypePixels = 0, | 144 UnitTypePixels = 0, |
127 UnitTypePercentage, | 145 UnitTypePercentage, |
128 UnitTypeFontSize, | 146 UnitTypeFontSize, |
129 UnitTypeFontXSize, | 147 UnitTypeFontXSize, |
130 UnitTypeRootFontSize, | 148 UnitTypeRootFontSize, |
131 UnitTypeZeroCharacterWidth, | 149 UnitTypeZeroCharacterWidth, |
132 UnitTypeViewportWidth, | 150 UnitTypeViewportWidth, |
133 UnitTypeViewportHeight, | 151 UnitTypeViewportHeight, |
134 UnitTypeViewportMin, | 152 UnitTypeViewportMin, |
135 UnitTypeViewportMax, | 153 UnitTypeViewportMax, |
136 | 154 |
137 // 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. |
138 LengthUnitTypeCount, | 156 LengthUnitTypeCount, |
139 }; | 157 }; |
140 | 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 |
| 162 // 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
. |
| 164 class CSSLargePrimitiveValue final : public CSSValueObject { |
| 165 friend class CSSPrimitiveValue; |
| 166 public: |
| 167 CSSLargePrimitiveValue(CSSValueID); |
| 168 CSSLargePrimitiveValue(CSSPropertyID); |
| 169 CSSLargePrimitiveValue(RGBA32 color); |
| 170 CSSLargePrimitiveValue(const Length&, float zoom); |
| 171 CSSLargePrimitiveValue(const LengthSize&, const ComputedStyle&); |
| 172 CSSLargePrimitiveValue(const String&, UnitType); |
| 173 CSSLargePrimitiveValue(double, UnitType); |
| 174 CSSLargePrimitiveValue(double, UnitType, bool isQuirkValue); |
| 175 |
| 176 template<typename T> CSSLargePrimitiveValue(T); // Defined in CSSPrimiti
veValueMappings.h |
| 177 template<typename T> CSSLargePrimitiveValue(T* val) |
| 178 : CSSValueObject(PrimitiveClass) |
| 179 { |
| 180 init(PassRefPtrWillBeRawPtr<T>(val)); |
| 181 } |
| 182 |
| 183 template<typename T> CSSLargePrimitiveValue(PassRefPtrWillBeRawPtr<T> va
l) |
| 184 : CSSValueObject(PrimitiveClass) |
| 185 { |
| 186 init(val); |
| 187 } |
| 188 |
| 189 |
| 190 ~CSSLargePrimitiveValue(); |
| 191 |
| 192 void cleanup(); |
| 193 |
| 194 DECLARE_TRACE_AFTER_DISPATCH(); |
| 195 |
| 196 private: |
| 197 void init(const Length&); |
| 198 void init(const LengthSize&, const ComputedStyle&); |
| 199 void init(PassRefPtrWillBeRawPtr<Counter>); |
| 200 void init(PassRefPtrWillBeRawPtr<Rect>); |
| 201 void init(PassRefPtrWillBeRawPtr<Pair>); |
| 202 void init(PassRefPtrWillBeRawPtr<Quad>); |
| 203 void init(PassRefPtrWillBeRawPtr<CSSBasicShape>); |
| 204 void init(PassRefPtrWillBeRawPtr<CSSCalcValue>); |
| 205 |
| 206 CSSPrimitiveValueData m_value; |
| 207 }; |
| 208 |
| 209 explicit CSSPrimitiveValue(const CSSLargePrimitiveValue* object) |
| 210 : m_rawValue(const_cast<CSSLargePrimitiveValue*>(object)) |
| 211 { |
| 212 ref(); |
| 213 } |
| 214 |
| 215 CSSPrimitiveValue(PassRefPtrWillBeRawPtr<CSSLargePrimitiveValue> cssValue) |
| 216 : m_rawValue(cssValue.leakRef()) |
| 217 { |
| 218 } |
| 219 |
| 220 |
| 221 CSSPrimitiveValue(const CSSPrimitiveValue& other) |
| 222 : m_rawValue(other.m_rawValue) |
| 223 { |
| 224 ref(); |
| 225 } |
| 226 |
| 227 CSSPrimitiveValue& operator=(const CSSPrimitiveValue& rhs) |
| 228 { |
| 229 rhs.ref(); |
| 230 deref(); |
| 231 m_rawValue = rhs.m_rawValue; |
| 232 return *this; |
| 233 } |
| 234 |
| 235 CSSPrimitiveValue& operator=(CSSPrimitiveValue&& rhs) |
| 236 { |
| 237 m_rawValue = rhs.m_rawValue; |
| 238 rhs.m_rawValue.clear(); |
| 239 return *this; |
| 240 } |
| 241 |
| 242 CSSPrimitiveValue(CSSPrimitiveValue&& rhs) |
| 243 : m_rawValue(rhs.m_rawValue) |
| 244 { |
| 245 rhs.m_rawValue.clear(); |
| 246 } |
| 247 |
| 248 ~CSSPrimitiveValue() |
| 249 { |
| 250 deref(); |
| 251 } |
| 252 |
| 253 |
| 254 CSSLargePrimitiveValue* get() const |
| 255 { |
| 256 return m_rawValue.get(); |
| 257 } |
| 258 |
144 void accumulateLengthArray(CSSLengthArray&, double multiplier = 1) const; | 259 void accumulateLengthArray(CSSLengthArray&, double multiplier = 1) const; |
145 void accumulateLengthArray(CSSLengthArray&, CSSLengthTypeArray&, double mult
iplier = 1) const; | 260 void accumulateLengthArray(CSSLengthArray&, CSSLengthTypeArray&, double mult
iplier = 1) const; |
146 | 261 |
147 enum UnitCategory { | 262 enum UnitCategory { |
148 UNumber, | 263 UNumber, |
149 UPercent, | 264 UPercent, |
150 ULength, | 265 ULength, |
151 UAngle, | 266 UAngle, |
152 UTime, | 267 UTime, |
153 UFrequency, | 268 UFrequency, |
154 UResolution, | 269 UResolution, |
155 UOther | 270 UOther |
156 }; | 271 }; |
157 static UnitCategory unitCategory(UnitType); | 272 static UnitCategory unitCategory(UnitType); |
158 static float clampToCSSLengthRange(double); | 273 static float clampToCSSLengthRange(double); |
159 | 274 |
160 static void initUnitTable(); | 275 static void initUnitTable(); |
161 | 276 |
162 static UnitType fromName(const String& unit); | 277 static UnitType fromName(const String& unit); |
163 | 278 |
164 bool isAngle() const | 279 bool isAngle() const |
165 { | 280 { |
166 return m_primitiveUnitType == CSS_DEG | 281 return type() == CSS_DEG |
167 || m_primitiveUnitType == CSS_RAD | 282 || type() == CSS_RAD |
168 || m_primitiveUnitType == CSS_GRAD | 283 || type() == CSS_GRAD |
169 || m_primitiveUnitType == CSS_TURN; | 284 || type() == CSS_TURN; |
170 } | 285 } |
171 bool isAttr() const { return m_primitiveUnitType == CSS_ATTR; } | 286 bool isAttr() const { return type() == CSS_ATTR; } |
172 bool isCounter() const { return m_primitiveUnitType == CSS_COUNTER; } | 287 bool isCounter() const { return type() == CSS_COUNTER; } |
173 bool isCustomIdent() const { return m_primitiveUnitType == CSS_CUSTOM_IDENT;
} | 288 bool isCustomIdent() const { return type() == CSS_CUSTOM_IDENT; } |
174 bool isFontRelativeLength() const | 289 bool isFontRelativeLength() const |
175 { | 290 { |
176 return m_primitiveUnitType == CSS_EMS | 291 return type() == CSS_EMS |
177 || m_primitiveUnitType == CSS_EXS | 292 || type() == CSS_EXS |
178 || m_primitiveUnitType == CSS_REMS | 293 || type() == CSS_REMS |
179 || m_primitiveUnitType == CSS_CHS; | 294 || type() == CSS_CHS; |
180 } | 295 } |
181 bool isViewportPercentageLength() const { return isViewportPercentageLength(
static_cast<UnitType>(m_primitiveUnitType)); } | 296 bool isViewportPercentageLength() const { return isViewportPercentageLength(
type()); } |
182 static bool isViewportPercentageLength(UnitType type) { return type >= CSS_V
W && type <= CSS_VMAX; } | 297 static bool isViewportPercentageLength(UnitType type) { return type >= CSS_V
W && type <= CSS_VMAX; } |
183 static bool isLength(UnitType type) | 298 static bool isLength(UnitType type) |
184 { | 299 { |
185 return (type >= CSS_EMS && type <= CSS_PC) || type == CSS_REMS || type =
= CSS_CHS || isViewportPercentageLength(type); | 300 return (type >= CSS_EMS && type <= CSS_PC) || type == CSS_REMS || type =
= CSS_CHS || isViewportPercentageLength(type); |
186 } | 301 } |
187 bool isLength() const { return isLength(primitiveType()); } | 302 bool isLength() const { return isLength(primitiveType()); } |
188 bool isNumber() const { return primitiveType() == CSS_NUMBER || primitiveTyp
e() == CSS_INTEGER; } | 303 bool isNumber() const { return primitiveType() == CSS_NUMBER || primitiveTyp
e() == CSS_INTEGER; } |
189 bool isPercentage() const { return primitiveType() == CSS_PERCENTAGE; } | 304 bool isPercentage() const { return primitiveType() == CSS_PERCENTAGE; } |
190 bool isPx() const { return primitiveType() == CSS_PX; } | 305 bool isPx() const { return primitiveType() == CSS_PX; } |
191 bool isRect() const { return m_primitiveUnitType == CSS_RECT; } | 306 bool isRect() const { return type() == CSS_RECT; } |
192 bool isRGBColor() const { return m_primitiveUnitType == CSS_RGBCOLOR; } | 307 bool isRGBColor() const { return type() == CSS_RGBCOLOR; } |
193 bool isShape() const { return m_primitiveUnitType == CSS_SHAPE; } | 308 bool isShape() const { return type() == CSS_SHAPE; } |
194 bool isString() const { return m_primitiveUnitType == CSS_STRING; } | 309 bool isString() const { return type() == CSS_STRING; } |
195 bool isTime() const { return m_primitiveUnitType == CSS_S || m_primitiveUnit
Type == CSS_MS; } | 310 bool isTime() const { return type() == CSS_S || type() == CSS_MS; } |
196 bool isURI() const { return m_primitiveUnitType == CSS_URI; } | 311 bool isURI() const { return type() == CSS_URI; } |
197 bool isCalculated() const { return m_primitiveUnitType == CSS_CALC; } | 312 bool isCalculated() const { return type() == CSS_CALC; } |
198 bool isCalculatedPercentageWithNumber() const { return primitiveType() == CS
S_CALC_PERCENTAGE_WITH_NUMBER; } | 313 bool isCalculatedPercentageWithNumber() const { return primitiveType() == CS
S_CALC_PERCENTAGE_WITH_NUMBER; } |
199 bool isCalculatedPercentageWithLength() const { return primitiveType() == CS
S_CALC_PERCENTAGE_WITH_LENGTH; } | 314 bool isCalculatedPercentageWithLength() const { return primitiveType() == CS
S_CALC_PERCENTAGE_WITH_LENGTH; } |
200 static bool isDotsPerInch(UnitType type) { return type == CSS_DPI; } | 315 static bool isDotsPerInch(UnitType type) { return type == CSS_DPI; } |
201 static bool isDotsPerPixel(UnitType type) { return type == CSS_DPPX; } | 316 static bool isDotsPerPixel(UnitType type) { return type == CSS_DPPX; } |
202 static bool isDotsPerCentimeter(UnitType type) { return type == CSS_DPCM; } | 317 static bool isDotsPerCentimeter(UnitType type) { return type == CSS_DPCM; } |
203 static bool isResolution(UnitType type) { return type >= CSS_DPPX && type <=
CSS_DPCM; } | 318 static bool isResolution(UnitType type) { return type >= CSS_DPPX && type <=
CSS_DPCM; } |
204 bool isFlex() const { return primitiveType() == CSS_FR; } | 319 bool isFlex() const { return primitiveType() == CSS_FR; } |
205 bool isValueID() const { return m_primitiveUnitType == CSS_VALUE_ID; } | 320 bool isValueID() const { return type() == CSS_VALUE_ID; } |
206 bool colorIsDerivedFromElement() const; | 321 bool colorIsDerivedFromElement() const; |
207 | 322 |
208 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createIdentifier(CSSValueID
valueID) | 323 static CSSPrimitiveValue createIdentifier(CSSValueID valueID) |
209 { | 324 { |
210 return adoptRefWillBeNoop(new CSSPrimitiveValue(valueID)); | 325 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(v
alueID))); |
211 } | 326 } |
212 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createIdentifier(CSSPropert
yID propertyID) | 327 |
| 328 static CSSPrimitiveValue createIdentifier(CSSPropertyID propertyID) |
213 { | 329 { |
214 return adoptRefWillBeNoop(new CSSPrimitiveValue(propertyID)); | 330 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(p
ropertyID))); |
215 } | 331 } |
216 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createColor(RGBA32 rgbValue
) | 332 static CSSPrimitiveValue createColor(RGBA32 rgbValue) |
217 { | 333 { |
218 return adoptRefWillBeNoop(new CSSPrimitiveValue(rgbValue)); | 334 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(r
gbValue))); |
219 } | 335 } |
220 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(double value, UnitTy
pe type) | 336 static CSSPrimitiveValue create(double value, UnitType type) |
221 { | 337 { |
222 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, type)); | 338 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(v
alue, type))); |
223 } | 339 } |
224 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const String& value,
UnitType type) | 340 static CSSPrimitiveValue create(const String& value, UnitType type) |
225 { | 341 { |
226 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, type)); | 342 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(v
alue, type))); |
227 } | 343 } |
228 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const Length& value,
float zoom) | 344 static CSSPrimitiveValue create(const Length& value, float zoom) |
229 { | 345 { |
230 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, zoom)); | 346 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(v
alue, zoom))); |
231 } | 347 } |
232 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const LengthSize& va
lue, const ComputedStyle& style) | 348 static CSSPrimitiveValue create(const LengthSize& value, const ComputedStyle
& style) |
233 { | 349 { |
234 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, style)); | 350 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(v
alue, style))); |
235 } | 351 } |
236 template<typename T> static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create
(T value) | 352 template<typename T> static CSSPrimitiveValue create(T value) |
237 { | 353 { |
238 return adoptRefWillBeNoop(new CSSPrimitiveValue(value)); | 354 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(v
alue))); |
239 } | 355 } |
240 | 356 |
241 // This value is used to handle quirky margins in reflow roots (body, td, an
d th) like WinIE. | 357 // This value is used to handle quirky margins in reflow roots (body, td, an
d th) like WinIE. |
242 // The basic idea is that a stylesheet can use the value __qem (for quirky e
m) instead of em. | 358 // The basic idea is that a stylesheet can use the value __qem (for quirky e
m) instead of em. |
243 // When the quirky value is used, if you're in quirks mode, the margin will
collapse away | 359 // When the quirky value is used, if you're in quirks mode, the margin will
collapse away |
244 // inside a table cell. | 360 // inside a table cell. |
245 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createAllowingMarginQuirk(d
ouble value, UnitType type) | 361 static CSSPrimitiveValue createAllowingMarginQuirk(double value, UnitType ty
pe) |
246 { | 362 { |
247 CSSPrimitiveValue* quirkValue = new CSSPrimitiveValue(value, type); | 363 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(v
alue, type, true))); |
248 quirkValue->m_isQuirkValue = true; | |
249 return adoptRefWillBeNoop(quirkValue); | |
250 } | 364 } |
251 | 365 |
252 ~CSSPrimitiveValue(); | |
253 | |
254 void cleanup(); | |
255 | |
256 UnitType primitiveType() const; | 366 UnitType primitiveType() const; |
257 | 367 |
258 double computeDegrees() const; | 368 double computeDegrees() const; |
259 double computeSeconds(); | 369 double computeSeconds() const; |
260 | 370 |
261 // Computes a length in pixels, resolving relative lengths | 371 // Computes a length in pixels, resolving relative lengths |
262 template<typename T> T computeLength(const CSSToLengthConversionData&); | 372 template<typename T> T computeLength(const CSSToLengthConversionData&) const
; |
263 | 373 |
264 // Converts to a Length (Fixed, Percent or Calculated) | 374 // Converts to a Length (Fixed, Percent or Calculated) |
265 Length convertToLength(const CSSToLengthConversionData&); | 375 Length convertToLength(const CSSToLengthConversionData&) const; |
266 | 376 |
267 double getDoubleValue() const; | 377 double getDoubleValue() const; |
268 float getFloatValue() const { return getValue<float>(); } | 378 float getFloatValue() const { return getValue<float>(); } |
269 int getIntValue() const { return getValue<int>(); } | 379 int getIntValue() const { return getValue<int>(); } |
270 template<typename T> inline T getValue() const { return clampTo<T>(getDouble
Value()); } | 380 template<typename T> inline T getValue() const { return clampTo<T>(getDouble
Value()); } |
271 | 381 |
272 String getStringValue() const; | 382 String getStringValue() const; |
273 | 383 |
274 Counter* getCounterValue() const { return m_primitiveUnitType != CSS_COUNTER
? 0 : m_value.counter; } | 384 Counter* getCounterValue() const { return type() != CSS_COUNTER ? 0 : value(
).counter; } |
275 | 385 |
276 Rect* getRectValue() const { return m_primitiveUnitType != CSS_RECT ? 0 : m_
value.rect; } | 386 Rect* getRectValue() const { return type() != CSS_RECT ? 0 : value().rect; } |
277 | 387 |
278 Quad* getQuadValue() const { return m_primitiveUnitType != CSS_QUAD ? 0 : m_
value.quad; } | 388 Quad* getQuadValue() const { return type() != CSS_QUAD ? 0 : value().quad; } |
279 | 389 |
280 RGBA32 getRGBA32Value() const { return m_primitiveUnitType != CSS_RGBCOLOR ?
0 : m_value.rgbcolor; } | 390 RGBA32 getRGBA32Value() const { return type() != CSS_RGBCOLOR ? 0 : value().
rgbcolor; } |
281 | 391 |
282 Pair* getPairValue() const { return m_primitiveUnitType != CSS_PAIR ? 0 : m_
value.pair; } | 392 Pair* getPairValue() const { return type() != CSS_PAIR ? 0 : value().pair; } |
283 | 393 |
284 CSSBasicShape* getShapeValue() const { return m_primitiveUnitType != CSS_SHA
PE ? 0 : m_value.shape; } | 394 CSSBasicShape* getShapeValue() const { return type() != CSS_SHAPE ? 0 : valu
e().shape; } |
285 | 395 |
286 CSSCalcValue* cssCalcValue() const { return m_primitiveUnitType != CSS_CALC
? 0 : m_value.calc; } | 396 CSSCalcValue* cssCalcValue() const { return type() != CSS_CALC ? 0 : value()
.calc; } |
287 | 397 |
288 CSSPropertyID getPropertyID() const { return m_primitiveUnitType == CSS_PROP
ERTY_ID ? m_value.propertyID : CSSPropertyInvalid; } | 398 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; } | 399 CSSValueID getValueID() const { return type() == CSS_VALUE_ID ? value().valu
eID : CSSValueInvalid; } |
290 | 400 |
291 template<typename T> inline operator T() const; // Defined in CSSPrimitiveVa
lueMappings.h | 401 template<typename T> inline operator T() const; // Defined in CSSPrimitiveVa
lueMappings.h |
292 | 402 |
293 static const char* unitTypeToString(UnitType); | 403 static const char* unitTypeToString(UnitType); |
| 404 // TODO(sashab): Remove customCSSText() once CSSValueObject uses vtables pro
perly. |
294 String customCSSText() const; | 405 String customCSSText() const; |
| 406 String cssText() const { return customCSSText(); } |
295 | 407 |
296 bool isQuirkValue() { return m_isQuirkValue; } | 408 bool isQuirkValue() const |
| 409 { |
| 410 return m_rawValue->m_isQuirkValue; |
| 411 } |
297 | 412 |
298 bool equals(const CSSPrimitiveValue&) const; | 413 bool equals(const CSSPrimitiveValue) const; |
299 | |
300 DECLARE_TRACE_AFTER_DISPATCH(); | |
301 | 414 |
302 static UnitType canonicalUnitTypeForCategory(UnitCategory); | 415 static UnitType canonicalUnitTypeForCategory(UnitCategory); |
303 static double conversionToCanonicalUnitsScaleFactor(UnitType); | 416 static double conversionToCanonicalUnitsScaleFactor(UnitType); |
304 | 417 |
305 // Returns true and populates lengthUnitType, if unitType is a length unit.
Otherwise, returns false. | 418 // Returns true and populates lengthUnitType, if unitType is a length unit.
Otherwise, returns false. |
306 static bool unitTypeToLengthUnitType(UnitType, LengthUnitType&); | 419 static bool unitTypeToLengthUnitType(UnitType, LengthUnitType&); |
307 static UnitType lengthUnitTypeToUnitType(LengthUnitType); | 420 static UnitType lengthUnitTypeToUnitType(LengthUnitType); |
308 | 421 |
309 private: | 422 DEFINE_INLINE_TRACE() |
310 CSSPrimitiveValue(CSSValueID); | |
311 CSSPrimitiveValue(CSSPropertyID); | |
312 CSSPrimitiveValue(RGBA32 color); | |
313 CSSPrimitiveValue(const Length&, float zoom); | |
314 CSSPrimitiveValue(const LengthSize&, const ComputedStyle&); | |
315 CSSPrimitiveValue(const String&, UnitType); | |
316 CSSPrimitiveValue(double, UnitType); | |
317 | |
318 template<typename T> CSSPrimitiveValue(T); // Defined in CSSPrimitiveValueMa
ppings.h | |
319 template<typename T> CSSPrimitiveValue(T* val) | |
320 : CSSValueObject(PrimitiveClass) | |
321 { | 423 { |
322 init(PassRefPtrWillBeRawPtr<T>(val)); | 424 visitor->trace(m_rawValue); |
| 425 m_rawValue->traceAfterDispatch(visitor); |
323 } | 426 } |
324 | 427 |
325 template<typename T> CSSPrimitiveValue(PassRefPtrWillBeRawPtr<T> val) | 428 private: |
326 : CSSValueObject(PrimitiveClass) | 429 void ref() const |
327 { | 430 { |
328 init(val); | 431 #if !ENABLE(OILPAN) |
| 432 m_rawValue->ref(); |
| 433 #endif |
| 434 } |
| 435 |
| 436 void deref() const |
| 437 { |
| 438 #if !ENABLE(OILPAN) |
| 439 // Might be null due to move semantics. |
| 440 if (m_rawValue) |
| 441 m_rawValue->deref(); |
| 442 #endif |
329 } | 443 } |
330 | 444 |
331 static void create(int); // compile-time guard | 445 static void create(int); // compile-time guard |
332 static void create(unsigned); // compile-time guard | 446 static void create(unsigned); // compile-time guard |
333 template<typename T> operator T*(); // compile-time guard | 447 template<typename T> operator T*(); // compile-time guard |
334 | 448 |
335 void init(const Length&); | 449 double computeLengthDouble(const CSSToLengthConversionData&) const; |
336 void init(const LengthSize&, const ComputedStyle&); | |
337 void init(PassRefPtrWillBeRawPtr<Counter>); | |
338 void init(PassRefPtrWillBeRawPtr<Rect>); | |
339 void init(PassRefPtrWillBeRawPtr<Pair>); | |
340 void init(PassRefPtrWillBeRawPtr<Quad>); | |
341 void init(PassRefPtrWillBeRawPtr<CSSBasicShape>); | |
342 void init(PassRefPtrWillBeRawPtr<CSSCalcValue>); | |
343 | 450 |
344 double computeLengthDouble(const CSSToLengthConversionData&); | 451 RawPtrWillBeMember<CSSLargePrimitiveValue> m_rawValue; |
| 452 static_assert(sizeof(m_rawValue) == sizeof(void*), "The tagged pointer field
in CSSPrimitiveValue must be the size of a pointer"); |
345 | 453 |
346 union { | 454 // Getters/setters for inner class. |
347 CSSPropertyID propertyID; | 455 CSSPrimitiveValueData value() const |
348 CSSValueID valueID; | 456 { |
349 double num; | 457 return m_rawValue->m_value; |
350 StringImpl* string; | 458 } |
351 RGBA32 rgbcolor; | 459 |
352 // FIXME: oilpan: Should be members, but no support for members in union
s. Just trace the raw ptr for now. | 460 UnitType type() const |
353 CSSBasicShape* shape; | 461 { |
354 CSSCalcValue* calc; | 462 return static_cast<UnitType>(m_rawValue->m_primitiveUnitType); |
355 Counter* counter; | 463 } |
356 Pair* pair; | |
357 Rect* rect; | |
358 Quad* quad; | |
359 } m_value; | |
360 }; | 464 }; |
361 | 465 |
362 typedef CSSPrimitiveValue::CSSLengthArray CSSLengthArray; | 466 typedef CSSPrimitiveValue::CSSLengthArray CSSLengthArray; |
363 typedef CSSPrimitiveValue::CSSLengthTypeArray CSSLengthTypeArray; | 467 typedef CSSPrimitiveValue::CSSLengthTypeArray CSSLengthTypeArray; |
364 | 468 |
365 DEFINE_CSS_VALUE_TYPE_CASTS(CSSPrimitiveValue, isPrimitiveValue()); | 469 static_assert(sizeof(CSSPrimitiveValue) == sizeof(void*), "CSSPrimitiveValue mus
t be the size of a pointer"); |
366 | 470 |
367 } // namespace blink | 471 } // namespace blink |
368 | 472 |
369 #endif // CSSPrimitiveValue_h | 473 #endif // CSSPrimitiveValue_h |
OLD | NEW |