FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
ScriptingCore/DOM/Node.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 "JSObject.h"
16 #include "variant_list.h"
17 #include "../precompiled_headers.h" // On windows, everything above this line in PCH
18 
19 #include "Node.h"
20 
21 FB::DOM::NodePtr FB::DOM::Node::getNode(const std::wstring& name) const
22 {
23  return getNode(FB::wstring_to_utf8(name));
24 }
25 FB::DOM::NodePtr FB::DOM::Node::getNode(const std::string& name) const
26 {
27  FB::JSObjectPtr api = getProperty<FB::JSObjectPtr>(name);
28  return Node::create(api);
29 }
30 
32 {
33  FB::JSObjectPtr api = getProperty<JSObjectPtr>(idx);
34  return Node::create(api);
35 }
36 
37 void FB::DOM::Node::setProperty(const std::wstring& name, const FB::variant& val) const
38 {
39  setProperty(FB::wstring_to_utf8(name), val);
40 }
41 void FB::DOM::Node::setProperty(const std::string& name, const FB::variant& val) const
42 {
43  m_element->SetProperty(name, val);
44 }
45 
46 void FB::DOM::Node::setProperty(const int idx, const FB::variant& val) const
47 {
48  m_element->SetProperty(idx, val);
49 }
50 
51 FB::DOM::NodePtr FB::DOM::Node::appendChild(FB::DOM::NodePtr node)
52 {
53  FB::JSObjectPtr result = callMethod<FB::JSObjectPtr>("appendChild", FB::variant_list_of(node->getJSObject()));
54  return Node::create(result);
55 }
static NodePtr create(const FB::JSObjectPtr &api)
Creates a FB::DOM::Node object from a JSObjectPtr representing a DOM node. This will probably throw a...
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 NodePtr getNode(const std::wstring &name) const
FB::detail::VariantListInserter variant_list_of(FB::variant v)
Allows convenient creation of an FB::VariantList.
Definition: variant_list.h:122
boost::shared_ptr< Node > NodePtr
shared_ptr for a FB::DOM::Node
Accepts any datatype, used in all interactions with javascript. Provides tools for getting back out t...
Definition: variant.h:198
virtual void setProperty(const std::wstring &name, const variant &val) const
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