2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2008, 2012 Apple Inc. All rights reserved.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
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
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
21 #ifndef StylePropertySet_h
22 #define StylePropertySet_h
24 #include "CSSParserMode.h"
25 #include "CSSPrimitiveValue.h"
26 #include "CSSProperty.h"
27 #include "CSSPropertyNames.h"
28 #include <wtf/ListHashSet.h>
29 #include <wtf/Vector.h>
30 #include <wtf/text/WTFString.h>
35 class CSSStyleDeclaration;
37 class MemoryObjectInfo;
38 class PropertySetCSSStyleDeclaration;
40 class StylePropertyShorthand;
41 class StyleSheetContents;
43 class StylePropertySet : public RefCounted<StylePropertySet> {
47 static PassRefPtr<StylePropertySet> create(CSSParserMode cssParserMode = CSSQuirksMode)
49 return adoptRef(new StylePropertySet(cssParserMode));
51 static PassRefPtr<StylePropertySet> create(const CSSProperty* properties, unsigned count)
53 return adoptRef(new StylePropertySet(properties, count, CSSStrictMode, /* makeMutable */ true));
55 static PassRefPtr<StylePropertySet> createImmutable(const CSSProperty* properties, unsigned count, CSSParserMode);
57 unsigned propertyCount() const;
59 const CSSProperty& propertyAt(unsigned index) const;
60 CSSProperty& propertyAt(unsigned index);
62 PassRefPtr<CSSValue> getPropertyCSSValue(CSSPropertyID) const;
63 String getPropertyValue(CSSPropertyID) const;
64 bool propertyIsImportant(CSSPropertyID) const;
65 CSSPropertyID getPropertyShorthand(CSSPropertyID) const;
66 bool isPropertyImplicit(CSSPropertyID) const;
68 // These expand shorthand properties into multiple properties.
69 bool setProperty(CSSPropertyID, const String& value, bool important = false, StyleSheetContents* contextStyleSheet = 0);
70 void setProperty(CSSPropertyID, PassRefPtr<CSSValue>, bool important = false);
72 // These do not. FIXME: This is too messy, we can do better.
73 bool setProperty(CSSPropertyID, int identifier, bool important = false);
74 void setProperty(const CSSProperty&, CSSProperty* slot = 0);
76 bool removeProperty(CSSPropertyID, String* returnText = 0);
78 void parseDeclaration(const String& styleDeclaration, StyleSheetContents* contextStyleSheet);
80 void addParsedProperties(const Vector<CSSProperty>&);
81 void addParsedProperty(const CSSProperty&);
83 PassRefPtr<StylePropertySet> copyBlockProperties() const;
84 void removeBlockProperties();
85 bool removePropertiesInSet(const CSSPropertyID* set, unsigned length);
87 void mergeAndOverrideOnConflict(const StylePropertySet*);
89 void setCSSParserMode(CSSParserMode);
90 CSSParserMode cssParserMode() const { return static_cast<CSSParserMode>(m_cssParserMode); }
92 void addSubresourceStyleURLs(ListHashSet<KURL>&, StyleSheetContents* contextStyleSheet) const;
94 PassRefPtr<StylePropertySet> copy() const;
96 // Used by StyledElement::copyNonAttributeProperties().
97 void copyPropertiesFrom(const StylePropertySet&);
99 void removeEquivalentProperties(const StylePropertySet*);
100 void removeEquivalentProperties(const CSSStyleDeclaration*);
102 PassRefPtr<StylePropertySet> copyPropertiesInSet(const CSSPropertyID* set, unsigned length) const;
104 String asText() const;
106 void clearParentElement(StyledElement*);
108 CSSStyleDeclaration* ensureCSSStyleDeclaration() const;
109 CSSStyleDeclaration* ensureInlineCSSStyleDeclaration(const StyledElement* parentElement) const;
111 bool isMutable() const { return m_isMutable; }
113 static unsigned averageSizeInBytes();
114 void reportMemoryUsage(MemoryObjectInfo*) const;
121 StylePropertySet(CSSParserMode);
122 StylePropertySet(const CSSProperty* properties, unsigned count, CSSParserMode, bool makeMutable);
123 StylePropertySet(const StylePropertySet&);
125 void setNeedsStyleRecalc();
127 String getShorthandValue(const StylePropertyShorthand&) const;
128 String getCommonValue(const StylePropertyShorthand&) const;
129 enum CommonValueMode { OmitUncommonValues, ReturnNullOnUncommonValues };
130 String borderPropertyValue(CommonValueMode) const;
131 String getLayeredShorthandValue(const StylePropertyShorthand&) const;
132 String get4Values(const StylePropertyShorthand&) const;
133 String borderSpacingValue(const StylePropertyShorthand&) const;
134 String fontValue() const;
135 bool appendFontLonghandValueIfExplicit(CSSPropertyID, StringBuilder& result) const;
137 bool removeShorthandProperty(CSSPropertyID);
138 bool propertyMatches(const CSSProperty*) const;
140 const CSSProperty* findPropertyWithId(CSSPropertyID) const;
141 CSSProperty* findPropertyWithId(CSSPropertyID);
143 void append(const CSSProperty&);
144 CSSProperty* array();
145 const CSSProperty* array() const;
147 unsigned m_cssParserMode : 2;
148 mutable unsigned m_ownsCSSOMWrapper : 1;
149 mutable unsigned m_isMutable : 1;
150 unsigned m_arraySize : 28;
153 Vector<CSSProperty>* m_mutablePropertyVector;
157 friend class PropertySetCSSStyleDeclaration;
160 inline CSSProperty& StylePropertySet::propertyAt(unsigned index)
163 return m_mutablePropertyVector->at(index);
164 return array()[index];
167 inline const CSSProperty& StylePropertySet::propertyAt(unsigned index) const
170 return m_mutablePropertyVector->at(index);
171 return array()[index];
174 inline unsigned StylePropertySet::propertyCount() const
177 return m_mutablePropertyVector->size();
181 inline bool StylePropertySet::isEmpty() const
183 return !propertyCount();
186 inline CSSProperty* StylePropertySet::array()
188 ASSERT(!isMutable());
189 return reinterpret_cast<CSSProperty*>(&m_properties);
192 inline const CSSProperty* StylePropertySet::array() const
194 ASSERT(!isMutable());
195 return reinterpret_cast<const CSSProperty*>(&m_properties);
198 } // namespace WebCore
200 #endif // StylePropertySet_h