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