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