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/CoreExport.h"
27 #include "core/dom/Element.h"
31 class DocumentFragment
;
32 class HTMLFormElement
;
33 class HTMLMenuElement
;
36 enum TranslateAttributeMode
{
37 TranslateAttributeYes
,
39 TranslateAttributeInherit
42 class CORE_EXPORT HTMLElement
: public Element
{
43 DEFINE_WRAPPERTYPEINFO();
45 DECLARE_ELEMENT_FACTORY_WITH_TAGNAME(HTMLElement
);
47 bool hasTagName(const HTMLQualifiedName
& name
) const { return hasLocalName(name
.localName()); }
49 String
title() const final
;
50 short tabIndex() const override
;
52 void setInnerText(const String
&, ExceptionState
&);
53 void setOuterText(const String
&, ExceptionState
&);
55 virtual bool hasCustomFocusLogic() const;
57 String
contentEditable() const;
58 void setContentEditable(const String
&, ExceptionState
&);
60 virtual bool draggable() const;
61 void setDraggable(bool);
63 bool spellcheck() const;
64 void setSpellcheck(bool);
66 bool translate() const;
67 void setTranslate(bool);
69 const AtomicString
& dir();
70 void setDir(const AtomicString
&);
72 void clickForBindings();
74 void accessKeyAction(bool sendMouseEvents
) override
;
76 bool ieForbidsInsertHTML() const;
78 virtual HTMLFormElement
* formOwner() const { return nullptr; }
80 HTMLFormElement
* findFormAncestor() const;
82 bool hasDirectionAuto() const;
83 TextDirection
directionalityIfhasDirAutoAttribute(bool& isAuto
) const;
85 virtual bool isHTMLUnknownElement() const { return false; }
86 virtual bool isPluginElement() const { return false; }
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 void defaultEventHandler(Event
*) override
;
93 static const AtomicString
& eventNameForAttributeName(const QualifiedName
& attrName
);
95 bool matchesReadOnlyPseudoClass() const override
;
96 bool matchesReadWritePseudoClass() const override
;
98 static const AtomicString
& eventParameterName();
100 HTMLMenuElement
* assignedContextMenu() const;
101 HTMLMenuElement
* contextMenu() const;
102 void setContextMenu(HTMLMenuElement
*);
104 virtual String
altText() const { return String(); }
107 HTMLElement(const QualifiedName
& tagName
, Document
&, ConstructionType
);
109 void addHTMLLengthToStyle(MutableStylePropertySet
*, CSSPropertyID
, const String
& value
);
110 void addHTMLColorToStyle(MutableStylePropertySet
*, CSSPropertyID
, const String
& color
);
112 void applyAlignmentAttributeToStyle(const AtomicString
&, MutableStylePropertySet
*);
113 void applyBorderAttributeToStyle(const AtomicString
&, MutableStylePropertySet
*);
115 void parseAttribute(const QualifiedName
&, const AtomicString
&) override
;
116 bool isPresentationAttribute(const QualifiedName
&) const override
;
117 void collectStyleForPresentationAttribute(const QualifiedName
&, const AtomicString
&, MutableStylePropertySet
*) override
;
118 unsigned parseBorderWidthAttribute(const AtomicString
&) const;
120 void childrenChanged(const ChildrenChange
&) override
;
121 void calculateAndAdjustDirectionality();
124 String
nodeName() const final
;
126 bool isHTMLElement() const = delete; // This will catch anyone doing an unnecessary check.
127 bool isStyledElement() const = delete; // This will catch anyone doing an unnecessary check.
129 void mapLanguageAttributeToLocale(const AtomicString
&, MutableStylePropertySet
*);
131 PassRefPtrWillBeRawPtr
<DocumentFragment
> textToFragment(const String
&, ExceptionState
&);
133 bool selfOrAncestorHasDirAutoAttribute() const;
134 void dirAttributeChanged(const AtomicString
&);
135 void adjustDirectionalityIfNeededAfterChildAttributeChanged(Element
* child
);
136 void adjustDirectionalityIfNeededAfterChildrenChanged(const ChildrenChange
&);
137 TextDirection
directionality(Node
** strongDirectionalityTextNode
= 0) const;
139 TranslateAttributeMode
translateAttributeMode() const;
141 void handleKeypressEvent(KeyboardEvent
*);
144 DEFINE_ELEMENT_TYPE_CASTS(HTMLElement
, isHTMLElement());
146 template <typename T
> bool isElementOfType(const HTMLElement
&);
147 template <> inline bool isElementOfType
<const HTMLElement
>(const HTMLElement
&) { return true; }
149 inline HTMLElement::HTMLElement(const QualifiedName
& tagName
, Document
& document
, ConstructionType type
= CreateHTMLElement
)
150 : Element(tagName
, &document
, type
)
152 ASSERT(!tagName
.localName().isNull());
155 inline bool Node::hasTagName(const HTMLQualifiedName
& name
) const
157 return isHTMLElement() && toHTMLElement(*this).hasTagName(name
);
160 // Functor used to match HTMLElements with a specific HTML tag when using the ElementTraversal API.
161 class HasHTMLTagName
{
164 explicit HasHTMLTagName(const HTMLQualifiedName
& tagName
): m_tagName(tagName
) { }
165 bool operator() (const HTMLElement
& element
) const { return element
.hasTagName(m_tagName
); }
167 const HTMLQualifiedName
& m_tagName
;
170 // This requires isHTML*Element(const Element&) and isHTML*Element(const HTMLElement&).
171 // When the input element is an HTMLElement, we don't need to check the namespace URI, just the local name.
172 #define DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(thisType) \
173 inline bool is##thisType(const thisType* element); \
174 inline bool is##thisType(const thisType& element); \
175 inline bool is##thisType(const HTMLElement* element) { return element && is##thisType(*element); } \
176 inline bool is##thisType(const Node& node) { return node.isHTMLElement() ? is##thisType(toHTMLElement(node)) : false; } \
177 inline bool is##thisType(const Node* node) { return node && is##thisType(*node); } \
178 inline bool is##thisType(const Element* element) { return element && is##thisType(*element); } \
179 template<typename T> inline bool is##thisType(const PassRefPtr<T>& node) { return is##thisType(node.get()); } \
180 template<typename T> inline bool is##thisType(const RefPtr<T>& node) { return is##thisType(node.get()); } \
181 template <> inline bool isElementOfType<const thisType>(const HTMLElement& element) { return is##thisType(element); } \
182 DEFINE_ELEMENT_TYPE_CASTS_WITH_FUNCTION(thisType)
186 #include "core/HTMLElementTypeHelpers.h"
188 #endif // HTMLElement_h