|
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 #ifndef WebNode_h |
|
32 #define WebNode_h |
|
33 |
|
34 #include "WebCommon.h" |
|
35 #include "WebPrivatePtr.h" |
|
36 #include "WebString.h" |
|
37 |
|
38 namespace WebCore { class Node; } |
|
39 |
|
40 namespace WebKit { |
|
41 class WebDocument; |
|
42 class WebEventListener; |
|
43 class WebEventListenerPrivate; |
|
44 class WebFrame; |
|
45 class WebNodeList; |
|
46 |
|
47 // Provides access to some properties of a DOM node. |
|
48 class WebNode { |
|
49 public: |
|
50 virtual ~WebNode() { reset(); } |
|
51 |
|
52 WebNode() { } |
|
53 WebNode(const WebNode& n) { assign(n); } |
|
54 WebNode& operator=(const WebNode& n) |
|
55 { |
|
56 assign(n); |
|
57 return *this; |
|
58 } |
|
59 |
|
60 WEBKIT_API void reset(); |
|
61 WEBKIT_API void assign(const WebNode&); |
|
62 |
|
63 WEBKIT_API 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_API bool lessThan(const WebNode&) const; |
|
67 |
|
68 bool isNull() const { return m_private.isNull(); } |
|
69 |
|
70 enum NodeType { |
|
71 ElementNode = 1, |
|
72 AttributeNode, |
|
73 TextNode, |
|
74 CDataSectionNode, |
|
75 EntityReferenceNode, |
|
76 EntityNode, |
|
77 ProcessingInstructionsNode, |
|
78 CommentNode, |
|
79 DocumentNode, |
|
80 DocumentTypeNode, |
|
81 DocumentFragmentNode, |
|
82 NotationNode, |
|
83 XPathNamespaceNode |
|
84 }; |
|
85 WEBKIT_API NodeType nodeType() const; |
|
86 WEBKIT_API WebNode parentNode() const; |
|
87 WEBKIT_API WebString nodeName() const; |
|
88 WEBKIT_API WebString nodeValue() const; |
|
89 WEBKIT_API bool setNodeValue(const WebString&); |
|
90 WEBKIT_API WebDocument document() const; |
|
91 WEBKIT_API WebNode firstChild() const; |
|
92 WEBKIT_API WebNode lastChild() const; |
|
93 WEBKIT_API WebNode previousSibling() const; |
|
94 WEBKIT_API WebNode nextSibling() const; |
|
95 WEBKIT_API bool hasChildNodes() const; |
|
96 WEBKIT_API WebNodeList childNodes(); |
|
97 WEBKIT_API WebString createMarkup() const; |
|
98 WEBKIT_API bool isTextNode() const; |
|
99 WEBKIT_API bool isElementNode() const; |
|
100 WEBKIT_API void addEventListener(const WebString& eventType, WebEventListener* listener, bool useCapture); |
|
101 WEBKIT_API void removeEventListener(const WebString& eventType, WebEventListener* listener, bool useCapture); |
|
102 WEBKIT_API void simulateClick(); |
|
103 WEBKIT_API WebNodeList getElementsByTagName(const WebString&) const; |
|
104 |
|
105 // Returns true if the node has a non-empty bounding box in layout. |
|
106 // This does not 100% guarantee the user can see it, but is pretty close. |
|
107 // Note: This method only works properly after layout has occurred. |
|
108 WEBKIT_API bool hasNonEmptyBoundingBox() const; |
|
109 |
|
110 template<typename T> T to() |
|
111 { |
|
112 T res; |
|
113 res.WebNode::assign(*this); |
|
114 return res; |
|
115 } |
|
116 |
|
117 template<typename T> const T toConst() const |
|
118 { |
|
119 T res; |
|
120 res.WebNode::assign(*this); |
|
121 return res; |
|
122 } |
|
123 |
|
124 #if WEBKIT_IMPLEMENTATION |
|
125 WebNode(const WTF::PassRefPtr<WebCore::Node>&); |
|
126 WebNode& operator=(const WTF::PassRefPtr<WebCore::Node>&); |
|
127 operator WTF::PassRefPtr<WebCore::Node>() const; |
|
128 #endif |
|
129 |
|
130 #if WEBKIT_IMPLEMENTATION |
|
131 template<typename T> T* unwrap() |
|
132 { |
|
133 return static_cast<T*>(m_private.get()); |
|
134 } |
|
135 |
|
136 template<typename T> const T* constUnwrap() const |
|
137 { |
|
138 return static_cast<const T*>(m_private.get()); |
|
139 } |
|
140 #endif |
|
141 |
|
142 protected: |
|
143 WebPrivatePtr<WebCore::Node> m_private; |
|
144 }; |
|
145 |
|
146 inline bool operator==(const WebNode& a, const WebNode& b) |
|
147 { |
|
148 return a.equals(b); |
|
149 } |
|
150 |
|
151 inline bool operator!=(const WebNode& a, const WebNode& b) |
|
152 { |
|
153 return !(a == b); |
|
154 } |
|
155 |
|
156 inline bool operator<(const WebNode& a, const WebNode& b) |
|
157 { |
|
158 return a.lessThan(b); |
|
159 } |
|
160 |
|
161 } // namespace WebKit |
|
162 |
|
163 #endif |