mshtml: Override default onsubmit action with our submit implementation.
[wine/multimedia.git] / dlls / mshtml / htmlform.c
blobdf425d1088337c661bd9b626e0fa53974198d1cf
1 /*
2 * Copyright 2009 Andrew Eikum for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
20 #include <assert.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "ole2.h"
29 #include "wine/debug.h"
31 #include "mshtml_private.h"
32 #include "htmlevent.h"
33 #include "binding.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
37 struct HTMLFormElement {
38 HTMLElement element;
40 IHTMLFormElement IHTMLFormElement_iface;
42 nsIDOMHTMLFormElement *nsform;
45 static HRESULT htmlform_item(HTMLFormElement *This, int i, IDispatch **ret)
47 nsIDOMHTMLCollection *elements;
48 nsIDOMNode *item;
49 HTMLDOMNode *node;
50 nsresult nsres;
51 HRESULT hres;
53 nsres = nsIDOMHTMLFormElement_GetElements(This->nsform, &elements);
54 if(NS_FAILED(nsres)) {
55 FIXME("GetElements failed: 0x%08x\n", nsres);
56 return E_FAIL;
59 nsres = nsIDOMHTMLCollection_Item(elements, i, &item);
60 nsIDOMHTMLCollection_Release(elements);
61 if(NS_FAILED(nsres)) {
62 FIXME("Item failed: 0x%08x\n", nsres);
63 return E_FAIL;
66 if(item) {
67 hres = get_node(This->element.node.doc, item, TRUE, &node);
68 if(FAILED(hres))
69 return hres;
71 nsIDOMNode_Release(item);
72 *ret = (IDispatch*)&node->IHTMLDOMNode_iface;
73 }else {
74 *ret = NULL;
77 return S_OK;
80 static inline HTMLFormElement *impl_from_IHTMLFormElement(IHTMLFormElement *iface)
82 return CONTAINING_RECORD(iface, HTMLFormElement, IHTMLFormElement_iface);
85 static HRESULT WINAPI HTMLFormElement_QueryInterface(IHTMLFormElement *iface,
86 REFIID riid, void **ppv)
88 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
90 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
93 static ULONG WINAPI HTMLFormElement_AddRef(IHTMLFormElement *iface)
95 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
97 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
100 static ULONG WINAPI HTMLFormElement_Release(IHTMLFormElement *iface)
102 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
104 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
107 static HRESULT WINAPI HTMLFormElement_GetTypeInfoCount(IHTMLFormElement *iface, UINT *pctinfo)
109 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
110 return IDispatchEx_GetTypeInfoCount(&This->element.node.dispex.IDispatchEx_iface, pctinfo);
113 static HRESULT WINAPI HTMLFormElement_GetTypeInfo(IHTMLFormElement *iface, UINT iTInfo,
114 LCID lcid, ITypeInfo **ppTInfo)
116 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
117 return IDispatchEx_GetTypeInfo(&This->element.node.dispex.IDispatchEx_iface, iTInfo, lcid,
118 ppTInfo);
121 static HRESULT WINAPI HTMLFormElement_GetIDsOfNames(IHTMLFormElement *iface, REFIID riid,
122 LPOLESTR *rgszNames, UINT cNames,
123 LCID lcid, DISPID *rgDispId)
125 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
126 return IDispatchEx_GetIDsOfNames(&This->element.node.dispex.IDispatchEx_iface, riid, rgszNames,
127 cNames, lcid, rgDispId);
130 static HRESULT WINAPI HTMLFormElement_Invoke(IHTMLFormElement *iface, DISPID dispIdMember,
131 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
132 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
134 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
135 return IDispatchEx_Invoke(&This->element.node.dispex.IDispatchEx_iface, dispIdMember, riid,
136 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
139 static HRESULT WINAPI HTMLFormElement_put_action(IHTMLFormElement *iface, BSTR v)
141 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
142 nsAString action_str;
143 nsresult nsres;
145 TRACE("(%p)->(%s)\n", This, wine_dbgstr_w(v));
147 nsAString_InitDepend(&action_str, v);
148 nsres = nsIDOMHTMLFormElement_SetAction(This->nsform, &action_str);
149 nsAString_Finish(&action_str);
150 if(NS_FAILED(nsres)) {
151 ERR("SetAction failed: %08x\n", nsres);
152 return E_FAIL;
155 return S_OK;
158 static HRESULT WINAPI HTMLFormElement_get_action(IHTMLFormElement *iface, BSTR *p)
160 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
161 nsAString action_str;
162 nsresult nsres;
163 HRESULT hres;
165 TRACE("(%p)->(%p)\n", This, p);
167 nsAString_Init(&action_str, NULL);
168 nsres = nsIDOMHTMLFormElement_GetAction(This->nsform, &action_str);
169 if(NS_SUCCEEDED(nsres)) {
170 const PRUnichar *action;
171 nsAString_GetData(&action_str, &action);
172 hres = nsuri_to_url(action, FALSE, p);
173 }else {
174 ERR("GetAction failed: %08x\n", nsres);
175 hres = E_FAIL;
178 nsAString_Finish(&action_str);
179 return hres;
182 static HRESULT WINAPI HTMLFormElement_put_dir(IHTMLFormElement *iface, BSTR v)
184 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
185 FIXME("(%p)->(%s)\n", This, wine_dbgstr_w(v));
186 return E_NOTIMPL;
189 static HRESULT WINAPI HTMLFormElement_get_dir(IHTMLFormElement *iface, BSTR *p)
191 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
192 FIXME("(%p)->(%p)\n", This, p);
193 return E_NOTIMPL;
196 static HRESULT WINAPI HTMLFormElement_put_encoding(IHTMLFormElement *iface, BSTR v)
198 static const WCHAR urlencodedW[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
199 'x','-','w','w','w','-','f','o','r','m','-','u','r','l','e','n','c','o','d','e','d',0};
200 static const WCHAR dataW[] = {'m','u','l','t','i','p','a','r','t','/',
201 'f','o','r','m','-','d','a','t','a',0};
202 static const WCHAR plainW[] = {'t','e','x','t','/','p','l','a','i','n',0};
204 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
205 nsAString encoding_str;
206 nsresult nsres;
208 TRACE("(%p)->(%s)\n", This, wine_dbgstr_w(v));
210 if(lstrcmpiW(v, urlencodedW) && lstrcmpiW(v, dataW) && lstrcmpiW(v, plainW)) {
211 WARN("incorrect enctype\n");
212 return E_INVALIDARG;
215 nsAString_InitDepend(&encoding_str, v);
216 nsres = nsIDOMHTMLFormElement_SetEnctype(This->nsform, &encoding_str);
217 nsAString_Finish(&encoding_str);
218 if(NS_FAILED(nsres))
219 return E_FAIL;
221 return S_OK;
224 static HRESULT WINAPI HTMLFormElement_get_encoding(IHTMLFormElement *iface, BSTR *p)
226 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
227 nsAString encoding_str;
228 nsresult nsres;
230 TRACE("(%p)->(%p)\n", This, p);
232 nsAString_Init(&encoding_str, NULL);
233 nsres = nsIDOMHTMLFormElement_GetEnctype(This->nsform, &encoding_str);
234 return return_nsstr(nsres, &encoding_str, p);
237 static HRESULT WINAPI HTMLFormElement_put_method(IHTMLFormElement *iface, BSTR v)
239 static const WCHAR postW[] = {'P','O','S','T',0};
240 static const WCHAR getW[] = {'G','E','T',0};
242 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
243 nsAString method_str;
244 nsresult nsres;
246 TRACE("(%p)->(%s)\n", This, wine_dbgstr_w(v));
248 if(lstrcmpiW(v, postW) && lstrcmpiW(v, getW)) {
249 WARN("unrecognized method\n");
250 return E_INVALIDARG;
253 nsAString_InitDepend(&method_str, v);
254 nsres = nsIDOMHTMLFormElement_SetMethod(This->nsform, &method_str);
255 nsAString_Finish(&method_str);
256 if(NS_FAILED(nsres))
257 return E_FAIL;
259 return S_OK;
262 static HRESULT WINAPI HTMLFormElement_get_method(IHTMLFormElement *iface, BSTR *p)
264 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
265 nsAString method_str;
266 nsresult nsres;
268 TRACE("(%p)->(%p)\n", This, p);
270 nsAString_Init(&method_str, NULL);
271 nsres = nsIDOMHTMLFormElement_GetMethod(This->nsform, &method_str);
272 return return_nsstr(nsres, &method_str, p);
275 static HRESULT WINAPI HTMLFormElement_get_elements(IHTMLFormElement *iface, IDispatch **p)
277 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
279 TRACE("(%p)->(%p)\n", This, p);
281 *p = (IDispatch*)&This->IHTMLFormElement_iface;
282 IDispatch_AddRef(*p);
283 return S_OK;
286 static HRESULT WINAPI HTMLFormElement_put_target(IHTMLFormElement *iface, BSTR v)
288 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
289 nsAString str;
290 nsresult nsres;
292 TRACE("(%p)->(%s)\n", This, wine_dbgstr_w(v));
294 nsAString_InitDepend(&str, v);
296 nsres = nsIDOMHTMLFormElement_SetTarget(This->nsform, &str);
298 nsAString_Finish(&str);
299 if (NS_FAILED(nsres)) {
300 ERR("Set Target(%s) failed: %08x\n", wine_dbgstr_w(v), nsres);
301 return E_FAIL;
304 return S_OK;
307 static HRESULT WINAPI HTMLFormElement_get_target(IHTMLFormElement *iface, BSTR *p)
309 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
310 nsAString str;
311 nsresult nsres;
313 TRACE("(%p)->(%p)\n", This, p);
315 nsAString_Init(&str, NULL);
316 nsres = nsIDOMHTMLFormElement_GetTarget(This->nsform, &str);
318 return return_nsstr(nsres, &str, p);
321 static HRESULT WINAPI HTMLFormElement_put_name(IHTMLFormElement *iface, BSTR v)
323 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
324 nsAString name_str;
325 nsresult nsres;
327 TRACE("(%p)->(%s)\n", This, wine_dbgstr_w(v));
329 nsAString_InitDepend(&name_str, v);
330 nsres = nsIDOMHTMLFormElement_SetName(This->nsform, &name_str);
331 nsAString_Finish(&name_str);
332 if(NS_FAILED(nsres))
333 return E_FAIL;
335 return S_OK;
338 static HRESULT WINAPI HTMLFormElement_get_name(IHTMLFormElement *iface, BSTR *p)
340 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
341 nsAString name_str;
342 nsresult nsres;
344 TRACE("(%p)->(%p)\n", This, p);
346 nsAString_Init(&name_str, NULL);
347 nsres = nsIDOMHTMLFormElement_GetName(This->nsform, &name_str);
348 return return_nsstr(nsres, &name_str, p);
351 static HRESULT WINAPI HTMLFormElement_put_onsubmit(IHTMLFormElement *iface, VARIANT v)
353 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
355 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
357 return set_node_event(&This->element.node, EVENTID_SUBMIT, &v);
360 static HRESULT WINAPI HTMLFormElement_get_onsubmit(IHTMLFormElement *iface, VARIANT *p)
362 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
364 TRACE("(%p)->(%p)\n", This, p);
366 return get_node_event(&This->element.node, EVENTID_SUBMIT, p);
369 static HRESULT WINAPI HTMLFormElement_put_onreset(IHTMLFormElement *iface, VARIANT v)
371 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
372 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
373 return E_NOTIMPL;
376 static HRESULT WINAPI HTMLFormElement_get_onreset(IHTMLFormElement *iface, VARIANT *p)
378 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
379 FIXME("(%p)->(%p)\n", This, p);
380 return E_NOTIMPL;
383 static HRESULT WINAPI HTMLFormElement_submit(IHTMLFormElement *iface)
385 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
386 HTMLOuterWindow *window = NULL, *this_window = NULL;
387 nsIInputStream *post_stream;
388 nsAString action_uri_str, target_str;
389 IUri *uri;
390 nsresult nsres;
391 HRESULT hres;
393 TRACE("(%p)->()\n", This);
395 if(This->element.node.doc) {
396 HTMLDocumentNode *doc = This->element.node.doc;
397 if(doc->window && doc->window->base.outer_window)
398 this_window = doc->window->base.outer_window;
400 if(!this_window) {
401 TRACE("No outer window\n");
402 return S_OK;
405 nsAString_Init(&target_str, NULL);
406 nsres = nsIDOMHTMLFormElement_GetTarget(This->nsform, &target_str);
407 if(NS_SUCCEEDED(nsres)) {
408 BOOL use_new_window;
409 window = get_target_window(this_window, &target_str, &use_new_window);
410 if(use_new_window)
411 FIXME("submit to new window is not supported\n");
413 nsAString_Finish(&target_str);
414 if(!window)
415 return S_OK;
418 * FIXME: We currently don't use our submit implementation for sub-windows because
419 * load_nsuri can't support post data. We should fix it.
421 if(!window->doc_obj || window->doc_obj->basedoc.window != window) {
422 nsres = nsIDOMHTMLFormElement_Submit(This->nsform);
423 IHTMLWindow2_Release(&window->base.IHTMLWindow2_iface);
424 if(NS_FAILED(nsres)) {
425 ERR("Submit failed: %08x\n", nsres);
426 return E_FAIL;
429 return S_OK;
432 nsAString_Init(&action_uri_str, NULL);
433 nsres = nsIDOMHTMLFormElement_GetFormData(This->nsform, NULL, &action_uri_str, &post_stream);
434 if(NS_SUCCEEDED(nsres)) {
435 const PRUnichar *action_uri;
437 nsAString_GetData(&action_uri_str, &action_uri);
438 hres = create_uri(action_uri, 0, &uri);
439 }else {
440 ERR("GetFormData failed: %08x\n", nsres);
441 hres = E_FAIL;
443 nsAString_Finish(&action_uri_str);
444 if(SUCCEEDED(hres)) {
445 window->readystate_locked++;
446 hres = submit_form(window, uri, post_stream);
447 window->readystate_locked--;
448 IUri_Release(uri);
451 IHTMLWindow2_Release(&window->base.IHTMLWindow2_iface);
452 if(post_stream)
453 nsIInputStream_Release(post_stream);
454 return hres;
457 static HRESULT WINAPI HTMLFormElement_reset(IHTMLFormElement *iface)
459 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
460 nsresult nsres;
462 TRACE("(%p)->()\n", This);
463 nsres = nsIDOMHTMLFormElement_Reset(This->nsform);
464 if (NS_FAILED(nsres)) {
465 ERR("Reset failed: %08x\n", nsres);
466 return E_FAIL;
469 return S_OK;
472 static HRESULT WINAPI HTMLFormElement_put_length(IHTMLFormElement *iface, LONG v)
474 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
475 FIXME("(%p)->(%d)\n", This, v);
476 return E_NOTIMPL;
479 static HRESULT WINAPI HTMLFormElement_get_length(IHTMLFormElement *iface, LONG *p)
481 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
482 nsresult nsres;
484 TRACE("(%p)->(%p)\n", This, p);
486 nsres = nsIDOMHTMLFormElement_GetLength(This->nsform, p);
487 if(NS_FAILED(nsres)) {
488 ERR("GetLength failed: %08x\n", nsres);
489 return E_FAIL;
492 return S_OK;
495 static HRESULT WINAPI HTMLFormElement__newEnum(IHTMLFormElement *iface, IUnknown **p)
497 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
498 FIXME("(%p)->(%p)\n", This, p);
499 return E_NOTIMPL;
502 static HRESULT WINAPI HTMLFormElement_item(IHTMLFormElement *iface, VARIANT name,
503 VARIANT index, IDispatch **pdisp)
505 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
507 TRACE("(%p)->(%s %s %p)\n", This, debugstr_variant(&name), debugstr_variant(&index), pdisp);
509 if(!pdisp)
510 return E_INVALIDARG;
511 *pdisp = NULL;
513 if(V_VT(&name) == VT_I4) {
514 if(V_I4(&name) < 0)
515 return E_INVALIDARG;
516 return htmlform_item(This, V_I4(&name), pdisp);
519 FIXME("Unsupported args\n");
520 return E_NOTIMPL;
523 static HRESULT WINAPI HTMLFormElement_tags(IHTMLFormElement *iface, VARIANT tagName,
524 IDispatch **pdisp)
526 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
527 FIXME("(%p)->(v %p)\n", This, pdisp);
528 return E_NOTIMPL;
531 static const IHTMLFormElementVtbl HTMLFormElementVtbl = {
532 HTMLFormElement_QueryInterface,
533 HTMLFormElement_AddRef,
534 HTMLFormElement_Release,
535 HTMLFormElement_GetTypeInfoCount,
536 HTMLFormElement_GetTypeInfo,
537 HTMLFormElement_GetIDsOfNames,
538 HTMLFormElement_Invoke,
539 HTMLFormElement_put_action,
540 HTMLFormElement_get_action,
541 HTMLFormElement_put_dir,
542 HTMLFormElement_get_dir,
543 HTMLFormElement_put_encoding,
544 HTMLFormElement_get_encoding,
545 HTMLFormElement_put_method,
546 HTMLFormElement_get_method,
547 HTMLFormElement_get_elements,
548 HTMLFormElement_put_target,
549 HTMLFormElement_get_target,
550 HTMLFormElement_put_name,
551 HTMLFormElement_get_name,
552 HTMLFormElement_put_onsubmit,
553 HTMLFormElement_get_onsubmit,
554 HTMLFormElement_put_onreset,
555 HTMLFormElement_get_onreset,
556 HTMLFormElement_submit,
557 HTMLFormElement_reset,
558 HTMLFormElement_put_length,
559 HTMLFormElement_get_length,
560 HTMLFormElement__newEnum,
561 HTMLFormElement_item,
562 HTMLFormElement_tags
565 static inline HTMLFormElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
567 return CONTAINING_RECORD(iface, HTMLFormElement, element.node);
570 static HRESULT HTMLFormElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
572 HTMLFormElement *This = impl_from_HTMLDOMNode(iface);
574 *ppv = NULL;
576 if(IsEqualGUID(&IID_IUnknown, riid)) {
577 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
578 *ppv = &This->IHTMLFormElement_iface;
579 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
580 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
581 *ppv = &This->IHTMLFormElement_iface;
582 }else if(IsEqualGUID(&IID_IHTMLFormElement, riid)) {
583 TRACE("(%p)->(IID_IHTMLFormElement %p)\n", This, ppv);
584 *ppv = &This->IHTMLFormElement_iface;
587 if(*ppv) {
588 IUnknown_AddRef((IUnknown*)*ppv);
589 return S_OK;
592 return HTMLElement_QI(&This->element.node, riid, ppv);
595 static HRESULT HTMLFormElement_get_dispid(HTMLDOMNode *iface,
596 BSTR name, DWORD grfdex, DISPID *pid)
598 HTMLFormElement *This = impl_from_HTMLDOMNode(iface);
599 nsIDOMHTMLCollection *elements;
600 nsAString nsstr, name_str;
601 UINT32 len, i;
602 nsresult nsres;
603 HRESULT hres = DISP_E_UNKNOWNNAME;
605 static const PRUnichar nameW[] = {'n','a','m','e',0};
607 TRACE("(%p)->(%s %x %p)\n", This, wine_dbgstr_w(name), grfdex, pid);
609 nsres = nsIDOMHTMLFormElement_GetElements(This->nsform, &elements);
610 if(NS_FAILED(nsres)) {
611 FIXME("GetElements failed: 0x%08x\n", nsres);
612 return E_FAIL;
615 nsres = nsIDOMHTMLCollection_GetLength(elements, &len);
616 if(NS_FAILED(nsres)) {
617 FIXME("GetLength failed: 0x%08x\n", nsres);
618 nsIDOMHTMLCollection_Release(elements);
619 return E_FAIL;
622 if(len > MSHTML_CUSTOM_DISPID_CNT)
623 len = MSHTML_CUSTOM_DISPID_CNT;
625 /* FIXME: Implement in more generic way */
626 if('0' <= *name && *name <= '9') {
627 WCHAR *end_ptr;
629 i = strtoulW(name, &end_ptr, 10);
630 if(!*end_ptr && i < len) {
631 *pid = MSHTML_DISPID_CUSTOM_MIN + i;
632 return S_OK;
636 nsAString_Init(&nsstr, NULL);
637 for(i = 0; i < len; ++i) {
638 nsIDOMNode *nsitem;
639 nsIDOMHTMLElement *nshtml_elem;
640 const PRUnichar *str;
642 nsres = nsIDOMHTMLCollection_Item(elements, i, &nsitem);
643 if(NS_FAILED(nsres)) {
644 FIXME("Item failed: 0x%08x\n", nsres);
645 hres = E_FAIL;
646 break;
649 nsres = nsIDOMNode_QueryInterface(nsitem, &IID_nsIDOMHTMLElement, (void**)&nshtml_elem);
650 nsIDOMNode_Release(nsitem);
651 if(NS_FAILED(nsres)) {
652 FIXME("Failed to get nsIDOMHTMLNode interface: 0x%08x\n", nsres);
653 hres = E_FAIL;
654 break;
657 /* compare by id attr */
658 nsres = nsIDOMHTMLElement_GetId(nshtml_elem, &nsstr);
659 if(NS_FAILED(nsres)) {
660 FIXME("GetId failed: 0x%08x\n", nsres);
661 nsIDOMHTMLElement_Release(nshtml_elem);
662 hres = E_FAIL;
663 break;
665 nsAString_GetData(&nsstr, &str);
666 if(!strcmpiW(str, name)) {
667 nsIDOMHTMLElement_Release(nshtml_elem);
668 /* FIXME: using index for dispid */
669 *pid = MSHTML_DISPID_CUSTOM_MIN + i;
670 hres = S_OK;
671 break;
674 /* compare by name attr */
675 nsres = get_elem_attr_value(nshtml_elem, nameW, &name_str, &str);
676 nsIDOMHTMLElement_Release(nshtml_elem);
677 if(NS_SUCCEEDED(nsres)) {
678 if(!strcmpiW(str, name)) {
679 nsAString_Finish(&name_str);
680 /* FIXME: using index for dispid */
681 *pid = MSHTML_DISPID_CUSTOM_MIN + i;
682 hres = S_OK;
683 break;
685 nsAString_Finish(&name_str);
689 nsAString_Finish(&nsstr);
690 nsIDOMHTMLCollection_Release(elements);
691 return hres;
694 static HRESULT HTMLFormElement_invoke(HTMLDOMNode *iface,
695 DISPID id, LCID lcid, WORD flags, DISPPARAMS *params, VARIANT *res,
696 EXCEPINFO *ei, IServiceProvider *caller)
698 HTMLFormElement *This = impl_from_HTMLDOMNode(iface);
699 IDispatch *ret;
700 HRESULT hres;
702 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
704 hres = htmlform_item(This, id - MSHTML_DISPID_CUSTOM_MIN, &ret);
705 if(FAILED(hres))
706 return hres;
708 if(ret) {
709 V_VT(res) = VT_DISPATCH;
710 V_DISPATCH(res) = ret;
711 }else {
712 V_VT(res) = VT_NULL;
714 return S_OK;
717 static HRESULT HTMLFormElement_handle_event(HTMLDOMNode *iface, eventid_t eid, nsIDOMEvent *event, BOOL *prevent_default)
719 HTMLFormElement *This = impl_from_HTMLDOMNode(iface);
721 if(eid == EVENTID_SUBMIT) {
722 *prevent_default = TRUE;
723 return IHTMLFormElement_submit(&This->IHTMLFormElement_iface);
726 return HTMLElement_handle_event(&This->element.node, eid, event, prevent_default);
729 static const NodeImplVtbl HTMLFormElementImplVtbl = {
730 HTMLFormElement_QI,
731 HTMLElement_destructor,
732 HTMLElement_cpc,
733 HTMLElement_clone,
734 HTMLFormElement_handle_event,
735 HTMLElement_get_attr_col,
736 NULL,
737 NULL,
738 NULL,
739 NULL,
740 NULL,
741 NULL,
742 HTMLFormElement_get_dispid,
743 HTMLFormElement_invoke
746 static const tid_t HTMLFormElement_iface_tids[] = {
747 HTMLELEMENT_TIDS,
748 IHTMLFormElement_tid,
752 static dispex_static_data_t HTMLFormElement_dispex = {
753 NULL,
754 DispHTMLFormElement_tid,
755 NULL,
756 HTMLFormElement_iface_tids
759 HRESULT HTMLFormElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
761 HTMLFormElement *ret;
762 nsresult nsres;
764 ret = heap_alloc_zero(sizeof(HTMLFormElement));
765 if(!ret)
766 return E_OUTOFMEMORY;
768 ret->IHTMLFormElement_iface.lpVtbl = &HTMLFormElementVtbl;
769 ret->element.node.vtbl = &HTMLFormElementImplVtbl;
771 HTMLElement_Init(&ret->element, doc, nselem, &HTMLFormElement_dispex);
773 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLFormElement, (void**)&ret->nsform);
775 /* Share the reference with nsnode */
776 assert(nsres == NS_OK && (nsIDOMNode*)ret->nsform == ret->element.node.nsnode);
777 nsIDOMNode_Release(ret->element.node.nsnode);
779 *elem = &ret->element;
780 return S_OK;