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 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
192 FIXME("(%p)->(%s)\n", This
, wine_dbgstr_w(v
));
196 static HRESULT WINAPI
HTMLFormElement_get_encoding(IHTMLFormElement
*iface
, BSTR
*p
)
198 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
199 FIXME("(%p)->(%p)\n", This
, p
);
203 static HRESULT WINAPI
HTMLFormElement_put_method(IHTMLFormElement
*iface
, BSTR v
)
205 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
206 FIXME("(%p)->(%s)\n", This
, wine_dbgstr_w(v
));
210 static HRESULT WINAPI
HTMLFormElement_get_method(IHTMLFormElement
*iface
, BSTR
*p
)
212 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
213 FIXME("(%p)->(%p)\n", This
, p
);
217 static HRESULT WINAPI
HTMLFormElement_get_elements(IHTMLFormElement
*iface
, IDispatch
**p
)
219 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
220 FIXME("(%p)->(%p)\n", This
, p
);
224 static HRESULT WINAPI
HTMLFormElement_put_target(IHTMLFormElement
*iface
, BSTR v
)
226 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
227 FIXME("(%p)->(%s)\n", This
, wine_dbgstr_w(v
));
231 static HRESULT WINAPI
HTMLFormElement_get_target(IHTMLFormElement
*iface
, BSTR
*p
)
233 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
234 FIXME("(%p)->(%p)\n", This
, p
);
238 static HRESULT WINAPI
HTMLFormElement_put_name(IHTMLFormElement
*iface
, BSTR v
)
240 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
241 FIXME("(%p)->(%s)\n", This
, wine_dbgstr_w(v
));
245 static HRESULT WINAPI
HTMLFormElement_get_name(IHTMLFormElement
*iface
, BSTR
*p
)
247 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
248 FIXME("(%p)->(%p)\n", This
, p
);
252 static HRESULT WINAPI
HTMLFormElement_put_onsubmit(IHTMLFormElement
*iface
, VARIANT v
)
254 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
255 FIXME("(%p)->(v)\n", This
);
259 static HRESULT WINAPI
HTMLFormElement_get_onsubmit(IHTMLFormElement
*iface
, VARIANT
*p
)
261 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
262 FIXME("(%p)->(%p)\n", This
, p
);
266 static HRESULT WINAPI
HTMLFormElement_put_onreset(IHTMLFormElement
*iface
, VARIANT v
)
268 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
269 FIXME("(%p)->(v)\n", This
);
273 static HRESULT WINAPI
HTMLFormElement_get_onreset(IHTMLFormElement
*iface
, VARIANT
*p
)
275 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
276 FIXME("(%p)->(%p)\n", This
, p
);
280 static HRESULT WINAPI
HTMLFormElement_submit(IHTMLFormElement
*iface
)
282 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
283 FIXME("(%p)->()\n", This
);
287 static HRESULT WINAPI
HTMLFormElement_reset(IHTMLFormElement
*iface
)
289 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
290 FIXME("(%p)->()\n", This
);
294 static HRESULT WINAPI
HTMLFormElement_put_length(IHTMLFormElement
*iface
, LONG v
)
296 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
297 FIXME("(%p)->(%d)\n", This
, v
);
301 static HRESULT WINAPI
HTMLFormElement_get_length(IHTMLFormElement
*iface
, LONG
*p
)
303 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
307 TRACE("(%p)->(%p)\n", This
, p
);
309 nsres
= nsIDOMHTMLFormElement_GetLength(This
->nsform
, &length
);
310 if(NS_FAILED(nsres
)) {
311 ERR("GetLength failed: %08x\n", nsres
);
319 static HRESULT WINAPI
HTMLFormElement__newEnum(IHTMLFormElement
*iface
, IUnknown
**p
)
321 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
322 FIXME("(%p)->(%p)\n", This
, p
);
326 static HRESULT WINAPI
HTMLFormElement_item(IHTMLFormElement
*iface
, VARIANT name
,
327 VARIANT index
, IDispatch
**pdisp
)
329 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
331 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_variant(&name
), debugstr_variant(&index
), pdisp
);
337 if(V_VT(&name
) == VT_I4
) {
340 return htmlform_item(This
, V_I4(&name
), pdisp
);
343 FIXME("Unsupported args\n");
347 static HRESULT WINAPI
HTMLFormElement_tags(IHTMLFormElement
*iface
, VARIANT tagName
,
350 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
351 FIXME("(%p)->(v %p)\n", This
, pdisp
);
357 static const IHTMLFormElementVtbl HTMLFormElementVtbl
= {
358 HTMLFormElement_QueryInterface
,
359 HTMLFormElement_AddRef
,
360 HTMLFormElement_Release
,
361 HTMLFormElement_GetTypeInfoCount
,
362 HTMLFormElement_GetTypeInfo
,
363 HTMLFormElement_GetIDsOfNames
,
364 HTMLFormElement_Invoke
,
365 HTMLFormElement_put_action
,
366 HTMLFormElement_get_action
,
367 HTMLFormElement_put_dir
,
368 HTMLFormElement_get_dir
,
369 HTMLFormElement_put_encoding
,
370 HTMLFormElement_get_encoding
,
371 HTMLFormElement_put_method
,
372 HTMLFormElement_get_method
,
373 HTMLFormElement_get_elements
,
374 HTMLFormElement_put_target
,
375 HTMLFormElement_get_target
,
376 HTMLFormElement_put_name
,
377 HTMLFormElement_get_name
,
378 HTMLFormElement_put_onsubmit
,
379 HTMLFormElement_get_onsubmit
,
380 HTMLFormElement_put_onreset
,
381 HTMLFormElement_get_onreset
,
382 HTMLFormElement_submit
,
383 HTMLFormElement_reset
,
384 HTMLFormElement_put_length
,
385 HTMLFormElement_get_length
,
386 HTMLFormElement__newEnum
,
387 HTMLFormElement_item
,
391 #define HTMLFORM_NODE_THIS(iface) DEFINE_THIS2(HTMLFormElement, element.node, iface)
393 static HRESULT
HTMLFormElement_QI(HTMLDOMNode
*iface
, REFIID riid
, void **ppv
)
395 HTMLFormElement
*This
= HTMLFORM_NODE_THIS(iface
);
399 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
400 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
401 *ppv
= HTMLFORM(This
);
402 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
403 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
404 *ppv
= HTMLFORM(This
);
405 }else if(IsEqualGUID(&IID_IHTMLFormElement
, riid
)) {
406 TRACE("(%p)->(IID_IHTMLFormElement %p)\n", This
, ppv
);
407 *ppv
= HTMLFORM(This
);
411 IUnknown_AddRef((IUnknown
*)*ppv
);
415 return HTMLElement_QI(&This
->element
.node
, riid
, ppv
);
418 static void HTMLFormElement_destructor(HTMLDOMNode
*iface
)
420 HTMLFormElement
*This
= HTMLFORM_NODE_THIS(iface
);
423 nsIDOMHTMLFormElement_Release(This
->nsform
);
425 HTMLElement_destructor(&This
->element
.node
);
428 static HRESULT
HTMLFormElement_get_dispid(HTMLDOMNode
*iface
,
429 BSTR name
, DWORD grfdex
, DISPID
*pid
)
431 HTMLFormElement
*This
= HTMLFORM_NODE_THIS(iface
);
432 nsIDOMHTMLCollection
*elements
;
433 nsAString nsname
, nsstr
;
436 HRESULT hres
= DISP_E_UNKNOWNNAME
;
438 static const PRUnichar nameW
[] = {'n','a','m','e',0};
440 TRACE("(%p)->(%s %x %p)\n", This
, wine_dbgstr_w(name
), grfdex
, pid
);
442 nsres
= nsIDOMHTMLFormElement_GetElements(This
->nsform
, &elements
);
443 if(NS_FAILED(nsres
)) {
444 FIXME("GetElements failed: 0x%08x\n", nsres
);
448 nsres
= nsIDOMHTMLCollection_GetLength(elements
, &len
);
449 if(NS_FAILED(nsres
)) {
450 FIXME("GetLength failed: 0x%08x\n", nsres
);
451 nsIDOMHTMLCollection_Release(elements
);
455 nsAString_InitDepend(&nsname
, nameW
);
456 nsAString_Init(&nsstr
, NULL
);
457 for(i
= 0; i
< len
; ++i
) {
459 nsIDOMHTMLElement
*nshtml_elem
;
460 const PRUnichar
*str
;
462 nsres
= nsIDOMHTMLCollection_Item(elements
, i
, &nsitem
);
463 if(NS_FAILED(nsres
)) {
464 FIXME("Item failed: 0x%08x\n", nsres
);
469 nsres
= nsIDOMNode_QueryInterface(nsitem
, &IID_nsIDOMHTMLElement
, (void**)&nshtml_elem
);
470 nsIDOMNode_Release(nsitem
);
471 if(NS_FAILED(nsres
)) {
472 FIXME("Failed to get nsIDOMHTMLNode interface: 0x%08x\n", nsres
);
477 /* compare by id attr */
478 nsres
= nsIDOMHTMLElement_GetId(nshtml_elem
, &nsstr
);
479 if(NS_FAILED(nsres
)) {
480 FIXME("GetId failed: 0x%08x\n", nsres
);
481 nsIDOMHTMLElement_Release(nshtml_elem
);
485 nsAString_GetData(&nsstr
, &str
);
486 if(!strcmpiW(str
, name
)) {
487 nsIDOMHTMLElement_Release(nshtml_elem
);
488 /* FIXME: using index for dispid */
489 *pid
= MSHTML_DISPID_CUSTOM_MIN
+ i
;
494 /* compare by name attr */
495 nsres
= nsIDOMHTMLElement_GetAttribute(nshtml_elem
, &nsname
, &nsstr
);
496 nsIDOMHTMLElement_Release(nshtml_elem
);
497 nsAString_GetData(&nsstr
, &str
);
498 if(!strcmpiW(str
, name
)) {
499 /* FIXME: using index for dispid */
500 *pid
= MSHTML_DISPID_CUSTOM_MIN
+ i
;
505 nsAString_Finish(&nsname
);
506 nsAString_Finish(&nsstr
);
508 nsIDOMHTMLCollection_Release(elements
);
513 static HRESULT
HTMLFormElement_invoke(HTMLDOMNode
*iface
,
514 DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*params
, VARIANT
*res
,
515 EXCEPINFO
*ei
, IServiceProvider
*caller
)
517 HTMLFormElement
*This
= HTMLFORM_NODE_THIS(iface
);
521 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, flags
, params
, res
, ei
, caller
);
523 hres
= htmlform_item(This
, id
- MSHTML_DISPID_CUSTOM_MIN
, &ret
);
528 V_VT(res
) = VT_DISPATCH
;
529 V_DISPATCH(res
) = ret
;
536 #undef HTMLFORM_NODE_THIS
538 static const NodeImplVtbl HTMLFormElementImplVtbl
= {
540 HTMLFormElement_destructor
,
547 HTMLFormElement_get_dispid
,
548 HTMLFormElement_invoke
551 static const tid_t HTMLFormElement_iface_tids
[] = {
553 IHTMLFormElement_tid
,
557 static dispex_static_data_t HTMLFormElement_dispex
= {
559 DispHTMLFormElement_tid
,
561 HTMLFormElement_iface_tids
564 HTMLElement
*HTMLFormElement_Create(HTMLDocumentNode
*doc
, nsIDOMHTMLElement
*nselem
)
566 HTMLFormElement
*ret
= heap_alloc_zero(sizeof(HTMLFormElement
));
569 ret
->lpHTMLFormElementVtbl
= &HTMLFormElementVtbl
;
570 ret
->element
.node
.vtbl
= &HTMLFormElementImplVtbl
;
572 HTMLElement_Init(&ret
->element
, doc
, nselem
, &HTMLFormElement_dispex
);
574 nsres
= nsIDOMHTMLElement_QueryInterface(nselem
, &IID_nsIDOMHTMLFormElement
, (void**)&ret
->nsform
);
576 ERR("Could not get nsIDOMHTMLFormElement interface: %08x\n", nsres
);
578 return &ret
->element
;