static HRESULT htmlform_item(HTMLFormElement *This, int i, IDispatch **ret) { nsIDOMHTMLCollection *elements; nsIDOMNode *item; HTMLDOMNode *node; nsresult nsres; HRESULT hres; nsres = nsIDOMHTMLFormElement_GetElements(This->nsform, &elements); if(NS_FAILED(nsres)) { FIXME("GetElements failed: 0x%08x\n", nsres); return E_FAIL; } nsres = nsIDOMHTMLCollection_Item(elements, i, &item); nsIDOMHTMLCollection_Release(elements); if(NS_FAILED(nsres)) { FIXME("Item failed: 0x%08x\n", nsres); return E_FAIL; } if(item) { hres = get_node(This->element.node.doc, item, TRUE, &node); if(FAILED(hres)) return hres; nsIDOMNode_Release(item); *ret = (IDispatch*)&node->IHTMLDOMNode_iface; }else { *ret = NULL; } return S_OK; }
static HRESULT HTMLFormElement_invoke(HTMLDOMNode *iface, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller) { HTMLFormElement *This = HTMLFORM_NODE_THIS(iface); nsIDOMHTMLCollection *elements; nsIDOMNode *item; HTMLDOMNode *node; nsresult nsres; TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller); nsres = nsIDOMHTMLFormElement_GetElements(This->nsform, &elements); if(NS_FAILED(nsres)) { FIXME("GetElements failed: 0x%08x\n", nsres); return E_FAIL; } nsres = nsIDOMHTMLCollection_Item(elements, id - MSHTML_DISPID_CUSTOM_MIN, &item); nsIDOMHTMLCollection_Release(elements); if(NS_FAILED(nsres)) { FIXME("Item failed: 0x%08x\n", nsres); return E_FAIL; } node = get_node(This->element.node.doc, item, TRUE); V_VT(res) = VT_DISPATCH; V_DISPATCH(res) = (IDispatch*)node; IHTMLDOMNode_AddRef(HTMLDOMNODE(node)); nsIDOMNode_Release(item); return S_OK; }
static HRESULT WINAPI HTMLTableRow_get_cells(IHTMLTableRow *iface, IHTMLElementCollection **p) { HTMLTableRow *This = impl_from_IHTMLTableRow(iface); nsIDOMHTMLCollection *nscol; nsresult nsres; TRACE("(%p)->(%p)\n", This, p); nsres = nsIDOMHTMLTableRowElement_GetCells(This->nsrow, &nscol); if(NS_FAILED(nsres)) { ERR("GetCells failed: %08x\n", nsres); return E_FAIL; } *p = create_collection_from_htmlcol(This->element.node.doc, nscol); nsIDOMHTMLCollection_Release(nscol); return S_OK; }
static HRESULT WINAPI HTMLElement2_getElementsByTagName(IHTMLElement2 *iface, BSTR v, IHTMLElementCollection **pelColl) { HTMLElement *This = impl_from_IHTMLElement2(iface); nsIDOMHTMLCollection *nscol; nsAString tag_str; nsresult nsres; TRACE("(%p)->(%s %p)\n", This, debugstr_w(v), pelColl); nsAString_InitDepend(&tag_str, v); nsres = nsIDOMHTMLElement_GetElementsByTagName(This->nselem, &tag_str, &nscol); nsAString_Finish(&tag_str); if(NS_FAILED(nsres)) { ERR("GetElementByTagName failed: %08x\n", nsres); return E_FAIL; } *pelColl = create_collection_from_htmlcol(This->node.doc, nscol); nsIDOMHTMLCollection_Release(nscol); return S_OK; }
static HRESULT HTMLFormElement_get_dispid(HTMLDOMNode *iface, BSTR name, DWORD grfdex, DISPID *pid) { HTMLFormElement *This = impl_from_HTMLDOMNode(iface); nsIDOMHTMLCollection *elements; nsAString nsstr, name_str; UINT32 len, i; nsresult nsres; HRESULT hres = DISP_E_UNKNOWNNAME; static const PRUnichar nameW[] = {'n','a','m','e',0}; TRACE("(%p)->(%s %x %p)\n", This, wine_dbgstr_w(name), grfdex, pid); nsres = nsIDOMHTMLFormElement_GetElements(This->nsform, &elements); if(NS_FAILED(nsres)) { FIXME("GetElements failed: 0x%08x\n", nsres); return E_FAIL; } nsres = nsIDOMHTMLCollection_GetLength(elements, &len); if(NS_FAILED(nsres)) { FIXME("GetLength failed: 0x%08x\n", nsres); nsIDOMHTMLCollection_Release(elements); return E_FAIL; } if(len > MSHTML_CUSTOM_DISPID_CNT) len = MSHTML_CUSTOM_DISPID_CNT; /* FIXME: Implement in more generic way */ if('0' <= *name && *name <= '9') { WCHAR *end_ptr; i = strtoulW(name, &end_ptr, 10); if(!*end_ptr && i < len) { *pid = MSHTML_DISPID_CUSTOM_MIN + i; return S_OK; } } nsAString_Init(&nsstr, NULL); for(i = 0; i < len; ++i) { nsIDOMNode *nsitem; nsIDOMHTMLElement *nshtml_elem; const PRUnichar *str; nsres = nsIDOMHTMLCollection_Item(elements, i, &nsitem); if(NS_FAILED(nsres)) { FIXME("Item failed: 0x%08x\n", nsres); hres = E_FAIL; break; } nsres = nsIDOMNode_QueryInterface(nsitem, &IID_nsIDOMHTMLElement, (void**)&nshtml_elem); nsIDOMNode_Release(nsitem); if(NS_FAILED(nsres)) { FIXME("Failed to get nsIDOMHTMLNode interface: 0x%08x\n", nsres); hres = E_FAIL; break; } /* compare by id attr */ nsres = nsIDOMHTMLElement_GetId(nshtml_elem, &nsstr); if(NS_FAILED(nsres)) { FIXME("GetId failed: 0x%08x\n", nsres); nsIDOMHTMLElement_Release(nshtml_elem); hres = E_FAIL; break; } nsAString_GetData(&nsstr, &str); if(!strcmpiW(str, name)) { nsIDOMHTMLElement_Release(nshtml_elem); /* FIXME: using index for dispid */ *pid = MSHTML_DISPID_CUSTOM_MIN + i; hres = S_OK; break; } /* compare by name attr */ nsres = get_elem_attr_value(nshtml_elem, nameW, &name_str, &str); nsIDOMHTMLElement_Release(nshtml_elem); if(NS_SUCCEEDED(nsres)) { if(!strcmpiW(str, name)) { nsAString_Finish(&name_str); /* FIXME: using index for dispid */ *pid = MSHTML_DISPID_CUSTOM_MIN + i; hres = S_OK; break; } nsAString_Finish(&name_str); } } nsAString_Finish(&nsstr); nsIDOMHTMLCollection_Release(elements); return hres; }
static HRESULT HTMLFormElement_get_dispid(HTMLDOMNode *iface, BSTR name, DWORD grfdex, DISPID *pid) { HTMLFormElement *This = HTMLFORM_NODE_THIS(iface); nsIDOMHTMLCollection *elements; nsAString nsname, nsstr; PRUint32 len, i; nsresult nsres; HRESULT hres = DISP_E_UNKNOWNNAME; static const PRUnichar nameW[] = {'n','a','m','e',0}; TRACE("(%p)->(%s %x %p)\n", This, wine_dbgstr_w(name), grfdex, pid); nsres = nsIDOMHTMLFormElement_GetElements(This->nsform, &elements); if(NS_FAILED(nsres)) { FIXME("GetElements failed: 0x%08x\n", nsres); return E_FAIL; } nsres = nsIDOMHTMLCollection_GetLength(elements, &len); if(NS_FAILED(nsres)) { FIXME("GetLength failed: 0x%08x\n", nsres); nsIDOMHTMLCollection_Release(elements); return E_FAIL; } nsAString_InitDepend(&nsname, nameW); nsAString_Init(&nsstr, NULL); for(i = 0; i < len; ++i) { nsIDOMNode *nsitem; nsIDOMHTMLElement *nshtml_elem; const PRUnichar *str; nsres = nsIDOMHTMLCollection_Item(elements, i, &nsitem); if(NS_FAILED(nsres)) { FIXME("Item failed: 0x%08x\n", nsres); hres = E_FAIL; break; } nsres = nsIDOMNode_QueryInterface(nsitem, &IID_nsIDOMHTMLElement, (void**)&nshtml_elem); nsIDOMNode_Release(nsitem); if(NS_FAILED(nsres)) { FIXME("Failed to get nsIDOMHTMLNode interface: 0x%08x\n", nsres); hres = E_FAIL; break; } /* compare by id attr */ nsres = nsIDOMHTMLElement_GetId(nshtml_elem, &nsstr); if(NS_FAILED(nsres)) { FIXME("GetId failed: 0x%08x\n", nsres); nsIDOMHTMLElement_Release(nshtml_elem); hres = E_FAIL; break; } nsAString_GetData(&nsstr, &str); if(!strcmpiW(str, name)) { nsIDOMHTMLElement_Release(nshtml_elem); /* FIXME: using index for dispid */ *pid = MSHTML_DISPID_CUSTOM_MIN + i; hres = S_OK; break; } /* compare by name attr */ nsres = nsIDOMHTMLElement_GetAttribute(nshtml_elem, &nsname, &nsstr); nsIDOMHTMLElement_Release(nshtml_elem); nsAString_GetData(&nsstr, &str); if(!strcmpiW(str, name)) { /* FIXME: using index for dispid */ *pid = MSHTML_DISPID_CUSTOM_MIN + i; hres = S_OK; break; } } nsAString_Finish(&nsname); nsAString_Finish(&nsstr); nsIDOMHTMLCollection_Release(elements); return hres; }