jscript: Don't use DISPPARAMS for internal arguments.
[wine] / dlls / mshtml / htmldoc3.c
1 /*
2  * Copyright 2005 Jacek Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include "config.h"
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #define COBJMACROS
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "ole2.h"
30
31 #include "wine/debug.h"
32
33 #include "mshtml_private.h"
34 #include "htmlevent.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
37
38 static inline HTMLDocument *impl_from_IHTMLDocument3(IHTMLDocument3 *iface)
39 {
40     return CONTAINING_RECORD(iface, HTMLDocument, IHTMLDocument3_iface);
41 }
42
43 static HRESULT WINAPI HTMLDocument3_QueryInterface(IHTMLDocument3 *iface,
44                                                   REFIID riid, void **ppv)
45 {
46     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
47     return htmldoc_query_interface(This, riid, ppv);
48 }
49
50 static ULONG WINAPI HTMLDocument3_AddRef(IHTMLDocument3 *iface)
51 {
52     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
53     return htmldoc_addref(This);
54 }
55
56 static ULONG WINAPI HTMLDocument3_Release(IHTMLDocument3 *iface)
57 {
58     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
59     return htmldoc_release(This);
60 }
61
62 static HRESULT WINAPI HTMLDocument3_GetTypeInfoCount(IHTMLDocument3 *iface, UINT *pctinfo)
63 {
64     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
65     return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
66 }
67
68 static HRESULT WINAPI HTMLDocument3_GetTypeInfo(IHTMLDocument3 *iface, UINT iTInfo,
69                                                 LCID lcid, ITypeInfo **ppTInfo)
70 {
71     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
72     return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
73 }
74
75 static HRESULT WINAPI HTMLDocument3_GetIDsOfNames(IHTMLDocument3 *iface, REFIID riid,
76                                                 LPOLESTR *rgszNames, UINT cNames,
77                                                 LCID lcid, DISPID *rgDispId)
78 {
79     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
80     return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
81             rgDispId);
82 }
83
84 static HRESULT WINAPI HTMLDocument3_Invoke(IHTMLDocument3 *iface, DISPID dispIdMember,
85                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
86                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
87 {
88     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
89     return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
90             pDispParams, pVarResult, pExcepInfo, puArgErr);
91 }
92
93 static HRESULT WINAPI HTMLDocument3_releaseCapture(IHTMLDocument3 *iface)
94 {
95     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
96     FIXME("(%p)\n", This);
97     return E_NOTIMPL;
98 }
99
100 static HRESULT WINAPI HTMLDocument3_recalc(IHTMLDocument3 *iface, VARIANT_BOOL fForce)
101 {
102     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
103     FIXME("(%p)->(%x)\n", This, fForce);
104     return E_NOTIMPL;
105 }
106
107 static HRESULT WINAPI HTMLDocument3_createTextNode(IHTMLDocument3 *iface, BSTR text,
108                                                    IHTMLDOMNode **newTextNode)
109 {
110     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
111     nsIDOMText *nstext;
112     HTMLDOMNode *node;
113     nsAString text_str;
114     nsresult nsres;
115     HRESULT hres;
116
117     TRACE("(%p)->(%s %p)\n", This, debugstr_w(text), newTextNode);
118
119     if(!This->doc_node->nsdoc) {
120         WARN("NULL nsdoc\n");
121         return E_UNEXPECTED;
122     }
123
124     nsAString_InitDepend(&text_str, text);
125     nsres = nsIDOMHTMLDocument_CreateTextNode(This->doc_node->nsdoc, &text_str, &nstext);
126     nsAString_Finish(&text_str);
127     if(NS_FAILED(nsres)) {
128         ERR("CreateTextNode failed: %08x\n", nsres);
129         return E_FAIL;
130     }
131
132     hres = HTMLDOMTextNode_Create(This->doc_node, (nsIDOMNode*)nstext, &node);
133     nsIDOMElement_Release(nstext);
134     if(FAILED(hres))
135         return hres;
136
137     *newTextNode = &node->IHTMLDOMNode_iface;
138     IHTMLDOMNode_AddRef(&node->IHTMLDOMNode_iface);
139     return S_OK;
140 }
141
142 static HRESULT WINAPI HTMLDocument3_get_documentElement(IHTMLDocument3 *iface, IHTMLElement **p)
143 {
144     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
145     nsIDOMElement *nselem = NULL;
146     HTMLDOMNode *node;
147     nsresult nsres;
148     HRESULT hres;
149
150     TRACE("(%p)->(%p)\n", This, p);
151
152     if(This->window->readystate == READYSTATE_UNINITIALIZED) {
153         *p = NULL;
154         return S_OK;
155     }
156
157     if(!This->doc_node->nsdoc) {
158         WARN("NULL nsdoc\n");
159         return E_UNEXPECTED;
160     }
161
162     nsres = nsIDOMHTMLDocument_GetDocumentElement(This->doc_node->nsdoc, &nselem);
163     if(NS_FAILED(nsres)) {
164         ERR("GetDocumentElement failed: %08x\n", nsres);
165         return E_FAIL;
166     }
167
168     if(!nselem) {
169         *p = NULL;
170         return S_OK;
171     }
172
173     hres = get_node(This->doc_node, (nsIDOMNode *)nselem, TRUE, &node);
174     nsIDOMElement_Release(nselem);
175     if(FAILED(hres))
176         return hres;
177
178     hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)p);
179     node_release(node);
180     return hres;
181 }
182
183 static HRESULT WINAPI HTMLDocument3_uniqueID(IHTMLDocument3 *iface, BSTR *p)
184 {
185     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
186     FIXME("(%p)->(%p)\n", This, p);
187     return E_NOTIMPL;
188 }
189
190 static HRESULT WINAPI HTMLDocument3_attachEvent(IHTMLDocument3 *iface, BSTR event,
191                                                 IDispatch* pDisp, VARIANT_BOOL *pfResult)
192 {
193     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
194
195     TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(event), pDisp, pfResult);
196
197     return attach_event(&This->doc_node->node.event_target, This->doc_node->node.nsnode, This, event, pDisp, pfResult);
198 }
199
200 static HRESULT WINAPI HTMLDocument3_detachEvent(IHTMLDocument3 *iface, BSTR event,
201                                                 IDispatch *pDisp)
202 {
203     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
204
205     TRACE("(%p)->(%s %p)\n", This, debugstr_w(event), pDisp);
206
207     return detach_event(This->doc_node->node.event_target, This, event, pDisp);
208 }
209
210 static HRESULT WINAPI HTMLDocument3_put_onrowsdelete(IHTMLDocument3 *iface, VARIANT v)
211 {
212     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
213     FIXME("(%p)->()\n", This);
214     return E_NOTIMPL;
215 }
216
217 static HRESULT WINAPI HTMLDocument3_get_onrowsdelete(IHTMLDocument3 *iface, VARIANT *p)
218 {
219     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
220     FIXME("(%p)->(%p)\n", This, p);
221     return E_NOTIMPL;
222 }
223
224 static HRESULT WINAPI HTMLDocument3_put_onrowsinserted(IHTMLDocument3 *iface, VARIANT v)
225 {
226     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
227     FIXME("(%p)->()\n", This);
228     return E_NOTIMPL;
229 }
230
231 static HRESULT WINAPI HTMLDocument3_get_onrowsinserted(IHTMLDocument3 *iface, VARIANT *p)
232 {
233     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
234     FIXME("(%p)->(%p)\n", This, p);
235     return E_NOTIMPL;
236 }
237
238 static HRESULT WINAPI HTMLDocument3_put_oncellchange(IHTMLDocument3 *iface, VARIANT v)
239 {
240     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
241     FIXME("(%p)->()\n", This);
242     return E_NOTIMPL;
243 }
244
245 static HRESULT WINAPI HTMLDocument3_get_oncellchange(IHTMLDocument3 *iface, VARIANT *p)
246 {
247     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
248     FIXME("(%p)->(%p)\n", This, p);
249     return E_NOTIMPL;
250 }
251
252 static HRESULT WINAPI HTMLDocument3_put_ondatasetchanged(IHTMLDocument3 *iface, VARIANT v)
253 {
254     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
255     FIXME("(%p)->()\n", This);
256     return E_NOTIMPL;
257 }
258
259 static HRESULT WINAPI HTMLDocument3_get_ondatasetchanged(IHTMLDocument3 *iface, VARIANT *p)
260 {
261     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
262     FIXME("(%p)->(%p)\n", This, p);
263     return E_NOTIMPL;
264 }
265
266 static HRESULT WINAPI HTMLDocument3_put_ondataavailable(IHTMLDocument3 *iface, VARIANT v)
267 {
268     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
269     FIXME("(%p)->()\n", This);
270     return E_NOTIMPL;
271 }
272
273 static HRESULT WINAPI HTMLDocument3_get_ondataavailable(IHTMLDocument3 *iface, VARIANT *p)
274 {
275     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
276     FIXME("(%p)->(%p)\n", This, p);
277     return E_NOTIMPL;
278 }
279
280 static HRESULT WINAPI HTMLDocument3_put_ondatasetcomplete(IHTMLDocument3 *iface, VARIANT v)
281 {
282     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
283     FIXME("(%p)->()\n", This);
284     return E_NOTIMPL;
285 }
286
287 static HRESULT WINAPI HTMLDocument3_get_ondatasetcomplete(IHTMLDocument3 *iface, VARIANT *p)
288 {
289     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
290     FIXME("(%p)->(%p)\n", This, p);
291     return E_NOTIMPL;
292 }
293
294 static HRESULT WINAPI HTMLDocument3_put_onpropertychange(IHTMLDocument3 *iface, VARIANT v)
295 {
296     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
297     FIXME("(%p)->()\n", This);
298     return E_NOTIMPL;
299 }
300
301 static HRESULT WINAPI HTMLDocument3_get_onpropertychange(IHTMLDocument3 *iface, VARIANT *p)
302 {
303     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
304     FIXME("(%p)->(%p)\n", This, p);
305     return E_NOTIMPL;
306 }
307
308 static HRESULT WINAPI HTMLDocument3_put_dir(IHTMLDocument3 *iface, BSTR v)
309 {
310     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
311     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
312     return E_NOTIMPL;
313 }
314
315 static HRESULT WINAPI HTMLDocument3_get_dir(IHTMLDocument3 *iface, BSTR *p)
316 {
317     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
318     FIXME("(%p)->(%p)\n", This, p);
319     return E_NOTIMPL;
320 }
321
322 static HRESULT WINAPI HTMLDocument3_put_oncontextmenu(IHTMLDocument3 *iface, VARIANT v)
323 {
324     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
325
326     TRACE("(%p)->()\n", This);
327
328     return set_doc_event(This, EVENTID_CONTEXTMENU, &v);
329 }
330
331 static HRESULT WINAPI HTMLDocument3_get_oncontextmenu(IHTMLDocument3 *iface, VARIANT *p)
332 {
333     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
334
335     TRACE("(%p)->(%p)\n", This, p);
336
337     return get_doc_event(This, EVENTID_CONTEXTMENU, p);
338 }
339
340 static HRESULT WINAPI HTMLDocument3_put_onstop(IHTMLDocument3 *iface, VARIANT v)
341 {
342     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
343     FIXME("(%p)->()\n", This);
344     return E_NOTIMPL;
345 }
346
347 static HRESULT WINAPI HTMLDocument3_get_onstop(IHTMLDocument3 *iface, VARIANT *p)
348 {
349     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
350     FIXME("(%p)->(%p)\n", This, p);
351     return E_NOTIMPL;
352 }
353
354 static HRESULT WINAPI HTMLDocument3_createDocumentFragment(IHTMLDocument3 *iface,
355                                                            IHTMLDocument2 **ppNewDoc)
356 {
357     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
358     nsIDOMDocumentFragment *doc_frag;
359     HTMLDocumentNode *docnode;
360     nsresult nsres;
361     HRESULT hres;
362
363     TRACE("(%p)->(%p)\n", This, ppNewDoc);
364
365     if(!This->doc_node->nsdoc) {
366         FIXME("NULL nsdoc\n");
367         return E_NOTIMPL;
368     }
369
370     nsres = nsIDOMHTMLDocument_CreateDocumentFragment(This->doc_node->nsdoc, &doc_frag);
371     if(NS_FAILED(nsres)) {
372         ERR("CreateDocumentFragment failed: %08x\n", nsres);
373         return E_FAIL;
374     }
375
376     hres = create_document_fragment((nsIDOMNode*)doc_frag, This->doc_node, &docnode);
377     nsIDOMDocumentFragment_Release(doc_frag);
378     if(FAILED(hres))
379         return hres;
380
381     *ppNewDoc = &docnode->basedoc.IHTMLDocument2_iface;
382     return S_OK;
383 }
384
385 static HRESULT WINAPI HTMLDocument3_get_parentDocument(IHTMLDocument3 *iface,
386                                                        IHTMLDocument2 **p)
387 {
388     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
389     FIXME("(%p)->(%p)\n", This, p);
390     return E_NOTIMPL;
391 }
392
393 static HRESULT WINAPI HTMLDocument3_put_enableDownload(IHTMLDocument3 *iface,
394                                                        VARIANT_BOOL v)
395 {
396     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
397     FIXME("(%p)->(%x)\n", This, v);
398     return E_NOTIMPL;
399 }
400
401 static HRESULT WINAPI HTMLDocument3_get_enableDownload(IHTMLDocument3 *iface,
402                                                        VARIANT_BOOL *p)
403 {
404     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
405     FIXME("(%p)->(%p)\n", This, p);
406     return E_NOTIMPL;
407 }
408
409 static HRESULT WINAPI HTMLDocument3_put_baseUrl(IHTMLDocument3 *iface, BSTR v)
410 {
411     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
412     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
413     return E_NOTIMPL;
414 }
415
416 static HRESULT WINAPI HTMLDocument3_get_baseUrl(IHTMLDocument3 *iface, BSTR *p)
417 {
418     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
419     FIXME("(%p)->(%p)\n", This, p);
420     return E_NOTIMPL;
421 }
422
423 static HRESULT WINAPI HTMLDocument3_get_childNodes(IHTMLDocument3 *iface, IDispatch **p)
424 {
425     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
426     FIXME("(%p)->(%p)\n", This, p);
427     return E_NOTIMPL;
428 }
429
430 static HRESULT WINAPI HTMLDocument3_put_inheritStyleSheets(IHTMLDocument3 *iface,
431                                                            VARIANT_BOOL v)
432 {
433     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
434     FIXME("(%p)->()\n", This);
435     return E_NOTIMPL;
436 }
437
438 static HRESULT WINAPI HTMLDocument3_get_inheritStyleSheets(IHTMLDocument3 *iface,
439                                                            VARIANT_BOOL *p)
440 {
441     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
442     FIXME("(%p)->(%p)\n", This, p);
443     return E_NOTIMPL;
444 }
445
446 static HRESULT WINAPI HTMLDocument3_put_onbeforeeditfocus(IHTMLDocument3 *iface, VARIANT v)
447 {
448     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
449     FIXME("(%p)->()\n", This);
450     return E_NOTIMPL;
451 }
452
453 static HRESULT WINAPI HTMLDocument3_get_onbeforeeditfocus(IHTMLDocument3 *iface, VARIANT *p)
454 {
455     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
456     FIXME("(%p)->(%p)\n", This, p);
457     return E_NOTIMPL;
458 }
459
460 static HRESULT WINAPI HTMLDocument3_getElementsByName(IHTMLDocument3 *iface, BSTR v,
461                                                       IHTMLElementCollection **ppelColl)
462 {
463     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
464     FIXME("(%p)->(%s %p)\n", This, debugstr_w(v), ppelColl);
465     return E_NOTIMPL;
466 }
467
468
469 static HRESULT WINAPI HTMLDocument3_getElementById(IHTMLDocument3 *iface, BSTR v,
470                                                    IHTMLElement **pel)
471 {
472     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
473     nsIDOMElement *nselem;
474     HTMLDOMNode *node;
475     nsIDOMNode *nsnode, *nsnode_by_id, *nsnode_by_name;
476     nsIDOMNodeList *nsnode_list;
477     nsAString id_str;
478     nsresult nsres;
479     HRESULT hres;
480
481     TRACE("(%p)->(%s %p)\n", This, debugstr_w(v), pel);
482
483     if(!This->doc_node->nsdoc) {
484         WARN("NULL nsdoc\n");
485         return E_UNEXPECTED;
486     }
487
488     nsAString_InitDepend(&id_str, v);
489     /* get element by id attribute */
490     nsres = nsIDOMHTMLDocument_GetElementById(This->doc_node->nsdoc, &id_str, &nselem);
491     if(FAILED(nsres)) {
492         ERR("GetElementById failed: %08x\n", nsres);
493         nsAString_Finish(&id_str);
494         return E_FAIL;
495     }
496     nsnode_by_id = (nsIDOMNode*)nselem;
497
498     /* get first element by name attribute */
499     nsres = nsIDOMHTMLDocument_GetElementsByName(This->doc_node->nsdoc, &id_str, &nsnode_list);
500     nsAString_Finish(&id_str);
501     if(FAILED(nsres)) {
502         ERR("getElementsByName failed: %08x\n", nsres);
503         if(nsnode_by_id)
504             nsIDOMNode_Release(nsnode_by_id);
505         return E_FAIL;
506     }
507     nsIDOMNodeList_Item(nsnode_list, 0, &nsnode_by_name);
508     nsIDOMNodeList_Release(nsnode_list);
509
510
511     if(nsnode_by_name && nsnode_by_id) {
512         PRUint16 pos;
513
514         nsres = nsIDOMNode_CompareDocumentPosition(nsnode_by_name, nsnode_by_id, &pos);
515         if(NS_FAILED(nsres)) {
516             FIXME("CompareDocumentPosition failed: 0x%08x\n", nsres);
517             nsIDOMNode_Release(nsnode_by_name);
518             nsIDOMNode_Release(nsnode_by_id);
519             return E_FAIL;
520         }
521
522         TRACE("CompareDocumentPosition gave: 0x%x\n", pos);
523         if(pos & (DOCUMENT_POSITION_PRECEDING | DOCUMENT_POSITION_CONTAINS)) {
524             nsnode = nsnode_by_id;
525             nsIDOMNode_Release(nsnode_by_name);
526         }else {
527             nsnode = nsnode_by_name;
528             nsIDOMNode_Release(nsnode_by_id);
529         }
530     }else
531         nsnode = nsnode_by_name ? nsnode_by_name : nsnode_by_id;
532
533     if(nsnode) {
534         hres = get_node(This->doc_node, nsnode, TRUE, &node);
535         nsIDOMNode_Release(nsnode);
536
537         if(SUCCEEDED(hres)) {
538             hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)pel);
539             node_release(node);
540         }
541     }else {
542         *pel = NULL;
543         hres = S_OK;
544     }
545
546     return hres;
547 }
548
549
550 static HRESULT WINAPI HTMLDocument3_getElementsByTagName(IHTMLDocument3 *iface, BSTR v,
551                                                          IHTMLElementCollection **pelColl)
552 {
553     HTMLDocument *This = impl_from_IHTMLDocument3(iface);
554     nsIDOMNodeList *nslist;
555     nsAString id_str, ns_str;
556     nsresult nsres;
557     static const WCHAR str[] = {'*',0};
558
559     TRACE("(%p)->(%s %p)\n", This, debugstr_w(v), pelColl);
560
561     if(!This->doc_node->nsdoc) {
562         WARN("NULL nsdoc\n");
563         return E_UNEXPECTED;
564     }
565
566     nsAString_InitDepend(&id_str, v);
567     nsAString_InitDepend(&ns_str, str);
568     nsres = nsIDOMHTMLDocument_GetElementsByTagNameNS(This->doc_node->nsdoc, &ns_str, &id_str, &nslist);
569     nsAString_Finish(&id_str);
570     nsAString_Finish(&ns_str);
571     if(FAILED(nsres)) {
572         ERR("GetElementByName failed: %08x\n", nsres);
573         return E_FAIL;
574     }
575
576     *pelColl = create_collection_from_nodelist(This->doc_node,
577                                                (IUnknown*)&This->IHTMLDocument3_iface, nslist);
578     nsIDOMNodeList_Release(nslist);
579
580     return S_OK;
581 }
582
583 static const IHTMLDocument3Vtbl HTMLDocument3Vtbl = {
584     HTMLDocument3_QueryInterface,
585     HTMLDocument3_AddRef,
586     HTMLDocument3_Release,
587     HTMLDocument3_GetTypeInfoCount,
588     HTMLDocument3_GetTypeInfo,
589     HTMLDocument3_GetIDsOfNames,
590     HTMLDocument3_Invoke,
591     HTMLDocument3_releaseCapture,
592     HTMLDocument3_recalc,
593     HTMLDocument3_createTextNode,
594     HTMLDocument3_get_documentElement,
595     HTMLDocument3_uniqueID,
596     HTMLDocument3_attachEvent,
597     HTMLDocument3_detachEvent,
598     HTMLDocument3_put_onrowsdelete,
599     HTMLDocument3_get_onrowsdelete,
600     HTMLDocument3_put_onrowsinserted,
601     HTMLDocument3_get_onrowsinserted,
602     HTMLDocument3_put_oncellchange,
603     HTMLDocument3_get_oncellchange,
604     HTMLDocument3_put_ondatasetchanged,
605     HTMLDocument3_get_ondatasetchanged,
606     HTMLDocument3_put_ondataavailable,
607     HTMLDocument3_get_ondataavailable,
608     HTMLDocument3_put_ondatasetcomplete,
609     HTMLDocument3_get_ondatasetcomplete,
610     HTMLDocument3_put_onpropertychange,
611     HTMLDocument3_get_onpropertychange,
612     HTMLDocument3_put_dir,
613     HTMLDocument3_get_dir,
614     HTMLDocument3_put_oncontextmenu,
615     HTMLDocument3_get_oncontextmenu,
616     HTMLDocument3_put_onstop,
617     HTMLDocument3_get_onstop,
618     HTMLDocument3_createDocumentFragment,
619     HTMLDocument3_get_parentDocument,
620     HTMLDocument3_put_enableDownload,
621     HTMLDocument3_get_enableDownload,
622     HTMLDocument3_put_baseUrl,
623     HTMLDocument3_get_baseUrl,
624     HTMLDocument3_get_childNodes,
625     HTMLDocument3_put_inheritStyleSheets,
626     HTMLDocument3_get_inheritStyleSheets,
627     HTMLDocument3_put_onbeforeeditfocus,
628     HTMLDocument3_get_onbeforeeditfocus,
629     HTMLDocument3_getElementsByName,
630     HTMLDocument3_getElementById,
631     HTMLDocument3_getElementsByTagName
632 };
633
634 static inline HTMLDocument *impl_from_IHTMLDocument4(IHTMLDocument4 *iface)
635 {
636     return CONTAINING_RECORD(iface, HTMLDocument, IHTMLDocument4_iface);
637 }
638
639 static HRESULT WINAPI HTMLDocument4_QueryInterface(IHTMLDocument4 *iface,
640                                                    REFIID riid, void **ppv)
641 {
642     HTMLDocument *This = impl_from_IHTMLDocument4(iface);
643     return htmldoc_query_interface(This, riid, ppv);
644 }
645
646 static ULONG WINAPI HTMLDocument4_AddRef(IHTMLDocument4 *iface)
647 {
648     HTMLDocument *This = impl_from_IHTMLDocument4(iface);
649     return htmldoc_addref(This);
650 }
651
652 static ULONG WINAPI HTMLDocument4_Release(IHTMLDocument4 *iface)
653 {
654     HTMLDocument *This = impl_from_IHTMLDocument4(iface);
655     return htmldoc_release(This);
656 }
657
658 static HRESULT WINAPI HTMLDocument4_GetTypeInfoCount(IHTMLDocument4 *iface, UINT *pctinfo)
659 {
660     HTMLDocument *This = impl_from_IHTMLDocument4(iface);
661     return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
662 }
663
664 static HRESULT WINAPI HTMLDocument4_GetTypeInfo(IHTMLDocument4 *iface, UINT iTInfo,
665                                                 LCID lcid, ITypeInfo **ppTInfo)
666 {
667     HTMLDocument *This = impl_from_IHTMLDocument4(iface);
668     return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
669 }
670
671 static HRESULT WINAPI HTMLDocument4_GetIDsOfNames(IHTMLDocument4 *iface, REFIID riid,
672                                                 LPOLESTR *rgszNames, UINT cNames,
673                                                 LCID lcid, DISPID *rgDispId)
674 {
675     HTMLDocument *This = impl_from_IHTMLDocument4(iface);
676     return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
677             rgDispId);
678 }
679
680 static HRESULT WINAPI HTMLDocument4_Invoke(IHTMLDocument4 *iface, DISPID dispIdMember,
681                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
682                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
683 {
684     HTMLDocument *This = impl_from_IHTMLDocument4(iface);
685     return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
686             pDispParams, pVarResult, pExcepInfo, puArgErr);
687 }
688
689 static HRESULT WINAPI HTMLDocument4_focus(IHTMLDocument4 *iface)
690 {
691     HTMLDocument *This = impl_from_IHTMLDocument4(iface);
692     nsIDOMHTMLElement *nsbody;
693     nsresult nsres;
694
695     TRACE("(%p)->()\n", This);
696
697     nsres = nsIDOMHTMLDocument_GetBody(This->doc_node->nsdoc, &nsbody);
698     if(NS_FAILED(nsres) || !nsbody) {
699         ERR("GetBody failed: %08x\n", nsres);
700         return E_FAIL;
701     }
702
703     nsres = nsIDOMHTMLElement_Focus(nsbody);
704     nsIDOMHTMLElement_Release(nsbody);
705     if(NS_FAILED(nsres)) {
706         ERR("Focus failed: %08x\n", nsres);
707         return E_FAIL;
708     }
709
710     return S_OK;
711 }
712
713 static HRESULT WINAPI HTMLDocument4_hasFocus(IHTMLDocument4 *iface, VARIANT_BOOL *pfFocus)
714 {
715     HTMLDocument *This = impl_from_IHTMLDocument4(iface);
716     FIXME("(%p)->(%p)\n", This, pfFocus);
717     return E_NOTIMPL;
718 }
719
720 static HRESULT WINAPI HTMLDocument4_put_onselectionchange(IHTMLDocument4 *iface, VARIANT v)
721 {
722     HTMLDocument *This = impl_from_IHTMLDocument4(iface);
723     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
724     return E_NOTIMPL;
725 }
726
727 static HRESULT WINAPI HTMLDocument4_get_onselectionchange(IHTMLDocument4 *iface, VARIANT *p)
728 {
729     HTMLDocument *This = impl_from_IHTMLDocument4(iface);
730     FIXME("(%p)->(%p)\n", This, p);
731     return E_NOTIMPL;
732 }
733
734 static HRESULT WINAPI HTMLDocument4_get_namespace(IHTMLDocument4 *iface, IDispatch **p)
735 {
736     HTMLDocument *This = impl_from_IHTMLDocument4(iface);
737     FIXME("(%p)->(%p)\n", This, p);
738     return E_NOTIMPL;
739 }
740
741 static HRESULT WINAPI HTMLDocument4_createDocumentFromUrl(IHTMLDocument4 *iface, BSTR bstrUrl,
742         BSTR bstrOptions, IHTMLDocument2 **newDoc)
743 {
744     HTMLDocument *This = impl_from_IHTMLDocument4(iface);
745     FIXME("(%p)->(%s %s %p)\n", This, debugstr_w(bstrUrl), debugstr_w(bstrOptions), newDoc);
746     return E_NOTIMPL;
747 }
748
749 static HRESULT WINAPI HTMLDocument4_put_media(IHTMLDocument4 *iface, BSTR v)
750 {
751     HTMLDocument *This = impl_from_IHTMLDocument4(iface);
752     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
753     return E_NOTIMPL;
754 }
755
756 static HRESULT WINAPI HTMLDocument4_get_media(IHTMLDocument4 *iface, BSTR *p)
757 {
758     HTMLDocument *This = impl_from_IHTMLDocument4(iface);
759     FIXME("(%p)->(%p)\n", This, p);
760     return E_NOTIMPL;
761 }
762
763 static HRESULT WINAPI HTMLDocument4_createEventObject(IHTMLDocument4 *iface,
764         VARIANT *pvarEventObject, IHTMLEventObj **ppEventObj)
765 {
766     HTMLDocument *This = impl_from_IHTMLDocument4(iface);
767     FIXME("(%p)->(%p %p)\n", This, pvarEventObject, ppEventObj);
768     return E_NOTIMPL;
769 }
770
771 static HRESULT WINAPI HTMLDocument4_fireEvent(IHTMLDocument4 *iface, BSTR bstrEventName,
772         VARIANT *pvarEventObject, VARIANT_BOOL *pfCanceled)
773 {
774     HTMLDocument *This = impl_from_IHTMLDocument4(iface);
775     FIXME("(%p)->(%s %p %p)\n", This, debugstr_w(bstrEventName), pvarEventObject, pfCanceled);
776     return E_NOTIMPL;
777 }
778
779 static HRESULT WINAPI HTMLDocument4_createRenderStyle(IHTMLDocument4 *iface, BSTR v,
780         IHTMLRenderStyle **ppIHTMLRenderStyle)
781 {
782     HTMLDocument *This = impl_from_IHTMLDocument4(iface);
783     FIXME("(%p)->(%s %p)\n", This, debugstr_w(v), ppIHTMLRenderStyle);
784     return E_NOTIMPL;
785 }
786
787 static HRESULT WINAPI HTMLDocument4_put_oncontrolselect(IHTMLDocument4 *iface, VARIANT v)
788 {
789     HTMLDocument *This = impl_from_IHTMLDocument4(iface);
790     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
791     return E_NOTIMPL;
792 }
793
794 static HRESULT WINAPI HTMLDocument4_get_oncontrolselect(IHTMLDocument4 *iface, VARIANT *p)
795 {
796     HTMLDocument *This = impl_from_IHTMLDocument4(iface);
797     FIXME("(%p)->(%p)\n", This, p);
798     return E_NOTIMPL;
799 }
800
801 static HRESULT WINAPI HTMLDocument4_get_URLEncoded(IHTMLDocument4 *iface, BSTR *p)
802 {
803     HTMLDocument *This = impl_from_IHTMLDocument4(iface);
804     FIXME("(%p)->(%p)\n", This, p);
805     return E_NOTIMPL;
806 }
807
808 static const IHTMLDocument4Vtbl HTMLDocument4Vtbl = {
809     HTMLDocument4_QueryInterface,
810     HTMLDocument4_AddRef,
811     HTMLDocument4_Release,
812     HTMLDocument4_GetTypeInfoCount,
813     HTMLDocument4_GetTypeInfo,
814     HTMLDocument4_GetIDsOfNames,
815     HTMLDocument4_Invoke,
816     HTMLDocument4_focus,
817     HTMLDocument4_hasFocus,
818     HTMLDocument4_put_onselectionchange,
819     HTMLDocument4_get_onselectionchange,
820     HTMLDocument4_get_namespace,
821     HTMLDocument4_createDocumentFromUrl,
822     HTMLDocument4_put_media,
823     HTMLDocument4_get_media,
824     HTMLDocument4_createEventObject,
825     HTMLDocument4_fireEvent,
826     HTMLDocument4_createRenderStyle,
827     HTMLDocument4_put_oncontrolselect,
828     HTMLDocument4_get_oncontrolselect,
829     HTMLDocument4_get_URLEncoded
830 };
831
832 void HTMLDocument_HTMLDocument3_Init(HTMLDocument *This)
833 {
834     This->IHTMLDocument3_iface.lpVtbl = &HTMLDocument3Vtbl;
835     This->IHTMLDocument4_iface.lpVtbl = &HTMLDocument4Vtbl;
836 }