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