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