Home | History | Annotate | Download | only in html
      1 /*
      2  * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org)
      3  *           (C) 1999 Antti Koivisto (koivisto (at) kde.org)
      4  * Copyright (C) 2004-2007, 2009, 2014 Apple Inc. All rights reserved.
      5  *
      6  * This library is free software; you can redistribute it and/or
      7  * modify it under the terms of the GNU Library General Public
      8  * License as published by the Free Software Foundation; either
      9  * version 2 of the License, or (at your option) any later version.
     10  *
     11  * This library is distributed in the hope that it will be useful,
     12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     14  * Library General Public License for more details.
     15  *
     16  * You should have received a copy of the GNU Library General Public License
     17  * along with this library; see the file COPYING.LIB.  If not, write to
     18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     19  * Boston, MA 02110-1301, USA.
     20  *
     21  */
     22 
     23 #ifndef HTMLElement_h
     24 #define HTMLElement_h
     25 
     26 #include "core/dom/Element.h"
     27 
     28 namespace blink {
     29 
     30 class DocumentFragment;
     31 class HTMLCollection;
     32 class HTMLFormElement;
     33 class HTMLMenuElement;
     34 class ExceptionState;
     35 
     36 enum TranslateAttributeMode {
     37     TranslateAttributeYes,
     38     TranslateAttributeNo,
     39     TranslateAttributeInherit
     40 };
     41 
     42 class HTMLElement : public Element {
     43     DEFINE_WRAPPERTYPEINFO();
     44 public:
     45     DECLARE_ELEMENT_FACTORY_WITH_TAGNAME(HTMLElement);
     46 
     47     bool hasTagName(const HTMLQualifiedName& name) const { return hasLocalName(name.localName()); }
     48 
     49     virtual String title() const OVERRIDE FINAL;
     50     virtual short tabIndex() const OVERRIDE;
     51 
     52     void setInnerText(const String&, ExceptionState&);
     53     void setOuterText(const String&, ExceptionState&);
     54 
     55     virtual bool hasCustomFocusLogic() const;
     56 
     57     String contentEditable() const;
     58     void setContentEditable(const String&, ExceptionState&);
     59 
     60     virtual bool draggable() const;
     61     void setDraggable(bool);
     62 
     63     bool spellcheck() const;
     64     void setSpellcheck(bool);
     65 
     66     bool translate() const;
     67     void setTranslate(bool);
     68 
     69     const AtomicString& dir();
     70     void setDir(const AtomicString&);
     71 
     72     void click();
     73 
     74     virtual void accessKeyAction(bool sendMouseEvents) OVERRIDE;
     75 
     76     bool ieForbidsInsertHTML() const;
     77 
     78     virtual HTMLFormElement* formOwner() const { return 0; }
     79 
     80     HTMLFormElement* findFormAncestor() const;
     81 
     82     bool hasDirectionAuto() const;
     83     TextDirection directionalityIfhasDirAutoAttribute(bool& isAuto) const;
     84 
     85     virtual bool isHTMLUnknownElement() const { return false; }
     86     virtual bool isPluginElement() const { return false; }
     87 
     88     virtual bool isLabelable() const { return false; }
     89     // http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#interactive-content
     90     virtual bool isInteractiveContent() const;
     91     virtual void defaultEventHandler(Event*) OVERRIDE;
     92 
     93     static const AtomicString& eventNameForAttributeName(const QualifiedName& attrName);
     94 
     95     virtual bool matchesReadOnlyPseudoClass() const OVERRIDE;
     96     virtual bool matchesReadWritePseudoClass() const OVERRIDE;
     97 
     98     static const AtomicString& eventParameterName();
     99 
    100     HTMLMenuElement* contextMenu() const;
    101     void setContextMenu(HTMLMenuElement*);
    102 
    103 protected:
    104     HTMLElement(const QualifiedName& tagName, Document&, ConstructionType);
    105 
    106     void addHTMLLengthToStyle(MutableStylePropertySet*, CSSPropertyID, const String& value);
    107     void addHTMLColorToStyle(MutableStylePropertySet*, CSSPropertyID, const String& color);
    108 
    109     void applyAlignmentAttributeToStyle(const AtomicString&, MutableStylePropertySet*);
    110     void applyBorderAttributeToStyle(const AtomicString&, MutableStylePropertySet*);
    111 
    112     virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
    113     virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE;
    114     virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) OVERRIDE;
    115     unsigned parseBorderWidthAttribute(const AtomicString&) const;
    116 
    117     virtual void childrenChanged(const ChildrenChange&) OVERRIDE;
    118     void calculateAndAdjustDirectionality();
    119 
    120 private:
    121     virtual String nodeName() const OVERRIDE FINAL;
    122 
    123     bool isHTMLElement() const WTF_DELETED_FUNCTION; // This will catch anyone doing an unnecessary check.
    124     bool isStyledElement() const WTF_DELETED_FUNCTION; // This will catch anyone doing an unnecessary check.
    125 
    126     void mapLanguageAttributeToLocale(const AtomicString&, MutableStylePropertySet*);
    127 
    128     PassRefPtrWillBeRawPtr<DocumentFragment> textToFragment(const String&, ExceptionState&);
    129 
    130     void dirAttributeChanged(const AtomicString&);
    131     void adjustDirectionalityIfNeededAfterChildAttributeChanged(Element* child);
    132     void adjustDirectionalityIfNeededAfterChildrenChanged(const ChildrenChange&);
    133     TextDirection directionality(Node** strongDirectionalityTextNode= 0) const;
    134 
    135     TranslateAttributeMode translateAttributeMode() const;
    136 
    137     void handleKeypressEvent(KeyboardEvent*);
    138 };
    139 
    140 DEFINE_ELEMENT_TYPE_CASTS(HTMLElement, isHTMLElement());
    141 
    142 template <typename T> bool isElementOfType(const HTMLElement&);
    143 template <> inline bool isElementOfType<const HTMLElement>(const HTMLElement&) { return true; }
    144 
    145 inline HTMLElement::HTMLElement(const QualifiedName& tagName, Document& document, ConstructionType type = CreateHTMLElement)
    146     : Element(tagName, &document, type)
    147 {
    148     ASSERT(!tagName.localName().isNull());
    149 }
    150 
    151 inline bool Node::hasTagName(const HTMLQualifiedName& name) const
    152 {
    153     return isHTMLElement() && toHTMLElement(*this).hasTagName(name);
    154 }
    155 
    156 // Functor used to match HTMLElements with a specific HTML tag when using the ElementTraversal API.
    157 class HasHTMLTagName {
    158 public:
    159     explicit HasHTMLTagName(const HTMLQualifiedName& tagName): m_tagName(tagName) { }
    160     bool operator() (const HTMLElement& element) const { return element.hasTagName(m_tagName); }
    161 private:
    162     const HTMLQualifiedName& m_tagName;
    163 };
    164 
    165 // This requires isHTML*Element(const Element&) and isHTML*Element(const HTMLElement&).
    166 // When the input element is an HTMLElement, we don't need to check the namespace URI, just the local name.
    167 #define DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(thisType) \
    168     inline bool is##thisType(const thisType* element); \
    169     inline bool is##thisType(const thisType& element); \
    170     inline bool is##thisType(const HTMLElement* element) { return element && is##thisType(*element); } \
    171     inline bool is##thisType(const Node& node) { return node.isHTMLElement() ? is##thisType(toHTMLElement(node)) : false; } \
    172     inline bool is##thisType(const Node* node) { return node && is##thisType(*node); } \
    173     inline bool is##thisType(const Element* element) { return element && is##thisType(*element); } \
    174     template<typename T> inline bool is##thisType(const PassRefPtr<T>& node) { return is##thisType(node.get()); } \
    175     template<typename T> inline bool is##thisType(const RefPtr<T>& node) { return is##thisType(node.get()); } \
    176     template <> inline bool isElementOfType<const thisType>(const HTMLElement& element) { return is##thisType(element); } \
    177     DEFINE_ELEMENT_TYPE_CASTS_WITH_FUNCTION(thisType)
    178 
    179 } // namespace blink
    180 
    181 #include "core/HTMLElementTypeHelpers.h"
    182 
    183 #endif // HTMLElement_h
    184