tizen beta release
[framework/web/webkit-efl.git] / Source / WebKit / chromium / src / WebNode.cpp
1 /*
2  * Copyright (C) 2009 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #include "config.h"
32 #include "WebNode.h"
33
34 #include "Document.h"
35 #include "Element.h"
36 #include "Frame.h"
37 #include "FrameLoaderClientImpl.h"
38 #include "Node.h"
39 #include "NodeList.h"
40
41 #include "EventListenerWrapper.h"
42 #include "WebDOMEvent.h"
43 #include "WebDOMEventListener.h"
44 #include "WebDocument.h"
45 #include "WebFrameImpl.h"
46 #include "WebNodeList.h"
47 #include "WebString.h"
48 #include "WebVector.h"
49
50 #include "markup.h"
51
52 using namespace WebCore;
53
54 namespace WebKit {
55
56 void WebNode::reset()
57 {
58     m_private.reset();
59 }
60
61 void WebNode::assign(const WebNode& other)
62 {
63     m_private = other.m_private;
64 }
65
66 bool WebNode::equals(const WebNode& n) const
67 {
68     return (m_private.get() == n.m_private.get());
69 }
70
71 bool WebNode::lessThan(const WebNode& n) const
72 {
73     return (m_private.get() < n.m_private.get());
74 }
75
76 WebNode::NodeType WebNode::nodeType() const
77 {
78     return static_cast<NodeType>(m_private->nodeType());
79 }
80
81 WebNode WebNode::parentNode() const
82 {
83     return WebNode(const_cast<ContainerNode*>(m_private->parentNode()));
84 }
85
86 WebString WebNode::nodeName() const
87 {
88     return m_private->nodeName();
89 }
90
91 WebString WebNode::nodeValue() const
92 {
93     return m_private->nodeValue();
94 }
95
96 bool WebNode::setNodeValue(const WebString& value)
97 {
98     ExceptionCode exceptionCode = 0;
99     m_private->setNodeValue(value, exceptionCode);
100     return !exceptionCode;
101 }
102
103 WebDocument WebNode::document() const
104 {
105     return WebDocument(m_private->document());
106 }
107
108 WebNode WebNode::firstChild() const
109 {
110     return WebNode(m_private->firstChild());
111 }
112
113 WebNode WebNode::lastChild() const
114 {
115     return WebNode(m_private->lastChild());
116 }
117
118 WebNode WebNode::previousSibling() const
119 {
120     return WebNode(m_private->previousSibling());
121 }
122
123 WebNode WebNode::nextSibling() const
124 {
125     return WebNode(m_private->nextSibling());
126 }
127
128 bool WebNode::hasChildNodes() const
129 {
130     return m_private->hasChildNodes();
131 }
132
133 WebNodeList WebNode::childNodes()
134 {
135     return WebNodeList(m_private->childNodes());
136 }
137
138 WebString WebNode::createMarkup() const
139 {
140     return WebCore::createMarkup(m_private.get());
141 }
142
143 bool WebNode::isLink() const
144 {
145     return m_private->isLink();
146 }
147
148 bool WebNode::isTextNode() const
149 {
150     return m_private->isTextNode();
151 }
152
153 bool WebNode::isFocusable() const
154 {
155     m_private->document()->updateLayout();
156     return m_private->isFocusable();
157 }
158
159 bool WebNode::isContentEditable() const
160 {
161     return m_private->isContentEditable();
162 }
163
164 bool WebNode::isElementNode() const
165 {
166     return m_private->isElementNode();
167 }
168
169 bool WebNode::hasEventListeners(const WebString& eventType) const
170 {
171     return m_private->hasEventListeners(eventType);
172 }
173
174 void WebNode::addEventListener(const WebString& eventType, WebDOMEventListener* listener, bool useCapture)
175 {
176     EventListenerWrapper* listenerWrapper =
177         listener->createEventListenerWrapper(eventType, useCapture, m_private.get());
178     // The listenerWrapper is only referenced by the actual Node.  Once it goes
179     // away, the wrapper notifies the WebEventListener so it can clear its
180     // pointer to it.
181     m_private->addEventListener(eventType, adoptRef(listenerWrapper), useCapture);
182 }
183
184 void WebNode::removeEventListener(const WebString& eventType, WebDOMEventListener* listener, bool useCapture)
185 {
186     EventListenerWrapper* listenerWrapper =
187         listener->getEventListenerWrapper(eventType, useCapture, m_private.get());
188     m_private->removeEventListener(eventType, listenerWrapper, useCapture);
189     // listenerWrapper is now deleted.
190 }
191
192 bool WebNode::dispatchEvent(const WebDOMEvent& event)
193 {
194     if (!event.isNull())
195         return m_private->dispatchEvent(event);
196     return false;
197 }
198
199 void WebNode::simulateClick()
200 {
201     RefPtr<Event> noEvent;
202     m_private->dispatchSimulatedClick(noEvent);
203 }
204
205 WebNodeList WebNode::getElementsByTagName(const WebString& tag) const
206 {
207     return WebNodeList(m_private->getElementsByTagName(tag));
208 }
209
210 bool WebNode::hasNonEmptyBoundingBox() const
211 {
212     return m_private->hasNonEmptyBoundingBox();
213 }
214
215 WebNode::WebNode(const PassRefPtr<Node>& node)
216     : m_private(node)
217 {
218 }
219
220 WebNode& WebNode::operator=(const PassRefPtr<Node>& node)
221 {
222     m_private = node;
223     return *this;
224 }
225
226 WebNode::operator PassRefPtr<Node>() const
227 {
228     return m_private.get();
229 }
230
231 } // namespace WebKit