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 "bindings/core/v8/ScriptWrappable.h"
25 #include "core/dom/ExceptionCode.h"
26 #include "platform/heap/Handle.h"
27 #include "platform/weborigin/KURL.h"
28 #include "wtf/HashMap.h"
29 #include "wtf/ListHashSet.h"
30 #include "wtf/RefCounted.h"
31 #include "wtf/RefPtr.h"
36 class StyleSheetContents;
38 enum CSSTextFormattingFlags { QuoteCSSStringIfNeeded, AlwaysQuoteCSSString };
40 // FIXME: The current CSSValue and subclasses should be turned into internal types (StyleValue).
41 // The few subtypes that are actually exposed in CSSOM can be seen in the cloneForCSSOM() function.
42 // They should be handled by separate wrapper classes.
44 // Please don't expose more CSSValue types to the web.
45 class CSSValue : public RefCountedWillBeGarbageCollectedFinalized<CSSValue>, public ScriptWrappableBase {
49 CSS_PRIMITIVE_VALUE = 1,
56 // Override RefCounted's deref() to ensure operator delete is called on
57 // the appropriate subclass type.
58 // When oilpan is enabled the finalize method is called by the garbage
59 // collector and not immediately when deref reached zero.
66 #endif // !ENABLE(OILPAN)
68 Type cssValueType() const;
70 String cssText() const;
71 void setCSSText(const String&, ExceptionState&) { } // FIXME: Not implemented.
73 bool isPrimitiveValue() const { return m_classType == PrimitiveClass; }
74 bool isValueList() const { return m_classType >= ValueListClass; }
76 bool isBaseValueList() const { return m_classType == ValueListClass; }
78 bool isAspectRatioValue() const { return m_classType == AspectRatioClass; }
79 bool isBorderImageSliceValue() const { return m_classType == BorderImageSliceClass; }
80 bool isCanvasValue() const { return m_classType == CanvasClass; }
81 bool isCursorImageValue() const { return m_classType == CursorImageClass; }
82 bool isCrossfadeValue() const { return m_classType == CrossfadeClass; }
83 bool isFontFeatureValue() const { return m_classType == FontFeatureClass; }
84 bool isFontValue() const { return m_classType == FontClass; }
85 bool isFontFaceSrcValue() const { return m_classType == FontFaceSrcClass; }
86 bool isFunctionValue() const { return m_classType == FunctionClass; }
87 bool isImageGeneratorValue() const { return m_classType >= CanvasClass && m_classType <= RadialGradientClass; }
88 bool isGradientValue() const { return m_classType >= LinearGradientClass && m_classType <= RadialGradientClass; }
89 bool isImageSetValue() const { return m_classType == ImageSetClass; }
90 bool isImageValue() const { return m_classType == ImageClass; }
91 bool isImplicitInitialValue() const;
92 bool isInheritedValue() const { return m_classType == InheritedClass; }
93 bool isInitialValue() const { return m_classType == InitialClass; }
94 bool isLinearGradientValue() const { return m_classType == LinearGradientClass; }
95 bool isRadialGradientValue() const { return m_classType == RadialGradientClass; }
96 bool isReflectValue() const { return m_classType == ReflectClass; }
97 bool isShadowValue() const { return m_classType == ShadowClass; }
98 bool isTextCloneCSSValue() const { return m_isTextClone; }
99 bool isCubicBezierTimingFunctionValue() const { return m_classType == CubicBezierTimingFunctionClass; }
100 bool isStepsTimingFunctionValue() const { return m_classType == StepsTimingFunctionClass; }
101 bool isTransformValue() const { return m_classType == CSSTransformClass; }
102 bool isLineBoxContainValue() const { return m_classType == LineBoxContainClass; }
103 bool isCalcValue() const {return m_classType == CalculationClass; }
104 bool isFilterValue() const { return m_classType == CSSFilterClass; }
105 bool isGridTemplateAreasValue() const { return m_classType == GridTemplateAreasClass; }
106 bool isSVGDocumentValue() const { return m_classType == CSSSVGDocumentClass; }
107 bool isUnicodeRangeValue() const { return m_classType == UnicodeRangeClass; }
108 bool isGridLineNamesValue() const { return m_classType == GridLineNamesClass; }
110 bool isCSSOMSafe() const { return m_isCSSOMSafe; }
111 bool isSubtypeExposedToCSSOM() const
113 return isPrimitiveValue() || isValueList();
116 PassRefPtrWillBeRawPtr<CSSValue> cloneForCSSOM() const;
118 bool hasFailedOrCanceledSubresources() const;
120 bool equals(const CSSValue&) const;
122 void finalizeGarbageCollectedObject();
123 void traceAfterDispatch(Visitor*) { }
124 void trace(Visitor*);
128 static const size_t ClassTypeBits = 6;
136 // Image generator classes.
142 // Timing function classes.
143 CubicBezierTimingFunctionClass,
144 StepsTimingFunctionClass,
146 // Other class types.
148 BorderImageSliceClass,
162 GridTemplateAreasClass,
167 // List class types must appear after ValueListClass.
173 // Do not append non-list class types here.
176 static const size_t ValueListSeparatorBits = 2;
177 enum ValueListSeparator {
183 ClassType classType() const { return static_cast<ClassType>(m_classType); }
185 explicit CSSValue(ClassType classType, bool isCSSOMSafe = false)
186 : m_isCSSOMSafe(isCSSOMSafe)
187 , m_isTextClone(false)
188 , m_primitiveUnitType(0)
189 , m_hasCachedCSSText(false)
190 , m_isQuirkValue(false)
191 , m_valueListSeparator(SpaceSeparator)
192 , m_classType(classType)
196 // NOTE: This class is non-virtual for memory and performance reasons.
197 // Don't go making it virtual again unless you know exactly what you're doing!
205 unsigned m_isCSSOMSafe : 1;
206 unsigned m_isTextClone : 1;
207 // The bits in this section are only used by specific subclasses but kept here
208 // to maximize struct packing.
210 // CSSPrimitiveValue bits:
211 unsigned m_primitiveUnitType : 7; // CSSPrimitiveValue::UnitType
212 mutable unsigned m_hasCachedCSSText : 1;
213 unsigned m_isQuirkValue : 1;
215 unsigned m_valueListSeparator : ValueListSeparatorBits;
218 unsigned m_classType : ClassTypeBits; // ClassType
221 template<typename CSSValueType, size_t inlineCapacity>
222 inline bool compareCSSValueVector(const WillBeHeapVector<RefPtrWillBeMember<CSSValueType>, inlineCapacity>& firstVector, const WillBeHeapVector<RefPtrWillBeMember<CSSValueType>, inlineCapacity>& secondVector)
224 size_t size = firstVector.size();
225 if (size != secondVector.size())
228 for (size_t i = 0; i < size; i++) {
229 const RefPtrWillBeMember<CSSValueType>& firstPtr = firstVector[i];
230 const RefPtrWillBeMember<CSSValueType>& secondPtr = secondVector[i];
231 if (firstPtr == secondPtr || (firstPtr && secondPtr && firstPtr->equals(*secondPtr)))
238 template<typename CSSValueType>
239 inline bool compareCSSValuePtr(const RefPtr<CSSValueType>& first, const RefPtr<CSSValueType>& second)
241 return first ? second && first->equals(*second) : !second;
244 template<typename CSSValueType>
245 inline bool compareCSSValuePtr(const RawPtr<CSSValueType>& first, const RawPtr<CSSValueType>& second)
247 return first ? second && first->equals(*second) : !second;
250 template<typename CSSValueType>
251 inline bool compareCSSValuePtr(const Member<CSSValueType>& first, const Member<CSSValueType>& second)
253 return first ? second && first->equals(*second) : !second;
256 #define DEFINE_CSS_VALUE_TYPE_CASTS(thisType, predicate) \
257 DEFINE_TYPE_CASTS(thisType, CSSValue, value, value->predicate, value.predicate)