• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
reset()56 void WebNode::reset()
57 {
58     m_private.reset();
59 }
60 
assign(const WebNode & other)61 void WebNode::assign(const WebNode& other)
62 {
63     m_private = other.m_private;
64 }
65 
equals(const WebNode & n) const66 bool WebNode::equals(const WebNode& n) const
67 {
68     return (m_private.get() == n.m_private.get());
69 }
70 
lessThan(const WebNode & n) const71 bool WebNode::lessThan(const WebNode& n) const
72 {
73     return (m_private.get() < n.m_private.get());
74 }
75 
nodeType() const76 WebNode::NodeType WebNode::nodeType() const
77 {
78     return static_cast<NodeType>(m_private->nodeType());
79 }
80 
parentNode() const81 WebNode WebNode::parentNode() const
82 {
83     return WebNode(const_cast<ContainerNode*>(m_private->parentNode()));
84 }
85 
nodeName() const86 WebString WebNode::nodeName() const
87 {
88     return m_private->nodeName();
89 }
90 
nodeValue() const91 WebString WebNode::nodeValue() const
92 {
93     return m_private->nodeValue();
94 }
95 
setNodeValue(const WebString & value)96 bool WebNode::setNodeValue(const WebString& value)
97 {
98     ExceptionCode exceptionCode = 0;
99     m_private->setNodeValue(value, exceptionCode);
100     return !exceptionCode;
101 }
102 
document() const103 WebDocument WebNode::document() const
104 {
105     return WebDocument(m_private->document());
106 }
107 
firstChild() const108 WebNode WebNode::firstChild() const
109 {
110     return WebNode(m_private->firstChild());
111 }
112 
lastChild() const113 WebNode WebNode::lastChild() const
114 {
115     return WebNode(m_private->lastChild());
116 }
117 
previousSibling() const118 WebNode WebNode::previousSibling() const
119 {
120     return WebNode(m_private->previousSibling());
121 }
122 
nextSibling() const123 WebNode WebNode::nextSibling() const
124 {
125     return WebNode(m_private->nextSibling());
126 }
127 
hasChildNodes() const128 bool WebNode::hasChildNodes() const
129 {
130     return m_private->hasChildNodes();
131 }
132 
childNodes()133 WebNodeList WebNode::childNodes()
134 {
135     return WebNodeList(m_private->childNodes());
136 }
137 
createMarkup() const138 WebString WebNode::createMarkup() const
139 {
140     return WebCore::createMarkup(m_private.get());
141 }
142 
isTextNode() const143 bool WebNode::isTextNode() const
144 {
145     return m_private->isTextNode();
146 }
147 
isFocusable() const148 bool WebNode::isFocusable() const
149 {
150     return m_private->isFocusable();
151 }
152 
isContentEditable() const153 bool WebNode::isContentEditable() const
154 {
155     return m_private->isContentEditable();
156 }
157 
isElementNode() const158 bool WebNode::isElementNode() const
159 {
160     return m_private->isElementNode();
161 }
162 
addEventListener(const WebString & eventType,WebDOMEventListener * listener,bool useCapture)163 void WebNode::addEventListener(const WebString& eventType, WebDOMEventListener* listener, bool useCapture)
164 {
165     EventListenerWrapper* listenerWrapper =
166         listener->createEventListenerWrapper(eventType, useCapture, m_private.get());
167     // The listenerWrapper is only referenced by the actual Node.  Once it goes
168     // away, the wrapper notifies the WebEventListener so it can clear its
169     // pointer to it.
170     m_private->addEventListener(eventType, adoptRef(listenerWrapper), useCapture);
171 }
172 
removeEventListener(const WebString & eventType,WebDOMEventListener * listener,bool useCapture)173 void WebNode::removeEventListener(const WebString& eventType, WebDOMEventListener* listener, bool useCapture)
174 {
175     EventListenerWrapper* listenerWrapper =
176         listener->getEventListenerWrapper(eventType, useCapture, m_private.get());
177     m_private->removeEventListener(eventType, listenerWrapper, useCapture);
178     // listenerWrapper is now deleted.
179 }
180 
simulateClick()181 void WebNode::simulateClick()
182 {
183     RefPtr<Event> noEvent;
184     m_private->dispatchSimulatedClick(noEvent);
185 }
186 
getElementsByTagName(const WebString & tag) const187 WebNodeList WebNode::getElementsByTagName(const WebString& tag) const
188 {
189     return WebNodeList(m_private->getElementsByTagName(tag));
190 }
191 
hasNonEmptyBoundingBox() const192 bool WebNode::hasNonEmptyBoundingBox() const
193 {
194     return m_private->hasNonEmptyBoundingBox();
195 }
196 
WebNode(const PassRefPtr<Node> & node)197 WebNode::WebNode(const PassRefPtr<Node>& node)
198     : m_private(node)
199 {
200 }
201 
operator =(const PassRefPtr<Node> & node)202 WebNode& WebNode::operator=(const PassRefPtr<Node>& node)
203 {
204     m_private = node;
205     return *this;
206 }
207 
operator PassRefPtr<Node>() const208 WebNode::operator PassRefPtr<Node>() const
209 {
210     return m_private.get();
211 }
212 
213 } // namespace WebKit
214