1 // Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved.
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
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
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.
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.
30 // ---------------------------------------------------------------------------
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.
37 #ifndef CEF_INCLUDE_CEF_DOM_H_
38 #define CEF_INCLUDE_CEF_DOM_H_
41 #include "include/cef_base.h"
48 // Interface to implement for visiting the DOM. The methods of this class will
49 // be called on the render process main thread.
51 /*--cef(source=client)--*/
52 class CefDOMVisitor : public virtual CefBase {
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
62 virtual void Visit(CefRefPtr<CefDOMDocument> document) =0;
67 // Class used to represent a DOM document. The methods of this class should only
68 // be called on the render process main thread thread.
70 /*--cef(source=library)--*/
71 class CefDOMDocument : public virtual CefBase {
73 typedef cef_dom_document_type_t Type;
76 // Returns the document type.
78 /*--cef(default_retval=DOM_DOCUMENT_TYPE_UNKNOWN)--*/
79 virtual Type GetType() =0;
82 // Returns the root document node.
85 virtual CefRefPtr<CefDOMNode> GetDocument() =0;
88 // Returns the BODY node of an HTML document.
91 virtual CefRefPtr<CefDOMNode> GetBody() =0;
94 // Returns the HEAD node of an HTML document.
97 virtual CefRefPtr<CefDOMNode> GetHead() =0;
100 // Returns the title of an HTML document.
103 virtual CefString GetTitle() =0;
106 // Returns the document element with the specified ID value.
109 virtual CefRefPtr<CefDOMNode> GetElementById(const CefString& id) =0;
112 // Returns the node that currently has keyboard focus.
115 virtual CefRefPtr<CefDOMNode> GetFocusedNode() =0;
118 // Returns true if a portion of the document is selected.
121 virtual bool HasSelection() =0;
124 // Returns the selection offset within the start node.
127 virtual int GetSelectionStartOffset() =0;
130 // Returns the selection offset within the end node.
133 virtual int GetSelectionEndOffset() =0;
136 // Returns the contents of this selection as markup.
139 virtual CefString GetSelectionAsMarkup() =0;
142 // Returns the contents of this selection as text.
145 virtual CefString GetSelectionAsText() =0;
148 // Returns the base URL for the document.
151 virtual CefString GetBaseURL() =0;
154 // Returns a complete URL based on the document base URL and the specified
158 virtual CefString GetCompleteURL(const CefString& partialURL) =0;
163 // Class used to represent a DOM node. The methods of this class should only be
164 // called on the render process main thread.
166 /*--cef(source=library)--*/
167 class CefDOMNode : public virtual CefBase {
169 typedef std::map<CefString, CefString> AttributeMap;
170 typedef cef_dom_node_type_t Type;
173 // Returns the type for this node.
175 /*--cef(default_retval=DOM_NODE_TYPE_UNSUPPORTED)--*/
176 virtual Type GetType() =0;
179 // Returns true if this is a text node.
182 virtual bool IsText() =0;
185 // Returns true if this is an element node.
188 virtual bool IsElement() =0;
191 // Returns true if this is an editable node.
194 virtual bool IsEditable() =0;
197 // Returns true if this is a form control element node.
200 virtual bool IsFormControlElement() =0;
203 // Returns the type of this form control element node.
206 virtual CefString GetFormControlElementType() =0;
209 // Returns true if this object is pointing to the same handle as |that|
213 virtual bool IsSame(CefRefPtr<CefDOMNode> that) =0;
216 // Returns the name of this node.
219 virtual CefString GetName() =0;
222 // Returns the value of this node.
225 virtual CefString GetValue() =0;
228 // Set the value of this node. Returns true on success.
231 virtual bool SetValue(const CefString& value) =0;
234 // Returns the contents of this node as markup.
237 virtual CefString GetAsMarkup() =0;
240 // Returns the document associated with this node.
243 virtual CefRefPtr<CefDOMDocument> GetDocument() =0;
246 // Returns the parent node.
249 virtual CefRefPtr<CefDOMNode> GetParent() =0;
252 // Returns the previous sibling node.
255 virtual CefRefPtr<CefDOMNode> GetPreviousSibling() =0;
258 // Returns the next sibling node.
261 virtual CefRefPtr<CefDOMNode> GetNextSibling() =0;
264 // Returns true if this node has child nodes.
267 virtual bool HasChildren() =0;
270 // Return the first child node.
273 virtual CefRefPtr<CefDOMNode> GetFirstChild() =0;
276 // Returns the last child node.
279 virtual CefRefPtr<CefDOMNode> GetLastChild() =0;
281 // The following methods are valid only for element nodes.
284 // Returns the tag name of this element.
287 virtual CefString GetElementTagName() =0;
290 // Returns true if this element has attributes.
293 virtual bool HasElementAttributes() =0;
296 // Returns true if this element has an attribute named |attrName|.
299 virtual bool HasElementAttribute(const CefString& attrName) =0;
302 // Returns the element attribute named |attrName|.
305 virtual CefString GetElementAttribute(const CefString& attrName) =0;
308 // Returns a map of all element attributes.
311 virtual void GetElementAttributes(AttributeMap& attrMap) =0;
314 // Set the value for the element attribute named |attrName|. Returns true on
318 virtual bool SetElementAttribute(const CefString& attrName,
319 const CefString& value) =0;
322 // Returns the inner text of the element.
325 virtual CefString GetElementInnerText() =0;
328 #endif // CEF_INCLUDE_CEF_DOM_H_