492555175a634650522c5f699d2c414e1fc17a3e
[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, 2005, 2006, 2007, 2009 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 WebCore {
29
30 class DocumentFragment;
31 class HTMLCollection;
32 class HTMLFormElement;
33 class ExceptionState;
34
35 enum TranslateAttributeMode {
36     TranslateAttributeYes,
37     TranslateAttributeNo,
38     TranslateAttributeInherit
39 };
40
41 class HTMLElement : public Element {
42 public:
43     DECLARE_ELEMENT_FACTORY_WITH_TAGNAME(HTMLElement);
44
45     virtual String title() const OVERRIDE FINAL;
46     virtual short tabIndex() const OVERRIDE;
47
48     void setInnerText(const String&, ExceptionState&);
49     void setOuterText(const String&, ExceptionState&);
50
51     virtual bool hasCustomFocusLogic() const;
52
53     String contentEditable() const;
54     void setContentEditable(const String&, ExceptionState&);
55
56     virtual bool draggable() const;
57     void setDraggable(bool);
58
59     bool spellcheck() const;
60     void setSpellcheck(bool);
61
62     bool translate() const;
63     void setTranslate(bool);
64
65     const AtomicString& dir();
66     void setDir(const AtomicString&);
67
68     void click();
69
70     virtual void accessKeyAction(bool sendMouseEvents) OVERRIDE;
71
72     bool ieForbidsInsertHTML() const;
73
74     virtual HTMLFormElement* formOwner() const { return 0; }
75
76     HTMLFormElement* findFormAncestor() const;
77
78     bool hasDirectionAuto() const;
79     TextDirection directionalityIfhasDirAutoAttribute(bool& isAuto) const;
80
81     virtual bool isHTMLUnknownElement() const { return false; }
82     virtual bool isPluginElement() const { return false; }
83
84     virtual bool isLabelable() const { return false; }
85     // http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#interactive-content
86     virtual bool isInteractiveContent() const;
87     virtual void defaultEventHandler(Event*) OVERRIDE;
88
89     static const AtomicString& eventNameForAttributeName(const QualifiedName& attrName);
90
91     virtual bool matchesReadOnlyPseudoClass() const OVERRIDE;
92     virtual bool matchesReadWritePseudoClass() const OVERRIDE;
93
94     static const AtomicString& eventParameterName();
95
96 protected:
97     HTMLElement(const QualifiedName& tagName, Document&, ConstructionType);
98
99     void addHTMLLengthToStyle(MutableStylePropertySet*, CSSPropertyID, const String& value);
100     void addHTMLColorToStyle(MutableStylePropertySet*, CSSPropertyID, const String& color);
101
102     void applyAlignmentAttributeToStyle(const AtomicString&, MutableStylePropertySet*);
103     void applyBorderAttributeToStyle(const AtomicString&, MutableStylePropertySet*);
104
105     virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
106     virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE;
107     virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) OVERRIDE;
108     unsigned parseBorderWidthAttribute(const AtomicString&) const;
109
110     virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0) OVERRIDE;
111     void calculateAndAdjustDirectionality();
112
113 private:
114     virtual String nodeName() const OVERRIDE FINAL;
115
116     void mapLanguageAttributeToLocale(const AtomicString&, MutableStylePropertySet*);
117
118     PassRefPtrWillBeRawPtr<DocumentFragment> textToFragment(const String&, ExceptionState&);
119
120     void dirAttributeChanged(const AtomicString&);
121     void adjustDirectionalityIfNeededAfterChildAttributeChanged(Element* child);
122     void adjustDirectionalityIfNeededAfterChildrenChanged(Node* beforeChange, int childCountDelta);
123     TextDirection directionality(Node** strongDirectionalityTextNode= 0) const;
124
125     TranslateAttributeMode translateAttributeMode() const;
126
127     void handleKeypressEvent(KeyboardEvent*);
128 };
129
130 DEFINE_ELEMENT_TYPE_CASTS(HTMLElement, isHTMLElement());
131
132 template <> inline bool isElementOfType<const HTMLElement>(const Node& node) { return node.isHTMLElement(); }
133 template <typename T> bool isElementOfType(const HTMLElement&);
134 template <> inline bool isElementOfType<const HTMLElement>(const HTMLElement&) { return true; }
135
136 inline HTMLElement::HTMLElement(const QualifiedName& tagName, Document& document, ConstructionType type = CreateHTMLElement)
137     : Element(tagName, &document, type)
138 {
139     ASSERT(!tagName.localName().isNull());
140     ScriptWrappable::init(this);
141 }
142
143 // This requires isHTML*Element(const Element&) and isHTML*Element(const HTMLElement&).
144 // When the input element is an HTMLElement, we don't need to check the namespace URI, just the local name.
145 #define DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(thisType) \
146     inline bool is##thisType(const thisType* element); \
147     inline bool is##thisType(const thisType& element); \
148     inline bool is##thisType(const HTMLElement* element) { return element && is##thisType(*element); } \
149     inline bool is##thisType(const Element* element) { return element && is##thisType(*element); } \
150     inline bool is##thisType(const Node& node) { return node.isElementNode() ? is##thisType(toElement(node)) : false; } \
151     inline bool is##thisType(const Node* node) { return node && node->isElementNode() ? is##thisType(*toElement(node)) : false; } \
152     template<typename T> inline bool is##thisType(const PassRefPtr<T>& node) { return is##thisType(node.get()); } \
153     template<typename T> inline bool is##thisType(const RefPtr<T>& node) { return is##thisType(node.get()); } \
154     template <> inline bool isElementOfType<const thisType>(const HTMLElement& element) { return is##thisType(element); } \
155     DEFINE_ELEMENT_TYPE_CASTS_WITH_FUNCTION(thisType)
156
157 } // namespace WebCore
158
159 #include "core/HTMLElementTypeHelpers.h"
160
161 #endif // HTMLElement_h