Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / html / HTMLElement.h
1 /*
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.
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 HTMLFormElement;
32 class HTMLMenuElement;
33 class ExceptionState;
34
35 enum TranslateAttributeMode {
36     TranslateAttributeYes,
37     TranslateAttributeNo,
38     TranslateAttributeInherit
39 };
40
41 class HTMLElement : public Element {
42     DEFINE_WRAPPERTYPEINFO();
43 public:
44     DECLARE_ELEMENT_FACTORY_WITH_TAGNAME(HTMLElement);
45
46     bool hasTagName(const HTMLQualifiedName& name) const { return hasLocalName(name.localName()); }
47
48     virtual String title() const override final;
49     virtual short tabIndex() const override;
50
51     void setInnerText(const String&, ExceptionState&);
52     void setOuterText(const String&, ExceptionState&);
53
54     virtual bool hasCustomFocusLogic() const;
55
56     String contentEditable() const;
57     void setContentEditable(const String&, ExceptionState&);
58
59     virtual bool draggable() const;
60     void setDraggable(bool);
61
62     bool spellcheck() const;
63     void setSpellcheck(bool);
64
65     bool translate() const;
66     void setTranslate(bool);
67
68     const AtomicString& dir();
69     void setDir(const AtomicString&);
70
71     void click();
72
73     virtual void accessKeyAction(bool sendMouseEvents) override;
74
75     bool ieForbidsInsertHTML() const;
76
77     virtual HTMLFormElement* formOwner() const { return nullptr; }
78
79     HTMLFormElement* findFormAncestor() const;
80
81     bool hasDirectionAuto() const;
82     TextDirection directionalityIfhasDirAutoAttribute(bool& isAuto) const;
83
84     virtual bool isHTMLUnknownElement() const { return false; }
85     virtual bool isPluginElement() const { return false; }
86
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;
91
92     static const AtomicString& eventNameForAttributeName(const QualifiedName& attrName);
93
94     virtual bool matchesReadOnlyPseudoClass() const override;
95     virtual bool matchesReadWritePseudoClass() const override;
96
97     static const AtomicString& eventParameterName();
98
99     HTMLMenuElement* contextMenu() const;
100     void setContextMenu(HTMLMenuElement*);
101
102 protected:
103     HTMLElement(const QualifiedName& tagName, Document&, ConstructionType);
104
105     void addHTMLLengthToStyle(MutableStylePropertySet*, CSSPropertyID, const String& value);
106     void addHTMLColorToStyle(MutableStylePropertySet*, CSSPropertyID, const String& color);
107
108     void applyAlignmentAttributeToStyle(const AtomicString&, MutableStylePropertySet*);
109     void applyBorderAttributeToStyle(const AtomicString&, MutableStylePropertySet*);
110
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;
115
116     virtual void childrenChanged(const ChildrenChange&) override;
117     void calculateAndAdjustDirectionality();
118
119 private:
120     virtual String nodeName() const override final;
121
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.
124
125     void mapLanguageAttributeToLocale(const AtomicString&, MutableStylePropertySet*);
126
127     PassRefPtrWillBeRawPtr<DocumentFragment> textToFragment(const String&, ExceptionState&);
128
129     void dirAttributeChanged(const AtomicString&);
130     void adjustDirectionalityIfNeededAfterChildAttributeChanged(Element* child);
131     void adjustDirectionalityIfNeededAfterChildrenChanged(const ChildrenChange&);
132     TextDirection directionality(Node** strongDirectionalityTextNode= 0) const;
133
134     TranslateAttributeMode translateAttributeMode() const;
135
136     void handleKeypressEvent(KeyboardEvent*);
137 };
138
139 DEFINE_ELEMENT_TYPE_CASTS(HTMLElement, isHTMLElement());
140
141 template <typename T> bool isElementOfType(const HTMLElement&);
142 template <> inline bool isElementOfType<const HTMLElement>(const HTMLElement&) { return true; }
143
144 inline HTMLElement::HTMLElement(const QualifiedName& tagName, Document& document, ConstructionType type = CreateHTMLElement)
145     : Element(tagName, &document, type)
146 {
147     ASSERT(!tagName.localName().isNull());
148 }
149
150 inline bool Node::hasTagName(const HTMLQualifiedName& name) const
151 {
152     return isHTMLElement() && toHTMLElement(*this).hasTagName(name);
153 }
154
155 // Functor used to match HTMLElements with a specific HTML tag when using the ElementTraversal API.
156 class HasHTMLTagName {
157 public:
158     explicit HasHTMLTagName(const HTMLQualifiedName& tagName): m_tagName(tagName) { }
159     bool operator() (const HTMLElement& element) const { return element.hasTagName(m_tagName); }
160 private:
161     const HTMLQualifiedName& m_tagName;
162 };
163
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)
177
178 } // namespace blink
179
180 #include "core/HTMLElementTypeHelpers.h"
181
182 #endif // HTMLElement_h