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

mshtml: Added IHTMLButtonElement::form property implementation.

parent 5a07f80e
......@@ -45,6 +45,32 @@ typedef struct {
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(elem->node.doc, 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);
......@@ -256,33 +282,17 @@ static HRESULT WINAPI HTMLInputElement_get_form(IHTMLInputElement *iface, IHTMLF
{
HTMLInputElement *This = impl_from_IHTMLInputElement(iface);
nsIDOMHTMLFormElement *nsform;
nsIDOMNode *form_node;
HTMLDOMNode *node;
HRESULT hres;
nsresult nsres;
TRACE("(%p)->(%p)\n", This, p);
nsres = nsIDOMHTMLInputElement_GetForm(This->nsinput, &nsform);
if (NS_FAILED(nsres) || nsform == NULL) {
if (NS_FAILED(nsres)) {
ERR("GetForm failed: %08x, nsform: %p\n", nsres, nsform);
*p = NULL;
return E_FAIL;
}
nsres = nsIDOMHTMLFormElement_QueryInterface(nsform, &IID_nsIDOMNode, (void**)&form_node);
nsIDOMHTMLFormElement_Release(nsform);
assert(nsres == NS_OK);
hres = get_node(This->element.node.doc, 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(&This->element, nsform, p);
}
static HRESULT WINAPI HTMLInputElement_put_size(IHTMLInputElement *iface, LONG v)
......@@ -1746,8 +1756,18 @@ static HRESULT WINAPI HTMLButtonElement_get_disabled(IHTMLButtonElement *iface,
static HRESULT WINAPI HTMLButtonElement_get_form(IHTMLButtonElement *iface, IHTMLFormElement **p)
{
HTMLButtonElement *This = impl_from_IHTMLButtonElement(iface);
FIXME("(%p)->(%p)\n", This, p);
return E_NOTIMPL;
nsIDOMHTMLFormElement *nsform;
nsresult nsres;
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);
}
static HRESULT WINAPI HTMLButtonElement_createTextRange(IHTMLButtonElement *iface, IHTMLTxtRange **range)
......
......@@ -4550,7 +4550,7 @@ static void test_select_form(IUnknown *uselect, IUnknown *uform)
ok(hres == S_OK, "get_form failed: %08x\n", hres);
ok(form != NULL, "form == NULL\n");
test_form_length((IUnknown*)form, 1);
test_form_length((IUnknown*)form, 2);
test_form_elements((IUnknown*)form);
test_form_name((IUnknown*)form, "form_name");
......@@ -6976,14 +6976,33 @@ static void _set_button_value(unsigned line, IHTMLElement *elem, const char *val
_test_button_value(line, elem, value);
}
#define get_button_form(a) _get_button_form(__LINE__,a)
static IHTMLFormElement *_get_button_form(unsigned line, IHTMLElement *elem)
{
IHTMLButtonElement *button = _get_button_iface(line, (IUnknown*)elem);
IHTMLFormElement *form;
HRESULT hres;
hres = IHTMLButtonElement_get_form(button, &form);
ok_(__FILE__,line)(hres == S_OK, "get_form failed: %08x\n", hres);
IHTMLButtonElement_Release(button);
return form;
}
static void test_button_elem(IHTMLElement *elem)
{
IHTMLFormElement *form;
test_button_name(elem, NULL);
set_button_name(elem, "button name");
test_button_type(elem, "submit");
test_button_value(elem, NULL);
set_button_value(elem, "val");
form = get_button_form(elem);
ok(!form, "form != NULL\n");
test_elem_istextedit(elem, VARIANT_TRUE);
}
......@@ -9062,10 +9081,12 @@ static void test_elems2(IHTMLDocument2 *doc)
}
test_elem_set_innerhtml((IUnknown*)div,
"<form id=\"form\" name=\"form_name\"><select id=\"sform\"><option id=\"oform\"></option></select></form>");
"<form id=\"form\" name=\"form_name\"><select id=\"sform\"><option id=\"oform\"></option></select><button id=\"btnid\"></button></form>");
elem = get_elem_by_id(doc, "sform", TRUE);
elem2 = get_elem_by_id(doc, "form", TRUE);
if(elem && elem2) {
IHTMLFormElement *form;
test_select_form((IUnknown*)elem, (IUnknown*)elem2);
IHTMLElement_Release(elem);
......@@ -9074,6 +9095,14 @@ static void test_elems2(IHTMLDocument2 *doc)
test_option_form((IUnknown*)elem, (IUnknown*)elem2);
IHTMLElement_Release(elem);
}
elem = get_elem_by_id(doc, "btnid", TRUE);
form = get_button_form(elem);
ok(iface_cmp((IUnknown*)form, (IUnknown*)elem2), "form != elem2\n");
IHTMLFormElement_Release(form);
IHTMLElement_Release(elem);
IHTMLElement_Release(elem2);
}
......
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