2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
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.
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.
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.
24 #include "ExceptionCode.h"
26 #include <wtf/ListHashSet.h>
27 #include <wtf/RefCounted.h>
28 #include <wtf/RefPtr.h>
32 class StyleSheetContents;
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.
38 // Please don't expose more CSSValue types to the web.
39 class CSSValue : public RefCounted<CSSValue> {
43 CSS_PRIMITIVE_VALUE = 1,
50 // Override RefCounted's deref() to ensure operator delete is called on
51 // the appropriate subclass type.
58 Type cssValueType() const;
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;
66 bool isPrimitiveValue() const { return m_classType == PrimitiveClass; }
67 bool isValueList() const { return m_classType >= ValueListClass; }
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; }
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; }
96 #endif // ENABLE(CSS_FILTERS)
97 #if ENABLE(CSS_VARIABLES)
98 bool isVariableValue() const { return m_classType == VariableClass; }
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; }
106 bool isCSSOMSafe() const { return m_isCSSOMSafe; }
107 bool isSubtypeExposedToCSSOM() const
109 return isPrimitiveValue()
116 PassRefPtr<CSSValue> cloneForCSSOM() const;
118 void addSubresourceStyleURLs(ListHashSet<KURL>&, const StyleSheetContents*) const;
122 static const size_t ClassTypeBits = 5;
130 // Image generator classes.
136 // Timing function classes.
137 CubicBezierTimingFunctionClass,
138 LinearTimingFunctionClass,
139 StepsTimingFunctionClass,
141 // Other class types.
143 BorderImageSliceClass,
157 #if ENABLE(CSS_FILTERS) && ENABLE(CSS_SHADERS)
158 WebKitCSSShaderClass,
160 #if ENABLE(CSS_VARIABLES)
166 WebKitCSSSVGDocumentClass,
169 // List class types must appear after ValueListClass.
171 #if ENABLE(CSS_IMAGE_SET)
174 #if ENABLE(CSS_FILTERS)
175 WebKitCSSFilterClass,
177 WebKitCSSTransformClass,
178 // Do not append non-list class types here.
181 static const size_t ValueListSeparatorBits = 2;
182 enum ValueListSeparator {
188 ClassType classType() const { return static_cast<ClassType>(m_classType); }
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)
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!
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.
215 // CSSPrimitiveValue bits:
216 unsigned m_primitiveUnitType : 7; // CSSPrimitiveValue::UnitTypes
217 mutable unsigned m_hasCachedCSSText : 1;
218 unsigned m_isQuirkValue : 1;
220 unsigned m_valueListSeparator : ValueListSeparatorBits;
223 unsigned m_classType : ClassTypeBits; // ClassType
226 } // namespace WebCore