2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
37 #include "FrameLoaderClientImpl.h"
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"
52 using namespace WebCore;
61 void WebNode::assign(const WebNode& other)
63 m_private = other.m_private;
66 bool WebNode::equals(const WebNode& n) const
68 return (m_private.get() == n.m_private.get());
71 bool WebNode::lessThan(const WebNode& n) const
73 return (m_private.get() < n.m_private.get());
76 WebNode::NodeType WebNode::nodeType() const
78 return static_cast<NodeType>(m_private->nodeType());
81 WebNode WebNode::parentNode() const
83 return WebNode(const_cast<ContainerNode*>(m_private->parentNode()));
86 WebString WebNode::nodeName() const
88 return m_private->nodeName();
91 WebString WebNode::nodeValue() const
93 return m_private->nodeValue();
96 bool WebNode::setNodeValue(const WebString& value)
98 ExceptionCode exceptionCode = 0;
99 m_private->setNodeValue(value, exceptionCode);
100 return !exceptionCode;
103 WebDocument WebNode::document() const
105 return WebDocument(m_private->document());
108 WebNode WebNode::firstChild() const
110 return WebNode(m_private->firstChild());
113 WebNode WebNode::lastChild() const
115 return WebNode(m_private->lastChild());
118 WebNode WebNode::previousSibling() const
120 return WebNode(m_private->previousSibling());
123 WebNode WebNode::nextSibling() const
125 return WebNode(m_private->nextSibling());
128 bool WebNode::hasChildNodes() const
130 return m_private->hasChildNodes();
133 WebNodeList WebNode::childNodes()
135 return WebNodeList(m_private->childNodes());
138 WebString WebNode::createMarkup() const
140 return WebCore::createMarkup(m_private.get());
143 bool WebNode::isLink() const
145 return m_private->isLink();
148 bool WebNode::isTextNode() const
150 return m_private->isTextNode();
153 bool WebNode::isFocusable() const
155 m_private->document()->updateLayout();
156 return m_private->isFocusable();
159 bool WebNode::isContentEditable() const
161 return m_private->isContentEditable();
164 bool WebNode::isElementNode() const
166 return m_private->isElementNode();
169 bool WebNode::hasEventListeners(const WebString& eventType) const
171 return m_private->hasEventListeners(eventType);
174 void WebNode::addEventListener(const WebString& eventType, WebDOMEventListener* listener, bool useCapture)
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
181 m_private->addEventListener(eventType, adoptRef(listenerWrapper), useCapture);
184 void WebNode::removeEventListener(const WebString& eventType, WebDOMEventListener* listener, bool useCapture)
186 EventListenerWrapper* listenerWrapper =
187 listener->getEventListenerWrapper(eventType, useCapture, m_private.get());
188 m_private->removeEventListener(eventType, listenerWrapper, useCapture);
189 // listenerWrapper is now deleted.
192 bool WebNode::dispatchEvent(const WebDOMEvent& event)
195 return m_private->dispatchEvent(event);
199 void WebNode::simulateClick()
201 RefPtr<Event> noEvent;
202 m_private->dispatchSimulatedClick(noEvent);
205 WebNodeList WebNode::getElementsByTagName(const WebString& tag) const
207 return WebNodeList(m_private->getElementsByTagName(tag));
210 bool WebNode::hasNonEmptyBoundingBox() const
212 return m_private->hasNonEmptyBoundingBox();
215 WebNode::WebNode(const PassRefPtr<Node>& node)
220 WebNode& WebNode::operator=(const PassRefPtr<Node>& node)
226 WebNode::operator PassRefPtr<Node>() const
228 return m_private.get();
231 } // namespace WebKit