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

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

Issue 2382653006: Split CSSPrimitiveValue into CSSPrimitiveValue and CSSIdentifierValue (Closed)
Patch Set: Make check-webkit-style happy Created 4 years, 2 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
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 11 matching lines...) Expand all
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 12 matching lines...) Expand all
55 inline float roundForImpreciseConversion(double value) { 54 inline float roundForImpreciseConversion(double value) {
56 double ceiledValue = ceil(value); 55 double ceiledValue = ceil(value);
57 double proximityToNextInt = ceiledValue - value; 56 double proximityToNextInt = ceiledValue - value;
58 if (proximityToNextInt <= 0.01 && value > 0) 57 if (proximityToNextInt <= 0.01 && value > 0)
59 return static_cast<float>(ceiledValue); 58 return static_cast<float>(ceiledValue);
60 if (proximityToNextInt >= 0.99 && value < 0) 59 if (proximityToNextInt >= 0.99 && value < 0)
61 return static_cast<float>(floor(value)); 60 return static_cast<float>(floor(value));
62 return static_cast<float>(value); 61 return static_cast<float>(value);
63 } 62 }
64 63
65 // CSSPrimitiveValues are immutable. This class has manual ref-counting 64 // CSSPrimitiveValue stores numeric data types (e.g. 1, 10px, 4%) and calc()
66 // of unioned types and does not have the code necessary 65 // values (e.g. calc(3px + 2em)).
67 // to handle any kind of mutations.
68 class CORE_EXPORT CSSPrimitiveValue : public CSSValue { 66 class CORE_EXPORT CSSPrimitiveValue : public CSSValue {
69 public: 67 public:
70 // These units are iterated through, so be careful when adding or changing the order. 68 // These units are iterated through, so be careful when adding or changing the order.
71 enum class UnitType { 69 enum class UnitType {
72 Unknown, 70 Unknown,
73 Number, 71 Number,
74 Percentage, 72 Percentage,
75 // Length units 73 // Length units
76 Ems, 74 Ems,
77 Exs, 75 Exs,
(...skipping 25 matching lines...) Expand all
103 DotsPerInch, 101 DotsPerInch,
104 DotsPerCentimeter, 102 DotsPerCentimeter,
105 // Other units 103 // Other units
106 Fraction, 104 Fraction,
107 Integer, 105 Integer,
108 Calc, 106 Calc,
109 CalcPercentageWithNumber, 107 CalcPercentageWithNumber,
110 CalcPercentageWithLength, 108 CalcPercentageWithLength,
111 CalcLengthWithNumber, 109 CalcLengthWithNumber,
112 CalcPercentageWithLengthAndNumber, 110 CalcPercentageWithLengthAndNumber,
113 ValueID,
114 111
115 // This value is used to handle quirky margins in reflow roots (body, td, an d th) like WinIE. 112 // This value is used to handle quirky margins in reflow roots (body, td, an d th) like WinIE.
116 // The basic idea is that a stylesheet can use the value __qem (for quirky e m) instead of em. 113 // The basic idea is that a stylesheet can use the value __qem (for quirky e m) instead of em.
117 // When the quirky value is used, if you're in quirks mode, the margin will collapse away 114 // When the quirky value is used, if you're in quirks mode, the margin will collapse away
118 // inside a table cell. This quirk is specified in the HTML spec but our imp l is different. 115 // inside a table cell. This quirk is specified in the HTML spec but our imp l is different.
119 // TODO: Remove this. crbug.com/443952 116 // TODO: Remove this. crbug.com/443952
120 QuirkyEms, 117 QuirkyEms,
121 }; 118 };
122 119
123 enum LengthUnitType { 120 enum LengthUnitType {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 return typeWithCalcResolved() == UnitType::CalcPercentageWithNumber; 200 return typeWithCalcResolved() == UnitType::CalcPercentageWithNumber;
204 } 201 }
205 bool isCalculatedPercentageWithLength() const { 202 bool isCalculatedPercentageWithLength() const {
206 return typeWithCalcResolved() == UnitType::CalcPercentageWithLength; 203 return typeWithCalcResolved() == UnitType::CalcPercentageWithLength;
207 } 204 }
208 static bool isResolution(UnitType type) { 205 static bool isResolution(UnitType type) {
209 return type >= UnitType::DotsPerPixel && 206 return type >= UnitType::DotsPerPixel &&
210 type <= UnitType::DotsPerCentimeter; 207 type <= UnitType::DotsPerCentimeter;
211 } 208 }
212 bool isFlex() const { return typeWithCalcResolved() == UnitType::Fraction; } 209 bool isFlex() const { return typeWithCalcResolved() == UnitType::Fraction; }
213 bool isValueID() const { return type() == UnitType::ValueID; }
214 bool colorIsDerivedFromElement() const;
215 210
216 static CSSPrimitiveValue* createIdentifier(CSSValueID);
217 static CSSPrimitiveValue* create(double value, UnitType); 211 static CSSPrimitiveValue* create(double value, UnitType);
218 static CSSPrimitiveValue* create(const Length& value, float zoom) { 212 static CSSPrimitiveValue* create(const Length& value, float zoom) {
219 return new CSSPrimitiveValue(value, zoom); 213 return new CSSPrimitiveValue(value, zoom);
220 } 214 }
215
216 // TODO(sashab): Remove this.
221 template <typename T> 217 template <typename T>
222 static CSSPrimitiveValue* create(T value) { 218 static CSSPrimitiveValue* create(T value) {
223 static_assert(!std::is_same<T, CSSValueID>::value,
224 "Do not call create() with a CSSValueID; call "
225 "createIdentifier() instead");
226 return new CSSPrimitiveValue(value); 219 return new CSSPrimitiveValue(value);
227 } 220 }
228 221
229 ~CSSPrimitiveValue(); 222 ~CSSPrimitiveValue();
230 223
231 UnitType typeWithCalcResolved() const; 224 UnitType typeWithCalcResolved() const;
232 225
233 double computeDegrees() const; 226 double computeDegrees() const;
234 double computeSeconds() const; 227 double computeSeconds() const;
235 228
(...skipping 10 matching lines...) Expand all
246 template <typename T> 239 template <typename T>
247 inline T getValue() const { 240 inline T getValue() const {
248 return clampTo<T>(getDoubleValue()); 241 return clampTo<T>(getDoubleValue());
249 } 242 }
250 243
251 CSSCalcValue* cssCalcValue() const { 244 CSSCalcValue* cssCalcValue() const {
252 ASSERT(isCalculated()); 245 ASSERT(isCalculated());
253 return m_value.calc; 246 return m_value.calc;
254 } 247 }
255 248
256 CSSValueID getValueID() const {
257 return type() == UnitType::ValueID ? m_value.valueID : CSSValueInvalid;
258 }
259
260 template <typename T> 249 template <typename T>
261 inline T convertTo() const; // Defined in CSSPrimitiveValueMappings.h 250 inline T convertTo() const; // Defined in CSSPrimitiveValueMappings.h
262 251
263 static const char* unitTypeToString(UnitType); 252 static const char* unitTypeToString(UnitType);
264 static UnitType stringToUnitType(StringView string) { 253 static UnitType stringToUnitType(StringView string) {
265 if (string.is8Bit()) 254 if (string.is8Bit())
266 return stringToUnitType(string.characters8(), string.length()); 255 return stringToUnitType(string.characters8(), string.length());
267 return stringToUnitType(string.characters16(), string.length()); 256 return stringToUnitType(string.characters16(), string.length());
268 } 257 }
269 258
270 String customCSSText() const; 259 String customCSSText() const;
271 260
272 bool equals(const CSSPrimitiveValue&) const; 261 bool equals(const CSSPrimitiveValue&) const;
273 262
274 DECLARE_TRACE_AFTER_DISPATCH(); 263 DECLARE_TRACE_AFTER_DISPATCH();
275 264
276 static UnitType canonicalUnitTypeForCategory(UnitCategory); 265 static UnitType canonicalUnitTypeForCategory(UnitCategory);
277 static double conversionToCanonicalUnitsScaleFactor(UnitType); 266 static double conversionToCanonicalUnitsScaleFactor(UnitType);
278 267
279 // Returns true and populates lengthUnitType, if unitType is a length unit. Ot herwise, returns false. 268 // Returns true and populates lengthUnitType, if unitType is a length unit. Ot herwise, returns false.
280 static bool unitTypeToLengthUnitType(UnitType, LengthUnitType&); 269 static bool unitTypeToLengthUnitType(UnitType, LengthUnitType&);
281 static UnitType lengthUnitTypeToUnitType(LengthUnitType); 270 static UnitType lengthUnitTypeToUnitType(LengthUnitType);
282 271
283 private: 272 private:
284 CSSPrimitiveValue(CSSValueID);
285 CSSPrimitiveValue(const Length&, float zoom); 273 CSSPrimitiveValue(const Length&, float zoom);
286 CSSPrimitiveValue(double, UnitType); 274 CSSPrimitiveValue(double, UnitType);
287 275
288 template <typename T> 276 template <typename T>
289 CSSPrimitiveValue(T); // Defined in CSSPrimitiveValueMappings.h 277 CSSPrimitiveValue(T); // Defined in CSSPrimitiveValueMappings.h
290 278
291 template <typename T> 279 template <typename T>
292 CSSPrimitiveValue(T* val) : CSSValue(PrimitiveClass) { 280 CSSPrimitiveValue(T* val) : CSSValue(PrimitiveClass) {
293 init(val); 281 init(val);
294 } 282 }
(...skipping 11 matching lines...) Expand all
306 void init(const Length&); 294 void init(const Length&);
307 void init(CSSCalcValue*); 295 void init(CSSCalcValue*);
308 296
309 double computeLengthDouble(const CSSToLengthConversionData&) const; 297 double computeLengthDouble(const CSSToLengthConversionData&) const;
310 298
311 inline UnitType type() const { 299 inline UnitType type() const {
312 return static_cast<UnitType>(m_primitiveUnitType); 300 return static_cast<UnitType>(m_primitiveUnitType);
313 } 301 }
314 302
315 union { 303 union {
316 CSSValueID valueID;
317 double num; 304 double num;
318 // FIXME: oilpan: Should be a member, but no support for members in unions. Just trace the raw ptr for now. 305 // FIXME: oilpan: Should be a member, but no support for members in unions. Just trace the raw ptr for now.
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 311
325 DEFINE_CSS_VALUE_TYPE_CASTS(CSSPrimitiveValue, isPrimitiveValue()); 312 DEFINE_CSS_VALUE_TYPE_CASTS(CSSPrimitiveValue, isPrimitiveValue());
326 313
327 } // namespace blink 314 } // namespace blink
328 315
329 #endif // CSSPrimitiveValue_h 316 #endif // CSSPrimitiveValue_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSMatrix.cpp ('k') | third_party/WebKit/Source/core/css/CSSPrimitiveValue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698