FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
ScriptingCore/DOM/Element.h
1 /**********************************************************\
2 Original Author: Richard Bateman (taxilian)
3 
4 Created: Dec 9, 2009
5 License: Dual license model; choose one of two:
6  New BSD License
7  http://www.opensource.org/licenses/bsd-license.php
8  - or -
9  GNU Lesser General Public License, version 2.1
10  http://www.gnu.org/licenses/lgpl-2.1.html
11 
12 Copyright 2009 PacketPass, Inc and the Firebreath development team
13 \**********************************************************/
14 
15 #pragma once
16 #ifndef H_FB_DOM_ELEMENT
17 #define H_FB_DOM_ELEMENT
18 
19 #include <string>
20 #include "JSObject.h"
21 #include "Node.h"
22 
23 namespace FB { namespace DOM {
24 
25  class Element;
26  typedef boost::shared_ptr<Element> ElementPtr;
27 
35  class Element : public virtual Node
36  {
37  public:
39  virtual ~Element();
40 
48  ElementPtr element() { return boost::dynamic_pointer_cast<Element>(node()); }
49 
61  static ElementPtr create(const FB::JSObjectPtr &api) {
62  if (!api) { return ElementPtr(); } // If the API is null, return a NULL Element
63  return api->getHost()->_createElement(api);
64  }
65 
66  public:
67 
75  virtual std::string getInnerHTML() const;
76 
84  virtual void setInnerHTML(const std::string& html) const;
85 
93  virtual int getWidth() const;
94 
102  virtual void setWidth(const int width) const;
103 
111  virtual int getScrollWidth() const;
112 
120  virtual int getHeight() const;
121 
129  virtual void setHeight(const int height) const;
130 
138  virtual int getScrollHeight() const;
139 
147  virtual int getChildNodeCount() const;
148 
161  virtual ElementPtr getChildNode(const int idx) const;
162 
170  virtual ElementPtr getParentNode() const;
171 
190  virtual ElementPtr getElement(const std::string& name) const
191  {
192  JSObjectPtr api = getProperty<FB::JSObjectPtr>(name);
193  ElementPtr retVal((api) ? new Element(api) : NULL);
194  return retVal;
195  }
196 
212  virtual ElementPtr getElement(const int idx) const
213  {
214  JSObjectPtr api = getProperty<FB::JSObjectPtr>(idx);
215  ElementPtr retVal((api) ? new Element(api) : NULL);
216  return retVal;
217  }
218 
219  virtual std::string getStringAttribute(const std::string& attr) const;
220 
230  virtual ElementPtr getElementById(const std::string& elem_id) const;
231 
241  virtual std::vector<ElementPtr> getElementsByTagName(const std::string& tagName) const;
242 
246  virtual std::vector<ElementPtr> getElementsByTagName(const std::wstring& tagName) const;
247  };
248 
249 }; };
250 
251 #endif // H_FB_DOM_ELEMENT
252 
DOM Node wrapper.
virtual int getScrollHeight() const
Gets the scroll height property (read-only) of the element.
virtual int getChildNodeCount() const
Gets a child node count.
boost::shared_ptr< FB::JSObject > JSObjectPtr
Defines an alias representing a JSObject shared_ptr (you should never use a JSObject* directly) ...
Definition: APITypes.h:109
virtual std::vector< ElementPtr > getElementsByTagName(const std::string &tagName) const
Gets a list of all elements in the document with the specified tag name.
virtual void setInnerHTML(const std::string &html) const
Sets an inner html for the element.
virtual ElementPtr getParentNode() const
Gets the parent node of the current Element.
virtual int getWidth() const
Gets the width property of the element.
virtual ElementPtr getElementById(const std::string &elem_id) const
Gets an element from the DOM with the specified id.
virtual ElementPtr getElement(const std::string &name) const
Gets a child element of the specified name.
virtual ElementPtr getElement(const int idx) const
Gets a child element of the specified name.
DOM Element wrapper.
static ElementPtr create(const FB::JSObjectPtr &api)
Creates a FB::DOM::Element object from a JSObjectPtr representing a DOM object. This will probably th...
virtual ElementPtr getChildNode(const int idx) const
Gets a child node.
NodePtr node()
Gets the NodePtr for the current node.
virtual void setWidth(const int width) const
Sets the width property of the element.
virtual std::string getInnerHTML() const
Gets the inner html for the element.
boost::shared_ptr< Element > ElementPtr
shared_ptr for a FB::DOM::Element
virtual int getHeight() const
Gets the height property of the element.
virtual void setHeight(const int height) const
Sets the height property of the element.
virtual int getScrollWidth() const
Gets the scroll width property (read-only) of the element.
ElementPtr element()
Gets a FB::DOM::ElementPtr pointing to the current object.