| 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 11 matching lines...) Expand all Loading... |
| 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/CSSValue.h" |
| 29 #include "wtf/BitVector.h" | 29 #include "wtf/BitVector.h" |
| 30 #include "wtf/Forward.h" | 30 #include "wtf/Forward.h" |
| 31 #include "wtf/MathExtras.h" | 31 #include "wtf/MathExtras.h" |
| 32 #include "wtf/TypeTraits.h" | |
| 33 #include "wtf/text/StringHash.h" | 32 #include "wtf/text/StringHash.h" |
| 34 #include "wtf/text/StringView.h" | 33 #include "wtf/text/StringView.h" |
| 35 | 34 |
| 36 namespace blink { | 35 namespace blink { |
| 37 | 36 |
| 38 class CSSCalcValue; | 37 class CSSCalcValue; |
| 39 class CSSToLengthConversionData; | 38 class CSSToLengthConversionData; |
| 40 class Length; | 39 class Length; |
| 41 | 40 |
| 42 // Dimension calculations are imprecise, often resulting in values of e.g. | 41 // Dimension calculations are imprecise, often resulting in values of e.g. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 DotsPerInch, | 99 DotsPerInch, |
| 101 DotsPerCentimeter, | 100 DotsPerCentimeter, |
| 102 // Other units | 101 // Other units |
| 103 Fraction, | 102 Fraction, |
| 104 Integer, | 103 Integer, |
| 105 Calc, | 104 Calc, |
| 106 CalcPercentageWithNumber, | 105 CalcPercentageWithNumber, |
| 107 CalcPercentageWithLength, | 106 CalcPercentageWithLength, |
| 108 CalcLengthWithNumber, | 107 CalcLengthWithNumber, |
| 109 CalcPercentageWithLengthAndNumber, | 108 CalcPercentageWithLengthAndNumber, |
| 110 ValueID, | |
| 111 | 109 |
| 112 // This value is used to handle quirky margins in reflow roots (body, td
, and th) like WinIE. | 110 // 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. | 111 // 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 | 112 // 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. | 113 // inside a table cell. This quirk is specified in the HTML spec but our
impl is different. |
| 116 // TODO: Remove this. crbug.com/443952 | 114 // TODO: Remove this. crbug.com/443952 |
| 117 QuirkyEms, | 115 QuirkyEms, |
| 118 }; | 116 }; |
| 119 | 117 |
| 120 enum LengthUnitType { | 118 enum LengthUnitType { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 bool isLength() const { return isLength(typeWithCalcResolved()); } | 193 bool isLength() const { return isLength(typeWithCalcResolved()); } |
| 196 bool isNumber() const { return typeWithCalcResolved() == UnitType::Number ||
typeWithCalcResolved() == UnitType::Integer; } | 194 bool isNumber() const { return typeWithCalcResolved() == UnitType::Number ||
typeWithCalcResolved() == UnitType::Integer; } |
| 197 bool isPercentage() const { return typeWithCalcResolved() == UnitType::Perce
ntage; } | 195 bool isPercentage() const { return typeWithCalcResolved() == UnitType::Perce
ntage; } |
| 198 bool isPx() const { return typeWithCalcResolved() == UnitType::Pixels; } | 196 bool isPx() const { return typeWithCalcResolved() == UnitType::Pixels; } |
| 199 bool isTime() const { return type() == UnitType::Seconds || type() == UnitTy
pe::Milliseconds; } | 197 bool isTime() const { return type() == UnitType::Seconds || type() == UnitTy
pe::Milliseconds; } |
| 200 bool isCalculated() const { return type() == UnitType::Calc; } | 198 bool isCalculated() const { return type() == UnitType::Calc; } |
| 201 bool isCalculatedPercentageWithNumber() const { return typeWithCalcResolved(
) == UnitType::CalcPercentageWithNumber; } | 199 bool isCalculatedPercentageWithNumber() const { return typeWithCalcResolved(
) == UnitType::CalcPercentageWithNumber; } |
| 202 bool isCalculatedPercentageWithLength() const { return typeWithCalcResolved(
) == UnitType::CalcPercentageWithLength; } | 200 bool isCalculatedPercentageWithLength() const { return typeWithCalcResolved(
) == UnitType::CalcPercentageWithLength; } |
| 203 static bool isResolution(UnitType type) { return type >= UnitType::DotsPerPi
xel && type <= UnitType::DotsPerCentimeter; } | 201 static bool isResolution(UnitType type) { return type >= UnitType::DotsPerPi
xel && type <= UnitType::DotsPerCentimeter; } |
| 204 bool isFlex() const { return typeWithCalcResolved() == UnitType::Fraction; } | 202 bool isFlex() const { return typeWithCalcResolved() == UnitType::Fraction; } |
| 205 bool isValueID() const { return type() == UnitType::ValueID; } | |
| 206 bool colorIsDerivedFromElement() const; | |
| 207 | 203 |
| 208 static CSSPrimitiveValue* createIdentifier(CSSValueID); | |
| 209 static CSSPrimitiveValue* create(double value, UnitType); | 204 static CSSPrimitiveValue* create(double value, UnitType); |
| 210 static CSSPrimitiveValue* create(const Length& value, float zoom) | 205 static CSSPrimitiveValue* create(const Length& value, float zoom) |
| 211 { | 206 { |
| 212 return new CSSPrimitiveValue(value, zoom); | 207 return new CSSPrimitiveValue(value, zoom); |
| 213 } | 208 } |
| 209 |
| 210 // TODO(sashab): Remove this. |
| 214 template<typename T> static CSSPrimitiveValue* create(T value) | 211 template<typename T> static CSSPrimitiveValue* create(T value) |
| 215 { | 212 { |
| 216 static_assert(!std::is_same<T, CSSValueID>::value, "Do not call create()
with a CSSValueID; call createIdentifier() instead"); | |
| 217 return new CSSPrimitiveValue(value); | 213 return new CSSPrimitiveValue(value); |
| 218 } | 214 } |
| 219 | 215 |
| 220 ~CSSPrimitiveValue(); | 216 ~CSSPrimitiveValue(); |
| 221 | 217 |
| 222 UnitType typeWithCalcResolved() const; | 218 UnitType typeWithCalcResolved() const; |
| 223 | 219 |
| 224 double computeDegrees() const; | 220 double computeDegrees() const; |
| 225 double computeSeconds() const; | 221 double computeSeconds() const; |
| 226 | 222 |
| 227 // Computes a length in pixels, resolving relative lengths | 223 // Computes a length in pixels, resolving relative lengths |
| 228 template<typename T> T computeLength(const CSSToLengthConversionData&) const
; | 224 template<typename T> T computeLength(const CSSToLengthConversionData&) const
; |
| 229 | 225 |
| 230 // Converts to a Length (Fixed, Percent or Calculated) | 226 // Converts to a Length (Fixed, Percent or Calculated) |
| 231 Length convertToLength(const CSSToLengthConversionData&) const; | 227 Length convertToLength(const CSSToLengthConversionData&) const; |
| 232 | 228 |
| 233 double getDoubleValue() const; | 229 double getDoubleValue() const; |
| 234 float getFloatValue() const { return getValue<float>(); } | 230 float getFloatValue() const { return getValue<float>(); } |
| 235 int getIntValue() const { return getValue<int>(); } | 231 int getIntValue() const { return getValue<int>(); } |
| 236 template<typename T> inline T getValue() const { return clampTo<T>(getDouble
Value()); } | 232 template<typename T> inline T getValue() const { return clampTo<T>(getDouble
Value()); } |
| 237 | 233 |
| 238 CSSCalcValue* cssCalcValue() const { ASSERT(isCalculated()); return m_value.
calc; } | 234 CSSCalcValue* cssCalcValue() const { ASSERT(isCalculated()); return m_value.
calc; } |
| 239 | 235 |
| 240 CSSValueID getValueID() const { return type() == UnitType::ValueID ? m_value
.valueID : CSSValueInvalid; } | |
| 241 | |
| 242 template<typename T> inline T convertTo() const; // Defined in CSSPrimitiveV
alueMappings.h | 236 template<typename T> inline T convertTo() const; // Defined in CSSPrimitiveV
alueMappings.h |
| 243 | 237 |
| 244 static const char* unitTypeToString(UnitType); | 238 static const char* unitTypeToString(UnitType); |
| 245 static UnitType stringToUnitType(StringView string) | 239 static UnitType stringToUnitType(StringView string) |
| 246 { | 240 { |
| 247 if (string.is8Bit()) | 241 if (string.is8Bit()) |
| 248 return stringToUnitType(string.characters8(), string.length()); | 242 return stringToUnitType(string.characters8(), string.length()); |
| 249 return stringToUnitType(string.characters16(), string.length()); | 243 return stringToUnitType(string.characters16(), string.length()); |
| 250 } | 244 } |
| 251 | 245 |
| 252 String customCSSText() const; | 246 String customCSSText() const; |
| 253 | 247 |
| 254 bool equals(const CSSPrimitiveValue&) const; | 248 bool equals(const CSSPrimitiveValue&) const; |
| 255 | 249 |
| 256 DECLARE_TRACE_AFTER_DISPATCH(); | 250 DECLARE_TRACE_AFTER_DISPATCH(); |
| 257 | 251 |
| 258 static UnitType canonicalUnitTypeForCategory(UnitCategory); | 252 static UnitType canonicalUnitTypeForCategory(UnitCategory); |
| 259 static double conversionToCanonicalUnitsScaleFactor(UnitType); | 253 static double conversionToCanonicalUnitsScaleFactor(UnitType); |
| 260 | 254 |
| 261 // Returns true and populates lengthUnitType, if unitType is a length unit.
Otherwise, returns false. | 255 // Returns true and populates lengthUnitType, if unitType is a length unit.
Otherwise, returns false. |
| 262 static bool unitTypeToLengthUnitType(UnitType, LengthUnitType&); | 256 static bool unitTypeToLengthUnitType(UnitType, LengthUnitType&); |
| 263 static UnitType lengthUnitTypeToUnitType(LengthUnitType); | 257 static UnitType lengthUnitTypeToUnitType(LengthUnitType); |
| 264 | 258 |
| 265 private: | 259 private: |
| 266 CSSPrimitiveValue(CSSValueID); | |
| 267 CSSPrimitiveValue(const Length&, float zoom); | 260 CSSPrimitiveValue(const Length&, float zoom); |
| 268 CSSPrimitiveValue(double, UnitType); | 261 CSSPrimitiveValue(double, UnitType); |
| 269 | 262 |
| 270 template<typename T> CSSPrimitiveValue(T); // Defined in CSSPrimitiveValueMa
ppings.h | 263 template<typename T> CSSPrimitiveValue(T); // Defined in CSSPrimitiveValueMa
ppings.h |
| 271 | 264 |
| 272 template<typename T> CSSPrimitiveValue(T* val) | 265 template<typename T> CSSPrimitiveValue(T* val) |
| 273 : CSSValue(PrimitiveClass) | 266 : CSSValue(PrimitiveClass) |
| 274 { | 267 { |
| 275 init(val); | 268 init(val); |
| 276 } | 269 } |
| 277 | 270 |
| 278 static void create(int); // compile-time guard | 271 static void create(int); // compile-time guard |
| 279 static void create(unsigned); // compile-time guard | 272 static void create(unsigned); // compile-time guard |
| 280 template<typename T> operator T*(); // compile-time guard | 273 template<typename T> operator T*(); // compile-time guard |
| 281 | 274 |
| 282 // Code generated by CSSPrimitiveValueUnitTrie.cpp.tmpl | 275 // Code generated by CSSPrimitiveValueUnitTrie.cpp.tmpl |
| 283 static UnitType stringToUnitType(const LChar*, unsigned length); | 276 static UnitType stringToUnitType(const LChar*, unsigned length); |
| 284 static UnitType stringToUnitType(const UChar*, unsigned length); | 277 static UnitType stringToUnitType(const UChar*, unsigned length); |
| 285 | 278 |
| 286 void init(UnitType); | 279 void init(UnitType); |
| 287 void init(const Length&); | 280 void init(const Length&); |
| 288 void init(CSSCalcValue*); | 281 void init(CSSCalcValue*); |
| 289 | 282 |
| 290 double computeLengthDouble(const CSSToLengthConversionData&) const; | 283 double computeLengthDouble(const CSSToLengthConversionData&) const; |
| 291 | 284 |
| 292 inline UnitType type() const { return static_cast<UnitType>(m_primitiveUnitT
ype); } | 285 inline UnitType type() const { return static_cast<UnitType>(m_primitiveUnitT
ype); } |
| 293 | 286 |
| 294 union { | 287 union { |
| 295 CSSValueID valueID; | |
| 296 double num; | 288 double num; |
| 297 // FIXME: oilpan: Should be a member, but no support for members in unio
ns. Just trace the raw ptr for now. | 289 // FIXME: oilpan: Should be a member, but no support for members in unio
ns. Just trace the raw ptr for now. |
| 298 CSSCalcValue* calc; | 290 CSSCalcValue* calc; |
| 299 } m_value; | 291 } m_value; |
| 300 }; | 292 }; |
| 301 | 293 |
| 302 using CSSLengthArray = CSSPrimitiveValue::CSSLengthArray; | 294 using CSSLengthArray = CSSPrimitiveValue::CSSLengthArray; |
| 303 | 295 |
| 304 DEFINE_CSS_VALUE_TYPE_CASTS(CSSPrimitiveValue, isPrimitiveValue()); | 296 DEFINE_CSS_VALUE_TYPE_CASTS(CSSPrimitiveValue, isPrimitiveValue()); |
| 305 | 297 |
| 306 } // namespace blink | 298 } // namespace blink |
| 307 | 299 |
| 308 #endif // CSSPrimitiveValue_h | 300 #endif // CSSPrimitiveValue_h |
| OLD | NEW |