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 "../platform/WebCommon.h"
35 #include "../platform/WebPrivatePtr.h"
36 #include "../platform/WebString.h"
37 #include "WebExceptionCode.h"
39 namespace WebCore { class Node; }
43 class WebDOMEventListener;
44 class WebDOMEventListenerPrivate;
47 class WebElementCollection;
49 class WebPluginContainer;
51 // Provides access to some properties of a DOM node.
52 // Note that the class design requires that neither this class nor any of its subclasses have any virtual
53 // methods (other than the destructor), so that it is possible to safely static_cast an instance of one
54 // class to the appropriate subclass based on the actual type of the wrapped WebCore::Node. For the same
55 // reason, subclasses must not add any additional data members.
58 virtual ~WebNode() { reset(); }
61 WebNode(const WebNode& n) { assign(n); }
62 WebNode& operator=(const WebNode& n)
68 BLINK_EXPORT void reset();
69 BLINK_EXPORT void assign(const WebNode&);
71 BLINK_EXPORT bool equals(const WebNode&) const;
72 // Required for using WebNodes in std maps. Note the order used is
73 // arbitrary and should not be expected to have any specific meaning.
74 BLINK_EXPORT bool lessThan(const WebNode&) const;
76 bool isNull() const { return m_private.isNull(); }
83 // EntityReferenceNodes are impossible to create in Blink.
84 // EntityNodes are impossible to create in Blink.
85 ProcessingInstructionsNode = 7,
88 DocumentTypeNode = 10,
89 DocumentFragmentNode = 11,
90 // NotationNodes are impossible to create in Blink.
91 // XPathNamespaceNodes are impossible to create in Blink.
95 BLINK_EXPORT NodeType nodeType() const;
96 BLINK_EXPORT WebNode parentNode() const;
97 BLINK_EXPORT WebString nodeName() const;
98 BLINK_EXPORT WebString nodeValue() const;
99 BLINK_EXPORT WebDocument document() const;
100 BLINK_EXPORT WebNode firstChild() const;
101 BLINK_EXPORT WebNode lastChild() const;
102 BLINK_EXPORT WebNode previousSibling() const;
103 BLINK_EXPORT WebNode nextSibling() const;
104 BLINK_EXPORT bool hasChildNodes() const;
105 BLINK_EXPORT WebNodeList childNodes();
106 BLINK_EXPORT WebString createMarkup() const;
107 BLINK_EXPORT bool isLink() const;
108 BLINK_EXPORT bool isTextNode() const;
109 BLINK_EXPORT bool isFocusable() const;
110 BLINK_EXPORT bool isContentEditable() const;
111 BLINK_EXPORT bool isElementNode() const;
112 // addEventListener only works with a small set of eventTypes.
113 BLINK_EXPORT void addEventListener(const WebString& eventType, WebDOMEventListener* listener, bool useCapture);
114 BLINK_EXPORT bool dispatchEvent(const WebDOMEvent&);
115 BLINK_EXPORT void simulateClick();
116 BLINK_EXPORT WebElementCollection getElementsByTagName(const WebString&) const;
117 BLINK_EXPORT WebElement querySelector(const WebString&, WebExceptionCode&) const;
118 BLINK_EXPORT WebElement rootEditableElement() const;
119 BLINK_EXPORT bool focused() const;
120 BLINK_EXPORT bool remove();
122 // Returns true if the node has a non-empty bounding box in layout.
123 // This does not 100% guarantee the user can see it, but is pretty close.
124 // Note: This method only works properly after layout has occurred.
125 BLINK_EXPORT bool hasNonEmptyBoundingBox() const;
126 BLINK_EXPORT WebPluginContainer* pluginContainer() const;
127 BLINK_EXPORT WebElement shadowHost() const;
129 template<typename T> T to()
132 res.WebNode::assign(*this);
136 template<typename T> const T toConst() const
139 res.WebNode::assign(*this);
143 #if BLINK_IMPLEMENTATION
144 WebNode(const PassRefPtrWillBeRawPtr<WebCore::Node>&);
145 WebNode& operator=(const PassRefPtrWillBeRawPtr<WebCore::Node>&);
146 operator PassRefPtrWillBeRawPtr<WebCore::Node>() const;
148 // This constructor enables creation of WebNodes from Members
149 // holding WebCore::Node-derived objects (this shows up in WebVector
150 // assignments, for instance.) It is needed because a RawPtr<T> constructor
151 // from a Member<U> isn't provided, hence the above constructor
154 WebNode(const WebCore::Member<U>& other, EnsurePtrConvertibleArgDecl(U, WebCore::Node))
155 : m_private(other.get())
161 #if BLINK_IMPLEMENTATION
162 template<typename T> T* unwrap()
164 return static_cast<T*>(m_private.get());
167 template<typename T> const T* constUnwrap() const
169 return static_cast<const T*>(m_private.get());
174 WebPrivatePtr<WebCore::Node> m_private;
177 inline bool operator==(const WebNode& a, const WebNode& b)
182 inline bool operator!=(const WebNode& a, const WebNode& b)
187 inline bool operator<(const WebNode& a, const WebNode& b)
189 return a.lessThan(b);