diff --git a/dlls/mshtml/htmlform.c b/dlls/mshtml/htmlform.c
index 27a82fa1c38..c22fa9e019a 100644
--- a/dlls/mshtml/htmlform.c
+++ b/dlls/mshtml/htmlform.c
@@ -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;
diff --git a/dlls/mshtml/htmlinput.c b/dlls/mshtml/htmlinput.c
index 9c4486408ee..1ae1f8a55e3 100644
--- a/dlls/mshtml/htmlinput.c
+++ b/dlls/mshtml/htmlinput.c
@@ -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)
diff --git a/dlls/mshtml/htmloption.c b/dlls/mshtml/htmloption.c
index a2bf0738317..e337be92be6 100644
--- a/dlls/mshtml/htmloption.c
+++ b/dlls/mshtml/htmloption.c
@@ -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 = {
diff --git a/dlls/mshtml/htmlselect.c b/dlls/mshtml/htmlselect.c
index 320cf5f199a..a1d9b052f92 100644
--- a/dlls/mshtml/htmlselect.c
+++ b/dlls/mshtml/htmlselect.c
@@ -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,
diff --git a/dlls/mshtml/htmltextarea.c b/dlls/mshtml/htmltextarea.c
index 599c0296b2e..caf5d85f749 100644
--- a/dlls/mshtml/htmltextarea.c
+++ b/dlls/mshtml/htmltextarea.c
@@ -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)
diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h
index c720ef420c9..551ee12862d 100644
--- a/dlls/mshtml/mshtml_private.h
+++ b/dlls/mshtml/mshtml_private.h
@@ -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;