HTMLElement.h revision 2fc2651226baac27029e38c9d6ef883fa32084db
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
28namespace WebCore {
29
30class DocumentFragment;
31class HTMLCollection;
32class HTMLFormElement;
33
34class HTMLElement : public StyledElement {
35public:
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    virtual bool isContentEditable() const;
61    virtual bool isContentRichlyEditable() const;
62
63    String contentEditable() const;
64    void setContentEditable(const String&, ExceptionCode&);
65
66    virtual bool draggable() const;
67    void setDraggable(bool);
68
69    bool spellcheck() const;
70    void setSpellcheck(bool);
71
72    void click();
73
74    virtual void accessKeyAction(bool sendToAnyElement);
75
76    bool ieForbidsInsertHTML() const;
77
78    virtual bool rendererIsNeeded(RenderStyle*);
79    virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
80
81    HTMLFormElement* form() const { return virtualForm(); }
82
83    static void addHTMLAlignmentToStyledElement(StyledElement*, Attribute*);
84
85    HTMLFormElement* findFormAncestor() const;
86
87    virtual void dispatchChangeEvents();
88    virtual void dispatchInputEvents();
89
90protected:
91    HTMLElement(const QualifiedName& tagName, Document*);
92
93    void addHTMLAlignment(Attribute*);
94
95    virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const;
96    virtual void parseMappedAttribute(Attribute*);
97
98private:
99    virtual String nodeName() const;
100
101    void setContentEditable(Attribute*);
102
103    virtual HTMLFormElement* virtualForm() const;
104
105    Node* insertAdjacent(const String& where, Node* newChild, ExceptionCode&);
106    PassRefPtr<DocumentFragment> textToFragment(const String&, ExceptionCode&);
107
108    HTMLFormElement* shadowAncestorOwnerForm();
109};
110
111inline HTMLElement* toHTMLElement(Node* node)
112{
113    ASSERT(!node || node->isHTMLElement());
114    return static_cast<HTMLElement*>(node);
115}
116
117inline const HTMLElement* toHTMLElement(const Node* node)
118{
119    ASSERT(!node || node->isHTMLElement());
120    return static_cast<const HTMLElement*>(node);
121}
122
123inline HTMLElement::HTMLElement(const QualifiedName& tagName, Document* document)
124    : StyledElement(tagName, document, CreateHTMLElement)
125{
126    ASSERT(tagName.localName().impl());
127}
128
129} // namespace WebCore
130
131#endif // HTMLElement_h
132