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 #if ENABLE(OILPAN) && USE_4BYTE_HEADER_PADDING |
| 35 #define BIT_FIELD reinterpret_cast<HeapObjectHeader*>(reinterpret_cast<uint8_t*>
(static_cast<CSSValue*>(const_cast<CSSValue*>(this))) - sizeof(HeapObjectHeader)
)->m_padding |
| 36 #else |
| 37 #define BIT_FIELD m_bitField |
| 38 #endif |
| 39 |
34 class CORE_EXPORT CSSValue : public RefCountedWillBeGarbageCollectedFinalized<CS
SValue> { | 40 class CORE_EXPORT CSSValue : public RefCountedWillBeGarbageCollectedFinalized<CS
SValue> { |
35 public: | 41 public: |
36 #if ENABLE(OILPAN) | 42 #if ENABLE(OILPAN) |
37 // Override operator new to allocate CSSValue subtype objects onto | 43 // Override operator new to allocate CSSValue subtype objects onto |
38 // a dedicated heap. | 44 // a dedicated heap. |
39 GC_PLUGIN_IGNORE("crbug.com/443854") | 45 GC_PLUGIN_IGNORE("crbug.com/443854") |
40 void* operator new(size_t size) | 46 void* operator new(size_t size) |
41 { | 47 { |
42 return allocateObject(size, false); | 48 void* result = allocateObject(size, false); |
| 49 // fprintf(stderr, "%p %ld\n", result, size); |
| 50 return result; |
43 } | 51 } |
44 static void* allocateObject(size_t size, bool isEager) | 52 static void* allocateObject(size_t size, bool isEager) |
45 { | 53 { |
46 ThreadState* state = ThreadStateFor<ThreadingTrait<CSSValue>::Affinity>:
:state(); | 54 ThreadState* state = ThreadStateFor<ThreadingTrait<CSSValue>::Affinity>:
:state(); |
47 return Heap::allocateOnHeapIndex(state, size, isEager ? ThreadState::Eag
erSweepHeapIndex : ThreadState::CSSValueHeapIndex, GCInfoTrait<CSSValue>::index(
)); | 55 return Heap::allocateOnHeapIndex(state, size, isEager ? ThreadState::Eag
erSweepHeapIndex : ThreadState::CSSValueHeapIndex, GCInfoTrait<CSSValue>::index(
)); |
48 } | 56 } |
49 #else | 57 #else |
50 // Override RefCounted's deref() to ensure operator delete is called on | 58 // Override RefCounted's deref() to ensure operator delete is called on |
51 // the appropriate subclass type. | 59 // the appropriate subclass type. |
52 void deref() | 60 void deref() |
53 { | 61 { |
54 if (derefBase()) | 62 if (derefBase()) |
55 destroy(); | 63 destroy(); |
56 } | 64 } |
57 #endif // !ENABLE(OILPAN) | 65 #endif // !ENABLE(OILPAN) |
58 | 66 |
59 String cssText() const; | 67 String cssText() const; |
60 | 68 |
61 bool isPrimitiveValue() const { return m_classType == PrimitiveClass; } | 69 bool isPrimitiveValue() const { return classType() == PrimitiveClass; } |
62 bool isValueList() const { return m_classType >= ValueListClass; } | 70 bool isValueList() const { return classType() >= ValueListClass; } |
63 | 71 |
64 bool isBaseValueList() const { return m_classType == ValueListClass; } | 72 bool isBaseValueList() const { return classType() == ValueListClass; } |
65 | 73 |
66 bool isBorderImageSliceValue() const { return m_classType == BorderImageSlic
eClass; } | 74 bool isBorderImageSliceValue() const { return classType() == BorderImageSlic
eClass; } |
67 bool isCanvasValue() const { return m_classType == CanvasClass; } | 75 bool isCanvasValue() const { return classType() == CanvasClass; } |
68 bool isCounterValue() const { return m_classType == CounterClass; } | 76 bool isCounterValue() const { return classType() == CounterClass; } |
69 bool isCursorImageValue() const { return m_classType == CursorImageClass; } | 77 bool isCursorImageValue() const { return classType() == CursorImageClass; } |
70 bool isCrossfadeValue() const { return m_classType == CrossfadeClass; } | 78 bool isCrossfadeValue() const { return classType() == CrossfadeClass; } |
71 bool isFontFeatureValue() const { return m_classType == FontFeatureClass; } | 79 bool isFontFeatureValue() const { return classType() == FontFeatureClass; } |
72 bool isFontFaceSrcValue() const { return m_classType == FontFaceSrcClass; } | 80 bool isFontFaceSrcValue() const { return classType() == FontFaceSrcClass; } |
73 bool isFunctionValue() const { return m_classType == FunctionClass; } | 81 bool isFunctionValue() const { return classType() == FunctionClass; } |
74 bool isImageGeneratorValue() const { return m_classType >= CanvasClass && m_
classType <= RadialGradientClass; } | 82 bool isImageGeneratorValue() const { return classType() >= CanvasClass && cl
assType() <= RadialGradientClass; } |
75 bool isGradientValue() const { return m_classType >= LinearGradientClass &&
m_classType <= RadialGradientClass; } | 83 bool isGradientValue() const { return classType() >= LinearGradientClass &&
classType() <= RadialGradientClass; } |
76 bool isImageSetValue() const { return m_classType == ImageSetClass; } | 84 bool isImageSetValue() const { return classType() == ImageSetClass; } |
77 bool isImageValue() const { return m_classType == ImageClass; } | 85 bool isImageValue() const { return classType() == ImageClass; } |
78 bool isImplicitInitialValue() const; | 86 bool isImplicitInitialValue() const; |
79 bool isInheritedValue() const { return m_classType == InheritedClass; } | 87 bool isInheritedValue() const { return classType() == InheritedClass; } |
80 bool isInitialValue() const { return m_classType == InitialClass; } | 88 bool isInitialValue() const { return classType() == InitialClass; } |
81 bool isUnsetValue() const { return m_classType == UnsetClass; } | 89 bool isUnsetValue() const { return classType() == UnsetClass; } |
82 bool isCSSWideKeyword() const { return m_classType >= InheritedClass && m_cl
assType <= UnsetClass; } | 90 bool isCSSWideKeyword() const { return classType() >= InheritedClass && clas
sType() <= UnsetClass; } |
83 bool isLinearGradientValue() const { return m_classType == LinearGradientCla
ss; } | 91 bool isLinearGradientValue() const { return classType() == LinearGradientCla
ss; } |
84 bool isPathValue() const { return m_classType == PathClass; } | 92 bool isPathValue() const { return classType() == PathClass; } |
85 bool isRadialGradientValue() const { return m_classType == RadialGradientCla
ss; } | 93 bool isRadialGradientValue() const { return classType() == RadialGradientCla
ss; } |
86 bool isReflectValue() const { return m_classType == ReflectClass; } | 94 bool isReflectValue() const { return classType() == ReflectClass; } |
87 bool isShadowValue() const { return m_classType == ShadowClass; } | 95 bool isShadowValue() const { return classType() == ShadowClass; } |
88 bool isCubicBezierTimingFunctionValue() const { return m_classType == CubicB
ezierTimingFunctionClass; } | 96 bool isCubicBezierTimingFunctionValue() const { return classType() == CubicB
ezierTimingFunctionClass; } |
89 bool isStepsTimingFunctionValue() const { return m_classType == StepsTimingF
unctionClass; } | 97 bool isStepsTimingFunctionValue() const { return classType() == StepsTimingF
unctionClass; } |
90 bool isLineBoxContainValue() const { return m_classType == LineBoxContainCla
ss; } | 98 bool isLineBoxContainValue() const { return classType() == LineBoxContainCla
ss; } |
91 bool isGridTemplateAreasValue() const { return m_classType == GridTemplateAr
easClass; } | 99 bool isGridTemplateAreasValue() const { return classType() == GridTemplateAr
easClass; } |
92 bool isSVGDocumentValue() const { return m_classType == CSSSVGDocumentClass;
} | 100 bool isSVGDocumentValue() const { return classType() == CSSSVGDocumentClass;
} |
93 bool isContentDistributionValue() const { return m_classType == CSSContentDi
stributionClass; } | 101 bool isContentDistributionValue() const { return classType() == CSSContentDi
stributionClass; } |
94 bool isUnicodeRangeValue() const { return m_classType == UnicodeRangeClass;
} | 102 bool isUnicodeRangeValue() const { return classType() == UnicodeRangeClass;
} |
95 bool isGridLineNamesValue() const { return m_classType == GridLineNamesClass
; } | 103 bool isGridLineNamesValue() const { return classType() == GridLineNamesClass
; } |
96 | 104 |
97 bool hasFailedOrCanceledSubresources() const; | 105 bool hasFailedOrCanceledSubresources() const; |
98 | 106 |
99 bool equals(const CSSValue&) const; | 107 bool equals(const CSSValue&) const; |
100 | 108 |
101 void finalizeGarbageCollectedObject(); | 109 void finalizeGarbageCollectedObject(); |
102 DEFINE_INLINE_TRACE_AFTER_DISPATCH() { } | 110 DEFINE_INLINE_TRACE_AFTER_DISPATCH() { } |
103 DECLARE_TRACE(); | 111 DECLARE_TRACE(); |
104 | 112 |
105 // ~CSSValue should be public, because non-public ~CSSValue causes C2248 | 113 // ~CSSValue should be public, because non-public ~CSSValue causes C2248 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 // Do not append non-list class types here. | 166 // Do not append non-list class types here. |
159 }; | 167 }; |
160 | 168 |
161 static const size_t ValueListSeparatorBits = 2; | 169 static const size_t ValueListSeparatorBits = 2; |
162 enum ValueListSeparator { | 170 enum ValueListSeparator { |
163 SpaceSeparator, | 171 SpaceSeparator, |
164 CommaSeparator, | 172 CommaSeparator, |
165 SlashSeparator | 173 SlashSeparator |
166 }; | 174 }; |
167 | 175 |
168 ClassType classType() const { return static_cast<ClassType>(m_classType); } | |
169 | |
170 explicit CSSValue(ClassType classType) | 176 explicit CSSValue(ClassType classType) |
171 : m_primitiveUnitType(0) | |
172 , m_hasCachedCSSText(false) | |
173 , m_isQuirkValue(false) | |
174 , m_valueListSeparator(SpaceSeparator) | |
175 , m_classType(classType) | |
176 { | 177 { |
| 178 setClassType(classType); |
| 179 setValueListSeparator(SpaceSeparator); |
| 180 setHasCachedCSSText(false); |
| 181 setPrimitiveUnitType(0); |
| 182 setIsQuirkValue(false); |
177 } | 183 } |
178 | 184 |
179 // NOTE: This class is non-virtual for memory and performance reasons. | 185 // 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! | 186 // Don't go making it virtual again unless you know exactly what you're doin
g! |
181 | 187 |
| 188 public: |
| 189 unsigned primitiveUnitType() const { return getBitField(10, 7); } |
| 190 void setPrimitiveUnitType(unsigned value) { setBitField(10, 7, value); } |
| 191 bool isQuirkValue() const { return getBitField(9, 1); } |
| 192 void setIsQuirkValue(bool value) { setBitField(9, 1, value); } |
| 193 bool hasCachedCSSText() const { return getBitField(8, 1); } |
| 194 void setHasCachedCSSText(bool value) { setBitField(8, 1, value); } |
| 195 unsigned valueListSeparator() const { return getBitField(6, 2); } |
| 196 void setValueListSeparator(unsigned value) { setBitField(6, 2, value); } |
| 197 ClassType classType() const { return static_cast<ClassType>(getBitField(0, 6
)); } |
| 198 void setClassType(ClassType value) { setBitField(0, 6, value); } |
| 199 |
182 private: | 200 private: |
| 201 unsigned getBitField(unsigned offset, unsigned length) const |
| 202 { |
| 203 return (BIT_FIELD >> offset) & ((1 << length) - 1); |
| 204 } |
| 205 void setBitField(unsigned offset, unsigned length, unsigned value) |
| 206 { |
| 207 unsigned lower = getBitField(0, offset); |
| 208 unsigned higher = getBitField(length + offset, 32 - length - offset); |
| 209 BIT_FIELD = (higher << (length + offset)) | (value << offset) | lower; |
| 210 } |
| 211 |
183 void destroy(); | 212 void destroy(); |
184 | 213 |
185 protected: | |
186 // The bits in this section are only used by specific subclasses but kept he
re | 214 // The bits in this section are only used by specific subclasses but kept he
re |
187 // to maximize struct packing. | 215 // to maximize struct packing. |
188 | 216 |
| 217 #if !(ENABLE(OILPAN) && USE_4BYTE_HEADER_PADDING) |
189 // CSSPrimitiveValue bits: | 218 // CSSPrimitiveValue bits: |
| 219 unsigned m_bitField; |
| 220 #endif |
| 221 |
| 222 /* |
190 unsigned m_primitiveUnitType : 7; // CSSPrimitiveValue::UnitType | 223 unsigned m_primitiveUnitType : 7; // CSSPrimitiveValue::UnitType |
191 mutable unsigned m_hasCachedCSSText : 1; | 224 unsigned m_hasCachedCSSText : 1; |
192 unsigned m_isQuirkValue : 1; | 225 unsigned m_isQuirkValue : 1; |
193 | 226 unsigned m_valueListSeparator : 2; |
194 unsigned m_valueListSeparator : ValueListSeparatorBits; | 227 unsigned m_classType : 6; // ClassType |
195 | 228 */ |
196 private: | |
197 unsigned m_classType : ClassTypeBits; // ClassType | |
198 }; | 229 }; |
199 | 230 |
200 template<typename CSSValueType, size_t inlineCapacity> | 231 template<typename CSSValueType, size_t inlineCapacity> |
201 inline bool compareCSSValueVector(const WillBeHeapVector<RefPtrWillBeMember<CSSV
alueType>, inlineCapacity>& firstVector, const WillBeHeapVector<RefPtrWillBeMemb
er<CSSValueType>, inlineCapacity>& secondVector) | 232 inline bool compareCSSValueVector(const WillBeHeapVector<RefPtrWillBeMember<CSSV
alueType>, inlineCapacity>& firstVector, const WillBeHeapVector<RefPtrWillBeMemb
er<CSSValueType>, inlineCapacity>& secondVector) |
202 { | 233 { |
203 size_t size = firstVector.size(); | 234 size_t size = firstVector.size(); |
204 if (size != secondVector.size()) | 235 if (size != secondVector.size()) |
205 return false; | 236 return false; |
206 | 237 |
207 for (size_t i = 0; i < size; i++) { | 238 for (size_t i = 0; i < size; i++) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 return false; | 274 return false; |
244 return first->equals(*second); | 275 return first->equals(*second); |
245 } | 276 } |
246 | 277 |
247 #define DEFINE_CSS_VALUE_TYPE_CASTS(thisType, predicate) \ | 278 #define DEFINE_CSS_VALUE_TYPE_CASTS(thisType, predicate) \ |
248 DEFINE_TYPE_CASTS(thisType, CSSValue, value, value->predicate, value.predica
te) | 279 DEFINE_TYPE_CASTS(thisType, CSSValue, value, value->predicate, value.predica
te) |
249 | 280 |
250 } // namespace blink | 281 } // namespace blink |
251 | 282 |
252 #endif // CSSValue_h | 283 #endif // CSSValue_h |
OLD | NEW |