• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 //    * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 //    * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 //    * Neither the name of Google Inc. nor the name Chromium Embedded
14 // Framework nor the names of its contributors may be used to endorse
15 // or promote products derived from this software without specific prior
16 // 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 //
32 // The contents of this file must follow a specific format in order to
33 // support the CEF translator tool. See the translator.README.txt file in the
34 // tools directory for more information.
35 //
36 
37 #ifndef CEF_INCLUDE_CEF_DOM_H_
38 #define CEF_INCLUDE_CEF_DOM_H_
39 #pragma once
40 
41 #include <map>
42 #include "include/cef_base.h"
43 
44 class CefDOMDocument;
45 class CefDOMNode;
46 
47 ///
48 // Interface to implement for visiting the DOM. The methods of this class will
49 // be called on the render process main thread.
50 ///
51 /*--cef(source=client)--*/
52 class CefDOMVisitor : public virtual CefBaseRefCounted {
53  public:
54   ///
55   // Method executed for visiting the DOM. The document object passed to this
56   // method represents a snapshot of the DOM at the time this method is
57   // executed. DOM objects are only valid for the scope of this method. Do not
58   // keep references to or attempt to access any DOM objects outside the scope
59   // of this method.
60   ///
61   /*--cef()--*/
62   virtual void Visit(CefRefPtr<CefDOMDocument> document) = 0;
63 };
64 
65 ///
66 // Class used to represent a DOM document. The methods of this class should only
67 // be called on the render process main thread thread.
68 ///
69 /*--cef(source=library)--*/
70 class CefDOMDocument : public virtual CefBaseRefCounted {
71  public:
72   typedef cef_dom_document_type_t Type;
73 
74   ///
75   // Returns the document type.
76   ///
77   /*--cef(default_retval=DOM_DOCUMENT_TYPE_UNKNOWN)--*/
78   virtual Type GetType() = 0;
79 
80   ///
81   // Returns the root document node.
82   ///
83   /*--cef()--*/
84   virtual CefRefPtr<CefDOMNode> GetDocument() = 0;
85 
86   ///
87   // Returns the BODY node of an HTML document.
88   ///
89   /*--cef()--*/
90   virtual CefRefPtr<CefDOMNode> GetBody() = 0;
91 
92   ///
93   // Returns the HEAD node of an HTML document.
94   ///
95   /*--cef()--*/
96   virtual CefRefPtr<CefDOMNode> GetHead() = 0;
97 
98   ///
99   // Returns the title of an HTML document.
100   ///
101   /*--cef()--*/
102   virtual CefString GetTitle() = 0;
103 
104   ///
105   // Returns the document element with the specified ID value.
106   ///
107   /*--cef()--*/
108   virtual CefRefPtr<CefDOMNode> GetElementById(const CefString& id) = 0;
109 
110   ///
111   // Returns the node that currently has keyboard focus.
112   ///
113   /*--cef()--*/
114   virtual CefRefPtr<CefDOMNode> GetFocusedNode() = 0;
115 
116   ///
117   // Returns true if a portion of the document is selected.
118   ///
119   /*--cef()--*/
120   virtual bool HasSelection() = 0;
121 
122   ///
123   // Returns the selection offset within the start node.
124   ///
125   /*--cef()--*/
126   virtual int GetSelectionStartOffset() = 0;
127 
128   ///
129   // Returns the selection offset within the end node.
130   ///
131   /*--cef()--*/
132   virtual int GetSelectionEndOffset() = 0;
133 
134   ///
135   // Returns the contents of this selection as markup.
136   ///
137   /*--cef()--*/
138   virtual CefString GetSelectionAsMarkup() = 0;
139 
140   ///
141   // Returns the contents of this selection as text.
142   ///
143   /*--cef()--*/
144   virtual CefString GetSelectionAsText() = 0;
145 
146   ///
147   // Returns the base URL for the document.
148   ///
149   /*--cef()--*/
150   virtual CefString GetBaseURL() = 0;
151 
152   ///
153   // Returns a complete URL based on the document base URL and the specified
154   // partial URL.
155   ///
156   /*--cef()--*/
157   virtual CefString GetCompleteURL(const CefString& partialURL) = 0;
158 };
159 
160 ///
161 // Class used to represent a DOM node. The methods of this class should only be
162 // called on the render process main thread.
163 ///
164 /*--cef(source=library)--*/
165 class CefDOMNode : public virtual CefBaseRefCounted {
166  public:
167   typedef std::map<CefString, CefString> AttributeMap;
168   typedef cef_dom_node_type_t Type;
169 
170   ///
171   // Returns the type for this node.
172   ///
173   /*--cef(default_retval=DOM_NODE_TYPE_UNSUPPORTED)--*/
174   virtual Type GetType() = 0;
175 
176   ///
177   // Returns true if this is a text node.
178   ///
179   /*--cef()--*/
180   virtual bool IsText() = 0;
181 
182   ///
183   // Returns true if this is an element node.
184   ///
185   /*--cef()--*/
186   virtual bool IsElement() = 0;
187 
188   ///
189   // Returns true if this is an editable node.
190   ///
191   /*--cef()--*/
192   virtual bool IsEditable() = 0;
193 
194   ///
195   // Returns true if this is a form control element node.
196   ///
197   /*--cef()--*/
198   virtual bool IsFormControlElement() = 0;
199 
200   ///
201   // Returns the type of this form control element node.
202   ///
203   /*--cef()--*/
204   virtual CefString GetFormControlElementType() = 0;
205 
206   ///
207   // Returns true if this object is pointing to the same handle as |that|
208   // object.
209   ///
210   /*--cef()--*/
211   virtual bool IsSame(CefRefPtr<CefDOMNode> that) = 0;
212 
213   ///
214   // Returns the name of this node.
215   ///
216   /*--cef()--*/
217   virtual CefString GetName() = 0;
218 
219   ///
220   // Returns the value of this node.
221   ///
222   /*--cef()--*/
223   virtual CefString GetValue() = 0;
224 
225   ///
226   // Set the value of this node. Returns true on success.
227   ///
228   /*--cef()--*/
229   virtual bool SetValue(const CefString& value) = 0;
230 
231   ///
232   // Returns the contents of this node as markup.
233   ///
234   /*--cef()--*/
235   virtual CefString GetAsMarkup() = 0;
236 
237   ///
238   // Returns the document associated with this node.
239   ///
240   /*--cef()--*/
241   virtual CefRefPtr<CefDOMDocument> GetDocument() = 0;
242 
243   ///
244   // Returns the parent node.
245   ///
246   /*--cef()--*/
247   virtual CefRefPtr<CefDOMNode> GetParent() = 0;
248 
249   ///
250   // Returns the previous sibling node.
251   ///
252   /*--cef()--*/
253   virtual CefRefPtr<CefDOMNode> GetPreviousSibling() = 0;
254 
255   ///
256   // Returns the next sibling node.
257   ///
258   /*--cef()--*/
259   virtual CefRefPtr<CefDOMNode> GetNextSibling() = 0;
260 
261   ///
262   // Returns true if this node has child nodes.
263   ///
264   /*--cef()--*/
265   virtual bool HasChildren() = 0;
266 
267   ///
268   // Return the first child node.
269   ///
270   /*--cef()--*/
271   virtual CefRefPtr<CefDOMNode> GetFirstChild() = 0;
272 
273   ///
274   // Returns the last child node.
275   ///
276   /*--cef()--*/
277   virtual CefRefPtr<CefDOMNode> GetLastChild() = 0;
278 
279   // The following methods are valid only for element nodes.
280 
281   ///
282   // Returns the tag name of this element.
283   ///
284   /*--cef()--*/
285   virtual CefString GetElementTagName() = 0;
286 
287   ///
288   // Returns true if this element has attributes.
289   ///
290   /*--cef()--*/
291   virtual bool HasElementAttributes() = 0;
292 
293   ///
294   // Returns true if this element has an attribute named |attrName|.
295   ///
296   /*--cef()--*/
297   virtual bool HasElementAttribute(const CefString& attrName) = 0;
298 
299   ///
300   // Returns the element attribute named |attrName|.
301   ///
302   /*--cef()--*/
303   virtual CefString GetElementAttribute(const CefString& attrName) = 0;
304 
305   ///
306   // Returns a map of all element attributes.
307   ///
308   /*--cef()--*/
309   virtual void GetElementAttributes(AttributeMap& attrMap) = 0;
310 
311   ///
312   // Set the value for the element attribute named |attrName|. Returns true on
313   // success.
314   ///
315   /*--cef()--*/
316   virtual bool SetElementAttribute(const CefString& attrName,
317                                    const CefString& value) = 0;
318 
319   ///
320   // Returns the inner text of the element.
321   ///
322   /*--cef()--*/
323   virtual CefString GetElementInnerText() = 0;
324 
325   ///
326   // Returns the bounds of the element.
327   ///
328   /*--cef()--*/
329   virtual CefRect GetElementBounds() = 0;
330 };
331 
332 #endif  // CEF_INCLUDE_CEF_DOM_H_
333