[css-grid] Remove compilation flag ENABLE_CSS_GRID_LAYOUT
[WebKit-https.git] / Source / WebCore / css / CSSValue.cpp
1 /*
2  * Copyright (C) 2011 Andreas Kling (kling@webkit.org)
3  * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  */
27
28 #include "config.h"
29 #include "CSSValue.h"
30
31 #include "CSSAnimationTriggerScrollValue.h"
32 #include "CSSAspectRatioValue.h"
33 #include "CSSBorderImageSliceValue.h"
34 #include "CSSCalculationValue.h"
35 #include "CSSCanvasValue.h"
36 #include "CSSContentDistributionValue.h"
37 #include "CSSCrossfadeValue.h"
38 #include "CSSCursorImageValue.h"
39 #include "CSSCustomIdentValue.h"
40 #include "CSSCustomPropertyValue.h"
41 #include "CSSFilterImageValue.h"
42 #include "CSSFontFaceSrcValue.h"
43 #include "CSSFontFeatureValue.h"
44 #include "CSSFontValue.h"
45 #include "CSSFontVariationValue.h"
46 #include "CSSFunctionValue.h"
47 #include "CSSGradientValue.h"
48 #include "CSSImageSetValue.h"
49 #include "CSSImageValue.h"
50 #include "CSSInheritedValue.h"
51 #include "CSSInitialValue.h"
52 #include "CSSLineBoxContainValue.h"
53 #include "CSSNamedImageValue.h"
54 #include "CSSPendingSubstitutionValue.h"
55 #include "CSSPrimitiveValue.h"
56 #include "CSSProperty.h"
57 #include "CSSReflectValue.h"
58 #include "CSSShadowValue.h"
59 #include "CSSTimingFunctionValue.h"
60 #include "CSSUnicodeRangeValue.h"
61 #include "CSSUnsetValue.h"
62 #include "CSSValueList.h"
63 #include "CSSVariableReferenceValue.h"
64
65 #include "CSSGridAutoRepeatValue.h"
66 #include "CSSGridLineNamesValue.h"
67 #include "CSSGridTemplateAreasValue.h"
68
69 #include "DeprecatedCSSOMPrimitiveValue.h"
70 #include "DeprecatedCSSOMValueList.h"
71
72 namespace WebCore {
73
74 struct SameSizeAsCSSValue : public RefCounted<SameSizeAsCSSValue> {
75     uint32_t bitfields;
76 };
77
78 COMPILE_ASSERT(sizeof(CSSValue) == sizeof(SameSizeAsCSSValue), CSS_value_should_stay_small);
79
80 bool CSSValue::isImplicitInitialValue() const
81 {
82     return m_classType == InitialClass && downcast<CSSInitialValue>(*this).isImplicit();
83 }
84
85 CSSValue::Type CSSValue::cssValueType() const
86 {
87     if (isInheritedValue())
88         return CSS_INHERIT;
89     if (isPrimitiveValue())
90         return CSS_PRIMITIVE_VALUE;
91     if (isValueList())
92         return CSS_VALUE_LIST;
93     if (isInitialValue())
94         return CSS_INITIAL;
95     if (isUnsetValue())
96         return CSS_UNSET;
97     if (isRevertValue())
98         return CSS_REVERT;
99     return CSS_CUSTOM;
100 }
101
102 bool CSSValue::traverseSubresources(const std::function<bool (const CachedResource&)>& handler) const
103 {
104     if (is<CSSValueList>(*this))
105         return downcast<CSSValueList>(*this).traverseSubresources(handler);
106     if (is<CSSFontFaceSrcValue>(*this))
107         return downcast<CSSFontFaceSrcValue>(*this).traverseSubresources(handler);
108     if (is<CSSImageValue>(*this))
109         return downcast<CSSImageValue>(*this).traverseSubresources(handler);
110     if (is<CSSCrossfadeValue>(*this))
111         return downcast<CSSCrossfadeValue>(*this).traverseSubresources(handler);
112     if (is<CSSFilterImageValue>(*this))
113         return downcast<CSSFilterImageValue>(*this).traverseSubresources(handler);
114     if (is<CSSImageSetValue>(*this))
115         return downcast<CSSImageSetValue>(*this).traverseSubresources(handler);
116     return false;
117 }
118
119 template<class ChildClassType>
120 inline static bool compareCSSValues(const CSSValue& first, const CSSValue& second)
121 {
122     return static_cast<const ChildClassType&>(first).equals(static_cast<const ChildClassType&>(second));
123 }
124
125 bool CSSValue::equals(const CSSValue& other) const
126 {
127     if (m_classType == other.m_classType) {
128         switch (m_classType) {
129         case AspectRatioClass:
130             return compareCSSValues<CSSAspectRatioValue>(*this, other);
131         case BorderImageSliceClass:
132             return compareCSSValues<CSSBorderImageSliceValue>(*this, other);
133         case CanvasClass:
134             return compareCSSValues<CSSCanvasValue>(*this, other);
135         case NamedImageClass:
136             return compareCSSValues<CSSNamedImageValue>(*this, other);
137         case CursorImageClass:
138             return compareCSSValues<CSSCursorImageValue>(*this, other);
139         case FilterImageClass:
140             return compareCSSValues<CSSFilterImageValue>(*this, other);
141         case FontClass:
142             return compareCSSValues<CSSFontValue>(*this, other);
143         case FontFaceSrcClass:
144             return compareCSSValues<CSSFontFaceSrcValue>(*this, other);
145         case FontFeatureClass:
146             return compareCSSValues<CSSFontFeatureValue>(*this, other);
147 #if ENABLE(VARIATION_FONTS)
148         case FontVariationClass:
149             return compareCSSValues<CSSFontVariationValue>(*this, other);
150 #endif
151         case FunctionClass:
152             return compareCSSValues<CSSFunctionValue>(*this, other);
153         case LinearGradientClass:
154             return compareCSSValues<CSSLinearGradientValue>(*this, other);
155         case RadialGradientClass:
156             return compareCSSValues<CSSRadialGradientValue>(*this, other);
157         case CrossfadeClass:
158             return compareCSSValues<CSSCrossfadeValue>(*this, other);
159         case ImageClass:
160             return compareCSSValues<CSSImageValue>(*this, other);
161         case InheritedClass:
162             return compareCSSValues<CSSInheritedValue>(*this, other);
163         case InitialClass:
164             return compareCSSValues<CSSInitialValue>(*this, other);
165         case UnsetClass:
166             return compareCSSValues<CSSUnsetValue>(*this, other);
167         case RevertClass:
168             return compareCSSValues<CSSRevertValue>(*this, other);
169         case GridAutoRepeatClass:
170             return compareCSSValues<CSSGridAutoRepeatValue>(*this, other);
171         case GridLineNamesClass:
172             return compareCSSValues<CSSGridLineNamesValue>(*this, other);
173         case GridTemplateAreasClass:
174             return compareCSSValues<CSSGridTemplateAreasValue>(*this, other);
175         case PrimitiveClass:
176             return compareCSSValues<CSSPrimitiveValue>(*this, other);
177         case ReflectClass:
178             return compareCSSValues<CSSReflectValue>(*this, other);
179         case ShadowClass:
180             return compareCSSValues<CSSShadowValue>(*this, other);
181         case CubicBezierTimingFunctionClass:
182             return compareCSSValues<CSSCubicBezierTimingFunctionValue>(*this, other);
183         case StepsTimingFunctionClass:
184             return compareCSSValues<CSSStepsTimingFunctionValue>(*this, other);
185         case SpringTimingFunctionClass:
186             return compareCSSValues<CSSSpringTimingFunctionValue>(*this, other);
187         case UnicodeRangeClass:
188             return compareCSSValues<CSSUnicodeRangeValue>(*this, other);
189         case ValueListClass:
190             return compareCSSValues<CSSValueList>(*this, other);
191         case LineBoxContainClass:
192             return compareCSSValues<CSSLineBoxContainValue>(*this, other);
193         case CalculationClass:
194             return compareCSSValues<CSSCalcValue>(*this, other);
195         case ImageSetClass:
196             return compareCSSValues<CSSImageSetValue>(*this, other);
197 #if ENABLE(CSS_ANIMATIONS_LEVEL_2)
198         case AnimationTriggerScrollClass:
199             return compareCSSValues<CSSAnimationTriggerScrollValue>(*this, other);
200 #endif
201         case CSSContentDistributionClass:
202             return compareCSSValues<CSSContentDistributionValue>(*this, other);
203         case CustomPropertyClass:
204             return compareCSSValues<CSSCustomPropertyValue>(*this, other);
205         case VariableReferenceClass:
206             return compareCSSValues<CSSVariableReferenceValue>(*this, other);
207         case PendingSubstitutionValueClass:
208             return compareCSSValues<CSSPendingSubstitutionValue>(*this, other);
209         default:
210             ASSERT_NOT_REACHED();
211             return false;
212         }
213     } else if (is<CSSValueList>(*this) && !is<CSSValueList>(other))
214         return downcast<CSSValueList>(*this).equals(other);
215     else if (!is<CSSValueList>(*this) && is<CSSValueList>(other))
216         return static_cast<const CSSValueList&>(other).equals(*this);
217     return false;
218 }
219
220 String CSSValue::cssText() const
221 {
222     switch (classType()) {
223     case AspectRatioClass:
224         return downcast<CSSAspectRatioValue>(*this).customCSSText();
225     case BorderImageSliceClass:
226         return downcast<CSSBorderImageSliceValue>(*this).customCSSText();
227     case CanvasClass:
228         return downcast<CSSCanvasValue>(*this).customCSSText();
229     case NamedImageClass:
230         return downcast<CSSNamedImageValue>(*this).customCSSText();
231     case CursorImageClass:
232         return downcast<CSSCursorImageValue>(*this).customCSSText();
233     case FilterImageClass:
234         return downcast<CSSFilterImageValue>(*this).customCSSText();
235     case FontClass:
236         return downcast<CSSFontValue>(*this).customCSSText();
237     case FontFaceSrcClass:
238         return downcast<CSSFontFaceSrcValue>(*this).customCSSText();
239     case FontFeatureClass:
240         return downcast<CSSFontFeatureValue>(*this).customCSSText();
241 #if ENABLE(VARIATION_FONTS)
242     case FontVariationClass:
243         return downcast<CSSFontVariationValue>(*this).customCSSText();
244 #endif
245     case FunctionClass:
246         return downcast<CSSFunctionValue>(*this).customCSSText();
247     case LinearGradientClass:
248         return downcast<CSSLinearGradientValue>(*this).customCSSText();
249     case RadialGradientClass:
250         return downcast<CSSRadialGradientValue>(*this).customCSSText();
251     case CrossfadeClass:
252         return downcast<CSSCrossfadeValue>(*this).customCSSText();
253     case ImageClass:
254         return downcast<CSSImageValue>(*this).customCSSText();
255     case InheritedClass:
256         return downcast<CSSInheritedValue>(*this).customCSSText();
257     case InitialClass:
258         return downcast<CSSInitialValue>(*this).customCSSText();
259     case UnsetClass:
260         return downcast<CSSUnsetValue>(*this).customCSSText();
261     case RevertClass:
262         return downcast<CSSRevertValue>(*this).customCSSText();
263     case GridAutoRepeatClass:
264         return downcast<CSSGridAutoRepeatValue>(*this).customCSSText();
265     case GridLineNamesClass:
266         return downcast<CSSGridLineNamesValue>(*this).customCSSText();
267     case GridTemplateAreasClass:
268         return downcast<CSSGridTemplateAreasValue>(*this).customCSSText();
269     case PrimitiveClass:
270         return downcast<CSSPrimitiveValue>(*this).customCSSText();
271     case ReflectClass:
272         return downcast<CSSReflectValue>(*this).customCSSText();
273     case ShadowClass:
274         return downcast<CSSShadowValue>(*this).customCSSText();
275     case CubicBezierTimingFunctionClass:
276         return downcast<CSSCubicBezierTimingFunctionValue>(*this).customCSSText();
277     case StepsTimingFunctionClass:
278         return downcast<CSSStepsTimingFunctionValue>(*this).customCSSText();
279     case SpringTimingFunctionClass:
280         return downcast<CSSSpringTimingFunctionValue>(*this).customCSSText();
281     case UnicodeRangeClass:
282         return downcast<CSSUnicodeRangeValue>(*this).customCSSText();
283     case ValueListClass:
284         return downcast<CSSValueList>(*this).customCSSText();
285     case LineBoxContainClass:
286         return downcast<CSSLineBoxContainValue>(*this).customCSSText();
287     case CalculationClass:
288         return downcast<CSSCalcValue>(*this).customCSSText();
289     case ImageSetClass:
290         return downcast<CSSImageSetValue>(*this).customCSSText();
291 #if ENABLE(CSS_ANIMATIONS_LEVEL_2)
292     case AnimationTriggerScrollClass:
293         return downcast<CSSAnimationTriggerScrollValue>(*this).customCSSText();
294 #endif
295     case CSSContentDistributionClass:
296         return downcast<CSSContentDistributionValue>(*this).customCSSText();
297     case CustomPropertyClass:
298         return downcast<CSSCustomPropertyValue>(*this).customCSSText();
299     case CustomIdentClass:
300         return downcast<CSSCustomIdentValue>(*this).customCSSText();
301     case VariableReferenceClass:
302         return downcast<CSSVariableReferenceValue>(*this).customCSSText();
303     case PendingSubstitutionValueClass:
304         return downcast<CSSPendingSubstitutionValue>(*this).customCSSText();
305     }
306
307     ASSERT_NOT_REACHED();
308     return String();
309 }
310
311 void CSSValue::destroy()
312 {
313     switch (classType()) {
314     case AspectRatioClass:
315         delete downcast<CSSAspectRatioValue>(this);
316         return;
317     case BorderImageSliceClass:
318         delete downcast<CSSBorderImageSliceValue>(this);
319         return;
320     case CanvasClass:
321         delete downcast<CSSCanvasValue>(this);
322         return;
323     case NamedImageClass:
324         delete downcast<CSSNamedImageValue>(this);
325         return;
326     case CursorImageClass:
327         delete downcast<CSSCursorImageValue>(this);
328         return;
329     case FontClass:
330         delete downcast<CSSFontValue>(this);
331         return;
332     case FontFaceSrcClass:
333         delete downcast<CSSFontFaceSrcValue>(this);
334         return;
335     case FontFeatureClass:
336         delete downcast<CSSFontFeatureValue>(this);
337         return;
338 #if ENABLE(VARIATION_FONTS)
339     case FontVariationClass:
340         delete downcast<CSSFontVariationValue>(this);
341         return;
342 #endif
343     case FunctionClass:
344         delete downcast<CSSFunctionValue>(this);
345         return;
346     case LinearGradientClass:
347         delete downcast<CSSLinearGradientValue>(this);
348         return;
349     case RadialGradientClass:
350         delete downcast<CSSRadialGradientValue>(this);
351         return;
352     case CrossfadeClass:
353         delete downcast<CSSCrossfadeValue>(this);
354         return;
355     case ImageClass:
356         delete downcast<CSSImageValue>(this);
357         return;
358     case InheritedClass:
359         delete downcast<CSSInheritedValue>(this);
360         return;
361     case InitialClass:
362         delete downcast<CSSInitialValue>(this);
363         return;
364     case UnsetClass:
365         delete downcast<CSSUnsetValue>(this);
366         return;
367     case RevertClass:
368         delete downcast<CSSRevertValue>(this);
369         return;
370     case GridAutoRepeatClass:
371         delete downcast<CSSGridAutoRepeatValue>(this);
372         return;
373     case GridLineNamesClass:
374         delete downcast<CSSGridLineNamesValue>(this);
375         return;
376     case GridTemplateAreasClass:
377         delete downcast<CSSGridTemplateAreasValue>(this);
378         return;
379     case PrimitiveClass:
380         delete downcast<CSSPrimitiveValue>(this);
381         return;
382     case ReflectClass:
383         delete downcast<CSSReflectValue>(this);
384         return;
385     case ShadowClass:
386         delete downcast<CSSShadowValue>(this);
387         return;
388     case CubicBezierTimingFunctionClass:
389         delete downcast<CSSCubicBezierTimingFunctionValue>(this);
390         return;
391     case StepsTimingFunctionClass:
392         delete downcast<CSSStepsTimingFunctionValue>(this);
393         return;
394     case SpringTimingFunctionClass:
395         delete downcast<CSSSpringTimingFunctionValue>(this);
396         return;
397     case UnicodeRangeClass:
398         delete downcast<CSSUnicodeRangeValue>(this);
399         return;
400     case ValueListClass:
401         delete downcast<CSSValueList>(this);
402         return;
403     case LineBoxContainClass:
404         delete downcast<CSSLineBoxContainValue>(this);
405         return;
406     case CalculationClass:
407         delete downcast<CSSCalcValue>(this);
408         return;
409     case ImageSetClass:
410         delete downcast<CSSImageSetValue>(this);
411         return;
412     case FilterImageClass:
413         delete downcast<CSSFilterImageValue>(this);
414         return;
415 #if ENABLE(CSS_ANIMATIONS_LEVEL_2)
416     case AnimationTriggerScrollClass:
417         delete downcast<CSSAnimationTriggerScrollValue>(this);
418         return;
419 #endif
420     case CSSContentDistributionClass:
421         delete downcast<CSSContentDistributionValue>(this);
422         return;
423     case CustomPropertyClass:
424         delete downcast<CSSCustomPropertyValue>(this);
425         return;
426     case CustomIdentClass:
427         delete downcast<CSSCustomIdentValue>(this);
428         return;
429     case VariableReferenceClass:
430         delete downcast<CSSVariableReferenceValue>(this);
431         return;
432     case PendingSubstitutionValueClass:
433         delete downcast<CSSPendingSubstitutionValue>(this);
434         return;
435     }
436     ASSERT_NOT_REACHED();
437 }
438
439 Ref<DeprecatedCSSOMValue> CSSValue::createDeprecatedCSSOMWrapper() const
440 {
441     if (isImageValue() || isCursorImageValue())
442         return downcast<CSSImageValue>(this)->createDeprecatedCSSOMWrapper();
443     if (isPrimitiveValue())
444         return DeprecatedCSSOMPrimitiveValue::create(downcast<CSSPrimitiveValue>(*this));
445     if (isValueList())
446         return DeprecatedCSSOMValueList::create(downcast<CSSValueList>(*this));
447     return DeprecatedCSSOMComplexValue::create(*this);
448 }
449
450 bool CSSValue::treatAsInheritedValue(CSSPropertyID propertyID) const
451 {
452     return classType() == InheritedClass || (classType() == UnsetClass && CSSProperty::isInheritedProperty(propertyID));
453 }
454
455 bool CSSValue::treatAsInitialValue(CSSPropertyID propertyID) const
456 {
457     return classType() == InitialClass || (classType() == UnsetClass && !CSSProperty::isInheritedProperty(propertyID));
458 }
459
460 }