mshtml: Added http loading test.
[wine] / dlls / mshtml / htmldoc.c
1 /*
2  * Copyright 2005 Jacek Caban
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 #include "perhist.h"
31
32 #include "wine/debug.h"
33
34 #include "mshtml_private.h"
35 #include "htmlevent.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38
39 #define HTMLDOC_THIS(iface) DEFINE_THIS(HTMLDocument, HTMLDocument2, iface)
40
41 static HRESULT WINAPI HTMLDocument_QueryInterface(IHTMLDocument2 *iface, REFIID riid, void **ppvObject)
42 {
43     HTMLDocument *This = HTMLDOC_THIS(iface);
44
45     *ppvObject = NULL;
46     if(IsEqualGUID(&IID_IUnknown, riid)) {
47         TRACE("(%p)->(IID_IUnknown, %p)\n", This, ppvObject);
48         *ppvObject = HTMLDOC(This);
49     }else if(IsEqualGUID(&IID_IDispatch, riid)) {
50         TRACE("(%p)->(IID_IDispatch, %p)\n", This, ppvObject);
51         *ppvObject = DISPATCHEX(This);
52     }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
53         TRACE("(%p)->(IID_IDispatchEx, %p)\n", This, ppvObject);
54         *ppvObject = DISPATCHEX(This);
55     }else if(IsEqualGUID(&IID_IHTMLDocument, riid)) {
56         TRACE("(%p)->(IID_IHTMLDocument, %p)\n", This, ppvObject);
57         *ppvObject = HTMLDOC(This);
58     }else if(IsEqualGUID(&IID_IHTMLDocument2, riid)) {
59         TRACE("(%p)->(IID_IHTMLDocument2, %p)\n", This, ppvObject);
60         *ppvObject = HTMLDOC(This);
61     }else if(IsEqualGUID(&IID_IHTMLDocument3, riid)) {
62         TRACE("(%p)->(IID_IHTMLDocument3, %p)\n", This, ppvObject);
63         *ppvObject = HTMLDOC3(This);
64     }else if(IsEqualGUID(&IID_IHTMLDocument4, riid)) {
65         TRACE("(%p)->(IID_IHTMLDocument4, %p)\n", This, ppvObject);
66         *ppvObject = HTMLDOC4(This);
67     }else if(IsEqualGUID(&IID_IHTMLDocument5, riid)) {
68         TRACE("(%p)->(IID_IHTMLDocument5, %p)\n", This, ppvObject);
69         *ppvObject = HTMLDOC5(This);
70     }else if(IsEqualGUID(&IID_IPersist, riid)) {
71         TRACE("(%p)->(IID_IPersist, %p)\n", This, ppvObject);
72         *ppvObject = PERSIST(This);
73     }else if(IsEqualGUID(&IID_IPersistMoniker, riid)) {
74         TRACE("(%p)->(IID_IPersistMoniker, %p)\n", This, ppvObject);
75         *ppvObject = PERSISTMON(This);
76     }else if(IsEqualGUID(&IID_IPersistFile, riid)) {
77         TRACE("(%p)->(IID_IPersistFile, %p)\n", This, ppvObject);
78         *ppvObject = PERSISTFILE(This);
79     }else if(IsEqualGUID(&IID_IMonikerProp, riid)) {
80         TRACE("(%p)->(IID_IMonikerProp, %p)\n", This, ppvObject);
81         *ppvObject = MONPROP(This);
82     }else if(IsEqualGUID(&IID_IOleObject, riid)) {
83         TRACE("(%p)->(IID_IOleObject, %p)\n", This, ppvObject);
84         *ppvObject = OLEOBJ(This);
85     }else if(IsEqualGUID(&IID_IOleDocument, riid)) {
86         TRACE("(%p)->(IID_IOleDocument, %p)\n", This, ppvObject);
87         *ppvObject = OLEDOC(This);
88     }else if(IsEqualGUID(&IID_IOleDocumentView, riid)) {
89         TRACE("(%p)->(IID_IOleDocumentView, %p)\n", This, ppvObject);
90         *ppvObject = DOCVIEW(This);
91     }else if(IsEqualGUID(&IID_IOleInPlaceActiveObject, riid)) {
92         TRACE("(%p)->(IID_IOleInPlaceActiveObject, %p)\n", This, ppvObject);
93         *ppvObject = ACTOBJ(This);
94     }else if(IsEqualGUID(&IID_IViewObject, riid)) {
95         TRACE("(%p)->(IID_IViewObject, %p)\n", This, ppvObject);
96         *ppvObject = VIEWOBJ(This);
97     }else if(IsEqualGUID(&IID_IViewObject2, riid)) {
98         TRACE("(%p)->(IID_IViewObject2, %p)\n", This, ppvObject);
99         *ppvObject = VIEWOBJ2(This);
100     }else if(IsEqualGUID(&IID_IOleWindow, riid)) {
101         TRACE("(%p)->(IID_IOleWindow, %p)\n", This, ppvObject);
102         *ppvObject = OLEWIN(This);
103     }else if(IsEqualGUID(&IID_IOleInPlaceObject, riid)) {
104         TRACE("(%p)->(IID_IOleInPlaceObject, %p)\n", This, ppvObject);
105         *ppvObject = INPLACEOBJ(This);
106     }else if(IsEqualGUID(&IID_IOleInPlaceObjectWindowless, riid)) {
107         TRACE("(%p)->(IID_IOleInPlaceObjectWindowless, %p)\n", This, ppvObject);
108         *ppvObject = INPLACEWIN(This);
109     }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
110         TRACE("(%p)->(IID_IServiceProvider, %p)\n", This, ppvObject);
111         *ppvObject = SERVPROV(This);
112     }else if(IsEqualGUID(&IID_IOleCommandTarget, riid)) {
113         TRACE("(%p)->(IID_IOleCommandTarget, %p)\n", This, ppvObject);
114         *ppvObject = CMDTARGET(This);
115     }else if(IsEqualGUID(&IID_IOleControl, riid)) {
116         TRACE("(%p)->(IID_IOleControl, %p)\n", This, ppvObject);
117         *ppvObject = CONTROL(This);
118     }else if(IsEqualGUID(&IID_IHlinkTarget, riid)) {
119         TRACE("(%p)->(IID_IHlinkTarget, %p)\n", This, ppvObject);
120         *ppvObject = HLNKTARGET(This);
121     }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
122         TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppvObject);
123         *ppvObject = CONPTCONT(&This->cp_container);
124     }else if(IsEqualGUID(&IID_IPersistStreamInit, riid)) {
125         TRACE("(%p)->(IID_IPersistStreamInit %p)\n", This, ppvObject);
126         *ppvObject = PERSTRINIT(This);
127     }else if(IsEqualGUID(&IID_ICustomDoc, riid)) {
128         TRACE("(%p)->(IID_ICustomDoc %p)\n", This, ppvObject);
129         *ppvObject = CUSTOMDOC(This);
130     }else if(IsEqualGUID(&DIID_DispHTMLDocument, riid)) {
131         TRACE("(%p)->(DIID_DispHTMLDocument %p)\n", This, ppvObject);
132         *ppvObject = HTMLDOC(This);
133     }else if(IsEqualGUID(&IID_ISupportErrorInfo, riid)) {
134         TRACE("(%p)->(IID_ISupportErrorInfo %p)\n", This, ppvObject);
135         *ppvObject = SUPPERRINFO(This);
136     }else if(IsEqualGUID(&IID_IPersistHistory, riid)) {
137         TRACE("(%p)->(IID_IPersistHistory %p)\n", This, ppvObject);
138         *ppvObject = PERSISTHIST(This);
139     }else if(IsEqualGUID(&CLSID_CMarkup, riid)) {
140         FIXME("(%p)->(CLSID_CMarkup %p)\n", This, ppvObject);
141         return E_NOINTERFACE;
142     }else if(IsEqualGUID(&IID_IRunnableObject, riid)) {
143         TRACE("(%p)->(IID_IRunnableObject %p) returning NULL\n", This, ppvObject);
144         return E_NOINTERFACE;
145     }else if(IsEqualGUID(&IID_IPersistPropertyBag, riid)) {
146         TRACE("(%p)->(IID_IPersistPropertyBag %p) returning NULL\n", This, ppvObject);
147         return E_NOINTERFACE;
148     }else if(IsEqualGUID(&IID_IMarshal, riid)) {
149         TRACE("(%p)->(IID_IMarshal %p) returning NULL\n", This, ppvObject);
150         return E_NOINTERFACE;
151     }else if(dispex_query_interface(&This->dispex, riid, ppvObject)) {
152         return *ppvObject ? S_OK : E_NOINTERFACE;
153     }
154
155     if(*ppvObject) {
156         IHTMLDocument2_AddRef(iface);
157         return S_OK;
158     }
159
160     FIXME("(%p)->(%s %p) interface not supported\n", This, debugstr_guid(riid), ppvObject);
161     return E_NOINTERFACE;
162 }
163
164 static ULONG WINAPI HTMLDocument_AddRef(IHTMLDocument2 *iface)
165 {
166     HTMLDocument *This = HTMLDOC_THIS(iface);
167     ULONG ref = InterlockedIncrement(&This->ref);
168     TRACE("(%p) ref = %u\n", This, ref);
169     return ref;
170 }
171
172 static ULONG WINAPI HTMLDocument_Release(IHTMLDocument2 *iface)
173 {
174     HTMLDocument *This = HTMLDOC_THIS(iface);
175     ULONG ref = InterlockedDecrement(&This->ref);
176
177     TRACE("(%p) ref = %u\n", This, ref);
178
179     if(!ref) {
180         remove_doc_tasks(This);
181         release_script_hosts(This);
182
183         if(This->client)
184             IOleObject_SetClientSite(OLEOBJ(This), NULL);
185         if(This->in_place_active)
186             IOleInPlaceObjectWindowless_InPlaceDeactivate(INPLACEWIN(This));
187         if(This->ipsite)
188             IOleDocumentView_SetInPlaceSite(DOCVIEW(This), NULL);
189         if(This->undomgr)
190             IOleUndoManager_Release(This->undomgr);
191
192         set_document_bscallback(This, NULL);
193         set_current_mon(This, NULL);
194
195         if(This->tooltips_hwnd)
196             DestroyWindow(This->tooltips_hwnd);
197         if(This->hwnd)
198             DestroyWindow(This->hwnd);
199
200         if(This->option_factory) {
201             This->option_factory->doc = NULL;
202             IHTMLOptionElementFactory_Release(HTMLOPTFACTORY(This->option_factory));
203         }
204
205         if(This->location)
206             This->location->doc = NULL;
207
208         if(This->window)
209             IHTMLWindow2_Release(HTMLWINDOW2(This->window));
210
211         if(This->event_target)
212             release_event_target(This->event_target);
213
214         heap_free(This->mime);
215         detach_selection(This);
216         detach_ranges(This);
217         release_nodes(This);
218         release_dispex(&This->dispex);
219
220         ConnectionPointContainer_Destroy(&This->cp_container);
221
222         if(This->nsdoc) {
223             remove_mutation_observer(This->nscontainer, This->nsdoc);
224             nsIDOMHTMLDocument_Release(This->nsdoc);
225         }
226         if(This->nscontainer)
227             NSContainer_Release(This->nscontainer);
228
229         heap_free(This);
230     }
231
232     return ref;
233 }
234
235 static HRESULT WINAPI HTMLDocument_GetTypeInfoCount(IHTMLDocument2 *iface, UINT *pctinfo)
236 {
237     HTMLDocument *This = HTMLDOC_THIS(iface);
238
239     return IDispatchEx_GetTypeInfoCount(DISPATCHEX(This), pctinfo);
240 }
241
242 static HRESULT WINAPI HTMLDocument_GetTypeInfo(IHTMLDocument2 *iface, UINT iTInfo,
243                                                 LCID lcid, ITypeInfo **ppTInfo)
244 {
245     HTMLDocument *This = HTMLDOC_THIS(iface);
246
247     return IDispatchEx_GetTypeInfo(DISPATCHEX(This), iTInfo, lcid, ppTInfo);
248 }
249
250 static HRESULT WINAPI HTMLDocument_GetIDsOfNames(IHTMLDocument2 *iface, REFIID riid,
251                                                 LPOLESTR *rgszNames, UINT cNames,
252                                                 LCID lcid, DISPID *rgDispId)
253 {
254     HTMLDocument *This = HTMLDOC_THIS(iface);
255
256     return IDispatchEx_GetIDsOfNames(DISPATCHEX(This), riid, rgszNames, cNames, lcid, rgDispId);
257 }
258
259 static HRESULT WINAPI HTMLDocument_Invoke(IHTMLDocument2 *iface, DISPID dispIdMember,
260                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
261                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
262 {
263     HTMLDocument *This = HTMLDOC_THIS(iface);
264
265     return IDispatchEx_Invoke(DISPATCHEX(This), dispIdMember, riid, lcid, wFlags, pDispParams,
266             pVarResult, pExcepInfo, puArgErr);
267 }
268
269 static HRESULT WINAPI HTMLDocument_get_Script(IHTMLDocument2 *iface, IDispatch **p)
270 {
271     HTMLDocument *This = HTMLDOC_THIS(iface);
272
273     TRACE("(%p)->(%p)\n", This, p);
274
275     *p = (IDispatch*)HTMLWINDOW2(This->window);
276     IDispatch_AddRef(*p);
277     return S_OK;
278 }
279
280 static HRESULT WINAPI HTMLDocument_get_all(IHTMLDocument2 *iface, IHTMLElementCollection **p)
281 {
282     HTMLDocument *This = HTMLDOC_THIS(iface);
283     nsIDOMElement *nselem = NULL;
284     nsresult nsres;
285
286     TRACE("(%p)->(%p)\n", This, p);
287
288     if(!This->nsdoc) {
289         WARN("NULL nsdoc\n");
290         return E_UNEXPECTED;
291     }
292
293     nsres = nsIDOMHTMLDocument_GetDocumentElement(This->nsdoc, &nselem);
294     if(NS_FAILED(nsres)) {
295         ERR("GetDocumentElement failed: %08x\n", nsres);
296         return E_FAIL;
297     }
298
299     if(nselem) {
300         *p = create_all_collection(get_node(This, (nsIDOMNode*)nselem, TRUE), TRUE);
301         nsIDOMElement_Release(nselem);
302     }else {
303         *p = NULL;
304     }
305
306     return S_OK;
307 }
308
309 static HRESULT WINAPI HTMLDocument_get_body(IHTMLDocument2 *iface, IHTMLElement **p)
310 {
311     HTMLDocument *This = HTMLDOC_THIS(iface);
312     nsIDOMHTMLElement *nsbody = NULL;
313     HTMLDOMNode *node;
314     nsresult nsres;
315
316     TRACE("(%p)->(%p)\n", This, p);
317
318     if(!This->nsdoc) {
319         WARN("NULL nsdoc\n");
320         return E_UNEXPECTED;
321     }
322
323     nsres = nsIDOMHTMLDocument_GetBody(This->nsdoc, &nsbody);
324     if(NS_FAILED(nsres)) {
325         TRACE("Could not get body: %08x\n", nsres);
326         return E_UNEXPECTED;
327     }
328
329     if(nsbody) {
330         node = get_node(This, (nsIDOMNode*)nsbody, TRUE);
331         nsIDOMHTMLElement_Release(nsbody);
332
333         IHTMLDOMNode_QueryInterface(HTMLDOMNODE(node), &IID_IHTMLElement, (void**)p);
334     }else {
335         *p = NULL;
336     }
337
338     TRACE("*p = %p\n", *p);
339     return S_OK;
340 }
341
342 static HRESULT WINAPI HTMLDocument_get_activeElement(IHTMLDocument2 *iface, IHTMLElement **p)
343 {
344     HTMLDocument *This = HTMLDOC_THIS(iface);
345     FIXME("(%p)->(%p)\n", This, p);
346     return E_NOTIMPL;
347 }
348
349 static HRESULT WINAPI HTMLDocument_get_images(IHTMLDocument2 *iface, IHTMLElementCollection **p)
350 {
351     HTMLDocument *This = HTMLDOC_THIS(iface);
352     nsIDOMHTMLCollection *nscoll = NULL;
353     nsresult nsres;
354
355     TRACE("(%p)->(%p)\n", This, p);
356
357     if(!p)
358         return E_INVALIDARG;
359
360     *p = NULL;
361
362     if(!This->nsdoc) {
363         WARN("NULL nsdoc\n");
364         return E_UNEXPECTED;
365     }
366
367     nsres = nsIDOMHTMLDocument_GetImages(This->nsdoc, &nscoll);
368     if(NS_FAILED(nsres)) {
369         ERR("GetImages failed: %08x\n", nsres);
370         return E_FAIL;
371     }
372
373     if(nscoll) {
374         *p = create_collection_from_htmlcol(This, (IUnknown*)HTMLDOC(This), nscoll);
375         nsIDOMElement_Release(nscoll);
376     }
377
378     return S_OK;
379 }
380
381 static HRESULT WINAPI HTMLDocument_get_applets(IHTMLDocument2 *iface, IHTMLElementCollection **p)
382 {
383     HTMLDocument *This = HTMLDOC_THIS(iface);
384     nsIDOMHTMLCollection *nscoll = NULL;
385     nsresult nsres;
386
387     TRACE("(%p)->(%p)\n", This, p);
388
389     if(!p)
390         return E_INVALIDARG;
391
392     *p = NULL;
393
394     if(!This->nsdoc) {
395         WARN("NULL nsdoc\n");
396         return E_UNEXPECTED;
397     }
398
399     nsres = nsIDOMHTMLDocument_GetApplets(This->nsdoc, &nscoll);
400     if(NS_FAILED(nsres)) {
401         ERR("GetApplets failed: %08x\n", nsres);
402         return E_FAIL;
403     }
404
405     if(nscoll) {
406         *p = create_collection_from_htmlcol(This, (IUnknown*)HTMLDOC(This), nscoll);
407         nsIDOMElement_Release(nscoll);
408     }
409
410     return S_OK;
411 }
412
413 static HRESULT WINAPI HTMLDocument_get_links(IHTMLDocument2 *iface, IHTMLElementCollection **p)
414 {
415     HTMLDocument *This = HTMLDOC_THIS(iface);
416     nsIDOMHTMLCollection *nscoll = NULL;
417     nsresult nsres;
418
419     TRACE("(%p)->(%p)\n", This, p);
420
421     if(!p)
422         return E_INVALIDARG;
423
424     *p = NULL;
425
426     if(!This->nsdoc) {
427         WARN("NULL nsdoc\n");
428         return E_UNEXPECTED;
429     }
430
431     nsres = nsIDOMHTMLDocument_GetLinks(This->nsdoc, &nscoll);
432     if(NS_FAILED(nsres)) {
433         ERR("GetLinks failed: %08x\n", nsres);
434         return E_FAIL;
435     }
436
437     if(nscoll) {
438         *p = create_collection_from_htmlcol(This, (IUnknown*)HTMLDOC(This), nscoll);
439         nsIDOMElement_Release(nscoll);
440     }
441
442     return S_OK;
443 }
444
445 static HRESULT WINAPI HTMLDocument_get_forms(IHTMLDocument2 *iface, IHTMLElementCollection **p)
446 {
447     HTMLDocument *This = HTMLDOC_THIS(iface);
448     nsIDOMHTMLCollection *nscoll = NULL;
449     nsresult nsres;
450
451     TRACE("(%p)->(%p)\n", This, p);
452
453     if(!p)
454         return E_INVALIDARG;
455
456     *p = NULL;
457
458     if(!This->nsdoc) {
459         WARN("NULL nsdoc\n");
460         return E_UNEXPECTED;
461     }
462
463     nsres = nsIDOMHTMLDocument_GetForms(This->nsdoc, &nscoll);
464     if(NS_FAILED(nsres)) {
465         ERR("GetForms failed: %08x\n", nsres);
466         return E_FAIL;
467     }
468
469     if(nscoll) {
470         *p = create_collection_from_htmlcol(This, (IUnknown*)HTMLDOC(This), nscoll);
471         nsIDOMElement_Release(nscoll);
472     }
473
474     return S_OK;
475 }
476
477 static HRESULT WINAPI HTMLDocument_get_anchors(IHTMLDocument2 *iface, IHTMLElementCollection **p)
478 {
479     HTMLDocument *This = HTMLDOC_THIS(iface);
480     nsIDOMHTMLCollection *nscoll = NULL;
481     nsresult nsres;
482
483     TRACE("(%p)->(%p)\n", This, p);
484
485     if(!p)
486         return E_INVALIDARG;
487
488     *p = NULL;
489
490     if(!This->nsdoc) {
491         WARN("NULL nsdoc\n");
492         return E_UNEXPECTED;
493     }
494
495     nsres = nsIDOMHTMLDocument_GetAnchors(This->nsdoc, &nscoll);
496     if(NS_FAILED(nsres)) {
497         ERR("GetAnchors failed: %08x\n", nsres);
498         return E_FAIL;
499     }
500
501     if(nscoll) {
502         *p = create_collection_from_htmlcol(This, (IUnknown*)HTMLDOC(This), nscoll);
503         nsIDOMElement_Release(nscoll);
504     }
505
506     return S_OK;
507 }
508
509 static HRESULT WINAPI HTMLDocument_put_title(IHTMLDocument2 *iface, BSTR v)
510 {
511     HTMLDocument *This = HTMLDOC_THIS(iface);
512     nsAString nsstr;
513     nsresult nsres;
514
515     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
516
517     if(!This->nsdoc) {
518         WARN("NULL nsdoc\n");
519         return E_UNEXPECTED;
520     }
521
522     nsAString_Init(&nsstr, v);
523     nsres = nsIDOMHTMLDocument_SetTitle(This->nsdoc, &nsstr);
524     nsAString_Finish(&nsstr);
525     if(NS_FAILED(nsres))
526         ERR("SetTitle failed: %08x\n", nsres);
527
528     return S_OK;
529 }
530
531 static HRESULT WINAPI HTMLDocument_get_title(IHTMLDocument2 *iface, BSTR *p)
532 {
533     HTMLDocument *This = HTMLDOC_THIS(iface);
534     const PRUnichar *ret;
535     nsAString nsstr;
536     nsresult nsres;
537
538     TRACE("(%p)->(%p)\n", This, p);
539
540     if(!This->nsdoc) {
541         WARN("NULL nsdoc\n");
542         return E_UNEXPECTED;
543     }
544
545
546     nsAString_Init(&nsstr, NULL);
547     nsres = nsIDOMHTMLDocument_GetTitle(This->nsdoc, &nsstr);
548     if (NS_SUCCEEDED(nsres)) {
549         nsAString_GetData(&nsstr, &ret);
550         *p = SysAllocString(ret);
551     }
552     nsAString_Finish(&nsstr);
553
554     if(NS_FAILED(nsres)) {
555         ERR("GetTitle failed: %08x\n", nsres);
556         return E_FAIL;
557     }
558
559     return S_OK;
560 }
561
562 static HRESULT WINAPI HTMLDocument_get_scripts(IHTMLDocument2 *iface, IHTMLElementCollection **p)
563 {
564     HTMLDocument *This = HTMLDOC_THIS(iface);
565     FIXME("(%p)->(%p)\n", This, p);
566     return E_NOTIMPL;
567 }
568
569 static HRESULT WINAPI HTMLDocument_put_designMode(IHTMLDocument2 *iface, BSTR v)
570 {
571     HTMLDocument *This = HTMLDOC_THIS(iface);
572     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
573     return E_NOTIMPL;
574 }
575
576 static HRESULT WINAPI HTMLDocument_get_designMode(IHTMLDocument2 *iface, BSTR *p)
577 {
578     HTMLDocument *This = HTMLDOC_THIS(iface);
579     static WCHAR szOff[] = {'O','f','f',0};
580     FIXME("(%p)->(%p) always returning Off\n", This, p);
581
582     if(!p)
583         return E_INVALIDARG;
584
585     *p = SysAllocString(szOff);
586
587     return S_OK;
588 }
589
590 static HRESULT WINAPI HTMLDocument_get_selection(IHTMLDocument2 *iface, IHTMLSelectionObject **p)
591 {
592     HTMLDocument *This = HTMLDOC_THIS(iface);
593     nsISelection *nsselection = NULL;
594
595     TRACE("(%p)->(%p)\n", This, p);
596
597     if(This->nscontainer) {
598         nsIDOMWindow *dom_window = NULL;
599
600         nsIWebBrowser_GetContentDOMWindow(This->nscontainer->webbrowser, &dom_window);
601         if(dom_window) {
602             nsIDOMWindow_GetSelection(dom_window, &nsselection);
603             nsIDOMWindow_Release(dom_window);
604         }
605     }
606
607     *p = HTMLSelectionObject_Create(This, nsselection);
608     return S_OK;
609 }
610
611 static HRESULT WINAPI HTMLDocument_get_readyState(IHTMLDocument2 *iface, BSTR *p)
612 {
613     HTMLDocument *This = HTMLDOC_THIS(iface);
614
615     static const WCHAR wszUninitialized[] = {'u','n','i','n','i','t','i','a','l','i','z','e','d',0};
616     static const WCHAR wszLoading[] = {'l','o','a','d','i','n','g',0};
617     static const WCHAR wszLoaded[] = {'l','o','a','d','e','d',0};
618     static const WCHAR wszInteractive[] = {'i','n','t','e','r','a','c','t','i','v','e',0};
619     static const WCHAR wszComplete[] = {'c','o','m','p','l','e','t','e',0};
620
621     static const LPCWSTR readystate_str[] = {
622         wszUninitialized,
623         wszLoading,
624         wszLoaded,
625         wszInteractive,
626         wszComplete
627     };
628
629     TRACE("(%p)->(%p)\n", iface, p);
630
631     if(!p)
632         return E_POINTER;
633
634     *p = SysAllocString(readystate_str[This->readystate]);
635     return S_OK;
636 }
637
638 static HRESULT WINAPI HTMLDocument_get_frames(IHTMLDocument2 *iface, IHTMLFramesCollection2 **p)
639 {
640     HTMLDocument *This = HTMLDOC_THIS(iface);
641     FIXME("(%p)->(%p)\n", This, p);
642     return E_NOTIMPL;
643 }
644
645 static HRESULT WINAPI HTMLDocument_get_embeds(IHTMLDocument2 *iface, IHTMLElementCollection **p)
646 {
647     HTMLDocument *This = HTMLDOC_THIS(iface);
648     FIXME("(%p)->(%p)\n", This, p);
649     return E_NOTIMPL;
650 }
651
652 static HRESULT WINAPI HTMLDocument_get_plugins(IHTMLDocument2 *iface, IHTMLElementCollection **p)
653 {
654     HTMLDocument *This = HTMLDOC_THIS(iface);
655     FIXME("(%p)->(%p)\n", This, p);
656     return E_NOTIMPL;
657 }
658
659 static HRESULT WINAPI HTMLDocument_put_alinkColor(IHTMLDocument2 *iface, VARIANT v)
660 {
661     HTMLDocument *This = HTMLDOC_THIS(iface);
662     FIXME("(%p)\n", This);
663     return E_NOTIMPL;
664 }
665
666 static HRESULT WINAPI HTMLDocument_get_alinkColor(IHTMLDocument2 *iface, VARIANT *p)
667 {
668     HTMLDocument *This = HTMLDOC_THIS(iface);
669     FIXME("(%p)->(%p)\n", This, p);
670     return E_NOTIMPL;
671 }
672
673 static HRESULT WINAPI HTMLDocument_put_bgColor(IHTMLDocument2 *iface, VARIANT v)
674 {
675     HTMLDocument *This = HTMLDOC_THIS(iface);
676     FIXME("(%p)\n", This);
677     return E_NOTIMPL;
678 }
679
680 static HRESULT WINAPI HTMLDocument_get_bgColor(IHTMLDocument2 *iface, VARIANT *p)
681 {
682     HTMLDocument *This = HTMLDOC_THIS(iface);
683     FIXME("(%p)->(%p)\n", This, p);
684     return E_NOTIMPL;
685 }
686
687 static HRESULT WINAPI HTMLDocument_put_fgColor(IHTMLDocument2 *iface, VARIANT v)
688 {
689     HTMLDocument *This = HTMLDOC_THIS(iface);
690     FIXME("(%p)\n", This);
691     return E_NOTIMPL;
692 }
693
694 static HRESULT WINAPI HTMLDocument_get_fgColor(IHTMLDocument2 *iface, VARIANT *p)
695 {
696     HTMLDocument *This = HTMLDOC_THIS(iface);
697     FIXME("(%p)->(%p)\n", This, p);
698     return E_NOTIMPL;
699 }
700
701 static HRESULT WINAPI HTMLDocument_put_linkColor(IHTMLDocument2 *iface, VARIANT v)
702 {
703     HTMLDocument *This = HTMLDOC_THIS(iface);
704     FIXME("(%p)->()\n", This);
705     return E_NOTIMPL;
706 }
707
708 static HRESULT WINAPI HTMLDocument_get_linkColor(IHTMLDocument2 *iface, VARIANT *p)
709 {
710     HTMLDocument *This = HTMLDOC_THIS(iface);
711     FIXME("(%p)->(%p)\n", This, p);
712     return E_NOTIMPL;
713 }
714
715 static HRESULT WINAPI HTMLDocument_put_vlinkColor(IHTMLDocument2 *iface, VARIANT v)
716 {
717     HTMLDocument *This = HTMLDOC_THIS(iface);
718     FIXME("(%p)\n", This);
719     return E_NOTIMPL;
720 }
721
722 static HRESULT WINAPI HTMLDocument_get_vlinkColor(IHTMLDocument2 *iface, VARIANT *p)
723 {
724     HTMLDocument *This = HTMLDOC_THIS(iface);
725     FIXME("(%p)->(%p)\n", This, p);
726     return E_NOTIMPL;
727 }
728
729 static HRESULT WINAPI HTMLDocument_get_referrer(IHTMLDocument2 *iface, BSTR *p)
730 {
731     HTMLDocument *This = HTMLDOC_THIS(iface);
732     FIXME("(%p)->(%p)\n", This, p);
733     return E_NOTIMPL;
734 }
735
736 static HRESULT WINAPI HTMLDocument_get_location(IHTMLDocument2 *iface, IHTMLLocation **p)
737 {
738     HTMLDocument *This = HTMLDOC_THIS(iface);
739
740     TRACE("(%p)->(%p)\n", This, p);
741
742     if(This->location)
743         IHTMLLocation_AddRef(HTMLLOCATION(This->location));
744     else
745         This->location = HTMLLocation_Create(This);
746
747     *p = HTMLLOCATION(This->location);
748     return S_OK;
749 }
750
751 static HRESULT WINAPI HTMLDocument_get_lastModified(IHTMLDocument2 *iface, BSTR *p)
752 {
753     HTMLDocument *This = HTMLDOC_THIS(iface);
754     FIXME("(%p)->(%p)\n", This, p);
755     return E_NOTIMPL;
756 }
757
758 static HRESULT WINAPI HTMLDocument_put_URL(IHTMLDocument2 *iface, BSTR v)
759 {
760     HTMLDocument *This = HTMLDOC_THIS(iface);
761     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
762     return E_NOTIMPL;
763 }
764
765 static HRESULT WINAPI HTMLDocument_get_URL(IHTMLDocument2 *iface, BSTR *p)
766 {
767     HTMLDocument *This = HTMLDOC_THIS(iface);
768
769     static const WCHAR about_blank_url[] =
770         {'a','b','o','u','t',':','b','l','a','n','k',0};
771
772     TRACE("(%p)->(%p)\n", iface, p);
773
774     *p = SysAllocString(This->url ? This->url : about_blank_url);
775     return S_OK;
776 }
777
778 static HRESULT WINAPI HTMLDocument_put_domain(IHTMLDocument2 *iface, BSTR v)
779 {
780     HTMLDocument *This = HTMLDOC_THIS(iface);
781     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
782     return E_NOTIMPL;
783 }
784
785 static HRESULT WINAPI HTMLDocument_get_domain(IHTMLDocument2 *iface, BSTR *p)
786 {
787     HTMLDocument *This = HTMLDOC_THIS(iface);
788     FIXME("(%p)->(%p)\n", This, p);
789     return E_NOTIMPL;
790 }
791
792 static HRESULT WINAPI HTMLDocument_put_cookie(IHTMLDocument2 *iface, BSTR v)
793 {
794     HTMLDocument *This = HTMLDOC_THIS(iface);
795     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
796     return E_NOTIMPL;
797 }
798
799 static HRESULT WINAPI HTMLDocument_get_cookie(IHTMLDocument2 *iface, BSTR *p)
800 {
801     HTMLDocument *This = HTMLDOC_THIS(iface);
802     FIXME("(%p)->(%p)\n", This, p);
803     return E_NOTIMPL;
804 }
805
806 static HRESULT WINAPI HTMLDocument_put_expando(IHTMLDocument2 *iface, VARIANT_BOOL v)
807 {
808     HTMLDocument *This = HTMLDOC_THIS(iface);
809     FIXME("(%p)->(%x)\n", This, v);
810     return E_NOTIMPL;
811 }
812
813 static HRESULT WINAPI HTMLDocument_get_expando(IHTMLDocument2 *iface, VARIANT_BOOL *p)
814 {
815     HTMLDocument *This = HTMLDOC_THIS(iface);
816     FIXME("(%p)->(%p)\n", This, p);
817     return E_NOTIMPL;
818 }
819
820 static HRESULT WINAPI HTMLDocument_put_charset(IHTMLDocument2 *iface, BSTR v)
821 {
822     HTMLDocument *This = HTMLDOC_THIS(iface);
823     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
824     return E_NOTIMPL;
825 }
826
827 static HRESULT WINAPI HTMLDocument_get_charset(IHTMLDocument2 *iface, BSTR *p)
828 {
829     HTMLDocument *This = HTMLDOC_THIS(iface);
830     FIXME("(%p)->(%p)\n", This, p);
831     return E_NOTIMPL;
832 }
833
834 static HRESULT WINAPI HTMLDocument_put_defaultCharset(IHTMLDocument2 *iface, BSTR v)
835 {
836     HTMLDocument *This = HTMLDOC_THIS(iface);
837     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
838     return E_NOTIMPL;
839 }
840
841 static HRESULT WINAPI HTMLDocument_get_defaultCharset(IHTMLDocument2 *iface, BSTR *p)
842 {
843     HTMLDocument *This = HTMLDOC_THIS(iface);
844     FIXME("(%p)->(%p)\n", This, p);
845     return E_NOTIMPL;
846 }
847
848 static HRESULT WINAPI HTMLDocument_get_mimeType(IHTMLDocument2 *iface, BSTR *p)
849 {
850     HTMLDocument *This = HTMLDOC_THIS(iface);
851     FIXME("(%p)->(%p)\n", This, p);
852     return E_NOTIMPL;
853 }
854
855 static HRESULT WINAPI HTMLDocument_get_fileSize(IHTMLDocument2 *iface, BSTR *p)
856 {
857     HTMLDocument *This = HTMLDOC_THIS(iface);
858     FIXME("(%p)->(%p)\n", This, p);
859     return E_NOTIMPL;
860 }
861
862 static HRESULT WINAPI HTMLDocument_get_fileCreatedDate(IHTMLDocument2 *iface, BSTR *p)
863 {
864     HTMLDocument *This = HTMLDOC_THIS(iface);
865     FIXME("(%p)->(%p)\n", This, p);
866     return E_NOTIMPL;
867 }
868
869 static HRESULT WINAPI HTMLDocument_get_fileModifiedDate(IHTMLDocument2 *iface, BSTR *p)
870 {
871     HTMLDocument *This = HTMLDOC_THIS(iface);
872     FIXME("(%p)->(%p)\n", This, p);
873     return E_NOTIMPL;
874 }
875
876 static HRESULT WINAPI HTMLDocument_get_fileUpdatedDate(IHTMLDocument2 *iface, BSTR *p)
877 {
878     HTMLDocument *This = HTMLDOC_THIS(iface);
879     FIXME("(%p)->(%p)\n", This, p);
880     return E_NOTIMPL;
881 }
882
883 static HRESULT WINAPI HTMLDocument_get_security(IHTMLDocument2 *iface, BSTR *p)
884 {
885     HTMLDocument *This = HTMLDOC_THIS(iface);
886     FIXME("(%p)->(%p)\n", This, p);
887     return E_NOTIMPL;
888 }
889
890 static HRESULT WINAPI HTMLDocument_get_protocol(IHTMLDocument2 *iface, BSTR *p)
891 {
892     HTMLDocument *This = HTMLDOC_THIS(iface);
893     FIXME("(%p)->(%p)\n", This, p);
894     return E_NOTIMPL;
895 }
896
897 static HRESULT WINAPI HTMLDocument_get_nameProp(IHTMLDocument2 *iface, BSTR *p)
898 {
899     HTMLDocument *This = HTMLDOC_THIS(iface);
900     FIXME("(%p)->(%p)\n", This, p);
901     return E_NOTIMPL;
902 }
903
904 static HRESULT WINAPI HTMLDocument_write(IHTMLDocument2 *iface, SAFEARRAY *psarray)
905 {
906     HTMLDocument *This = HTMLDOC_THIS(iface);
907     nsAString nsstr;
908     VARIANT *var;
909     ULONG i;
910     nsresult nsres;
911     HRESULT hres;
912
913     TRACE("(%p)->(%p)\n", iface, psarray);
914
915     if(!This->nsdoc) {
916         WARN("NULL nsdoc\n");
917         return E_UNEXPECTED;
918     }
919
920     if(psarray->cDims != 1) {
921         FIXME("cDims=%d\n", psarray->cDims);
922         return E_INVALIDARG;
923     }
924
925     hres = SafeArrayAccessData(psarray, (void**)&var);
926     if(FAILED(hres)) {
927         WARN("SafeArrayAccessData failed: %08x\n", hres);
928         return hres;
929     }
930
931     nsAString_Init(&nsstr, NULL);
932
933     for(i=0; i < psarray->rgsabound[0].cElements; i++) {
934         if(V_VT(var+i) == VT_BSTR) {
935             nsAString_SetData(&nsstr, V_BSTR(var+i));
936             nsres = nsIDOMHTMLDocument_Write(This->nsdoc, &nsstr);
937             if(NS_FAILED(nsres))
938                 ERR("Write failed: %08x\n", nsres);
939         }else {
940             FIXME("vt=%d\n", V_VT(var+i));
941         }
942     }
943
944     nsAString_Finish(&nsstr);
945     SafeArrayUnaccessData(psarray);
946
947     return S_OK;
948 }
949
950 static HRESULT WINAPI HTMLDocument_writeln(IHTMLDocument2 *iface, SAFEARRAY *psarray)
951 {
952     HTMLDocument *This = HTMLDOC_THIS(iface);
953     FIXME("(%p)->(%p)\n", This, psarray);
954     return E_NOTIMPL;
955 }
956
957 static HRESULT WINAPI HTMLDocument_open(IHTMLDocument2 *iface, BSTR url, VARIANT name,
958                         VARIANT features, VARIANT replace, IDispatch **pomWindowResult)
959 {
960     HTMLDocument *This = HTMLDOC_THIS(iface);
961     nsresult nsres;
962
963     static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};
964
965     TRACE("(%p)->(%s %s %s %s %p)\n", This, debugstr_w(url), debugstr_variant(&name),
966           debugstr_variant(&features), debugstr_variant(&replace), pomWindowResult);
967
968     if(!This->nsdoc) {
969         ERR("!nsdoc\n");
970         return E_NOTIMPL;
971     }
972
973     if(!url || strcmpW(url, text_htmlW) || V_VT(&name) != VT_ERROR
974        || V_VT(&features) != VT_ERROR || V_VT(&replace) != VT_ERROR)
975         FIXME("unsupported args\n");
976
977     nsres = nsIDOMHTMLDocument_Open(This->nsdoc);
978     if(NS_FAILED(nsres)) {
979         ERR("Open failed: %08x\n", nsres);
980         return E_FAIL;
981     }
982
983     *pomWindowResult = (IDispatch*)HTMLWINDOW2(This->window);
984     IHTMLWindow2_AddRef(HTMLWINDOW2(This->window));
985     return S_OK;
986 }
987
988 static HRESULT WINAPI HTMLDocument_close(IHTMLDocument2 *iface)
989 {
990     HTMLDocument *This = HTMLDOC_THIS(iface);
991     nsresult nsres;
992
993     TRACE("(%p)\n", This);
994
995     if(!This->nsdoc) {
996         ERR("!nsdoc\n");
997         return E_NOTIMPL;
998     }
999
1000     nsres = nsIDOMHTMLDocument_Close(This->nsdoc);
1001     if(NS_FAILED(nsres)) {
1002         ERR("Close failed: %08x\n", nsres);
1003         return E_FAIL;
1004     }
1005
1006     return S_OK;
1007 }
1008
1009 static HRESULT WINAPI HTMLDocument_clear(IHTMLDocument2 *iface)
1010 {
1011     HTMLDocument *This = HTMLDOC_THIS(iface);
1012     FIXME("(%p)\n", This);
1013     return E_NOTIMPL;
1014 }
1015
1016 static HRESULT WINAPI HTMLDocument_queryCommandSupported(IHTMLDocument2 *iface, BSTR cmdID,
1017                                                         VARIANT_BOOL *pfRet)
1018 {
1019     HTMLDocument *This = HTMLDOC_THIS(iface);
1020     FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1021     return E_NOTIMPL;
1022 }
1023
1024 static HRESULT WINAPI HTMLDocument_queryCommandEnabled(IHTMLDocument2 *iface, BSTR cmdID,
1025                                                         VARIANT_BOOL *pfRet)
1026 {
1027     HTMLDocument *This = HTMLDOC_THIS(iface);
1028     FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1029     return E_NOTIMPL;
1030 }
1031
1032 static HRESULT WINAPI HTMLDocument_queryCommandState(IHTMLDocument2 *iface, BSTR cmdID,
1033                                                         VARIANT_BOOL *pfRet)
1034 {
1035     HTMLDocument *This = HTMLDOC_THIS(iface);
1036     FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1037     return E_NOTIMPL;
1038 }
1039
1040 static HRESULT WINAPI HTMLDocument_queryCommandIndeterm(IHTMLDocument2 *iface, BSTR cmdID,
1041                                                         VARIANT_BOOL *pfRet)
1042 {
1043     HTMLDocument *This = HTMLDOC_THIS(iface);
1044     FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1045     return E_NOTIMPL;
1046 }
1047
1048 static HRESULT WINAPI HTMLDocument_queryCommandText(IHTMLDocument2 *iface, BSTR cmdID,
1049                                                         BSTR *pfRet)
1050 {
1051     HTMLDocument *This = HTMLDOC_THIS(iface);
1052     FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1053     return E_NOTIMPL;
1054 }
1055
1056 static HRESULT WINAPI HTMLDocument_queryCommandValue(IHTMLDocument2 *iface, BSTR cmdID,
1057                                                         VARIANT *pfRet)
1058 {
1059     HTMLDocument *This = HTMLDOC_THIS(iface);
1060     FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1061     return E_NOTIMPL;
1062 }
1063
1064 static HRESULT WINAPI HTMLDocument_execCommand(IHTMLDocument2 *iface, BSTR cmdID,
1065                                 VARIANT_BOOL showUI, VARIANT value, VARIANT_BOOL *pfRet)
1066 {
1067     HTMLDocument *This = HTMLDOC_THIS(iface);
1068     FIXME("(%p)->(%s %x %p)\n", This, debugstr_w(cmdID), showUI, pfRet);
1069     return E_NOTIMPL;
1070 }
1071
1072 static HRESULT WINAPI HTMLDocument_execCommandShowHelp(IHTMLDocument2 *iface, BSTR cmdID,
1073                                                         VARIANT_BOOL *pfRet)
1074 {
1075     HTMLDocument *This = HTMLDOC_THIS(iface);
1076     FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1077     return E_NOTIMPL;
1078 }
1079
1080 static HRESULT WINAPI HTMLDocument_createElement(IHTMLDocument2 *iface, BSTR eTag,
1081                                                  IHTMLElement **newElem)
1082 {
1083     HTMLDocument *This = HTMLDOC_THIS(iface);
1084     nsIDOMElement *nselem;
1085     HTMLElement *elem;
1086     nsAString tag_str;
1087     nsresult nsres;
1088
1089     TRACE("(%p)->(%s %p)\n", This, debugstr_w(eTag), newElem);
1090
1091     if(!This->nsdoc) {
1092         WARN("NULL nsdoc\n");
1093         return E_UNEXPECTED;
1094     }
1095
1096     nsAString_Init(&tag_str, eTag);
1097     nsres = nsIDOMDocument_CreateElement(This->nsdoc, &tag_str, &nselem);
1098     nsAString_Finish(&tag_str);
1099     if(NS_FAILED(nsres)) {
1100         ERR("CreateElement failed: %08x\n", nsres);
1101         return E_FAIL;
1102     }
1103
1104     elem = HTMLElement_Create(This, (nsIDOMNode*)nselem, TRUE);
1105     nsIDOMElement_Release(nselem);
1106
1107     *newElem = HTMLELEM(elem);
1108     IHTMLElement_AddRef(HTMLELEM(elem));
1109     return S_OK;
1110 }
1111
1112 static HRESULT WINAPI HTMLDocument_put_onhelp(IHTMLDocument2 *iface, VARIANT v)
1113 {
1114     HTMLDocument *This = HTMLDOC_THIS(iface);
1115     FIXME("(%p)\n", This);
1116     return E_NOTIMPL;
1117 }
1118
1119 static HRESULT WINAPI HTMLDocument_get_onhelp(IHTMLDocument2 *iface, VARIANT *p)
1120 {
1121     HTMLDocument *This = HTMLDOC_THIS(iface);
1122     FIXME("(%p)->(%p)\n", This, p);
1123     return E_NOTIMPL;
1124 }
1125
1126 static HRESULT WINAPI HTMLDocument_put_onclick(IHTMLDocument2 *iface, VARIANT v)
1127 {
1128     HTMLDocument *This = HTMLDOC_THIS(iface);
1129     FIXME("(%p)\n", This);
1130     return E_NOTIMPL;
1131 }
1132
1133 static HRESULT WINAPI HTMLDocument_get_onclick(IHTMLDocument2 *iface, VARIANT *p)
1134 {
1135     HTMLDocument *This = HTMLDOC_THIS(iface);
1136     FIXME("(%p)->(%p)\n", This, p);
1137     return E_NOTIMPL;
1138 }
1139
1140 static HRESULT WINAPI HTMLDocument_put_ondblclick(IHTMLDocument2 *iface, VARIANT v)
1141 {
1142     HTMLDocument *This = HTMLDOC_THIS(iface);
1143     FIXME("(%p)\n", This);
1144     return E_NOTIMPL;
1145 }
1146
1147 static HRESULT WINAPI HTMLDocument_get_ondblclick(IHTMLDocument2 *iface, VARIANT *p)
1148 {
1149     HTMLDocument *This = HTMLDOC_THIS(iface);
1150     FIXME("(%p)->(%p)\n", This, p);
1151     return E_NOTIMPL;
1152 }
1153
1154 static HRESULT WINAPI HTMLDocument_put_onkeyup(IHTMLDocument2 *iface, VARIANT v)
1155 {
1156     HTMLDocument *This = HTMLDOC_THIS(iface);
1157
1158     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1159
1160     return set_doc_event(This, EVENTID_KEYUP, &v);
1161 }
1162
1163 static HRESULT WINAPI HTMLDocument_get_onkeyup(IHTMLDocument2 *iface, VARIANT *p)
1164 {
1165     HTMLDocument *This = HTMLDOC_THIS(iface);
1166
1167     TRACE("(%p)->(%p)\n", This, p);
1168
1169     return get_doc_event(This, EVENTID_KEYUP, p);
1170 }
1171
1172 static HRESULT WINAPI HTMLDocument_put_onkeydown(IHTMLDocument2 *iface, VARIANT v)
1173 {
1174     HTMLDocument *This = HTMLDOC_THIS(iface);
1175
1176     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1177
1178     return set_doc_event(This, EVENTID_KEYDOWN, &v);
1179 }
1180
1181 static HRESULT WINAPI HTMLDocument_get_onkeydown(IHTMLDocument2 *iface, VARIANT *p)
1182 {
1183     HTMLDocument *This = HTMLDOC_THIS(iface);
1184
1185     TRACE("(%p)->(%p)\n", This, p);
1186
1187     return get_doc_event(This, EVENTID_KEYDOWN, p);
1188 }
1189
1190 static HRESULT WINAPI HTMLDocument_put_onkeypress(IHTMLDocument2 *iface, VARIANT v)
1191 {
1192     HTMLDocument *This = HTMLDOC_THIS(iface);
1193     FIXME("(%p)\n", This);
1194     return E_NOTIMPL;
1195 }
1196
1197 static HRESULT WINAPI HTMLDocument_get_onkeypress(IHTMLDocument2 *iface, VARIANT *p)
1198 {
1199     HTMLDocument *This = HTMLDOC_THIS(iface);
1200     FIXME("(%p)->(%p)\n", This, p);
1201     return E_NOTIMPL;
1202 }
1203
1204 static HRESULT WINAPI HTMLDocument_put_onmouseup(IHTMLDocument2 *iface, VARIANT v)
1205 {
1206     HTMLDocument *This = HTMLDOC_THIS(iface);
1207     FIXME("(%p)\n", This);
1208     return E_NOTIMPL;
1209 }
1210
1211 static HRESULT WINAPI HTMLDocument_get_onmouseup(IHTMLDocument2 *iface, VARIANT *p)
1212 {
1213     HTMLDocument *This = HTMLDOC_THIS(iface);
1214     FIXME("(%p)->(%p)\n", This, p);
1215     return E_NOTIMPL;
1216 }
1217
1218 static HRESULT WINAPI HTMLDocument_put_onmousedown(IHTMLDocument2 *iface, VARIANT v)
1219 {
1220     HTMLDocument *This = HTMLDOC_THIS(iface);
1221     FIXME("(%p)\n", This);
1222     return E_NOTIMPL;
1223 }
1224
1225 static HRESULT WINAPI HTMLDocument_get_onmousedown(IHTMLDocument2 *iface, VARIANT *p)
1226 {
1227     HTMLDocument *This = HTMLDOC_THIS(iface);
1228     FIXME("(%p)->(%p)\n", This, p);
1229     return E_NOTIMPL;
1230 }
1231
1232 static HRESULT WINAPI HTMLDocument_put_onmousemove(IHTMLDocument2 *iface, VARIANT v)
1233 {
1234     HTMLDocument *This = HTMLDOC_THIS(iface);
1235     FIXME("(%p)\n", This);
1236     return E_NOTIMPL;
1237 }
1238
1239 static HRESULT WINAPI HTMLDocument_get_onmousemove(IHTMLDocument2 *iface, VARIANT *p)
1240 {
1241     HTMLDocument *This = HTMLDOC_THIS(iface);
1242     FIXME("(%p)->(%p)\n", This, p);
1243     return E_NOTIMPL;
1244 }
1245
1246 static HRESULT WINAPI HTMLDocument_put_onmouseout(IHTMLDocument2 *iface, VARIANT v)
1247 {
1248     HTMLDocument *This = HTMLDOC_THIS(iface);
1249     FIXME("(%p)\n", This);
1250     return E_NOTIMPL;
1251 }
1252
1253 static HRESULT WINAPI HTMLDocument_get_onmouseout(IHTMLDocument2 *iface, VARIANT *p)
1254 {
1255     HTMLDocument *This = HTMLDOC_THIS(iface);
1256     FIXME("(%p)->(%p)\n", This, p);
1257     return E_NOTIMPL;
1258 }
1259
1260 static HRESULT WINAPI HTMLDocument_put_onmouseover(IHTMLDocument2 *iface, VARIANT v)
1261 {
1262     HTMLDocument *This = HTMLDOC_THIS(iface);
1263
1264     TRACE("(%p)\n", This);
1265
1266     return set_doc_event(This, EVENTID_MOUSEOVER, &v);
1267 }
1268
1269 static HRESULT WINAPI HTMLDocument_get_onmouseover(IHTMLDocument2 *iface, VARIANT *p)
1270 {
1271     HTMLDocument *This = HTMLDOC_THIS(iface);
1272
1273     TRACE("(%p)->(%p)\n", This, p);
1274
1275     return get_doc_event(This, EVENTID_MOUSEOVER, p);
1276 }
1277
1278 static HRESULT WINAPI HTMLDocument_put_onreadystatechange(IHTMLDocument2 *iface, VARIANT v)
1279 {
1280     HTMLDocument *This = HTMLDOC_THIS(iface);
1281     FIXME("(%p)\n", This);
1282     return E_NOTIMPL;
1283 }
1284
1285 static HRESULT WINAPI HTMLDocument_get_onreadystatechange(IHTMLDocument2 *iface, VARIANT *p)
1286 {
1287     HTMLDocument *This = HTMLDOC_THIS(iface);
1288     FIXME("(%p)->(%p)\n", This, p);
1289     return E_NOTIMPL;
1290 }
1291
1292 static HRESULT WINAPI HTMLDocument_put_onafterupdate(IHTMLDocument2 *iface, VARIANT v)
1293 {
1294     HTMLDocument *This = HTMLDOC_THIS(iface);
1295     FIXME("(%p)\n", This);
1296     return E_NOTIMPL;
1297 }
1298
1299 static HRESULT WINAPI HTMLDocument_get_onafterupdate(IHTMLDocument2 *iface, VARIANT *p)
1300 {
1301     HTMLDocument *This = HTMLDOC_THIS(iface);
1302     FIXME("(%p)->(%p)\n", This, p);
1303     return E_NOTIMPL;
1304 }
1305
1306 static HRESULT WINAPI HTMLDocument_put_onrowexit(IHTMLDocument2 *iface, VARIANT v)
1307 {
1308     HTMLDocument *This = HTMLDOC_THIS(iface);
1309     FIXME("(%p)\n", This);
1310     return E_NOTIMPL;
1311 }
1312
1313 static HRESULT WINAPI HTMLDocument_get_onrowexit(IHTMLDocument2 *iface, VARIANT *p)
1314 {
1315     HTMLDocument *This = HTMLDOC_THIS(iface);
1316     FIXME("(%p)->(%p)\n", This, p);
1317     return E_NOTIMPL;
1318 }
1319
1320 static HRESULT WINAPI HTMLDocument_put_onrowenter(IHTMLDocument2 *iface, VARIANT v)
1321 {
1322     HTMLDocument *This = HTMLDOC_THIS(iface);
1323     FIXME("(%p)\n", This);
1324     return E_NOTIMPL;
1325 }
1326
1327 static HRESULT WINAPI HTMLDocument_get_onrowenter(IHTMLDocument2 *iface, VARIANT *p)
1328 {
1329     HTMLDocument *This = HTMLDOC_THIS(iface);
1330     FIXME("(%p)->(%p)\n", This, p);
1331     return E_NOTIMPL;
1332 }
1333
1334 static HRESULT WINAPI HTMLDocument_put_ondragstart(IHTMLDocument2 *iface, VARIANT v)
1335 {
1336     HTMLDocument *This = HTMLDOC_THIS(iface);
1337
1338     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1339
1340     return set_doc_event(This, EVENTID_DRAGSTART, &v);
1341 }
1342
1343 static HRESULT WINAPI HTMLDocument_get_ondragstart(IHTMLDocument2 *iface, VARIANT *p)
1344 {
1345     HTMLDocument *This = HTMLDOC_THIS(iface);
1346
1347     TRACE("(%p)->(%p)\n", This, p);
1348
1349     return get_doc_event(This, EVENTID_DRAGSTART, p);
1350 }
1351
1352 static HRESULT WINAPI HTMLDocument_put_onselectstart(IHTMLDocument2 *iface, VARIANT v)
1353 {
1354     HTMLDocument *This = HTMLDOC_THIS(iface);
1355
1356     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1357
1358     return set_doc_event(This, EVENTID_SELECTSTART, &v);
1359 }
1360
1361 static HRESULT WINAPI HTMLDocument_get_onselectstart(IHTMLDocument2 *iface, VARIANT *p)
1362 {
1363     HTMLDocument *This = HTMLDOC_THIS(iface);
1364
1365     TRACE("(%p)->(%p)\n", This, p);
1366
1367     return get_doc_event(This, EVENTID_SELECTSTART, p);
1368 }
1369
1370 static HRESULT WINAPI HTMLDocument_elementFromPoint(IHTMLDocument2 *iface, LONG x, LONG y,
1371                                                         IHTMLElement **elementHit)
1372 {
1373     HTMLDocument *This = HTMLDOC_THIS(iface);
1374     FIXME("(%p)->(%d %d %p)\n", This, x, y, elementHit);
1375     return E_NOTIMPL;
1376 }
1377
1378 static HRESULT WINAPI HTMLDocument_get_parentWindow(IHTMLDocument2 *iface, IHTMLWindow2 **p)
1379 {
1380     HTMLDocument *This = HTMLDOC_THIS(iface);
1381
1382     TRACE("(%p)->(%p)\n", This, p);
1383
1384     *p = HTMLWINDOW2(This->window);
1385     IHTMLWindow2_AddRef(*p);
1386     return S_OK;
1387 }
1388
1389 static HRESULT WINAPI HTMLDocument_get_styleSheets(IHTMLDocument2 *iface,
1390                                                    IHTMLStyleSheetsCollection **p)
1391 {
1392     HTMLDocument *This = HTMLDOC_THIS(iface);
1393     nsIDOMStyleSheetList *nsstylelist;
1394     nsIDOMDocumentStyle *nsdocstyle;
1395     nsresult nsres;
1396
1397     TRACE("(%p)->(%p)\n", This, p);
1398
1399     *p = NULL;
1400
1401     if(!This->nsdoc) {
1402         WARN("NULL nsdoc\n");
1403         return E_UNEXPECTED;
1404     }
1405
1406     nsIDOMHTMLDocument_QueryInterface(This->nsdoc, &IID_nsIDOMDocumentStyle, (void**)&nsdocstyle);
1407     nsres = nsIDOMDocumentStyle_GetStyleSheets(nsdocstyle, &nsstylelist);
1408     nsIDOMDocumentStyle_Release(nsdocstyle);
1409     if(NS_FAILED(nsres)) {
1410         ERR("GetStyleSheets failed: %08x\n", nsres);
1411         return E_FAIL;
1412     }
1413
1414     *p = HTMLStyleSheetsCollection_Create(nsstylelist);
1415     nsIDOMDocumentStyle_Release(nsstylelist);
1416
1417     return S_OK;
1418 }
1419
1420 static HRESULT WINAPI HTMLDocument_put_onbeforeupdate(IHTMLDocument2 *iface, VARIANT v)
1421 {
1422     HTMLDocument *This = HTMLDOC_THIS(iface);
1423     FIXME("(%p)\n", This);
1424     return E_NOTIMPL;
1425 }
1426
1427 static HRESULT WINAPI HTMLDocument_get_onbeforeupdate(IHTMLDocument2 *iface, VARIANT *p)
1428 {
1429     HTMLDocument *This = HTMLDOC_THIS(iface);
1430     FIXME("(%p)->(%p)\n", This, p);
1431     return E_NOTIMPL;
1432 }
1433
1434 static HRESULT WINAPI HTMLDocument_put_onerrorupdate(IHTMLDocument2 *iface, VARIANT v)
1435 {
1436     HTMLDocument *This = HTMLDOC_THIS(iface);
1437     FIXME("(%p)\n", This);
1438     return E_NOTIMPL;
1439 }
1440
1441 static HRESULT WINAPI HTMLDocument_get_onerrorupdate(IHTMLDocument2 *iface, VARIANT *p)
1442 {
1443     HTMLDocument *This = HTMLDOC_THIS(iface);
1444     FIXME("(%p)->(%p)\n", This, p);
1445     return E_NOTIMPL;
1446 }
1447
1448 static HRESULT WINAPI HTMLDocument_toString(IHTMLDocument2 *iface, BSTR *String)
1449 {
1450     HTMLDocument *This = HTMLDOC_THIS(iface);
1451     FIXME("(%p)->(%p)\n", This, String);
1452     return E_NOTIMPL;
1453 }
1454
1455 static HRESULT WINAPI HTMLDocument_createStyleSheet(IHTMLDocument2 *iface, BSTR bstrHref,
1456                                             LONG lIndex, IHTMLStyleSheet **ppnewStyleSheet)
1457 {
1458     HTMLDocument *This = HTMLDOC_THIS(iface);
1459
1460     FIXME("(%p)->(%s %d %p) semi-stub\n", This, debugstr_w(bstrHref), lIndex, ppnewStyleSheet);
1461
1462     *ppnewStyleSheet = HTMLStyleSheet_Create(NULL);
1463     return S_OK;
1464 }
1465
1466 static const IHTMLDocument2Vtbl HTMLDocumentVtbl = {
1467     HTMLDocument_QueryInterface,
1468     HTMLDocument_AddRef,
1469     HTMLDocument_Release,
1470     HTMLDocument_GetTypeInfoCount,
1471     HTMLDocument_GetTypeInfo,
1472     HTMLDocument_GetIDsOfNames,
1473     HTMLDocument_Invoke,
1474     HTMLDocument_get_Script,
1475     HTMLDocument_get_all,
1476     HTMLDocument_get_body,
1477     HTMLDocument_get_activeElement,
1478     HTMLDocument_get_images,
1479     HTMLDocument_get_applets,
1480     HTMLDocument_get_links,
1481     HTMLDocument_get_forms,
1482     HTMLDocument_get_anchors,
1483     HTMLDocument_put_title,
1484     HTMLDocument_get_title,
1485     HTMLDocument_get_scripts,
1486     HTMLDocument_put_designMode,
1487     HTMLDocument_get_designMode,
1488     HTMLDocument_get_selection,
1489     HTMLDocument_get_readyState,
1490     HTMLDocument_get_frames,
1491     HTMLDocument_get_embeds,
1492     HTMLDocument_get_plugins,
1493     HTMLDocument_put_alinkColor,
1494     HTMLDocument_get_alinkColor,
1495     HTMLDocument_put_bgColor,
1496     HTMLDocument_get_bgColor,
1497     HTMLDocument_put_fgColor,
1498     HTMLDocument_get_fgColor,
1499     HTMLDocument_put_linkColor,
1500     HTMLDocument_get_linkColor,
1501     HTMLDocument_put_vlinkColor,
1502     HTMLDocument_get_vlinkColor,
1503     HTMLDocument_get_referrer,
1504     HTMLDocument_get_location,
1505     HTMLDocument_get_lastModified,
1506     HTMLDocument_put_URL,
1507     HTMLDocument_get_URL,
1508     HTMLDocument_put_domain,
1509     HTMLDocument_get_domain,
1510     HTMLDocument_put_cookie,
1511     HTMLDocument_get_cookie,
1512     HTMLDocument_put_expando,
1513     HTMLDocument_get_expando,
1514     HTMLDocument_put_charset,
1515     HTMLDocument_get_charset,
1516     HTMLDocument_put_defaultCharset,
1517     HTMLDocument_get_defaultCharset,
1518     HTMLDocument_get_mimeType,
1519     HTMLDocument_get_fileSize,
1520     HTMLDocument_get_fileCreatedDate,
1521     HTMLDocument_get_fileModifiedDate,
1522     HTMLDocument_get_fileUpdatedDate,
1523     HTMLDocument_get_security,
1524     HTMLDocument_get_protocol,
1525     HTMLDocument_get_nameProp,
1526     HTMLDocument_write,
1527     HTMLDocument_writeln,
1528     HTMLDocument_open,
1529     HTMLDocument_close,
1530     HTMLDocument_clear,
1531     HTMLDocument_queryCommandSupported,
1532     HTMLDocument_queryCommandEnabled,
1533     HTMLDocument_queryCommandState,
1534     HTMLDocument_queryCommandIndeterm,
1535     HTMLDocument_queryCommandText,
1536     HTMLDocument_queryCommandValue,
1537     HTMLDocument_execCommand,
1538     HTMLDocument_execCommandShowHelp,
1539     HTMLDocument_createElement,
1540     HTMLDocument_put_onhelp,
1541     HTMLDocument_get_onhelp,
1542     HTMLDocument_put_onclick,
1543     HTMLDocument_get_onclick,
1544     HTMLDocument_put_ondblclick,
1545     HTMLDocument_get_ondblclick,
1546     HTMLDocument_put_onkeyup,
1547     HTMLDocument_get_onkeyup,
1548     HTMLDocument_put_onkeydown,
1549     HTMLDocument_get_onkeydown,
1550     HTMLDocument_put_onkeypress,
1551     HTMLDocument_get_onkeypress,
1552     HTMLDocument_put_onmouseup,
1553     HTMLDocument_get_onmouseup,
1554     HTMLDocument_put_onmousedown,
1555     HTMLDocument_get_onmousedown,
1556     HTMLDocument_put_onmousemove,
1557     HTMLDocument_get_onmousemove,
1558     HTMLDocument_put_onmouseout,
1559     HTMLDocument_get_onmouseout,
1560     HTMLDocument_put_onmouseover,
1561     HTMLDocument_get_onmouseover,
1562     HTMLDocument_put_onreadystatechange,
1563     HTMLDocument_get_onreadystatechange,
1564     HTMLDocument_put_onafterupdate,
1565     HTMLDocument_get_onafterupdate,
1566     HTMLDocument_put_onrowexit,
1567     HTMLDocument_get_onrowexit,
1568     HTMLDocument_put_onrowenter,
1569     HTMLDocument_get_onrowenter,
1570     HTMLDocument_put_ondragstart,
1571     HTMLDocument_get_ondragstart,
1572     HTMLDocument_put_onselectstart,
1573     HTMLDocument_get_onselectstart,
1574     HTMLDocument_elementFromPoint,
1575     HTMLDocument_get_parentWindow,
1576     HTMLDocument_get_styleSheets,
1577     HTMLDocument_put_onbeforeupdate,
1578     HTMLDocument_get_onbeforeupdate,
1579     HTMLDocument_put_onerrorupdate,
1580     HTMLDocument_get_onerrorupdate,
1581     HTMLDocument_toString,
1582     HTMLDocument_createStyleSheet
1583 };
1584
1585 #define SUPPINFO_THIS(iface) DEFINE_THIS(HTMLDocument, SupportErrorInfo, iface)
1586
1587 static HRESULT WINAPI SupportErrorInfo_QueryInterface(ISupportErrorInfo *iface, REFIID riid, void **ppv)
1588 {
1589     HTMLDocument *This = SUPPINFO_THIS(iface);
1590     return IHTMLDocument_QueryInterface(HTMLDOC(This), riid, ppv);
1591 }
1592
1593 static ULONG WINAPI SupportErrorInfo_AddRef(ISupportErrorInfo *iface)
1594 {
1595     HTMLDocument *This = SUPPINFO_THIS(iface);
1596     return IHTMLDocument_AddRef(HTMLDOC(This));
1597 }
1598
1599 static ULONG WINAPI SupportErrorInfo_Release(ISupportErrorInfo *iface)
1600 {
1601     HTMLDocument *This = SUPPINFO_THIS(iface);
1602     return IHTMLDocument_Release(HTMLDOC(This));
1603 }
1604
1605 static HRESULT WINAPI SupportErrorInfo_InterfaceSupportsErrorInfo(ISupportErrorInfo *iface, REFIID riid)
1606 {
1607     FIXME("(%p)->(%s)\n", iface, debugstr_guid(riid));
1608     return S_FALSE;
1609 }
1610
1611 static const ISupportErrorInfoVtbl SupportErrorInfoVtbl = {
1612     SupportErrorInfo_QueryInterface,
1613     SupportErrorInfo_AddRef,
1614     SupportErrorInfo_Release,
1615     SupportErrorInfo_InterfaceSupportsErrorInfo
1616 };
1617
1618 #define DISPEX_THIS(iface) DEFINE_THIS(HTMLDocument, IDispatchEx, iface)
1619
1620 static HRESULT WINAPI DocDispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
1621 {
1622     HTMLDocument *This = DISPEX_THIS(iface);
1623
1624     return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppv);
1625 }
1626
1627 static ULONG WINAPI DocDispatchEx_AddRef(IDispatchEx *iface)
1628 {
1629     HTMLDocument *This = DISPEX_THIS(iface);
1630
1631     return IHTMLDocument2_AddRef(HTMLDOC(This));
1632 }
1633
1634 static ULONG WINAPI DocDispatchEx_Release(IDispatchEx *iface)
1635 {
1636     HTMLDocument *This = DISPEX_THIS(iface);
1637
1638     return IHTMLDocument2_Release(HTMLDOC(This));
1639 }
1640
1641 static HRESULT WINAPI DocDispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
1642 {
1643     HTMLDocument *This = DISPEX_THIS(iface);
1644
1645     return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->dispex), pctinfo);
1646 }
1647
1648 static HRESULT WINAPI DocDispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
1649                                                LCID lcid, ITypeInfo **ppTInfo)
1650 {
1651     HTMLDocument *This = DISPEX_THIS(iface);
1652
1653     return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
1654 }
1655
1656 static HRESULT WINAPI DocDispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
1657                                                  LPOLESTR *rgszNames, UINT cNames,
1658                                                  LCID lcid, DISPID *rgDispId)
1659 {
1660     HTMLDocument *This = DISPEX_THIS(iface);
1661
1662     return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->dispex), riid, rgszNames, cNames, lcid, rgDispId);
1663 }
1664
1665 static HRESULT WINAPI DocDispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
1666                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1667                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1668 {
1669     HTMLDocument *This = DISPEX_THIS(iface);
1670
1671     TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1672           lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1673
1674     switch(dispIdMember) {
1675     case DISPID_READYSTATE:
1676         TRACE("DISPID_READYSTATE\n");
1677
1678         if(!(wFlags & DISPATCH_PROPERTYGET))
1679             return E_INVALIDARG;
1680
1681         V_VT(pVarResult) = VT_I4;
1682         V_I4(pVarResult) = This->readystate;
1683         return S_OK;
1684     }
1685
1686     return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid, wFlags, pDispParams,
1687                               pVarResult, pExcepInfo, puArgErr);
1688 }
1689
1690 static HRESULT WINAPI DocDispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
1691 {
1692     HTMLDocument *This = DISPEX_THIS(iface);
1693
1694     return IDispatchEx_GetDispID(DISPATCHEX(&This->dispex), bstrName, grfdex, pid);
1695 }
1696
1697 static HRESULT WINAPI DocDispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1698         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1699 {
1700     HTMLDocument *This = DISPEX_THIS(iface);
1701
1702     return IDispatchEx_InvokeEx(DISPATCHEX(&This->dispex), id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1703 }
1704
1705 static HRESULT WINAPI DocDispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
1706 {
1707     HTMLDocument *This = DISPEX_THIS(iface);
1708
1709     return IDispatchEx_DeleteMemberByName(DISPATCHEX(&This->dispex), bstrName, grfdex);
1710 }
1711
1712 static HRESULT WINAPI DocDispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
1713 {
1714     HTMLDocument *This = DISPEX_THIS(iface);
1715
1716     return IDispatchEx_DeleteMemberByDispID(DISPATCHEX(&This->dispex), id);
1717 }
1718
1719 static HRESULT WINAPI DocDispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
1720 {
1721     HTMLDocument *This = DISPEX_THIS(iface);
1722
1723     return IDispatchEx_GetMemberProperties(DISPATCHEX(&This->dispex), id, grfdexFetch, pgrfdex);
1724 }
1725
1726 static HRESULT WINAPI DocDispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
1727 {
1728     HTMLDocument *This = DISPEX_THIS(iface);
1729
1730     return IDispatchEx_GetMemberName(DISPATCHEX(&This->dispex), id, pbstrName);
1731 }
1732
1733 static HRESULT WINAPI DocDispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
1734 {
1735     HTMLDocument *This = DISPEX_THIS(iface);
1736
1737     return IDispatchEx_GetNextDispID(DISPATCHEX(&This->dispex), grfdex, id, pid);
1738 }
1739
1740 static HRESULT WINAPI DocDispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
1741 {
1742     HTMLDocument *This = DISPEX_THIS(iface);
1743
1744     return IDispatchEx_GetNameSpaceParent(DISPATCHEX(&This->dispex), ppunk);
1745 }
1746
1747 #undef DISPEX_THIS
1748
1749 static const IDispatchExVtbl DocDispatchExVtbl = {
1750     DocDispatchEx_QueryInterface,
1751     DocDispatchEx_AddRef,
1752     DocDispatchEx_Release,
1753     DocDispatchEx_GetTypeInfoCount,
1754     DocDispatchEx_GetTypeInfo,
1755     DocDispatchEx_GetIDsOfNames,
1756     DocDispatchEx_Invoke,
1757     DocDispatchEx_GetDispID,
1758     DocDispatchEx_InvokeEx,
1759     DocDispatchEx_DeleteMemberByName,
1760     DocDispatchEx_DeleteMemberByDispID,
1761     DocDispatchEx_GetMemberProperties,
1762     DocDispatchEx_GetMemberName,
1763     DocDispatchEx_GetNextDispID,
1764     DocDispatchEx_GetNameSpaceParent
1765 };
1766
1767 static const tid_t HTMLDocument_iface_tids[] = {
1768     IHTMLDocument2_tid,
1769     IHTMLDocument3_tid,
1770     IHTMLDocument4_tid,
1771     IHTMLDocument5_tid,
1772     0
1773 };
1774 static dispex_static_data_t HTMLDocument_dispex = {
1775     NULL,
1776     DispHTMLDocument_tid,
1777     NULL,
1778     HTMLDocument_iface_tids
1779 };
1780
1781 static HRESULT alloc_doc(HTMLDocument **ret)
1782 {
1783     HTMLDocument *doc;
1784
1785     doc = heap_alloc_zero(sizeof(HTMLDocument));
1786     doc->lpHTMLDocument2Vtbl = &HTMLDocumentVtbl;
1787     doc->lpIDispatchExVtbl = &DocDispatchExVtbl;
1788     doc->lpSupportErrorInfoVtbl = &SupportErrorInfoVtbl;
1789     doc->ref = 1;
1790     doc->readystate = READYSTATE_UNINITIALIZED;
1791     doc->scriptmode = SCRIPTMODE_GECKO;
1792
1793     list_init(&doc->bindings);
1794     list_init(&doc->script_hosts);
1795     list_init(&doc->selection_list);
1796     list_init(&doc->range_list);
1797
1798     HTMLDocument_HTMLDocument3_Init(doc);
1799     HTMLDocument_HTMLDocument5_Init(doc);
1800     HTMLDocument_Persist_Init(doc);
1801     HTMLDocument_OleCmd_Init(doc);
1802     HTMLDocument_OleObj_Init(doc);
1803     HTMLDocument_View_Init(doc);
1804     HTMLDocument_Window_Init(doc);
1805     HTMLDocument_Service_Init(doc);
1806     HTMLDocument_Hlink_Init(doc);
1807
1808     ConnectionPointContainer_Init(&doc->cp_container, (IUnknown*)HTMLDOC(doc));
1809     ConnectionPoint_Init(&doc->cp_propnotif, &doc->cp_container, &IID_IPropertyNotifySink);
1810     ConnectionPoint_Init(&doc->cp_htmldocevents, &doc->cp_container, &DIID_HTMLDocumentEvents);
1811     ConnectionPoint_Init(&doc->cp_htmldocevents2, &doc->cp_container, &DIID_HTMLDocumentEvents2);
1812
1813     init_dispex(&doc->dispex, (IUnknown*)HTMLDOC(doc), &HTMLDocument_dispex);
1814
1815     *ret = doc;
1816     return S_OK;
1817 }
1818
1819 HRESULT create_doc_from_nsdoc(nsIDOMHTMLDocument *nsdoc, HTMLDocument **ret)
1820 {
1821     HTMLDocument *doc;
1822     HRESULT hres;
1823
1824     hres = alloc_doc(&doc);
1825     if(FAILED(hres))
1826         return hres;
1827
1828     nsIDOMHTMLDocument_AddRef(nsdoc);
1829     doc->nsdoc = nsdoc;
1830
1831     hres = HTMLWindow_Create(doc, NULL, &doc->window);
1832     if(FAILED(hres)) {
1833         IHTMLDocument_Release(HTMLDOC(doc));
1834         return hres;
1835     }
1836
1837     *ret = doc;
1838     return S_OK;
1839 }
1840
1841 HRESULT HTMLDocument_Create(IUnknown *pUnkOuter, REFIID riid, void** ppvObject)
1842 {
1843     HTMLDocument *doc;
1844     nsIDOMWindow *nswindow = NULL;
1845     HRESULT hres;
1846
1847     TRACE("(%p %s %p)\n", pUnkOuter, debugstr_guid(riid), ppvObject);
1848
1849     hres = alloc_doc(&doc);
1850     if(FAILED(hres))
1851         return hres;
1852
1853     hres = IHTMLDocument_QueryInterface(HTMLDOC(doc), riid, ppvObject);
1854     IHTMLDocument_Release(HTMLDOC(doc));
1855     if(FAILED(hres))
1856         return hres;
1857
1858     doc->nscontainer = NSContainer_Create(doc, NULL);
1859     update_nsdocument(doc);
1860
1861     if(doc->nscontainer) {
1862         nsresult nsres;
1863
1864         nsres = nsIWebBrowser_GetContentDOMWindow(doc->nscontainer->webbrowser, &nswindow);
1865         if(NS_FAILED(nsres))
1866             ERR("GetContentDOMWindow failed: %08x\n", nsres);
1867     }
1868
1869     hres = HTMLWindow_Create(doc, nswindow, &doc->window);
1870     if(nswindow)
1871         nsIDOMWindow_Release(nswindow);
1872     if(FAILED(hres)) {
1873         IHTMLDocument_Release(HTMLDOC(doc));
1874         return hres;
1875     }
1876
1877     get_thread_hwnd();
1878
1879     return S_OK;
1880 }