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 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
231 nsAString encoding_str
;
234 TRACE("(%p)->(%s)\n", This
, wine_dbgstr_w(v
));
236 if(lstrcmpiW(v
, L
"application/x-www-form-urlencoded") && lstrcmpiW(v
, L
"multipart/form-data")
237 && lstrcmpiW(v
, L
"text/plain")) {
238 WARN("incorrect enctype\n");
242 nsAString_InitDepend(&encoding_str
, v
);
243 nsres
= nsIDOMHTMLFormElement_SetEnctype(This
->nsform
, &encoding_str
);
244 nsAString_Finish(&encoding_str
);
251 static HRESULT WINAPI
HTMLFormElement_get_encoding(IHTMLFormElement
*iface
, BSTR
*p
)
253 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
254 nsAString encoding_str
;
257 TRACE("(%p)->(%p)\n", This
, p
);
259 nsAString_Init(&encoding_str
, NULL
);
260 nsres
= nsIDOMHTMLFormElement_GetEnctype(This
->nsform
, &encoding_str
);
261 return return_nsstr(nsres
, &encoding_str
, p
);
264 static HRESULT WINAPI
HTMLFormElement_put_method(IHTMLFormElement
*iface
, BSTR v
)
266 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
267 nsAString method_str
;
270 TRACE("(%p)->(%s)\n", This
, wine_dbgstr_w(v
));
272 if(lstrcmpiW(v
, L
"POST") && lstrcmpiW(v
, L
"GET")) {
273 WARN("unrecognized method\n");
277 nsAString_InitDepend(&method_str
, v
);
278 nsres
= nsIDOMHTMLFormElement_SetMethod(This
->nsform
, &method_str
);
279 nsAString_Finish(&method_str
);
286 static HRESULT WINAPI
HTMLFormElement_get_method(IHTMLFormElement
*iface
, BSTR
*p
)
288 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
289 nsAString method_str
;
292 TRACE("(%p)->(%p)\n", This
, p
);
294 nsAString_Init(&method_str
, NULL
);
295 nsres
= nsIDOMHTMLFormElement_GetMethod(This
->nsform
, &method_str
);
296 return return_nsstr(nsres
, &method_str
, p
);
299 static HRESULT WINAPI
HTMLFormElement_get_elements(IHTMLFormElement
*iface
, IDispatch
**p
)
301 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
302 nsIDOMHTMLCollection
*elements
;
305 TRACE("(%p)->(%p)\n", This
, p
);
307 if(dispex_compat_mode(&This
->element
.node
.event_target
.dispex
) < COMPAT_MODE_IE9
) {
308 IDispatch_AddRef(*p
= (IDispatch
*)&This
->IHTMLFormElement_iface
);
312 nsres
= nsIDOMHTMLFormElement_GetElements(This
->nsform
, &elements
);
313 if(NS_FAILED(nsres
)) {
314 ERR("GetElements failed: %08x\n", nsres
);
318 *p
= (IDispatch
*)create_collection_from_htmlcol(elements
, dispex_compat_mode(&This
->element
.node
.event_target
.dispex
));
319 nsIDOMHTMLCollection_Release(elements
);
323 static HRESULT WINAPI
HTMLFormElement_put_target(IHTMLFormElement
*iface
, BSTR v
)
325 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
329 TRACE("(%p)->(%s)\n", This
, wine_dbgstr_w(v
));
331 nsAString_InitDepend(&str
, v
);
333 nsres
= nsIDOMHTMLFormElement_SetTarget(This
->nsform
, &str
);
335 nsAString_Finish(&str
);
336 if (NS_FAILED(nsres
)) {
337 ERR("Set Target(%s) failed: %08x\n", wine_dbgstr_w(v
), nsres
);
344 static HRESULT WINAPI
HTMLFormElement_get_target(IHTMLFormElement
*iface
, BSTR
*p
)
346 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
350 TRACE("(%p)->(%p)\n", This
, p
);
352 nsAString_Init(&str
, NULL
);
353 nsres
= nsIDOMHTMLFormElement_GetTarget(This
->nsform
, &str
);
355 return return_nsstr(nsres
, &str
, p
);
358 static HRESULT WINAPI
HTMLFormElement_put_name(IHTMLFormElement
*iface
, BSTR v
)
360 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
364 TRACE("(%p)->(%s)\n", This
, wine_dbgstr_w(v
));
366 nsAString_InitDepend(&name_str
, v
);
367 nsres
= nsIDOMHTMLFormElement_SetName(This
->nsform
, &name_str
);
368 nsAString_Finish(&name_str
);
375 static HRESULT WINAPI
HTMLFormElement_get_name(IHTMLFormElement
*iface
, BSTR
*p
)
377 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
381 TRACE("(%p)->(%p)\n", This
, p
);
383 nsAString_Init(&name_str
, NULL
);
384 nsres
= nsIDOMHTMLFormElement_GetName(This
->nsform
, &name_str
);
385 return return_nsstr(nsres
, &name_str
, p
);
388 static HRESULT WINAPI
HTMLFormElement_put_onsubmit(IHTMLFormElement
*iface
, VARIANT v
)
390 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
392 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&v
));
394 return set_node_event(&This
->element
.node
, EVENTID_SUBMIT
, &v
);
397 static HRESULT WINAPI
HTMLFormElement_get_onsubmit(IHTMLFormElement
*iface
, VARIANT
*p
)
399 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
401 TRACE("(%p)->(%p)\n", This
, p
);
403 return get_node_event(&This
->element
.node
, EVENTID_SUBMIT
, p
);
406 static HRESULT WINAPI
HTMLFormElement_put_onreset(IHTMLFormElement
*iface
, VARIANT v
)
408 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
409 FIXME("(%p)->(%s)\n", This
, debugstr_variant(&v
));
413 static HRESULT WINAPI
HTMLFormElement_get_onreset(IHTMLFormElement
*iface
, VARIANT
*p
)
415 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
416 FIXME("(%p)->(%p)\n", This
, p
);
420 static HRESULT WINAPI
HTMLFormElement_submit(IHTMLFormElement
*iface
)
422 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
423 HTMLOuterWindow
*window
= NULL
, *this_window
= NULL
;
424 nsAString action_uri_str
, target_str
, method_str
;
425 nsIInputStream
*post_stream
;
426 BOOL is_post_submit
= FALSE
;
430 BOOL use_new_window
= FALSE
;
432 TRACE("(%p)\n", This
);
434 if(This
->element
.node
.doc
) {
435 HTMLDocumentNode
*doc
= This
->element
.node
.doc
;
436 if(doc
->window
&& doc
->window
->base
.outer_window
)
437 this_window
= doc
->window
->base
.outer_window
;
440 TRACE("No outer window\n");
444 nsAString_Init(&target_str
, NULL
);
445 nsres
= nsIDOMHTMLFormElement_GetTarget(This
->nsform
, &target_str
);
446 if(NS_SUCCEEDED(nsres
))
447 window
= get_target_window(this_window
, &target_str
, &use_new_window
);
449 if(!window
&& !use_new_window
) {
450 nsAString_Finish(&target_str
);
454 nsAString_Init(&method_str
, NULL
);
455 nsres
= nsIDOMHTMLFormElement_GetMethod(This
->nsform
, &method_str
);
456 if(NS_SUCCEEDED(nsres
)) {
457 const PRUnichar
*method
;
459 nsAString_GetData(&method_str
, &method
);
460 TRACE("method is %s\n", debugstr_w(method
));
461 is_post_submit
= !wcsicmp(method
, L
"post");
463 nsAString_Finish(&method_str
);
466 * FIXME: We currently use our submit implementation for POST submit. We should always use it.
468 if(window
&& !is_post_submit
) {
469 nsres
= nsIDOMHTMLFormElement_Submit(This
->nsform
);
470 nsAString_Finish(&target_str
);
471 IHTMLWindow2_Release(&window
->base
.IHTMLWindow2_iface
);
472 if(NS_FAILED(nsres
)) {
473 ERR("Submit failed: %08x\n", nsres
);
480 nsAString_Init(&action_uri_str
, NULL
);
481 nsres
= nsIDOMHTMLFormElement_GetFormData(This
->nsform
, NULL
, &action_uri_str
, &post_stream
);
482 if(NS_SUCCEEDED(nsres
)) {
483 const PRUnichar
*action_uri
;
485 nsAString_GetData(&action_uri_str
, &action_uri
);
486 hres
= create_uri(action_uri
, 0, &uri
);
488 ERR("GetFormData failed: %08x\n", nsres
);
491 nsAString_Finish(&action_uri_str
);
492 if(SUCCEEDED(hres
)) {
493 const PRUnichar
*target
;
495 nsAString_GetData(&target_str
, &target
);
496 hres
= submit_form(window
, target
, uri
, post_stream
);
500 nsAString_Finish(&target_str
);
502 IHTMLWindow2_Release(&window
->base
.IHTMLWindow2_iface
);
504 nsIInputStream_Release(post_stream
);
508 static HRESULT WINAPI
HTMLFormElement_reset(IHTMLFormElement
*iface
)
510 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
513 TRACE("(%p)->()\n", This
);
514 nsres
= nsIDOMHTMLFormElement_Reset(This
->nsform
);
515 if (NS_FAILED(nsres
)) {
516 ERR("Reset failed: %08x\n", nsres
);
523 static HRESULT WINAPI
HTMLFormElement_put_length(IHTMLFormElement
*iface
, LONG v
)
525 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
526 FIXME("(%p)->(%d)\n", This
, v
);
530 static HRESULT WINAPI
HTMLFormElement_get_length(IHTMLFormElement
*iface
, LONG
*p
)
532 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
535 TRACE("(%p)->(%p)\n", This
, p
);
537 nsres
= nsIDOMHTMLFormElement_GetLength(This
->nsform
, p
);
538 if(NS_FAILED(nsres
)) {
539 ERR("GetLength failed: %08x\n", nsres
);
546 static HRESULT WINAPI
HTMLFormElement__newEnum(IHTMLFormElement
*iface
, IUnknown
**p
)
548 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
549 FIXME("(%p)->(%p)\n", This
, p
);
553 static HRESULT WINAPI
HTMLFormElement_item(IHTMLFormElement
*iface
, VARIANT name
,
554 VARIANT index
, IDispatch
**pdisp
)
556 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
558 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_variant(&name
), debugstr_variant(&index
), pdisp
);
564 if(V_VT(&name
) == VT_I4
) {
565 if(V_I4(&name
) < 0) {
567 return dispex_compat_mode(&This
->element
.node
.event_target
.dispex
) >= COMPAT_MODE_IE9
568 ? S_OK
: E_INVALIDARG
;
570 return htmlform_item(This
, V_I4(&name
), pdisp
);
573 FIXME("Unsupported args\n");
577 static HRESULT WINAPI
HTMLFormElement_tags(IHTMLFormElement
*iface
, VARIANT tagName
,
580 HTMLFormElement
*This
= impl_from_IHTMLFormElement(iface
);
581 FIXME("(%p)->(v %p)\n", This
, pdisp
);
585 static const IHTMLFormElementVtbl HTMLFormElementVtbl
= {
586 HTMLFormElement_QueryInterface
,
587 HTMLFormElement_AddRef
,
588 HTMLFormElement_Release
,
589 HTMLFormElement_GetTypeInfoCount
,
590 HTMLFormElement_GetTypeInfo
,
591 HTMLFormElement_GetIDsOfNames
,
592 HTMLFormElement_Invoke
,
593 HTMLFormElement_put_action
,
594 HTMLFormElement_get_action
,
595 HTMLFormElement_put_dir
,
596 HTMLFormElement_get_dir
,
597 HTMLFormElement_put_encoding
,
598 HTMLFormElement_get_encoding
,
599 HTMLFormElement_put_method
,
600 HTMLFormElement_get_method
,
601 HTMLFormElement_get_elements
,
602 HTMLFormElement_put_target
,
603 HTMLFormElement_get_target
,
604 HTMLFormElement_put_name
,
605 HTMLFormElement_get_name
,
606 HTMLFormElement_put_onsubmit
,
607 HTMLFormElement_get_onsubmit
,
608 HTMLFormElement_put_onreset
,
609 HTMLFormElement_get_onreset
,
610 HTMLFormElement_submit
,
611 HTMLFormElement_reset
,
612 HTMLFormElement_put_length
,
613 HTMLFormElement_get_length
,
614 HTMLFormElement__newEnum
,
615 HTMLFormElement_item
,
619 static inline HTMLFormElement
*impl_from_HTMLDOMNode(HTMLDOMNode
*iface
)
621 return CONTAINING_RECORD(iface
, HTMLFormElement
, element
.node
);
624 static HRESULT
HTMLFormElement_QI(HTMLDOMNode
*iface
, REFIID riid
, void **ppv
)
626 HTMLFormElement
*This
= impl_from_HTMLDOMNode(iface
);
630 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
631 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
632 *ppv
= &This
->IHTMLFormElement_iface
;
633 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
634 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
635 *ppv
= &This
->IHTMLFormElement_iface
;
636 }else if(IsEqualGUID(&IID_IHTMLFormElement
, riid
)) {
637 TRACE("(%p)->(IID_IHTMLFormElement %p)\n", This
, ppv
);
638 *ppv
= &This
->IHTMLFormElement_iface
;
639 }else if(IsEqualGUID(&DIID_DispHTMLFormElement
, riid
)) {
640 TRACE("(%p)->(DIID_DispHTMLFormElement %p)\n", This
, ppv
);
641 *ppv
= &This
->IHTMLFormElement_iface
;
645 IUnknown_AddRef((IUnknown
*)*ppv
);
649 return HTMLElement_QI(&This
->element
.node
, riid
, ppv
);
652 static HRESULT
HTMLFormElement_get_dispid(HTMLDOMNode
*iface
,
653 BSTR name
, DWORD grfdex
, DISPID
*pid
)
655 HTMLFormElement
*This
= impl_from_HTMLDOMNode(iface
);
656 nsIDOMHTMLCollection
*elements
;
657 nsAString nsstr
, name_str
;
660 HRESULT hres
= DISP_E_UNKNOWNNAME
;
662 TRACE("(%p)->(%s %x %p)\n", This
, wine_dbgstr_w(name
), grfdex
, pid
);
664 nsres
= nsIDOMHTMLFormElement_GetElements(This
->nsform
, &elements
);
665 if(NS_FAILED(nsres
)) {
666 FIXME("GetElements failed: 0x%08x\n", nsres
);
670 nsres
= nsIDOMHTMLCollection_GetLength(elements
, &len
);
671 if(NS_FAILED(nsres
)) {
672 FIXME("GetLength failed: 0x%08x\n", nsres
);
673 nsIDOMHTMLCollection_Release(elements
);
677 if(len
> MSHTML_CUSTOM_DISPID_CNT
)
678 len
= MSHTML_CUSTOM_DISPID_CNT
;
680 /* FIXME: Implement in more generic way */
681 if('0' <= *name
&& *name
<= '9') {
684 i
= wcstoul(name
, &end_ptr
, 10);
685 if(!*end_ptr
&& i
< len
) {
686 *pid
= MSHTML_DISPID_CUSTOM_MIN
+ i
;
691 nsAString_Init(&nsstr
, NULL
);
692 for(i
= 0; i
< len
; ++i
) {
695 const PRUnichar
*str
;
697 nsres
= nsIDOMHTMLCollection_Item(elements
, i
, &nsitem
);
698 if(NS_FAILED(nsres
)) {
699 FIXME("Item failed: 0x%08x\n", nsres
);
704 nsres
= nsIDOMNode_QueryInterface(nsitem
, &IID_nsIDOMElement
, (void**)&elem
);
705 nsIDOMNode_Release(nsitem
);
706 if(NS_FAILED(nsres
)) {
707 FIXME("Failed to get nsIDOMHTMLNode interface: 0x%08x\n", nsres
);
712 /* compare by id attr */
713 nsres
= nsIDOMElement_GetId(elem
, &nsstr
);
714 if(NS_FAILED(nsres
)) {
715 FIXME("GetId failed: 0x%08x\n", nsres
);
716 nsIDOMElement_Release(elem
);
720 nsAString_GetData(&nsstr
, &str
);
721 if(!wcsicmp(str
, name
)) {
722 nsIDOMElement_Release(elem
);
723 /* FIXME: using index for dispid */
724 *pid
= MSHTML_DISPID_CUSTOM_MIN
+ i
;
729 /* compare by name attr */
730 nsres
= get_elem_attr_value(elem
, L
"name", &name_str
, &str
);
731 nsIDOMElement_Release(elem
);
732 if(NS_SUCCEEDED(nsres
)) {
733 if(!wcsicmp(str
, name
)) {
734 nsAString_Finish(&name_str
);
735 /* FIXME: using index for dispid */
736 *pid
= MSHTML_DISPID_CUSTOM_MIN
+ i
;
740 nsAString_Finish(&name_str
);
744 nsAString_Finish(&nsstr
);
745 nsIDOMHTMLCollection_Release(elements
);
749 static HRESULT
HTMLFormElement_invoke(HTMLDOMNode
*iface
,
750 DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*params
, VARIANT
*res
,
751 EXCEPINFO
*ei
, IServiceProvider
*caller
)
753 HTMLFormElement
*This
= impl_from_HTMLDOMNode(iface
);
757 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, flags
, params
, res
, ei
, caller
);
759 hres
= htmlform_item(This
, id
- MSHTML_DISPID_CUSTOM_MIN
, &ret
);
764 V_VT(res
) = VT_DISPATCH
;
765 V_DISPATCH(res
) = ret
;
772 static HRESULT
HTMLFormElement_handle_event(HTMLDOMNode
*iface
, DWORD eid
, nsIDOMEvent
*event
, BOOL
*prevent_default
)
774 HTMLFormElement
*This
= impl_from_HTMLDOMNode(iface
);
776 if(eid
== EVENTID_SUBMIT
) {
777 *prevent_default
= TRUE
;
778 return IHTMLFormElement_submit(&This
->IHTMLFormElement_iface
);
781 return HTMLElement_handle_event(&This
->element
.node
, eid
, event
, prevent_default
);
784 static void HTMLFormElement_traverse(HTMLDOMNode
*iface
, nsCycleCollectionTraversalCallback
*cb
)
786 HTMLFormElement
*This
= impl_from_HTMLDOMNode(iface
);
789 note_cc_edge((nsISupports
*)This
->nsform
, "This->nsform", cb
);
792 static void HTMLFormElement_unlink(HTMLDOMNode
*iface
)
794 HTMLFormElement
*This
= impl_from_HTMLDOMNode(iface
);
797 nsIDOMHTMLFormElement
*nsform
= This
->nsform
;
800 nsIDOMHTMLFormElement_Release(nsform
);
804 static const NodeImplVtbl HTMLFormElementImplVtbl
= {
805 &CLSID_HTMLFormElement
,
807 HTMLElement_destructor
,
810 HTMLFormElement_handle_event
,
811 HTMLElement_get_attr_col
,
817 HTMLFormElement_get_dispid
,
818 HTMLFormElement_invoke
,
820 HTMLFormElement_traverse
,
821 HTMLFormElement_unlink
824 static const tid_t HTMLFormElement_iface_tids
[] = {
826 IHTMLFormElement_tid
,
830 static dispex_static_data_t HTMLFormElement_dispex
= {
832 DispHTMLFormElement_tid
,
833 HTMLFormElement_iface_tids
,
834 HTMLElement_init_dispex_info
837 HRESULT
HTMLFormElement_Create(HTMLDocumentNode
*doc
, nsIDOMElement
*nselem
, HTMLElement
**elem
)
839 HTMLFormElement
*ret
;
842 ret
= heap_alloc_zero(sizeof(HTMLFormElement
));
844 return E_OUTOFMEMORY
;
846 ret
->IHTMLFormElement_iface
.lpVtbl
= &HTMLFormElementVtbl
;
847 ret
->element
.node
.vtbl
= &HTMLFormElementImplVtbl
;
849 HTMLElement_Init(&ret
->element
, doc
, nselem
, &HTMLFormElement_dispex
);
851 nsres
= nsIDOMElement_QueryInterface(nselem
, &IID_nsIDOMHTMLFormElement
, (void**)&ret
->nsform
);
852 assert(nsres
== NS_OK
);
854 *elem
= &ret
->element
;