2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Peter Kelly (pmk@post.com)
5 * (C) 2001 Dirk Mueller (mueller@kde.org)
6 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
25 #ifndef StyledElement_h
26 #define StyledElement_h
28 #include "CSSMutableStyleDeclaration.h"
30 #include "MappedAttributeEntry.h"
35 class CSSMappedAttributeDeclaration;
37 class StyledElement : public Element {
39 virtual ~StyledElement();
41 size_t mappedAttributeCount() const { return attributeMap() ? attributeMap()->mappedAttributeCount() : 0; }
42 bool isMappedAttribute(const QualifiedName& name) const { MappedAttributeEntry res = eNone; mapToEntry(name, res); return res != eNone; }
44 void addCSSLength(Attribute*, int id, const String& value);
45 void addCSSProperty(Attribute*, int id, const String& value);
46 void addCSSProperty(Attribute*, int id, int value);
47 void addCSSImageProperty(Attribute*, int propertyID, const String& url);
48 void addCSSColor(Attribute*, int id, const String& color);
49 void removeCSSProperty(Attribute*, int id);
51 static CSSMappedAttributeDeclaration* getMappedAttributeDecl(MappedAttributeEntry, const QualifiedName& name, const AtomicString& value);
52 static void setMappedAttributeDecl(MappedAttributeEntry, const QualifiedName& name, const AtomicString& value, CSSMappedAttributeDeclaration*);
53 static void removeMappedAttributeDecl(MappedAttributeEntry, const QualifiedName& name, const AtomicString& value);
55 static CSSMappedAttributeDeclaration* getMappedAttributeDecl(MappedAttributeEntry, Attribute*);
56 static void setMappedAttributeDecl(MappedAttributeEntry, Attribute*, CSSMappedAttributeDeclaration*);
58 virtual PassRefPtr<CSSMutableStyleDeclaration> additionalAttributeStyle() { return 0; }
59 void invalidateStyleAttribute();
61 CSSMutableStyleDeclaration* inlineStyleDecl() const { return attributeMap() ? attributeMap()->inlineStyleDecl() : 0; }
62 CSSMutableStyleDeclaration* ensureInlineStyleDecl() { return ensureAttributeMap()->ensureInlineStyleDecl(); }
63 virtual CSSStyleDeclaration* style() OVERRIDE { return ensureInlineStyleDecl(); }
65 const SpaceSplitString& classNames() const;
67 virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const;
69 virtual PassRefPtr<Attribute> createAttribute(const QualifiedName&, const AtomicString& value);
72 StyledElement(const QualifiedName& name, Document* document, ConstructionType type)
73 : Element(name, document, type)
77 virtual void attributeChanged(Attribute*, bool preserveDecls = false);
78 virtual void parseMappedAttribute(Attribute*);
79 virtual void copyNonAttributeProperties(const Element*);
81 virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const;
83 // classAttributeChanged() exists to share code between
84 // parseMappedAttribute (called via setAttribute()) and
85 // svgAttributeChanged (called when element.className.baseValue is set)
86 void classAttributeChanged(const AtomicString& newClassString);
89 void createMappedDecl(Attribute*);
91 virtual void updateStyleAttribute() const;
93 void destroyInlineStyleDecl()
96 attributeMap()->destroyInlineStyleDecl();
100 inline const SpaceSplitString& StyledElement::classNames() const
103 ASSERT(attributeData());
104 return attributeData()->classNames();
107 inline void StyledElement::invalidateStyleAttribute()
109 clearIsStyleAttributeValid();