Commit ad1599f2 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

mshtml: Share more code between get_form implementations.

parent cff46126
......@@ -42,6 +42,38 @@ struct HTMLFormElement {
nsIDOMHTMLFormElement *nsform;
};
HRESULT return_nsform(nsresult nsres, nsIDOMHTMLFormElement *form, IHTMLFormElement **p)
{
nsIDOMNode *form_node;
HTMLDOMNode *node;
HRESULT hres;
if (NS_FAILED(nsres)) {
ERR("GetForm failed: %08x\n", nsres);
return E_FAIL;
}
if(!form) {
*p = NULL;
TRACE("NULL\n");
return S_OK;
}
nsres = nsIDOMHTMLFormElement_QueryInterface(form, &IID_nsIDOMNode, (void**)&form_node);
nsIDOMHTMLFormElement_Release(form);
assert(nsres == NS_OK);
hres = get_node(form_node, TRUE, &node);
nsIDOMNode_Release(form_node);
if (FAILED(hres))
return hres;
TRACE("node %p\n", node);
hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLFormElement, (void**)p);
node_release(node);
return hres;
}
static HRESULT htmlform_item(HTMLFormElement *This, int i, IDispatch **ret)
{
nsIDOMHTMLCollection *elements;
......
......@@ -46,32 +46,6 @@ struct HTMLInputElement {
static const WCHAR forW[] = {'f','o','r',0};
static HRESULT return_nsform(HTMLElement *elem, nsIDOMHTMLFormElement *nsform, IHTMLFormElement **p)
{
nsIDOMNode *form_node;
HTMLDOMNode *node;
nsresult nsres;
HRESULT hres;
if(!nsform) {
*p = NULL;
return S_OK;
}
nsres = nsIDOMHTMLFormElement_QueryInterface(nsform, &IID_nsIDOMNode, (void**)&form_node);
nsIDOMHTMLFormElement_Release(nsform);
assert(nsres == NS_OK);
hres = get_node(form_node, TRUE, &node);
nsIDOMNode_Release(form_node);
if (FAILED(hres))
return hres;
hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)p);
node_release(node);
return hres;
}
static inline HTMLInputElement *impl_from_IHTMLInputElement(IHTMLInputElement *iface)
{
return CONTAINING_RECORD(iface, HTMLInputElement, IHTMLInputElement_iface);
......@@ -288,12 +262,7 @@ static HRESULT WINAPI HTMLInputElement_get_form(IHTMLInputElement *iface, IHTMLF
TRACE("(%p)->(%p)\n", This, p);
nsres = nsIDOMHTMLInputElement_GetForm(This->nsinput, &nsform);
if (NS_FAILED(nsres)) {
ERR("GetForm failed: %08x, nsform: %p\n", nsres, nsform);
return E_FAIL;
}
return return_nsform(&This->element, nsform, p);
return return_nsform(nsres, nsform, p);
}
static HRESULT WINAPI HTMLInputElement_put_size(IHTMLInputElement *iface, LONG v)
......@@ -1905,12 +1874,7 @@ static HRESULT WINAPI HTMLButtonElement_get_form(IHTMLButtonElement *iface, IHTM
TRACE("(%p)->(%p)\n", This, p);
nsres = nsIDOMHTMLButtonElement_GetForm(This->nsbutton, &nsform);
if (NS_FAILED(nsres)) {
ERR("GetForm failed: %08x, nsform: %p\n", nsres, nsform);
return E_FAIL;
}
return return_nsform(&This->element, nsform, p);
return return_nsform(nsres, nsform, p);
}
static HRESULT WINAPI HTMLButtonElement_createTextRange(IHTMLButtonElement *iface, IHTMLTxtRange **range)
......
......@@ -308,9 +308,6 @@ static HRESULT WINAPI HTMLOptionElement_get_form(IHTMLOptionElement *iface, IHTM
{
HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
nsIDOMHTMLFormElement *nsform;
nsIDOMNode *form_node;
HTMLDOMNode *node;
HRESULT hres;
nsresult nsres;
TRACE("(%p)->(%p)\n", This, p);
......@@ -319,30 +316,7 @@ static HRESULT WINAPI HTMLOptionElement_get_form(IHTMLOptionElement *iface, IHTM
return E_POINTER;
nsres = nsIDOMHTMLOptionElement_GetForm(This->nsoption, &nsform);
if (NS_FAILED(nsres)) {
ERR("GetForm failed: %08x, nsform: %p\n", nsres, nsform);
*p = NULL;
return E_FAIL;
}
if (nsform == NULL) {
TRACE("nsform not found\n");
*p = NULL;
return S_OK;
}
nsres = nsIDOMHTMLFormElement_QueryInterface(nsform, &IID_nsIDOMNode, (void**)&form_node);
nsIDOMHTMLFormElement_Release(nsform);
assert(nsres == NS_OK);
hres = get_node(form_node, TRUE, &node);
nsIDOMNode_Release(form_node);
if (FAILED(hres))
return hres;
hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)p);
node_release(node);
return hres;
return return_nsform(nsres, nsform, p);
}
static const IHTMLOptionElementVtbl HTMLOptionElementVtbl = {
......
......@@ -372,9 +372,6 @@ static HRESULT WINAPI HTMLSelectElement_get_form(IHTMLSelectElement *iface, IHTM
{
HTMLSelectElement *This = impl_from_IHTMLSelectElement(iface);
nsIDOMHTMLFormElement *nsform;
nsIDOMNode *form_node;
HTMLDOMNode *node;
HRESULT hres;
nsresult nsres;
TRACE("(%p)->(%p)\n", This, p);
......@@ -383,30 +380,7 @@ static HRESULT WINAPI HTMLSelectElement_get_form(IHTMLSelectElement *iface, IHTM
return E_POINTER;
nsres = nsIDOMHTMLSelectElement_GetForm(This->nsselect, &nsform);
if (NS_FAILED(nsres)) {
ERR("GetForm failed: %08x, nsform: %p\n", nsres, nsform);
*p = NULL;
return E_FAIL;
}
if (nsform == NULL) {
TRACE("nsform not found\n");
*p = NULL;
return S_OK;
}
nsres = nsIDOMHTMLFormElement_QueryInterface(nsform, &IID_nsIDOMNode, (void**)&form_node);
nsIDOMHTMLFormElement_Release(nsform);
assert(nsres == NS_OK);
hres = get_node(form_node, TRUE, &node);
nsIDOMNode_Release(form_node);
if (FAILED(hres))
return hres;
hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)p);
node_release(node);
return hres;
return return_nsform(nsres, nsform, p);
}
static HRESULT WINAPI HTMLSelectElement_add(IHTMLSelectElement *iface, IHTMLElement *element,
......
......@@ -197,33 +197,12 @@ static HRESULT WINAPI HTMLTextAreaElement_get_form(IHTMLTextAreaElement *iface,
{
HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
nsIDOMHTMLFormElement *nsform;
nsIDOMNode *nsnode;
HTMLDOMNode *node;
nsresult nsres;
HRESULT hres;
TRACE("(%p)->(%p)\n", This, p);
nsres = nsIDOMHTMLTextAreaElement_GetForm(This->nstextarea, &nsform);
assert(nsres == NS_OK);
if(!nsform) {
*p = NULL;
return S_OK;
}
nsres = nsIDOMHTMLFormElement_QueryInterface(nsform, &IID_nsIDOMNode, (void**)&nsnode);
nsIDOMHTMLFormElement_Release(nsform);
assert(nsres == NS_OK);
hres = get_node(nsnode, TRUE, &node);
nsIDOMNode_Release(nsnode);
if(FAILED(hres))
return hres;
hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLFormElement, (void**)p);
IHTMLDOMNode_Release(&node->IHTMLDOMNode_iface);
return hres;
return return_nsform(nsres, nsform, p);
}
static HRESULT WINAPI HTMLTextAreaElement_put_defaultValue(IHTMLTextAreaElement *iface, BSTR v)
......
......@@ -948,6 +948,7 @@ void nsAString_Finish(nsAString*) DECLSPEC_HIDDEN;
HRESULT return_nsstr(nsresult,nsAString*,BSTR*) DECLSPEC_HIDDEN;
HRESULT return_nsstr_variant(nsresult nsres, nsAString *nsstr, VARIANT *p) DECLSPEC_HIDDEN;
HRESULT return_nsform(nsresult,nsIDOMHTMLFormElement*,IHTMLFormElement**) DECLSPEC_HIDDEN;
nsICommandParams *create_nscommand_params(void) DECLSPEC_HIDDEN;
HRESULT nsnode_to_nsstring(nsIDOMNode*,nsAString*) DECLSPEC_HIDDEN;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment