FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
std::vector< FB::DOM::ElementPtr > Element::getElementsByTagName ( const std::string &  tagName) const
virtual

Gets a list of all elements in the document with the specified tag name.

Parameters
tagNameName of the tag.
Returns
The elements by tag name.

Reimplemented from FB::DOM::Element.

Reimplemented in FB::ActiveX::AXDOM::Document.

Definition at line 32 of file ActiveXCore/AXDOM/Element.cpp.

References FB::DOM::Element::create(), FB::DOM::Node::getJSObject(), and FB::utf8_to_wstring().

33 {
34  CComQIPtr<IHTMLElement2> elem(m_axDisp);
35  CComQIPtr<IHTMLDocument3> doc(m_axDisp);
36  CComPtr<IHTMLElementCollection> list;
37  std::vector<FB::DOM::ElementPtr> tagList;
38  CComBSTR tName(FB::utf8_to_wstring(tagName).c_str());
39  if (elem) {
40  elem->getElementsByTagName(tName, &list);
41  } else if (doc) {
42  doc->getElementsByTagName(tName, &list);
43  } else {
44  throw std::runtime_error("Could not get element by tag name");
45  }
46  long length(0);
47  if (SUCCEEDED(list->get_length(&length))) {
48  for (long i = 0; i < length; i++) {
49  CComPtr<IDispatch> dispObj;
50  CComVariant idx(i);
51  list->item(idx, idx, &dispObj);
52  FB::JSObjectPtr obj(IDispatchAPI::create(dispObj, FB::ptr_cast<ActiveXBrowserHost>(getJSObject()->getHost())));
53  tagList.push_back(FB::DOM::Element::create(obj));
54  }
55  }
56  return tagList;
57 }
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 FB::JSObjectPtr getJSObject() const
Returns the FB::JSObjectPtr that this object is wrapping.
static ElementPtr create(const FB::JSObjectPtr &api)
Creates a FB::DOM::Element object from a JSObjectPtr representing a DOM object. This will probably th...
std::wstring utf8_to_wstring(const std::string &src)
Accepts a UTF8-encoded std::string and returns a std::wstring.
Definition: utf8_tools.cpp:50

Here is the call graph for this function: