urlmon: Implemented PARSE_PATH_FROM_URL for CoInternetParseIUri.
[wine] / dlls / mshtml / htmlform.c
1 /*
2  * Copyright 2009 Andrew Eikum for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include <stdarg.h>
20
21 #define COBJMACROS
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "ole2.h"
27
28 #include "wine/debug.h"
29
30 #include "mshtml_private.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
33
34 struct HTMLFormElement {
35     HTMLElement element;
36
37     const IHTMLFormElementVtbl *lpHTMLFormElementVtbl;
38
39     nsIDOMHTMLFormElement *nsform;
40 };
41
42 #define HTMLFORM(x)  (&(x)->lpHTMLFormElementVtbl)
43
44 static HRESULT htmlform_item(HTMLFormElement *This, int i, IDispatch **ret)
45 {
46     nsIDOMHTMLCollection *elements;
47     nsIDOMNode *item;
48     HTMLDOMNode *node;
49     nsresult nsres;
50     HRESULT hres;
51
52     nsres = nsIDOMHTMLFormElement_GetElements(This->nsform, &elements);
53     if(NS_FAILED(nsres)) {
54         FIXME("GetElements failed: 0x%08x\n", nsres);
55         return E_FAIL;
56     }
57
58     nsres = nsIDOMHTMLCollection_Item(elements, i, &item);
59     nsIDOMHTMLCollection_Release(elements);
60     if(NS_FAILED(nsres)) {
61         FIXME("Item failed: 0x%08x\n", nsres);
62         return E_FAIL;
63     }
64
65     if(item) {
66         hres = get_node(This->element.node.doc, item, TRUE, &node);
67         if(FAILED(hres))
68             return hres;
69
70         IHTMLDOMNode_AddRef(HTMLDOMNODE(node));
71         nsIDOMNode_Release(item);
72         *ret = (IDispatch*)HTMLDOMNODE(node);
73     }else {
74         *ret = NULL;
75     }
76
77     return S_OK;
78 }
79
80 #define HTMLFORM_THIS(iface) DEFINE_THIS(HTMLFormElement, HTMLFormElement, iface)
81
82 static HRESULT WINAPI HTMLFormElement_QueryInterface(IHTMLFormElement *iface,
83         REFIID riid, void **ppv)
84 {
85     HTMLFormElement *This = HTMLFORM_THIS(iface);
86
87     return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(&This->element.node), riid, ppv);
88 }
89
90 static ULONG WINAPI HTMLFormElement_AddRef(IHTMLFormElement *iface)
91 {
92     HTMLFormElement *This = HTMLFORM_THIS(iface);
93
94     return IHTMLDOMNode_AddRef(HTMLDOMNODE(&This->element.node));
95 }
96
97 static ULONG WINAPI HTMLFormElement_Release(IHTMLFormElement *iface)
98 {
99     HTMLFormElement *This = HTMLFORM_THIS(iface);
100
101     return IHTMLDOMNode_Release(HTMLDOMNODE(&This->element.node));
102 }
103
104 static HRESULT WINAPI HTMLFormElement_GetTypeInfoCount(IHTMLFormElement *iface, UINT *pctinfo)
105 {
106     HTMLFormElement *This = HTMLFORM_THIS(iface);
107     return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->element.node.dispex), pctinfo);
108 }
109
110 static HRESULT WINAPI HTMLFormElement_GetTypeInfo(IHTMLFormElement *iface, UINT iTInfo,
111                                               LCID lcid, ITypeInfo **ppTInfo)
112 {
113     HTMLFormElement *This = HTMLFORM_THIS(iface);
114     return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->element.node.dispex), iTInfo, lcid, ppTInfo);
115 }
116
117 static HRESULT WINAPI HTMLFormElement_GetIDsOfNames(IHTMLFormElement *iface, REFIID riid,
118                                                 LPOLESTR *rgszNames, UINT cNames,
119                                                 LCID lcid, DISPID *rgDispId)
120 {
121     HTMLFormElement *This = HTMLFORM_THIS(iface);
122     return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->element.node.dispex), riid, rgszNames, cNames, lcid, rgDispId);
123 }
124
125 static HRESULT WINAPI HTMLFormElement_Invoke(IHTMLFormElement *iface, DISPID dispIdMember,
126                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
127                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
128 {
129     HTMLFormElement *This = HTMLFORM_THIS(iface);
130     return IDispatchEx_Invoke(DISPATCHEX(&This->element.node.dispex), dispIdMember, riid, lcid, wFlags, pDispParams,
131             pVarResult, pExcepInfo, puArgErr);
132 }
133
134 static HRESULT WINAPI HTMLFormElement_put_action(IHTMLFormElement *iface, BSTR v)
135 {
136     HTMLFormElement *This = HTMLFORM_THIS(iface);
137     nsAString action_str;
138     nsresult nsres;
139
140     TRACE("(%p)->(%s)\n", This, wine_dbgstr_w(v));
141
142     nsAString_InitDepend(&action_str, v);
143     nsres = nsIDOMHTMLFormElement_SetAction(This->nsform, &action_str);
144     nsAString_Finish(&action_str);
145     if(NS_FAILED(nsres)) {
146         ERR("SetAction failed: %08x\n", nsres);
147         return E_FAIL;
148     }
149
150     return S_OK;
151 }
152
153 static HRESULT WINAPI HTMLFormElement_get_action(IHTMLFormElement *iface, BSTR *p)
154 {
155     HTMLFormElement *This = HTMLFORM_THIS(iface);
156     nsAString action_str;
157     nsresult nsres;
158     HRESULT hres;
159
160     TRACE("(%p)->(%p)\n", This, p);
161
162     nsAString_Init(&action_str, NULL);
163     nsres = nsIDOMHTMLFormElement_GetAction(This->nsform, &action_str);
164     if(NS_SUCCEEDED(nsres)) {
165         const PRUnichar *action;
166         nsAString_GetData(&action_str, &action);
167         hres = nsuri_to_url(action, FALSE, p);
168     }else {
169         ERR("GetAction failed: %08x\n", nsres);
170         hres = E_FAIL;
171     }
172
173     return hres;
174 }
175
176 static HRESULT WINAPI HTMLFormElement_put_dir(IHTMLFormElement *iface, BSTR v)
177 {
178     HTMLFormElement *This = HTMLFORM_THIS(iface);
179     FIXME("(%p)->(%s)\n", This, wine_dbgstr_w(v));
180     return E_NOTIMPL;
181 }
182
183 static HRESULT WINAPI HTMLFormElement_get_dir(IHTMLFormElement *iface, BSTR *p)
184 {
185     HTMLFormElement *This = HTMLFORM_THIS(iface);
186     FIXME("(%p)->(%p)\n", This, p);
187     return E_NOTIMPL;
188 }
189
190 static HRESULT WINAPI HTMLFormElement_put_encoding(IHTMLFormElement *iface, BSTR v)
191 {
192     static const WCHAR urlencodedW[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
193         'x','-','w','w','w','-','f','o','r','m','-','u','r','l','e','n','c','o','d','e','d',0};
194     static const WCHAR dataW[] = {'m','u','l','t','i','p','a','r','t','/',
195         'f','o','r','m','-','d','a','t','a',0};
196     static const WCHAR plainW[] = {'t','e','x','t','/','p','l','a','i','n',0};
197
198     HTMLFormElement *This = HTMLFORM_THIS(iface);
199     nsAString encoding_str;
200     nsresult nsres;
201
202     TRACE("(%p)->(%s)\n", This, wine_dbgstr_w(v));
203
204     if(lstrcmpiW(v, urlencodedW) && lstrcmpiW(v, dataW) && lstrcmpiW(v, plainW)) {
205         WARN("incorrect enctype\n");
206         return E_INVALIDARG;
207     }
208
209     nsAString_InitDepend(&encoding_str, v);
210     nsres = nsIDOMHTMLFormElement_SetEnctype(This->nsform, &encoding_str);
211     nsAString_Finish(&encoding_str);
212     if(NS_FAILED(nsres))
213         return E_FAIL;
214
215     return S_OK;
216 }
217
218 static HRESULT WINAPI HTMLFormElement_get_encoding(IHTMLFormElement *iface, BSTR *p)
219 {
220     HTMLFormElement *This = HTMLFORM_THIS(iface);
221     nsAString encoding_str;
222     nsresult nsres;
223
224     TRACE("(%p)->(%p)\n", This, p);
225
226     nsAString_Init(&encoding_str, NULL);
227     nsres = nsIDOMHTMLFormElement_GetEnctype(This->nsform, &encoding_str);
228     if(NS_SUCCEEDED(nsres)) {
229         const PRUnichar *encoding;
230         nsAString_GetData(&encoding_str, &encoding);
231
232         *p = SysAllocString(encoding);
233         if(!*p)
234             return E_OUTOFMEMORY;
235     }else
236         return E_FAIL;
237
238     return S_OK;
239 }
240
241 static HRESULT WINAPI HTMLFormElement_put_method(IHTMLFormElement *iface, BSTR v)
242 {
243     static const WCHAR postW[] = {'P','O','S','T',0};
244     static const WCHAR getW[] = {'G','E','T',0};
245
246     HTMLFormElement *This = HTMLFORM_THIS(iface);
247     nsAString method_str;
248     nsresult nsres;
249
250     TRACE("(%p)->(%s)\n", This, wine_dbgstr_w(v));
251
252     if(lstrcmpiW(v, postW) && lstrcmpiW(v, getW)) {
253         WARN("unrecognized method\n");
254         return E_INVALIDARG;
255     }
256
257     nsAString_InitDepend(&method_str, v);
258     nsres = nsIDOMHTMLFormElement_SetMethod(This->nsform, &method_str);
259     nsAString_Finish(&method_str);
260     if(NS_FAILED(nsres))
261         return E_FAIL;
262
263     return S_OK;
264 }
265
266 static HRESULT WINAPI HTMLFormElement_get_method(IHTMLFormElement *iface, BSTR *p)
267 {
268     HTMLFormElement *This = HTMLFORM_THIS(iface);
269     nsAString method_str;
270     nsresult nsres;
271
272     TRACE("(%p)->(%p)\n", This, p);
273
274     nsAString_Init(&method_str, NULL);
275     nsres = nsIDOMHTMLFormElement_GetMethod(This->nsform, &method_str);
276     if(NS_SUCCEEDED(nsres)) {
277         const PRUnichar *method;
278         nsAString_GetData(&method_str, &method);
279
280         *p = SysAllocString(method);
281         if(!*p)
282             return E_OUTOFMEMORY;
283     }else
284         return E_FAIL;
285
286     return S_OK;
287 }
288
289 static HRESULT WINAPI HTMLFormElement_get_elements(IHTMLFormElement *iface, IDispatch **p)
290 {
291     HTMLFormElement *This = HTMLFORM_THIS(iface);
292     FIXME("(%p)->(%p)\n", This, p);
293     return E_NOTIMPL;
294 }
295
296 static HRESULT WINAPI HTMLFormElement_put_target(IHTMLFormElement *iface, BSTR v)
297 {
298     HTMLFormElement *This = HTMLFORM_THIS(iface);
299     FIXME("(%p)->(%s)\n", This, wine_dbgstr_w(v));
300     return E_NOTIMPL;
301 }
302
303 static HRESULT WINAPI HTMLFormElement_get_target(IHTMLFormElement *iface, BSTR *p)
304 {
305     HTMLFormElement *This = HTMLFORM_THIS(iface);
306     FIXME("(%p)->(%p)\n", This, p);
307     return E_NOTIMPL;
308 }
309
310 static HRESULT WINAPI HTMLFormElement_put_name(IHTMLFormElement *iface, BSTR v)
311 {
312     HTMLFormElement *This = HTMLFORM_THIS(iface);
313     nsAString name_str;
314     nsresult nsres;
315
316     TRACE("(%p)->(%s)\n", This, wine_dbgstr_w(v));
317
318     nsAString_InitDepend(&name_str, v);
319     nsres = nsIDOMHTMLFormElement_SetName(This->nsform, &name_str);
320     nsAString_Finish(&name_str);
321     if(NS_FAILED(nsres))
322         return E_FAIL;
323
324     return S_OK;
325 }
326
327 static HRESULT WINAPI HTMLFormElement_get_name(IHTMLFormElement *iface, BSTR *p)
328 {
329     HTMLFormElement *This = HTMLFORM_THIS(iface);
330     nsAString name_str;
331     nsresult nsres;
332
333     TRACE("(%p)->(%p)\n", This, p);
334
335     nsAString_Init(&name_str, NULL);
336     nsres = nsIDOMHTMLFormElement_GetName(This->nsform, &name_str);
337     if(NS_SUCCEEDED(nsres)) {
338         const PRUnichar *name;
339         nsAString_GetData(&name_str, &name);
340
341         if(*name) {
342             *p = SysAllocString(name);
343             if(!*p)
344                 return E_OUTOFMEMORY;
345         }else
346             *p = NULL;
347     }else
348         return E_FAIL;
349
350     return S_OK;
351 }
352
353 static HRESULT WINAPI HTMLFormElement_put_onsubmit(IHTMLFormElement *iface, VARIANT v)
354 {
355     HTMLFormElement *This = HTMLFORM_THIS(iface);
356     FIXME("(%p)->(v)\n", This);
357     return E_NOTIMPL;
358 }
359
360 static HRESULT WINAPI HTMLFormElement_get_onsubmit(IHTMLFormElement *iface, VARIANT *p)
361 {
362     HTMLFormElement *This = HTMLFORM_THIS(iface);
363     FIXME("(%p)->(%p)\n", This, p);
364     return E_NOTIMPL;
365 }
366
367 static HRESULT WINAPI HTMLFormElement_put_onreset(IHTMLFormElement *iface, VARIANT v)
368 {
369     HTMLFormElement *This = HTMLFORM_THIS(iface);
370     FIXME("(%p)->(v)\n", This);
371     return E_NOTIMPL;
372 }
373
374 static HRESULT WINAPI HTMLFormElement_get_onreset(IHTMLFormElement *iface, VARIANT *p)
375 {
376     HTMLFormElement *This = HTMLFORM_THIS(iface);
377     FIXME("(%p)->(%p)\n", This, p);
378     return E_NOTIMPL;
379 }
380
381 static HRESULT WINAPI HTMLFormElement_submit(IHTMLFormElement *iface)
382 {
383     HTMLFormElement *This = HTMLFORM_THIS(iface);
384     FIXME("(%p)->()\n", This);
385     return E_NOTIMPL;
386 }
387
388 static HRESULT WINAPI HTMLFormElement_reset(IHTMLFormElement *iface)
389 {
390     HTMLFormElement *This = HTMLFORM_THIS(iface);
391     FIXME("(%p)->()\n", This);
392     return E_NOTIMPL;
393 }
394
395 static HRESULT WINAPI HTMLFormElement_put_length(IHTMLFormElement *iface, LONG v)
396 {
397     HTMLFormElement *This = HTMLFORM_THIS(iface);
398     FIXME("(%p)->(%d)\n", This, v);
399     return E_NOTIMPL;
400 }
401
402 static HRESULT WINAPI HTMLFormElement_get_length(IHTMLFormElement *iface, LONG *p)
403 {
404     HTMLFormElement *This = HTMLFORM_THIS(iface);
405     PRInt32 length;
406     nsresult nsres;
407
408     TRACE("(%p)->(%p)\n", This, p);
409
410     nsres = nsIDOMHTMLFormElement_GetLength(This->nsform, &length);
411     if(NS_FAILED(nsres)) {
412         ERR("GetLength failed: %08x\n", nsres);
413         return E_FAIL;
414     }
415
416     *p = length;
417     return S_OK;
418 }
419
420 static HRESULT WINAPI HTMLFormElement__newEnum(IHTMLFormElement *iface, IUnknown **p)
421 {
422     HTMLFormElement *This = HTMLFORM_THIS(iface);
423     FIXME("(%p)->(%p)\n", This, p);
424     return E_NOTIMPL;
425 }
426
427 static HRESULT WINAPI HTMLFormElement_item(IHTMLFormElement *iface, VARIANT name,
428         VARIANT index, IDispatch **pdisp)
429 {
430     HTMLFormElement *This = HTMLFORM_THIS(iface);
431
432     TRACE("(%p)->(%s %s %p)\n", This, debugstr_variant(&name), debugstr_variant(&index), pdisp);
433
434     if(!pdisp)
435         return E_INVALIDARG;
436     *pdisp = NULL;
437
438     if(V_VT(&name) == VT_I4) {
439         if(V_I4(&name) < 0)
440             return E_INVALIDARG;
441         return htmlform_item(This, V_I4(&name), pdisp);
442     }
443
444     FIXME("Unsupported args\n");
445     return E_NOTIMPL;
446 }
447
448 static HRESULT WINAPI HTMLFormElement_tags(IHTMLFormElement *iface, VARIANT tagName,
449         IDispatch **pdisp)
450 {
451     HTMLFormElement *This = HTMLFORM_THIS(iface);
452     FIXME("(%p)->(v %p)\n", This, pdisp);
453     return E_NOTIMPL;
454 }
455
456 #undef HTMLFORM_THIS
457
458 static const IHTMLFormElementVtbl HTMLFormElementVtbl = {
459     HTMLFormElement_QueryInterface,
460     HTMLFormElement_AddRef,
461     HTMLFormElement_Release,
462     HTMLFormElement_GetTypeInfoCount,
463     HTMLFormElement_GetTypeInfo,
464     HTMLFormElement_GetIDsOfNames,
465     HTMLFormElement_Invoke,
466     HTMLFormElement_put_action,
467     HTMLFormElement_get_action,
468     HTMLFormElement_put_dir,
469     HTMLFormElement_get_dir,
470     HTMLFormElement_put_encoding,
471     HTMLFormElement_get_encoding,
472     HTMLFormElement_put_method,
473     HTMLFormElement_get_method,
474     HTMLFormElement_get_elements,
475     HTMLFormElement_put_target,
476     HTMLFormElement_get_target,
477     HTMLFormElement_put_name,
478     HTMLFormElement_get_name,
479     HTMLFormElement_put_onsubmit,
480     HTMLFormElement_get_onsubmit,
481     HTMLFormElement_put_onreset,
482     HTMLFormElement_get_onreset,
483     HTMLFormElement_submit,
484     HTMLFormElement_reset,
485     HTMLFormElement_put_length,
486     HTMLFormElement_get_length,
487     HTMLFormElement__newEnum,
488     HTMLFormElement_item,
489     HTMLFormElement_tags
490 };
491
492 #define HTMLFORM_NODE_THIS(iface) DEFINE_THIS2(HTMLFormElement, element.node, iface)
493
494 static HRESULT HTMLFormElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
495 {
496     HTMLFormElement *This = HTMLFORM_NODE_THIS(iface);
497
498     *ppv = NULL;
499
500     if(IsEqualGUID(&IID_IUnknown, riid)) {
501         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
502         *ppv = HTMLFORM(This);
503     }else if(IsEqualGUID(&IID_IDispatch, riid)) {
504         TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
505         *ppv = HTMLFORM(This);
506     }else if(IsEqualGUID(&IID_IHTMLFormElement, riid)) {
507         TRACE("(%p)->(IID_IHTMLFormElement %p)\n", This, ppv);
508         *ppv = HTMLFORM(This);
509     }
510
511     if(*ppv) {
512         IUnknown_AddRef((IUnknown*)*ppv);
513         return S_OK;
514     }
515
516     return HTMLElement_QI(&This->element.node, riid, ppv);
517 }
518
519 static void HTMLFormElement_destructor(HTMLDOMNode *iface)
520 {
521     HTMLFormElement *This = HTMLFORM_NODE_THIS(iface);
522
523     if(This->nsform)
524         nsIDOMHTMLFormElement_Release(This->nsform);
525
526     HTMLElement_destructor(&This->element.node);
527 }
528
529 static HRESULT HTMLFormElement_get_dispid(HTMLDOMNode *iface,
530         BSTR name, DWORD grfdex, DISPID *pid)
531 {
532     HTMLFormElement *This = HTMLFORM_NODE_THIS(iface);
533     nsIDOMHTMLCollection *elements;
534     nsAString nsname, nsstr;
535     PRUint32 len, i;
536     nsresult nsres;
537     HRESULT hres = DISP_E_UNKNOWNNAME;
538
539     static const PRUnichar nameW[] = {'n','a','m','e',0};
540
541     TRACE("(%p)->(%s %x %p)\n", This, wine_dbgstr_w(name), grfdex, pid);
542
543     nsres = nsIDOMHTMLFormElement_GetElements(This->nsform, &elements);
544     if(NS_FAILED(nsres)) {
545         FIXME("GetElements failed: 0x%08x\n", nsres);
546         return E_FAIL;
547     }
548
549     nsres = nsIDOMHTMLCollection_GetLength(elements, &len);
550     if(NS_FAILED(nsres)) {
551         FIXME("GetLength failed: 0x%08x\n", nsres);
552         nsIDOMHTMLCollection_Release(elements);
553         return E_FAIL;
554     }
555
556     nsAString_InitDepend(&nsname, nameW);
557     nsAString_Init(&nsstr, NULL);
558     for(i = 0; i < len; ++i) {
559         nsIDOMNode *nsitem;
560         nsIDOMHTMLElement *nshtml_elem;
561         const PRUnichar *str;
562
563         nsres = nsIDOMHTMLCollection_Item(elements, i, &nsitem);
564         if(NS_FAILED(nsres)) {
565             FIXME("Item failed: 0x%08x\n", nsres);
566             hres = E_FAIL;
567             break;
568         }
569
570         nsres = nsIDOMNode_QueryInterface(nsitem, &IID_nsIDOMHTMLElement, (void**)&nshtml_elem);
571         nsIDOMNode_Release(nsitem);
572         if(NS_FAILED(nsres)) {
573             FIXME("Failed to get nsIDOMHTMLNode interface: 0x%08x\n", nsres);
574             hres = E_FAIL;
575             break;
576         }
577
578         /* compare by id attr */
579         nsres = nsIDOMHTMLElement_GetId(nshtml_elem, &nsstr);
580         if(NS_FAILED(nsres)) {
581             FIXME("GetId failed: 0x%08x\n", nsres);
582             nsIDOMHTMLElement_Release(nshtml_elem);
583             hres = E_FAIL;
584             break;
585         }
586         nsAString_GetData(&nsstr, &str);
587         if(!strcmpiW(str, name)) {
588             nsIDOMHTMLElement_Release(nshtml_elem);
589             /* FIXME: using index for dispid */
590             *pid = MSHTML_DISPID_CUSTOM_MIN + i;
591             hres = S_OK;
592             break;
593         }
594
595         /* compare by name attr */
596         nsres = nsIDOMHTMLElement_GetAttribute(nshtml_elem, &nsname, &nsstr);
597         nsIDOMHTMLElement_Release(nshtml_elem);
598         nsAString_GetData(&nsstr, &str);
599         if(!strcmpiW(str, name)) {
600             /* FIXME: using index for dispid */
601             *pid = MSHTML_DISPID_CUSTOM_MIN + i;
602             hres = S_OK;
603             break;
604         }
605     }
606     nsAString_Finish(&nsname);
607     nsAString_Finish(&nsstr);
608
609     nsIDOMHTMLCollection_Release(elements);
610
611     return hres;
612 }
613
614 static HRESULT HTMLFormElement_invoke(HTMLDOMNode *iface,
615         DISPID id, LCID lcid, WORD flags, DISPPARAMS *params, VARIANT *res,
616         EXCEPINFO *ei, IServiceProvider *caller)
617 {
618     HTMLFormElement *This = HTMLFORM_NODE_THIS(iface);
619     IDispatch *ret;
620     HRESULT hres;
621
622     TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
623
624     hres = htmlform_item(This, id - MSHTML_DISPID_CUSTOM_MIN, &ret);
625     if(FAILED(hres))
626         return hres;
627
628     if(ret) {
629         V_VT(res) = VT_DISPATCH;
630         V_DISPATCH(res) = ret;
631     }else {
632         V_VT(res) = VT_NULL;
633     }
634     return S_OK;
635 }
636
637 #undef HTMLFORM_NODE_THIS
638
639 static const NodeImplVtbl HTMLFormElementImplVtbl = {
640     HTMLFormElement_QI,
641     HTMLFormElement_destructor,
642     HTMLElement_clone,
643     NULL,
644     NULL,
645     NULL,
646     NULL,
647     NULL,
648     NULL,
649     HTMLFormElement_get_dispid,
650     HTMLFormElement_invoke
651 };
652
653 static const tid_t HTMLFormElement_iface_tids[] = {
654     HTMLELEMENT_TIDS,
655     IHTMLFormElement_tid,
656     0
657 };
658
659 static dispex_static_data_t HTMLFormElement_dispex = {
660     NULL,
661     DispHTMLFormElement_tid,
662     NULL,
663     HTMLFormElement_iface_tids
664 };
665
666 HRESULT HTMLFormElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
667 {
668     HTMLFormElement *ret;
669     nsresult nsres;
670
671     ret = heap_alloc_zero(sizeof(HTMLFormElement));
672     if(!ret)
673         return E_OUTOFMEMORY;
674
675     ret->lpHTMLFormElementVtbl = &HTMLFormElementVtbl;
676     ret->element.node.vtbl = &HTMLFormElementImplVtbl;
677
678     nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLFormElement, (void**)&ret->nsform);
679     if(NS_FAILED(nsres)) {
680         ERR("Could not get nsIDOMHTMLFormElement interface: %08x\n", nsres);
681         heap_free(ret);
682         return E_FAIL;
683     }
684
685     HTMLElement_Init(&ret->element, doc, nselem, &HTMLFormElement_dispex);
686
687     *elem = &ret->element;
688     return S_OK;
689 }