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
29 #include "wine/debug.h"
31 #include "mshtml_private.h"
32 #include "htmlevent.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
37 struct HTMLFormElement
{
40 IHTMLFormElement IHTMLFormElement_iface
;
42 nsIDOMHTMLFormElement
*nsform
;
45 HRESULT
return_nsform(nsresult nsres
, nsIDOMHTMLFormElement
*form
, IHTMLFormElement
**p
)
47 nsIDOMNode
*form_node
;
51 if (NS_FAILED(nsres
)) {
52 ERR("GetForm failed: %08x\n", nsres
);
62 nsres
= nsIDOMHTMLFormElement_QueryInterface(form
, &IID_nsIDOMNode
, (void**)&form_node
);
63 nsIDOMHTMLFormElement_Release(form
);
64 assert(nsres
== NS_OK
);
66 hres
= get_node(form_node
, TRUE
, &node
);
67 nsIDOMNode_Release(form_node
);
71 TRACE("node %p\n", node
);
72 hres
= IHTMLDOMNode_QueryInterface(&node
->IHTMLDOMNode_iface
, &IID_IHTMLFormElement
, (void**)p
);
77 static HRESULT
htmlform_item(HTMLFormElement
*This
, int i
, IDispatch
**ret
)
79 nsIDOMHTMLCollection
*elements
;
85 nsres
= nsIDOMHTMLFormElement_GetElements(This
->nsform
, &elements
);
86 if(NS_FAILED(nsres
)) {
87 FIXME("GetElements failed: 0x%08x\n", nsres
);
91 nsres
= nsIDOMHTMLCollection_Item(elements
, i
, &item
);
92 nsIDOMHTMLCollection_Release(elements
);
93 if(NS_FAILED(nsres
)) {
94 FIXME("Item failed: 0x%08x\n", nsres
);
99 hres
= get_node(item
, TRUE
, &node
);
103 nsIDOMNode_Release(item
);
104 *ret
= (IDispatch
*)&node
->IHTMLDOMNode_iface
;
112 static inline HTMLFormElement
*impl_from_IHTMLFormElement(IHTMLFormElement
*iface
)
114 return CONTAINING_RECORD(iface
, HTMLFormElement
, IHTMLFormElement_iface
);
117 static HRESULT WINAPI
HTMLFormElement_QueryInterface(IHTMLFormElement
*iface
,
118 REFIID riid
, void **ppv
)
120 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
122 return IHTMLDOMNode_QueryInterface(&This
->element
.node
.IHTMLDOMNode_iface
, riid
, ppv
);
125 static ULONG WINAPI
HTMLFormElement_AddRef(IHTMLFormElement
*iface
)
127 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
129 return IHTMLDOMNode_AddRef(&This
->element
.node
.IHTMLDOMNode_iface
);
132 static ULONG WINAPI
HTMLFormElement_Release(IHTMLFormElement
*iface
)
134 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
136 return IHTMLDOMNode_Release(&This
->element
.node
.IHTMLDOMNode_iface
);
139 static HRESULT WINAPI
HTMLFormElement_GetTypeInfoCount(IHTMLFormElement
*iface
, UINT
*pctinfo
)
141 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
142 return IDispatchEx_GetTypeInfoCount(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, pctinfo
);
145 static HRESULT WINAPI
HTMLFormElement_GetTypeInfo(IHTMLFormElement
*iface
, UINT iTInfo
,
146 LCID lcid
, ITypeInfo
**ppTInfo
)
148 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
149 return IDispatchEx_GetTypeInfo(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, iTInfo
, lcid
,
153 static HRESULT WINAPI
HTMLFormElement_GetIDsOfNames(IHTMLFormElement
*iface
, REFIID riid
,
154 LPOLESTR
*rgszNames
, UINT cNames
,
155 LCID lcid
, DISPID
*rgDispId
)
157 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
158 return IDispatchEx_GetIDsOfNames(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, riid
, rgszNames
,
159 cNames
, lcid
, rgDispId
);
162 static HRESULT WINAPI
HTMLFormElement_Invoke(IHTMLFormElement
*iface
, DISPID dispIdMember
,
163 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
164 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
166 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
167 return IDispatchEx_Invoke(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, dispIdMember
, riid
,
168 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
171 static HRESULT WINAPI
HTMLFormElement_put_action(IHTMLFormElement
*iface
, BSTR v
)
173 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
174 nsAString action_str
;
177 TRACE("(%p)->(%s)\n", This
, wine_dbgstr_w(v
));
179 nsAString_InitDepend(&action_str
, v
);
180 nsres
= nsIDOMHTMLFormElement_SetAction(This
->nsform
, &action_str
);
181 nsAString_Finish(&action_str
);
182 if(NS_FAILED(nsres
)) {
183 ERR("SetAction failed: %08x\n", nsres
);
190 static HRESULT WINAPI
HTMLFormElement_get_action(IHTMLFormElement
*iface
, BSTR
*p
)
192 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
193 nsAString action_str
;
197 TRACE("(%p)->(%p)\n", This
, p
);
199 nsAString_Init(&action_str
, NULL
);
200 nsres
= nsIDOMHTMLFormElement_GetAction(This
->nsform
, &action_str
);
201 if(NS_SUCCEEDED(nsres
)) {
202 const PRUnichar
*action
;
203 nsAString_GetData(&action_str
, &action
);
204 hres
= nsuri_to_url(action
, FALSE
, p
);
206 ERR("GetAction failed: %08x\n", nsres
);
210 nsAString_Finish(&action_str
);
214 static HRESULT WINAPI
HTMLFormElement_put_dir(IHTMLFormElement
*iface
, BSTR v
)
216 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
217 FIXME("(%p)->(%s)\n", This
, wine_dbgstr_w(v
));
221 static HRESULT WINAPI
HTMLFormElement_get_dir(IHTMLFormElement
*iface
, BSTR
*p
)
223 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
224 FIXME("(%p)->(%p)\n", This
, p
);
228 static HRESULT WINAPI
HTMLFormElement_put_encoding(IHTMLFormElement
*iface
, BSTR v
)
230 static const WCHAR urlencodedW
[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
231 'x','-','w','w','w','-','f','o','r','m','-','u','r','l','e','n','c','o','d','e','d',0};
232 static const WCHAR dataW
[] = {'m','u','l','t','i','p','a','r','t','/',
233 'f','o','r','m','-','d','a','t','a',0};
234 static const WCHAR plainW
[] = {'t','e','x','t','/','p','l','a','i','n',0};
236 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
237 nsAString encoding_str
;
240 TRACE("(%p)->(%s)\n", This
, wine_dbgstr_w(v
));
242 if(lstrcmpiW(v
, urlencodedW
) && lstrcmpiW(v
, dataW
) && lstrcmpiW(v
, plainW
)) {
243 WARN("incorrect enctype\n");
247 nsAString_InitDepend(&encoding_str
, v
);
248 nsres
= nsIDOMHTMLFormElement_SetEnctype(This
->nsform
, &encoding_str
);
249 nsAString_Finish(&encoding_str
);
256 static HRESULT WINAPI
HTMLFormElement_get_encoding(IHTMLFormElement
*iface
, BSTR
*p
)
258 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
259 nsAString encoding_str
;
262 TRACE("(%p)->(%p)\n", This
, p
);
264 nsAString_Init(&encoding_str
, NULL
);
265 nsres
= nsIDOMHTMLFormElement_GetEnctype(This
->nsform
, &encoding_str
);
266 return return_nsstr(nsres
, &encoding_str
, p
);
269 static HRESULT WINAPI
HTMLFormElement_put_method(IHTMLFormElement
*iface
, BSTR v
)
271 static const WCHAR postW
[] = {'P','O','S','T',0};
272 static const WCHAR getW
[] = {'G','E','T',0};
274 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
275 nsAString method_str
;
278 TRACE("(%p)->(%s)\n", This
, wine_dbgstr_w(v
));
280 if(lstrcmpiW(v
, postW
) && lstrcmpiW(v
, getW
)) {
281 WARN("unrecognized method\n");
285 nsAString_InitDepend(&method_str
, v
);
286 nsres
= nsIDOMHTMLFormElement_SetMethod(This
->nsform
, &method_str
);
287 nsAString_Finish(&method_str
);
294 static HRESULT WINAPI
HTMLFormElement_get_method(IHTMLFormElement
*iface
, BSTR
*p
)
296 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
297 nsAString method_str
;
300 TRACE("(%p)->(%p)\n", This
, p
);
302 nsAString_Init(&method_str
, NULL
);
303 nsres
= nsIDOMHTMLFormElement_GetMethod(This
->nsform
, &method_str
);
304 return return_nsstr(nsres
, &method_str
, p
);
307 static HRESULT WINAPI
HTMLFormElement_get_elements(IHTMLFormElement
*iface
, IDispatch
**p
)
309 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
310 nsIDOMHTMLCollection
*elements
;
313 TRACE("(%p)->(%p)\n", This
, p
);
315 if(dispex_compat_mode(&This
->element
.node
.event_target
.dispex
) < COMPAT_MODE_IE9
) {
316 IDispatch_AddRef(*p
= (IDispatch
*)&This
->IHTMLFormElement_iface
);
320 nsres
= nsIDOMHTMLFormElement_GetElements(This
->nsform
, &elements
);
321 if(NS_FAILED(nsres
)) {
322 ERR("GetElements failed: %08x\n", nsres
);
326 *p
= (IDispatch
*)create_collection_from_htmlcol(elements
, dispex_compat_mode(&This
->element
.node
.event_target
.dispex
));
327 nsIDOMHTMLCollection_Release(elements
);
331 static HRESULT WINAPI
HTMLFormElement_put_target(IHTMLFormElement
*iface
, BSTR v
)
333 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
337 TRACE("(%p)->(%s)\n", This
, wine_dbgstr_w(v
));
339 nsAString_InitDepend(&str
, v
);
341 nsres
= nsIDOMHTMLFormElement_SetTarget(This
->nsform
, &str
);
343 nsAString_Finish(&str
);
344 if (NS_FAILED(nsres
)) {
345 ERR("Set Target(%s) failed: %08x\n", wine_dbgstr_w(v
), nsres
);
352 static HRESULT WINAPI
HTMLFormElement_get_target(IHTMLFormElement
*iface
, BSTR
*p
)
354 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
358 TRACE("(%p)->(%p)\n", This
, p
);
360 nsAString_Init(&str
, NULL
);
361 nsres
= nsIDOMHTMLFormElement_GetTarget(This
->nsform
, &str
);
363 return return_nsstr(nsres
, &str
, p
);
366 static HRESULT WINAPI
HTMLFormElement_put_name(IHTMLFormElement
*iface
, BSTR v
)
368 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
372 TRACE("(%p)->(%s)\n", This
, wine_dbgstr_w(v
));
374 nsAString_InitDepend(&name_str
, v
);
375 nsres
= nsIDOMHTMLFormElement_SetName(This
->nsform
, &name_str
);
376 nsAString_Finish(&name_str
);
383 static HRESULT WINAPI
HTMLFormElement_get_name(IHTMLFormElement
*iface
, BSTR
*p
)
385 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
389 TRACE("(%p)->(%p)\n", This
, p
);
391 nsAString_Init(&name_str
, NULL
);
392 nsres
= nsIDOMHTMLFormElement_GetName(This
->nsform
, &name_str
);
393 return return_nsstr(nsres
, &name_str
, p
);
396 static HRESULT WINAPI
HTMLFormElement_put_onsubmit(IHTMLFormElement
*iface
, VARIANT v
)
398 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
400 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&v
));
402 return set_node_event(&This
->element
.node
, EVENTID_SUBMIT
, &v
);
405 static HRESULT WINAPI
HTMLFormElement_get_onsubmit(IHTMLFormElement
*iface
, VARIANT
*p
)
407 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
409 TRACE("(%p)->(%p)\n", This
, p
);
411 return get_node_event(&This
->element
.node
, EVENTID_SUBMIT
, p
);
414 static HRESULT WINAPI
HTMLFormElement_put_onreset(IHTMLFormElement
*iface
, VARIANT v
)
416 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
417 FIXME("(%p)->(%s)\n", This
, debugstr_variant(&v
));
421 static HRESULT WINAPI
HTMLFormElement_get_onreset(IHTMLFormElement
*iface
, VARIANT
*p
)
423 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
424 FIXME("(%p)->(%p)\n", This
, p
);
428 static HRESULT WINAPI
HTMLFormElement_submit(IHTMLFormElement
*iface
)
430 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
431 HTMLOuterWindow
*window
= NULL
, *this_window
= NULL
;
432 nsAString action_uri_str
, target_str
, method_str
;
433 nsIInputStream
*post_stream
;
434 BOOL is_post_submit
= FALSE
;
438 BOOL use_new_window
= FALSE
;
440 TRACE("(%p)\n", This
);
442 if(This
->element
.node
.doc
) {
443 HTMLDocumentNode
*doc
= This
->element
.node
.doc
;
444 if(doc
->window
&& doc
->window
->base
.outer_window
)
445 this_window
= doc
->window
->base
.outer_window
;
448 TRACE("No outer window\n");
452 nsAString_Init(&target_str
, NULL
);
453 nsres
= nsIDOMHTMLFormElement_GetTarget(This
->nsform
, &target_str
);
454 if(NS_SUCCEEDED(nsres
))
455 window
= get_target_window(this_window
, &target_str
, &use_new_window
);
457 if(!window
&& !use_new_window
) {
458 nsAString_Finish(&target_str
);
462 nsAString_Init(&method_str
, NULL
);
463 nsres
= nsIDOMHTMLFormElement_GetMethod(This
->nsform
, &method_str
);
464 if(NS_SUCCEEDED(nsres
)) {
465 const PRUnichar
*method
;
467 static const PRUnichar postW
[] = {'p','o','s','t',0};
469 nsAString_GetData(&method_str
, &method
);
470 TRACE("method is %s\n", debugstr_w(method
));
471 is_post_submit
= !wcsicmp(method
, postW
);
473 nsAString_Finish(&method_str
);
476 * FIXME: We currently use our submit implementation for POST submit. We should always use it.
478 if(window
&& !is_post_submit
) {
479 nsres
= nsIDOMHTMLFormElement_Submit(This
->nsform
);
480 nsAString_Finish(&target_str
);
481 IHTMLWindow2_Release(&window
->base
.IHTMLWindow2_iface
);
482 if(NS_FAILED(nsres
)) {
483 ERR("Submit failed: %08x\n", nsres
);
490 nsAString_Init(&action_uri_str
, NULL
);
491 nsres
= nsIDOMHTMLFormElement_GetFormData(This
->nsform
, NULL
, &action_uri_str
, &post_stream
);
492 if(NS_SUCCEEDED(nsres
)) {
493 const PRUnichar
*action_uri
;
495 nsAString_GetData(&action_uri_str
, &action_uri
);
496 hres
= create_uri(action_uri
, 0, &uri
);
498 ERR("GetFormData failed: %08x\n", nsres
);
501 nsAString_Finish(&action_uri_str
);
502 if(SUCCEEDED(hres
)) {
503 const PRUnichar
*target
;
505 nsAString_GetData(&target_str
, &target
);
506 hres
= submit_form(window
, target
, uri
, post_stream
);
510 nsAString_Finish(&target_str
);
512 IHTMLWindow2_Release(&window
->base
.IHTMLWindow2_iface
);
514 nsIInputStream_Release(post_stream
);
518 static HRESULT WINAPI
HTMLFormElement_reset(IHTMLFormElement
*iface
)
520 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
523 TRACE("(%p)->()\n", This
);
524 nsres
= nsIDOMHTMLFormElement_Reset(This
->nsform
);
525 if (NS_FAILED(nsres
)) {
526 ERR("Reset failed: %08x\n", nsres
);
533 static HRESULT WINAPI
HTMLFormElement_put_length(IHTMLFormElement
*iface
, LONG v
)
535 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
536 FIXME("(%p)->(%d)\n", This
, v
);
540 static HRESULT WINAPI
HTMLFormElement_get_length(IHTMLFormElement
*iface
, LONG
*p
)
542 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
545 TRACE("(%p)->(%p)\n", This
, p
);
547 nsres
= nsIDOMHTMLFormElement_GetLength(This
->nsform
, p
);
548 if(NS_FAILED(nsres
)) {
549 ERR("GetLength failed: %08x\n", nsres
);
556 static HRESULT WINAPI
HTMLFormElement__newEnum(IHTMLFormElement
*iface
, IUnknown
**p
)
558 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
559 FIXME("(%p)->(%p)\n", This
, p
);
563 static HRESULT WINAPI
HTMLFormElement_item(IHTMLFormElement
*iface
, VARIANT name
,
564 VARIANT index
, IDispatch
**pdisp
)
566 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
568 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_variant(&name
), debugstr_variant(&index
), pdisp
);
574 if(V_VT(&name
) == VT_I4
) {
575 if(V_I4(&name
) < 0) {
577 return dispex_compat_mode(&This
->element
.node
.event_target
.dispex
) >= COMPAT_MODE_IE9
578 ? S_OK
: E_INVALIDARG
;
580 return htmlform_item(This
, V_I4(&name
), pdisp
);
583 FIXME("Unsupported args\n");
587 static HRESULT WINAPI
HTMLFormElement_tags(IHTMLFormElement
*iface
, VARIANT tagName
,
590 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
591 FIXME("(%p)->(v %p)\n", This
, pdisp
);
595 static const IHTMLFormElementVtbl HTMLFormElementVtbl
= {
596 HTMLFormElement_QueryInterface
,
597 HTMLFormElement_AddRef
,
598 HTMLFormElement_Release
,
599 HTMLFormElement_GetTypeInfoCount
,
600 HTMLFormElement_GetTypeInfo
,
601 HTMLFormElement_GetIDsOfNames
,
602 HTMLFormElement_Invoke
,
603 HTMLFormElement_put_action
,
604 HTMLFormElement_get_action
,
605 HTMLFormElement_put_dir
,
606 HTMLFormElement_get_dir
,
607 HTMLFormElement_put_encoding
,
608 HTMLFormElement_get_encoding
,
609 HTMLFormElement_put_method
,
610 HTMLFormElement_get_method
,
611 HTMLFormElement_get_elements
,
612 HTMLFormElement_put_target
,
613 HTMLFormElement_get_target
,
614 HTMLFormElement_put_name
,
615 HTMLFormElement_get_name
,
616 HTMLFormElement_put_onsubmit
,
617 HTMLFormElement_get_onsubmit
,
618 HTMLFormElement_put_onreset
,
619 HTMLFormElement_get_onreset
,
620 HTMLFormElement_submit
,
621 HTMLFormElement_reset
,
622 HTMLFormElement_put_length
,
623 HTMLFormElement_get_length
,
624 HTMLFormElement__newEnum
,
625 HTMLFormElement_item
,
629 static inline HTMLFormElement
*impl_from_HTMLDOMNode(HTMLDOMNode
*iface
)
631 return CONTAINING_RECORD(iface
, HTMLFormElement
, element
.node
);
634 static HRESULT
HTMLFormElement_QI(HTMLDOMNode
*iface
, REFIID riid
, void **ppv
)
636 HTMLFormElement
*This
= impl_from_HTMLDOMNode(iface
);
640 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
641 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
642 *ppv
= &This
->IHTMLFormElement_iface
;
643 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
644 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
645 *ppv
= &This
->IHTMLFormElement_iface
;
646 }else if(IsEqualGUID(&IID_IHTMLFormElement
, riid
)) {
647 TRACE("(%p)->(IID_IHTMLFormElement %p)\n", This
, ppv
);
648 *ppv
= &This
->IHTMLFormElement_iface
;
649 }else if(IsEqualGUID(&DIID_DispHTMLFormElement
, riid
)) {
650 TRACE("(%p)->(DIID_DispHTMLFormElement %p)\n", This
, ppv
);
651 *ppv
= &This
->IHTMLFormElement_iface
;
655 IUnknown_AddRef((IUnknown
*)*ppv
);
659 return HTMLElement_QI(&This
->element
.node
, riid
, ppv
);
662 static HRESULT
HTMLFormElement_get_dispid(HTMLDOMNode
*iface
,
663 BSTR name
, DWORD grfdex
, DISPID
*pid
)
665 HTMLFormElement
*This
= impl_from_HTMLDOMNode(iface
);
666 nsIDOMHTMLCollection
*elements
;
667 nsAString nsstr
, name_str
;
670 HRESULT hres
= DISP_E_UNKNOWNNAME
;
672 static const PRUnichar nameW
[] = {'n','a','m','e',0};
674 TRACE("(%p)->(%s %x %p)\n", This
, wine_dbgstr_w(name
), grfdex
, pid
);
676 nsres
= nsIDOMHTMLFormElement_GetElements(This
->nsform
, &elements
);
677 if(NS_FAILED(nsres
)) {
678 FIXME("GetElements failed: 0x%08x\n", nsres
);
682 nsres
= nsIDOMHTMLCollection_GetLength(elements
, &len
);
683 if(NS_FAILED(nsres
)) {
684 FIXME("GetLength failed: 0x%08x\n", nsres
);
685 nsIDOMHTMLCollection_Release(elements
);
689 if(len
> MSHTML_CUSTOM_DISPID_CNT
)
690 len
= MSHTML_CUSTOM_DISPID_CNT
;
692 /* FIXME: Implement in more generic way */
693 if('0' <= *name
&& *name
<= '9') {
696 i
= wcstoul(name
, &end_ptr
, 10);
697 if(!*end_ptr
&& i
< len
) {
698 *pid
= MSHTML_DISPID_CUSTOM_MIN
+ i
;
703 nsAString_Init(&nsstr
, NULL
);
704 for(i
= 0; i
< len
; ++i
) {
707 const PRUnichar
*str
;
709 nsres
= nsIDOMHTMLCollection_Item(elements
, i
, &nsitem
);
710 if(NS_FAILED(nsres
)) {
711 FIXME("Item failed: 0x%08x\n", nsres
);
716 nsres
= nsIDOMNode_QueryInterface(nsitem
, &IID_nsIDOMElement
, (void**)&elem
);
717 nsIDOMNode_Release(nsitem
);
718 if(NS_FAILED(nsres
)) {
719 FIXME("Failed to get nsIDOMHTMLNode interface: 0x%08x\n", nsres
);
724 /* compare by id attr */
725 nsres
= nsIDOMElement_GetId(elem
, &nsstr
);
726 if(NS_FAILED(nsres
)) {
727 FIXME("GetId failed: 0x%08x\n", nsres
);
728 nsIDOMElement_Release(elem
);
732 nsAString_GetData(&nsstr
, &str
);
733 if(!wcsicmp(str
, name
)) {
734 nsIDOMElement_Release(elem
);
735 /* FIXME: using index for dispid */
736 *pid
= MSHTML_DISPID_CUSTOM_MIN
+ i
;
741 /* compare by name attr */
742 nsres
= get_elem_attr_value(elem
, nameW
, &name_str
, &str
);
743 nsIDOMElement_Release(elem
);
744 if(NS_SUCCEEDED(nsres
)) {
745 if(!wcsicmp(str
, name
)) {
746 nsAString_Finish(&name_str
);
747 /* FIXME: using index for dispid */
748 *pid
= MSHTML_DISPID_CUSTOM_MIN
+ i
;
752 nsAString_Finish(&name_str
);
756 nsAString_Finish(&nsstr
);
757 nsIDOMHTMLCollection_Release(elements
);
761 static HRESULT
HTMLFormElement_invoke(HTMLDOMNode
*iface
,
762 DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*params
, VARIANT
*res
,
763 EXCEPINFO
*ei
, IServiceProvider
*caller
)
765 HTMLFormElement
*This
= impl_from_HTMLDOMNode(iface
);
769 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, flags
, params
, res
, ei
, caller
);
771 hres
= htmlform_item(This
, id
- MSHTML_DISPID_CUSTOM_MIN
, &ret
);
776 V_VT(res
) = VT_DISPATCH
;
777 V_DISPATCH(res
) = ret
;
784 static HRESULT
HTMLFormElement_handle_event(HTMLDOMNode
*iface
, DWORD eid
, nsIDOMEvent
*event
, BOOL
*prevent_default
)
786 HTMLFormElement
*This
= impl_from_HTMLDOMNode(iface
);
788 if(eid
== EVENTID_SUBMIT
) {
789 *prevent_default
= TRUE
;
790 return IHTMLFormElement_submit(&This
->IHTMLFormElement_iface
);
793 return HTMLElement_handle_event(&This
->element
.node
, eid
, event
, prevent_default
);
796 static void HTMLFormElement_traverse(HTMLDOMNode
*iface
, nsCycleCollectionTraversalCallback
*cb
)
798 HTMLFormElement
*This
= impl_from_HTMLDOMNode(iface
);
801 note_cc_edge((nsISupports
*)This
->nsform
, "This->nsform", cb
);
804 static void HTMLFormElement_unlink(HTMLDOMNode
*iface
)
806 HTMLFormElement
*This
= impl_from_HTMLDOMNode(iface
);
809 nsIDOMHTMLFormElement
*nsform
= This
->nsform
;
812 nsIDOMHTMLFormElement_Release(nsform
);
816 static const NodeImplVtbl HTMLFormElementImplVtbl
= {
817 &CLSID_HTMLFormElement
,
819 HTMLElement_destructor
,
822 HTMLFormElement_handle_event
,
823 HTMLElement_get_attr_col
,
829 HTMLFormElement_get_dispid
,
830 HTMLFormElement_invoke
,
832 HTMLFormElement_traverse
,
833 HTMLFormElement_unlink
836 static const tid_t HTMLFormElement_iface_tids
[] = {
838 IHTMLFormElement_tid
,
842 static dispex_static_data_t HTMLFormElement_dispex
= {
844 DispHTMLFormElement_tid
,
845 HTMLFormElement_iface_tids
,
846 HTMLElement_init_dispex_info
849 HRESULT
HTMLFormElement_Create(HTMLDocumentNode
*doc
, nsIDOMElement
*nselem
, HTMLElement
**elem
)
851 HTMLFormElement
*ret
;
854 ret
= heap_alloc_zero(sizeof(HTMLFormElement
));
856 return E_OUTOFMEMORY
;
858 ret
->IHTMLFormElement_iface
.lpVtbl
= &HTMLFormElementVtbl
;
859 ret
->element
.node
.vtbl
= &HTMLFormElementImplVtbl
;
861 HTMLElement_Init(&ret
->element
, doc
, nselem
, &HTMLFormElement_dispex
);
863 nsres
= nsIDOMElement_QueryInterface(nselem
, &IID_nsIDOMHTMLFormElement
, (void**)&ret
->nsform
);
864 assert(nsres
== NS_OK
);
866 *elem
= &ret
->element
;