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;
51 nsres = nsIDOMHTMLFormElement_GetElements(This->nsform, &elements);
52 if(NS_FAILED(nsres)) {
53 FIXME("GetElements failed: 0x%08x\n", nsres);
57 nsres = nsIDOMHTMLCollection_Item(elements, i, &item);
58 nsIDOMHTMLCollection_Release(elements);
59 if(NS_FAILED(nsres)) {
60 FIXME("Item failed: 0x%08x\n", nsres);
65 node = get_node(This->element.node.doc, item, TRUE);
69 IHTMLDOMNode_AddRef(HTMLDOMNODE(node));
70 nsIDOMNode_Release(item);
71 *ret = (IDispatch*)HTMLDOMNODE(node);
79 #define HTMLFORM_THIS(iface) DEFINE_THIS(HTMLFormElement, HTMLFormElement, iface)
81 static HRESULT WINAPI HTMLFormElement_QueryInterface(IHTMLFormElement *iface,
82 REFIID riid, void **ppv)
84 HTMLFormElement *This = HTMLFORM_THIS(iface);
86 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(&This->element.node), riid, ppv);
89 static ULONG WINAPI HTMLFormElement_AddRef(IHTMLFormElement *iface)
91 HTMLFormElement *This = HTMLFORM_THIS(iface);
93 return IHTMLDOMNode_AddRef(HTMLDOMNODE(&This->element.node));
96 static ULONG WINAPI HTMLFormElement_Release(IHTMLFormElement *iface)
98 HTMLFormElement *This = HTMLFORM_THIS(iface);
100 return IHTMLDOMNode_Release(HTMLDOMNODE(&This->element.node));
103 static HRESULT WINAPI HTMLFormElement_GetTypeInfoCount(IHTMLFormElement *iface, UINT *pctinfo)
105 HTMLFormElement *This = HTMLFORM_THIS(iface);
106 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->element.node.dispex), pctinfo);
109 static HRESULT WINAPI HTMLFormElement_GetTypeInfo(IHTMLFormElement *iface, UINT iTInfo,
110 LCID lcid, ITypeInfo **ppTInfo)
112 HTMLFormElement *This = HTMLFORM_THIS(iface);
113 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->element.node.dispex), iTInfo, lcid, ppTInfo);
116 static HRESULT WINAPI HTMLFormElement_GetIDsOfNames(IHTMLFormElement *iface, REFIID riid,
117 LPOLESTR *rgszNames, UINT cNames,
118 LCID lcid, DISPID *rgDispId)
120 HTMLFormElement *This = HTMLFORM_THIS(iface);
121 return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->element.node.dispex), riid, rgszNames, cNames, lcid, rgDispId);
124 static HRESULT WINAPI HTMLFormElement_Invoke(IHTMLFormElement *iface, DISPID dispIdMember,
125 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
126 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
128 HTMLFormElement *This = HTMLFORM_THIS(iface);
129 return IDispatchEx_Invoke(DISPATCHEX(&This->element.node.dispex), dispIdMember, riid, lcid, wFlags, pDispParams,
130 pVarResult, pExcepInfo, puArgErr);
133 static HRESULT WINAPI HTMLFormElement_put_action(IHTMLFormElement *iface, BSTR v)
135 HTMLFormElement *This = HTMLFORM_THIS(iface);
136 nsAString action_str;
139 TRACE("(%p)->(%s)\n", This, wine_dbgstr_w(v));
141 nsAString_InitDepend(&action_str, v);
142 nsres = nsIDOMHTMLFormElement_SetAction(This->nsform, &action_str);
143 nsAString_Finish(&action_str);
144 if(NS_FAILED(nsres)) {
145 ERR("SetAction failed: %08x\n", nsres);
152 static HRESULT WINAPI HTMLFormElement_get_action(IHTMLFormElement *iface, BSTR *p)
154 HTMLFormElement *This = HTMLFORM_THIS(iface);
155 nsAString action_str;
159 TRACE("(%p)->(%p)\n", This, p);
161 nsAString_Init(&action_str, NULL);
162 nsres = nsIDOMHTMLFormElement_GetAction(This->nsform, &action_str);
163 if(NS_SUCCEEDED(nsres)) {
164 const PRUnichar *action;
165 nsAString_GetData(&action_str, &action);
166 hres = nsuri_to_url(action, FALSE, p);
168 ERR("GetAction failed: %08x\n", nsres);
175 static HRESULT WINAPI HTMLFormElement_put_dir(IHTMLFormElement *iface, BSTR v)
177 HTMLFormElement *This = HTMLFORM_THIS(iface);
178 FIXME("(%p)->(%s)\n", This, wine_dbgstr_w(v));
182 static HRESULT WINAPI HTMLFormElement_get_dir(IHTMLFormElement *iface, BSTR *p)
184 HTMLFormElement *This = HTMLFORM_THIS(iface);
185 FIXME("(%p)->(%p)\n", This, p);
189 static HRESULT WINAPI HTMLFormElement_put_encoding(IHTMLFormElement *iface, BSTR v)
191 static const WCHAR urlencodedW[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
192 'x','-','w','w','w','-','f','o','r','m','-','u','r','l','e','n','c','o','d','e','d',0};
193 static const WCHAR dataW[] = {'m','u','l','t','i','p','a','r','t','/',
194 'f','o','r','m','-','d','a','t','a',0};
195 static const WCHAR plainW[] = {'t','e','x','t','/','p','l','a','i','n',0};
197 HTMLFormElement *This = HTMLFORM_THIS(iface);
198 nsAString encoding_str;
201 TRACE("(%p)->(%s)\n", This, wine_dbgstr_w(v));
203 if(lstrcmpiW(v, urlencodedW) && lstrcmpiW(v, dataW) && lstrcmpiW(v, plainW)) {
204 WARN("incorrect enctype\n");
208 nsAString_InitDepend(&encoding_str, v);
209 nsres = nsIDOMHTMLFormElement_SetEnctype(This->nsform, &encoding_str);
210 nsAString_Finish(&encoding_str);
217 static HRESULT WINAPI HTMLFormElement_get_encoding(IHTMLFormElement *iface, BSTR *p)
219 HTMLFormElement *This = HTMLFORM_THIS(iface);
220 nsAString encoding_str;
223 TRACE("(%p)->(%p)\n", This, p);
225 nsAString_Init(&encoding_str, NULL);
226 nsres = nsIDOMHTMLFormElement_GetEnctype(This->nsform, &encoding_str);
227 if(NS_SUCCEEDED(nsres)) {
228 const PRUnichar *encoding;
229 nsAString_GetData(&encoding_str, &encoding);
231 *p = SysAllocString(encoding);
233 return E_OUTOFMEMORY;
240 static HRESULT WINAPI HTMLFormElement_put_method(IHTMLFormElement *iface, BSTR v)
242 static const WCHAR postW[] = {'P','O','S','T',0};
243 static const WCHAR getW[] = {'G','E','T',0};
245 HTMLFormElement *This = HTMLFORM_THIS(iface);
246 nsAString method_str;
249 TRACE("(%p)->(%s)\n", This, wine_dbgstr_w(v));
251 if(lstrcmpiW(v, postW) && lstrcmpiW(v, getW)) {
252 WARN("unrecognized method\n");
256 nsAString_InitDepend(&method_str, v);
257 nsres = nsIDOMHTMLFormElement_SetMethod(This->nsform, &method_str);
258 nsAString_Finish(&method_str);
265 static HRESULT WINAPI HTMLFormElement_get_method(IHTMLFormElement *iface, BSTR *p)
267 HTMLFormElement *This = HTMLFORM_THIS(iface);
268 nsAString method_str;
271 TRACE("(%p)->(%p)\n", This, p);
273 nsAString_Init(&method_str, NULL);
274 nsres = nsIDOMHTMLFormElement_GetMethod(This->nsform, &method_str);
275 if(NS_SUCCEEDED(nsres)) {
276 const PRUnichar *method;
277 nsAString_GetData(&method_str, &method);
279 *p = SysAllocString(method);
281 return E_OUTOFMEMORY;
288 static HRESULT WINAPI HTMLFormElement_get_elements(IHTMLFormElement *iface, IDispatch **p)
290 HTMLFormElement *This = HTMLFORM_THIS(iface);
291 FIXME("(%p)->(%p)\n", This, p);
295 static HRESULT WINAPI HTMLFormElement_put_target(IHTMLFormElement *iface, BSTR v)
297 HTMLFormElement *This = HTMLFORM_THIS(iface);
298 FIXME("(%p)->(%s)\n", This, wine_dbgstr_w(v));
302 static HRESULT WINAPI HTMLFormElement_get_target(IHTMLFormElement *iface, BSTR *p)
304 HTMLFormElement *This = HTMLFORM_THIS(iface);
305 FIXME("(%p)->(%p)\n", This, p);
309 static HRESULT WINAPI HTMLFormElement_put_name(IHTMLFormElement *iface, BSTR v)
311 HTMLFormElement *This = HTMLFORM_THIS(iface);
315 TRACE("(%p)->(%s)\n", This, wine_dbgstr_w(v));
317 nsAString_InitDepend(&name_str, v);
318 nsres = nsIDOMHTMLFormElement_SetName(This->nsform, &name_str);
319 nsAString_Finish(&name_str);
326 static HRESULT WINAPI HTMLFormElement_get_name(IHTMLFormElement *iface, BSTR *p)
328 HTMLFormElement *This = HTMLFORM_THIS(iface);
332 TRACE("(%p)->(%p)\n", This, p);
334 nsAString_Init(&name_str, NULL);
335 nsres = nsIDOMHTMLFormElement_GetName(This->nsform, &name_str);
336 if(NS_SUCCEEDED(nsres)) {
337 const PRUnichar *name;
338 nsAString_GetData(&name_str, &name);
341 *p = SysAllocString(name);
343 return E_OUTOFMEMORY;
352 static HRESULT WINAPI HTMLFormElement_put_onsubmit(IHTMLFormElement *iface, VARIANT v)
354 HTMLFormElement *This = HTMLFORM_THIS(iface);
355 FIXME("(%p)->(v)\n", This);
359 static HRESULT WINAPI HTMLFormElement_get_onsubmit(IHTMLFormElement *iface, VARIANT *p)
361 HTMLFormElement *This = HTMLFORM_THIS(iface);
362 FIXME("(%p)->(%p)\n", This, p);
366 static HRESULT WINAPI HTMLFormElement_put_onreset(IHTMLFormElement *iface, VARIANT v)
368 HTMLFormElement *This = HTMLFORM_THIS(iface);
369 FIXME("(%p)->(v)\n", This);
373 static HRESULT WINAPI HTMLFormElement_get_onreset(IHTMLFormElement *iface, VARIANT *p)
375 HTMLFormElement *This = HTMLFORM_THIS(iface);
376 FIXME("(%p)->(%p)\n", This, p);
380 static HRESULT WINAPI HTMLFormElement_submit(IHTMLFormElement *iface)
382 HTMLFormElement *This = HTMLFORM_THIS(iface);
383 FIXME("(%p)->()\n", This);
387 static HRESULT WINAPI HTMLFormElement_reset(IHTMLFormElement *iface)
389 HTMLFormElement *This = HTMLFORM_THIS(iface);
390 FIXME("(%p)->()\n", This);
394 static HRESULT WINAPI HTMLFormElement_put_length(IHTMLFormElement *iface, LONG v)
396 HTMLFormElement *This = HTMLFORM_THIS(iface);
397 FIXME("(%p)->(%d)\n", This, v);
401 static HRESULT WINAPI HTMLFormElement_get_length(IHTMLFormElement *iface, LONG *p)
403 HTMLFormElement *This = HTMLFORM_THIS(iface);
407 TRACE("(%p)->(%p)\n", This, p);
409 nsres = nsIDOMHTMLFormElement_GetLength(This->nsform, &length);
410 if(NS_FAILED(nsres)) {
411 ERR("GetLength failed: %08x\n", nsres);
419 static HRESULT WINAPI HTMLFormElement__newEnum(IHTMLFormElement *iface, IUnknown **p)
421 HTMLFormElement *This = HTMLFORM_THIS(iface);
422 FIXME("(%p)->(%p)\n", This, p);
426 static HRESULT WINAPI HTMLFormElement_item(IHTMLFormElement *iface, VARIANT name,
427 VARIANT index, IDispatch **pdisp)
429 HTMLFormElement *This = HTMLFORM_THIS(iface);
431 TRACE("(%p)->(%s %s %p)\n", This, debugstr_variant(&name), debugstr_variant(&index), pdisp);
437 if(V_VT(&name) == VT_I4) {
440 return htmlform_item(This, V_I4(&name), pdisp);
443 FIXME("Unsupported args\n");
447 static HRESULT WINAPI HTMLFormElement_tags(IHTMLFormElement *iface, VARIANT tagName,
450 HTMLFormElement *This = HTMLFORM_THIS(iface);
451 FIXME("(%p)->(v %p)\n", This, pdisp);
457 static const IHTMLFormElementVtbl HTMLFormElementVtbl = {
458 HTMLFormElement_QueryInterface,
459 HTMLFormElement_AddRef,
460 HTMLFormElement_Release,
461 HTMLFormElement_GetTypeInfoCount,
462 HTMLFormElement_GetTypeInfo,
463 HTMLFormElement_GetIDsOfNames,
464 HTMLFormElement_Invoke,
465 HTMLFormElement_put_action,
466 HTMLFormElement_get_action,
467 HTMLFormElement_put_dir,
468 HTMLFormElement_get_dir,
469 HTMLFormElement_put_encoding,
470 HTMLFormElement_get_encoding,
471 HTMLFormElement_put_method,
472 HTMLFormElement_get_method,
473 HTMLFormElement_get_elements,
474 HTMLFormElement_put_target,
475 HTMLFormElement_get_target,
476 HTMLFormElement_put_name,
477 HTMLFormElement_get_name,
478 HTMLFormElement_put_onsubmit,
479 HTMLFormElement_get_onsubmit,
480 HTMLFormElement_put_onreset,
481 HTMLFormElement_get_onreset,
482 HTMLFormElement_submit,
483 HTMLFormElement_reset,
484 HTMLFormElement_put_length,
485 HTMLFormElement_get_length,
486 HTMLFormElement__newEnum,
487 HTMLFormElement_item,
491 #define HTMLFORM_NODE_THIS(iface) DEFINE_THIS2(HTMLFormElement, element.node, iface)
493 static HRESULT HTMLFormElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
495 HTMLFormElement *This = HTMLFORM_NODE_THIS(iface);
499 if(IsEqualGUID(&IID_IUnknown, riid)) {
500 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
501 *ppv = HTMLFORM(This);
502 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
503 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
504 *ppv = HTMLFORM(This);
505 }else if(IsEqualGUID(&IID_IHTMLFormElement, riid)) {
506 TRACE("(%p)->(IID_IHTMLFormElement %p)\n", This, ppv);
507 *ppv = HTMLFORM(This);
511 IUnknown_AddRef((IUnknown*)*ppv);
515 return HTMLElement_QI(&This->element.node, riid, ppv);
518 static void HTMLFormElement_destructor(HTMLDOMNode *iface)
520 HTMLFormElement *This = HTMLFORM_NODE_THIS(iface);
523 nsIDOMHTMLFormElement_Release(This->nsform);
525 HTMLElement_destructor(&This->element.node);
528 static HRESULT HTMLFormElement_get_dispid(HTMLDOMNode *iface,
529 BSTR name, DWORD grfdex, DISPID *pid)
531 HTMLFormElement *This = HTMLFORM_NODE_THIS(iface);
532 nsIDOMHTMLCollection *elements;
533 nsAString nsname, nsstr;
536 HRESULT hres = DISP_E_UNKNOWNNAME;
538 static const PRUnichar nameW[] = {'n','a','m','e',0};
540 TRACE("(%p)->(%s %x %p)\n", This, wine_dbgstr_w(name), grfdex, pid);
542 nsres = nsIDOMHTMLFormElement_GetElements(This->nsform, &elements);
543 if(NS_FAILED(nsres)) {
544 FIXME("GetElements failed: 0x%08x\n", nsres);
548 nsres = nsIDOMHTMLCollection_GetLength(elements, &len);
549 if(NS_FAILED(nsres)) {
550 FIXME("GetLength failed: 0x%08x\n", nsres);
551 nsIDOMHTMLCollection_Release(elements);
555 nsAString_InitDepend(&nsname, nameW);
556 nsAString_Init(&nsstr, NULL);
557 for(i = 0; i < len; ++i) {
559 nsIDOMHTMLElement *nshtml_elem;
560 const PRUnichar *str;
562 nsres = nsIDOMHTMLCollection_Item(elements, i, &nsitem);
563 if(NS_FAILED(nsres)) {
564 FIXME("Item failed: 0x%08x\n", nsres);
569 nsres = nsIDOMNode_QueryInterface(nsitem, &IID_nsIDOMHTMLElement, (void**)&nshtml_elem);
570 nsIDOMNode_Release(nsitem);
571 if(NS_FAILED(nsres)) {
572 FIXME("Failed to get nsIDOMHTMLNode interface: 0x%08x\n", nsres);
577 /* compare by id attr */
578 nsres = nsIDOMHTMLElement_GetId(nshtml_elem, &nsstr);
579 if(NS_FAILED(nsres)) {
580 FIXME("GetId failed: 0x%08x\n", nsres);
581 nsIDOMHTMLElement_Release(nshtml_elem);
585 nsAString_GetData(&nsstr, &str);
586 if(!strcmpiW(str, name)) {
587 nsIDOMHTMLElement_Release(nshtml_elem);
588 /* FIXME: using index for dispid */
589 *pid = MSHTML_DISPID_CUSTOM_MIN + i;
594 /* compare by name attr */
595 nsres = nsIDOMHTMLElement_GetAttribute(nshtml_elem, &nsname, &nsstr);
596 nsIDOMHTMLElement_Release(nshtml_elem);
597 nsAString_GetData(&nsstr, &str);
598 if(!strcmpiW(str, name)) {
599 /* FIXME: using index for dispid */
600 *pid = MSHTML_DISPID_CUSTOM_MIN + i;
605 nsAString_Finish(&nsname);
606 nsAString_Finish(&nsstr);
608 nsIDOMHTMLCollection_Release(elements);
613 static HRESULT HTMLFormElement_invoke(HTMLDOMNode *iface,
614 DISPID id, LCID lcid, WORD flags, DISPPARAMS *params, VARIANT *res,
615 EXCEPINFO *ei, IServiceProvider *caller)
617 HTMLFormElement *This = HTMLFORM_NODE_THIS(iface);
621 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
623 hres = htmlform_item(This, id - MSHTML_DISPID_CUSTOM_MIN, &ret);
628 V_VT(res) = VT_DISPATCH;
629 V_DISPATCH(res) = ret;
636 #undef HTMLFORM_NODE_THIS
638 static const NodeImplVtbl HTMLFormElementImplVtbl = {
640 HTMLFormElement_destructor,
648 HTMLFormElement_get_dispid,
649 HTMLFormElement_invoke
652 static const tid_t HTMLFormElement_iface_tids[] = {
654 IHTMLFormElement_tid,
658 static dispex_static_data_t HTMLFormElement_dispex = {
660 DispHTMLFormElement_tid,
662 HTMLFormElement_iface_tids
665 HTMLElement *HTMLFormElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem)
667 HTMLFormElement *ret = heap_alloc_zero(sizeof(HTMLFormElement));
670 ret->lpHTMLFormElementVtbl = &HTMLFormElementVtbl;
671 ret->element.node.vtbl = &HTMLFormElementImplVtbl;
673 HTMLElement_Init(&ret->element, doc, nselem, &HTMLFormElement_dispex);
675 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLFormElement, (void**)&ret->nsform);
677 ERR("Could not get nsIDOMHTMLFormElement interface: %08x\n", nsres);
679 return &ret->element;