oleaut32/tests: Test UnRegisterTypeLib surely deletes registry keys.
[wine.git] / dlls / mshtml / htmlform.c
blob6cbf1f661e8816c7fdb1af1ae3220579b0b95b3c
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 FIXME("(%p)->(%s)\n", This, wine_dbgstr_w(v));
290 return E_NOTIMPL;
293 static HRESULT WINAPI HTMLFormElement_get_target(IHTMLFormElement *iface, BSTR *p)
295 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
296 FIXME("(%p)->(%p)\n", This, p);
297 return E_NOTIMPL;
300 static HRESULT WINAPI HTMLFormElement_put_name(IHTMLFormElement *iface, BSTR v)
302 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
303 nsAString name_str;
304 nsresult nsres;
306 TRACE("(%p)->(%s)\n", This, wine_dbgstr_w(v));
308 nsAString_InitDepend(&name_str, v);
309 nsres = nsIDOMHTMLFormElement_SetName(This->nsform, &name_str);
310 nsAString_Finish(&name_str);
311 if(NS_FAILED(nsres))
312 return E_FAIL;
314 return S_OK;
317 static HRESULT WINAPI HTMLFormElement_get_name(IHTMLFormElement *iface, BSTR *p)
319 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
320 nsAString name_str;
321 nsresult nsres;
323 TRACE("(%p)->(%p)\n", This, p);
325 nsAString_Init(&name_str, NULL);
326 nsres = nsIDOMHTMLFormElement_GetName(This->nsform, &name_str);
327 return return_nsstr(nsres, &name_str, p);
330 static HRESULT WINAPI HTMLFormElement_put_onsubmit(IHTMLFormElement *iface, VARIANT v)
332 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
334 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
336 return set_node_event(&This->element.node, EVENTID_SUBMIT, &v);
339 static HRESULT WINAPI HTMLFormElement_get_onsubmit(IHTMLFormElement *iface, VARIANT *p)
341 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
343 TRACE("(%p)->(%p)\n", This, p);
345 return get_node_event(&This->element.node, EVENTID_SUBMIT, p);
348 static HRESULT WINAPI HTMLFormElement_put_onreset(IHTMLFormElement *iface, VARIANT v)
350 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
351 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
352 return E_NOTIMPL;
355 static HRESULT WINAPI HTMLFormElement_get_onreset(IHTMLFormElement *iface, VARIANT *p)
357 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
358 FIXME("(%p)->(%p)\n", This, p);
359 return E_NOTIMPL;
362 static HRESULT WINAPI HTMLFormElement_submit(IHTMLFormElement *iface)
364 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
365 HTMLOuterWindow *window = NULL, *this_window = NULL;
366 nsIInputStream *post_stream;
367 nsAString action_uri_str, target_str;
368 IUri *uri;
369 nsresult nsres;
370 HRESULT hres;
372 TRACE("(%p)->()\n", This);
374 if(This->element.node.doc) {
375 HTMLDocumentNode *doc = This->element.node.doc;
376 if(doc->window && doc->window->base.outer_window)
377 this_window = doc->window->base.outer_window;
379 if(!this_window) {
380 TRACE("No outer window\n");
381 return S_OK;
384 nsAString_Init(&target_str, NULL);
385 nsres = nsIDOMHTMLFormElement_GetTarget(This->nsform, &target_str);
386 if(NS_SUCCEEDED(nsres)) {
387 BOOL use_new_window;
388 window = get_target_window(this_window, &target_str, &use_new_window);
389 if(use_new_window)
390 FIXME("submit to new window is not supported\n");
392 nsAString_Finish(&target_str);
393 if(!window)
394 return S_OK;
397 * FIXME: We currently don't use our submit implementation for sub-windows because
398 * load_nsuri can't support post data. We should fix it.
400 if(!window->doc_obj || window->doc_obj->basedoc.window != window) {
401 nsres = nsIDOMHTMLFormElement_Submit(This->nsform);
402 IHTMLWindow2_Release(&window->base.IHTMLWindow2_iface);
403 if(NS_FAILED(nsres)) {
404 ERR("Submit failed: %08x\n", nsres);
405 return E_FAIL;
408 return S_OK;
411 nsAString_Init(&action_uri_str, NULL);
412 nsres = nsIDOMHTMLFormElement_GetFormData(This->nsform, NULL, &action_uri_str, &post_stream);
413 if(NS_SUCCEEDED(nsres)) {
414 const PRUnichar *action_uri;
416 nsAString_GetData(&action_uri_str, &action_uri);
417 hres = create_uri(action_uri, 0, &uri);
418 }else {
419 ERR("GetFormData failed: %08x\n", nsres);
420 hres = E_FAIL;
422 nsAString_Finish(&action_uri_str);
423 if(SUCCEEDED(hres)) {
424 window->readystate_locked++;
425 hres = submit_form(window, uri, post_stream);
426 window->readystate_locked--;
427 IUri_Release(uri);
430 IHTMLWindow2_Release(&window->base.IHTMLWindow2_iface);
431 if(post_stream)
432 nsIInputStream_Release(post_stream);
433 return hres;
436 static HRESULT WINAPI HTMLFormElement_reset(IHTMLFormElement *iface)
438 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
439 FIXME("(%p)->()\n", This);
440 return E_NOTIMPL;
443 static HRESULT WINAPI HTMLFormElement_put_length(IHTMLFormElement *iface, LONG v)
445 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
446 FIXME("(%p)->(%d)\n", This, v);
447 return E_NOTIMPL;
450 static HRESULT WINAPI HTMLFormElement_get_length(IHTMLFormElement *iface, LONG *p)
452 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
453 nsresult nsres;
455 TRACE("(%p)->(%p)\n", This, p);
457 nsres = nsIDOMHTMLFormElement_GetLength(This->nsform, p);
458 if(NS_FAILED(nsres)) {
459 ERR("GetLength failed: %08x\n", nsres);
460 return E_FAIL;
463 return S_OK;
466 static HRESULT WINAPI HTMLFormElement__newEnum(IHTMLFormElement *iface, IUnknown **p)
468 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
469 FIXME("(%p)->(%p)\n", This, p);
470 return E_NOTIMPL;
473 static HRESULT WINAPI HTMLFormElement_item(IHTMLFormElement *iface, VARIANT name,
474 VARIANT index, IDispatch **pdisp)
476 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
478 TRACE("(%p)->(%s %s %p)\n", This, debugstr_variant(&name), debugstr_variant(&index), pdisp);
480 if(!pdisp)
481 return E_INVALIDARG;
482 *pdisp = NULL;
484 if(V_VT(&name) == VT_I4) {
485 if(V_I4(&name) < 0)
486 return E_INVALIDARG;
487 return htmlform_item(This, V_I4(&name), pdisp);
490 FIXME("Unsupported args\n");
491 return E_NOTIMPL;
494 static HRESULT WINAPI HTMLFormElement_tags(IHTMLFormElement *iface, VARIANT tagName,
495 IDispatch **pdisp)
497 HTMLFormElement *This = impl_from_IHTMLFormElement(iface);
498 FIXME("(%p)->(v %p)\n", This, pdisp);
499 return E_NOTIMPL;
502 static const IHTMLFormElementVtbl HTMLFormElementVtbl = {
503 HTMLFormElement_QueryInterface,
504 HTMLFormElement_AddRef,
505 HTMLFormElement_Release,
506 HTMLFormElement_GetTypeInfoCount,
507 HTMLFormElement_GetTypeInfo,
508 HTMLFormElement_GetIDsOfNames,
509 HTMLFormElement_Invoke,
510 HTMLFormElement_put_action,
511 HTMLFormElement_get_action,
512 HTMLFormElement_put_dir,
513 HTMLFormElement_get_dir,
514 HTMLFormElement_put_encoding,
515 HTMLFormElement_get_encoding,
516 HTMLFormElement_put_method,
517 HTMLFormElement_get_method,
518 HTMLFormElement_get_elements,
519 HTMLFormElement_put_target,
520 HTMLFormElement_get_target,
521 HTMLFormElement_put_name,
522 HTMLFormElement_get_name,
523 HTMLFormElement_put_onsubmit,
524 HTMLFormElement_get_onsubmit,
525 HTMLFormElement_put_onreset,
526 HTMLFormElement_get_onreset,
527 HTMLFormElement_submit,
528 HTMLFormElement_reset,
529 HTMLFormElement_put_length,
530 HTMLFormElement_get_length,
531 HTMLFormElement__newEnum,
532 HTMLFormElement_item,
533 HTMLFormElement_tags
536 static inline HTMLFormElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
538 return CONTAINING_RECORD(iface, HTMLFormElement, element.node);
541 static HRESULT HTMLFormElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
543 HTMLFormElement *This = impl_from_HTMLDOMNode(iface);
545 *ppv = NULL;
547 if(IsEqualGUID(&IID_IUnknown, riid)) {
548 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
549 *ppv = &This->IHTMLFormElement_iface;
550 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
551 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
552 *ppv = &This->IHTMLFormElement_iface;
553 }else if(IsEqualGUID(&IID_IHTMLFormElement, riid)) {
554 TRACE("(%p)->(IID_IHTMLFormElement %p)\n", This, ppv);
555 *ppv = &This->IHTMLFormElement_iface;
558 if(*ppv) {
559 IUnknown_AddRef((IUnknown*)*ppv);
560 return S_OK;
563 return HTMLElement_QI(&This->element.node, riid, ppv);
566 static HRESULT HTMLFormElement_get_dispid(HTMLDOMNode *iface,
567 BSTR name, DWORD grfdex, DISPID *pid)
569 HTMLFormElement *This = impl_from_HTMLDOMNode(iface);
570 nsIDOMHTMLCollection *elements;
571 nsAString nsstr, name_str;
572 UINT32 len, i;
573 nsresult nsres;
574 HRESULT hres = DISP_E_UNKNOWNNAME;
576 static const PRUnichar nameW[] = {'n','a','m','e',0};
578 TRACE("(%p)->(%s %x %p)\n", This, wine_dbgstr_w(name), grfdex, pid);
580 nsres = nsIDOMHTMLFormElement_GetElements(This->nsform, &elements);
581 if(NS_FAILED(nsres)) {
582 FIXME("GetElements failed: 0x%08x\n", nsres);
583 return E_FAIL;
586 nsres = nsIDOMHTMLCollection_GetLength(elements, &len);
587 if(NS_FAILED(nsres)) {
588 FIXME("GetLength failed: 0x%08x\n", nsres);
589 nsIDOMHTMLCollection_Release(elements);
590 return E_FAIL;
593 if(len > MSHTML_CUSTOM_DISPID_CNT)
594 len = MSHTML_CUSTOM_DISPID_CNT;
596 /* FIXME: Implement in more generic way */
597 if('0' <= *name && *name <= '9') {
598 WCHAR *end_ptr;
600 i = strtoulW(name, &end_ptr, 10);
601 if(!*end_ptr && i < len) {
602 *pid = MSHTML_DISPID_CUSTOM_MIN + i;
603 return S_OK;
607 nsAString_Init(&nsstr, NULL);
608 for(i = 0; i < len; ++i) {
609 nsIDOMNode *nsitem;
610 nsIDOMHTMLElement *nshtml_elem;
611 const PRUnichar *str;
613 nsres = nsIDOMHTMLCollection_Item(elements, i, &nsitem);
614 if(NS_FAILED(nsres)) {
615 FIXME("Item failed: 0x%08x\n", nsres);
616 hres = E_FAIL;
617 break;
620 nsres = nsIDOMNode_QueryInterface(nsitem, &IID_nsIDOMHTMLElement, (void**)&nshtml_elem);
621 nsIDOMNode_Release(nsitem);
622 if(NS_FAILED(nsres)) {
623 FIXME("Failed to get nsIDOMHTMLNode interface: 0x%08x\n", nsres);
624 hres = E_FAIL;
625 break;
628 /* compare by id attr */
629 nsres = nsIDOMHTMLElement_GetId(nshtml_elem, &nsstr);
630 if(NS_FAILED(nsres)) {
631 FIXME("GetId failed: 0x%08x\n", nsres);
632 nsIDOMHTMLElement_Release(nshtml_elem);
633 hres = E_FAIL;
634 break;
636 nsAString_GetData(&nsstr, &str);
637 if(!strcmpiW(str, name)) {
638 nsIDOMHTMLElement_Release(nshtml_elem);
639 /* FIXME: using index for dispid */
640 *pid = MSHTML_DISPID_CUSTOM_MIN + i;
641 hres = S_OK;
642 break;
645 /* compare by name attr */
646 nsres = get_elem_attr_value(nshtml_elem, nameW, &name_str, &str);
647 nsIDOMHTMLElement_Release(nshtml_elem);
648 if(NS_SUCCEEDED(nsres)) {
649 if(!strcmpiW(str, name)) {
650 nsAString_Finish(&name_str);
651 /* FIXME: using index for dispid */
652 *pid = MSHTML_DISPID_CUSTOM_MIN + i;
653 hres = S_OK;
654 break;
656 nsAString_Finish(&name_str);
660 nsAString_Finish(&nsstr);
661 nsIDOMHTMLCollection_Release(elements);
662 return hres;
665 static HRESULT HTMLFormElement_invoke(HTMLDOMNode *iface,
666 DISPID id, LCID lcid, WORD flags, DISPPARAMS *params, VARIANT *res,
667 EXCEPINFO *ei, IServiceProvider *caller)
669 HTMLFormElement *This = impl_from_HTMLDOMNode(iface);
670 IDispatch *ret;
671 HRESULT hres;
673 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
675 hres = htmlform_item(This, id - MSHTML_DISPID_CUSTOM_MIN, &ret);
676 if(FAILED(hres))
677 return hres;
679 if(ret) {
680 V_VT(res) = VT_DISPATCH;
681 V_DISPATCH(res) = ret;
682 }else {
683 V_VT(res) = VT_NULL;
685 return S_OK;
688 static const NodeImplVtbl HTMLFormElementImplVtbl = {
689 HTMLFormElement_QI,
690 HTMLElement_destructor,
691 HTMLElement_cpc,
692 HTMLElement_clone,
693 HTMLElement_handle_event,
694 HTMLElement_get_attr_col,
695 NULL,
696 NULL,
697 NULL,
698 NULL,
699 NULL,
700 NULL,
701 HTMLFormElement_get_dispid,
702 HTMLFormElement_invoke
705 static const tid_t HTMLFormElement_iface_tids[] = {
706 HTMLELEMENT_TIDS,
707 IHTMLFormElement_tid,
711 static dispex_static_data_t HTMLFormElement_dispex = {
712 NULL,
713 DispHTMLFormElement_tid,
714 NULL,
715 HTMLFormElement_iface_tids
718 HRESULT HTMLFormElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
720 HTMLFormElement *ret;
721 nsresult nsres;
723 ret = heap_alloc_zero(sizeof(HTMLFormElement));
724 if(!ret)
725 return E_OUTOFMEMORY;
727 ret->IHTMLFormElement_iface.lpVtbl = &HTMLFormElementVtbl;
728 ret->element.node.vtbl = &HTMLFormElementImplVtbl;
730 HTMLElement_Init(&ret->element, doc, nselem, &HTMLFormElement_dispex);
732 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLFormElement, (void**)&ret->nsform);
734 /* Share the reference with nsnode */
735 assert(nsres == NS_OK && (nsIDOMNode*)ret->nsform == ret->element.node.nsnode);
736 nsIDOMNode_Release(ret->element.node.nsnode);
738 *elem = &ret->element;
739 return S_OK;