Devirtualize CSSValue.
[WebKit-https.git] / Source / WebCore / css / CSSValue.cpp
1 /*
2  * Copyright (C) 2011 Andreas Kling (kling@webkit.org)
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  */
26
27 #include "config.h"
28 #include "CSSValue.h"
29
30 #include "CSSAspectRatioValue.h"
31 #include "CSSBorderImageValue.h"
32 #include "CSSBorderImageSliceValue.h"
33 #include "CSSCanvasValue.h"
34 #include "CSSCrossfadeValue.h"
35 #include "CSSCursorImageValue.h"
36 #include "CSSFlexValue.h"
37 #include "CSSFontFaceSrcValue.h"
38 #include "CSSFunctionValue.h"
39 #include "CSSGradientValue.h"
40 #include "CSSImageGeneratorValue.h"
41 #include "CSSImageValue.h"
42 #include "CSSInheritedValue.h"
43 #include "CSSInitialValue.h"
44 #include "CSSLineBoxContainValue.h"
45 #include "CSSPrimitiveValue.h"
46 #include "CSSReflectValue.h"
47 #include "CSSTimingFunctionValue.h"
48 #include "CSSUnicodeRangeValue.h"
49 #include "CSSValueList.h"
50 #include "FontValue.h"
51 #include "FontFamilyValue.h"
52 #include "FontFeatureValue.h"
53 #include "ShadowValue.h"
54 #include "SVGColor.h"
55 #include "SVGPaint.h"
56 #include "WebKitCSSFilterValue.h"
57 #include "WebKitCSSTransformValue.h"
58
59 namespace WebCore {
60
61 CSSValue::Type CSSValue::cssValueType() const
62 {
63     if (isInheritedValue())
64         return CSS_INHERIT;
65     if (isPrimitiveValue())
66         return CSS_PRIMITIVE_VALUE;
67     if (isValueList())
68         return CSS_VALUE_LIST;
69     if (isInitialValue())
70         return CSS_INITIAL;
71     return CSS_CUSTOM;
72 }
73
74 void CSSValue::addSubresourceStyleURLs(ListHashSet<KURL>& urls, const CSSStyleSheet* styleSheet)
75 {
76     if (isPrimitiveValue())
77         static_cast<CSSPrimitiveValue*>(this)->addSubresourceStyleURLs(urls, styleSheet);
78     else if (isValueList())
79         static_cast<CSSValueList*>(this)->addSubresourceStyleURLs(urls, styleSheet);
80     else if (classType() == BorderImageClass)
81         static_cast<CSSBorderImageValue*>(this)->addSubresourceStyleURLs(urls, styleSheet);
82     else if (classType() == FontFaceSrcClass)
83         static_cast<CSSFontFaceSrcValue*>(this)->addSubresourceStyleURLs(urls, styleSheet);
84     else if (classType() == ReflectClass)
85         static_cast<CSSReflectValue*>(this)->addSubresourceStyleURLs(urls, styleSheet);
86 }
87
88 String CSSValue::cssText() const
89 {
90     switch (classType()) {
91     case AspectRatioClass:
92         return static_cast<const CSSAspectRatioValue*>(this)->customCssText();
93     case BorderImageClass:
94         return static_cast<const CSSBorderImageValue*>(this)->customCssText();
95     case BorderImageSliceClass:
96         return static_cast<const CSSBorderImageSliceValue*>(this)->customCssText();
97     case CanvasClass:
98         return static_cast<const CSSCanvasValue*>(this)->customCssText();
99     case CursorImageClass:
100         return static_cast<const CSSCursorImageValue*>(this)->customCssText();
101     case FontClass:
102         return static_cast<const FontValue*>(this)->customCssText();
103     case FontFaceSrcClass:
104         return static_cast<const CSSFontFaceSrcValue*>(this)->customCssText();
105     case FontFamilyClass:
106         return static_cast<const FontFamilyValue*>(this)->customCssText();
107     case FontFeatureClass:
108         return static_cast<const FontFeatureValue*>(this)->customCssText();
109     case FunctionClass:
110         return static_cast<const CSSFunctionValue*>(this)->customCssText();
111     case LinearGradientClass:
112         return static_cast<const CSSLinearGradientValue*>(this)->customCssText();
113     case RadialGradientClass:
114         return static_cast<const CSSRadialGradientValue*>(this)->customCssText();
115     case CrossfadeClass:
116         return static_cast<const CSSCrossfadeValue*>(this)->customCssText();
117     case ImageClass:
118         return static_cast<const CSSImageValue*>(this)->customCssText();
119     case InheritedClass:
120         return static_cast<const CSSInheritedValue*>(this)->customCssText();
121     case InitialClass:
122     case ImplicitInitialClass:
123         return static_cast<const CSSInitialValue*>(this)->customCssText();
124     case PrimitiveClass:
125         return static_cast<const CSSPrimitiveValue*>(this)->customCssText();
126     case ReflectClass:
127         return static_cast<const CSSReflectValue*>(this)->customCssText();
128     case ShadowClass:
129         return static_cast<const ShadowValue*>(this)->customCssText();
130     case LinearTimingFunctionClass:
131         return static_cast<const CSSLinearTimingFunctionValue*>(this)->customCssText();
132     case CubicBezierTimingFunctionClass:
133         return static_cast<const CSSCubicBezierTimingFunctionValue*>(this)->customCssText();
134     case StepsTimingFunctionClass:
135         return static_cast<const CSSStepsTimingFunctionValue*>(this)->customCssText();
136     case UnicodeRangeClass:
137         return static_cast<const CSSUnicodeRangeValue*>(this)->customCssText();
138     case ValueListClass:
139         return static_cast<const CSSValueList*>(this)->customCssText();
140     case WebKitCSSTransformClass:
141         return static_cast<const WebKitCSSTransformValue*>(this)->customCssText();
142     case LineBoxContainClass:
143         return static_cast<const CSSLineBoxContainValue*>(this)->customCssText();
144 #if ENABLE(CSS3_FLEXBOX)
145     case FlexClass:
146         return static_cast<const CSSFlexValue*>(this)->customCssText();
147 #endif
148 #if ENABLE(CSS_FILTERS)
149     case WebKitCSSFilterClass:
150         return static_cast<const WebKitCSSFilterValue*>(this)->customCssText();
151 #endif
152 #if ENABLE(SVG)
153     case SVGColorClass:
154         return static_cast<const SVGColor*>(this)->customCssText();
155     case SVGPaintClass:
156         return static_cast<const SVGPaint*>(this)->customCssText();
157 #endif
158     }
159     ASSERT_NOT_REACHED();
160     return String();
161 }
162
163 void CSSValue::destroy()
164 {
165     switch (classType()) {
166     case AspectRatioClass:
167         delete static_cast<CSSAspectRatioValue*>(this);
168         return;
169     case BorderImageClass:
170         delete static_cast<CSSBorderImageValue*>(this);
171         return;
172     case BorderImageSliceClass:
173         delete static_cast<CSSBorderImageSliceValue*>(this);
174         return;
175     case CanvasClass:
176         delete static_cast<CSSCanvasValue*>(this);
177         return;
178     case CursorImageClass:
179         delete static_cast<CSSCursorImageValue*>(this);
180         return;
181     case FontClass:
182         delete static_cast<FontValue*>(this);
183         return;
184     case FontFaceSrcClass:
185         delete static_cast<CSSFontFaceSrcValue*>(this);
186         return;
187     case FontFamilyClass:
188         delete static_cast<FontFamilyValue*>(this);
189         return;
190     case FontFeatureClass:
191         delete static_cast<FontFeatureValue*>(this);
192         return;
193     case FunctionClass:
194         delete static_cast<CSSFunctionValue*>(this);
195         return;
196     case LinearGradientClass:
197         delete static_cast<CSSLinearGradientValue*>(this);
198         return;
199     case RadialGradientClass:
200         delete static_cast<CSSRadialGradientValue*>(this);
201         return;
202     case CrossfadeClass:
203         delete static_cast<CSSCrossfadeValue*>(this);
204         return;
205     case ImageClass:
206         delete static_cast<CSSImageValue*>(this);
207         return;
208     case InheritedClass:
209         delete static_cast<CSSInheritedValue*>(this);
210         return;
211     case InitialClass:
212     case ImplicitInitialClass:
213         delete static_cast<CSSInitialValue*>(this);
214         return;
215     case PrimitiveClass:
216         delete static_cast<CSSPrimitiveValue*>(this);
217         return;
218     case ReflectClass:
219         delete static_cast<CSSReflectValue*>(this);
220         return;
221     case ShadowClass:
222         delete static_cast<ShadowValue*>(this);
223         return;
224     case LinearTimingFunctionClass:
225         delete static_cast<CSSLinearTimingFunctionValue*>(this);
226         return;
227     case CubicBezierTimingFunctionClass:
228         delete static_cast<CSSCubicBezierTimingFunctionValue*>(this);
229         return;
230     case StepsTimingFunctionClass:
231         delete static_cast<CSSStepsTimingFunctionValue*>(this);
232         return;
233     case UnicodeRangeClass:
234         delete static_cast<CSSUnicodeRangeValue*>(this);
235         return;
236     case ValueListClass:
237         delete static_cast<CSSValueList*>(this);
238         return;
239     case WebKitCSSTransformClass:
240         delete static_cast<WebKitCSSTransformValue*>(this);
241         return;
242     case LineBoxContainClass:
243         delete static_cast<CSSLineBoxContainValue*>(this);
244         return;
245 #if ENABLE(CSS3_FLEXBOX)
246     case FlexClass:
247         delete static_cast<CSSFlexValue*>(this);
248         return;
249 #endif
250 #if ENABLE(CSS_FILTERS)
251     case WebKitCSSFilterClass:
252         delete static_cast<WebKitCSSFilterValue*>(this);
253         return;
254 #endif
255 #if ENABLE(SVG)
256     case SVGColorClass:
257         delete static_cast<SVGColor*>(this);
258         return;
259     case SVGPaintClass:
260         delete static_cast<SVGPaint*>(this);
261         return;
262 #endif
263     }
264     ASSERT_NOT_REACHED();
265 }
266
267 }