static BOOL is_elem_name(HTMLElement *elem, LPCWSTR name) { const PRUnichar *str; nsAString nsstr; BOOL ret = FALSE; nsresult nsres; static const PRUnichar nameW[] = {'n','a','m','e',0}; if(!elem->nselem) return FALSE; nsAString_Init(&nsstr, NULL); nsIDOMHTMLElement_GetId(elem->nselem, &nsstr); nsAString_GetData(&nsstr, &str); if(!strcmpiW(str, name)) { nsAString_Finish(&nsstr); return TRUE; } nsres = get_elem_attr_value(elem->nselem, nameW, &nsstr, &str); if(NS_SUCCEEDED(nsres)) { ret = !strcmpiW(str, name); nsAString_Finish(&nsstr); } return ret; }
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; }