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 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
29 #include "NamedMappedAttrMap.h"
33 class CSSMappedAttributeDeclaration
;
34 class MappedAttribute
;
36 class StyledElement
: public Element
{
38 StyledElement(const QualifiedName
&, Document
*);
39 virtual ~StyledElement();
41 virtual bool isStyledElement() const { return true; }
43 NamedMappedAttrMap
* mappedAttributes() { return static_cast<NamedMappedAttrMap
*>(namedAttrMap
.get()); }
44 const NamedMappedAttrMap
* mappedAttributes() const { return static_cast<NamedMappedAttrMap
*>(namedAttrMap
.get()); }
45 bool hasMappedAttributes() const { return namedAttrMap
&& mappedAttributes()->hasMappedAttributes(); }
46 bool isMappedAttribute(const QualifiedName
& name
) const { MappedAttributeEntry res
= eNone
; mapToEntry(name
, res
); return res
!= eNone
; }
48 void addCSSLength(MappedAttribute
* attr
, int id
, const String
&value
);
49 void addCSSProperty(MappedAttribute
* attr
, int id
, const String
&value
);
50 void addCSSProperty(MappedAttribute
* attr
, int id
, int value
);
51 void addCSSStringProperty(MappedAttribute
* attr
, int id
, const String
&value
, CSSPrimitiveValue::UnitTypes
= CSSPrimitiveValue::CSS_STRING
);
52 void addCSSImageProperty(MappedAttribute
*, int propertyID
, const String
& url
);
53 void addCSSColor(MappedAttribute
* attr
, int id
, const String
&c
);
54 void createMappedDecl(MappedAttribute
* attr
);
56 static CSSMappedAttributeDeclaration
* getMappedAttributeDecl(MappedAttributeEntry type
, const QualifiedName
& name
, const AtomicString
& value
);
57 static void setMappedAttributeDecl(MappedAttributeEntry
, const QualifiedName
& name
, const AtomicString
& value
, CSSMappedAttributeDeclaration
*);
58 static void removeMappedAttributeDecl(MappedAttributeEntry type
, const QualifiedName
& name
, const AtomicString
& value
);
60 static CSSMappedAttributeDeclaration
* getMappedAttributeDecl(MappedAttributeEntry
, Attribute
*);
61 static void setMappedAttributeDecl(MappedAttributeEntry
, Attribute
*, CSSMappedAttributeDeclaration
*);
63 CSSMutableStyleDeclaration
* inlineStyleDecl() const { return m_inlineStyleDecl
.get(); }
64 virtual bool canHaveAdditionalAttributeStyleDecls() const { return false; }
65 virtual void additionalAttributeStyleDecls(Vector
<CSSMutableStyleDeclaration
*>&) {};
66 CSSMutableStyleDeclaration
* getInlineStyleDecl();
67 CSSStyleDeclaration
* style();
68 void createInlineStyleDecl();
69 void destroyInlineStyleDecl();
70 void invalidateStyleAttribute();
71 virtual void updateStyleAttribute() const;
73 const ClassNames
& classNames() const { ASSERT(hasClass()); ASSERT(mappedAttributes()); return mappedAttributes()->classNames(); }
75 virtual void attributeChanged(Attribute
*, bool preserveDecls
= false);
76 virtual void parseMappedAttribute(MappedAttribute
*);
77 virtual bool mapToEntry(const QualifiedName
& attrName
, MappedAttributeEntry
& result
) const;
78 virtual void createAttributeMap() const;
79 virtual PassRefPtr
<Attribute
> createAttribute(const QualifiedName
&, const AtomicString
& value
);
81 virtual void copyNonAttributeProperties(const Element
*);
84 // classAttributeChanged() exists to share code between
85 // parseMappedAttribute (called via setAttribute()) and
86 // svgAttributeChanged (called when element.className.baseValue is set)
87 void classAttributeChanged(const AtomicString
& newClassString
);
89 RefPtr
<CSSMutableStyleDeclaration
> m_inlineStyleDecl
;