1 /* 2 * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org) 3 * (C) 1999 Antti Koivisto (koivisto (at) kde.org) 4 * (C) 2001 Peter Kelly (pmk (at) post.com) 5 * (C) 2001 Dirk Mueller (mueller (at) kde.org) 6 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 7 * 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. 12 * 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. 17 * 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. 22 * 23 */ 24 25 #ifndef StyledElement_h 26 #define StyledElement_h 27 28 #include "CSSPrimitiveValue.h" 29 #include "Element.h" 30 #include "MappedAttributeEntry.h" 31 #include "NamedMappedAttrMap.h" 32 33 namespace WebCore { 34 35 class CSSMappedAttributeDeclaration; 36 class CSSMutableStyleDeclaration; 37 class MappedAttribute; 38 39 class StyledElement : public Element { 40 public: 41 virtual ~StyledElement(); 42 43 NamedMappedAttrMap* mappedAttributes() { return static_cast<NamedMappedAttrMap*>(namedAttrMap.get()); } 44 const NamedMappedAttrMap* mappedAttributes() const { return static_cast<NamedMappedAttrMap*>(namedAttrMap.get()); } 45 46 bool hasMappedAttributes() const { return namedAttrMap && mappedAttributes()->hasMappedAttributes(); } 47 bool isMappedAttribute(const QualifiedName& name) const { MappedAttributeEntry res = eNone; mapToEntry(name, res); return res != eNone; } 48 49 void addCSSLength(MappedAttribute*, int id, const String& value); 50 void addCSSProperty(MappedAttribute*, int id, const String& value); 51 void addCSSProperty(MappedAttribute*, int id, int value); 52 void addCSSImageProperty(MappedAttribute*, int propertyID, const String& url); 53 void addCSSColor(MappedAttribute*, int id, const String& color); 54 55 static CSSMappedAttributeDeclaration* getMappedAttributeDecl(MappedAttributeEntry, const QualifiedName& name, const AtomicString& value); 56 static void setMappedAttributeDecl(MappedAttributeEntry, const QualifiedName& name, const AtomicString& value, CSSMappedAttributeDeclaration*); 57 static void removeMappedAttributeDecl(MappedAttributeEntry, const QualifiedName& name, const AtomicString& value); 58 59 static CSSMappedAttributeDeclaration* getMappedAttributeDecl(MappedAttributeEntry, Attribute*); 60 static void setMappedAttributeDecl(MappedAttributeEntry, Attribute*, CSSMappedAttributeDeclaration*); 61 62 CSSMutableStyleDeclaration* inlineStyleDecl() const { return m_inlineStyleDecl.get(); } 63 virtual bool canHaveAdditionalAttributeStyleDecls() const { return false; } 64 virtual void additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>&) {}; 65 CSSMutableStyleDeclaration* getInlineStyleDecl(); 66 CSSStyleDeclaration* style(); 67 void invalidateStyleAttribute(); 68 69 const SpaceSplitString& classNames() const { ASSERT(hasClass()); ASSERT(mappedAttributes()); return mappedAttributes()->classNames(); } 70 71 virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const; 72 73 virtual PassRefPtr<Attribute> createAttribute(const QualifiedName&, const AtomicString& value); 74 75 protected: 76 StyledElement(const QualifiedName&, Document*, ConstructionType); 77 78 virtual void attributeChanged(Attribute*, bool preserveDecls = false); 79 virtual void parseMappedAttribute(MappedAttribute*); 80 virtual void copyNonAttributeProperties(const Element*); 81 82 virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const; 83 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); 88 89 virtual void didMoveToNewOwnerDocument(); 90 91 private: 92 virtual bool isStyledElement() const { return true; } 93 94 void createMappedDecl(MappedAttribute*); 95 96 void createInlineStyleDecl(); 97 void destroyInlineStyleDecl(); 98 virtual void updateStyleAttribute() const; 99 100 virtual void createAttributeMap() const; 101 102 RefPtr<CSSMutableStyleDeclaration> m_inlineStyleDecl; 103 }; 104 105 inline void StyledElement::invalidateStyleAttribute() 106 { 107 m_isStyleAttributeValid = false; 108 } 109 110 } //namespace 111 112 #endif 113