00001 /**********************************************************\ 00002 Original Author: Richard Bateman (taxilian) 00003 00004 Created: Dec 9, 2009 00005 License: Dual license model; choose one of two: 00006 New BSD License 00007 http://www.opensource.org/licenses/bsd-license.php 00008 - or - 00009 GNU Lesser General Public License, version 2.1 00010 http://www.gnu.org/licenses/lgpl-2.1.html 00011 00012 Copyright 2009 PacketPass, Inc and the Firebreath development team 00013 \**********************************************************/ 00014 00015 #include "variant_list.h" 00016 #include "../precompiled_headers.h" // On windows, everything above this line in PCH 00017 #include "Element.h" 00018 00019 using namespace FB::DOM; 00020 00021 Element::Element(const FB::JSObjectPtr& element) : Node(element) 00022 { 00023 } 00024 00025 Element::~Element() 00026 { 00027 } 00028 00029 std::string Element::getInnerHTML() const 00030 { 00031 return getProperty<std::string>("innerHTML"); 00032 } 00033 void Element::setInnerHTML(const std::string& html) const 00034 { 00035 setProperty("innerHTML", html); 00036 } 00037 00038 int Element::getWidth() const 00039 { 00040 return getProperty<int>("width"); 00041 } 00042 void Element::setWidth(const int width) const 00043 { 00044 setProperty("width", width); 00045 } 00046 00047 int Element::getScrollWidth() const 00048 { 00049 return getProperty<int>("scrollWidth"); 00050 } 00051 00052 int Element::getHeight() const 00053 { 00054 return getProperty<int>("height"); 00055 } 00056 void Element::setHeight(const int height) const 00057 { 00058 setProperty("height", height); 00059 } 00060 00061 int Element::getScrollHeight() const 00062 { 00063 return getProperty<int>("scrollHeight"); 00064 } 00065 00066 int Element::getChildNodeCount() const 00067 { 00068 return getNode("childNodes")->getProperty<int>("length"); 00069 } 00070 00071 ElementPtr Element::getChildNode(const int idx) const 00072 { 00073 ElementPtr retVal(getElement("childNodes")->getElement(idx)); 00074 return retVal; 00075 } 00076 00077 ElementPtr Element::getParentNode() const 00078 { 00079 ElementPtr retVal(getElement("parentNode")); 00080 return retVal; 00081 } 00082 00083 ElementPtr Element::getElementById(const std::string& id) const 00084 { 00085 JSObjectPtr api = 00086 callMethod<JSObjectPtr>("getElementById", variant_list_of(id)); 00087 return Element::create(api); 00088 } 00089 00090 std::vector<ElementPtr> Element::getElementsByTagName(const std::wstring& tagName) const 00091 { 00092 return getElementsByTagName(FB::wstring_to_utf8(tagName)); 00093 } 00094 00095 std::vector<ElementPtr> Element::getElementsByTagName(const std::string& tagName) const 00096 { 00097 std::vector<FB::JSObjectPtr> tagList = callMethod<std::vector<FB::JSObjectPtr> >("getElementsByTagName", FB::variant_list_of(tagName)); 00098 std::vector<FB::JSObjectPtr>::iterator it; 00099 std::vector<ElementPtr> outList; 00100 for (it = tagList.begin(); it != tagList.end(); ++it) 00101 { 00102 outList.push_back(Element::create(*it)); 00103 } 00104 return outList; 00105 } 00106 00107 std::string FB::DOM::Element::getStringAttribute( const std::string& attr ) const 00108 { 00109 return callMethod<std::string>("getAttribute", FB::variant_list_of(attr)); 00110 } 00111