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

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

Issue 1192983003: CSS Custom Properties (Variables) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: with missing files Created 5 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 | 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 Counter; 42 class Counter;
42 class Length; 43 class Length;
43 class LengthSize; 44 class LengthSize;
44 class Pair; 45 class Pair;
45 class Quad; 46 class Quad;
46 class RGBColor; 47 class RGBColor;
47 class Rect; 48 class Rect;
48 class ComputedStyle; 49 class ComputedStyle;
49 50
50 // Dimension calculations are imprecise, often resulting in values of e.g. 51 // Dimension calculations are imprecise, often resulting in values of e.g.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 CSS_REMS = 108, 112 CSS_REMS = 108,
112 CSS_CHS = 109, 113 CSS_CHS = 109,
113 CSS_SHAPE = 111, 114 CSS_SHAPE = 111,
114 CSS_QUAD = 112, 115 CSS_QUAD = 112,
115 CSS_CALC = 113, 116 CSS_CALC = 113,
116 CSS_CALC_PERCENTAGE_WITH_NUMBER = 114, 117 CSS_CALC_PERCENTAGE_WITH_NUMBER = 114,
117 CSS_CALC_PERCENTAGE_WITH_LENGTH = 115, 118 CSS_CALC_PERCENTAGE_WITH_LENGTH = 115,
118 CSS_STRING = 116, 119 CSS_STRING = 116,
119 CSS_PROPERTY_ID = 117, 120 CSS_PROPERTY_ID = 117,
120 CSS_VALUE_ID = 118, 121 CSS_VALUE_ID = 118,
121 CSS_QEM = 119 122 CSS_QEM = 119,
123 CSS_VARIABLE_REFERENCE = 120
122 }; 124 };
123 125
124 enum LengthUnitType { 126 enum LengthUnitType {
125 UnitTypePixels = 0, 127 UnitTypePixels = 0,
126 UnitTypePercentage, 128 UnitTypePercentage,
127 UnitTypeFontSize, 129 UnitTypeFontSize,
128 UnitTypeFontXSize, 130 UnitTypeFontXSize,
129 UnitTypeRootFontSize, 131 UnitTypeRootFontSize,
130 UnitTypeZeroCharacterWidth, 132 UnitTypeZeroCharacterWidth,
131 UnitTypeViewportWidth, 133 UnitTypeViewportWidth,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 bool isAttr() const { return m_primitiveUnitType == CSS_ATTR; } 172 bool isAttr() const { return m_primitiveUnitType == CSS_ATTR; }
171 bool isCounter() const { return m_primitiveUnitType == CSS_COUNTER; } 173 bool isCounter() const { return m_primitiveUnitType == CSS_COUNTER; }
172 bool isCustomIdent() const { return m_primitiveUnitType == CSS_CUSTOM_IDENT; } 174 bool isCustomIdent() const { return m_primitiveUnitType == CSS_CUSTOM_IDENT; }
173 bool isFontRelativeLength() const 175 bool isFontRelativeLength() const
174 { 176 {
175 return m_primitiveUnitType == CSS_EMS 177 return m_primitiveUnitType == CSS_EMS
176 || m_primitiveUnitType == CSS_EXS 178 || m_primitiveUnitType == CSS_EXS
177 || m_primitiveUnitType == CSS_REMS 179 || m_primitiveUnitType == CSS_REMS
178 || m_primitiveUnitType == CSS_CHS; 180 || m_primitiveUnitType == CSS_CHS;
179 } 181 }
182 bool isVariableReference() const { return primitiveType() == CSS_VARIABLE_RE FERENCE; }
180 bool isViewportPercentageLength() const { return isViewportPercentageLength( static_cast<UnitType>(m_primitiveUnitType)); } 183 bool isViewportPercentageLength() const { return isViewportPercentageLength( static_cast<UnitType>(m_primitiveUnitType)); }
181 static bool isViewportPercentageLength(UnitType type) { return type >= CSS_V W && type <= CSS_VMAX; } 184 static bool isViewportPercentageLength(UnitType type) { return type >= CSS_V W && type <= CSS_VMAX; }
182 static bool isLength(UnitType type) 185 static bool isLength(UnitType type)
183 { 186 {
184 return (type >= CSS_EMS && type <= CSS_PC) || type == CSS_REMS || type = = CSS_CHS || isViewportPercentageLength(type); 187 return (type >= CSS_EMS && type <= CSS_PC) || type == CSS_REMS || type = = CSS_CHS || isViewportPercentageLength(type);
185 } 188 }
186 bool isLength() const { return isLength(primitiveType()); } 189 bool isLength() const { return isLength(primitiveType()); }
187 bool isNumber() const { return primitiveType() == CSS_NUMBER; } 190 bool isNumber() const { return primitiveType() == CSS_NUMBER; }
188 bool isPercentage() const { return primitiveType() == CSS_PERCENTAGE; } 191 bool isPercentage() const { return primitiveType() == CSS_PERCENTAGE; }
189 bool isPx() const { return primitiveType() == CSS_PX; } 192 bool isPx() const { return primitiveType() == CSS_PX; }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, type)); 228 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, type));
226 } 229 }
227 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const Length& value, float zoom) 230 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const Length& value, float zoom)
228 { 231 {
229 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, zoom)); 232 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, zoom));
230 } 233 }
231 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const LengthSize& va lue, const ComputedStyle& style) 234 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const LengthSize& va lue, const ComputedStyle& style)
232 { 235 {
233 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, style)); 236 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, style));
234 } 237 }
238 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(CSSVariableData* val ue)
239 {
240 return adoptRefWillBeNoop(new CSSPrimitiveValue(value));
241 }
235 template<typename T> static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create (T value) 242 template<typename T> static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create (T value)
236 { 243 {
237 return adoptRefWillBeNoop(new CSSPrimitiveValue(value)); 244 return adoptRefWillBeNoop(new CSSPrimitiveValue(value));
238 } 245 }
239 246
240 // This value is used to handle quirky margins in reflow roots (body, td, an d th) like WinIE. 247 // This value is used to handle quirky margins in reflow roots (body, td, an d th) like WinIE.
241 // The basic idea is that a stylesheet can use the value __qem (for quirky e m) instead of em. 248 // The basic idea is that a stylesheet can use the value __qem (for quirky e m) instead of em.
242 // When the quirky value is used, if you're in quirks mode, the margin will collapse away 249 // When the quirky value is used, if you're in quirks mode, the margin will collapse away
243 // inside a table cell. 250 // inside a table cell.
244 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createAllowingMarginQuirk(d ouble value, UnitType type) 251 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createAllowingMarginQuirk(d ouble value, UnitType type)
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 Quad* getQuadValue() const { return m_primitiveUnitType != CSS_QUAD ? 0 : m_ value.quad; } 284 Quad* getQuadValue() const { return m_primitiveUnitType != CSS_QUAD ? 0 : m_ value.quad; }
278 285
279 RGBA32 getRGBA32Value() const { return m_primitiveUnitType != CSS_RGBCOLOR ? 0 : m_value.rgbcolor; } 286 RGBA32 getRGBA32Value() const { return m_primitiveUnitType != CSS_RGBCOLOR ? 0 : m_value.rgbcolor; }
280 287
281 Pair* getPairValue() const { return m_primitiveUnitType != CSS_PAIR ? 0 : m_ value.pair; } 288 Pair* getPairValue() const { return m_primitiveUnitType != CSS_PAIR ? 0 : m_ value.pair; }
282 289
283 CSSBasicShape* getShapeValue() const { return m_primitiveUnitType != CSS_SHA PE ? 0 : m_value.shape; } 290 CSSBasicShape* getShapeValue() const { return m_primitiveUnitType != CSS_SHA PE ? 0 : m_value.shape; }
284 291
285 CSSCalcValue* cssCalcValue() const { return m_primitiveUnitType != CSS_CALC ? 0 : m_value.calc; } 292 CSSCalcValue* cssCalcValue() const { return m_primitiveUnitType != CSS_CALC ? 0 : m_value.calc; }
286 293
294 CSSVariableData* getVariableDataValue() const { return m_primitiveUnitType ! = CSS_VARIABLE_REFERENCE ? 0 : m_value.variableData; }
295
287 CSSPropertyID getPropertyID() const { return m_primitiveUnitType == CSS_PROP ERTY_ID ? m_value.propertyID : CSSPropertyInvalid; } 296 CSSPropertyID getPropertyID() const { return m_primitiveUnitType == CSS_PROP ERTY_ID ? m_value.propertyID : CSSPropertyInvalid; }
288 CSSValueID getValueID() const { return m_primitiveUnitType == CSS_VALUE_ID ? m_value.valueID : CSSValueInvalid; } 297 CSSValueID getValueID() const { return m_primitiveUnitType == CSS_VALUE_ID ? m_value.valueID : CSSValueInvalid; }
289 298
290 template<typename T> inline operator T() const; // Defined in CSSPrimitiveVa lueMappings.h 299 template<typename T> inline operator T() const; // Defined in CSSPrimitiveVa lueMappings.h
291 300
292 static const char* unitTypeToString(UnitType); 301 static const char* unitTypeToString(UnitType);
293 String customCSSText() const; 302 String customCSSText() const;
294 303
295 bool isQuirkValue() { return m_isQuirkValue; } 304 bool isQuirkValue() { return m_isQuirkValue; }
296 305
297 bool equals(const CSSPrimitiveValue&) const; 306 bool equals(const CSSPrimitiveValue&) const;
298 307
299 DECLARE_TRACE_AFTER_DISPATCH(); 308 DECLARE_TRACE_AFTER_DISPATCH();
300 309
301 static UnitType canonicalUnitTypeForCategory(UnitCategory); 310 static UnitType canonicalUnitTypeForCategory(UnitCategory);
302 static double conversionToCanonicalUnitsScaleFactor(UnitType); 311 static double conversionToCanonicalUnitsScaleFactor(UnitType);
303 312
304 // Returns true and populates lengthUnitType, if unitType is a length unit. Otherwise, returns false. 313 // Returns true and populates lengthUnitType, if unitType is a length unit. Otherwise, returns false.
305 static bool unitTypeToLengthUnitType(UnitType, LengthUnitType&); 314 static bool unitTypeToLengthUnitType(UnitType, LengthUnitType&);
306 static UnitType lengthUnitTypeToUnitType(LengthUnitType); 315 static UnitType lengthUnitTypeToUnitType(LengthUnitType);
307 316
308 private: 317 private:
309 CSSPrimitiveValue(CSSValueID); 318 CSSPrimitiveValue(CSSValueID);
310 CSSPrimitiveValue(CSSPropertyID); 319 CSSPrimitiveValue(CSSPropertyID);
311 CSSPrimitiveValue(RGBA32 color); 320 CSSPrimitiveValue(RGBA32 color);
312 CSSPrimitiveValue(const Length&, float zoom); 321 CSSPrimitiveValue(const Length&, float zoom);
313 CSSPrimitiveValue(const LengthSize&, const ComputedStyle&); 322 CSSPrimitiveValue(const LengthSize&, const ComputedStyle&);
314 CSSPrimitiveValue(const String&, UnitType); 323 CSSPrimitiveValue(const String&, UnitType);
315 CSSPrimitiveValue(double, UnitType); 324 CSSPrimitiveValue(double, UnitType);
325 CSSPrimitiveValue(CSSVariableData*);
316 326
317 template<typename T> CSSPrimitiveValue(T); // Defined in CSSPrimitiveValueMa ppings.h 327 template<typename T> CSSPrimitiveValue(T); // Defined in CSSPrimitiveValueMa ppings.h
318 template<typename T> CSSPrimitiveValue(T* val) 328 template<typename T> CSSPrimitiveValue(T* val)
319 : CSSValue(PrimitiveClass) 329 : CSSValue(PrimitiveClass)
320 { 330 {
321 init(PassRefPtrWillBeRawPtr<T>(val)); 331 init(PassRefPtrWillBeRawPtr<T>(val));
322 } 332 }
323 333
324 template<typename T> CSSPrimitiveValue(PassRefPtrWillBeRawPtr<T> val) 334 template<typename T> CSSPrimitiveValue(PassRefPtrWillBeRawPtr<T> val)
325 : CSSValue(PrimitiveClass) 335 : CSSValue(PrimitiveClass)
(...skipping 22 matching lines...) Expand all
348 double num; 358 double num;
349 StringImpl* string; 359 StringImpl* string;
350 RGBA32 rgbcolor; 360 RGBA32 rgbcolor;
351 // FIXME: oilpan: Should be members, but no support for members in union s. Just trace the raw ptr for now. 361 // FIXME: oilpan: Should be members, but no support for members in union s. Just trace the raw ptr for now.
352 CSSBasicShape* shape; 362 CSSBasicShape* shape;
353 CSSCalcValue* calc; 363 CSSCalcValue* calc;
354 Counter* counter; 364 Counter* counter;
355 Pair* pair; 365 Pair* pair;
356 Rect* rect; 366 Rect* rect;
357 Quad* quad; 367 Quad* quad;
368 CSSVariableData* variableData;
358 } m_value; 369 } m_value;
359 }; 370 };
360 371
361 typedef CSSPrimitiveValue::CSSLengthArray CSSLengthArray; 372 typedef CSSPrimitiveValue::CSSLengthArray CSSLengthArray;
362 typedef CSSPrimitiveValue::CSSLengthTypeArray CSSLengthTypeArray; 373 typedef CSSPrimitiveValue::CSSLengthTypeArray CSSLengthTypeArray;
363 374
364 DEFINE_CSS_VALUE_TYPE_CASTS(CSSPrimitiveValue, isPrimitiveValue()); 375 DEFINE_CSS_VALUE_TYPE_CASTS(CSSPrimitiveValue, isPrimitiveValue());
365 376
366 } // namespace blink 377 } // namespace blink
367 378
368 #endif // CSSPrimitiveValue_h 379 #endif // CSSPrimitiveValue_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698