Home | History | Annotate | Download | only in dom
      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, 2010 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 "Element.h"
     29 #include "MappedAttributeEntry.h"
     30 
     31 namespace WebCore {
     32 
     33 class Attribute;
     34 class CSSMappedAttributeDeclaration;
     35 class CSSMutableStyleDeclaration;
     36 
     37 class StyledElement : public Element {
     38 public:
     39     virtual ~StyledElement();
     40 
     41     bool hasMappedAttributes() const { return attributeMap() && attributeMap()->hasMappedAttributes(); }
     42     bool isMappedAttribute(const QualifiedName& name) const { MappedAttributeEntry res = eNone; mapToEntry(name, res); return res != eNone; }
     43 
     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 
     50     static CSSMappedAttributeDeclaration* getMappedAttributeDecl(MappedAttributeEntry, const QualifiedName& name, const AtomicString& value);
     51     static void setMappedAttributeDecl(MappedAttributeEntry, const QualifiedName& name, const AtomicString& value, CSSMappedAttributeDeclaration*);
     52     static void removeMappedAttributeDecl(MappedAttributeEntry, const QualifiedName& name, const AtomicString& value);
     53 
     54     static CSSMappedAttributeDeclaration* getMappedAttributeDecl(MappedAttributeEntry, Attribute*);
     55     static void setMappedAttributeDecl(MappedAttributeEntry, Attribute*, CSSMappedAttributeDeclaration*);
     56 
     57     CSSMutableStyleDeclaration* inlineStyleDecl() const { return m_inlineStyleDecl.get(); }
     58     virtual bool canHaveAdditionalAttributeStyleDecls() const { return false; }
     59     virtual void additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>&) { }
     60     CSSMutableStyleDeclaration* getInlineStyleDecl();
     61     CSSStyleDeclaration* style();
     62     void invalidateStyleAttribute();
     63 
     64     const SpaceSplitString& classNames() const;
     65 
     66     virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const;
     67 
     68     virtual PassRefPtr<Attribute> createAttribute(const QualifiedName&, const AtomicString& value);
     69 
     70 protected:
     71     StyledElement(const QualifiedName& name, Document* document, ConstructionType type)
     72         : Element(name, document, type)
     73     {
     74     }
     75 
     76     virtual void attributeChanged(Attribute*, bool preserveDecls = false);
     77     virtual void parseMappedAttribute(Attribute*);
     78     virtual void copyNonAttributeProperties(const Element*);
     79 
     80     virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const;
     81 
     82     // classAttributeChanged() exists to share code between
     83     // parseMappedAttribute (called via setAttribute()) and
     84     // svgAttributeChanged (called when element.className.baseValue is set)
     85     void classAttributeChanged(const AtomicString& newClassString);
     86 
     87     virtual void didMoveToNewOwnerDocument();
     88 
     89 private:
     90     void createMappedDecl(Attribute*);
     91 
     92     void createInlineStyleDecl();
     93     void destroyInlineStyleDecl();
     94     virtual void updateStyleAttribute() const;
     95 
     96     RefPtr<CSSMutableStyleDeclaration> m_inlineStyleDecl;
     97 };
     98 
     99 inline const SpaceSplitString& StyledElement::classNames() const
    100 {
    101     ASSERT(hasClass());
    102     ASSERT(attributeMap());
    103     return attributeMap()->classNames();
    104 }
    105 
    106 inline void StyledElement::invalidateStyleAttribute()
    107 {
    108     clearIsStyleAttributeValid();
    109 }
    110 
    111 } //namespace
    112 
    113 #endif
    114