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 * |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 Points, | 80 Points, |
81 Picas, | 81 Picas, |
82 Degrees, | 82 Degrees, |
83 Radians, | 83 Radians, |
84 Gradians, | 84 Gradians, |
85 Turns, | 85 Turns, |
86 Milliseconds, | 86 Milliseconds, |
87 Seconds, | 87 Seconds, |
88 Hertz, | 88 Hertz, |
89 Kilohertz, | 89 Kilohertz, |
90 CustomIdentifier, | |
91 URI, | |
92 RGBColor, | 90 RGBColor, |
93 ViewportWidth, | 91 ViewportWidth, |
94 ViewportHeight, | 92 ViewportHeight, |
95 ViewportMin, | 93 ViewportMin, |
96 ViewportMax, | 94 ViewportMax, |
97 DotsPerPixel, | 95 DotsPerPixel, |
98 DotsPerInch, | 96 DotsPerInch, |
99 DotsPerCentimeter, | 97 DotsPerCentimeter, |
100 Fraction, | 98 Fraction, |
101 Integer, | 99 Integer, |
102 Rems, | 100 Rems, |
103 Chs, | 101 Chs, |
104 Shape, | 102 Shape, |
105 Calc, | 103 Calc, |
106 CalcPercentageWithNumber, | 104 CalcPercentageWithNumber, |
107 CalcPercentageWithLength, | 105 CalcPercentageWithLength, |
108 String, | |
109 PropertyID, | 106 PropertyID, |
110 ValueID, | 107 ValueID, |
111 | 108 |
112 // This value is used to handle quirky margins in reflow roots (body, td
, and th) like WinIE. | 109 // This value is used to handle quirky margins in reflow roots (body, td
, and th) like WinIE. |
113 // The basic idea is that a stylesheet can use the value __qem (for quir
ky em) instead of em. | 110 // The basic idea is that a stylesheet can use the value __qem (for quir
ky em) instead of em. |
114 // When the quirky value is used, if you're in quirks mode, the margin w
ill collapse away | 111 // When the quirky value is used, if you're in quirks mode, the margin w
ill collapse away |
115 // inside a table cell. This quirk is specified in the HTML spec but our
impl is different. | 112 // inside a table cell. This quirk is specified in the HTML spec but our
impl is different. |
116 // TODO: Remove this. crbug.com/443952 | 113 // TODO: Remove this. crbug.com/443952 |
117 QuirkyEms, | 114 QuirkyEms, |
118 }; | 115 }; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 | 153 |
157 static UnitType fromName(const String& unit); | 154 static UnitType fromName(const String& unit); |
158 | 155 |
159 bool isAngle() const | 156 bool isAngle() const |
160 { | 157 { |
161 return type() == UnitType::Degrees | 158 return type() == UnitType::Degrees |
162 || type() == UnitType::Radians | 159 || type() == UnitType::Radians |
163 || type() == UnitType::Gradians | 160 || type() == UnitType::Gradians |
164 || type() == UnitType::Turns; | 161 || type() == UnitType::Turns; |
165 } | 162 } |
166 bool isCustomIdent() const { return type() == UnitType::CustomIdentifier; } | |
167 bool isFontRelativeLength() const | 163 bool isFontRelativeLength() const |
168 { | 164 { |
169 return type() == UnitType::QuirkyEms | 165 return type() == UnitType::QuirkyEms |
170 || type() == UnitType::Ems | 166 || type() == UnitType::Ems |
171 || type() == UnitType::Exs | 167 || type() == UnitType::Exs |
172 || type() == UnitType::Rems | 168 || type() == UnitType::Rems |
173 || type() == UnitType::Chs; | 169 || type() == UnitType::Chs; |
174 } | 170 } |
175 bool isQuirkyEms() const { return type() == UnitType::QuirkyEms; } | 171 bool isQuirkyEms() const { return type() == UnitType::QuirkyEms; } |
176 bool isViewportPercentageLength() const { return isViewportPercentageLength(
type()); } | 172 bool isViewportPercentageLength() const { return isViewportPercentageLength(
type()); } |
177 static bool isViewportPercentageLength(UnitType type) { return type >= UnitT
ype::ViewportWidth && type <= UnitType::ViewportMax; } | 173 static bool isViewportPercentageLength(UnitType type) { return type >= UnitT
ype::ViewportWidth && type <= UnitType::ViewportMax; } |
178 static bool isLength(UnitType type) | 174 static bool isLength(UnitType type) |
179 { | 175 { |
180 return (type >= UnitType::Ems && type <= UnitType::Picas) || type == Uni
tType::QuirkyEms || type == UnitType::Rems || type == UnitType::Chs || isViewpor
tPercentageLength(type); | 176 return (type >= UnitType::Ems && type <= UnitType::Picas) || type == Uni
tType::QuirkyEms || type == UnitType::Rems || type == UnitType::Chs || isViewpor
tPercentageLength(type); |
181 } | 177 } |
182 bool isLength() const { return isLength(typeWithCalcResolved()); } | 178 bool isLength() const { return isLength(typeWithCalcResolved()); } |
183 bool isNumber() const { return typeWithCalcResolved() == UnitType::Number ||
typeWithCalcResolved() == UnitType::Integer; } | 179 bool isNumber() const { return typeWithCalcResolved() == UnitType::Number ||
typeWithCalcResolved() == UnitType::Integer; } |
184 bool isPercentage() const { return typeWithCalcResolved() == UnitType::Perce
ntage; } | 180 bool isPercentage() const { return typeWithCalcResolved() == UnitType::Perce
ntage; } |
185 bool isPropertyID() const { return type() == UnitType::PropertyID; } | 181 bool isPropertyID() const { return type() == UnitType::PropertyID; } |
186 bool isPx() const { return typeWithCalcResolved() == UnitType::Pixels; } | 182 bool isPx() const { return typeWithCalcResolved() == UnitType::Pixels; } |
187 bool isRGBColor() const { return type() == UnitType::RGBColor; } | 183 bool isRGBColor() const { return type() == UnitType::RGBColor; } |
188 bool isShape() const { return type() == UnitType::Shape; } | 184 bool isShape() const { return type() == UnitType::Shape; } |
189 bool isString() const { return type() == UnitType::String; } | |
190 bool isTime() const { return type() == UnitType::Seconds || type() == UnitTy
pe::Milliseconds; } | 185 bool isTime() const { return type() == UnitType::Seconds || type() == UnitTy
pe::Milliseconds; } |
191 bool isURI() const { return type() == UnitType::URI; } | |
192 bool isCalculated() const { return type() == UnitType::Calc; } | 186 bool isCalculated() const { return type() == UnitType::Calc; } |
193 bool isCalculatedPercentageWithNumber() const { return typeWithCalcResolved(
) == UnitType::CalcPercentageWithNumber; } | 187 bool isCalculatedPercentageWithNumber() const { return typeWithCalcResolved(
) == UnitType::CalcPercentageWithNumber; } |
194 bool isCalculatedPercentageWithLength() const { return typeWithCalcResolved(
) == UnitType::CalcPercentageWithLength; } | 188 bool isCalculatedPercentageWithLength() const { return typeWithCalcResolved(
) == UnitType::CalcPercentageWithLength; } |
195 static bool isDotsPerInch(UnitType type) { return type == UnitType::DotsPerI
nch; } | 189 static bool isDotsPerInch(UnitType type) { return type == UnitType::DotsPerI
nch; } |
196 static bool isDotsPerPixel(UnitType type) { return type == UnitType::DotsPer
Pixel; } | 190 static bool isDotsPerPixel(UnitType type) { return type == UnitType::DotsPer
Pixel; } |
197 static bool isDotsPerCentimeter(UnitType type) { return type == UnitType::Do
tsPerCentimeter; } | 191 static bool isDotsPerCentimeter(UnitType type) { return type == UnitType::Do
tsPerCentimeter; } |
198 static bool isResolution(UnitType type) { return type >= UnitType::DotsPerPi
xel && type <= UnitType::DotsPerCentimeter; } | 192 static bool isResolution(UnitType type) { return type >= UnitType::DotsPerPi
xel && type <= UnitType::DotsPerCentimeter; } |
199 bool isFlex() const { return typeWithCalcResolved() == UnitType::Fraction; } | 193 bool isFlex() const { return typeWithCalcResolved() == UnitType::Fraction; } |
200 bool isValueID() const { return type() == UnitType::ValueID; } | 194 bool isValueID() const { return type() == UnitType::ValueID; } |
201 bool colorIsDerivedFromElement() const; | 195 bool colorIsDerivedFromElement() const; |
202 | 196 |
203 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createIdentifier(CSSValueID
valueID) | 197 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createIdentifier(CSSValueID
valueID) |
204 { | 198 { |
205 return adoptRefWillBeNoop(new CSSPrimitiveValue(valueID)); | 199 return adoptRefWillBeNoop(new CSSPrimitiveValue(valueID)); |
206 } | 200 } |
207 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createIdentifier(CSSPropert
yID propertyID) | 201 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createIdentifier(CSSPropert
yID propertyID) |
208 { | 202 { |
209 return adoptRefWillBeNoop(new CSSPrimitiveValue(propertyID)); | 203 return adoptRefWillBeNoop(new CSSPrimitiveValue(propertyID)); |
210 } | 204 } |
211 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createColor(RGBA32 rgbValue
) | 205 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createColor(RGBA32 rgbValue
) |
212 { | 206 { |
213 return adoptRefWillBeNoop(new CSSPrimitiveValue(rgbValue)); | 207 return adoptRefWillBeNoop(new CSSPrimitiveValue(rgbValue)); |
214 } | 208 } |
215 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(double value, UnitTy
pe type) | 209 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(double value, UnitTy
pe type) |
216 { | 210 { |
217 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, type)); | 211 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, type)); |
218 } | 212 } |
219 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const String& value,
UnitType type) | |
220 { | |
221 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, type)); | |
222 } | |
223 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const Length& value,
float zoom) | 213 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const Length& value,
float zoom) |
224 { | 214 { |
225 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, zoom)); | 215 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, zoom)); |
226 } | 216 } |
227 template<typename T> static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create
(T value) | 217 template<typename T> static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create
(T value) |
228 { | 218 { |
229 return adoptRefWillBeNoop(new CSSPrimitiveValue(value)); | 219 return adoptRefWillBeNoop(new CSSPrimitiveValue(value)); |
230 } | 220 } |
231 | 221 |
232 ~CSSPrimitiveValue(); | 222 ~CSSPrimitiveValue(); |
233 | 223 |
234 void cleanup(); | 224 void cleanup(); |
235 | 225 |
236 UnitType typeWithCalcResolved() const; | 226 UnitType typeWithCalcResolved() const; |
237 | 227 |
238 double computeDegrees() const; | 228 double computeDegrees() const; |
239 double computeSeconds() const; | 229 double computeSeconds() const; |
240 | 230 |
241 // Computes a length in pixels, resolving relative lengths | 231 // Computes a length in pixels, resolving relative lengths |
242 template<typename T> T computeLength(const CSSToLengthConversionData&) const
; | 232 template<typename T> T computeLength(const CSSToLengthConversionData&) const
; |
243 | 233 |
244 // Converts to a Length (Fixed, Percent or Calculated) | 234 // Converts to a Length (Fixed, Percent or Calculated) |
245 Length convertToLength(const CSSToLengthConversionData&) const; | 235 Length convertToLength(const CSSToLengthConversionData&) const; |
246 | 236 |
247 double getDoubleValue() const; | 237 double getDoubleValue() const; |
248 float getFloatValue() const { return getValue<float>(); } | 238 float getFloatValue() const { return getValue<float>(); } |
249 int getIntValue() const { return getValue<int>(); } | 239 int getIntValue() const { return getValue<int>(); } |
250 template<typename T> inline T getValue() const { return clampTo<T>(getDouble
Value()); } | 240 template<typename T> inline T getValue() const { return clampTo<T>(getDouble
Value()); } |
251 | 241 |
252 String getStringValue() const; | |
253 RGBA32 getRGBA32Value() const { ASSERT(isRGBColor()); return m_value.rgbcolo
r; } | 242 RGBA32 getRGBA32Value() const { ASSERT(isRGBColor()); return m_value.rgbcolo
r; } |
254 | 243 |
255 CSSBasicShape* getShapeValue() const { ASSERT(isShape()); return m_value.sha
pe; } | 244 CSSBasicShape* getShapeValue() const { ASSERT(isShape()); return m_value.sha
pe; } |
256 CSSCalcValue* cssCalcValue() const { ASSERT(isCalculated()); return m_value.
calc; } | 245 CSSCalcValue* cssCalcValue() const { ASSERT(isCalculated()); return m_value.
calc; } |
257 CSSPropertyID getPropertyID() const { ASSERT(isPropertyID()); return m_value
.propertyID; } | 246 CSSPropertyID getPropertyID() const { ASSERT(isPropertyID()); return m_value
.propertyID; } |
258 | 247 |
259 CSSValueID getValueID() const { return type() == UnitType::ValueID ? m_value
.valueID : CSSValueInvalid; } | 248 CSSValueID getValueID() const { return type() == UnitType::ValueID ? m_value
.valueID : CSSValueInvalid; } |
260 | 249 |
261 template<typename T> inline operator T() const; // Defined in CSSPrimitiveVa
lueMappings.h | 250 template<typename T> inline operator T() const; // Defined in CSSPrimitiveVa
lueMappings.h |
262 | 251 |
263 static const char* unitTypeToString(UnitType); | 252 static const char* unitTypeToString(UnitType); |
264 String customCSSText() const; | 253 String customCSSText() const; |
265 | 254 |
266 bool equals(const CSSPrimitiveValue&) const; | 255 bool equals(const CSSPrimitiveValue&) const; |
267 | 256 |
268 DECLARE_TRACE_AFTER_DISPATCH(); | 257 DECLARE_TRACE_AFTER_DISPATCH(); |
269 | 258 |
270 static UnitType canonicalUnitTypeForCategory(UnitCategory); | 259 static UnitType canonicalUnitTypeForCategory(UnitCategory); |
271 static double conversionToCanonicalUnitsScaleFactor(UnitType); | 260 static double conversionToCanonicalUnitsScaleFactor(UnitType); |
272 | 261 |
273 // Returns true and populates lengthUnitType, if unitType is a length unit.
Otherwise, returns false. | 262 // Returns true and populates lengthUnitType, if unitType is a length unit.
Otherwise, returns false. |
274 static bool unitTypeToLengthUnitType(UnitType, LengthUnitType&); | 263 static bool unitTypeToLengthUnitType(UnitType, LengthUnitType&); |
275 static UnitType lengthUnitTypeToUnitType(LengthUnitType); | 264 static UnitType lengthUnitTypeToUnitType(LengthUnitType); |
276 | 265 |
277 private: | 266 private: |
278 CSSPrimitiveValue(CSSValueID); | 267 CSSPrimitiveValue(CSSValueID); |
279 CSSPrimitiveValue(CSSPropertyID); | 268 CSSPrimitiveValue(CSSPropertyID); |
280 CSSPrimitiveValue(RGBA32 color); | 269 CSSPrimitiveValue(RGBA32 color); |
281 CSSPrimitiveValue(const Length&, float zoom); | 270 CSSPrimitiveValue(const Length&, float zoom); |
282 CSSPrimitiveValue(const String&, UnitType); | |
283 CSSPrimitiveValue(double, UnitType); | 271 CSSPrimitiveValue(double, UnitType); |
284 | 272 |
285 template<typename T> CSSPrimitiveValue(T); // Defined in CSSPrimitiveValueMa
ppings.h | 273 template<typename T> CSSPrimitiveValue(T); // Defined in CSSPrimitiveValueMa
ppings.h |
286 template<typename T> CSSPrimitiveValue(T* val) | 274 template<typename T> CSSPrimitiveValue(T* val) |
287 : CSSValue(PrimitiveClass) | 275 : CSSValue(PrimitiveClass) |
288 { | 276 { |
289 init(PassRefPtrWillBeRawPtr<T>(val)); | 277 init(PassRefPtrWillBeRawPtr<T>(val)); |
290 } | 278 } |
291 | 279 |
292 template<typename T> CSSPrimitiveValue(PassRefPtrWillBeRawPtr<T> val) | 280 template<typename T> CSSPrimitiveValue(PassRefPtrWillBeRawPtr<T> val) |
(...skipping 12 matching lines...) Expand all Loading... |
305 void init(PassRefPtrWillBeRawPtr<CSSCalcValue>); | 293 void init(PassRefPtrWillBeRawPtr<CSSCalcValue>); |
306 | 294 |
307 double computeLengthDouble(const CSSToLengthConversionData&) const; | 295 double computeLengthDouble(const CSSToLengthConversionData&) const; |
308 | 296 |
309 inline UnitType type() const { return static_cast<UnitType>(m_primitiveUnitT
ype); } | 297 inline UnitType type() const { return static_cast<UnitType>(m_primitiveUnitT
ype); } |
310 | 298 |
311 union { | 299 union { |
312 CSSPropertyID propertyID; | 300 CSSPropertyID propertyID; |
313 CSSValueID valueID; | 301 CSSValueID valueID; |
314 double num; | 302 double num; |
315 StringImpl* string; | |
316 RGBA32 rgbcolor; | 303 RGBA32 rgbcolor; |
317 // FIXME: oilpan: Should be members, but no support for members in union
s. Just trace the raw ptr for now. | 304 // FIXME: oilpan: Should be members, but no support for members in union
s. Just trace the raw ptr for now. |
318 CSSBasicShape* shape; | 305 CSSBasicShape* shape; |
319 CSSCalcValue* calc; | 306 CSSCalcValue* calc; |
320 } m_value; | 307 } m_value; |
321 }; | 308 }; |
322 | 309 |
323 using CSSLengthArray = CSSPrimitiveValue::CSSLengthArray; | 310 using CSSLengthArray = CSSPrimitiveValue::CSSLengthArray; |
324 using CSSLengthTypeArray = CSSPrimitiveValue::CSSLengthTypeArray; | 311 using CSSLengthTypeArray = CSSPrimitiveValue::CSSLengthTypeArray; |
325 | 312 |
326 DEFINE_CSS_VALUE_TYPE_CASTS(CSSPrimitiveValue, isPrimitiveValue()); | 313 DEFINE_CSS_VALUE_TYPE_CASTS(CSSPrimitiveValue, isPrimitiveValue()); |
327 | 314 |
328 } // namespace blink | 315 } // namespace blink |
329 | 316 |
330 #endif // CSSPrimitiveValue_h | 317 #endif // CSSPrimitiveValue_h |
OLD | NEW |