OLD | NEW |
1 /* | 1 /* |
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) | 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) |
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "core/CoreExport.h" | 24 #include "core/CoreExport.h" |
25 #include "platform/heap/Handle.h" | 25 #include "platform/heap/Handle.h" |
26 #include "platform/weborigin/KURL.h" | 26 #include "platform/weborigin/KURL.h" |
27 #include "wtf/HashMap.h" | 27 #include "wtf/HashMap.h" |
28 #include "wtf/ListHashSet.h" | 28 #include "wtf/ListHashSet.h" |
29 #include "wtf/RefCounted.h" | 29 #include "wtf/RefCounted.h" |
30 #include "wtf/RefPtr.h" | 30 #include "wtf/RefPtr.h" |
31 | 31 |
32 namespace blink { | 32 namespace blink { |
33 | 33 |
| 34 class CSSValue; |
| 35 |
| 36 struct CSSTaggedPtrValue { |
| 37 // Variables for accessing parts of the tagged pointer. |
| 38 // 32 bits = <value 25 bits><type 6 bits><tag 1 bit> |
| 39 // 64 bits = <value 57 bits><type 6 bits><tag 1 bit> |
| 40 unsigned flag : 1; |
| 41 unsigned type : 6; |
| 42 #if CPU(32BIT) |
| 43 unsigned long long value : 25; |
| 44 #elif CPU(64BIT) |
| 45 unsigned long long value : 57; |
| 46 #endif |
| 47 }; |
| 48 |
| 49 // In some cases, CSSValue is a tagged pointer. If isTaggedPtr() returns true, |
| 50 // |this| is an invalid pointer and member variables should not be accessed. |
34 class CORE_EXPORT CSSValue : public RefCountedWillBeGarbageCollectedFinalized<CS
SValue> { | 51 class CORE_EXPORT CSSValue : public RefCountedWillBeGarbageCollectedFinalized<CS
SValue> { |
35 public: | 52 public: |
36 #if ENABLE(OILPAN) | 53 #if ENABLE(OILPAN) |
37 // Override operator new to allocate CSSValue subtype objects onto | 54 // Override operator new to allocate CSSValue subtype objects onto |
38 // a dedicated heap. | 55 // a dedicated heap. |
39 GC_PLUGIN_IGNORE("crbug.com/443854") | 56 GC_PLUGIN_IGNORE("crbug.com/443854") |
40 void* operator new(size_t size) | 57 void* operator new(size_t size) |
41 { | 58 { |
42 return allocateObject(size, false); | 59 return allocateObject(size, false); |
43 } | 60 } |
44 static void* allocateObject(size_t size, bool isEager) | 61 static void* allocateObject(size_t size, bool isEager) |
45 { | 62 { |
46 ThreadState* state = ThreadStateFor<ThreadingTrait<CSSValue>::Affinity>:
:state(); | 63 ThreadState* state = ThreadStateFor<ThreadingTrait<CSSValue>::Affinity>:
:state(); |
47 return Heap::allocateOnHeapIndex(state, size, isEager ? ThreadState::Eag
erSweepHeapIndex : ThreadState::CSSValueHeapIndex, GCInfoTrait<CSSValue>::index(
)); | 64 return Heap::allocateOnHeapIndex(state, size, isEager ? ThreadState::Eag
erSweepHeapIndex : ThreadState::CSSValueHeapIndex, GCInfoTrait<CSSValue>::index(
)); |
48 } | 65 } |
49 #else | 66 #else |
| 67 void ref() |
| 68 { |
| 69 if (!isTaggedPtr()) |
| 70 RefCountedBase::ref(); |
| 71 } |
| 72 |
50 // Override RefCounted's deref() to ensure operator delete is called on | 73 // Override RefCounted's deref() to ensure operator delete is called on |
51 // the appropriate subclass type. | 74 // the appropriate subclass type. |
52 void deref() | 75 void deref() |
53 { | 76 { |
54 if (derefBase()) | 77 if (!isTaggedPtr() && derefBase()) |
55 destroy(); | 78 destroy(); |
56 } | 79 } |
57 #endif // !ENABLE(OILPAN) | 80 #endif // !ENABLE(OILPAN) |
58 | 81 |
59 String cssText() const; | 82 String cssText() const; |
60 | 83 |
61 bool isPrimitiveValue() const { return m_classType == PrimitiveClass; } | 84 bool isPrimitiveValue() const { return isTaggedPtr() || m_classType == Primi
tiveClass; } |
62 bool isValueList() const { return m_classType >= ValueListClass; } | 85 bool isValueList() const { return !isTaggedPtr() && m_classType >= ValueList
Class; } |
63 | 86 |
64 bool isBaseValueList() const { return m_classType == ValueListClass; } | 87 bool isBaseValueList() const { return !isTaggedPtr() && m_classType == Value
ListClass; } |
65 | 88 |
66 bool isBorderImageSliceValue() const { return m_classType == BorderImageSlic
eClass; } | 89 bool isBorderImageSliceValue() const { return !isTaggedPtr() && m_classType
== BorderImageSliceClass; } |
67 bool isCanvasValue() const { return m_classType == CanvasClass; } | 90 bool isCanvasValue() const { return !isTaggedPtr() && m_classType == CanvasC
lass; } |
68 bool isCursorImageValue() const { return m_classType == CursorImageClass; } | 91 bool isCursorImageValue() const { return !isTaggedPtr() && m_classType == Cu
rsorImageClass; } |
69 bool isCrossfadeValue() const { return m_classType == CrossfadeClass; } | 92 bool isCrossfadeValue() const { return !isTaggedPtr() && m_classType == Cros
sfadeClass; } |
70 bool isFontFeatureValue() const { return m_classType == FontFeatureClass; } | 93 bool isFontFeatureValue() const { return !isTaggedPtr() && m_classType == Fo
ntFeatureClass; } |
71 bool isFontFaceSrcValue() const { return m_classType == FontFaceSrcClass; } | 94 bool isFontFaceSrcValue() const { return !isTaggedPtr() && m_classType == Fo
ntFaceSrcClass; } |
72 bool isFunctionValue() const { return m_classType == FunctionClass; } | 95 bool isFunctionValue() const { return !isTaggedPtr() && m_classType == Funct
ionClass; } |
73 bool isImageGeneratorValue() const { return m_classType >= CanvasClass && m_
classType <= RadialGradientClass; } | 96 bool isImageGeneratorValue() const { return !isTaggedPtr() && m_classType >=
CanvasClass && m_classType <= RadialGradientClass; } |
74 bool isGradientValue() const { return m_classType >= LinearGradientClass &&
m_classType <= RadialGradientClass; } | 97 bool isGradientValue() const { return !isTaggedPtr() && m_classType >= Linea
rGradientClass && m_classType <= RadialGradientClass; } |
75 bool isImageSetValue() const { return m_classType == ImageSetClass; } | 98 bool isImageSetValue() const { return !isTaggedPtr() && m_classType == Image
SetClass; } |
76 bool isImageValue() const { return m_classType == ImageClass; } | 99 bool isImageValue() const { return !isTaggedPtr() && m_classType == ImageCla
ss; } |
77 bool isImplicitInitialValue() const; | 100 bool isImplicitInitialValue() const; |
78 bool isInheritedValue() const { return m_classType == InheritedClass; } | 101 bool isInheritedValue() const { return !isTaggedPtr() && m_classType == Inhe
ritedClass; } |
79 bool isInitialValue() const { return m_classType == InitialClass; } | 102 bool isInitialValue() const { return !isTaggedPtr() && m_classType == Initia
lClass; } |
80 bool isUnsetValue() const { return m_classType == UnsetClass; } | 103 bool isUnsetValue() const { return !isTaggedPtr() && m_classType == UnsetCla
ss; } |
81 bool isCSSWideKeyword() const { return m_classType >= InheritedClass && m_cl
assType <= UnsetClass; } | 104 bool isCSSWideKeyword() const { return !isTaggedPtr() && m_classType >= Inhe
ritedClass && m_classType <= UnsetClass; } |
82 bool isLinearGradientValue() const { return m_classType == LinearGradientCla
ss; } | 105 bool isLinearGradientValue() const { return !isTaggedPtr() && m_classType ==
LinearGradientClass; } |
83 bool isPathValue() const { return m_classType == PathClass; } | 106 bool isPathValue() const { return !isTaggedPtr() && m_classType == PathClass
; } |
84 bool isRadialGradientValue() const { return m_classType == RadialGradientCla
ss; } | 107 bool isRadialGradientValue() const { return !isTaggedPtr() && m_classType ==
RadialGradientClass; } |
85 bool isReflectValue() const { return m_classType == ReflectClass; } | 108 bool isReflectValue() const { return !isTaggedPtr() && m_classType == Reflec
tClass; } |
86 bool isShadowValue() const { return m_classType == ShadowClass; } | 109 bool isShadowValue() const { return !isTaggedPtr() && m_classType == ShadowC
lass; } |
87 bool isCubicBezierTimingFunctionValue() const { return m_classType == CubicB
ezierTimingFunctionClass; } | 110 bool isCubicBezierTimingFunctionValue() const { return !isTaggedPtr() && m_c
lassType == CubicBezierTimingFunctionClass; } |
88 bool isStepsTimingFunctionValue() const { return m_classType == StepsTimingF
unctionClass; } | 111 bool isStepsTimingFunctionValue() const { return !isTaggedPtr() && m_classTy
pe == StepsTimingFunctionClass; } |
89 bool isLineBoxContainValue() const { return m_classType == LineBoxContainCla
ss; } | 112 bool isLineBoxContainValue() const { return !isTaggedPtr() && m_classType ==
LineBoxContainClass; } |
90 bool isCalcValue() const {return m_classType == CalculationClass; } | 113 bool isCalcValue() const {return !isTaggedPtr() && m_classType == Calculatio
nClass; } |
91 bool isGridTemplateAreasValue() const { return m_classType == GridTemplateAr
easClass; } | 114 bool isGridTemplateAreasValue() const { return !isTaggedPtr() && m_classType
== GridTemplateAreasClass; } |
92 bool isSVGDocumentValue() const { return m_classType == CSSSVGDocumentClass;
} | 115 bool isSVGDocumentValue() const { return !isTaggedPtr() && m_classType == CS
SSVGDocumentClass; } |
93 bool isContentDistributionValue() const { return m_classType == CSSContentDi
stributionClass; } | 116 bool isContentDistributionValue() const { return !isTaggedPtr() && m_classTy
pe == CSSContentDistributionClass; } |
94 bool isUnicodeRangeValue() const { return m_classType == UnicodeRangeClass;
} | 117 bool isUnicodeRangeValue() const { return !isTaggedPtr() && m_classType == U
nicodeRangeClass; } |
95 bool isGridLineNamesValue() const { return m_classType == GridLineNamesClass
; } | 118 bool isGridLineNamesValue() const { return !isTaggedPtr() && m_classType ==
GridLineNamesClass; } |
96 | 119 |
97 bool hasFailedOrCanceledSubresources() const; | 120 bool hasFailedOrCanceledSubresources() const; |
98 | 121 |
99 bool equals(const CSSValue&) const; | 122 bool equals(const CSSValue&) const; |
100 | 123 |
101 void finalizeGarbageCollectedObject(); | 124 void finalizeGarbageCollectedObject(); |
102 DEFINE_INLINE_TRACE_AFTER_DISPATCH() { } | 125 DEFINE_INLINE_TRACE_AFTER_DISPATCH() { } |
103 DECLARE_TRACE(); | 126 DECLARE_TRACE(); |
104 | 127 |
105 // ~CSSValue should be public, because non-public ~CSSValue causes C2248 | 128 // ~CSSValue should be public, because non-public ~CSSValue causes C2248 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 | 190 |
168 ClassType classType() const { return static_cast<ClassType>(m_classType); } | 191 ClassType classType() const { return static_cast<ClassType>(m_classType); } |
169 | 192 |
170 explicit CSSValue(ClassType classType) | 193 explicit CSSValue(ClassType classType) |
171 : m_primitiveUnitType(0) | 194 : m_primitiveUnitType(0) |
172 , m_hasCachedCSSText(false) | 195 , m_hasCachedCSSText(false) |
173 , m_isQuirkValue(false) | 196 , m_isQuirkValue(false) |
174 , m_valueListSeparator(SpaceSeparator) | 197 , m_valueListSeparator(SpaceSeparator) |
175 , m_classType(classType) | 198 , m_classType(classType) |
176 { | 199 { |
| 200 ASSERT(!isTaggedPtr()); |
177 } | 201 } |
178 | 202 |
179 // NOTE: This class is non-virtual for memory and performance reasons. | 203 // NOTE: This class is non-virtual for memory and performance reasons. |
180 // Don't go making it virtual again unless you know exactly what you're doin
g! | 204 // Don't go making it virtual again unless you know exactly what you're doin
g! |
181 | 205 |
182 private: | 206 private: |
183 void destroy(); | 207 void destroy(); |
184 | 208 |
185 protected: | 209 protected: |
186 // The bits in this section are only used by specific subclasses but kept he
re | 210 // The bits in this section are only used by specific subclasses but kept he
re |
187 // to maximize struct packing. | 211 // to maximize struct packing. |
188 | 212 |
189 // CSSPrimitiveValue bits: | 213 // CSSPrimitiveValue bits: |
190 unsigned m_primitiveUnitType : 7; // CSSPrimitiveValue::UnitType | 214 unsigned m_primitiveUnitType : 7; // CSSPrimitiveValue::UnitType |
191 mutable unsigned m_hasCachedCSSText : 1; | 215 mutable unsigned m_hasCachedCSSText : 1; |
192 unsigned m_isQuirkValue : 1; | 216 unsigned m_isQuirkValue : 1; |
193 | 217 |
194 unsigned m_valueListSeparator : ValueListSeparatorBits; | 218 unsigned m_valueListSeparator : ValueListSeparatorBits; |
195 | 219 |
196 private: | 220 private: |
197 unsigned m_classType : ClassTypeBits; // ClassType | 221 unsigned m_classType : ClassTypeBits; // ClassType |
| 222 |
| 223 inline bool isTaggedPtr() const |
| 224 { |
| 225 return reinterpret_cast<uintptr_t>(this) & 1; |
| 226 } |
198 }; | 227 }; |
199 | 228 |
200 template<typename CSSValueType, size_t inlineCapacity> | 229 template<typename CSSValueType, size_t inlineCapacity> |
201 inline bool compareCSSValueVector(const WillBeHeapVector<RefPtrWillBeMember<CSSV
alueType>, inlineCapacity>& firstVector, const WillBeHeapVector<RefPtrWillBeMemb
er<CSSValueType>, inlineCapacity>& secondVector) | 230 inline bool compareCSSValueVector(const WillBeHeapVector<RefPtrWillBeMember<CSSV
alueType>, inlineCapacity>& firstVector, const WillBeHeapVector<RefPtrWillBeMemb
er<CSSValueType>, inlineCapacity>& secondVector) |
202 { | 231 { |
203 size_t size = firstVector.size(); | 232 size_t size = firstVector.size(); |
204 if (size != secondVector.size()) | 233 if (size != secondVector.size()) |
205 return false; | 234 return false; |
206 | 235 |
207 for (size_t i = 0; i < size; i++) { | 236 for (size_t i = 0; i < size; i++) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 if (!first || !second) | 271 if (!first || !second) |
243 return false; | 272 return false; |
244 return first->equals(*second); | 273 return first->equals(*second); |
245 } | 274 } |
246 | 275 |
247 #define DEFINE_CSS_VALUE_TYPE_CASTS(thisType, predicate) \ | 276 #define DEFINE_CSS_VALUE_TYPE_CASTS(thisType, predicate) \ |
248 DEFINE_TYPE_CASTS(thisType, CSSValue, value, value->predicate, value.predica
te) | 277 DEFINE_TYPE_CASTS(thisType, CSSValue, value, value->predicate, value.predica
te) |
249 | 278 |
250 } // namespace blink | 279 } // namespace blink |
251 | 280 |
| 281 namespace WTF { |
| 282 |
| 283 #if !ENABLE(OILPAN) |
| 284 // Must be defined *after* CSSValue to compile with the correct adopted() method
. |
| 285 template<> inline PassRefPtr<blink::CSSValue> adoptRef(blink::CSSValue* p) |
| 286 { |
| 287 // Immediates (non-pointers) end in a 1. |
| 288 if (!(reinterpret_cast<uintptr_t>(p) & 1)) |
| 289 WTF::adopted(p); |
| 290 return PassRefPtr<blink::CSSValue>(p, PassRefPtr<blink::CSSValue>::AdoptRef)
; |
| 291 } |
| 292 #endif |
| 293 |
| 294 } // namespace WTF |
| 295 |
252 #endif // CSSValue_h | 296 #endif // CSSValue_h |
OLD | NEW |