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