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 #define HTMLFORM_THIS(iface) DEFINE_THIS(HTMLFormElement, HTMLFormElement, iface)
46 static HRESULT WINAPI
HTMLFormElement_QueryInterface(IHTMLFormElement
*iface
,
47 REFIID riid
, void **ppv
)
49 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
51 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(&This
->element
.node
), riid
, ppv
);
54 static ULONG WINAPI
HTMLFormElement_AddRef(IHTMLFormElement
*iface
)
56 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
58 return IHTMLDOMNode_AddRef(HTMLDOMNODE(&This
->element
.node
));
61 static ULONG WINAPI
HTMLFormElement_Release(IHTMLFormElement
*iface
)
63 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
65 return IHTMLDOMNode_Release(HTMLDOMNODE(&This
->element
.node
));
68 static HRESULT WINAPI
HTMLFormElement_GetTypeInfoCount(IHTMLFormElement
*iface
, UINT
*pctinfo
)
70 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
71 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This
->element
.node
.dispex
), pctinfo
);
74 static HRESULT WINAPI
HTMLFormElement_GetTypeInfo(IHTMLFormElement
*iface
, UINT iTInfo
,
75 LCID lcid
, ITypeInfo
**ppTInfo
)
77 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
78 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This
->element
.node
.dispex
), iTInfo
, lcid
, ppTInfo
);
81 static HRESULT WINAPI
HTMLFormElement_GetIDsOfNames(IHTMLFormElement
*iface
, REFIID riid
,
82 LPOLESTR
*rgszNames
, UINT cNames
,
83 LCID lcid
, DISPID
*rgDispId
)
85 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
86 return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This
->element
.node
.dispex
), riid
, rgszNames
, cNames
, lcid
, rgDispId
);
89 static HRESULT WINAPI
HTMLFormElement_Invoke(IHTMLFormElement
*iface
, DISPID dispIdMember
,
90 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
91 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
93 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
94 return IDispatchEx_Invoke(DISPATCHEX(&This
->element
.node
.dispex
), dispIdMember
, riid
, lcid
, wFlags
, pDispParams
,
95 pVarResult
, pExcepInfo
, puArgErr
);
98 static HRESULT WINAPI
HTMLFormElement_put_action(IHTMLFormElement
*iface
, BSTR v
)
100 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
101 FIXME("(%p)->(%s)\n", This
, wine_dbgstr_w(v
));
105 static HRESULT WINAPI
HTMLFormElement_get_action(IHTMLFormElement
*iface
, BSTR
*p
)
107 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
108 FIXME("(%p)->(%p)\n", This
, p
);
112 static HRESULT WINAPI
HTMLFormElement_put_dir(IHTMLFormElement
*iface
, BSTR v
)
114 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
115 FIXME("(%p)->(%s)\n", This
, wine_dbgstr_w(v
));
119 static HRESULT WINAPI
HTMLFormElement_get_dir(IHTMLFormElement
*iface
, BSTR
*p
)
121 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
122 FIXME("(%p)->(%p)\n", This
, p
);
126 static HRESULT WINAPI
HTMLFormElement_put_encoding(IHTMLFormElement
*iface
, BSTR v
)
128 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
129 FIXME("(%p)->(%s)\n", This
, wine_dbgstr_w(v
));
133 static HRESULT WINAPI
HTMLFormElement_get_encoding(IHTMLFormElement
*iface
, BSTR
*p
)
135 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
136 FIXME("(%p)->(%p)\n", This
, p
);
140 static HRESULT WINAPI
HTMLFormElement_put_method(IHTMLFormElement
*iface
, BSTR v
)
142 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
143 FIXME("(%p)->(%s)\n", This
, wine_dbgstr_w(v
));
147 static HRESULT WINAPI
HTMLFormElement_get_method(IHTMLFormElement
*iface
, BSTR
*p
)
149 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
150 FIXME("(%p)->(%p)\n", This
, p
);
154 static HRESULT WINAPI
HTMLFormElement_get_elements(IHTMLFormElement
*iface
, IDispatch
**p
)
156 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
157 FIXME("(%p)->(%p)\n", This
, p
);
161 static HRESULT WINAPI
HTMLFormElement_put_target(IHTMLFormElement
*iface
, BSTR v
)
163 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
164 FIXME("(%p)->(%s)\n", This
, wine_dbgstr_w(v
));
168 static HRESULT WINAPI
HTMLFormElement_get_target(IHTMLFormElement
*iface
, BSTR
*p
)
170 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
171 FIXME("(%p)->(%p)\n", This
, p
);
175 static HRESULT WINAPI
HTMLFormElement_put_name(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_name(IHTMLFormElement
*iface
, BSTR
*p
)
184 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
185 FIXME("(%p)->(%p)\n", This
, p
);
189 static HRESULT WINAPI
HTMLFormElement_put_onsubmit(IHTMLFormElement
*iface
, VARIANT v
)
191 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
192 FIXME("(%p)->(v)\n", This
);
196 static HRESULT WINAPI
HTMLFormElement_get_onsubmit(IHTMLFormElement
*iface
, VARIANT
*p
)
198 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
199 FIXME("(%p)->(%p)\n", This
, p
);
203 static HRESULT WINAPI
HTMLFormElement_put_onreset(IHTMLFormElement
*iface
, VARIANT v
)
205 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
206 FIXME("(%p)->(v)\n", This
);
210 static HRESULT WINAPI
HTMLFormElement_get_onreset(IHTMLFormElement
*iface
, VARIANT
*p
)
212 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
213 FIXME("(%p)->(%p)\n", This
, p
);
217 static HRESULT WINAPI
HTMLFormElement_submit(IHTMLFormElement
*iface
)
219 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
220 FIXME("(%p)->()\n", This
);
224 static HRESULT WINAPI
HTMLFormElement_reset(IHTMLFormElement
*iface
)
226 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
227 FIXME("(%p)->()\n", This
);
231 static HRESULT WINAPI
HTMLFormElement_put_length(IHTMLFormElement
*iface
, LONG v
)
233 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
234 FIXME("(%p)->(%d)\n", This
, v
);
238 static HRESULT WINAPI
HTMLFormElement_get_length(IHTMLFormElement
*iface
, LONG
*p
)
240 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
241 FIXME("(%p)->(%p)\n", This
, p
);
245 static HRESULT WINAPI
HTMLFormElement__newEnum(IHTMLFormElement
*iface
, IUnknown
**p
)
247 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
248 FIXME("(%p)->(%p)\n", This
, p
);
252 static HRESULT WINAPI
HTMLFormElement_item(IHTMLFormElement
*iface
, VARIANT name
,
253 VARIANT index
, IDispatch
**pdisp
)
255 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
256 FIXME("(%p)->(v v %p)\n", This
, pdisp
);
260 static HRESULT WINAPI
HTMLFormElement_tags(IHTMLFormElement
*iface
, VARIANT tagName
,
263 HTMLFormElement
*This
= HTMLFORM_THIS(iface
);
264 FIXME("(%p)->(v %p)\n", This
, pdisp
);
270 static const IHTMLFormElementVtbl HTMLFormElementVtbl
= {
271 HTMLFormElement_QueryInterface
,
272 HTMLFormElement_AddRef
,
273 HTMLFormElement_Release
,
274 HTMLFormElement_GetTypeInfoCount
,
275 HTMLFormElement_GetTypeInfo
,
276 HTMLFormElement_GetIDsOfNames
,
277 HTMLFormElement_Invoke
,
278 HTMLFormElement_put_action
,
279 HTMLFormElement_get_action
,
280 HTMLFormElement_put_dir
,
281 HTMLFormElement_get_dir
,
282 HTMLFormElement_put_encoding
,
283 HTMLFormElement_get_encoding
,
284 HTMLFormElement_put_method
,
285 HTMLFormElement_get_method
,
286 HTMLFormElement_get_elements
,
287 HTMLFormElement_put_target
,
288 HTMLFormElement_get_target
,
289 HTMLFormElement_put_name
,
290 HTMLFormElement_get_name
,
291 HTMLFormElement_put_onsubmit
,
292 HTMLFormElement_get_onsubmit
,
293 HTMLFormElement_put_onreset
,
294 HTMLFormElement_get_onreset
,
295 HTMLFormElement_submit
,
296 HTMLFormElement_reset
,
297 HTMLFormElement_put_length
,
298 HTMLFormElement_get_length
,
299 HTMLFormElement__newEnum
,
300 HTMLFormElement_item
,
304 #define HTMLFORM_NODE_THIS(iface) DEFINE_THIS2(HTMLFormElement, element.node, iface)
306 static HRESULT
HTMLFormElement_QI(HTMLDOMNode
*iface
, REFIID riid
, void **ppv
)
308 HTMLFormElement
*This
= HTMLFORM_NODE_THIS(iface
);
312 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
313 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
314 *ppv
= HTMLFORM(This
);
315 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
316 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
317 *ppv
= HTMLFORM(This
);
318 }else if(IsEqualGUID(&IID_IHTMLFormElement
, riid
)) {
319 TRACE("(%p)->(IID_IHTMLFormElement %p)\n", This
, ppv
);
320 *ppv
= HTMLFORM(This
);
324 IUnknown_AddRef((IUnknown
*)*ppv
);
328 return HTMLElement_QI(&This
->element
.node
, riid
, ppv
);
331 static void HTMLFormElement_destructor(HTMLDOMNode
*iface
)
333 HTMLFormElement
*This
= HTMLFORM_NODE_THIS(iface
);
336 nsIDOMHTMLFormElement_Release(This
->nsform
);
338 HTMLElement_destructor(&This
->element
.node
);
341 static HRESULT
HTMLFormElement_get_dispid(HTMLDOMNode
*iface
,
342 BSTR name
, DWORD grfdex
, DISPID
*pid
)
344 HTMLFormElement
*This
= HTMLFORM_NODE_THIS(iface
);
345 nsIDOMHTMLCollection
*elements
;
346 nsAString nsname
, nsstr
;
349 HRESULT hres
= DISP_E_UNKNOWNNAME
;
351 static const PRUnichar nameW
[] = {'n','a','m','e',0};
353 TRACE("(%p)->(%s %x %p)\n", This
, wine_dbgstr_w(name
), grfdex
, pid
);
355 nsres
= nsIDOMHTMLFormElement_GetElements(This
->nsform
, &elements
);
356 if(NS_FAILED(nsres
)) {
357 FIXME("GetElements failed: 0x%08x\n", nsres
);
361 nsres
= nsIDOMHTMLCollection_GetLength(elements
, &len
);
362 if(NS_FAILED(nsres
)) {
363 FIXME("GetLength failed: 0x%08x\n", nsres
);
364 nsIDOMHTMLCollection_Release(elements
);
368 nsAString_InitDepend(&nsname
, nameW
);
369 nsAString_Init(&nsstr
, NULL
);
370 for(i
= 0; i
< len
; ++i
) {
372 nsIDOMHTMLElement
*nshtml_elem
;
373 const PRUnichar
*str
;
375 nsres
= nsIDOMHTMLCollection_Item(elements
, i
, &nsitem
);
376 if(NS_FAILED(nsres
)) {
377 FIXME("Item failed: 0x%08x\n", nsres
);
382 nsres
= nsIDOMNode_QueryInterface(nsitem
, &IID_nsIDOMHTMLElement
, (void**)&nshtml_elem
);
383 nsIDOMNode_Release(nsitem
);
384 if(NS_FAILED(nsres
)) {
385 FIXME("Failed to get nsIDOMHTMLNode interface: 0x%08x\n", nsres
);
390 /* compare by id attr */
391 nsres
= nsIDOMHTMLElement_GetId(nshtml_elem
, &nsstr
);
392 if(NS_FAILED(nsres
)) {
393 FIXME("GetId failed: 0x%08x\n", nsres
);
394 nsIDOMHTMLElement_Release(nshtml_elem
);
398 nsAString_GetData(&nsstr
, &str
);
399 if(!strcmpiW(str
, name
)) {
400 nsIDOMHTMLElement_Release(nshtml_elem
);
401 /* FIXME: using index for dispid */
402 *pid
= MSHTML_DISPID_CUSTOM_MIN
+ i
;
407 /* compare by name attr */
408 nsres
= nsIDOMHTMLElement_GetAttribute(nshtml_elem
, &nsname
, &nsstr
);
409 nsIDOMHTMLElement_Release(nshtml_elem
);
410 nsAString_GetData(&nsstr
, &str
);
411 if(!strcmpiW(str
, name
)) {
412 /* FIXME: using index for dispid */
413 *pid
= MSHTML_DISPID_CUSTOM_MIN
+ i
;
418 nsAString_Finish(&nsname
);
419 nsAString_Finish(&nsstr
);
421 nsIDOMHTMLCollection_Release(elements
);
426 static HRESULT
HTMLFormElement_invoke(HTMLDOMNode
*iface
,
427 DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*params
, VARIANT
*res
,
428 EXCEPINFO
*ei
, IServiceProvider
*caller
)
430 HTMLFormElement
*This
= HTMLFORM_NODE_THIS(iface
);
431 nsIDOMHTMLCollection
*elements
;
436 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, flags
, params
, res
, ei
, caller
);
438 nsres
= nsIDOMHTMLFormElement_GetElements(This
->nsform
, &elements
);
439 if(NS_FAILED(nsres
)) {
440 FIXME("GetElements failed: 0x%08x\n", nsres
);
444 nsres
= nsIDOMHTMLCollection_Item(elements
, id
- MSHTML_DISPID_CUSTOM_MIN
, &item
);
445 nsIDOMHTMLCollection_Release(elements
);
446 if(NS_FAILED(nsres
)) {
447 FIXME("Item failed: 0x%08x\n", nsres
);
451 node
= get_node(This
->element
.node
.doc
, item
, TRUE
);
453 V_VT(res
) = VT_DISPATCH
;
454 V_DISPATCH(res
) = (IDispatch
*)node
;
456 IHTMLDOMNode_AddRef(HTMLDOMNODE(node
));
457 nsIDOMNode_Release(item
);
462 #undef HTMLFORM_NODE_THIS
464 static const NodeImplVtbl HTMLFormElementImplVtbl
= {
466 HTMLFormElement_destructor
,
473 HTMLFormElement_get_dispid
,
474 HTMLFormElement_invoke
477 static const tid_t HTMLFormElement_iface_tids
[] = {
479 IHTMLFormElement_tid
,
483 static dispex_static_data_t HTMLFormElement_dispex
= {
485 DispHTMLFormElement_tid
,
487 HTMLFormElement_iface_tids
490 HTMLElement
*HTMLFormElement_Create(HTMLDocumentNode
*doc
, nsIDOMHTMLElement
*nselem
)
492 HTMLFormElement
*ret
= heap_alloc_zero(sizeof(HTMLFormElement
));
495 ret
->lpHTMLFormElementVtbl
= &HTMLFormElementVtbl
;
496 ret
->element
.node
.vtbl
= &HTMLFormElementImplVtbl
;
498 HTMLElement_Init(&ret
->element
, doc
, nselem
, &HTMLFormElement_dispex
);
500 nsres
= nsIDOMHTMLElement_QueryInterface(nselem
, &IID_nsIDOMHTMLFormElement
, (void**)&ret
->nsform
);
502 ERR("Could not get nsIDOMHTMLFormElement interface: %08x\n", nsres
);
504 return &ret
->element
;