1/*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2004-2018 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#pragma once
24
25#if ENABLE(IOS_AUTOCORRECT_AND_AUTOCAPITALIZE)
26#include "Autocapitalize.h"
27#endif
28
29#include "InputMode.h"
30#include "StyledElement.h"
31
32namespace WebCore {
33
34class DocumentFragment;
35class FormAssociatedElement;
36class FormNamedItem;
37class HTMLCollection;
38class HTMLFormElement;
39
40class HTMLElement : public StyledElement {
41 WTF_MAKE_ISO_ALLOCATED(HTMLElement);
42public:
43 static Ref<HTMLElement> create(const QualifiedName& tagName, Document&);
44
45 WEBCORE_EXPORT String title() const final;
46
47 int tabIndex() const override;
48
49 WEBCORE_EXPORT ExceptionOr<void> setInnerText(const String&);
50 WEBCORE_EXPORT ExceptionOr<void> setOuterText(const String&);
51
52 virtual bool hasCustomFocusLogic() const;
53 bool supportsFocus() const override;
54
55 WEBCORE_EXPORT String contentEditable() const;
56 WEBCORE_EXPORT ExceptionOr<void> setContentEditable(const String&);
57
58 static Editability editabilityFromContentEditableAttr(const Node&);
59
60 virtual bool draggable() const;
61 WEBCORE_EXPORT void setDraggable(bool);
62
63 WEBCORE_EXPORT bool spellcheck() const;
64 WEBCORE_EXPORT void setSpellcheck(bool);
65
66 WEBCORE_EXPORT bool translate() const;
67 WEBCORE_EXPORT void setTranslate(bool);
68
69 WEBCORE_EXPORT void click();
70
71 void accessKeyAction(bool sendMouseEvents) override;
72
73 bool rendererIsNeeded(const RenderStyle&) override;
74 RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) override;
75
76 WEBCORE_EXPORT virtual HTMLFormElement* form() const;
77
78 WEBCORE_EXPORT const AtomString& dir() const;
79 WEBCORE_EXPORT void setDir(const AtomString&);
80
81 bool hasDirectionAuto() const;
82 TextDirection directionalityIfhasDirAutoAttribute(bool& isAuto) const;
83
84 virtual bool isHTMLUnknownElement() const { return false; }
85 virtual bool isTextControlInnerTextElement() const { return false; }
86
87 bool willRespondToMouseMoveEvents() override;
88 bool willRespondToMouseWheelEvents() override;
89 bool willRespondToMouseClickEvents() override;
90
91 virtual bool isLabelable() const { return false; }
92 virtual FormNamedItem* asFormNamedItem();
93 virtual FormAssociatedElement* asFormAssociatedElement();
94
95 bool hasTagName(const HTMLQualifiedName& name) const { return hasLocalName(name.localName()); }
96
97 static const AtomString& eventNameForEventHandlerAttribute(const QualifiedName& attributeName);
98
99 // Only some element types can be disabled: https://html.spec.whatwg.org/multipage/scripting.html#concept-element-disabled
100 bool canBeActuallyDisabled() const;
101 bool isActuallyDisabled() const;
102
103#if ENABLE(IOS_AUTOCORRECT_AND_AUTOCAPITALIZE)
104 WEBCORE_EXPORT virtual AutocapitalizeType autocapitalizeType() const;
105 WEBCORE_EXPORT const AtomString& autocapitalize() const;
106 WEBCORE_EXPORT void setAutocapitalize(const AtomString& value);
107
108 bool autocorrect() const { return shouldAutocorrect(); }
109 WEBCORE_EXPORT virtual bool shouldAutocorrect() const;
110 WEBCORE_EXPORT void setAutocorrect(bool);
111#endif
112
113 WEBCORE_EXPORT InputMode canonicalInputMode() const;
114 const AtomString& inputMode() const;
115 void setInputMode(const AtomString& value);
116
117protected:
118 HTMLElement(const QualifiedName& tagName, Document&, ConstructionType);
119
120 void addHTMLLengthToStyle(MutableStyleProperties&, CSSPropertyID, const String& value);
121 void addHTMLColorToStyle(MutableStyleProperties&, CSSPropertyID, const String& color);
122
123 void applyAlignmentAttributeToStyle(const AtomString&, MutableStyleProperties&);
124 void applyBorderAttributeToStyle(const AtomString&, MutableStyleProperties&);
125
126 bool matchesReadWritePseudoClass() const override;
127 void parseAttribute(const QualifiedName&, const AtomString&) override;
128 bool isPresentationAttribute(const QualifiedName&) const override;
129 void collectStyleForPresentationAttribute(const QualifiedName&, const AtomString&, MutableStyleProperties&) override;
130 unsigned parseBorderWidthAttribute(const AtomString&) const;
131
132 void childrenChanged(const ChildChange&) override;
133 void calculateAndAdjustDirectionality();
134
135 typedef HashMap<AtomStringImpl*, AtomString> EventHandlerNameMap;
136 template<size_t tableSize> static void populateEventHandlerNameMap(EventHandlerNameMap&, const QualifiedName* const (&table)[tableSize]);
137 static const AtomString& eventNameForEventHandlerAttribute(const QualifiedName& attributeName, const EventHandlerNameMap&);
138
139private:
140 String nodeName() const final;
141
142 void mapLanguageAttributeToLocale(const AtomString&, MutableStyleProperties&);
143
144 void dirAttributeChanged(const AtomString&);
145 void adjustDirectionalityIfNeededAfterChildAttributeChanged(Element* child);
146 void adjustDirectionalityIfNeededAfterChildrenChanged(Element* beforeChange, ChildChangeType);
147 TextDirection directionality(Node** strongDirectionalityTextNode= 0) const;
148
149 static void populateEventHandlerNameMap(EventHandlerNameMap&, const QualifiedName* const table[], size_t tableSize);
150 static EventHandlerNameMap createEventHandlerNameMap();
151};
152
153inline HTMLElement::HTMLElement(const QualifiedName& tagName, Document& document, ConstructionType type = CreateHTMLElement)
154 : StyledElement(tagName, document, type)
155{
156 ASSERT(tagName.localName().impl());
157}
158
159template<size_t tableSize> inline void HTMLElement::populateEventHandlerNameMap(EventHandlerNameMap& map, const QualifiedName* const (&table)[tableSize])
160{
161 populateEventHandlerNameMap(map, table, tableSize);
162}
163
164inline bool Node::hasTagName(const HTMLQualifiedName& name) const
165{
166 return is<HTMLElement>(*this) && downcast<HTMLElement>(*this).hasTagName(name);
167}
168
169} // namespace WebCore
170
171SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::HTMLElement)
172 static bool isType(const WebCore::Node& node) { return node.isHTMLElement(); }
173 static bool isType(const WebCore::EventTarget& target) { return is<WebCore::Node>(target) && isType(downcast<WebCore::Node>(target)); }
174SPECIALIZE_TYPE_TRAITS_END()
175
176#include "HTMLElementTypeHelpers.h"
177