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