FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
ScriptingCore/DOM/Element.cpp
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 #include "variant_list.h"
16 #include "../precompiled_headers.h" // On windows, everything above this line in PCH
17 #include "Element.h"
18 
19 using namespace FB::DOM;
20 
21 Element::Element(const FB::JSObjectPtr& element) : Node(element)
22 {
23 }
24 
25 Element::~Element()
26 {
27 }
28 
29 std::string Element::getInnerHTML() const
30 {
31  return getProperty<std::string>("innerHTML");
32 }
33 void Element::setInnerHTML(const std::string& html) const
34 {
35  setProperty("innerHTML", html);
36 }
37 
38 int Element::getWidth() const
39 {
40  return getProperty<int>("width");
41 }
42 void Element::setWidth(const int width) const
43 {
44  setProperty("width", width);
45 }
46 
47 int Element::getScrollWidth() const
48 {
49  return getProperty<int>("scrollWidth");
50 }
51 
52 int Element::getHeight() const
53 {
54  return getProperty<int>("height");
55 }
56 void Element::setHeight(const int height) const
57 {
58  setProperty("height", height);
59 }
60 
61 int Element::getScrollHeight() const
62 {
63  return getProperty<int>("scrollHeight");
64 }
65 
66 int Element::getChildNodeCount() const
67 {
68  return getNode("childNodes")->getProperty<int>("length");
69 }
70 
71 ElementPtr Element::getChildNode(const int idx) const
72 {
73  ElementPtr retVal(getElement("childNodes")->getElement(idx));
74  return retVal;
75 }
76 
77 ElementPtr Element::getParentNode() const
78 {
79  ElementPtr retVal(getElement("parentNode"));
80  return retVal;
81 }
82 
83 ElementPtr Element::getElementById(const std::string& id) const
84 {
85  JSObjectPtr api =
86  callMethod<JSObjectPtr>("getElementById", variant_list_of(id));
87  return Element::create(api);
88 }
89 
90 std::vector<ElementPtr> Element::getElementsByTagName(const std::wstring& tagName) const
91 {
92  return getElementsByTagName(FB::wstring_to_utf8(tagName));
93 }
94 
95 std::vector<ElementPtr> Element::getElementsByTagName(const std::string& tagName) const
96 {
97  std::vector<FB::JSObjectPtr> tagList = callMethod<std::vector<FB::JSObjectPtr> >("getElementsByTagName", FB::variant_list_of(tagName));
98  std::vector<FB::JSObjectPtr>::iterator it;
99  std::vector<ElementPtr> outList;
100  for (it = tagList.begin(); it != tagList.end(); ++it)
101  {
102  outList.push_back(Element::create(*it));
103  }
104  return outList;
105 }
106 
107 std::string FB::DOM::Element::getStringAttribute( const std::string& attr ) const
108 {
109  return callMethod<std::string>("getAttribute", FB::variant_list_of(attr));
110 }
111 
DOM Node wrapper.
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
FB::detail::VariantListInserter variant_list_of(FB::variant v)
Allows convenient creation of an FB::VariantList.
Definition: variant_list.h:122
std::string wstring_to_utf8(const std::wstring &src)
Accepts a std::wstring and returns a UTF8-encoded std::string.
Definition: utf8_tools.cpp:37
boost::shared_ptr< Element > ElementPtr
shared_ptr for a FB::DOM::Element