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