| 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, |
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 * Library General Public License for more details. | 13 * Library General Public License for more details. |
| 14 * | 14 * |
| 15 * You should have received a copy of the GNU Library General Public License | 15 * You should have received a copy of the GNU Library General Public License |
| 16 * along with this library; see the file COPYING.LIB. If not, write to | 16 * along with this library; see the file COPYING.LIB. If not, write to |
| 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 * Boston, MA 02110-1301, USA. | 18 * Boston, MA 02110-1301, USA. |
| 19 */ | 19 */ |
| 20 | 20 |
| 21 #ifndef StylePropertySet_h | 21 #ifndef StylePropertySet_h |
| 22 #define StylePropertySet_h | 22 #define StylePropertySet_h |
| 23 | 23 |
| 24 #include "CSSPropertyNames.h" | 24 #include "CSSPropertyNames.h" |
| 25 #include "core/css/CSSParserMode.h" | 25 #include "core/css/CSSParserMode.h" |
| 26 #include "core/css/CSSPrimitiveValue.h" | 26 #include "core/css/CSSPrimitiveValue.h" |
| 27 #include "core/css/CSSProperty.h" | 27 #include "core/css/CSSProperty.h" |
| 28 #include "core/css/PropertySetCSSStyleDeclaration.h" |
| 28 #include <wtf/ListHashSet.h> | 29 #include <wtf/ListHashSet.h> |
| 29 #include <wtf/text/WTFString.h> | 30 #include <wtf/text/WTFString.h> |
| 30 #include <wtf/Vector.h> | 31 #include <wtf/Vector.h> |
| 31 | 32 |
| 32 namespace WebCore { | 33 namespace WebCore { |
| 33 | 34 |
| 34 class CSSRule; | 35 class CSSRule; |
| 35 class CSSStyleDeclaration; | 36 class CSSStyleDeclaration; |
| 36 class Element; | 37 class Element; |
| 37 class ImmutableStylePropertySet; | 38 class ImmutableStylePropertySet; |
| 38 class KURL; | 39 class KURL; |
| 39 class MutableStylePropertySet; | 40 class MutableStylePropertySet; |
| 40 class PropertySetCSSStyleDeclaration; | |
| 41 class StylePropertyShorthand; | 41 class StylePropertyShorthand; |
| 42 class StyleSheetContents; | 42 class StyleSheetContents; |
| 43 | 43 |
| 44 class StylePropertySet : public RefCounted<StylePropertySet> { | 44 class StylePropertySet : public RefCounted<StylePropertySet> { |
| 45 friend class PropertyReference; | 45 friend class PropertyReference; |
| 46 public: | 46 public: |
| 47 // Override RefCounted's deref() to ensure operator delete is called on | 47 // Override RefCounted's deref() to ensure operator delete is called on |
| 48 // the appropriate subclass type. | 48 // the appropriate subclass type. |
| 49 void deref(); | 49 void deref(); |
| 50 | 50 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 void addSubresourceStyleURLs(ListHashSet<KURL>&, StyleSheetContents* context
StyleSheet) const; | 99 void addSubresourceStyleURLs(ListHashSet<KURL>&, StyleSheetContents* context
StyleSheet) const; |
| 100 | 100 |
| 101 PassRefPtr<MutableStylePropertySet> mutableCopy() const; | 101 PassRefPtr<MutableStylePropertySet> mutableCopy() const; |
| 102 PassRefPtr<ImmutableStylePropertySet> immutableCopyIfNeeded() const; | 102 PassRefPtr<ImmutableStylePropertySet> immutableCopyIfNeeded() const; |
| 103 | 103 |
| 104 PassRefPtr<MutableStylePropertySet> copyPropertiesInSet(const Vector<CSSProp
ertyID>&) const; | 104 PassRefPtr<MutableStylePropertySet> copyPropertiesInSet(const Vector<CSSProp
ertyID>&) const; |
| 105 | 105 |
| 106 String asText() const; | 106 String asText() const; |
| 107 | 107 |
| 108 bool isMutable() const { return m_isMutable; } | 108 bool isMutable() const { return m_isMutable; } |
| 109 bool hasCSSOMWrapper() const { return m_ownsCSSOMWrapper; } | 109 bool hasCSSOMWrapper() const; |
| 110 | 110 |
| 111 bool hasFailedOrCanceledSubresources() const; | 111 bool hasFailedOrCanceledSubresources() const; |
| 112 | 112 |
| 113 static unsigned averageSizeInBytes(); | 113 static unsigned averageSizeInBytes(); |
| 114 void reportMemoryUsage(MemoryObjectInfo*) const; | 114 void reportMemoryUsage(MemoryObjectInfo*) const; |
| 115 | 115 |
| 116 #ifndef NDEBUG | 116 #ifndef NDEBUG |
| 117 void showStyle(); | 117 void showStyle(); |
| 118 #endif | 118 #endif |
| 119 | 119 |
| 120 bool propertyMatches(CSSPropertyID, const CSSValue*) const; | 120 bool propertyMatches(CSSPropertyID, const CSSValue*) const; |
| 121 | 121 |
| 122 protected: | 122 protected: |
| 123 StylePropertySet(CSSParserMode cssParserMode) | 123 StylePropertySet(CSSParserMode cssParserMode) |
| 124 : m_cssParserMode(cssParserMode) | 124 : m_cssParserMode(cssParserMode) |
| 125 , m_ownsCSSOMWrapper(false) | |
| 126 , m_isMutable(true) | 125 , m_isMutable(true) |
| 127 , m_arraySize(0) | 126 , m_arraySize(0) |
| 128 { } | 127 { } |
| 129 | 128 |
| 130 StylePropertySet(CSSParserMode cssParserMode, unsigned immutableArraySize) | 129 StylePropertySet(CSSParserMode cssParserMode, unsigned immutableArraySize) |
| 131 : m_cssParserMode(cssParserMode) | 130 : m_cssParserMode(cssParserMode) |
| 132 , m_ownsCSSOMWrapper(false) | |
| 133 , m_isMutable(false) | 131 , m_isMutable(false) |
| 134 , m_arraySize(immutableArraySize) | 132 , m_arraySize(immutableArraySize) |
| 135 { } | 133 { } |
| 136 | 134 |
| 137 unsigned m_cssParserMode : 2; | 135 unsigned m_cssParserMode : 2; |
| 138 mutable unsigned m_ownsCSSOMWrapper : 1; | |
| 139 mutable unsigned m_isMutable : 1; | 136 mutable unsigned m_isMutable : 1; |
| 140 unsigned m_arraySize : 28; | 137 unsigned m_arraySize : 29; |
| 141 | 138 |
| 142 friend class PropertySetCSSStyleDeclaration; | 139 friend class PropertySetCSSStyleDeclaration; |
| 143 }; | 140 }; |
| 144 | 141 |
| 145 class ImmutableStylePropertySet : public StylePropertySet { | 142 class ImmutableStylePropertySet : public StylePropertySet { |
| 146 // This is needed because we malloc() space for an | 143 // This is needed because we malloc() space for an |
| 147 // ImmutableStylePropertySet plus following properties, as a performance | 144 // ImmutableStylePropertySet plus following properties, as a performance |
| 148 // tweak. | 145 // tweak. |
| 149 NEW_DELETE_SAME_AS_MALLOC_FREE; | 146 NEW_DELETE_SAME_AS_MALLOC_FREE; |
| 150 public: | 147 public: |
| (...skipping 16 matching lines...) Expand all Loading... |
| 167 return reinterpret_cast<const CSSValue**>(const_cast<const void**>((&static_
cast<const ImmutableStylePropertySet*>(this)->m_storage))); | 164 return reinterpret_cast<const CSSValue**>(const_cast<const void**>((&static_
cast<const ImmutableStylePropertySet*>(this)->m_storage))); |
| 168 } | 165 } |
| 169 | 166 |
| 170 inline const StylePropertyMetadata* ImmutableStylePropertySet::metadataArray() c
onst | 167 inline const StylePropertyMetadata* ImmutableStylePropertySet::metadataArray() c
onst |
| 171 { | 168 { |
| 172 return reinterpret_cast<const StylePropertyMetadata*>(&reinterpret_cast<cons
t char*>((&static_cast<const ImmutableStylePropertySet*>(this)->m_storage))[m_ar
raySize * sizeof(CSSValue*)]); | 169 return reinterpret_cast<const StylePropertyMetadata*>(&reinterpret_cast<cons
t char*>((&static_cast<const ImmutableStylePropertySet*>(this)->m_storage))[m_ar
raySize * sizeof(CSSValue*)]); |
| 173 } | 170 } |
| 174 | 171 |
| 175 class MutableStylePropertySet : public StylePropertySet { | 172 class MutableStylePropertySet : public StylePropertySet { |
| 176 public: | 173 public: |
| 177 ~MutableStylePropertySet(); | |
| 178 | |
| 179 static PassRefPtr<MutableStylePropertySet> create(CSSParserMode = CSSQuirksM
ode); | 174 static PassRefPtr<MutableStylePropertySet> create(CSSParserMode = CSSQuirksM
ode); |
| 180 static PassRefPtr<MutableStylePropertySet> create(const CSSProperty* propert
ies, unsigned count); | 175 static PassRefPtr<MutableStylePropertySet> create(const CSSProperty* propert
ies, unsigned count); |
| 181 | 176 |
| 182 MutableStylePropertySet(const StylePropertySet&); | |
| 183 | |
| 184 unsigned propertyCount() const { return m_propertyVector.size(); } | 177 unsigned propertyCount() const { return m_propertyVector.size(); } |
| 185 PropertySetCSSStyleDeclaration* cssStyleDeclaration(); | 178 PropertySetCSSStyleDeclaration* cssStyleDeclaration(); |
| 186 | 179 |
| 187 void addParsedProperties(const Vector<CSSProperty>&); | 180 void addParsedProperties(const Vector<CSSProperty>&); |
| 188 void addParsedProperty(const CSSProperty&); | 181 void addParsedProperty(const CSSProperty&); |
| 189 | 182 |
| 190 // These expand shorthand properties into multiple properties. | 183 // These expand shorthand properties into multiple properties. |
| 191 bool setProperty(CSSPropertyID, const String& value, bool important = false,
StyleSheetContents* contextStyleSheet = 0); | 184 bool setProperty(CSSPropertyID, const String& value, bool important = false,
StyleSheetContents* contextStyleSheet = 0); |
| 192 void setProperty(CSSPropertyID, PassRefPtr<CSSValue>, bool important = false
); | 185 void setProperty(CSSPropertyID, PassRefPtr<CSSValue>, bool important = false
); |
| 193 | 186 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 209 | 202 |
| 210 void clear(); | 203 void clear(); |
| 211 void parseDeclaration(const String& styleDeclaration, StyleSheetContents* co
ntextStyleSheet); | 204 void parseDeclaration(const String& styleDeclaration, StyleSheetContents* co
ntextStyleSheet); |
| 212 | 205 |
| 213 CSSStyleDeclaration* ensureCSSStyleDeclaration(); | 206 CSSStyleDeclaration* ensureCSSStyleDeclaration(); |
| 214 CSSStyleDeclaration* ensureInlineCSSStyleDeclaration(Element* parentElement)
; | 207 CSSStyleDeclaration* ensureInlineCSSStyleDeclaration(Element* parentElement)
; |
| 215 | 208 |
| 216 Vector<CSSProperty, 4> m_propertyVector; | 209 Vector<CSSProperty, 4> m_propertyVector; |
| 217 | 210 |
| 218 private: | 211 private: |
| 219 MutableStylePropertySet(CSSParserMode cssParserMode) | 212 explicit MutableStylePropertySet(CSSParserMode); |
| 220 : StylePropertySet(cssParserMode) | 213 explicit MutableStylePropertySet(const StylePropertySet&); |
| 221 { } | |
| 222 | |
| 223 MutableStylePropertySet(const CSSProperty* properties, unsigned count); | 214 MutableStylePropertySet(const CSSProperty* properties, unsigned count); |
| 224 | 215 |
| 225 bool removeShorthandProperty(CSSPropertyID); | 216 bool removeShorthandProperty(CSSPropertyID); |
| 226 CSSProperty* findCSSPropertyWithID(CSSPropertyID); | 217 CSSProperty* findCSSPropertyWithID(CSSPropertyID); |
| 218 OwnPtr<PropertySetCSSStyleDeclaration> m_cssomWrapper; |
| 219 |
| 220 friend class StylePropertySet; |
| 227 }; | 221 }; |
| 228 | 222 |
| 229 inline StylePropertyMetadata StylePropertySet::PropertyReference::propertyMetada
ta() const | 223 inline StylePropertyMetadata StylePropertySet::PropertyReference::propertyMetada
ta() const |
| 230 { | 224 { |
| 231 if (m_propertySet.isMutable()) | 225 if (m_propertySet.isMutable()) |
| 232 return static_cast<const MutableStylePropertySet&>(m_propertySet).m_prop
ertyVector.at(m_index).metadata(); | 226 return static_cast<const MutableStylePropertySet&>(m_propertySet).m_prop
ertyVector.at(m_index).metadata(); |
| 233 return static_cast<const ImmutableStylePropertySet&>(m_propertySet).metadata
Array()[m_index]; | 227 return static_cast<const ImmutableStylePropertySet&>(m_propertySet).metadata
Array()[m_index]; |
| 234 } | 228 } |
| 235 | 229 |
| 236 inline const CSSValue* StylePropertySet::PropertyReference::propertyValue() cons
t | 230 inline const CSSValue* StylePropertySet::PropertyReference::propertyValue() cons
t |
| (...skipping 22 matching lines...) Expand all Loading... |
| 259 | 253 |
| 260 if (m_isMutable) | 254 if (m_isMutable) |
| 261 delete static_cast<MutableStylePropertySet*>(this); | 255 delete static_cast<MutableStylePropertySet*>(this); |
| 262 else | 256 else |
| 263 delete static_cast<ImmutableStylePropertySet*>(this); | 257 delete static_cast<ImmutableStylePropertySet*>(this); |
| 264 } | 258 } |
| 265 | 259 |
| 266 } // namespace WebCore | 260 } // namespace WebCore |
| 267 | 261 |
| 268 #endif // StylePropertySet_h | 262 #endif // StylePropertySet_h |
| OLD | NEW |