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

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

Issue 1192983003: CSS Custom Properties (Variables) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Post-merge Created 5 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 | Annotate | Revision Log
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 20 matching lines...) Expand all
31 #include "wtf/Forward.h" 31 #include "wtf/Forward.h"
32 #include "wtf/MathExtras.h" 32 #include "wtf/MathExtras.h"
33 #include "wtf/PassRefPtr.h" 33 #include "wtf/PassRefPtr.h"
34 #include "wtf/text/StringHash.h" 34 #include "wtf/text/StringHash.h"
35 35
36 namespace blink { 36 namespace blink {
37 37
38 class CSSBasicShape; 38 class CSSBasicShape;
39 class CSSCalcValue; 39 class CSSCalcValue;
40 class CSSToLengthConversionData; 40 class CSSToLengthConversionData;
41 class CSSVariableData;
41 class Length; 42 class Length;
42 class RGBColor; 43 class RGBColor;
43 class ComputedStyle; 44 class ComputedStyle;
44 45
45 // Dimension calculations are imprecise, often resulting in values of e.g. 46 // Dimension calculations are imprecise, often resulting in values of e.g.
46 // 44.99998. We need to go ahead and round if we're really close to the next 47 // 44.99998. We need to go ahead and round if we're really close to the next
47 // integer value. 48 // integer value.
48 template<typename T> inline T roundForImpreciseConversion(double value) 49 template<typename T> inline T roundForImpreciseConversion(double value)
49 { 50 {
50 value += (value < 0) ? -0.01 : +0.01; 51 value += (value < 0) ? -0.01 : +0.01;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 String, 109 String,
109 PropertyID, 110 PropertyID,
110 ValueID, 111 ValueID,
111 112
112 // This value is used to handle quirky margins in reflow roots (body, td , and th) like WinIE. 113 // 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. 114 // 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 115 // 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. 116 // inside a table cell. This quirk is specified in the HTML spec but our impl is different.
116 // TODO: Remove this. crbug.com/443952 117 // TODO: Remove this. crbug.com/443952
117 QuirkyEms, 118 QuirkyEms,
119 VariableReference,
Timothy Loh 2015/09/30 02:09:27 I think we aren't adding any more random types to
118 }; 120 };
119 121
120 enum LengthUnitType { 122 enum LengthUnitType {
121 UnitTypePixels = 0, 123 UnitTypePixels = 0,
122 UnitTypePercentage, 124 UnitTypePercentage,
123 UnitTypeFontSize, 125 UnitTypeFontSize,
124 UnitTypeFontXSize, 126 UnitTypeFontXSize,
125 UnitTypeRootFontSize, 127 UnitTypeRootFontSize,
126 UnitTypeZeroCharacterWidth, 128 UnitTypeZeroCharacterWidth,
127 UnitTypeViewportWidth, 129 UnitTypeViewportWidth,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 bool isNumber() const { return typeWithCalcResolved() == UnitType::Number || typeWithCalcResolved() == UnitType::Integer; } 185 bool isNumber() const { return typeWithCalcResolved() == UnitType::Number || typeWithCalcResolved() == UnitType::Integer; }
184 bool isPercentage() const { return typeWithCalcResolved() == UnitType::Perce ntage; } 186 bool isPercentage() const { return typeWithCalcResolved() == UnitType::Perce ntage; }
185 bool isPropertyID() const { return type() == UnitType::PropertyID; } 187 bool isPropertyID() const { return type() == UnitType::PropertyID; }
186 bool isPx() const { return typeWithCalcResolved() == UnitType::Pixels; } 188 bool isPx() const { return typeWithCalcResolved() == UnitType::Pixels; }
187 bool isRGBColor() const { return type() == UnitType::RGBColor; } 189 bool isRGBColor() const { return type() == UnitType::RGBColor; }
188 bool isShape() const { return type() == UnitType::Shape; } 190 bool isShape() const { return type() == UnitType::Shape; }
189 bool isString() const { return type() == UnitType::String; } 191 bool isString() const { return type() == UnitType::String; }
190 bool isTime() const { return type() == UnitType::Seconds || type() == UnitTy pe::Milliseconds; } 192 bool isTime() const { return type() == UnitType::Seconds || type() == UnitTy pe::Milliseconds; }
191 bool isURI() const { return type() == UnitType::URI; } 193 bool isURI() const { return type() == UnitType::URI; }
192 bool isCalculated() const { return type() == UnitType::Calc; } 194 bool isCalculated() const { return type() == UnitType::Calc; }
195 bool isVariableReference() const { return type() == UnitType::VariableRefere nce; }
193 bool isCalculatedPercentageWithNumber() const { return typeWithCalcResolved( ) == UnitType::CalcPercentageWithNumber; } 196 bool isCalculatedPercentageWithNumber() const { return typeWithCalcResolved( ) == UnitType::CalcPercentageWithNumber; }
194 bool isCalculatedPercentageWithLength() const { return typeWithCalcResolved( ) == UnitType::CalcPercentageWithLength; } 197 bool isCalculatedPercentageWithLength() const { return typeWithCalcResolved( ) == UnitType::CalcPercentageWithLength; }
195 static bool isDotsPerInch(UnitType type) { return type == UnitType::DotsPerI nch; } 198 static bool isDotsPerInch(UnitType type) { return type == UnitType::DotsPerI nch; }
196 static bool isDotsPerPixel(UnitType type) { return type == UnitType::DotsPer Pixel; } 199 static bool isDotsPerPixel(UnitType type) { return type == UnitType::DotsPer Pixel; }
197 static bool isDotsPerCentimeter(UnitType type) { return type == UnitType::Do tsPerCentimeter; } 200 static bool isDotsPerCentimeter(UnitType type) { return type == UnitType::Do tsPerCentimeter; }
198 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; }
199 bool isFlex() const { return typeWithCalcResolved() == UnitType::Fraction; } 202 bool isFlex() const { return typeWithCalcResolved() == UnitType::Fraction; }
200 bool isValueID() const { return type() == UnitType::ValueID; } 203 bool isValueID() const { return type() == UnitType::ValueID; }
201 bool colorIsDerivedFromElement() const; 204 bool colorIsDerivedFromElement() const;
202 205
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 int getIntValue() const { return getValue<int>(); } 252 int getIntValue() const { return getValue<int>(); }
250 template<typename T> inline T getValue() const { return clampTo<T>(getDouble Value()); } 253 template<typename T> inline T getValue() const { return clampTo<T>(getDouble Value()); }
251 254
252 String getStringValue() const; 255 String getStringValue() const;
253 RGBA32 getRGBA32Value() const { ASSERT(isRGBColor()); return m_value.rgbcolo r; } 256 RGBA32 getRGBA32Value() const { ASSERT(isRGBColor()); return m_value.rgbcolo r; }
254 257
255 CSSBasicShape* getShapeValue() const { ASSERT(isShape()); return m_value.sha pe; } 258 CSSBasicShape* getShapeValue() const { ASSERT(isShape()); return m_value.sha pe; }
256 CSSCalcValue* cssCalcValue() const { ASSERT(isCalculated()); return m_value. calc; } 259 CSSCalcValue* cssCalcValue() const { ASSERT(isCalculated()); return m_value. calc; }
257 CSSPropertyID getPropertyID() const { ASSERT(isPropertyID()); return m_value .propertyID; } 260 CSSPropertyID getPropertyID() const { ASSERT(isPropertyID()); return m_value .propertyID; }
258 261
262 CSSVariableData* getVariableDataValue() const
263 {
264 ASSERT(type() == UnitType::VariableReference);
265 return m_value.variableData;
266 }
267
259 CSSValueID getValueID() const { return type() == UnitType::ValueID ? m_value .valueID : CSSValueInvalid; } 268 CSSValueID getValueID() const { return type() == UnitType::ValueID ? m_value .valueID : CSSValueInvalid; }
260 269
261 template<typename T> inline operator T() const; // Defined in CSSPrimitiveVa lueMappings.h 270 template<typename T> inline operator T() const; // Defined in CSSPrimitiveVa lueMappings.h
262 271
263 static const char* unitTypeToString(UnitType); 272 static const char* unitTypeToString(UnitType);
264 String customCSSText() const; 273 String customCSSText() const;
265 274
266 bool equals(const CSSPrimitiveValue&) const; 275 bool equals(const CSSPrimitiveValue&) const;
267 276
268 DECLARE_TRACE_AFTER_DISPATCH(); 277 DECLARE_TRACE_AFTER_DISPATCH();
(...skipping 27 matching lines...) Expand all
296 } 305 }
297 306
298 static void create(int); // compile-time guard 307 static void create(int); // compile-time guard
299 static void create(unsigned); // compile-time guard 308 static void create(unsigned); // compile-time guard
300 template<typename T> operator T*(); // compile-time guard 309 template<typename T> operator T*(); // compile-time guard
301 310
302 void init(UnitType); 311 void init(UnitType);
303 void init(const Length&); 312 void init(const Length&);
304 void init(PassRefPtrWillBeRawPtr<CSSBasicShape>); 313 void init(PassRefPtrWillBeRawPtr<CSSBasicShape>);
305 void init(PassRefPtrWillBeRawPtr<CSSCalcValue>); 314 void init(PassRefPtrWillBeRawPtr<CSSCalcValue>);
315 void init(PassRefPtrWillBeRawPtr<CSSVariableData>);
306 316
307 double computeLengthDouble(const CSSToLengthConversionData&) const; 317 double computeLengthDouble(const CSSToLengthConversionData&) const;
308 318
309 inline UnitType type() const { return static_cast<UnitType>(m_primitiveUnitT ype); } 319 inline UnitType type() const { return static_cast<UnitType>(m_primitiveUnitT ype); }
310 320
311 union { 321 union {
312 CSSPropertyID propertyID; 322 CSSPropertyID propertyID;
313 CSSValueID valueID; 323 CSSValueID valueID;
314 double num; 324 double num;
315 StringImpl* string; 325 StringImpl* string;
316 RGBA32 rgbcolor; 326 RGBA32 rgbcolor;
317 // FIXME: oilpan: Should be members, but no support for members in union s. Just trace the raw ptr for now. 327 // FIXME: oilpan: Should be members, but no support for members in union s. Just trace the raw ptr for now.
318 CSSBasicShape* shape; 328 CSSBasicShape* shape;
319 CSSCalcValue* calc; 329 CSSCalcValue* calc;
330 CSSVariableData* variableData;
320 } m_value; 331 } m_value;
321 }; 332 };
322 333
323 using CSSLengthArray = CSSPrimitiveValue::CSSLengthArray; 334 using CSSLengthArray = CSSPrimitiveValue::CSSLengthArray;
324 using CSSLengthTypeArray = CSSPrimitiveValue::CSSLengthTypeArray; 335 using CSSLengthTypeArray = CSSPrimitiveValue::CSSLengthTypeArray;
325 336
326 DEFINE_CSS_VALUE_TYPE_CASTS(CSSPrimitiveValue, isPrimitiveValue()); 337 DEFINE_CSS_VALUE_TYPE_CASTS(CSSPrimitiveValue, isPrimitiveValue());
327 338
328 } // namespace blink 339 } // namespace blink
329 340
330 #endif // CSSPrimitiveValue_h 341 #endif // CSSPrimitiveValue_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698