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 52using namespace WebCore; 53 54namespace WebKit { 55 56void WebNode::reset() 57{ 58 m_private.reset(); 59} 60 61void WebNode::assign(const WebNode& other) 62{ 63 m_private = other.m_private; 64} 65 66bool WebNode::equals(const WebNode& n) const 67{ 68 return (m_private.get() == n.m_private.get()); 69} 70 71bool WebNode::lessThan(const WebNode& n) const 72{ 73 return (m_private.get() < n.m_private.get()); 74} 75 76WebNode::NodeType WebNode::nodeType() const 77{ 78 return static_cast<NodeType>(m_private->nodeType()); 79} 80 81WebNode WebNode::parentNode() const 82{ 83 return WebNode(const_cast<ContainerNode*>(m_private->parentNode())); 84} 85 86WebString WebNode::nodeName() const 87{ 88 return m_private->nodeName(); 89} 90 91WebString WebNode::nodeValue() const 92{ 93 return m_private->nodeValue(); 94} 95 96bool WebNode::setNodeValue(const WebString& value) 97{ 98 ExceptionCode exceptionCode = 0; 99 m_private->setNodeValue(value, exceptionCode); 100 return !exceptionCode; 101} 102 103WebDocument WebNode::document() const 104{ 105 return WebDocument(m_private->document()); 106} 107 108WebNode WebNode::firstChild() const 109{ 110 return WebNode(m_private->firstChild()); 111} 112 113WebNode WebNode::lastChild() const 114{ 115 return WebNode(m_private->lastChild()); 116} 117 118WebNode WebNode::previousSibling() const 119{ 120 return WebNode(m_private->previousSibling()); 121} 122 123WebNode WebNode::nextSibling() const 124{ 125 return WebNode(m_private->nextSibling()); 126} 127 128bool WebNode::hasChildNodes() const 129{ 130 return m_private->hasChildNodes(); 131} 132 133WebNodeList WebNode::childNodes() 134{ 135 return WebNodeList(m_private->childNodes()); 136} 137 138WebString WebNode::createMarkup() const 139{ 140 return WebCore::createMarkup(m_private.get()); 141} 142 143bool WebNode::isTextNode() const 144{ 145 return m_private->isTextNode(); 146} 147 148bool WebNode::isFocusable() const 149{ 150 return m_private->isFocusable(); 151} 152 153bool WebNode::isContentEditable() const 154{ 155 return m_private->isContentEditable(); 156} 157 158bool WebNode::isElementNode() const 159{ 160 return m_private->isElementNode(); 161} 162 163void 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 173void 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 181void WebNode::simulateClick() 182{ 183 RefPtr<Event> noEvent; 184 m_private->dispatchSimulatedClick(noEvent); 185} 186 187WebNodeList WebNode::getElementsByTagName(const WebString& tag) const 188{ 189 return WebNodeList(m_private->getElementsByTagName(tag)); 190} 191 192bool WebNode::hasNonEmptyBoundingBox() const 193{ 194 return m_private->hasNonEmptyBoundingBox(); 195} 196 197WebNode::WebNode(const PassRefPtr<Node>& node) 198 : m_private(node) 199{ 200} 201 202WebNode& WebNode::operator=(const PassRefPtr<Node>& node) 203{ 204 m_private = node; 205 return *this; 206} 207 208WebNode::operator PassRefPtr<Node>() const 209{ 210 return m_private.get(); 211} 212 213} // namespace WebKit 214