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 "StyledElement.h"
27
28 namespace WebCore {
29
30 class DocumentFragment;
31 class HTMLCollection;
32 class HTMLFormElement;
33
34 class HTMLElement : public StyledElement {
35 public:
36 static PassRefPtr<HTMLElement> create(const QualifiedName& tagName, Document*);
37
38 PassRefPtr<HTMLCollection> children();
39
40 virtual String title() const;
41
42 virtual short tabIndex() const;
43 void setTabIndex(int);
44
45 String innerHTML() const;
46 String outerHTML() const;
47 // deprecatedCreateContextualFragment logic should be moved into Range::createContextualFragment
48 PassRefPtr<DocumentFragment> deprecatedCreateContextualFragment(const String&, FragmentScriptingPermission = FragmentScriptingAllowed);
49 void setInnerHTML(const String&, ExceptionCode&);
50 void setOuterHTML(const String&, ExceptionCode&);
51 void setInnerText(const String&, ExceptionCode&);
52 void setOuterText(const String&, ExceptionCode&);
53
54 Element* insertAdjacentElement(const String& where, Element* newChild, ExceptionCode&);
55 void insertAdjacentHTML(const String& where, const String& html, ExceptionCode&);
56 void insertAdjacentText(const String& where, const String& text, ExceptionCode&);
57
58 virtual bool supportsFocus() const;
59
60 String contentEditable() const;
61 void setContentEditable(const String&, ExceptionCode&);
62
63 virtual bool draggable() const;
64 void setDraggable(bool);
65
66 bool spellcheck() const;
67 void setSpellcheck(bool);
68
69 void click();
70
71 virtual void accessKeyAction(bool sendToAnyElement);
72
73 bool ieForbidsInsertHTML() const;
74
75 virtual bool rendererIsNeeded(RenderStyle*);
76 virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
77
form()78 HTMLFormElement* form() const { return virtualForm(); }
79
80 static void addHTMLAlignmentToStyledElement(StyledElement*, Attribute*);
81
82 HTMLFormElement* findFormAncestor() const;
83
84 TextDirection directionalityIfhasDirAutoAttribute(bool& isAuto) const;
85
86 protected:
87 HTMLElement(const QualifiedName& tagName, Document*);
88
89 void addHTMLAlignment(Attribute*);
90
91 virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const;
92 virtual void parseMappedAttribute(Attribute*);
93
94 virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
95
96 private:
97 virtual String nodeName() const;
98
99 void setContentEditable(Attribute*);
100
101 virtual HTMLFormElement* virtualForm() const;
102
103 Node* insertAdjacent(const String& where, Node* newChild, ExceptionCode&);
104 PassRefPtr<DocumentFragment> textToFragment(const String&, ExceptionCode&);
105
106 void dirAttributeChanged(Attribute*);
107 void adjustDirectionalityIfNeededAfterChildAttributeChanged(Element* child);
108 void calculateAndAdjustDirectionality();
109 void adjustDirectionalityIfNeededAfterChildrenChanged(Node* beforeChange, int childCountDelta);
110 TextDirection directionality(Node** strongDirectionalityTextNode= 0) const;
111 };
112
toHTMLElement(Node * node)113 inline HTMLElement* toHTMLElement(Node* node)
114 {
115 ASSERT(!node || node->isHTMLElement());
116 return static_cast<HTMLElement*>(node);
117 }
118
toHTMLElement(const Node * node)119 inline const HTMLElement* toHTMLElement(const Node* node)
120 {
121 ASSERT(!node || node->isHTMLElement());
122 return static_cast<const HTMLElement*>(node);
123 }
124
HTMLElement(const QualifiedName & tagName,Document * document)125 inline HTMLElement::HTMLElement(const QualifiedName& tagName, Document* document)
126 : StyledElement(tagName, document, CreateHTMLElement)
127 {
128 ASSERT(tagName.localName().impl());
129 }
130
131 } // namespace WebCore
132
133 #endif // HTMLElement_h
134