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, 2008, 2012 Apple Inc. All rights reserved. | 3 * Copyright (C) 2004, 2005, 2006, 2008, 2012 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 23 matching lines...) Expand all Loading... | |
34 | 34 |
35 class CSSRule; | 35 class CSSRule; |
36 class CSSStyleDeclaration; | 36 class CSSStyleDeclaration; |
37 class Element; | 37 class Element; |
38 class ImmutableStylePropertySet; | 38 class ImmutableStylePropertySet; |
39 class KURL; | 39 class KURL; |
40 class MutableStylePropertySet; | 40 class MutableStylePropertySet; |
41 class StylePropertyShorthand; | 41 class StylePropertyShorthand; |
42 class StyleSheetContents; | 42 class StyleSheetContents; |
43 | 43 |
44 class StylePropertySet : public RefCounted<StylePropertySet> { | 44 class StylePropertySet : public RefCountedWillBeRefCountedGarbageCollected<Style PropertySet> { |
45 friend class PropertyReference; | 45 friend class PropertyReference; |
46 public: | 46 public: |
47 | |
48 #if !ENABLE(OILPAN) | |
47 // Override RefCounted's deref() to ensure operator delete is called on | 49 // Override RefCounted's deref() to ensure operator delete is called on |
48 // the appropriate subclass type. | 50 // the appropriate subclass type. |
51 // When oilpan is enabled there is no need for the destructors since the | |
52 // memory management will be handled by the garbage collector. | |
49 void deref(); | 53 void deref(); |
Mads Ager (chromium)
2014/03/06 13:30:10
I think you need to have a finalize method then? I
wibling-chromium
2014/03/06 13:34:36
Thanks for catching that. I had missed the OwnPtr.
| |
54 #endif | |
50 | 55 |
51 class PropertyReference { | 56 class PropertyReference { |
52 public: | 57 public: |
53 PropertyReference(const StylePropertySet& propertySet, unsigned index) | 58 PropertyReference(const StylePropertySet& propertySet, unsigned index) |
54 : m_propertySet(propertySet) | 59 : m_propertySet(propertySet) |
55 , m_index(index) | 60 , m_index(index) |
56 { | 61 { |
57 } | 62 } |
58 | 63 |
59 CSSPropertyID id() const { return static_cast<CSSPropertyID>(propertyMet adata().m_propertyID); } | 64 CSSPropertyID id() const { return static_cast<CSSPropertyID>(propertyMet adata().m_propertyID); } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 bool hasFailedOrCanceledSubresources() const; | 115 bool hasFailedOrCanceledSubresources() const; |
111 | 116 |
112 static unsigned averageSizeInBytes(); | 117 static unsigned averageSizeInBytes(); |
113 | 118 |
114 #ifndef NDEBUG | 119 #ifndef NDEBUG |
115 void showStyle(); | 120 void showStyle(); |
116 #endif | 121 #endif |
117 | 122 |
118 bool propertyMatches(CSSPropertyID, const CSSValue*) const; | 123 bool propertyMatches(CSSPropertyID, const CSSValue*) const; |
119 | 124 |
125 void trace(Visitor*); | |
126 void traceAfterDispatch(Visitor*) { } | |
127 | |
120 protected: | 128 protected: |
121 | 129 |
122 enum { MaxArraySize = (1 << 28) - 1 }; | 130 enum { MaxArraySize = (1 << 28) - 1 }; |
123 | 131 |
124 StylePropertySet(CSSParserMode cssParserMode) | 132 StylePropertySet(CSSParserMode cssParserMode) |
125 : m_cssParserMode(cssParserMode) | 133 : m_cssParserMode(cssParserMode) |
126 , m_isMutable(true) | 134 , m_isMutable(true) |
127 , m_arraySize(0) | 135 , m_arraySize(0) |
128 { } | 136 { } |
129 | 137 |
130 StylePropertySet(CSSParserMode cssParserMode, unsigned immutableArraySize) | 138 StylePropertySet(CSSParserMode cssParserMode, unsigned immutableArraySize) |
131 : m_cssParserMode(cssParserMode) | 139 : m_cssParserMode(cssParserMode) |
132 , m_isMutable(false) | 140 , m_isMutable(false) |
133 , m_arraySize(std::min(immutableArraySize, unsigned(MaxArraySize))) | 141 , m_arraySize(std::min(immutableArraySize, unsigned(MaxArraySize))) |
134 { } | 142 { } |
135 | 143 |
136 unsigned m_cssParserMode : 3; | 144 unsigned m_cssParserMode : 3; |
137 mutable unsigned m_isMutable : 1; | 145 mutable unsigned m_isMutable : 1; |
138 unsigned m_arraySize : 28; | 146 unsigned m_arraySize : 28; |
139 | 147 |
140 friend class PropertySetCSSStyleDeclaration; | 148 friend class PropertySetCSSStyleDeclaration; |
141 }; | 149 }; |
142 | 150 |
143 class ImmutableStylePropertySet : public StylePropertySet { | 151 class ImmutableStylePropertySet : public StylePropertySet { |
144 public: | 152 public: |
153 #if !ENABLE(OILPAN) | |
145 ~ImmutableStylePropertySet(); | 154 ~ImmutableStylePropertySet(); |
155 #endif | |
146 static PassRefPtr<ImmutableStylePropertySet> create(const CSSProperty* prope rties, unsigned count, CSSParserMode); | 156 static PassRefPtr<ImmutableStylePropertySet> create(const CSSProperty* prope rties, unsigned count, CSSParserMode); |
147 | 157 |
148 unsigned propertyCount() const { return m_arraySize; } | 158 unsigned propertyCount() const { return m_arraySize; } |
149 | 159 |
150 const CSSValue** valueArray() const; | 160 const RawPtrWillBeMember<CSSValue>* valueArray() const; |
151 const StylePropertyMetadata* metadataArray() const; | 161 const StylePropertyMetadata* metadataArray() const; |
152 int findPropertyIndex(CSSPropertyID) const; | 162 int findPropertyIndex(CSSPropertyID) const; |
153 | 163 |
164 void traceAfterDispatch(Visitor*); | |
165 | |
166 void* operator new(std::size_t, void* location) | |
167 { | |
168 return location; | |
169 } | |
170 | |
154 void* m_storage; | 171 void* m_storage; |
155 | 172 |
156 private: | 173 private: |
157 ImmutableStylePropertySet(const CSSProperty*, unsigned count, CSSParserMode) ; | 174 ImmutableStylePropertySet(const CSSProperty*, unsigned count, CSSParserMode) ; |
158 }; | 175 }; |
159 | 176 |
160 inline const CSSValue** ImmutableStylePropertySet::valueArray() const | 177 inline const RawPtrWillBeMember<CSSValue>* ImmutableStylePropertySet::valueArray () const |
161 { | 178 { |
162 return reinterpret_cast<const CSSValue**>(const_cast<const void**>(&(this->m _storage))); | 179 return reinterpret_cast<const RawPtrWillBeMember<CSSValue>*>(const_cast<cons t void**>(&(this->m_storage))); |
163 } | 180 } |
164 | 181 |
165 inline const StylePropertyMetadata* ImmutableStylePropertySet::metadataArray() c onst | 182 inline const StylePropertyMetadata* ImmutableStylePropertySet::metadataArray() c onst |
166 { | 183 { |
167 return reinterpret_cast<const StylePropertyMetadata*>(&reinterpret_cast<cons t char*>(&(this->m_storage))[m_arraySize * sizeof(CSSValue*)]); | 184 return reinterpret_cast<const StylePropertyMetadata*>(&reinterpret_cast<cons t char*>(&(this->m_storage))[m_arraySize * sizeof(RawPtrWillBeMember<CSSValue>)] ); |
168 } | 185 } |
169 | 186 |
170 DEFINE_TYPE_CASTS(ImmutableStylePropertySet, StylePropertySet, set, !set->isMuta ble(), !set.isMutable()); | 187 DEFINE_TYPE_CASTS(ImmutableStylePropertySet, StylePropertySet, set, !set->isMuta ble(), !set.isMutable()); |
171 | 188 |
172 inline ImmutableStylePropertySet* toImmutableStylePropertySet(const RefPtr<Style PropertySet>& set) | 189 inline ImmutableStylePropertySet* toImmutableStylePropertySet(const RefPtr<Style PropertySet>& set) |
173 { | 190 { |
174 return toImmutableStylePropertySet(set.get()); | 191 return toImmutableStylePropertySet(set.get()); |
175 } | 192 } |
176 | 193 |
177 class MutableStylePropertySet : public StylePropertySet { | 194 class MutableStylePropertySet : public StylePropertySet { |
178 public: | 195 public: |
196 #if !ENABLE(OILPAN) | |
179 ~MutableStylePropertySet() { } | 197 ~MutableStylePropertySet() { } |
198 #endif | |
180 static PassRefPtr<MutableStylePropertySet> create(CSSParserMode = HTMLQuirks Mode); | 199 static PassRefPtr<MutableStylePropertySet> create(CSSParserMode = HTMLQuirks Mode); |
181 static PassRefPtr<MutableStylePropertySet> create(const CSSProperty* propert ies, unsigned count); | 200 static PassRefPtr<MutableStylePropertySet> create(const CSSProperty* propert ies, unsigned count); |
182 | 201 |
183 unsigned propertyCount() const { return m_propertyVector.size(); } | 202 unsigned propertyCount() const { return m_propertyVector.size(); } |
184 | 203 |
185 void addParsedProperties(const Vector<CSSProperty, 256>&); | 204 void addParsedProperties(const WillBeHeapVector<CSSProperty, 256>&); |
186 void addParsedProperty(const CSSProperty&); | 205 void addParsedProperty(const CSSProperty&); |
187 | 206 |
188 // These expand shorthand properties into multiple properties. | 207 // These expand shorthand properties into multiple properties. |
189 bool setProperty(CSSPropertyID, const String& value, bool important = false, StyleSheetContents* contextStyleSheet = 0); | 208 bool setProperty(CSSPropertyID, const String& value, bool important = false, StyleSheetContents* contextStyleSheet = 0); |
190 void setProperty(CSSPropertyID, PassRefPtrWillBeRawPtr<CSSValue>, bool impor tant = false); | 209 void setProperty(CSSPropertyID, PassRefPtrWillBeRawPtr<CSSValue>, bool impor tant = false); |
191 | 210 |
192 // These do not. FIXME: This is too messy, we can do better. | 211 // These do not. FIXME: This is too messy, we can do better. |
193 bool setProperty(CSSPropertyID, CSSValueID identifier, bool important = fals e); | 212 bool setProperty(CSSPropertyID, CSSValueID identifier, bool important = fals e); |
194 bool setProperty(CSSPropertyID, CSSPropertyID identifier, bool important = f alse); | 213 bool setProperty(CSSPropertyID, CSSPropertyID identifier, bool important = f alse); |
195 void appendPrefixingVariantProperty(const CSSProperty&); | 214 void appendPrefixingVariantProperty(const CSSProperty&); |
196 void setPrefixingVariantProperty(const CSSProperty&); | 215 void setPrefixingVariantProperty(const CSSProperty&); |
197 void setProperty(const CSSProperty&, CSSProperty* slot = 0); | 216 void setProperty(const CSSProperty&, CSSProperty* slot = 0); |
198 | 217 |
199 bool removeProperty(CSSPropertyID, String* returnText = 0); | 218 bool removeProperty(CSSPropertyID, String* returnText = 0); |
200 void removePrefixedOrUnprefixedProperty(CSSPropertyID); | 219 void removePrefixedOrUnprefixedProperty(CSSPropertyID); |
201 void removeBlockProperties(); | 220 void removeBlockProperties(); |
202 bool removePropertiesInSet(const CSSPropertyID* set, unsigned length); | 221 bool removePropertiesInSet(const CSSPropertyID* set, unsigned length); |
203 void removeEquivalentProperties(const StylePropertySet*); | 222 void removeEquivalentProperties(const StylePropertySet*); |
204 void removeEquivalentProperties(const CSSStyleDeclaration*); | 223 void removeEquivalentProperties(const CSSStyleDeclaration*); |
205 | 224 |
206 void mergeAndOverrideOnConflict(const StylePropertySet*); | 225 void mergeAndOverrideOnConflict(const StylePropertySet*); |
207 | 226 |
208 void clear(); | 227 void clear(); |
209 void parseDeclaration(const String& styleDeclaration, StyleSheetContents* co ntextStyleSheet); | 228 void parseDeclaration(const String& styleDeclaration, StyleSheetContents* co ntextStyleSheet); |
210 | 229 |
211 CSSStyleDeclaration* ensureCSSStyleDeclaration(); | 230 CSSStyleDeclaration* ensureCSSStyleDeclaration(); |
212 int findPropertyIndex(CSSPropertyID) const; | 231 int findPropertyIndex(CSSPropertyID) const; |
213 | 232 |
233 void traceAfterDispatch(Visitor*); | |
234 | |
214 private: | 235 private: |
215 explicit MutableStylePropertySet(CSSParserMode); | 236 explicit MutableStylePropertySet(CSSParserMode); |
216 explicit MutableStylePropertySet(const StylePropertySet&); | 237 explicit MutableStylePropertySet(const StylePropertySet&); |
217 MutableStylePropertySet(const CSSProperty* properties, unsigned count); | 238 MutableStylePropertySet(const CSSProperty* properties, unsigned count); |
218 | 239 |
219 bool removeShorthandProperty(CSSPropertyID); | 240 bool removeShorthandProperty(CSSPropertyID); |
220 CSSProperty* findCSSPropertyWithID(CSSPropertyID); | 241 CSSProperty* findCSSPropertyWithID(CSSPropertyID); |
221 OwnPtr<PropertySetCSSStyleDeclaration> m_cssomWrapper; | 242 OwnPtr<PropertySetCSSStyleDeclaration> m_cssomWrapper; |
222 | 243 |
223 friend class StylePropertySet; | 244 friend class StylePropertySet; |
224 | 245 |
225 Vector<CSSProperty, 4> m_propertyVector; | 246 WillBeHeapVector<CSSProperty, 4> m_propertyVector; |
226 }; | 247 }; |
227 | 248 |
228 DEFINE_TYPE_CASTS(MutableStylePropertySet, StylePropertySet, set, set->isMutable (), set.isMutable()); | 249 DEFINE_TYPE_CASTS(MutableStylePropertySet, StylePropertySet, set, set->isMutable (), set.isMutable()); |
229 | 250 |
230 inline MutableStylePropertySet* toMutableStylePropertySet(const RefPtr<StyleProp ertySet>& set) | 251 inline MutableStylePropertySet* toMutableStylePropertySet(const RefPtr<StyleProp ertySet>& set) |
231 { | 252 { |
232 return toMutableStylePropertySet(set.get()); | 253 return toMutableStylePropertySet(set.get()); |
233 } | 254 } |
234 | 255 |
235 inline const StylePropertyMetadata& StylePropertySet::PropertyReference::propert yMetadata() const | 256 inline const StylePropertyMetadata& StylePropertySet::PropertyReference::propert yMetadata() const |
(...skipping 15 matching lines...) Expand all Loading... | |
251 if (m_isMutable) | 272 if (m_isMutable) |
252 return toMutableStylePropertySet(this)->m_propertyVector.size(); | 273 return toMutableStylePropertySet(this)->m_propertyVector.size(); |
253 return m_arraySize; | 274 return m_arraySize; |
254 } | 275 } |
255 | 276 |
256 inline bool StylePropertySet::isEmpty() const | 277 inline bool StylePropertySet::isEmpty() const |
257 { | 278 { |
258 return !propertyCount(); | 279 return !propertyCount(); |
259 } | 280 } |
260 | 281 |
282 #if !ENABLE(OILPAN) | |
261 inline void StylePropertySet::deref() | 283 inline void StylePropertySet::deref() |
262 { | 284 { |
263 if (!derefBase()) | 285 if (!derefBase()) |
264 return; | 286 return; |
265 | 287 |
266 if (m_isMutable) | 288 if (m_isMutable) |
267 delete toMutableStylePropertySet(this); | 289 delete toMutableStylePropertySet(this); |
268 else | 290 else |
269 delete toImmutableStylePropertySet(this); | 291 delete toImmutableStylePropertySet(this); |
270 } | 292 } |
293 #endif // !ENABLE(OILPAN) | |
271 | 294 |
272 inline int StylePropertySet::findPropertyIndex(CSSPropertyID propertyID) const | 295 inline int StylePropertySet::findPropertyIndex(CSSPropertyID propertyID) const |
273 { | 296 { |
274 if (m_isMutable) | 297 if (m_isMutable) |
275 return toMutableStylePropertySet(this)->findPropertyIndex(propertyID); | 298 return toMutableStylePropertySet(this)->findPropertyIndex(propertyID); |
276 return toImmutableStylePropertySet(this)->findPropertyIndex(propertyID); | 299 return toImmutableStylePropertySet(this)->findPropertyIndex(propertyID); |
277 } | 300 } |
278 | 301 |
279 } // namespace WebCore | 302 } // namespace WebCore |
280 | 303 |
281 #endif // StylePropertySet_h | 304 #endif // StylePropertySet_h |
OLD | NEW |