WebKit/chromium/src/WebNode.cpp
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     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 "Frame.h"
       
    36 #include "FrameLoaderClientImpl.h"
       
    37 #include "Node.h"
       
    38 #include "NodeList.h"
       
    39 
       
    40 #include "EventListenerWrapper.h"
       
    41 #include "WebDocument.h"
       
    42 #include "WebEvent.h"
       
    43 #include "WebEventListener.h"
       
    44 #include "WebFrameImpl.h"
       
    45 #include "WebNodeList.h"
       
    46 #include "WebString.h"
       
    47 #include "WebVector.h"
       
    48 
       
    49 #include "markup.h"
       
    50 
       
    51 using namespace WebCore;
       
    52 
       
    53 namespace WebKit {
       
    54 
       
    55 void WebNode::reset()
       
    56 {
       
    57     m_private.reset();
       
    58 }
       
    59 
       
    60 void WebNode::assign(const WebNode& other)
       
    61 {
       
    62     m_private = other.m_private;
       
    63 }
       
    64 
       
    65 bool WebNode::equals(const WebNode& n) const
       
    66 {
       
    67     return (m_private.get() == n.m_private.get());
       
    68 }
       
    69 
       
    70 bool WebNode::lessThan(const WebNode& n) const
       
    71 {
       
    72     return (m_private.get() < n.m_private.get());
       
    73 }
       
    74 
       
    75 WebNode::NodeType WebNode::nodeType() const
       
    76 {
       
    77     return static_cast<NodeType>(m_private->nodeType());
       
    78 }
       
    79 
       
    80 WebNode WebNode::parentNode() const
       
    81 {
       
    82     return WebNode(const_cast<Node*>(m_private->parentNode()));
       
    83 }
       
    84 
       
    85 WebString WebNode::nodeName() const
       
    86 {
       
    87     return m_private->nodeName();
       
    88 }
       
    89 
       
    90 WebString WebNode::nodeValue() const
       
    91 {
       
    92     return m_private->nodeValue();
       
    93 }
       
    94 
       
    95 bool WebNode::setNodeValue(const WebString& value)
       
    96 {
       
    97     ExceptionCode exceptionCode = 0;
       
    98     m_private->setNodeValue(value, exceptionCode);
       
    99     return !exceptionCode;
       
   100 }
       
   101 
       
   102 WebDocument WebNode::document() const
       
   103 {
       
   104     return WebDocument(m_private->document());
       
   105 }
       
   106 
       
   107 WebNode WebNode::firstChild() const
       
   108 {
       
   109     return WebNode(m_private->firstChild());
       
   110 }
       
   111 
       
   112 WebNode WebNode::lastChild() const
       
   113 {
       
   114     return WebNode(m_private->lastChild());
       
   115 }
       
   116 
       
   117 WebNode WebNode::previousSibling() const
       
   118 {
       
   119     return WebNode(m_private->previousSibling());
       
   120 }
       
   121 
       
   122 WebNode WebNode::nextSibling() const
       
   123 {
       
   124     return WebNode(m_private->nextSibling());
       
   125 }
       
   126 
       
   127 bool WebNode::hasChildNodes() const
       
   128 {
       
   129     return m_private->hasChildNodes();
       
   130 }
       
   131 
       
   132 WebNodeList WebNode::childNodes()
       
   133 {
       
   134     return WebNodeList(m_private->childNodes());
       
   135 }
       
   136 
       
   137 WebString WebNode::createMarkup() const
       
   138 {
       
   139     return WebCore::createMarkup(m_private.get());
       
   140 }
       
   141 
       
   142 bool WebNode::isTextNode() const
       
   143 {
       
   144     return m_private->isTextNode();
       
   145 }
       
   146 
       
   147 bool WebNode::isElementNode() const
       
   148 {
       
   149     return m_private->isElementNode();
       
   150 }
       
   151 
       
   152 void WebNode::addEventListener(const WebString& eventType, WebEventListener* listener, bool useCapture)
       
   153 {
       
   154     EventListenerWrapper* listenerWrapper =
       
   155         listener->createEventListenerWrapper(eventType, useCapture, m_private.get());
       
   156     // The listenerWrapper is only referenced by the actual Node.  Once it goes
       
   157     // away, the wrapper notifies the WebEventListener so it can clear its
       
   158     // pointer to it.
       
   159     m_private->addEventListener(eventType, adoptRef(listenerWrapper), useCapture);
       
   160 }
       
   161 
       
   162 void WebNode::removeEventListener(const WebString& eventType, WebEventListener* listener, bool useCapture)
       
   163 {
       
   164     EventListenerWrapper* listenerWrapper =
       
   165         listener->getEventListenerWrapper(eventType, useCapture, m_private.get());
       
   166     m_private->removeEventListener(eventType, listenerWrapper, useCapture);
       
   167     // listenerWrapper is now deleted.
       
   168 }
       
   169 
       
   170 void WebNode::simulateClick()
       
   171 {
       
   172     RefPtr<Event> noEvent;
       
   173     m_private->dispatchSimulatedClick(noEvent);
       
   174 }
       
   175 
       
   176 WebNodeList WebNode::getElementsByTagName(const WebString& tag) const
       
   177 {
       
   178     return WebNodeList(m_private->getElementsByTagName(tag));
       
   179 }
       
   180 
       
   181 bool WebNode::hasNonEmptyBoundingBox() const
       
   182 {
       
   183     return m_private->hasNonEmptyBoundingBox();
       
   184 }
       
   185 
       
   186 WebNode::WebNode(const PassRefPtr<Node>& node)
       
   187     : m_private(node)
       
   188 {
       
   189 }
       
   190 
       
   191 WebNode& WebNode::operator=(const PassRefPtr<Node>& node)
       
   192 {
       
   193     m_private = node;
       
   194     return *this;
       
   195 }
       
   196 
       
   197 WebNode::operator PassRefPtr<Node>() const
       
   198 {
       
   199     return m_private.get();
       
   200 }
       
   201 
       
   202 } // namespace WebKit