| 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 22 matching lines...) Expand all Loading... |
| 33 #include "wtf/text/WTFString.h" | 33 #include "wtf/text/WTFString.h" |
| 34 #include <algorithm> | 34 #include <algorithm> |
| 35 | 35 |
| 36 namespace blink { | 36 namespace blink { |
| 37 | 37 |
| 38 class CSSStyleDeclaration; | 38 class CSSStyleDeclaration; |
| 39 class ImmutableStylePropertySet; | 39 class ImmutableStylePropertySet; |
| 40 class MutableStylePropertySet; | 40 class MutableStylePropertySet; |
| 41 class StyleSheetContents; | 41 class StyleSheetContents; |
| 42 | 42 |
| 43 class CORE_EXPORT StylePropertySet : public RefCountedWillBeGarbageCollectedFina
lized<StylePropertySet> { | 43 class CORE_EXPORT StylePropertySet : public GarbageCollectedFinalized<StylePrope
rtySet> { |
| 44 WTF_MAKE_NONCOPYABLE(StylePropertySet); | 44 WTF_MAKE_NONCOPYABLE(StylePropertySet); |
| 45 friend class PropertyReference; | 45 friend class PropertyReference; |
| 46 public: | 46 public: |
| 47 | 47 |
| 48 #if ENABLE(OILPAN) | 48 #if ENABLE(OILPAN) |
| 49 // When oilpan is enabled override the finalize method to dispatch to the su
bclasses' | 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 | 50 // destructor. This can be removed once the MutableStylePropertySet's OwnPtr
is moved |
| 51 // to the heap. | 51 // to the heap. |
| 52 void finalizeGarbageCollectedObject(); | 52 void finalizeGarbageCollectedObject(); |
| 53 #else | 53 #else |
| (...skipping 23 matching lines...) Expand all Loading... |
| 77 CSSValue* value() { return const_cast<CSSValue*>(propertyValue()); } | 77 CSSValue* value() { return const_cast<CSSValue*>(propertyValue()); } |
| 78 | 78 |
| 79 // FIXME: Remove this. | 79 // FIXME: Remove this. |
| 80 CSSProperty toCSSProperty() const { return CSSProperty(propertyMetadata(
), const_cast<CSSValue*>(propertyValue())); } | 80 CSSProperty toCSSProperty() const { return CSSProperty(propertyMetadata(
), const_cast<CSSValue*>(propertyValue())); } |
| 81 | 81 |
| 82 const StylePropertyMetadata& propertyMetadata() const; | 82 const StylePropertyMetadata& propertyMetadata() const; |
| 83 | 83 |
| 84 private: | 84 private: |
| 85 const CSSValue* propertyValue() const; | 85 const CSSValue* propertyValue() const; |
| 86 | 86 |
| 87 RawPtrWillBeMember<const StylePropertySet> m_propertySet; | 87 Member<const StylePropertySet> m_propertySet; |
| 88 unsigned m_index; | 88 unsigned m_index; |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 unsigned propertyCount() const; | 91 unsigned propertyCount() const; |
| 92 bool isEmpty() const; | 92 bool isEmpty() const; |
| 93 PropertyReference propertyAt(unsigned index) const { return PropertyReferenc
e(*this, index); } | 93 PropertyReference propertyAt(unsigned index) const { return PropertyReferenc
e(*this, index); } |
| 94 | 94 |
| 95 template<typename T> // CSSPropertyID or AtomicString | 95 template<typename T> // CSSPropertyID or AtomicString |
| 96 int findPropertyIndex(T property) const; | 96 int findPropertyIndex(T property) const; |
| 97 | 97 |
| 98 bool hasProperty(CSSPropertyID property) const { return findPropertyIndex(pr
operty) != -1; } | 98 bool hasProperty(CSSPropertyID property) const { return findPropertyIndex(pr
operty) != -1; } |
| 99 | 99 |
| 100 template<typename T> // CSSPropertyID or AtomicString | 100 template<typename T> // CSSPropertyID or AtomicString |
| 101 PassRefPtrWillBeRawPtr<CSSValue> getPropertyCSSValue(T property) const; | 101 RawPtr<CSSValue> getPropertyCSSValue(T property) const; |
| 102 | 102 |
| 103 template<typename T> // CSSPropertyID or AtomicString | 103 template<typename T> // CSSPropertyID or AtomicString |
| 104 String getPropertyValue(T property) const; | 104 String getPropertyValue(T property) const; |
| 105 | 105 |
| 106 template<typename T> // CSSPropertyID or AtomicString | 106 template<typename T> // CSSPropertyID or AtomicString |
| 107 bool propertyIsImportant(T property) const; | 107 bool propertyIsImportant(T property) const; |
| 108 | 108 |
| 109 bool shorthandIsImportant(CSSPropertyID) const; | 109 bool shorthandIsImportant(CSSPropertyID) const; |
| 110 bool shorthandIsImportant(AtomicString customPropertyName) const; | 110 bool shorthandIsImportant(AtomicString customPropertyName) const; |
| 111 | 111 |
| 112 CSSPropertyID getPropertyShorthand(CSSPropertyID) const; | 112 CSSPropertyID getPropertyShorthand(CSSPropertyID) const; |
| 113 bool isPropertyImplicit(CSSPropertyID) const; | 113 bool isPropertyImplicit(CSSPropertyID) const; |
| 114 | 114 |
| 115 CSSParserMode cssParserMode() const { return static_cast<CSSParserMode>(m_cs
sParserMode); } | 115 CSSParserMode cssParserMode() const { return static_cast<CSSParserMode>(m_cs
sParserMode); } |
| 116 | 116 |
| 117 PassRefPtrWillBeRawPtr<MutableStylePropertySet> mutableCopy() const; | 117 RawPtr<MutableStylePropertySet> mutableCopy() const; |
| 118 PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> immutableCopyIfNeeded() co
nst; | 118 RawPtr<ImmutableStylePropertySet> immutableCopyIfNeeded() const; |
| 119 | 119 |
| 120 PassRefPtrWillBeRawPtr<MutableStylePropertySet> copyPropertiesInSet(const Ve
ctor<CSSPropertyID>&) const; | 120 RawPtr<MutableStylePropertySet> copyPropertiesInSet(const Vector<CSSProperty
ID>&) const; |
| 121 | 121 |
| 122 String asText() const; | 122 String asText() const; |
| 123 | 123 |
| 124 bool isMutable() const { return m_isMutable; } | 124 bool isMutable() const { return m_isMutable; } |
| 125 | 125 |
| 126 bool hasFailedOrCanceledSubresources() const; | 126 bool hasFailedOrCanceledSubresources() const; |
| 127 | 127 |
| 128 static unsigned averageSizeInBytes(); | 128 static unsigned averageSizeInBytes(); |
| 129 | 129 |
| 130 #ifndef NDEBUG | 130 #ifndef NDEBUG |
| (...skipping 24 matching lines...) Expand all Loading... |
| 155 unsigned m_cssParserMode : 3; | 155 unsigned m_cssParserMode : 3; |
| 156 mutable unsigned m_isMutable : 1; | 156 mutable unsigned m_isMutable : 1; |
| 157 unsigned m_arraySize : 28; | 157 unsigned m_arraySize : 28; |
| 158 | 158 |
| 159 friend class PropertySetCSSStyleDeclaration; | 159 friend class PropertySetCSSStyleDeclaration; |
| 160 }; | 160 }; |
| 161 | 161 |
| 162 class CORE_EXPORT ImmutableStylePropertySet : public StylePropertySet { | 162 class CORE_EXPORT ImmutableStylePropertySet : public StylePropertySet { |
| 163 public: | 163 public: |
| 164 ~ImmutableStylePropertySet(); | 164 ~ImmutableStylePropertySet(); |
| 165 static PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> create(const CSSPro
perty* properties, unsigned count, CSSParserMode); | 165 static RawPtr<ImmutableStylePropertySet> create(const CSSProperty* propertie
s, unsigned count, CSSParserMode); |
| 166 | 166 |
| 167 unsigned propertyCount() const { return m_arraySize; } | 167 unsigned propertyCount() const { return m_arraySize; } |
| 168 | 168 |
| 169 const RawPtrWillBeMember<CSSValue>* valueArray() const; | 169 const Member<CSSValue>* valueArray() const; |
| 170 const StylePropertyMetadata* metadataArray() const; | 170 const StylePropertyMetadata* metadataArray() const; |
| 171 | 171 |
| 172 template<typename T> // CSSPropertyID or AtomicString | 172 template<typename T> // CSSPropertyID or AtomicString |
| 173 int findPropertyIndex(T property) const; | 173 int findPropertyIndex(T property) const; |
| 174 | 174 |
| 175 DECLARE_TRACE_AFTER_DISPATCH(); | 175 DECLARE_TRACE_AFTER_DISPATCH(); |
| 176 | 176 |
| 177 void* operator new(std::size_t, void* location) | 177 void* operator new(std::size_t, void* location) |
| 178 { | 178 { |
| 179 return location; | 179 return location; |
| 180 } | 180 } |
| 181 | 181 |
| 182 void* m_storage; | 182 void* m_storage; |
| 183 | 183 |
| 184 private: | 184 private: |
| 185 ImmutableStylePropertySet(const CSSProperty*, unsigned count, CSSParserMode)
; | 185 ImmutableStylePropertySet(const CSSProperty*, unsigned count, CSSParserMode)
; |
| 186 }; | 186 }; |
| 187 | 187 |
| 188 inline const RawPtrWillBeMember<CSSValue>* ImmutableStylePropertySet::valueArray
() const | 188 inline const Member<CSSValue>* ImmutableStylePropertySet::valueArray() const |
| 189 { | 189 { |
| 190 return reinterpret_cast<const RawPtrWillBeMember<CSSValue>*>(const_cast<cons
t void**>(&(this->m_storage))); | 190 return reinterpret_cast<const Member<CSSValue>*>(const_cast<const void**>(&(
this->m_storage))); |
| 191 } | 191 } |
| 192 | 192 |
| 193 inline const StylePropertyMetadata* ImmutableStylePropertySet::metadataArray() c
onst | 193 inline const StylePropertyMetadata* ImmutableStylePropertySet::metadataArray() c
onst |
| 194 { | 194 { |
| 195 return reinterpret_cast<const StylePropertyMetadata*>(&reinterpret_cast<cons
t char*>(&(this->m_storage))[m_arraySize * sizeof(RawPtrWillBeMember<CSSValue>)]
); | 195 return reinterpret_cast<const StylePropertyMetadata*>(&reinterpret_cast<cons
t char*>(&(this->m_storage))[m_arraySize * sizeof(Member<CSSValue>)]); |
| 196 } | 196 } |
| 197 | 197 |
| 198 DEFINE_TYPE_CASTS(ImmutableStylePropertySet, StylePropertySet, set, !set->isMuta
ble(), !set.isMutable()); | 198 DEFINE_TYPE_CASTS(ImmutableStylePropertySet, StylePropertySet, set, !set->isMuta
ble(), !set.isMutable()); |
| 199 | 199 |
| 200 class CORE_EXPORT MutableStylePropertySet : public StylePropertySet { | 200 class CORE_EXPORT MutableStylePropertySet : public StylePropertySet { |
| 201 public: | 201 public: |
| 202 ~MutableStylePropertySet() { } | 202 ~MutableStylePropertySet() { } |
| 203 static PassRefPtrWillBeRawPtr<MutableStylePropertySet> create(CSSParserMode)
; | 203 static RawPtr<MutableStylePropertySet> create(CSSParserMode); |
| 204 static PassRefPtrWillBeRawPtr<MutableStylePropertySet> create(const CSSPrope
rty* properties, unsigned count); | 204 static RawPtr<MutableStylePropertySet> create(const CSSProperty* properties,
unsigned count); |
| 205 | 205 |
| 206 unsigned propertyCount() const { return m_propertyVector.size(); } | 206 unsigned propertyCount() const { return m_propertyVector.size(); } |
| 207 | 207 |
| 208 // Returns whether this style set was changed. | 208 // Returns whether this style set was changed. |
| 209 bool addParsedProperties(const WillBeHeapVector<CSSProperty, 256>&); | 209 bool addParsedProperties(const HeapVector<CSSProperty, 256>&); |
| 210 bool addRespectingCascade(const CSSProperty&); | 210 bool addRespectingCascade(const CSSProperty&); |
| 211 | 211 |
| 212 // These expand shorthand properties into multiple properties. | 212 // These expand shorthand properties into multiple properties. |
| 213 bool setProperty(CSSPropertyID unresolvedProperty, const String& value, bool
important = false, StyleSheetContents* contextStyleSheet = 0); | 213 bool setProperty(CSSPropertyID unresolvedProperty, const String& value, bool
important = false, StyleSheetContents* contextStyleSheet = 0); |
| 214 bool setProperty(const AtomicString& customPropertyName, const String& value
, bool important = false, StyleSheetContents* contextStyleSheet = 0); | 214 bool setProperty(const AtomicString& customPropertyName, const String& value
, bool important = false, StyleSheetContents* contextStyleSheet = 0); |
| 215 void setProperty(CSSPropertyID, PassRefPtrWillBeRawPtr<CSSValue>, bool impor
tant = false); | 215 void setProperty(CSSPropertyID, RawPtr<CSSValue>, bool important = false); |
| 216 | 216 |
| 217 // These do not. FIXME: This is too messy, we can do better. | 217 // These do not. FIXME: This is too messy, we can do better. |
| 218 bool setProperty(CSSPropertyID, CSSValueID identifier, bool important = fals
e); | 218 bool setProperty(CSSPropertyID, CSSValueID identifier, bool important = fals
e); |
| 219 bool setProperty(const CSSProperty&, CSSProperty* slot = 0); | 219 bool setProperty(const CSSProperty&, CSSProperty* slot = 0); |
| 220 | 220 |
| 221 template<typename T> // CSSPropertyID or AtomicString | 221 template<typename T> // CSSPropertyID or AtomicString |
| 222 bool removeProperty(T property, String* returnText = 0); | 222 bool removeProperty(T property, String* returnText = 0); |
| 223 bool removePropertiesInSet(const CSSPropertyID* set, unsigned length); | 223 bool removePropertiesInSet(const CSSPropertyID* set, unsigned length); |
| 224 void removeEquivalentProperties(const StylePropertySet*); | 224 void removeEquivalentProperties(const StylePropertySet*); |
| 225 void removeEquivalentProperties(const CSSStyleDeclaration*); | 225 void removeEquivalentProperties(const CSSStyleDeclaration*); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 239 private: | 239 private: |
| 240 explicit MutableStylePropertySet(CSSParserMode); | 240 explicit MutableStylePropertySet(CSSParserMode); |
| 241 explicit MutableStylePropertySet(const StylePropertySet&); | 241 explicit MutableStylePropertySet(const StylePropertySet&); |
| 242 MutableStylePropertySet(const CSSProperty* properties, unsigned count); | 242 MutableStylePropertySet(const CSSProperty* properties, unsigned count); |
| 243 | 243 |
| 244 bool removePropertyAtIndex(int, String* returnText); | 244 bool removePropertyAtIndex(int, String* returnText); |
| 245 | 245 |
| 246 bool removeShorthandProperty(CSSPropertyID); | 246 bool removeShorthandProperty(CSSPropertyID); |
| 247 bool removeShorthandProperty(const AtomicString& customPropertyName) { retur
n false; } | 247 bool removeShorthandProperty(const AtomicString& customPropertyName) { retur
n false; } |
| 248 CSSProperty* findCSSPropertyWithID(CSSPropertyID, const AtomicString& custom
PropertyName = nullAtom); | 248 CSSProperty* findCSSPropertyWithID(CSSPropertyID, const AtomicString& custom
PropertyName = nullAtom); |
| 249 OwnPtrWillBeMember<PropertySetCSSStyleDeclaration> m_cssomWrapper; | 249 Member<PropertySetCSSStyleDeclaration> m_cssomWrapper; |
| 250 | 250 |
| 251 friend class StylePropertySet; | 251 friend class StylePropertySet; |
| 252 | 252 |
| 253 WillBeHeapVector<CSSProperty, 4> m_propertyVector; | 253 HeapVector<CSSProperty, 4> m_propertyVector; |
| 254 }; | 254 }; |
| 255 | 255 |
| 256 DEFINE_TYPE_CASTS(MutableStylePropertySet, StylePropertySet, set, set->isMutable
(), set.isMutable()); | 256 DEFINE_TYPE_CASTS(MutableStylePropertySet, StylePropertySet, set, set->isMutable
(), set.isMutable()); |
| 257 | 257 |
| 258 inline MutableStylePropertySet* toMutableStylePropertySet(const RefPtrWillBeRawP
tr<StylePropertySet>& set) | 258 inline MutableStylePropertySet* toMutableStylePropertySet(const RawPtr<StyleProp
ertySet>& set) |
| 259 { | 259 { |
| 260 return toMutableStylePropertySet(set.get()); | 260 return toMutableStylePropertySet(set.get()); |
| 261 } | 261 } |
| 262 | 262 |
| 263 inline MutableStylePropertySet* toMutableStylePropertySet(const Persistent<Style
PropertySet>& set) | 263 inline MutableStylePropertySet* toMutableStylePropertySet(const Persistent<Style
PropertySet>& set) |
| 264 { | 264 { |
| 265 return toMutableStylePropertySet(set.get()); | 265 return toMutableStylePropertySet(set.get()); |
| 266 } | 266 } |
| 267 | 267 |
| 268 inline MutableStylePropertySet* toMutableStylePropertySet(const Member<StyleProp
ertySet>& set) | 268 inline MutableStylePropertySet* toMutableStylePropertySet(const Member<StyleProp
ertySet>& set) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 inline int StylePropertySet::findPropertyIndex(T property) const | 313 inline int StylePropertySet::findPropertyIndex(T property) const |
| 314 { | 314 { |
| 315 if (m_isMutable) | 315 if (m_isMutable) |
| 316 return toMutableStylePropertySet(this)->findPropertyIndex(property); | 316 return toMutableStylePropertySet(this)->findPropertyIndex(property); |
| 317 return toImmutableStylePropertySet(this)->findPropertyIndex(property); | 317 return toImmutableStylePropertySet(this)->findPropertyIndex(property); |
| 318 } | 318 } |
| 319 | 319 |
| 320 } // namespace blink | 320 } // namespace blink |
| 321 | 321 |
| 322 #endif // StylePropertySet_h | 322 #endif // StylePropertySet_h |
| OLD | NEW |