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"
37 enum CSSTextFormattingFlags { QuoteCSSStringIfNeeded, AlwaysQuoteCSSString };
39 // FIXME: The current CSSValue and subclasses should be turned into internal types (StyleValue).
40 // The few subtypes that are actually exposed in CSSOM can be seen in the cloneForCSSOM() function.
41 // They should be handled by separate wrapper classes.
43 // Please don't expose more CSSValue types to the web.
44 class CSSValue : public RefCountedWillBeGarbageCollectedFinalized<CSSValue>, public ScriptWrappableBase {
48 CSS_PRIMITIVE_VALUE = 1,
55 // Override RefCounted's deref() to ensure operator delete is called on
56 // the appropriate subclass type.
57 // When oilpan is enabled the finalize method is called by the garbage
58 // collector and not immediately when deref reached zero.
65 #endif // !ENABLE(OILPAN)
67 Type cssValueType() const;
69 String cssText() const;
70 void setCSSText(const String&, ExceptionState&) { } // FIXME: Not implemented.
72 bool isPrimitiveValue() const { return m_classType == PrimitiveClass; }
73 bool isValueList() const { return m_classType >= ValueListClass; }
75 bool isBaseValueList() const { return m_classType == ValueListClass; }
77 bool isAspectRatioValue() const { return m_classType == AspectRatioClass; }
78 bool isBorderImageSliceValue() const { return m_classType == BorderImageSliceClass; }
79 bool isCanvasValue() const { return m_classType == CanvasClass; }
80 bool isCursorImageValue() const { return m_classType == CursorImageClass; }
81 bool isCrossfadeValue() const { return m_classType == CrossfadeClass; }
82 bool isFontFeatureValue() const { return m_classType == FontFeatureClass; }
83 bool isFontValue() const { return m_classType == FontClass; }
84 bool isFontFaceSrcValue() const { return m_classType == FontFaceSrcClass; }
85 bool isFunctionValue() const { return m_classType == FunctionClass; }
86 bool isImageGeneratorValue() const { return m_classType >= CanvasClass && m_classType <= RadialGradientClass; }
87 bool isGradientValue() const { return m_classType >= LinearGradientClass && m_classType <= RadialGradientClass; }
88 bool isImageSetValue() const { return m_classType == ImageSetClass; }
89 bool isImageValue() const { return m_classType == ImageClass; }
90 bool isImplicitInitialValue() const;
91 bool isInheritedValue() const { return m_classType == InheritedClass; }
92 bool isInitialValue() const { return m_classType == InitialClass; }
93 bool isLinearGradientValue() const { return m_classType == LinearGradientClass; }
94 bool isRadialGradientValue() const { return m_classType == RadialGradientClass; }
95 bool isReflectValue() const { return m_classType == ReflectClass; }
96 bool isShadowValue() const { return m_classType == ShadowClass; }
97 bool isTextCloneCSSValue() const { return m_isTextClone; }
98 bool isCubicBezierTimingFunctionValue() const { return m_classType == CubicBezierTimingFunctionClass; }
99 bool isStepsTimingFunctionValue() const { return m_classType == StepsTimingFunctionClass; }
100 bool isTransformValue() const { return m_classType == CSSTransformClass; }
101 bool isLineBoxContainValue() const { return m_classType == LineBoxContainClass; }
102 bool isCalcValue() const {return m_classType == CalculationClass; }
103 bool isFilterValue() const { return m_classType == CSSFilterClass; }
104 bool isGridTemplateAreasValue() const { return m_classType == GridTemplateAreasClass; }
105 bool isSVGDocumentValue() const { return m_classType == CSSSVGDocumentClass; }
106 bool isUnicodeRangeValue() const { return m_classType == UnicodeRangeClass; }
107 bool isGridLineNamesValue() const { return m_classType == GridLineNamesClass; }
109 bool isCSSOMSafe() const { return m_isCSSOMSafe; }
110 bool isSubtypeExposedToCSSOM() const
112 return isPrimitiveValue() || isValueList();
115 PassRefPtrWillBeRawPtr<CSSValue> cloneForCSSOM() const;
117 bool hasFailedOrCanceledSubresources() const;
119 bool equals(const CSSValue&) const;
121 void finalizeGarbageCollectedObject();
122 void traceAfterDispatch(Visitor*) { }
123 void trace(Visitor*);
127 static const size_t ClassTypeBits = 6;
135 // Image generator classes.
141 // Timing function classes.
142 CubicBezierTimingFunctionClass,
143 StepsTimingFunctionClass,
145 // Other class types.
147 BorderImageSliceClass,
161 GridTemplateAreasClass,
166 // List class types must appear after ValueListClass.
172 // Do not append non-list class types here.
175 static const size_t ValueListSeparatorBits = 2;
176 enum ValueListSeparator {
182 ClassType classType() const { return static_cast<ClassType>(m_classType); }
184 explicit CSSValue(ClassType classType, bool isCSSOMSafe = false)
185 : m_isCSSOMSafe(isCSSOMSafe)
186 , m_isTextClone(false)
187 , m_primitiveUnitType(0)
188 , m_hasCachedCSSText(false)
189 , m_isQuirkValue(false)
190 , m_valueListSeparator(SpaceSeparator)
191 , m_classType(classType)
195 // NOTE: This class is non-virtual for memory and performance reasons.
196 // Don't go making it virtual again unless you know exactly what you're doing!
204 unsigned m_isCSSOMSafe : 1;
205 unsigned m_isTextClone : 1;
206 // The bits in this section are only used by specific subclasses but kept here
207 // to maximize struct packing.
209 // CSSPrimitiveValue bits:
210 unsigned m_primitiveUnitType : 7; // CSSPrimitiveValue::UnitType
211 mutable unsigned m_hasCachedCSSText : 1;
212 unsigned m_isQuirkValue : 1;
214 unsigned m_valueListSeparator : ValueListSeparatorBits;
217 unsigned m_classType : ClassTypeBits; // ClassType
220 template<typename CSSValueType, size_t inlineCapacity>
221 inline bool compareCSSValueVector(const WillBeHeapVector<RefPtrWillBeMember<CSSValueType>, inlineCapacity>& firstVector, const WillBeHeapVector<RefPtrWillBeMember<CSSValueType>, inlineCapacity>& secondVector)
223 size_t size = firstVector.size();
224 if (size != secondVector.size())
227 for (size_t i = 0; i < size; i++) {
228 const RefPtrWillBeMember<CSSValueType>& firstPtr = firstVector[i];
229 const RefPtrWillBeMember<CSSValueType>& secondPtr = secondVector[i];
230 if (firstPtr == secondPtr || (firstPtr && secondPtr && firstPtr->equals(*secondPtr)))
237 template<typename CSSValueType>
238 inline bool compareCSSValuePtr(const RefPtr<CSSValueType>& first, const RefPtr<CSSValueType>& second)
240 return first ? second && first->equals(*second) : !second;
243 template<typename CSSValueType>
244 inline bool compareCSSValuePtr(const RawPtr<CSSValueType>& first, const RawPtr<CSSValueType>& second)
246 return first ? second && first->equals(*second) : !second;
249 template<typename CSSValueType>
250 inline bool compareCSSValuePtr(const Member<CSSValueType>& first, const Member<CSSValueType>& second)
252 return first ? second && first->equals(*second) : !second;
255 #define DEFINE_CSS_VALUE_TYPE_CASTS(thisType, predicate) \
256 DEFINE_TYPE_CASTS(thisType, CSSValue, value, value->predicate, value.predicate)