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
28 #include "wine/debug.h"
30 #include "mshtml_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
34 struct HTMLFormElement {
37 const IHTMLFormElementVtbl *lpHTMLFormElementVtbl;
39 nsIDOMHTMLFormElement *nsform;
42 #define HTMLFORM(x) (&(x)->lpHTMLFormElementVtbl)
44 static HRESULT htmlform_item(HTMLFormElement *This, int i, IDispatch **ret)
46 nsIDOMHTMLCollection *elements;
52 nsres = nsIDOMHTMLFormElement_GetElements(This->nsform, &elements);
53 if(NS_FAILED(nsres)) {
54 FIXME("GetElements failed: 0x%08x\n", nsres);
58 nsres = nsIDOMHTMLCollection_Item(elements, i, &item);
59 nsIDOMHTMLCollection_Release(elements);
60 if(NS_FAILED(nsres)) {
61 FIXME("Item failed: 0x%08x\n", nsres);
66 hres = get_node(This->element.node.doc, item, TRUE, &node);
70 IHTMLDOMNode_AddRef(&node->IHTMLDOMNode_iface);
71 nsIDOMNode_Release(item);
72 *ret = (IDispatch*)&node->IHTMLDOMNode_iface;
80 #define HTMLFORM_THIS(iface) DEFINE_THIS(HTMLFormElement, HTMLFormElement, iface)
82 static HRESULT WINAPI HTMLFormElement_QueryInterface(IHTMLFormElement *iface,
83 REFIID riid, void **ppv)
85 HTMLFormElement *This = HTMLFORM_THIS(iface);
87 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
90 static ULONG WINAPI HTMLFormElement_AddRef(IHTMLFormElement *iface)
92 HTMLFormElement *This = HTMLFORM_THIS(iface);
94 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
97 static ULONG WINAPI HTMLFormElement_Release(IHTMLFormElement *iface)
99 HTMLFormElement *This = HTMLFORM_THIS(iface);
101 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
104 static HRESULT WINAPI HTMLFormElement_GetTypeInfoCount(IHTMLFormElement *iface, UINT *pctinfo)
106 HTMLFormElement *This = HTMLFORM_THIS(iface);
107 return IDispatchEx_GetTypeInfoCount(&This->element.node.dispex.IDispatchEx_iface, pctinfo);
110 static HRESULT WINAPI HTMLFormElement_GetTypeInfo(IHTMLFormElement *iface, UINT iTInfo,
111 LCID lcid, ITypeInfo **ppTInfo)
113 HTMLFormElement *This = HTMLFORM_THIS(iface);
114 return IDispatchEx_GetTypeInfo(&This->element.node.dispex.IDispatchEx_iface, iTInfo, lcid,
118 static HRESULT WINAPI HTMLFormElement_GetIDsOfNames(IHTMLFormElement *iface, REFIID riid,
119 LPOLESTR *rgszNames, UINT cNames,
120 LCID lcid, DISPID *rgDispId)
122 HTMLFormElement *This = HTMLFORM_THIS(iface);
123 return IDispatchEx_GetIDsOfNames(&This->element.node.dispex.IDispatchEx_iface, riid, rgszNames,
124 cNames, lcid, rgDispId);
127 static HRESULT WINAPI HTMLFormElement_Invoke(IHTMLFormElement *iface, DISPID dispIdMember,
128 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
129 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
131 HTMLFormElement *This = HTMLFORM_THIS(iface);
132 return IDispatchEx_Invoke(&This->element.node.dispex.IDispatchEx_iface, dispIdMember, riid,
133 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
136 static HRESULT WINAPI HTMLFormElement_put_action(IHTMLFormElement *iface, BSTR v)
138 HTMLFormElement *This = HTMLFORM_THIS(iface);
139 nsAString action_str;
142 TRACE("(%p)->(%s)\n", This, wine_dbgstr_w(v));
144 nsAString_InitDepend(&action_str, v);
145 nsres = nsIDOMHTMLFormElement_SetAction(This->nsform, &action_str);
146 nsAString_Finish(&action_str);
147 if(NS_FAILED(nsres)) {
148 ERR("SetAction failed: %08x\n", nsres);
155 static HRESULT WINAPI HTMLFormElement_get_action(IHTMLFormElement *iface, BSTR *p)
157 HTMLFormElement *This = HTMLFORM_THIS(iface);
158 nsAString action_str;
162 TRACE("(%p)->(%p)\n", This, p);
164 nsAString_Init(&action_str, NULL);
165 nsres = nsIDOMHTMLFormElement_GetAction(This->nsform, &action_str);
166 if(NS_SUCCEEDED(nsres)) {
167 const PRUnichar *action;
168 nsAString_GetData(&action_str, &action);
169 hres = nsuri_to_url(action, FALSE, p);
171 ERR("GetAction failed: %08x\n", nsres);
178 static HRESULT WINAPI HTMLFormElement_put_dir(IHTMLFormElement *iface, BSTR v)
180 HTMLFormElement *This = HTMLFORM_THIS(iface);
181 FIXME("(%p)->(%s)\n", This, wine_dbgstr_w(v));
185 static HRESULT WINAPI HTMLFormElement_get_dir(IHTMLFormElement *iface, BSTR *p)
187 HTMLFormElement *This = HTMLFORM_THIS(iface);
188 FIXME("(%p)->(%p)\n", This, p);
192 static HRESULT WINAPI HTMLFormElement_put_encoding(IHTMLFormElement *iface, BSTR v)
194 static const WCHAR urlencodedW[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
195 'x','-','w','w','w','-','f','o','r','m','-','u','r','l','e','n','c','o','d','e','d',0};
196 static const WCHAR dataW[] = {'m','u','l','t','i','p','a','r','t','/',
197 'f','o','r','m','-','d','a','t','a',0};
198 static const WCHAR plainW[] = {'t','e','x','t','/','p','l','a','i','n',0};
200 HTMLFormElement *This = HTMLFORM_THIS(iface);
201 nsAString encoding_str;
204 TRACE("(%p)->(%s)\n", This, wine_dbgstr_w(v));
206 if(lstrcmpiW(v, urlencodedW) && lstrcmpiW(v, dataW) && lstrcmpiW(v, plainW)) {
207 WARN("incorrect enctype\n");
211 nsAString_InitDepend(&encoding_str, v);
212 nsres = nsIDOMHTMLFormElement_SetEnctype(This->nsform, &encoding_str);
213 nsAString_Finish(&encoding_str);
220 static HRESULT WINAPI HTMLFormElement_get_encoding(IHTMLFormElement *iface, BSTR *p)
222 HTMLFormElement *This = HTMLFORM_THIS(iface);
223 nsAString encoding_str;
226 TRACE("(%p)->(%p)\n", This, p);
228 nsAString_Init(&encoding_str, NULL);
229 nsres = nsIDOMHTMLFormElement_GetEnctype(This->nsform, &encoding_str);
230 if(NS_SUCCEEDED(nsres)) {
231 const PRUnichar *encoding;
232 nsAString_GetData(&encoding_str, &encoding);
234 *p = SysAllocString(encoding);
236 return E_OUTOFMEMORY;
243 static HRESULT WINAPI HTMLFormElement_put_method(IHTMLFormElement *iface, BSTR v)
245 static const WCHAR postW[] = {'P','O','S','T',0};
246 static const WCHAR getW[] = {'G','E','T',0};
248 HTMLFormElement *This = HTMLFORM_THIS(iface);
249 nsAString method_str;
252 TRACE("(%p)->(%s)\n", This, wine_dbgstr_w(v));
254 if(lstrcmpiW(v, postW) && lstrcmpiW(v, getW)) {
255 WARN("unrecognized method\n");
259 nsAString_InitDepend(&method_str, v);
260 nsres = nsIDOMHTMLFormElement_SetMethod(This->nsform, &method_str);
261 nsAString_Finish(&method_str);
268 static HRESULT WINAPI HTMLFormElement_get_method(IHTMLFormElement *iface, BSTR *p)
270 HTMLFormElement *This = HTMLFORM_THIS(iface);
271 nsAString method_str;
274 TRACE("(%p)->(%p)\n", This, p);
276 nsAString_Init(&method_str, NULL);
277 nsres = nsIDOMHTMLFormElement_GetMethod(This->nsform, &method_str);
278 if(NS_SUCCEEDED(nsres)) {
279 const PRUnichar *method;
280 nsAString_GetData(&method_str, &method);
282 *p = SysAllocString(method);
284 return E_OUTOFMEMORY;
291 static HRESULT WINAPI HTMLFormElement_get_elements(IHTMLFormElement *iface, IDispatch **p)
293 HTMLFormElement *This = HTMLFORM_THIS(iface);
294 FIXME("(%p)->(%p)\n", This, p);
298 static HRESULT WINAPI HTMLFormElement_put_target(IHTMLFormElement *iface, BSTR v)
300 HTMLFormElement *This = HTMLFORM_THIS(iface);
301 FIXME("(%p)->(%s)\n", This, wine_dbgstr_w(v));
305 static HRESULT WINAPI HTMLFormElement_get_target(IHTMLFormElement *iface, BSTR *p)
307 HTMLFormElement *This = HTMLFORM_THIS(iface);
308 FIXME("(%p)->(%p)\n", This, p);
312 static HRESULT WINAPI HTMLFormElement_put_name(IHTMLFormElement *iface, BSTR v)
314 HTMLFormElement *This = HTMLFORM_THIS(iface);
318 TRACE("(%p)->(%s)\n", This, wine_dbgstr_w(v));
320 nsAString_InitDepend(&name_str, v);
321 nsres = nsIDOMHTMLFormElement_SetName(This->nsform, &name_str);
322 nsAString_Finish(&name_str);
329 static HRESULT WINAPI HTMLFormElement_get_name(IHTMLFormElement *iface, BSTR *p)
331 HTMLFormElement *This = HTMLFORM_THIS(iface);
335 TRACE("(%p)->(%p)\n", This, p);
337 nsAString_Init(&name_str, NULL);
338 nsres = nsIDOMHTMLFormElement_GetName(This->nsform, &name_str);
339 if(NS_SUCCEEDED(nsres)) {
340 const PRUnichar *name;
341 nsAString_GetData(&name_str, &name);
344 *p = SysAllocString(name);
346 return E_OUTOFMEMORY;
355 static HRESULT WINAPI HTMLFormElement_put_onsubmit(IHTMLFormElement *iface, VARIANT v)
357 HTMLFormElement *This = HTMLFORM_THIS(iface);
358 FIXME("(%p)->(v)\n", This);
362 static HRESULT WINAPI HTMLFormElement_get_onsubmit(IHTMLFormElement *iface, VARIANT *p)
364 HTMLFormElement *This = HTMLFORM_THIS(iface);
365 FIXME("(%p)->(%p)\n", This, p);
369 static HRESULT WINAPI HTMLFormElement_put_onreset(IHTMLFormElement *iface, VARIANT v)
371 HTMLFormElement *This = HTMLFORM_THIS(iface);
372 FIXME("(%p)->(v)\n", This);
376 static HRESULT WINAPI HTMLFormElement_get_onreset(IHTMLFormElement *iface, VARIANT *p)
378 HTMLFormElement *This = HTMLFORM_THIS(iface);
379 FIXME("(%p)->(%p)\n", This, p);
383 static HRESULT WINAPI HTMLFormElement_submit(IHTMLFormElement *iface)
385 HTMLFormElement *This = HTMLFORM_THIS(iface);
386 FIXME("(%p)->()\n", This);
390 static HRESULT WINAPI HTMLFormElement_reset(IHTMLFormElement *iface)
392 HTMLFormElement *This = HTMLFORM_THIS(iface);
393 FIXME("(%p)->()\n", This);
397 static HRESULT WINAPI HTMLFormElement_put_length(IHTMLFormElement *iface, LONG v)
399 HTMLFormElement *This = HTMLFORM_THIS(iface);
400 FIXME("(%p)->(%d)\n", This, v);
404 static HRESULT WINAPI HTMLFormElement_get_length(IHTMLFormElement *iface, LONG *p)
406 HTMLFormElement *This = HTMLFORM_THIS(iface);
410 TRACE("(%p)->(%p)\n", This, p);
412 nsres = nsIDOMHTMLFormElement_GetLength(This->nsform, &length);
413 if(NS_FAILED(nsres)) {
414 ERR("GetLength failed: %08x\n", nsres);
422 static HRESULT WINAPI HTMLFormElement__newEnum(IHTMLFormElement *iface, IUnknown **p)
424 HTMLFormElement *This = HTMLFORM_THIS(iface);
425 FIXME("(%p)->(%p)\n", This, p);
429 static HRESULT WINAPI HTMLFormElement_item(IHTMLFormElement *iface, VARIANT name,
430 VARIANT index, IDispatch **pdisp)
432 HTMLFormElement *This = HTMLFORM_THIS(iface);
434 TRACE("(%p)->(%s %s %p)\n", This, debugstr_variant(&name), debugstr_variant(&index), pdisp);
440 if(V_VT(&name) == VT_I4) {
443 return htmlform_item(This, V_I4(&name), pdisp);
446 FIXME("Unsupported args\n");
450 static HRESULT WINAPI HTMLFormElement_tags(IHTMLFormElement *iface, VARIANT tagName,
453 HTMLFormElement *This = HTMLFORM_THIS(iface);
454 FIXME("(%p)->(v %p)\n", This, pdisp);
460 static const IHTMLFormElementVtbl HTMLFormElementVtbl = {
461 HTMLFormElement_QueryInterface,
462 HTMLFormElement_AddRef,
463 HTMLFormElement_Release,
464 HTMLFormElement_GetTypeInfoCount,
465 HTMLFormElement_GetTypeInfo,
466 HTMLFormElement_GetIDsOfNames,
467 HTMLFormElement_Invoke,
468 HTMLFormElement_put_action,
469 HTMLFormElement_get_action,
470 HTMLFormElement_put_dir,
471 HTMLFormElement_get_dir,
472 HTMLFormElement_put_encoding,
473 HTMLFormElement_get_encoding,
474 HTMLFormElement_put_method,
475 HTMLFormElement_get_method,
476 HTMLFormElement_get_elements,
477 HTMLFormElement_put_target,
478 HTMLFormElement_get_target,
479 HTMLFormElement_put_name,
480 HTMLFormElement_get_name,
481 HTMLFormElement_put_onsubmit,
482 HTMLFormElement_get_onsubmit,
483 HTMLFormElement_put_onreset,
484 HTMLFormElement_get_onreset,
485 HTMLFormElement_submit,
486 HTMLFormElement_reset,
487 HTMLFormElement_put_length,
488 HTMLFormElement_get_length,
489 HTMLFormElement__newEnum,
490 HTMLFormElement_item,
494 static inline HTMLFormElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
496 return CONTAINING_RECORD(iface, HTMLFormElement, element.node);
499 static HRESULT HTMLFormElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
501 HTMLFormElement *This = impl_from_HTMLDOMNode(iface);
505 if(IsEqualGUID(&IID_IUnknown, riid)) {
506 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
507 *ppv = HTMLFORM(This);
508 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
509 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
510 *ppv = HTMLFORM(This);
511 }else if(IsEqualGUID(&IID_IHTMLFormElement, riid)) {
512 TRACE("(%p)->(IID_IHTMLFormElement %p)\n", This, ppv);
513 *ppv = HTMLFORM(This);
517 IUnknown_AddRef((IUnknown*)*ppv);
521 return HTMLElement_QI(&This->element.node, riid, ppv);
524 static void HTMLFormElement_destructor(HTMLDOMNode *iface)
526 HTMLFormElement *This = impl_from_HTMLDOMNode(iface);
529 nsIDOMHTMLFormElement_Release(This->nsform);
531 HTMLElement_destructor(&This->element.node);
534 static HRESULT HTMLFormElement_get_dispid(HTMLDOMNode *iface,
535 BSTR name, DWORD grfdex, DISPID *pid)
537 HTMLFormElement *This = impl_from_HTMLDOMNode(iface);
538 nsIDOMHTMLCollection *elements;
539 nsAString nsname, nsstr;
542 HRESULT hres = DISP_E_UNKNOWNNAME;
544 static const PRUnichar nameW[] = {'n','a','m','e',0};
546 TRACE("(%p)->(%s %x %p)\n", This, wine_dbgstr_w(name), grfdex, pid);
548 nsres = nsIDOMHTMLFormElement_GetElements(This->nsform, &elements);
549 if(NS_FAILED(nsres)) {
550 FIXME("GetElements failed: 0x%08x\n", nsres);
554 nsres = nsIDOMHTMLCollection_GetLength(elements, &len);
555 if(NS_FAILED(nsres)) {
556 FIXME("GetLength failed: 0x%08x\n", nsres);
557 nsIDOMHTMLCollection_Release(elements);
561 nsAString_InitDepend(&nsname, nameW);
562 nsAString_Init(&nsstr, NULL);
563 for(i = 0; i < len; ++i) {
565 nsIDOMHTMLElement *nshtml_elem;
566 const PRUnichar *str;
568 nsres = nsIDOMHTMLCollection_Item(elements, i, &nsitem);
569 if(NS_FAILED(nsres)) {
570 FIXME("Item failed: 0x%08x\n", nsres);
575 nsres = nsIDOMNode_QueryInterface(nsitem, &IID_nsIDOMHTMLElement, (void**)&nshtml_elem);
576 nsIDOMNode_Release(nsitem);
577 if(NS_FAILED(nsres)) {
578 FIXME("Failed to get nsIDOMHTMLNode interface: 0x%08x\n", nsres);
583 /* compare by id attr */
584 nsres = nsIDOMHTMLElement_GetId(nshtml_elem, &nsstr);
585 if(NS_FAILED(nsres)) {
586 FIXME("GetId failed: 0x%08x\n", nsres);
587 nsIDOMHTMLElement_Release(nshtml_elem);
591 nsAString_GetData(&nsstr, &str);
592 if(!strcmpiW(str, name)) {
593 nsIDOMHTMLElement_Release(nshtml_elem);
594 /* FIXME: using index for dispid */
595 *pid = MSHTML_DISPID_CUSTOM_MIN + i;
600 /* compare by name attr */
601 nsres = nsIDOMHTMLElement_GetAttribute(nshtml_elem, &nsname, &nsstr);
602 nsIDOMHTMLElement_Release(nshtml_elem);
603 nsAString_GetData(&nsstr, &str);
604 if(!strcmpiW(str, name)) {
605 /* FIXME: using index for dispid */
606 *pid = MSHTML_DISPID_CUSTOM_MIN + i;
611 nsAString_Finish(&nsname);
612 nsAString_Finish(&nsstr);
614 nsIDOMHTMLCollection_Release(elements);
619 static HRESULT HTMLFormElement_invoke(HTMLDOMNode *iface,
620 DISPID id, LCID lcid, WORD flags, DISPPARAMS *params, VARIANT *res,
621 EXCEPINFO *ei, IServiceProvider *caller)
623 HTMLFormElement *This = impl_from_HTMLDOMNode(iface);
627 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
629 hres = htmlform_item(This, id - MSHTML_DISPID_CUSTOM_MIN, &ret);
634 V_VT(res) = VT_DISPATCH;
635 V_DISPATCH(res) = ret;
642 static const NodeImplVtbl HTMLFormElementImplVtbl = {
644 HTMLFormElement_destructor,
652 HTMLFormElement_get_dispid,
653 HTMLFormElement_invoke
656 static const tid_t HTMLFormElement_iface_tids[] = {
658 IHTMLFormElement_tid,
662 static dispex_static_data_t HTMLFormElement_dispex = {
664 DispHTMLFormElement_tid,
666 HTMLFormElement_iface_tids
669 HRESULT HTMLFormElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
671 HTMLFormElement *ret;
674 ret = heap_alloc_zero(sizeof(HTMLFormElement));
676 return E_OUTOFMEMORY;
678 ret->lpHTMLFormElementVtbl = &HTMLFormElementVtbl;
679 ret->element.node.vtbl = &HTMLFormElementImplVtbl;
681 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLFormElement, (void**)&ret->nsform);
682 if(NS_FAILED(nsres)) {
683 ERR("Could not get nsIDOMHTMLFormElement interface: %08x\n", nsres);
688 HTMLElement_Init(&ret->element, doc, nselem, &HTMLFormElement_dispex);
690 *elem = &ret->element;