[CherryPick] flex-grow should be 1 when flex:auto
[framework/web/webkit-efl.git] / Source / WebCore / css / CSSValue.h
1 /*
2  * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3  * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB.  If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 #ifndef CSSValue_h
22 #define CSSValue_h
23
24 #include "ExceptionCode.h"
25 #include "KURLHash.h"
26 #include <wtf/ListHashSet.h>
27 #include <wtf/RefCounted.h>
28 #include <wtf/RefPtr.h>
29
30 namespace WebCore {
31
32 class StyleSheetContents;
33     
34 // FIXME: The current CSSValue and subclasses should be turned into internal types (StyleValue).
35 // The few subtypes that are actually exposed in CSSOM can be seen in the cloneForCSSOM() function.
36 // They should be handled by separate wrapper classes.
37
38 // Please don't expose more CSSValue types to the web.
39 class CSSValue : public RefCounted<CSSValue> {
40 public:
41     enum Type {
42         CSS_INHERIT = 0,
43         CSS_PRIMITIVE_VALUE = 1,
44         CSS_VALUE_LIST = 2,
45         CSS_CUSTOM = 3,
46         CSS_INITIAL = 4
47
48     };
49
50     // Override RefCounted's deref() to ensure operator delete is called on
51     // the appropriate subclass type.
52     void deref()
53     {
54         if (derefBase())
55             destroy();
56     }
57
58     Type cssValueType() const;
59
60     String cssText() const;
61     void setCssText(const String&, ExceptionCode&) { } // FIXME: Not implemented.
62 #if ENABLE(CSS_VARIABLES)
63     String serializeResolvingVariables(const HashMap<AtomicString, String>&) const;
64 #endif
65
66     bool isPrimitiveValue() const { return m_classType == PrimitiveClass; }
67     bool isValueList() const { return m_classType >= ValueListClass; }
68
69     bool isAspectRatioValue() const { return m_classType == AspectRatioClass; }
70     bool isBorderImageSliceValue() const { return m_classType == BorderImageSliceClass; }
71     bool isCursorImageValue() const { return m_classType == CursorImageClass; }
72     bool isFontFeatureValue() const { return m_classType == FontFeatureClass; }
73     bool isFontValue() const { return m_classType == FontClass; }
74     bool isImageGeneratorValue() const { return m_classType >= CanvasClass && m_classType <= RadialGradientClass; }
75     bool isGradientValue() const { return m_classType >= LinearGradientClass && m_classType <= RadialGradientClass; }
76 #if ENABLE(CSS_IMAGE_SET)
77     bool isImageSetValue() const { return m_classType == ImageSetClass; }
78 #endif
79     bool isImageValue() const { return m_classType == ImageClass || m_classType == CursorImageClass; }
80     bool isImplicitInitialValue() const;
81     bool isInheritedValue() const { return m_classType == InheritedClass; }
82     bool isInitialValue() const { return m_classType == InitialClass; }
83     bool isReflectValue() const { return m_classType == ReflectClass; }
84     bool isShadowValue() const { return m_classType == ShadowClass; }
85     bool isCubicBezierTimingFunctionValue() const { return m_classType == CubicBezierTimingFunctionClass; }
86     bool isLinearTimingFunctionValue() const { return m_classType == LinearTimingFunctionClass; }
87     bool isStepsTimingFunctionValue() const { return m_classType == StepsTimingFunctionClass; }
88     bool isWebKitCSSTransformValue() const { return m_classType == WebKitCSSTransformClass; }
89     bool isCSSLineBoxContainValue() const { return m_classType == LineBoxContainClass; }
90     bool isCalculationValue() const {return m_classType == CalculationClass; }
91 #if ENABLE(CSS_FILTERS)
92     bool isWebKitCSSFilterValue() const { return m_classType == WebKitCSSFilterClass; }
93 #if ENABLE(CSS_SHADERS)
94     bool isWebKitCSSShaderValue() const { return m_classType == WebKitCSSShaderClass; }
95 #endif
96 #endif // ENABLE(CSS_FILTERS)
97 #if ENABLE(CSS_VARIABLES)
98     bool isVariableValue() const { return m_classType == VariableClass; }
99 #endif
100 #if ENABLE(SVG)
101     bool isSVGColor() const { return m_classType == SVGColorClass || m_classType == SVGPaintClass; }
102     bool isSVGPaint() const { return m_classType == SVGPaintClass; }
103     bool isWebKitCSSSVGDocumentValue() const { return m_classType == WebKitCSSSVGDocumentClass; }
104 #endif
105     
106     bool isCSSOMSafe() const { return m_isCSSOMSafe; }
107     bool isSubtypeExposedToCSSOM() const
108     { 
109         return isPrimitiveValue() 
110 #if ENABLE(SVG)
111             || isSVGColor()
112 #endif
113             || isValueList();
114     }
115
116     PassRefPtr<CSSValue> cloneForCSSOM() const;
117
118     void addSubresourceStyleURLs(ListHashSet<KURL>&, const StyleSheetContents*) const;
119
120 protected:
121
122     static const size_t ClassTypeBits = 5;
123     enum ClassType {
124         PrimitiveClass,
125
126         // Image classes.
127         ImageClass,
128         CursorImageClass,
129
130         // Image generator classes.
131         CanvasClass,
132         CrossfadeClass,
133         LinearGradientClass,
134         RadialGradientClass,
135
136         // Timing function classes.
137         CubicBezierTimingFunctionClass,
138         LinearTimingFunctionClass,
139         StepsTimingFunctionClass,
140
141         // Other class types.
142         AspectRatioClass,
143         BorderImageSliceClass,
144         FontFeatureClass,
145         FontClass,
146         FontFaceSrcClass,
147         FunctionClass,
148
149         InheritedClass,
150         InitialClass,
151
152         ReflectClass,
153         ShadowClass,
154         UnicodeRangeClass,
155         LineBoxContainClass,
156         CalculationClass,
157 #if ENABLE(CSS_FILTERS) && ENABLE(CSS_SHADERS)
158         WebKitCSSShaderClass,
159 #endif
160 #if ENABLE(CSS_VARIABLES)
161         VariableClass,
162 #endif
163 #if ENABLE(SVG)
164         SVGColorClass,
165         SVGPaintClass,
166         WebKitCSSSVGDocumentClass,
167 #endif
168
169         // List class types must appear after ValueListClass.
170         ValueListClass,
171 #if ENABLE(CSS_IMAGE_SET)
172         ImageSetClass,
173 #endif
174 #if ENABLE(CSS_FILTERS)
175         WebKitCSSFilterClass,
176 #endif
177         WebKitCSSTransformClass,
178         // Do not append non-list class types here.
179     };
180
181     static const size_t ValueListSeparatorBits = 2;
182     enum ValueListSeparator {
183         SpaceSeparator,
184         CommaSeparator,
185         SlashSeparator
186     };
187
188     ClassType classType() const { return static_cast<ClassType>(m_classType); }
189
190     explicit CSSValue(ClassType classType, bool isCSSOMSafe = false)
191         : m_isCSSOMSafe(isCSSOMSafe)
192         , m_isTextClone(false)
193         , m_primitiveUnitType(0)
194         , m_hasCachedCSSText(false)
195         , m_isQuirkValue(false)
196         , m_valueListSeparator(SpaceSeparator)
197         , m_classType(classType)
198     {
199     }
200
201     // NOTE: This class is non-virtual for memory and performance reasons.
202     // Don't go making it virtual again unless you know exactly what you're doing!
203
204     ~CSSValue() { }
205
206 private:
207     void destroy();
208
209 protected:
210     unsigned m_isCSSOMSafe : 1;
211     unsigned m_isTextClone : 1;
212     // The bits in this section are only used by specific subclasses but kept here
213     // to maximize struct packing.
214
215     // CSSPrimitiveValue bits:
216     unsigned m_primitiveUnitType : 7; // CSSPrimitiveValue::UnitTypes
217     mutable unsigned m_hasCachedCSSText : 1;
218     unsigned m_isQuirkValue : 1;
219
220     unsigned m_valueListSeparator : ValueListSeparatorBits;
221
222 private:
223     unsigned m_classType : ClassTypeBits; // ClassType
224 };
225
226 } // namespace WebCore
227
228 #endif // CSSValue_h