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.
34 #include "WebCommon.h"
35 #include "WebPrivatePtr.h"
36 #include "WebString.h"
38 namespace WebCore { class Node; }
41 class WebDOMEventListener;
42 class WebDOMEventListenerPrivate;
47 // Provides access to some properties of a DOM node.
50 virtual ~WebNode() { reset(); }
53 WebNode(const WebNode& n) { assign(n); }
54 WebNode& operator=(const WebNode& n)
60 WEBKIT_EXPORT void reset();
61 WEBKIT_EXPORT void assign(const WebNode&);
63 WEBKIT_EXPORT bool equals(const WebNode&) const;
64 // Required for using WebNodes in std maps. Note the order used is
65 // arbitrary and should not be expected to have any specific meaning.
66 WEBKIT_EXPORT bool lessThan(const WebNode&) const;
68 bool isNull() const { return m_private.isNull(); }
77 ProcessingInstructionsNode,
86 WEBKIT_EXPORT NodeType nodeType() const;
87 WEBKIT_EXPORT WebNode parentNode() const;
88 WEBKIT_EXPORT WebString nodeName() const;
89 WEBKIT_EXPORT WebString nodeValue() const;
90 WEBKIT_EXPORT bool setNodeValue(const WebString&);
91 WEBKIT_EXPORT WebDocument document() const;
92 WEBKIT_EXPORT WebNode firstChild() const;
93 WEBKIT_EXPORT WebNode lastChild() const;
94 WEBKIT_EXPORT WebNode previousSibling() const;
95 WEBKIT_EXPORT WebNode nextSibling() const;
96 WEBKIT_EXPORT bool hasChildNodes() const;
97 WEBKIT_EXPORT WebNodeList childNodes();
98 WEBKIT_EXPORT WebString createMarkup() const;
99 WEBKIT_EXPORT bool isLink() const;
100 WEBKIT_EXPORT bool isTextNode() const;
101 WEBKIT_EXPORT bool isFocusable() const;
102 WEBKIT_EXPORT bool isContentEditable() const;
103 WEBKIT_EXPORT bool isElementNode() const;
104 WEBKIT_EXPORT void addEventListener(const WebString& eventType, WebDOMEventListener* listener, bool useCapture);
105 WEBKIT_EXPORT void removeEventListener(const WebString& eventType, WebDOMEventListener* listener, bool useCapture);
106 WEBKIT_EXPORT void simulateClick();
107 WEBKIT_EXPORT WebNodeList getElementsByTagName(const WebString&) const;
109 // Returns true if the node has a non-empty bounding box in layout.
110 // This does not 100% guarantee the user can see it, but is pretty close.
111 // Note: This method only works properly after layout has occurred.
112 WEBKIT_EXPORT bool hasNonEmptyBoundingBox() const;
114 template<typename T> T to()
117 res.WebNode::assign(*this);
121 template<typename T> const T toConst() const
124 res.WebNode::assign(*this);
128 #if WEBKIT_IMPLEMENTATION
129 WebNode(const WTF::PassRefPtr<WebCore::Node>&);
130 WebNode& operator=(const WTF::PassRefPtr<WebCore::Node>&);
131 operator WTF::PassRefPtr<WebCore::Node>() const;
134 #if WEBKIT_IMPLEMENTATION
135 template<typename T> T* unwrap()
137 return static_cast<T*>(m_private.get());
140 template<typename T> const T* constUnwrap() const
142 return static_cast<const T*>(m_private.get());
147 WebPrivatePtr<WebCore::Node> m_private;
150 inline bool operator==(const WebNode& a, const WebNode& b)
155 inline bool operator!=(const WebNode& a, const WebNode& b)
160 inline bool operator<(const WebNode& a, const WebNode& b)
162 return a.lessThan(b);
165 } // namespace WebKit