2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2008 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 CSSMutableStyleDeclaration_h
22 #define CSSMutableStyleDeclaration_h
24 #include "CSSStyleDeclaration.h"
25 #include "CSSPrimitiveValue.h"
26 #include "CSSProperty.h"
28 #include "PlatformString.h"
29 #include <wtf/ListHashSet.h>
30 #include <wtf/Vector.h>
36 class CSSMutableStyleDeclarationConstIterator {
38 CSSMutableStyleDeclarationConstIterator(const CSSMutableStyleDeclaration* decl, CSSProperty* current);
39 CSSMutableStyleDeclarationConstIterator(const CSSMutableStyleDeclarationConstIterator& o);
40 ~CSSMutableStyleDeclarationConstIterator();
42 const CSSProperty& operator*() const { return *m_current; }
43 const CSSProperty* operator->() const { return m_current; }
45 bool operator!=(const CSSMutableStyleDeclarationConstIterator& o) { ASSERT(m_decl == o.m_decl); return m_current != o.m_current; }
46 bool operator==(const CSSMutableStyleDeclarationConstIterator& o) { ASSERT(m_decl == o.m_decl); return m_current == o.m_current; }
48 CSSMutableStyleDeclarationConstIterator& operator=(const CSSMutableStyleDeclarationConstIterator& o);
50 CSSMutableStyleDeclarationConstIterator& operator++();
51 CSSMutableStyleDeclarationConstIterator& operator--();
54 const CSSMutableStyleDeclaration* m_decl;
55 CSSProperty* m_current;
58 class CSSMutableStyleDeclaration : public CSSStyleDeclaration {
60 static PassRefPtr<CSSMutableStyleDeclaration> create()
62 return adoptRef(new CSSMutableStyleDeclaration);
64 static PassRefPtr<CSSMutableStyleDeclaration> create(CSSRule* parentRule)
66 return adoptRef(new CSSMutableStyleDeclaration(parentRule));
68 static PassRefPtr<CSSMutableStyleDeclaration> create(CSSRule* parentRule, const CSSProperty* const* properties, int numProperties)
70 return adoptRef(new CSSMutableStyleDeclaration(parentRule, properties, numProperties));
72 static PassRefPtr<CSSMutableStyleDeclaration> create(const Vector<CSSProperty>& properties, unsigned variableDependentValueCount)
74 return adoptRef(new CSSMutableStyleDeclaration(0, properties, variableDependentValueCount));
77 CSSMutableStyleDeclaration& operator=(const CSSMutableStyleDeclaration&);
79 typedef CSSMutableStyleDeclarationConstIterator const_iterator;
81 const_iterator begin() { return const_iterator(this, m_properties.begin()); }
82 const_iterator end() { return const_iterator(this, m_properties.end()); }
84 void setNode(Node* node) { m_node = node; }
86 virtual bool isMutableStyleDeclaration() const { return true; }
88 virtual String cssText() const;
89 virtual void setCssText(const String&, ExceptionCode&);
91 virtual unsigned virtualLength() const;
92 unsigned length() const { return m_properties.size(); }
94 virtual String item(unsigned index) const;
96 virtual PassRefPtr<CSSValue> getPropertyCSSValue(int propertyID) const;
97 virtual String getPropertyValue(int propertyID) const;
98 virtual bool getPropertyPriority(int propertyID) const;
99 virtual int getPropertyShorthand(int propertyID) const;
100 virtual bool isPropertyImplicit(int propertyID) const;
102 virtual void setProperty(int propertyId, const String& value, bool important, ExceptionCode&);
103 virtual String removeProperty(int propertyID, ExceptionCode&);
105 virtual PassRefPtr<CSSMutableStyleDeclaration> copy() const;
107 bool setProperty(int propertyID, int value, bool important = false, bool notifyChanged = true);
108 bool setProperty(int propertyID, const String& value, bool important = false, bool notifyChanged = true);
110 String removeProperty(int propertyID, bool notifyChanged = true, bool returnText = false);
112 // setLengthProperty treats integers as pixels! (Needed for conversion of HTML attributes.)
113 void setLengthProperty(int propertyId, const String& value, bool important, bool multiLength = false);
114 void setStringProperty(int propertyId, const String& value, CSSPrimitiveValue::UnitTypes, bool important = false); // parsed string value
115 void setImageProperty(int propertyId, const String& url, bool important = false);
117 // The following parses an entire new style declaration.
118 void parseDeclaration(const String& styleDeclaration);
120 // Besides adding the properties, this also removes any existing properties with these IDs.
121 // It does no notification since it's called by the parser.
122 void addParsedProperties(const CSSProperty* const *, int numProperties);
123 // This does no change notifications since it's only called by createMarkup.
124 void addParsedProperty(const CSSProperty&);
126 PassRefPtr<CSSMutableStyleDeclaration> copyBlockProperties() const;
127 void removeBlockProperties();
128 void removePropertiesInSet(const int* set, unsigned length, bool notifyChanged = true);
130 void merge(CSSMutableStyleDeclaration*, bool argOverridesOnConflict = true);
132 bool hasVariableDependentValue() const { return m_variableDependentValueCount > 0; }
134 void setStrictParsing(bool b) { m_strictParsing = b; }
135 bool useStrictParsing() const { return m_strictParsing; }
137 void addSubresourceStyleURLs(ListHashSet<KURL>&);
140 CSSMutableStyleDeclaration(CSSRule* parentRule);
143 CSSMutableStyleDeclaration();
144 CSSMutableStyleDeclaration(CSSRule* parentRule, const Vector<CSSProperty>&, unsigned variableDependentValueCount);
145 CSSMutableStyleDeclaration(CSSRule* parentRule, const CSSProperty* const *, int numProperties);
147 virtual PassRefPtr<CSSMutableStyleDeclaration> makeMutable();
149 void setNeedsStyleRecalc();
151 String getShorthandValue(const int* properties, int number) const;
152 String getCommonValue(const int* properties, int number) const;
153 String getLayeredShorthandValue(const int* properties, unsigned number) const;
154 String get4Values(const int* properties) const;
156 void setPropertyInternal(const CSSProperty&, CSSProperty* slot = 0);
157 bool removeShorthandProperty(int propertyID, bool notifyChanged);
159 Vector<CSSProperty>::const_iterator findPropertyWithId(int propertyId) const;
160 Vector<CSSProperty>::iterator findPropertyWithId(int propertyId);
162 Vector<CSSProperty, 4> m_properties;
165 unsigned m_variableDependentValueCount : 24;
166 bool m_strictParsing : 1;
168 unsigned m_iteratorCount : 4;
171 friend class CSSMutableStyleDeclarationConstIterator;
174 inline CSSMutableStyleDeclarationConstIterator::CSSMutableStyleDeclarationConstIterator(const CSSMutableStyleDeclaration* decl, CSSProperty* current)
179 const_cast<CSSMutableStyleDeclaration*>(m_decl)->m_iteratorCount++;
183 inline CSSMutableStyleDeclarationConstIterator::CSSMutableStyleDeclarationConstIterator(const CSSMutableStyleDeclarationConstIterator& o)
185 , m_current(o.m_current)
188 const_cast<CSSMutableStyleDeclaration*>(m_decl)->m_iteratorCount++;
192 inline CSSMutableStyleDeclarationConstIterator::~CSSMutableStyleDeclarationConstIterator()
195 const_cast<CSSMutableStyleDeclaration*>(m_decl)->m_iteratorCount--;
199 inline CSSMutableStyleDeclarationConstIterator& CSSMutableStyleDeclarationConstIterator::operator=(const CSSMutableStyleDeclarationConstIterator& o)
202 m_current = o.m_current;
204 const_cast<CSSMutableStyleDeclaration*>(m_decl)->m_iteratorCount++;
209 inline CSSMutableStyleDeclarationConstIterator& CSSMutableStyleDeclarationConstIterator::operator++()
211 ASSERT(m_current != const_cast<CSSMutableStyleDeclaration*>(m_decl)->m_properties.end());
216 inline CSSMutableStyleDeclarationConstIterator& CSSMutableStyleDeclarationConstIterator::operator--()
222 } // namespace WebCore
224 #endif // CSSMutableStyleDeclaration_h