2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2004-2007, 2009, 2014 Apple Inc. All rights reserved.
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.
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.
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.
26 #include "core/dom/Element.h"
30 class DocumentFragment;
31 class HTMLFormElement;
32 class HTMLMenuElement;
35 enum TranslateAttributeMode {
36 TranslateAttributeYes,
38 TranslateAttributeInherit
41 class HTMLElement : public Element {
42 DEFINE_WRAPPERTYPEINFO();
44 DECLARE_ELEMENT_FACTORY_WITH_TAGNAME(HTMLElement);
46 bool hasTagName(const HTMLQualifiedName& name) const { return hasLocalName(name.localName()); }
48 virtual String title() const override final;
49 virtual short tabIndex() const override;
51 void setInnerText(const String&, ExceptionState&);
52 void setOuterText(const String&, ExceptionState&);
54 virtual bool hasCustomFocusLogic() const;
56 String contentEditable() const;
57 void setContentEditable(const String&, ExceptionState&);
59 virtual bool draggable() const;
60 void setDraggable(bool);
62 bool spellcheck() const;
63 void setSpellcheck(bool);
65 bool translate() const;
66 void setTranslate(bool);
68 const AtomicString& dir();
69 void setDir(const AtomicString&);
73 virtual void accessKeyAction(bool sendMouseEvents) override;
75 bool ieForbidsInsertHTML() const;
77 virtual HTMLFormElement* formOwner() const { return nullptr; }
79 HTMLFormElement* findFormAncestor() const;
81 bool hasDirectionAuto() const;
82 TextDirection directionalityIfhasDirAutoAttribute(bool& isAuto) const;
84 virtual bool isHTMLUnknownElement() const { return false; }
85 virtual bool isPluginElement() const { return false; }
87 virtual bool isLabelable() const { return false; }
88 // http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#interactive-content
89 virtual bool isInteractiveContent() const;
90 virtual void defaultEventHandler(Event*) override;
92 static const AtomicString& eventNameForAttributeName(const QualifiedName& attrName);
94 virtual bool matchesReadOnlyPseudoClass() const override;
95 virtual bool matchesReadWritePseudoClass() const override;
97 static const AtomicString& eventParameterName();
99 HTMLMenuElement* contextMenu() const;
100 void setContextMenu(HTMLMenuElement*);
103 HTMLElement(const QualifiedName& tagName, Document&, ConstructionType);
105 void addHTMLLengthToStyle(MutableStylePropertySet*, CSSPropertyID, const String& value);
106 void addHTMLColorToStyle(MutableStylePropertySet*, CSSPropertyID, const String& color);
108 void applyAlignmentAttributeToStyle(const AtomicString&, MutableStylePropertySet*);
109 void applyBorderAttributeToStyle(const AtomicString&, MutableStylePropertySet*);
111 virtual void parseAttribute(const QualifiedName&, const AtomicString&) override;
112 virtual bool isPresentationAttribute(const QualifiedName&) const override;
113 virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) override;
114 unsigned parseBorderWidthAttribute(const AtomicString&) const;
116 virtual void childrenChanged(const ChildrenChange&) override;
117 void calculateAndAdjustDirectionality();
120 virtual String nodeName() const override final;
122 bool isHTMLElement() const WTF_DELETED_FUNCTION; // This will catch anyone doing an unnecessary check.
123 bool isStyledElement() const WTF_DELETED_FUNCTION; // This will catch anyone doing an unnecessary check.
125 void mapLanguageAttributeToLocale(const AtomicString&, MutableStylePropertySet*);
127 PassRefPtrWillBeRawPtr<DocumentFragment> textToFragment(const String&, ExceptionState&);
129 void dirAttributeChanged(const AtomicString&);
130 void adjustDirectionalityIfNeededAfterChildAttributeChanged(Element* child);
131 void adjustDirectionalityIfNeededAfterChildrenChanged(const ChildrenChange&);
132 TextDirection directionality(Node** strongDirectionalityTextNode= 0) const;
134 TranslateAttributeMode translateAttributeMode() const;
136 void handleKeypressEvent(KeyboardEvent*);
139 DEFINE_ELEMENT_TYPE_CASTS(HTMLElement, isHTMLElement());
141 template <typename T> bool isElementOfType(const HTMLElement&);
142 template <> inline bool isElementOfType<const HTMLElement>(const HTMLElement&) { return true; }
144 inline HTMLElement::HTMLElement(const QualifiedName& tagName, Document& document, ConstructionType type = CreateHTMLElement)
145 : Element(tagName, &document, type)
147 ASSERT(!tagName.localName().isNull());
150 inline bool Node::hasTagName(const HTMLQualifiedName& name) const
152 return isHTMLElement() && toHTMLElement(*this).hasTagName(name);
155 // Functor used to match HTMLElements with a specific HTML tag when using the ElementTraversal API.
156 class HasHTMLTagName {
158 explicit HasHTMLTagName(const HTMLQualifiedName& tagName): m_tagName(tagName) { }
159 bool operator() (const HTMLElement& element) const { return element.hasTagName(m_tagName); }
161 const HTMLQualifiedName& m_tagName;
164 // This requires isHTML*Element(const Element&) and isHTML*Element(const HTMLElement&).
165 // When the input element is an HTMLElement, we don't need to check the namespace URI, just the local name.
166 #define DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(thisType) \
167 inline bool is##thisType(const thisType* element); \
168 inline bool is##thisType(const thisType& element); \
169 inline bool is##thisType(const HTMLElement* element) { return element && is##thisType(*element); } \
170 inline bool is##thisType(const Node& node) { return node.isHTMLElement() ? is##thisType(toHTMLElement(node)) : false; } \
171 inline bool is##thisType(const Node* node) { return node && is##thisType(*node); } \
172 inline bool is##thisType(const Element* element) { return element && is##thisType(*element); } \
173 template<typename T> inline bool is##thisType(const PassRefPtr<T>& node) { return is##thisType(node.get()); } \
174 template<typename T> inline bool is##thisType(const RefPtr<T>& node) { return is##thisType(node.get()); } \
175 template <> inline bool isElementOfType<const thisType>(const HTMLElement& element) { return is##thisType(element); } \
176 DEFINE_ELEMENT_TYPE_CASTS_WITH_FUNCTION(thisType)
180 #include "core/HTMLElementTypeHelpers.h"
182 #endif // HTMLElement_h