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

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: Missing file :( Created 5 years, 4 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 Chs, 113 Chs,
113 Shape, 114 Shape,
114 Quad, 115 Quad,
115 Calc, 116 Calc,
116 CalcPercentageWithNumber, 117 CalcPercentageWithNumber,
117 CalcPercentageWithLength, 118 CalcPercentageWithLength,
118 String, 119 String,
119 PropertyID, 120 PropertyID,
120 ValueID, 121 ValueID,
121 QuirkyEms, 122 QuirkyEms,
123 VariableReference,
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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 bool isPropertyID() const { return type() == UnitType::PropertyID; } 191 bool isPropertyID() const { return type() == UnitType::PropertyID; }
190 bool isPx() const { return typeWithCalcResolved() == UnitType::Pixels; } 192 bool isPx() const { return typeWithCalcResolved() == UnitType::Pixels; }
191 bool isQuad() const { return type() == UnitType::Quad; } 193 bool isQuad() const { return type() == UnitType::Quad; }
192 bool isRect() const { return type() == UnitType::Rect; } 194 bool isRect() const { return type() == UnitType::Rect; }
193 bool isRGBColor() const { return type() == UnitType::RGBColor; } 195 bool isRGBColor() const { return type() == UnitType::RGBColor; }
194 bool isShape() const { return type() == UnitType::Shape; } 196 bool isShape() const { return type() == UnitType::Shape; }
195 bool isString() const { return type() == UnitType::String; } 197 bool isString() const { return type() == UnitType::String; }
196 bool isTime() const { return type() == UnitType::Seconds || type() == UnitTy pe::Milliseconds; } 198 bool isTime() const { return type() == UnitType::Seconds || type() == UnitTy pe::Milliseconds; }
197 bool isURI() const { return type() == UnitType::URI; } 199 bool isURI() const { return type() == UnitType::URI; }
198 bool isCalculated() const { return type() == UnitType::Calc; } 200 bool isCalculated() const { return type() == UnitType::Calc; }
201 bool isVariableReference() const { return type() == UnitType::VariableRefere nce; }
199 bool isCalculatedPercentageWithNumber() const { return typeWithCalcResolved( ) == UnitType::CalcPercentageWithNumber; } 202 bool isCalculatedPercentageWithNumber() const { return typeWithCalcResolved( ) == UnitType::CalcPercentageWithNumber; }
200 bool isCalculatedPercentageWithLength() const { return typeWithCalcResolved( ) == UnitType::CalcPercentageWithLength; } 203 bool isCalculatedPercentageWithLength() const { return typeWithCalcResolved( ) == UnitType::CalcPercentageWithLength; }
201 static bool isDotsPerInch(UnitType type) { return type == UnitType::DotsPerI nch; } 204 static bool isDotsPerInch(UnitType type) { return type == UnitType::DotsPerI nch; }
202 static bool isDotsPerPixel(UnitType type) { return type == UnitType::DotsPer Pixel; } 205 static bool isDotsPerPixel(UnitType type) { return type == UnitType::DotsPer Pixel; }
203 static bool isDotsPerCentimeter(UnitType type) { return type == UnitType::Do tsPerCentimeter; } 206 static bool isDotsPerCentimeter(UnitType type) { return type == UnitType::Do tsPerCentimeter; }
204 static bool isResolution(UnitType type) { return type >= UnitType::DotsPerPi xel && type <= UnitType::DotsPerCentimeter; } 207 static bool isResolution(UnitType type) { return type >= UnitType::DotsPerPi xel && type <= UnitType::DotsPerCentimeter; }
205 bool isFlex() const { return typeWithCalcResolved() == UnitType::Fraction; } 208 bool isFlex() const { return typeWithCalcResolved() == UnitType::Fraction; }
206 bool isValueID() const { return type() == UnitType::ValueID; } 209 bool isValueID() const { return type() == UnitType::ValueID; }
207 bool colorIsDerivedFromElement() const; 210 bool colorIsDerivedFromElement() const;
208 211
(...skipping 18 matching lines...) Expand all
227 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, type)); 230 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, type));
228 } 231 }
229 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const Length& value, float zoom) 232 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const Length& value, float zoom)
230 { 233 {
231 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, zoom)); 234 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, zoom));
232 } 235 }
233 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const LengthSize& va lue, const ComputedStyle& style) 236 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const LengthSize& va lue, const ComputedStyle& style)
234 { 237 {
235 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, style)); 238 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, style));
236 } 239 }
240 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(CSSVariableData* val ue)
241 {
242 return adoptRefWillBeNoop(new CSSPrimitiveValue(value));
243 }
237 template<typename T> static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create (T value) 244 template<typename T> static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create (T value)
238 { 245 {
239 return adoptRefWillBeNoop(new CSSPrimitiveValue(value)); 246 return adoptRefWillBeNoop(new CSSPrimitiveValue(value));
240 } 247 }
241 248
242 // This value is used to handle quirky margins in reflow roots (body, td, an d th) like WinIE. 249 // This value is used to handle quirky margins in reflow roots (body, td, an d th) like WinIE.
243 // The basic idea is that a stylesheet can use the value __qem (for quirky e m) instead of em. 250 // The basic idea is that a stylesheet can use the value __qem (for quirky e m) instead of em.
244 // When the quirky value is used, if you're in quirks mode, the margin will collapse away 251 // When the quirky value is used, if you're in quirks mode, the margin will collapse away
245 // inside a table cell. 252 // inside a table cell.
246 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createAllowingMarginQuirk(d ouble value, UnitType type) 253 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createAllowingMarginQuirk(d ouble value, UnitType type)
(...skipping 30 matching lines...) Expand all
277 Quad* getQuadValue() const { ASSERT(isQuad()); return m_value.quad; } 284 Quad* getQuadValue() const { ASSERT(isQuad()); return m_value.quad; }
278 RGBA32 getRGBA32Value() const { ASSERT(isRGBColor()); return m_value.rgbcolo r; } 285 RGBA32 getRGBA32Value() const { ASSERT(isRGBColor()); return m_value.rgbcolo r; }
279 286
280 // TODO(timloh): Add isPair() and update callers so we can ASSERT(isPair()) 287 // TODO(timloh): Add isPair() and update callers so we can ASSERT(isPair())
281 Pair* getPairValue() const { return type() != UnitType::Pair ? 0 : m_value.p air; } 288 Pair* getPairValue() const { return type() != UnitType::Pair ? 0 : m_value.p air; }
282 289
283 CSSBasicShape* getShapeValue() const { ASSERT(isShape()); return m_value.sha pe; } 290 CSSBasicShape* getShapeValue() const { ASSERT(isShape()); return m_value.sha pe; }
284 CSSCalcValue* cssCalcValue() const { ASSERT(isCalculated()); return m_value. calc; } 291 CSSCalcValue* cssCalcValue() const { ASSERT(isCalculated()); return m_value. calc; }
285 CSSPropertyID getPropertyID() const { ASSERT(isPropertyID()); return m_value .propertyID; } 292 CSSPropertyID getPropertyID() const { ASSERT(isPropertyID()); return m_value .propertyID; }
286 293
294 CSSVariableData* getVariableDataValue() const
295 {
296 ASSERT(type() == UnitType::VariableReference);
297 return m_value.variableData;
298 }
299
287 CSSValueID getValueID() const { return type() == UnitType::ValueID ? m_value .valueID : CSSValueInvalid; } 300 CSSValueID getValueID() const { return type() == UnitType::ValueID ? m_value .valueID : CSSValueInvalid; }
288 301
289 template<typename T> inline operator T() const; // Defined in CSSPrimitiveVa lueMappings.h 302 template<typename T> inline operator T() const; // Defined in CSSPrimitiveVa lueMappings.h
290 303
291 static const char* unitTypeToString(UnitType); 304 static const char* unitTypeToString(UnitType);
292 String customCSSText() const; 305 String customCSSText() const;
293 306
294 bool isQuirkValue() { return m_isQuirkValue; } 307 bool isQuirkValue() { return m_isQuirkValue; }
295 308
296 bool equals(const CSSPrimitiveValue&) const; 309 bool equals(const CSSPrimitiveValue&) const;
297 310
298 DECLARE_TRACE_AFTER_DISPATCH(); 311 DECLARE_TRACE_AFTER_DISPATCH();
299 312
300 static UnitType canonicalUnitTypeForCategory(UnitCategory); 313 static UnitType canonicalUnitTypeForCategory(UnitCategory);
301 static double conversionToCanonicalUnitsScaleFactor(UnitType); 314 static double conversionToCanonicalUnitsScaleFactor(UnitType);
302 315
303 // Returns true and populates lengthUnitType, if unitType is a length unit. Otherwise, returns false. 316 // Returns true and populates lengthUnitType, if unitType is a length unit. Otherwise, returns false.
304 static bool unitTypeToLengthUnitType(UnitType, LengthUnitType&); 317 static bool unitTypeToLengthUnitType(UnitType, LengthUnitType&);
305 static UnitType lengthUnitTypeToUnitType(LengthUnitType); 318 static UnitType lengthUnitTypeToUnitType(LengthUnitType);
306 319
307 private: 320 private:
308 CSSPrimitiveValue(CSSValueID); 321 CSSPrimitiveValue(CSSValueID);
309 CSSPrimitiveValue(CSSPropertyID); 322 CSSPrimitiveValue(CSSPropertyID);
310 CSSPrimitiveValue(RGBA32 color); 323 CSSPrimitiveValue(RGBA32 color);
311 CSSPrimitiveValue(const Length&, float zoom); 324 CSSPrimitiveValue(const Length&, float zoom);
312 CSSPrimitiveValue(const LengthSize&, const ComputedStyle&); 325 CSSPrimitiveValue(const LengthSize&, const ComputedStyle&);
313 CSSPrimitiveValue(const String&, UnitType); 326 CSSPrimitiveValue(const String&, UnitType);
314 CSSPrimitiveValue(double, UnitType); 327 CSSPrimitiveValue(double, UnitType);
328 CSSPrimitiveValue(CSSVariableData*);
315 329
316 template<typename T> CSSPrimitiveValue(T); // Defined in CSSPrimitiveValueMa ppings.h 330 template<typename T> CSSPrimitiveValue(T); // Defined in CSSPrimitiveValueMa ppings.h
317 template<typename T> CSSPrimitiveValue(T* val) 331 template<typename T> CSSPrimitiveValue(T* val)
318 : CSSValue(PrimitiveClass) 332 : CSSValue(PrimitiveClass)
319 { 333 {
320 init(PassRefPtrWillBeRawPtr<T>(val)); 334 init(PassRefPtrWillBeRawPtr<T>(val));
321 } 335 }
322 336
323 template<typename T> CSSPrimitiveValue(PassRefPtrWillBeRawPtr<T> val) 337 template<typename T> CSSPrimitiveValue(PassRefPtrWillBeRawPtr<T> val)
324 : CSSValue(PrimitiveClass) 338 : CSSValue(PrimitiveClass)
(...skipping 25 matching lines...) Expand all
350 double num; 364 double num;
351 StringImpl* string; 365 StringImpl* string;
352 RGBA32 rgbcolor; 366 RGBA32 rgbcolor;
353 // FIXME: oilpan: Should be members, but no support for members in union s. Just trace the raw ptr for now. 367 // FIXME: oilpan: Should be members, but no support for members in union s. Just trace the raw ptr for now.
354 CSSBasicShape* shape; 368 CSSBasicShape* shape;
355 CSSCalcValue* calc; 369 CSSCalcValue* calc;
356 Counter* counter; 370 Counter* counter;
357 Pair* pair; 371 Pair* pair;
358 Rect* rect; 372 Rect* rect;
359 Quad* quad; 373 Quad* quad;
374 CSSVariableData* variableData;
360 } m_value; 375 } m_value;
361 }; 376 };
362 377
363 typedef CSSPrimitiveValue::CSSLengthArray CSSLengthArray; 378 typedef CSSPrimitiveValue::CSSLengthArray CSSLengthArray;
364 typedef CSSPrimitiveValue::CSSLengthTypeArray CSSLengthTypeArray; 379 typedef CSSPrimitiveValue::CSSLengthTypeArray CSSLengthTypeArray;
365 380
366 DEFINE_CSS_VALUE_TYPE_CASTS(CSSPrimitiveValue, isPrimitiveValue()); 381 DEFINE_CSS_VALUE_TYPE_CASTS(CSSPrimitiveValue, isPrimitiveValue());
367 382
368 } // namespace blink 383 } // namespace blink
369 384
370 #endif // CSSPrimitiveValue_h 385 #endif // CSSPrimitiveValue_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698