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