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

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

Issue 2051313002: Encapsulate the CSSPrimitiveValue UnitType trie bethind a method that takes a StringView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 14 matching lines...) Expand all
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/PassRefPtr.h" 32 #include "wtf/PassRefPtr.h"
33 #include "wtf/TypeTraits.h" 33 #include "wtf/TypeTraits.h"
34 #include "wtf/text/StringHash.h" 34 #include "wtf/text/StringHash.h"
35 #include "wtf/text/StringView.h"
35 36
36 namespace blink { 37 namespace blink {
37 38
38 class CSSCalcValue; 39 class CSSCalcValue;
39 class CSSToLengthConversionData; 40 class CSSToLengthConversionData;
40 class Length; 41 class Length;
41 class ComputedStyle; 42 class ComputedStyle;
42 43
43 // Dimension calculations are imprecise, often resulting in values of e.g. 44 // Dimension calculations are imprecise, often resulting in values of e.g.
44 // 44.99998. We need to go ahead and round if we're really close to the next 45 // 44.99998. We need to go ahead and round if we're really close to the next
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 int getIntValue() const { return getValue<int>(); } 238 int getIntValue() const { return getValue<int>(); }
238 template<typename T> inline T getValue() const { return clampTo<T>(getDouble Value()); } 239 template<typename T> inline T getValue() const { return clampTo<T>(getDouble Value()); }
239 240
240 CSSCalcValue* cssCalcValue() const { ASSERT(isCalculated()); return m_value. calc; } 241 CSSCalcValue* cssCalcValue() const { ASSERT(isCalculated()); return m_value. calc; }
241 242
242 CSSValueID getValueID() const { return type() == UnitType::ValueID ? m_value .valueID : CSSValueInvalid; } 243 CSSValueID getValueID() const { return type() == UnitType::ValueID ? m_value .valueID : CSSValueInvalid; }
243 244
244 template<typename T> inline T convertTo() const; // Defined in CSSPrimitiveV alueMappings.h 245 template<typename T> inline T convertTo() const; // Defined in CSSPrimitiveV alueMappings.h
245 246
246 static const char* unitTypeToString(UnitType); 247 static const char* unitTypeToString(UnitType);
248 static UnitType stringToUnitType(StringView string)
249 {
250 if (string.is8Bit())
251 return stringToUnitType(string.characters8(), string.length());
252 return stringToUnitType(string.characters16(), string.length());
253 }
254
247 String customCSSText() const; 255 String customCSSText() const;
248 256
249 bool equals(const CSSPrimitiveValue&) const; 257 bool equals(const CSSPrimitiveValue&) const;
250 258
251 DECLARE_TRACE_AFTER_DISPATCH(); 259 DECLARE_TRACE_AFTER_DISPATCH();
252 260
253 static UnitType canonicalUnitTypeForCategory(UnitCategory); 261 static UnitType canonicalUnitTypeForCategory(UnitCategory);
254 static double conversionToCanonicalUnitsScaleFactor(UnitType); 262 static double conversionToCanonicalUnitsScaleFactor(UnitType);
255 263
256 // Returns true and populates lengthUnitType, if unitType is a length unit. Otherwise, returns false. 264 // Returns true and populates lengthUnitType, if unitType is a length unit. Otherwise, returns false.
(...skipping 10 matching lines...) Expand all
267 template<typename T> CSSPrimitiveValue(T* val) 275 template<typename T> CSSPrimitiveValue(T* val)
268 : CSSValue(PrimitiveClass) 276 : CSSValue(PrimitiveClass)
269 { 277 {
270 init(val); 278 init(val);
271 } 279 }
272 280
273 static void create(int); // compile-time guard 281 static void create(int); // compile-time guard
274 static void create(unsigned); // compile-time guard 282 static void create(unsigned); // compile-time guard
275 template<typename T> operator T*(); // compile-time guard 283 template<typename T> operator T*(); // compile-time guard
276 284
285 // Code generated by CSSPrimitiveValueUnitTrie.cpp.tmpl
286 static UnitType stringToUnitType(const LChar*, unsigned length);
287 static UnitType stringToUnitType(const UChar*, unsigned length);
288
277 void init(UnitType); 289 void init(UnitType);
278 void init(const Length&); 290 void init(const Length&);
279 void init(CSSCalcValue*); 291 void init(CSSCalcValue*);
280 292
281 double computeLengthDouble(const CSSToLengthConversionData&) const; 293 double computeLengthDouble(const CSSToLengthConversionData&) const;
282 294
283 inline UnitType type() const { return static_cast<UnitType>(m_primitiveUnitT ype); } 295 inline UnitType type() const { return static_cast<UnitType>(m_primitiveUnitT ype); }
284 296
285 union { 297 union {
286 CSSValueID valueID; 298 CSSValueID valueID;
287 double num; 299 double num;
288 // FIXME: oilpan: Should be a member, but no support for members in unio ns. Just trace the raw ptr for now. 300 // FIXME: oilpan: Should be a member, but no support for members in unio ns. Just trace the raw ptr for now.
289 CSSCalcValue* calc; 301 CSSCalcValue* calc;
290 } m_value; 302 } m_value;
291 }; 303 };
292 304
293 using CSSLengthArray = CSSPrimitiveValue::CSSLengthArray; 305 using CSSLengthArray = CSSPrimitiveValue::CSSLengthArray;
294 306
295 DEFINE_CSS_VALUE_TYPE_CASTS(CSSPrimitiveValue, isPrimitiveValue()); 307 DEFINE_CSS_VALUE_TYPE_CASTS(CSSPrimitiveValue, isPrimitiveValue());
296 308
297 } // namespace blink 309 } // namespace blink
298 310
299 #endif // CSSPrimitiveValue_h 311 #endif // CSSPrimitiveValue_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/core.gypi ('k') | third_party/WebKit/Source/core/css/CSSPrimitiveValueUnitTrie.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698