wineps: Move the installed font list to a standard list.
[wine/multimedia.git] / dlls / mshtml / htmldoc.c
bloba5b20bce1b43624ffa36920323b0b36babb07705
1 /*
2 * Copyright 2005-2009 Jacek Caban for CodeWeavers
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.
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.
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
19 #include "config.h"
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "wininet.h"
30 #include "ole2.h"
31 #include "perhist.h"
32 #include "mshtmdid.h"
34 #include "wine/debug.h"
36 #include "mshtml_private.h"
37 #include "htmlevent.h"
38 #include "pluginhost.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
42 static inline HTMLDocument *impl_from_IHTMLDocument2(IHTMLDocument2 *iface)
44 return CONTAINING_RECORD(iface, HTMLDocument, IHTMLDocument2_iface);
47 static HRESULT WINAPI HTMLDocument_QueryInterface(IHTMLDocument2 *iface, REFIID riid, void **ppv)
49 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
51 return htmldoc_query_interface(This, riid, ppv);
54 static ULONG WINAPI HTMLDocument_AddRef(IHTMLDocument2 *iface)
56 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
58 return htmldoc_addref(This);
61 static ULONG WINAPI HTMLDocument_Release(IHTMLDocument2 *iface)
63 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
65 return htmldoc_release(This);
68 static HRESULT WINAPI HTMLDocument_GetTypeInfoCount(IHTMLDocument2 *iface, UINT *pctinfo)
70 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
72 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
75 static HRESULT WINAPI HTMLDocument_GetTypeInfo(IHTMLDocument2 *iface, UINT iTInfo,
76 LCID lcid, ITypeInfo **ppTInfo)
78 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
80 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
83 static HRESULT WINAPI HTMLDocument_GetIDsOfNames(IHTMLDocument2 *iface, REFIID riid,
84 LPOLESTR *rgszNames, UINT cNames,
85 LCID lcid, DISPID *rgDispId)
87 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
89 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
90 rgDispId);
93 static HRESULT WINAPI HTMLDocument_Invoke(IHTMLDocument2 *iface, DISPID dispIdMember,
94 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
95 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
97 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
99 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
100 pDispParams, pVarResult, pExcepInfo, puArgErr);
103 static HRESULT WINAPI HTMLDocument_get_Script(IHTMLDocument2 *iface, IDispatch **p)
105 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
107 TRACE("(%p)->(%p)\n", This, p);
109 *p = (IDispatch*)&This->window->IHTMLWindow2_iface;
110 IDispatch_AddRef(*p);
111 return S_OK;
114 static HRESULT WINAPI HTMLDocument_get_all(IHTMLDocument2 *iface, IHTMLElementCollection **p)
116 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
117 nsIDOMElement *nselem = NULL;
118 HTMLDOMNode *node;
119 nsresult nsres;
120 HRESULT hres;
122 TRACE("(%p)->(%p)\n", This, p);
124 if(!This->doc_node->nsdoc) {
125 WARN("NULL nsdoc\n");
126 return E_UNEXPECTED;
129 nsres = nsIDOMHTMLDocument_GetDocumentElement(This->doc_node->nsdoc, &nselem);
130 if(NS_FAILED(nsres)) {
131 ERR("GetDocumentElement failed: %08x\n", nsres);
132 return E_FAIL;
135 if(!nselem) {
136 *p = NULL;
137 return S_OK;
140 hres = get_node(This->doc_node, (nsIDOMNode*)nselem, TRUE, &node);
141 if(SUCCEEDED(hres))
142 *p = create_all_collection(node, TRUE);
143 nsIDOMElement_Release(nselem);
144 return hres;
147 static HRESULT WINAPI HTMLDocument_get_body(IHTMLDocument2 *iface, IHTMLElement **p)
149 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
150 nsIDOMHTMLElement *nsbody = NULL;
151 HTMLDOMNode *node;
152 HRESULT hres;
154 TRACE("(%p)->(%p)\n", This, p);
156 if(This->doc_node->nsdoc) {
157 nsresult nsres;
159 nsres = nsIDOMHTMLDocument_GetBody(This->doc_node->nsdoc, &nsbody);
160 if(NS_FAILED(nsres)) {
161 TRACE("Could not get body: %08x\n", nsres);
162 return E_UNEXPECTED;
166 if(!nsbody) {
167 *p = NULL;
168 return S_OK;
171 hres = get_node(This->doc_node, (nsIDOMNode*)nsbody, TRUE, &node);
172 nsIDOMHTMLElement_Release(nsbody);
173 if(FAILED(hres))
174 return hres;
176 return IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)p);
179 static HRESULT WINAPI HTMLDocument_get_activeElement(IHTMLDocument2 *iface, IHTMLElement **p)
181 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
182 FIXME("(%p)->(%p)\n", This, p);
183 return E_NOTIMPL;
186 static HRESULT WINAPI HTMLDocument_get_images(IHTMLDocument2 *iface, IHTMLElementCollection **p)
188 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
189 nsIDOMHTMLCollection *nscoll = NULL;
190 nsresult nsres;
192 TRACE("(%p)->(%p)\n", This, p);
194 if(!p)
195 return E_INVALIDARG;
197 *p = NULL;
199 if(!This->doc_node->nsdoc) {
200 WARN("NULL nsdoc\n");
201 return E_UNEXPECTED;
204 nsres = nsIDOMHTMLDocument_GetImages(This->doc_node->nsdoc, &nscoll);
205 if(NS_FAILED(nsres)) {
206 ERR("GetImages failed: %08x\n", nsres);
207 return E_FAIL;
210 if(nscoll) {
211 *p = create_collection_from_htmlcol(This->doc_node, (IUnknown*)&This->IHTMLDocument2_iface, nscoll);
212 nsIDOMElement_Release(nscoll);
215 return S_OK;
218 static HRESULT WINAPI HTMLDocument_get_applets(IHTMLDocument2 *iface, IHTMLElementCollection **p)
220 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
221 nsIDOMHTMLCollection *nscoll = NULL;
222 nsresult nsres;
224 TRACE("(%p)->(%p)\n", This, p);
226 if(!p)
227 return E_INVALIDARG;
229 *p = NULL;
231 if(!This->doc_node->nsdoc) {
232 WARN("NULL nsdoc\n");
233 return E_UNEXPECTED;
236 nsres = nsIDOMHTMLDocument_GetApplets(This->doc_node->nsdoc, &nscoll);
237 if(NS_FAILED(nsres)) {
238 ERR("GetApplets failed: %08x\n", nsres);
239 return E_FAIL;
242 if(nscoll) {
243 *p = create_collection_from_htmlcol(This->doc_node, (IUnknown*)&This->IHTMLDocument2_iface, nscoll);
244 nsIDOMElement_Release(nscoll);
247 return S_OK;
250 static HRESULT WINAPI HTMLDocument_get_links(IHTMLDocument2 *iface, IHTMLElementCollection **p)
252 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
253 nsIDOMHTMLCollection *nscoll = NULL;
254 nsresult nsres;
256 TRACE("(%p)->(%p)\n", This, p);
258 if(!p)
259 return E_INVALIDARG;
261 *p = NULL;
263 if(!This->doc_node->nsdoc) {
264 WARN("NULL nsdoc\n");
265 return E_UNEXPECTED;
268 nsres = nsIDOMHTMLDocument_GetLinks(This->doc_node->nsdoc, &nscoll);
269 if(NS_FAILED(nsres)) {
270 ERR("GetLinks failed: %08x\n", nsres);
271 return E_FAIL;
274 if(nscoll) {
275 *p = create_collection_from_htmlcol(This->doc_node, (IUnknown*)&This->IHTMLDocument2_iface, nscoll);
276 nsIDOMElement_Release(nscoll);
279 return S_OK;
282 static HRESULT WINAPI HTMLDocument_get_forms(IHTMLDocument2 *iface, IHTMLElementCollection **p)
284 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
285 nsIDOMHTMLCollection *nscoll = NULL;
286 nsresult nsres;
288 TRACE("(%p)->(%p)\n", This, p);
290 if(!p)
291 return E_INVALIDARG;
293 *p = NULL;
295 if(!This->doc_node->nsdoc) {
296 WARN("NULL nsdoc\n");
297 return E_UNEXPECTED;
300 nsres = nsIDOMHTMLDocument_GetForms(This->doc_node->nsdoc, &nscoll);
301 if(NS_FAILED(nsres)) {
302 ERR("GetForms failed: %08x\n", nsres);
303 return E_FAIL;
306 if(nscoll) {
307 *p = create_collection_from_htmlcol(This->doc_node, (IUnknown*)&This->IHTMLDocument2_iface, nscoll);
308 nsIDOMElement_Release(nscoll);
311 return S_OK;
314 static HRESULT WINAPI HTMLDocument_get_anchors(IHTMLDocument2 *iface, IHTMLElementCollection **p)
316 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
317 nsIDOMHTMLCollection *nscoll = NULL;
318 nsresult nsres;
320 TRACE("(%p)->(%p)\n", This, p);
322 if(!p)
323 return E_INVALIDARG;
325 *p = NULL;
327 if(!This->doc_node->nsdoc) {
328 WARN("NULL nsdoc\n");
329 return E_UNEXPECTED;
332 nsres = nsIDOMHTMLDocument_GetAnchors(This->doc_node->nsdoc, &nscoll);
333 if(NS_FAILED(nsres)) {
334 ERR("GetAnchors failed: %08x\n", nsres);
335 return E_FAIL;
338 if(nscoll) {
339 *p = create_collection_from_htmlcol(This->doc_node, (IUnknown*)&This->IHTMLDocument2_iface, nscoll);
340 nsIDOMElement_Release(nscoll);
343 return S_OK;
346 static HRESULT WINAPI HTMLDocument_put_title(IHTMLDocument2 *iface, BSTR v)
348 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
349 nsAString nsstr;
350 nsresult nsres;
352 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
354 if(!This->doc_node->nsdoc) {
355 WARN("NULL nsdoc\n");
356 return E_UNEXPECTED;
359 nsAString_InitDepend(&nsstr, v);
360 nsres = nsIDOMHTMLDocument_SetTitle(This->doc_node->nsdoc, &nsstr);
361 nsAString_Finish(&nsstr);
362 if(NS_FAILED(nsres))
363 ERR("SetTitle failed: %08x\n", nsres);
365 return S_OK;
368 static HRESULT WINAPI HTMLDocument_get_title(IHTMLDocument2 *iface, BSTR *p)
370 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
371 const PRUnichar *ret;
372 nsAString nsstr;
373 nsresult nsres;
375 TRACE("(%p)->(%p)\n", This, p);
377 if(!This->doc_node->nsdoc) {
378 WARN("NULL nsdoc\n");
379 return E_UNEXPECTED;
383 nsAString_Init(&nsstr, NULL);
384 nsres = nsIDOMHTMLDocument_GetTitle(This->doc_node->nsdoc, &nsstr);
385 if (NS_SUCCEEDED(nsres)) {
386 nsAString_GetData(&nsstr, &ret);
387 *p = SysAllocString(ret);
389 nsAString_Finish(&nsstr);
391 if(NS_FAILED(nsres)) {
392 ERR("GetTitle failed: %08x\n", nsres);
393 return E_FAIL;
396 return S_OK;
399 static HRESULT WINAPI HTMLDocument_get_scripts(IHTMLDocument2 *iface, IHTMLElementCollection **p)
401 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
402 FIXME("(%p)->(%p)\n", This, p);
403 return E_NOTIMPL;
406 static HRESULT WINAPI HTMLDocument_put_designMode(IHTMLDocument2 *iface, BSTR v)
408 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
409 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
410 return E_NOTIMPL;
413 static HRESULT WINAPI HTMLDocument_get_designMode(IHTMLDocument2 *iface, BSTR *p)
415 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
416 static WCHAR szOff[] = {'O','f','f',0};
417 FIXME("(%p)->(%p) always returning Off\n", This, p);
419 if(!p)
420 return E_INVALIDARG;
422 *p = SysAllocString(szOff);
424 return S_OK;
427 static HRESULT WINAPI HTMLDocument_get_selection(IHTMLDocument2 *iface, IHTMLSelectionObject **p)
429 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
430 nsISelection *nsselection;
431 nsresult nsres;
433 TRACE("(%p)->(%p)\n", This, p);
435 nsres = nsIDOMWindow_GetSelection(This->window->nswindow, &nsselection);
436 if(NS_FAILED(nsres)) {
437 ERR("GetSelection failed: %08x\n", nsres);
438 return E_FAIL;
441 return HTMLSelectionObject_Create(This->doc_node, nsselection, p);
444 static HRESULT WINAPI HTMLDocument_get_readyState(IHTMLDocument2 *iface, BSTR *p)
446 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
448 static const WCHAR wszUninitialized[] = {'u','n','i','n','i','t','i','a','l','i','z','e','d',0};
449 static const WCHAR wszLoading[] = {'l','o','a','d','i','n','g',0};
450 static const WCHAR wszLoaded[] = {'l','o','a','d','e','d',0};
451 static const WCHAR wszInteractive[] = {'i','n','t','e','r','a','c','t','i','v','e',0};
452 static const WCHAR wszComplete[] = {'c','o','m','p','l','e','t','e',0};
454 static const LPCWSTR readystate_str[] = {
455 wszUninitialized,
456 wszLoading,
457 wszLoaded,
458 wszInteractive,
459 wszComplete
462 TRACE("(%p)->(%p)\n", iface, p);
464 if(!p)
465 return E_POINTER;
467 *p = SysAllocString(readystate_str[This->window->readystate]);
468 return S_OK;
471 static HRESULT WINAPI HTMLDocument_get_frames(IHTMLDocument2 *iface, IHTMLFramesCollection2 **p)
473 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
475 TRACE("(%p)->(%p)\n", This, p);
477 return IHTMLWindow2_get_frames(&This->window->IHTMLWindow2_iface, p);
480 static HRESULT WINAPI HTMLDocument_get_embeds(IHTMLDocument2 *iface, IHTMLElementCollection **p)
482 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
483 FIXME("(%p)->(%p)\n", This, p);
484 return E_NOTIMPL;
487 static HRESULT WINAPI HTMLDocument_get_plugins(IHTMLDocument2 *iface, IHTMLElementCollection **p)
489 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
490 FIXME("(%p)->(%p)\n", This, p);
491 return E_NOTIMPL;
494 static HRESULT WINAPI HTMLDocument_put_alinkColor(IHTMLDocument2 *iface, VARIANT v)
496 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
497 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
498 return E_NOTIMPL;
501 static HRESULT WINAPI HTMLDocument_get_alinkColor(IHTMLDocument2 *iface, VARIANT *p)
503 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
504 FIXME("(%p)->(%p)\n", This, p);
505 return E_NOTIMPL;
508 static HRESULT WINAPI HTMLDocument_put_bgColor(IHTMLDocument2 *iface, VARIANT v)
510 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
511 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
512 return E_NOTIMPL;
515 static HRESULT WINAPI HTMLDocument_get_bgColor(IHTMLDocument2 *iface, VARIANT *p)
517 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
518 FIXME("(%p)->(%p)\n", This, p);
519 return E_NOTIMPL;
522 static HRESULT WINAPI HTMLDocument_put_fgColor(IHTMLDocument2 *iface, VARIANT v)
524 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
525 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
526 return E_NOTIMPL;
529 static HRESULT WINAPI HTMLDocument_get_fgColor(IHTMLDocument2 *iface, VARIANT *p)
531 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
532 FIXME("(%p)->(%p)\n", This, p);
533 return E_NOTIMPL;
536 static HRESULT WINAPI HTMLDocument_put_linkColor(IHTMLDocument2 *iface, VARIANT v)
538 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
539 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
540 return E_NOTIMPL;
543 static HRESULT WINAPI HTMLDocument_get_linkColor(IHTMLDocument2 *iface, VARIANT *p)
545 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
546 FIXME("(%p)->(%p)\n", This, p);
547 return E_NOTIMPL;
550 static HRESULT WINAPI HTMLDocument_put_vlinkColor(IHTMLDocument2 *iface, VARIANT v)
552 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
553 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
554 return E_NOTIMPL;
557 static HRESULT WINAPI HTMLDocument_get_vlinkColor(IHTMLDocument2 *iface, VARIANT *p)
559 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
560 FIXME("(%p)->(%p)\n", This, p);
561 return E_NOTIMPL;
564 static HRESULT WINAPI HTMLDocument_get_referrer(IHTMLDocument2 *iface, BSTR *p)
566 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
568 FIXME("(%p)->(%p)\n", This, p);
570 *p = NULL;
571 return S_OK;
574 static HRESULT WINAPI HTMLDocument_get_location(IHTMLDocument2 *iface, IHTMLLocation **p)
576 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
578 TRACE("(%p)->(%p)\n", This, p);
580 if(!This->doc_node->nsdoc) {
581 WARN("NULL nsdoc\n");
582 return E_UNEXPECTED;
585 return IHTMLWindow2_get_location(&This->window->IHTMLWindow2_iface, p);
588 static HRESULT WINAPI HTMLDocument_get_lastModified(IHTMLDocument2 *iface, BSTR *p)
590 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
591 FIXME("(%p)->(%p)\n", This, p);
592 return E_NOTIMPL;
595 static HRESULT WINAPI HTMLDocument_put_URL(IHTMLDocument2 *iface, BSTR v)
597 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
598 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
599 return E_NOTIMPL;
602 static HRESULT WINAPI HTMLDocument_get_URL(IHTMLDocument2 *iface, BSTR *p)
604 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
606 static const WCHAR about_blank_url[] =
607 {'a','b','o','u','t',':','b','l','a','n','k',0};
609 TRACE("(%p)->(%p)\n", iface, p);
611 *p = SysAllocString(This->window->url ? This->window->url : about_blank_url);
612 return *p ? S_OK : E_OUTOFMEMORY;
615 static HRESULT WINAPI HTMLDocument_put_domain(IHTMLDocument2 *iface, BSTR v)
617 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
618 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
619 return E_NOTIMPL;
622 static HRESULT WINAPI HTMLDocument_get_domain(IHTMLDocument2 *iface, BSTR *p)
624 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
625 HRESULT hres;
627 TRACE("(%p)->(%p)\n", This, p);
629 if(!This->window || !This->window->uri) {
630 FIXME("No current URI\n");
631 return E_FAIL;
634 hres = IUri_GetHost(This->window->uri, p);
635 return FAILED(hres) ? hres : S_OK;
638 static HRESULT WINAPI HTMLDocument_put_cookie(IHTMLDocument2 *iface, BSTR v)
640 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
641 BOOL bret;
643 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
645 bret = InternetSetCookieExW(This->window->url, NULL, v, 0, 0);
646 if(!bret) {
647 FIXME("InternetSetCookieExW failed: %u\n", GetLastError());
648 return HRESULT_FROM_WIN32(GetLastError());
651 return S_OK;
654 static HRESULT WINAPI HTMLDocument_get_cookie(IHTMLDocument2 *iface, BSTR *p)
656 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
657 DWORD size;
658 BOOL bret;
660 TRACE("(%p)->(%p)\n", This, p);
662 size = 0;
663 bret = InternetGetCookieExW(This->window->url, NULL, NULL, &size, 0, NULL);
664 if(!bret) {
665 switch(GetLastError()) {
666 case ERROR_INSUFFICIENT_BUFFER:
667 break;
668 case ERROR_NO_MORE_ITEMS:
669 *p = NULL;
670 return S_OK;
671 default:
672 FIXME("InternetGetCookieExW failed: %u\n", GetLastError());
673 return HRESULT_FROM_WIN32(GetLastError());
677 if(!size) {
678 *p = NULL;
679 return S_OK;
682 *p = SysAllocStringLen(NULL, size-1);
683 if(!*p)
684 return E_OUTOFMEMORY;
686 bret = InternetGetCookieExW(This->window->url, NULL, *p, &size, 0, NULL);
687 if(!bret) {
688 ERR("InternetGetCookieExW failed: %u\n", GetLastError());
689 return E_FAIL;
692 return S_OK;
695 static HRESULT WINAPI HTMLDocument_put_expando(IHTMLDocument2 *iface, VARIANT_BOOL v)
697 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
698 FIXME("(%p)->(%x)\n", This, v);
699 return E_NOTIMPL;
702 static HRESULT WINAPI HTMLDocument_get_expando(IHTMLDocument2 *iface, VARIANT_BOOL *p)
704 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
705 FIXME("(%p)->(%p)\n", This, p);
706 return E_NOTIMPL;
709 static HRESULT WINAPI HTMLDocument_put_charset(IHTMLDocument2 *iface, BSTR v)
711 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
712 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
713 return E_NOTIMPL;
716 static HRESULT WINAPI HTMLDocument_get_charset(IHTMLDocument2 *iface, BSTR *p)
718 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
719 FIXME("(%p)->(%p)\n", This, p);
720 return E_NOTIMPL;
723 static HRESULT WINAPI HTMLDocument_put_defaultCharset(IHTMLDocument2 *iface, BSTR v)
725 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
726 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
727 return E_NOTIMPL;
730 static HRESULT WINAPI HTMLDocument_get_defaultCharset(IHTMLDocument2 *iface, BSTR *p)
732 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
733 FIXME("(%p)->(%p)\n", This, p);
734 return E_NOTIMPL;
737 static HRESULT WINAPI HTMLDocument_get_mimeType(IHTMLDocument2 *iface, BSTR *p)
739 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
740 FIXME("(%p)->(%p)\n", This, p);
741 return E_NOTIMPL;
744 static HRESULT WINAPI HTMLDocument_get_fileSize(IHTMLDocument2 *iface, BSTR *p)
746 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
747 FIXME("(%p)->(%p)\n", This, p);
748 return E_NOTIMPL;
751 static HRESULT WINAPI HTMLDocument_get_fileCreatedDate(IHTMLDocument2 *iface, BSTR *p)
753 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
754 FIXME("(%p)->(%p)\n", This, p);
755 return E_NOTIMPL;
758 static HRESULT WINAPI HTMLDocument_get_fileModifiedDate(IHTMLDocument2 *iface, BSTR *p)
760 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
761 FIXME("(%p)->(%p)\n", This, p);
762 return E_NOTIMPL;
765 static HRESULT WINAPI HTMLDocument_get_fileUpdatedDate(IHTMLDocument2 *iface, BSTR *p)
767 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
768 FIXME("(%p)->(%p)\n", This, p);
769 return E_NOTIMPL;
772 static HRESULT WINAPI HTMLDocument_get_security(IHTMLDocument2 *iface, BSTR *p)
774 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
775 FIXME("(%p)->(%p)\n", This, p);
776 return E_NOTIMPL;
779 static HRESULT WINAPI HTMLDocument_get_protocol(IHTMLDocument2 *iface, BSTR *p)
781 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
782 FIXME("(%p)->(%p)\n", This, p);
783 return E_NOTIMPL;
786 static HRESULT WINAPI HTMLDocument_get_nameProp(IHTMLDocument2 *iface, BSTR *p)
788 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
789 FIXME("(%p)->(%p)\n", This, p);
790 return E_NOTIMPL;
793 static HRESULT document_write(HTMLDocument *This, SAFEARRAY *psarray, BOOL ln)
795 nsAString nsstr;
796 VARIANT *var;
797 ULONG i, argc;
798 nsresult nsres;
799 HRESULT hres;
801 if(!This->doc_node->nsdoc) {
802 WARN("NULL nsdoc\n");
803 return E_UNEXPECTED;
806 if (!psarray)
807 return S_OK;
809 if(psarray->cDims != 1) {
810 FIXME("cDims=%d\n", psarray->cDims);
811 return E_INVALIDARG;
814 hres = SafeArrayAccessData(psarray, (void**)&var);
815 if(FAILED(hres)) {
816 WARN("SafeArrayAccessData failed: %08x\n", hres);
817 return hres;
820 nsAString_Init(&nsstr, NULL);
822 argc = psarray->rgsabound[0].cElements;
823 for(i=0; i < argc; i++) {
824 if(V_VT(var+i) == VT_BSTR) {
825 nsAString_SetData(&nsstr, V_BSTR(var+i));
826 if(!ln || i != argc-1)
827 nsres = nsIDOMHTMLDocument_Write(This->doc_node->nsdoc, &nsstr, NULL /* FIXME! */);
828 else
829 nsres = nsIDOMHTMLDocument_Writeln(This->doc_node->nsdoc, &nsstr, NULL /* FIXME! */);
830 if(NS_FAILED(nsres))
831 ERR("Write failed: %08x\n", nsres);
832 }else {
833 FIXME("unsupported arg[%d] = %s\n", i, debugstr_variant(var+i));
837 nsAString_Finish(&nsstr);
838 SafeArrayUnaccessData(psarray);
840 return S_OK;
843 static HRESULT WINAPI HTMLDocument_write(IHTMLDocument2 *iface, SAFEARRAY *psarray)
845 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
847 TRACE("(%p)->(%p)\n", iface, psarray);
849 return document_write(This, psarray, FALSE);
852 static HRESULT WINAPI HTMLDocument_writeln(IHTMLDocument2 *iface, SAFEARRAY *psarray)
854 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
856 TRACE("(%p)->(%p)\n", This, psarray);
858 return document_write(This, psarray, TRUE);
861 static HRESULT WINAPI HTMLDocument_open(IHTMLDocument2 *iface, BSTR url, VARIANT name,
862 VARIANT features, VARIANT replace, IDispatch **pomWindowResult)
864 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
865 nsISupports *tmp;
866 nsresult nsres;
868 static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};
870 TRACE("(%p)->(%s %s %s %s %p)\n", This, debugstr_w(url), debugstr_variant(&name),
871 debugstr_variant(&features), debugstr_variant(&replace), pomWindowResult);
873 if(!This->doc_node->nsdoc) {
874 ERR("!nsdoc\n");
875 return E_NOTIMPL;
878 if(!url || strcmpW(url, text_htmlW) || V_VT(&name) != VT_ERROR
879 || V_VT(&features) != VT_ERROR || V_VT(&replace) != VT_ERROR)
880 FIXME("unsupported args\n");
882 nsres = nsIDOMHTMLDocument_Open(This->doc_node->nsdoc, NULL, NULL, NULL, NULL, 0, &tmp);
883 if(NS_FAILED(nsres)) {
884 ERR("Open failed: %08x\n", nsres);
885 return E_FAIL;
888 if(tmp)
889 nsISupports_Release(tmp);
891 *pomWindowResult = (IDispatch*)&This->window->IHTMLWindow2_iface;
892 IHTMLWindow2_AddRef(&This->window->IHTMLWindow2_iface);
893 return S_OK;
896 static HRESULT WINAPI HTMLDocument_close(IHTMLDocument2 *iface)
898 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
899 nsresult nsres;
901 TRACE("(%p)\n", This);
903 if(!This->doc_node->nsdoc) {
904 ERR("!nsdoc\n");
905 return E_NOTIMPL;
908 nsres = nsIDOMHTMLDocument_Close(This->doc_node->nsdoc);
909 if(NS_FAILED(nsres)) {
910 ERR("Close failed: %08x\n", nsres);
911 return E_FAIL;
914 return S_OK;
917 static HRESULT WINAPI HTMLDocument_clear(IHTMLDocument2 *iface)
919 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
920 nsresult nsres;
922 TRACE("(%p)\n", This);
924 nsres = nsIDOMHTMLDocument_Clear(This->doc_node->nsdoc);
925 if(NS_FAILED(nsres)) {
926 ERR("Clear failed: %08x\n", nsres);
927 return E_FAIL;
930 return S_OK;
933 static HRESULT WINAPI HTMLDocument_queryCommandSupported(IHTMLDocument2 *iface, BSTR cmdID,
934 VARIANT_BOOL *pfRet)
936 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
937 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
938 return E_NOTIMPL;
941 static HRESULT WINAPI HTMLDocument_queryCommandEnabled(IHTMLDocument2 *iface, BSTR cmdID,
942 VARIANT_BOOL *pfRet)
944 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
945 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
946 return E_NOTIMPL;
949 static HRESULT WINAPI HTMLDocument_queryCommandState(IHTMLDocument2 *iface, BSTR cmdID,
950 VARIANT_BOOL *pfRet)
952 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
953 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
954 return E_NOTIMPL;
957 static HRESULT WINAPI HTMLDocument_queryCommandIndeterm(IHTMLDocument2 *iface, BSTR cmdID,
958 VARIANT_BOOL *pfRet)
960 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
961 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
962 return E_NOTIMPL;
965 static HRESULT WINAPI HTMLDocument_queryCommandText(IHTMLDocument2 *iface, BSTR cmdID,
966 BSTR *pfRet)
968 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
969 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
970 return E_NOTIMPL;
973 static HRESULT WINAPI HTMLDocument_queryCommandValue(IHTMLDocument2 *iface, BSTR cmdID,
974 VARIANT *pfRet)
976 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
977 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
978 return E_NOTIMPL;
981 static HRESULT WINAPI HTMLDocument_execCommand(IHTMLDocument2 *iface, BSTR cmdID,
982 VARIANT_BOOL showUI, VARIANT value, VARIANT_BOOL *pfRet)
984 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
985 FIXME("(%p)->(%s %x %s %p)\n", This, debugstr_w(cmdID), showUI, debugstr_variant(&value), pfRet);
986 return E_NOTIMPL;
989 static HRESULT WINAPI HTMLDocument_execCommandShowHelp(IHTMLDocument2 *iface, BSTR cmdID,
990 VARIANT_BOOL *pfRet)
992 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
993 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
994 return E_NOTIMPL;
997 static HRESULT WINAPI HTMLDocument_createElement(IHTMLDocument2 *iface, BSTR eTag,
998 IHTMLElement **newElem)
1000 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1001 nsIDOMHTMLElement *nselem;
1002 HTMLElement *elem;
1003 HRESULT hres;
1005 TRACE("(%p)->(%s %p)\n", This, debugstr_w(eTag), newElem);
1007 hres = create_nselem(This->doc_node, eTag, &nselem);
1008 if(FAILED(hres))
1009 return hres;
1011 hres = HTMLElement_Create(This->doc_node, (nsIDOMNode*)nselem, TRUE, &elem);
1012 nsIDOMHTMLElement_Release(nselem);
1013 if(FAILED(hres))
1014 return hres;
1016 *newElem = &elem->IHTMLElement_iface;
1017 IHTMLElement_AddRef(&elem->IHTMLElement_iface);
1018 return S_OK;
1021 static HRESULT WINAPI HTMLDocument_put_onhelp(IHTMLDocument2 *iface, VARIANT v)
1023 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1024 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1025 return E_NOTIMPL;
1028 static HRESULT WINAPI HTMLDocument_get_onhelp(IHTMLDocument2 *iface, VARIANT *p)
1030 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1031 FIXME("(%p)->(%p)\n", This, p);
1032 return E_NOTIMPL;
1035 static HRESULT WINAPI HTMLDocument_put_onclick(IHTMLDocument2 *iface, VARIANT v)
1037 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1039 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1041 return set_doc_event(This, EVENTID_CLICK, &v);
1044 static HRESULT WINAPI HTMLDocument_get_onclick(IHTMLDocument2 *iface, VARIANT *p)
1046 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1048 TRACE("(%p)->(%p)\n", This, p);
1050 return get_doc_event(This, EVENTID_CLICK, p);
1053 static HRESULT WINAPI HTMLDocument_put_ondblclick(IHTMLDocument2 *iface, VARIANT v)
1055 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1056 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1057 return E_NOTIMPL;
1060 static HRESULT WINAPI HTMLDocument_get_ondblclick(IHTMLDocument2 *iface, VARIANT *p)
1062 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1063 FIXME("(%p)->(%p)\n", This, p);
1064 return E_NOTIMPL;
1067 static HRESULT WINAPI HTMLDocument_put_onkeyup(IHTMLDocument2 *iface, VARIANT v)
1069 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1071 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1073 return set_doc_event(This, EVENTID_KEYUP, &v);
1076 static HRESULT WINAPI HTMLDocument_get_onkeyup(IHTMLDocument2 *iface, VARIANT *p)
1078 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1080 TRACE("(%p)->(%p)\n", This, p);
1082 return get_doc_event(This, EVENTID_KEYUP, p);
1085 static HRESULT WINAPI HTMLDocument_put_onkeydown(IHTMLDocument2 *iface, VARIANT v)
1087 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1089 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1091 return set_doc_event(This, EVENTID_KEYDOWN, &v);
1094 static HRESULT WINAPI HTMLDocument_get_onkeydown(IHTMLDocument2 *iface, VARIANT *p)
1096 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1098 TRACE("(%p)->(%p)\n", This, p);
1100 return get_doc_event(This, EVENTID_KEYDOWN, p);
1103 static HRESULT WINAPI HTMLDocument_put_onkeypress(IHTMLDocument2 *iface, VARIANT v)
1105 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1107 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1109 return set_doc_event(This, EVENTID_KEYPRESS, &v);
1112 static HRESULT WINAPI HTMLDocument_get_onkeypress(IHTMLDocument2 *iface, VARIANT *p)
1114 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1116 TRACE("(%p)->(%p)\n", This, p);
1118 return get_doc_event(This, EVENTID_KEYPRESS, p);
1121 static HRESULT WINAPI HTMLDocument_put_onmouseup(IHTMLDocument2 *iface, VARIANT v)
1123 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1125 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1127 return set_doc_event(This, EVENTID_MOUSEUP, &v);
1130 static HRESULT WINAPI HTMLDocument_get_onmouseup(IHTMLDocument2 *iface, VARIANT *p)
1132 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1134 TRACE("(%p)->(%p)\n", This, p);
1136 return get_doc_event(This, EVENTID_MOUSEUP, p);
1139 static HRESULT WINAPI HTMLDocument_put_onmousedown(IHTMLDocument2 *iface, VARIANT v)
1141 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1143 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1145 return set_doc_event(This, EVENTID_MOUSEDOWN, &v);
1148 static HRESULT WINAPI HTMLDocument_get_onmousedown(IHTMLDocument2 *iface, VARIANT *p)
1150 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1152 TRACE("(%p)->(%p)\n", This, p);
1154 return get_doc_event(This, EVENTID_MOUSEDOWN, p);
1157 static HRESULT WINAPI HTMLDocument_put_onmousemove(IHTMLDocument2 *iface, VARIANT v)
1159 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1161 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1163 return set_doc_event(This, EVENTID_MOUSEMOVE, &v);
1166 static HRESULT WINAPI HTMLDocument_get_onmousemove(IHTMLDocument2 *iface, VARIANT *p)
1168 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1170 TRACE("(%p)->(%p)\n", This, p);
1172 return get_doc_event(This, EVENTID_MOUSEMOVE, p);
1175 static HRESULT WINAPI HTMLDocument_put_onmouseout(IHTMLDocument2 *iface, VARIANT v)
1177 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1179 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1181 return set_doc_event(This, EVENTID_MOUSEOUT, &v);
1184 static HRESULT WINAPI HTMLDocument_get_onmouseout(IHTMLDocument2 *iface, VARIANT *p)
1186 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1188 TRACE("(%p)->(%p)\n", This, p);
1190 return get_doc_event(This, EVENTID_MOUSEOUT, p);
1193 static HRESULT WINAPI HTMLDocument_put_onmouseover(IHTMLDocument2 *iface, VARIANT v)
1195 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1197 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1199 return set_doc_event(This, EVENTID_MOUSEOVER, &v);
1202 static HRESULT WINAPI HTMLDocument_get_onmouseover(IHTMLDocument2 *iface, VARIANT *p)
1204 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1206 TRACE("(%p)->(%p)\n", This, p);
1208 return get_doc_event(This, EVENTID_MOUSEOVER, p);
1211 static HRESULT WINAPI HTMLDocument_put_onreadystatechange(IHTMLDocument2 *iface, VARIANT v)
1213 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1215 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1217 return set_doc_event(This, EVENTID_READYSTATECHANGE, &v);
1220 static HRESULT WINAPI HTMLDocument_get_onreadystatechange(IHTMLDocument2 *iface, VARIANT *p)
1222 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1224 TRACE("(%p)->(%p)\n", This, p);
1226 return get_doc_event(This, EVENTID_READYSTATECHANGE, p);
1229 static HRESULT WINAPI HTMLDocument_put_onafterupdate(IHTMLDocument2 *iface, VARIANT v)
1231 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1232 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1233 return E_NOTIMPL;
1236 static HRESULT WINAPI HTMLDocument_get_onafterupdate(IHTMLDocument2 *iface, VARIANT *p)
1238 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1239 FIXME("(%p)->(%p)\n", This, p);
1240 return E_NOTIMPL;
1243 static HRESULT WINAPI HTMLDocument_put_onrowexit(IHTMLDocument2 *iface, VARIANT v)
1245 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1246 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1247 return E_NOTIMPL;
1250 static HRESULT WINAPI HTMLDocument_get_onrowexit(IHTMLDocument2 *iface, VARIANT *p)
1252 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1253 FIXME("(%p)->(%p)\n", This, p);
1254 return E_NOTIMPL;
1257 static HRESULT WINAPI HTMLDocument_put_onrowenter(IHTMLDocument2 *iface, VARIANT v)
1259 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1260 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1261 return E_NOTIMPL;
1264 static HRESULT WINAPI HTMLDocument_get_onrowenter(IHTMLDocument2 *iface, VARIANT *p)
1266 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1267 FIXME("(%p)->(%p)\n", This, p);
1268 return E_NOTIMPL;
1271 static HRESULT WINAPI HTMLDocument_put_ondragstart(IHTMLDocument2 *iface, VARIANT v)
1273 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1275 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1277 return set_doc_event(This, EVENTID_DRAGSTART, &v);
1280 static HRESULT WINAPI HTMLDocument_get_ondragstart(IHTMLDocument2 *iface, VARIANT *p)
1282 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1284 TRACE("(%p)->(%p)\n", This, p);
1286 return get_doc_event(This, EVENTID_DRAGSTART, p);
1289 static HRESULT WINAPI HTMLDocument_put_onselectstart(IHTMLDocument2 *iface, VARIANT v)
1291 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1293 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1295 return set_doc_event(This, EVENTID_SELECTSTART, &v);
1298 static HRESULT WINAPI HTMLDocument_get_onselectstart(IHTMLDocument2 *iface, VARIANT *p)
1300 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1302 TRACE("(%p)->(%p)\n", This, p);
1304 return get_doc_event(This, EVENTID_SELECTSTART, p);
1307 static HRESULT WINAPI HTMLDocument_elementFromPoint(IHTMLDocument2 *iface, LONG x, LONG y,
1308 IHTMLElement **elementHit)
1310 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1311 nsIDOMElement *nselem;
1312 HTMLDOMNode *node;
1313 nsresult nsres;
1314 HRESULT hres;
1316 TRACE("(%p)->(%d %d %p)\n", This, x, y, elementHit);
1318 nsres = nsIDOMHTMLDocument_ElementFromPoint(This->doc_node->nsdoc, x, y, &nselem);
1319 if(NS_FAILED(nsres)) {
1320 ERR("ElementFromPoint failed: %08x\n", nsres);
1321 return E_FAIL;
1324 if(!nselem) {
1325 *elementHit = NULL;
1326 return S_OK;
1329 hres = get_node(This->doc_node, (nsIDOMNode*)nselem, TRUE, &node);
1330 nsIDOMElement_Release(nselem);
1331 if(FAILED(hres))
1332 return hres;
1334 return IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)elementHit);
1337 static HRESULT WINAPI HTMLDocument_get_parentWindow(IHTMLDocument2 *iface, IHTMLWindow2 **p)
1339 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1341 TRACE("(%p)->(%p)\n", This, p);
1343 *p = &This->window->IHTMLWindow2_iface;
1344 IHTMLWindow2_AddRef(*p);
1345 return S_OK;
1348 static HRESULT WINAPI HTMLDocument_get_styleSheets(IHTMLDocument2 *iface,
1349 IHTMLStyleSheetsCollection **p)
1351 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1352 nsIDOMStyleSheetList *nsstylelist;
1353 nsresult nsres;
1355 TRACE("(%p)->(%p)\n", This, p);
1357 *p = NULL;
1359 if(!This->doc_node->nsdoc) {
1360 WARN("NULL nsdoc\n");
1361 return E_UNEXPECTED;
1364 nsres = nsIDOMHTMLDocument_GetStyleSheets(This->doc_node->nsdoc, &nsstylelist);
1365 if(NS_FAILED(nsres)) {
1366 ERR("GetStyleSheets failed: %08x\n", nsres);
1367 return E_FAIL;
1370 *p = HTMLStyleSheetsCollection_Create(nsstylelist);
1371 nsIDOMStyleSheetList_Release(nsstylelist);
1373 return S_OK;
1376 static HRESULT WINAPI HTMLDocument_put_onbeforeupdate(IHTMLDocument2 *iface, VARIANT v)
1378 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1379 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1380 return E_NOTIMPL;
1383 static HRESULT WINAPI HTMLDocument_get_onbeforeupdate(IHTMLDocument2 *iface, VARIANT *p)
1385 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1386 FIXME("(%p)->(%p)\n", This, p);
1387 return E_NOTIMPL;
1390 static HRESULT WINAPI HTMLDocument_put_onerrorupdate(IHTMLDocument2 *iface, VARIANT v)
1392 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1393 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1394 return E_NOTIMPL;
1397 static HRESULT WINAPI HTMLDocument_get_onerrorupdate(IHTMLDocument2 *iface, VARIANT *p)
1399 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1400 FIXME("(%p)->(%p)\n", This, p);
1401 return E_NOTIMPL;
1404 static HRESULT WINAPI HTMLDocument_toString(IHTMLDocument2 *iface, BSTR *String)
1406 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1407 FIXME("(%p)->(%p)\n", This, String);
1408 return E_NOTIMPL;
1411 static HRESULT WINAPI HTMLDocument_createStyleSheet(IHTMLDocument2 *iface, BSTR bstrHref,
1412 LONG lIndex, IHTMLStyleSheet **ppnewStyleSheet)
1414 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1416 FIXME("(%p)->(%s %d %p) semi-stub\n", This, debugstr_w(bstrHref), lIndex, ppnewStyleSheet);
1418 *ppnewStyleSheet = HTMLStyleSheet_Create(NULL);
1419 return S_OK;
1422 static const IHTMLDocument2Vtbl HTMLDocumentVtbl = {
1423 HTMLDocument_QueryInterface,
1424 HTMLDocument_AddRef,
1425 HTMLDocument_Release,
1426 HTMLDocument_GetTypeInfoCount,
1427 HTMLDocument_GetTypeInfo,
1428 HTMLDocument_GetIDsOfNames,
1429 HTMLDocument_Invoke,
1430 HTMLDocument_get_Script,
1431 HTMLDocument_get_all,
1432 HTMLDocument_get_body,
1433 HTMLDocument_get_activeElement,
1434 HTMLDocument_get_images,
1435 HTMLDocument_get_applets,
1436 HTMLDocument_get_links,
1437 HTMLDocument_get_forms,
1438 HTMLDocument_get_anchors,
1439 HTMLDocument_put_title,
1440 HTMLDocument_get_title,
1441 HTMLDocument_get_scripts,
1442 HTMLDocument_put_designMode,
1443 HTMLDocument_get_designMode,
1444 HTMLDocument_get_selection,
1445 HTMLDocument_get_readyState,
1446 HTMLDocument_get_frames,
1447 HTMLDocument_get_embeds,
1448 HTMLDocument_get_plugins,
1449 HTMLDocument_put_alinkColor,
1450 HTMLDocument_get_alinkColor,
1451 HTMLDocument_put_bgColor,
1452 HTMLDocument_get_bgColor,
1453 HTMLDocument_put_fgColor,
1454 HTMLDocument_get_fgColor,
1455 HTMLDocument_put_linkColor,
1456 HTMLDocument_get_linkColor,
1457 HTMLDocument_put_vlinkColor,
1458 HTMLDocument_get_vlinkColor,
1459 HTMLDocument_get_referrer,
1460 HTMLDocument_get_location,
1461 HTMLDocument_get_lastModified,
1462 HTMLDocument_put_URL,
1463 HTMLDocument_get_URL,
1464 HTMLDocument_put_domain,
1465 HTMLDocument_get_domain,
1466 HTMLDocument_put_cookie,
1467 HTMLDocument_get_cookie,
1468 HTMLDocument_put_expando,
1469 HTMLDocument_get_expando,
1470 HTMLDocument_put_charset,
1471 HTMLDocument_get_charset,
1472 HTMLDocument_put_defaultCharset,
1473 HTMLDocument_get_defaultCharset,
1474 HTMLDocument_get_mimeType,
1475 HTMLDocument_get_fileSize,
1476 HTMLDocument_get_fileCreatedDate,
1477 HTMLDocument_get_fileModifiedDate,
1478 HTMLDocument_get_fileUpdatedDate,
1479 HTMLDocument_get_security,
1480 HTMLDocument_get_protocol,
1481 HTMLDocument_get_nameProp,
1482 HTMLDocument_write,
1483 HTMLDocument_writeln,
1484 HTMLDocument_open,
1485 HTMLDocument_close,
1486 HTMLDocument_clear,
1487 HTMLDocument_queryCommandSupported,
1488 HTMLDocument_queryCommandEnabled,
1489 HTMLDocument_queryCommandState,
1490 HTMLDocument_queryCommandIndeterm,
1491 HTMLDocument_queryCommandText,
1492 HTMLDocument_queryCommandValue,
1493 HTMLDocument_execCommand,
1494 HTMLDocument_execCommandShowHelp,
1495 HTMLDocument_createElement,
1496 HTMLDocument_put_onhelp,
1497 HTMLDocument_get_onhelp,
1498 HTMLDocument_put_onclick,
1499 HTMLDocument_get_onclick,
1500 HTMLDocument_put_ondblclick,
1501 HTMLDocument_get_ondblclick,
1502 HTMLDocument_put_onkeyup,
1503 HTMLDocument_get_onkeyup,
1504 HTMLDocument_put_onkeydown,
1505 HTMLDocument_get_onkeydown,
1506 HTMLDocument_put_onkeypress,
1507 HTMLDocument_get_onkeypress,
1508 HTMLDocument_put_onmouseup,
1509 HTMLDocument_get_onmouseup,
1510 HTMLDocument_put_onmousedown,
1511 HTMLDocument_get_onmousedown,
1512 HTMLDocument_put_onmousemove,
1513 HTMLDocument_get_onmousemove,
1514 HTMLDocument_put_onmouseout,
1515 HTMLDocument_get_onmouseout,
1516 HTMLDocument_put_onmouseover,
1517 HTMLDocument_get_onmouseover,
1518 HTMLDocument_put_onreadystatechange,
1519 HTMLDocument_get_onreadystatechange,
1520 HTMLDocument_put_onafterupdate,
1521 HTMLDocument_get_onafterupdate,
1522 HTMLDocument_put_onrowexit,
1523 HTMLDocument_get_onrowexit,
1524 HTMLDocument_put_onrowenter,
1525 HTMLDocument_get_onrowenter,
1526 HTMLDocument_put_ondragstart,
1527 HTMLDocument_get_ondragstart,
1528 HTMLDocument_put_onselectstart,
1529 HTMLDocument_get_onselectstart,
1530 HTMLDocument_elementFromPoint,
1531 HTMLDocument_get_parentWindow,
1532 HTMLDocument_get_styleSheets,
1533 HTMLDocument_put_onbeforeupdate,
1534 HTMLDocument_get_onbeforeupdate,
1535 HTMLDocument_put_onerrorupdate,
1536 HTMLDocument_get_onerrorupdate,
1537 HTMLDocument_toString,
1538 HTMLDocument_createStyleSheet
1541 static void HTMLDocument_on_advise(IUnknown *iface, cp_static_data_t *cp)
1543 HTMLDocument *This = impl_from_IHTMLDocument2((IHTMLDocument2*)iface);
1545 if(This->window)
1546 update_cp_events(This->window, &This->doc_node->node.event_target, cp, This->doc_node->node.nsnode);
1549 static inline HTMLDocument *impl_from_ISupportErrorInfo(ISupportErrorInfo *iface)
1551 return CONTAINING_RECORD(iface, HTMLDocument, ISupportErrorInfo_iface);
1554 static HRESULT WINAPI SupportErrorInfo_QueryInterface(ISupportErrorInfo *iface, REFIID riid, void **ppv)
1556 HTMLDocument *This = impl_from_ISupportErrorInfo(iface);
1557 return htmldoc_query_interface(This, riid, ppv);
1560 static ULONG WINAPI SupportErrorInfo_AddRef(ISupportErrorInfo *iface)
1562 HTMLDocument *This = impl_from_ISupportErrorInfo(iface);
1563 return htmldoc_addref(This);
1566 static ULONG WINAPI SupportErrorInfo_Release(ISupportErrorInfo *iface)
1568 HTMLDocument *This = impl_from_ISupportErrorInfo(iface);
1569 return htmldoc_release(This);
1572 static HRESULT WINAPI SupportErrorInfo_InterfaceSupportsErrorInfo(ISupportErrorInfo *iface, REFIID riid)
1574 FIXME("(%p)->(%s)\n", iface, debugstr_guid(riid));
1575 return S_FALSE;
1578 static const ISupportErrorInfoVtbl SupportErrorInfoVtbl = {
1579 SupportErrorInfo_QueryInterface,
1580 SupportErrorInfo_AddRef,
1581 SupportErrorInfo_Release,
1582 SupportErrorInfo_InterfaceSupportsErrorInfo
1585 static inline HTMLDocument *impl_from_IDispatchEx(IDispatchEx *iface)
1587 return CONTAINING_RECORD(iface, HTMLDocument, IDispatchEx_iface);
1590 static HRESULT dispid_from_elem_name(HTMLDocumentNode *This, BSTR name, DISPID *dispid)
1592 nsIDOMNodeList *node_list;
1593 nsAString name_str;
1594 PRUint32 len;
1595 unsigned i;
1596 nsresult nsres;
1598 if(!This->nsdoc)
1599 return DISP_E_UNKNOWNNAME;
1601 nsAString_InitDepend(&name_str, name);
1602 nsres = nsIDOMHTMLDocument_GetElementsByName(This->nsdoc, &name_str, &node_list);
1603 nsAString_Finish(&name_str);
1604 if(NS_FAILED(nsres))
1605 return E_FAIL;
1607 nsres = nsIDOMNodeList_GetLength(node_list, &len);
1608 nsIDOMNodeList_Release(node_list);
1609 if(NS_FAILED(nsres))
1610 return E_FAIL;
1612 if(!len)
1613 return DISP_E_UNKNOWNNAME;
1615 for(i=0; i < This->elem_vars_cnt; i++) {
1616 if(!strcmpW(name, This->elem_vars[i])) {
1617 *dispid = MSHTML_DISPID_CUSTOM_MIN+i;
1618 return S_OK;
1622 if(This->elem_vars_cnt == This->elem_vars_size) {
1623 WCHAR **new_vars;
1625 if(This->elem_vars_size) {
1626 new_vars = heap_realloc(This->elem_vars, This->elem_vars_size*2*sizeof(WCHAR*));
1627 if(!new_vars)
1628 return E_OUTOFMEMORY;
1629 This->elem_vars_size *= 2;
1630 }else {
1631 new_vars = heap_alloc(16*sizeof(WCHAR*));
1632 if(!new_vars)
1633 return E_OUTOFMEMORY;
1634 This->elem_vars_size = 16;
1637 This->elem_vars = new_vars;
1640 This->elem_vars[This->elem_vars_cnt] = heap_strdupW(name);
1641 if(!This->elem_vars[This->elem_vars_cnt])
1642 return E_OUTOFMEMORY;
1644 *dispid = MSHTML_DISPID_CUSTOM_MIN+This->elem_vars_cnt++;
1645 return S_OK;
1648 static HRESULT WINAPI DocDispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
1650 HTMLDocument *This = impl_from_IDispatchEx(iface);
1652 return htmldoc_query_interface(This, riid, ppv);
1655 static ULONG WINAPI DocDispatchEx_AddRef(IDispatchEx *iface)
1657 HTMLDocument *This = impl_from_IDispatchEx(iface);
1659 return htmldoc_addref(This);
1662 static ULONG WINAPI DocDispatchEx_Release(IDispatchEx *iface)
1664 HTMLDocument *This = impl_from_IDispatchEx(iface);
1666 return htmldoc_release(This);
1669 static HRESULT WINAPI DocDispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
1671 HTMLDocument *This = impl_from_IDispatchEx(iface);
1673 return IDispatchEx_GetTypeInfoCount(This->dispex, pctinfo);
1676 static HRESULT WINAPI DocDispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
1677 LCID lcid, ITypeInfo **ppTInfo)
1679 HTMLDocument *This = impl_from_IDispatchEx(iface);
1681 return IDispatchEx_GetTypeInfo(This->dispex, iTInfo, lcid, ppTInfo);
1684 static HRESULT WINAPI DocDispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
1685 LPOLESTR *rgszNames, UINT cNames,
1686 LCID lcid, DISPID *rgDispId)
1688 HTMLDocument *This = impl_from_IDispatchEx(iface);
1690 return IDispatchEx_GetIDsOfNames(This->dispex, riid, rgszNames, cNames, lcid, rgDispId);
1693 static HRESULT WINAPI DocDispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
1694 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1695 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1697 HTMLDocument *This = impl_from_IDispatchEx(iface);
1699 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1700 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1702 switch(dispIdMember) {
1703 case DISPID_READYSTATE:
1704 TRACE("DISPID_READYSTATE\n");
1706 if(!(wFlags & DISPATCH_PROPERTYGET))
1707 return E_INVALIDARG;
1709 V_VT(pVarResult) = VT_I4;
1710 V_I4(pVarResult) = This->window->readystate;
1711 return S_OK;
1714 return IDispatchEx_Invoke(This->dispex, dispIdMember, riid, lcid, wFlags, pDispParams,
1715 pVarResult, pExcepInfo, puArgErr);
1718 static HRESULT WINAPI DocDispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
1720 HTMLDocument *This = impl_from_IDispatchEx(iface);
1721 HRESULT hres;
1723 hres = IDispatchEx_GetDispID(This->dispex, bstrName, grfdex, pid);
1724 if(hres != DISP_E_UNKNOWNNAME)
1725 return hres;
1727 return dispid_from_elem_name(This->doc_node, bstrName, pid);
1730 static HRESULT WINAPI DocDispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1731 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1733 HTMLDocument *This = impl_from_IDispatchEx(iface);
1735 if(This->window && id == DISPID_IHTMLDOCUMENT2_LOCATION && (wFlags & DISPATCH_PROPERTYPUT))
1736 return IDispatchEx_InvokeEx(&This->window->IDispatchEx_iface, DISPID_IHTMLWINDOW2_LOCATION,
1737 lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1740 return IDispatchEx_InvokeEx(This->dispex, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1743 static HRESULT WINAPI DocDispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
1745 HTMLDocument *This = impl_from_IDispatchEx(iface);
1747 return IDispatchEx_DeleteMemberByName(This->dispex, bstrName, grfdex);
1750 static HRESULT WINAPI DocDispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
1752 HTMLDocument *This = impl_from_IDispatchEx(iface);
1754 return IDispatchEx_DeleteMemberByDispID(This->dispex, id);
1757 static HRESULT WINAPI DocDispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
1759 HTMLDocument *This = impl_from_IDispatchEx(iface);
1761 return IDispatchEx_GetMemberProperties(This->dispex, id, grfdexFetch, pgrfdex);
1764 static HRESULT WINAPI DocDispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
1766 HTMLDocument *This = impl_from_IDispatchEx(iface);
1768 return IDispatchEx_GetMemberName(This->dispex, id, pbstrName);
1771 static HRESULT WINAPI DocDispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
1773 HTMLDocument *This = impl_from_IDispatchEx(iface);
1775 return IDispatchEx_GetNextDispID(This->dispex, grfdex, id, pid);
1778 static HRESULT WINAPI DocDispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
1780 HTMLDocument *This = impl_from_IDispatchEx(iface);
1782 return IDispatchEx_GetNameSpaceParent(This->dispex, ppunk);
1785 static const IDispatchExVtbl DocDispatchExVtbl = {
1786 DocDispatchEx_QueryInterface,
1787 DocDispatchEx_AddRef,
1788 DocDispatchEx_Release,
1789 DocDispatchEx_GetTypeInfoCount,
1790 DocDispatchEx_GetTypeInfo,
1791 DocDispatchEx_GetIDsOfNames,
1792 DocDispatchEx_Invoke,
1793 DocDispatchEx_GetDispID,
1794 DocDispatchEx_InvokeEx,
1795 DocDispatchEx_DeleteMemberByName,
1796 DocDispatchEx_DeleteMemberByDispID,
1797 DocDispatchEx_GetMemberProperties,
1798 DocDispatchEx_GetMemberName,
1799 DocDispatchEx_GetNextDispID,
1800 DocDispatchEx_GetNameSpaceParent
1803 static inline HTMLDocument *impl_from_IProvideClassInfo(IProvideClassInfo *iface)
1805 return CONTAINING_RECORD(iface, HTMLDocument, IProvideClassInfo_iface);
1808 static HRESULT WINAPI ProvideClassInfo_QueryInterface(IProvideClassInfo *iface,
1809 REFIID riid, void **ppv)
1811 HTMLDocument *This = impl_from_IProvideClassInfo(iface);
1812 return htmldoc_query_interface(This, riid, ppv);
1815 static ULONG WINAPI ProvideClassInfo_AddRef(IProvideClassInfo *iface)
1817 HTMLDocument *This = impl_from_IProvideClassInfo(iface);
1818 return htmldoc_addref(This);
1821 static ULONG WINAPI ProvideClassInfo_Release(IProvideClassInfo *iface)
1823 HTMLDocument *This = impl_from_IProvideClassInfo(iface);
1824 return htmldoc_release(This);
1827 static HRESULT WINAPI ProvideClassInfo_GetClassInfo(IProvideClassInfo* iface,
1828 ITypeInfo **ppTI)
1830 HTMLDocument *This = impl_from_IProvideClassInfo(iface);
1831 TRACE("(%p)->(%p)\n", This, ppTI);
1832 return get_htmldoc_classinfo(ppTI);
1835 static const IProvideClassInfoVtbl ProvideClassInfoVtbl = {
1836 ProvideClassInfo_QueryInterface,
1837 ProvideClassInfo_AddRef,
1838 ProvideClassInfo_Release,
1839 ProvideClassInfo_GetClassInfo
1842 static BOOL htmldoc_qi(HTMLDocument *This, REFIID riid, void **ppv)
1844 *ppv = NULL;
1846 if(IsEqualGUID(&IID_IUnknown, riid)) {
1847 TRACE("(%p)->(IID_IUnknown, %p)\n", This, ppv);
1848 *ppv = &This->IHTMLDocument2_iface;
1849 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1850 TRACE("(%p)->(IID_IDispatch, %p)\n", This, ppv);
1851 *ppv = &This->IDispatchEx_iface;
1852 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
1853 TRACE("(%p)->(IID_IDispatchEx, %p)\n", This, ppv);
1854 *ppv = &This->IDispatchEx_iface;
1855 }else if(IsEqualGUID(&IID_IHTMLDocument, riid)) {
1856 TRACE("(%p)->(IID_IHTMLDocument, %p)\n", This, ppv);
1857 *ppv = &This->IHTMLDocument2_iface;
1858 }else if(IsEqualGUID(&IID_IHTMLDocument2, riid)) {
1859 TRACE("(%p)->(IID_IHTMLDocument2, %p)\n", This, ppv);
1860 *ppv = &This->IHTMLDocument2_iface;
1861 }else if(IsEqualGUID(&IID_IHTMLDocument3, riid)) {
1862 TRACE("(%p)->(IID_IHTMLDocument3, %p)\n", This, ppv);
1863 *ppv = &This->IHTMLDocument3_iface;
1864 }else if(IsEqualGUID(&IID_IHTMLDocument4, riid)) {
1865 TRACE("(%p)->(IID_IHTMLDocument4, %p)\n", This, ppv);
1866 *ppv = &This->IHTMLDocument4_iface;
1867 }else if(IsEqualGUID(&IID_IHTMLDocument5, riid)) {
1868 TRACE("(%p)->(IID_IHTMLDocument5, %p)\n", This, ppv);
1869 *ppv = &This->IHTMLDocument5_iface;
1870 }else if(IsEqualGUID(&IID_IHTMLDocument6, riid)) {
1871 TRACE("(%p)->(IID_IHTMLDocument6, %p)\n", This, ppv);
1872 *ppv = &This->IHTMLDocument6_iface;
1873 }else if(IsEqualGUID(&IID_IPersist, riid)) {
1874 TRACE("(%p)->(IID_IPersist, %p)\n", This, ppv);
1875 *ppv = &This->IPersistFile_iface;
1876 }else if(IsEqualGUID(&IID_IPersistMoniker, riid)) {
1877 TRACE("(%p)->(IID_IPersistMoniker, %p)\n", This, ppv);
1878 *ppv = &This->IPersistMoniker_iface;
1879 }else if(IsEqualGUID(&IID_IPersistFile, riid)) {
1880 TRACE("(%p)->(IID_IPersistFile, %p)\n", This, ppv);
1881 *ppv = &This->IPersistFile_iface;
1882 }else if(IsEqualGUID(&IID_IMonikerProp, riid)) {
1883 TRACE("(%p)->(IID_IMonikerProp, %p)\n", This, ppv);
1884 *ppv = &This->IMonikerProp_iface;
1885 }else if(IsEqualGUID(&IID_IOleObject, riid)) {
1886 TRACE("(%p)->(IID_IOleObject, %p)\n", This, ppv);
1887 *ppv = &This->IOleObject_iface;
1888 }else if(IsEqualGUID(&IID_IOleDocument, riid)) {
1889 TRACE("(%p)->(IID_IOleDocument, %p)\n", This, ppv);
1890 *ppv = &This->IOleDocument_iface;
1891 }else if(IsEqualGUID(&IID_IOleDocumentView, riid)) {
1892 TRACE("(%p)->(IID_IOleDocumentView, %p)\n", This, ppv);
1893 *ppv = &This->IOleDocumentView_iface;
1894 }else if(IsEqualGUID(&IID_IOleInPlaceActiveObject, riid)) {
1895 TRACE("(%p)->(IID_IOleInPlaceActiveObject, %p)\n", This, ppv);
1896 *ppv = &This->IOleInPlaceActiveObject_iface;
1897 }else if(IsEqualGUID(&IID_IViewObject, riid)) {
1898 TRACE("(%p)->(IID_IViewObject, %p)\n", This, ppv);
1899 *ppv = &This->IViewObjectEx_iface;
1900 }else if(IsEqualGUID(&IID_IViewObject2, riid)) {
1901 TRACE("(%p)->(IID_IViewObject2, %p)\n", This, ppv);
1902 *ppv = &This->IViewObjectEx_iface;
1903 }else if(IsEqualGUID(&IID_IViewObjectEx, riid)) {
1904 TRACE("(%p)->(IID_IViewObjectEx, %p)\n", This, ppv);
1905 *ppv = &This->IViewObjectEx_iface;
1906 }else if(IsEqualGUID(&IID_IOleWindow, riid)) {
1907 TRACE("(%p)->(IID_IOleWindow, %p)\n", This, ppv);
1908 *ppv = &This->IOleInPlaceActiveObject_iface;
1909 }else if(IsEqualGUID(&IID_IOleInPlaceObject, riid)) {
1910 TRACE("(%p)->(IID_IOleInPlaceObject, %p)\n", This, ppv);
1911 *ppv = &This->IOleInPlaceObjectWindowless_iface;
1912 }else if(IsEqualGUID(&IID_IOleInPlaceObjectWindowless, riid)) {
1913 TRACE("(%p)->(IID_IOleInPlaceObjectWindowless, %p)\n", This, ppv);
1914 *ppv = &This->IOleInPlaceObjectWindowless_iface;
1915 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
1916 TRACE("(%p)->(IID_IServiceProvider, %p)\n", This, ppv);
1917 *ppv = &This->IServiceProvider_iface;
1918 }else if(IsEqualGUID(&IID_IOleCommandTarget, riid)) {
1919 TRACE("(%p)->(IID_IOleCommandTarget, %p)\n", This, ppv);
1920 *ppv = &This->IOleCommandTarget_iface;
1921 }else if(IsEqualGUID(&IID_IOleControl, riid)) {
1922 TRACE("(%p)->(IID_IOleControl, %p)\n", This, ppv);
1923 *ppv = &This->IOleControl_iface;
1924 }else if(IsEqualGUID(&IID_IHlinkTarget, riid)) {
1925 TRACE("(%p)->(IID_IHlinkTarget, %p)\n", This, ppv);
1926 *ppv = &This->IHlinkTarget_iface;
1927 }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
1928 TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppv);
1929 *ppv = &This->cp_container.IConnectionPointContainer_iface;
1930 }else if(IsEqualGUID(&IID_IPersistStreamInit, riid)) {
1931 TRACE("(%p)->(IID_IPersistStreamInit %p)\n", This, ppv);
1932 *ppv = &This->IPersistStreamInit_iface;
1933 }else if(IsEqualGUID(&DIID_DispHTMLDocument, riid)) {
1934 TRACE("(%p)->(DIID_DispHTMLDocument %p)\n", This, ppv);
1935 *ppv = &This->IHTMLDocument2_iface;
1936 }else if(IsEqualGUID(&IID_ISupportErrorInfo, riid)) {
1937 TRACE("(%p)->(IID_ISupportErrorInfo %p)\n", This, ppv);
1938 *ppv = &This->ISupportErrorInfo_iface;
1939 }else if(IsEqualGUID(&IID_IPersistHistory, riid)) {
1940 TRACE("(%p)->(IID_IPersistHistory %p)\n", This, ppv);
1941 *ppv = &This->IPersistHistory_iface;
1942 }else if(IsEqualGUID(&CLSID_CMarkup, riid)) {
1943 FIXME("(%p)->(CLSID_CMarkup %p)\n", This, ppv);
1944 *ppv = NULL;
1945 }else if(IsEqualGUID(&IID_IRunnableObject, riid)) {
1946 TRACE("(%p)->(IID_IRunnableObject %p) returning NULL\n", This, ppv);
1947 *ppv = NULL;
1948 }else if(IsEqualGUID(&IID_IPersistPropertyBag, riid)) {
1949 TRACE("(%p)->(IID_IPersistPropertyBag %p) returning NULL\n", This, ppv);
1950 *ppv = NULL;
1951 }else if(IsEqualGUID(&IID_IMarshal, riid)) {
1952 TRACE("(%p)->(IID_IMarshal %p) returning NULL\n", This, ppv);
1953 *ppv = NULL;
1954 }else if(IsEqualGUID(&IID_IExternalConnection, riid)) {
1955 TRACE("(%p)->(IID_IExternalConnection %p) returning NULL\n", This, ppv);
1956 *ppv = NULL;
1957 }else if(IsEqualGUID(&IID_IStdMarshalInfo, riid)) {
1958 TRACE("(%p)->(IID_IStdMarshalInfo %p) returning NULL\n", This, ppv);
1959 *ppv = NULL;
1960 }else if(IsEqualGUID(&IID_IObjectWithSite, riid)) {
1961 TRACE("(%p)->(IID_IObjectWithSite %p)\n", This, ppv);
1962 *ppv = &This->IObjectWithSite_iface;
1963 }else if(IsEqualGUID(&IID_IOleContainer, riid)) {
1964 TRACE("(%p)->(IID_IOleContainer %p)\n", This, ppv);
1965 *ppv = &This->IOleContainer_iface;
1966 }else if(IsEqualGUID(&IID_IObjectSafety, riid)) {
1967 TRACE("(%p)->(IID_IObjectSafety %p)\n", This, ppv);
1968 *ppv = &This->IObjectSafety_iface;
1969 }else if(IsEqualGUID(&IID_IProvideClassInfo, riid)) {
1970 TRACE("(%p)->(IID_IProvideClassInfo, %p)\n", This, ppv);
1971 *ppv = &This->IProvideClassInfo_iface;
1972 }else {
1973 return FALSE;
1976 if(*ppv)
1977 IUnknown_AddRef((IUnknown*)*ppv);
1978 return TRUE;
1981 static cp_static_data_t HTMLDocumentEvents_data = { HTMLDocumentEvents_tid, HTMLDocument_on_advise };
1983 static void init_doc(HTMLDocument *doc, IUnknown *unk_impl, IDispatchEx *dispex)
1985 doc->IHTMLDocument2_iface.lpVtbl = &HTMLDocumentVtbl;
1986 doc->IDispatchEx_iface.lpVtbl = &DocDispatchExVtbl;
1987 doc->ISupportErrorInfo_iface.lpVtbl = &SupportErrorInfoVtbl;
1988 doc->IProvideClassInfo_iface.lpVtbl = &ProvideClassInfoVtbl;
1990 doc->unk_impl = unk_impl;
1991 doc->dispex = dispex;
1992 doc->task_magic = get_task_target_magic();
1994 HTMLDocument_HTMLDocument3_Init(doc);
1995 HTMLDocument_HTMLDocument5_Init(doc);
1996 HTMLDocument_Persist_Init(doc);
1997 HTMLDocument_OleCmd_Init(doc);
1998 HTMLDocument_OleObj_Init(doc);
1999 HTMLDocument_View_Init(doc);
2000 HTMLDocument_Window_Init(doc);
2001 HTMLDocument_Service_Init(doc);
2002 HTMLDocument_Hlink_Init(doc);
2004 ConnectionPointContainer_Init(&doc->cp_container, (IUnknown*)&doc->IHTMLDocument2_iface);
2005 ConnectionPoint_Init(&doc->cp_dispatch, &doc->cp_container, &IID_IDispatch, &HTMLDocumentEvents_data);
2006 ConnectionPoint_Init(&doc->cp_propnotif, &doc->cp_container, &IID_IPropertyNotifySink, NULL);
2007 ConnectionPoint_Init(&doc->cp_htmldocevents, &doc->cp_container, &DIID_HTMLDocumentEvents, &HTMLDocumentEvents_data);
2008 ConnectionPoint_Init(&doc->cp_htmldocevents2, &doc->cp_container, &DIID_HTMLDocumentEvents2, NULL);
2011 static void destroy_htmldoc(HTMLDocument *This)
2013 remove_target_tasks(This->task_magic);
2015 ConnectionPointContainer_Destroy(&This->cp_container);
2018 static inline HTMLDocumentNode *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
2020 return CONTAINING_RECORD(iface, HTMLDocumentNode, node);
2023 static HRESULT HTMLDocumentNode_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
2025 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2027 if(htmldoc_qi(&This->basedoc, riid, ppv))
2028 return *ppv ? S_OK : E_NOINTERFACE;
2030 if(IsEqualGUID(&IID_IInternetHostSecurityManager, riid)) {
2031 TRACE("(%p)->(IID_IInternetHostSecurityManager %p)\n", This, ppv);
2032 *ppv = &This->IInternetHostSecurityManager_iface;
2033 }else {
2034 return HTMLDOMNode_QI(&This->node, riid, ppv);
2037 IUnknown_AddRef((IUnknown*)*ppv);
2038 return S_OK;
2041 static void HTMLDocumentNode_destructor(HTMLDOMNode *iface)
2043 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2044 unsigned i;
2046 for(i=0; i < This->elem_vars_cnt; i++)
2047 heap_free(This->elem_vars[i]);
2048 heap_free(This->elem_vars);
2050 detach_events(This);
2051 if(This->body_event_target)
2052 release_event_target(This->body_event_target);
2053 if(This->catmgr)
2054 ICatInformation_Release(This->catmgr);
2056 detach_selection(This);
2057 detach_ranges(This);
2058 release_nodes(This);
2060 while(!list_empty(&This->plugin_hosts))
2061 detach_plugin_host(LIST_ENTRY(list_head(&This->plugin_hosts), PluginHost, entry));
2063 if(This->nsdoc) {
2064 release_document_mutation(This);
2065 nsIDOMHTMLDocument_Release(This->nsdoc);
2068 heap_free(This->event_vector);
2069 destroy_htmldoc(&This->basedoc);
2072 static HRESULT HTMLDocumentNode_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
2074 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2075 FIXME("%p\n", This);
2076 return E_NOTIMPL;
2079 static const NodeImplVtbl HTMLDocumentNodeImplVtbl = {
2080 HTMLDocumentNode_QI,
2081 HTMLDocumentNode_destructor,
2082 HTMLDocumentNode_clone
2085 static HRESULT HTMLDocumentFragment_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
2087 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2088 HTMLDocumentNode *new_node;
2089 HRESULT hres;
2091 hres = create_document_fragment(nsnode, This->node.doc, &new_node);
2092 if(FAILED(hres))
2093 return hres;
2095 *ret = &new_node->node;
2096 return S_OK;
2099 static inline HTMLDocumentNode *impl_from_DispatchEx(DispatchEx *iface)
2101 return CONTAINING_RECORD(iface, HTMLDocumentNode, node.dispex);
2104 static HRESULT HTMLDocumentNode_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
2105 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2107 HTMLDocumentNode *This = impl_from_DispatchEx(dispex);
2108 nsIDOMNodeList *node_list;
2109 nsAString name_str;
2110 nsIDOMNode *nsnode;
2111 HTMLDOMNode *node;
2112 unsigned i;
2113 nsresult nsres;
2114 HRESULT hres;
2116 if(flags != DISPATCH_PROPERTYGET) {
2117 FIXME("unsupported flags %x\n", flags);
2118 return E_NOTIMPL;
2121 i = id - MSHTML_DISPID_CUSTOM_MIN;
2123 if(!This->nsdoc || i >= This->elem_vars_cnt)
2124 return DISP_E_UNKNOWNNAME;
2126 nsAString_InitDepend(&name_str, This->elem_vars[i]);
2127 nsres = nsIDOMHTMLDocument_GetElementsByName(This->nsdoc, &name_str, &node_list);
2128 nsAString_Finish(&name_str);
2129 if(NS_FAILED(nsres))
2130 return E_FAIL;
2132 nsres = nsIDOMNodeList_Item(node_list, 0, &nsnode);
2133 nsIDOMNodeList_Release(node_list);
2134 if(NS_FAILED(nsres) || !nsnode)
2135 return DISP_E_UNKNOWNNAME;
2137 hres = get_node(This, nsnode, TRUE, &node);
2138 if(FAILED(hres))
2139 return hres;
2141 IHTMLDOMNode_AddRef(&node->IHTMLDOMNode_iface);
2142 V_VT(res) = VT_DISPATCH;
2143 V_DISPATCH(res) = (IDispatch*)&node->IHTMLDOMNode_iface;
2144 return S_OK;
2148 static const dispex_static_data_vtbl_t HTMLDocumentNode_dispex_vtbl = {
2149 NULL,
2150 NULL,
2151 HTMLDocumentNode_invoke,
2152 NULL
2155 static const NodeImplVtbl HTMLDocumentFragmentImplVtbl = {
2156 HTMLDocumentNode_QI,
2157 HTMLDocumentNode_destructor,
2158 HTMLDocumentFragment_clone
2161 static const tid_t HTMLDocumentNode_iface_tids[] = {
2162 IHTMLDOMNode_tid,
2163 IHTMLDOMNode2_tid,
2164 IHTMLDocument2_tid,
2165 IHTMLDocument3_tid,
2166 IHTMLDocument4_tid,
2167 IHTMLDocument5_tid,
2171 static dispex_static_data_t HTMLDocumentNode_dispex = {
2172 &HTMLDocumentNode_dispex_vtbl,
2173 DispHTMLDocument_tid,
2174 NULL,
2175 HTMLDocumentNode_iface_tids
2178 static HTMLDocumentNode *alloc_doc_node(HTMLDocumentObj *doc_obj, HTMLWindow *window)
2180 HTMLDocumentNode *doc;
2182 doc = heap_alloc_zero(sizeof(HTMLDocumentNode));
2183 if(!doc)
2184 return NULL;
2186 doc->ref = 1;
2187 doc->basedoc.doc_node = doc;
2188 doc->basedoc.doc_obj = doc_obj;
2189 doc->basedoc.window = window;
2191 init_dispex(&doc->node.dispex, (IUnknown*)&doc->node.IHTMLDOMNode_iface,
2192 &HTMLDocumentNode_dispex);
2193 init_doc(&doc->basedoc, (IUnknown*)&doc->node.IHTMLDOMNode_iface,
2194 &doc->node.dispex.IDispatchEx_iface);
2195 HTMLDocumentNode_SecMgr_Init(doc);
2197 list_init(&doc->bindings);
2198 list_init(&doc->selection_list);
2199 list_init(&doc->range_list);
2200 list_init(&doc->plugin_hosts);
2202 return doc;
2205 HRESULT create_doc_from_nsdoc(nsIDOMHTMLDocument *nsdoc, HTMLDocumentObj *doc_obj, HTMLWindow *window, HTMLDocumentNode **ret)
2207 HTMLDocumentNode *doc;
2209 doc = alloc_doc_node(doc_obj, window);
2210 if(!doc)
2211 return E_OUTOFMEMORY;
2213 if(!doc_obj->basedoc.window || window == doc_obj->basedoc.window)
2214 doc->basedoc.cp_container.forward_container = &doc_obj->basedoc.cp_container;
2216 nsIDOMHTMLDocument_AddRef(nsdoc);
2217 doc->nsdoc = nsdoc;
2218 init_document_mutation(doc);
2219 doc_init_events(doc);
2221 HTMLDOMNode_Init(doc, &doc->node, (nsIDOMNode*)nsdoc);
2222 doc->node.vtbl = &HTMLDocumentNodeImplVtbl;
2223 doc->node.cp_container = &doc->basedoc.cp_container;
2225 *ret = doc;
2226 return S_OK;
2229 HRESULT create_document_fragment(nsIDOMNode *nsnode, HTMLDocumentNode *doc_node, HTMLDocumentNode **ret)
2231 HTMLDocumentNode *doc_frag;
2233 doc_frag = alloc_doc_node(doc_node->basedoc.doc_obj, doc_node->basedoc.window);
2234 if(!doc_frag)
2235 return E_OUTOFMEMORY;
2237 HTMLDOMNode_Init(doc_node, &doc_frag->node, nsnode);
2238 doc_frag->node.vtbl = &HTMLDocumentFragmentImplVtbl;
2239 doc_frag->node.cp_container = &doc_frag->basedoc.cp_container;
2241 htmldoc_addref(&doc_frag->basedoc);
2242 *ret = doc_frag;
2243 return S_OK;
2246 /**********************************************************
2247 * ICustomDoc implementation
2250 static inline HTMLDocumentObj *impl_from_ICustomDoc(ICustomDoc *iface)
2252 return CONTAINING_RECORD(iface, HTMLDocumentObj, ICustomDoc_iface);
2255 static HRESULT WINAPI CustomDoc_QueryInterface(ICustomDoc *iface, REFIID riid, void **ppv)
2257 HTMLDocumentObj *This = impl_from_ICustomDoc(iface);
2259 if(htmldoc_qi(&This->basedoc, riid, ppv))
2260 return *ppv ? S_OK : E_NOINTERFACE;
2262 if(IsEqualGUID(&IID_ICustomDoc, riid)) {
2263 TRACE("(%p)->(IID_ICustomDoc %p)\n", This, ppv);
2264 *ppv = &This->ICustomDoc_iface;
2265 }else if(IsEqualGUID(&IID_ITargetContainer, riid)) {
2266 TRACE("(%p)->(IID_ITargetContainer %p)\n", This, ppv);
2267 *ppv = &This->ITargetContainer_iface;
2268 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
2269 return *ppv ? S_OK : E_NOINTERFACE;
2270 }else {
2271 FIXME("Unimplemented interface %s\n", debugstr_guid(riid));
2272 *ppv = NULL;
2273 return E_NOINTERFACE;
2276 IUnknown_AddRef((IUnknown*)*ppv);
2277 return S_OK;
2280 static ULONG WINAPI CustomDoc_AddRef(ICustomDoc *iface)
2282 HTMLDocumentObj *This = impl_from_ICustomDoc(iface);
2283 ULONG ref = InterlockedIncrement(&This->ref);
2285 TRACE("(%p) ref = %u\n", This, ref);
2287 return ref;
2290 static ULONG WINAPI CustomDoc_Release(ICustomDoc *iface)
2292 HTMLDocumentObj *This = impl_from_ICustomDoc(iface);
2293 ULONG ref = InterlockedDecrement(&This->ref);
2295 TRACE("(%p) ref = %u\n", This, ref);
2297 if(!ref) {
2298 if(This->basedoc.doc_node) {
2299 This->basedoc.doc_node->basedoc.doc_obj = NULL;
2300 htmldoc_release(&This->basedoc.doc_node->basedoc);
2302 if(This->basedoc.window) {
2303 This->basedoc.window->doc_obj = NULL;
2304 IHTMLWindow2_Release(&This->basedoc.window->IHTMLWindow2_iface);
2306 if(This->basedoc.advise_holder)
2307 IOleAdviseHolder_Release(This->basedoc.advise_holder);
2309 if(This->view_sink)
2310 IAdviseSink_Release(This->view_sink);
2311 if(This->client)
2312 IOleObject_SetClientSite(&This->basedoc.IOleObject_iface, NULL);
2313 if(This->hostui)
2314 ICustomDoc_SetUIHandler(&This->ICustomDoc_iface, NULL);
2315 if(This->in_place_active)
2316 IOleInPlaceObjectWindowless_InPlaceDeactivate(&This->basedoc.IOleInPlaceObjectWindowless_iface);
2317 if(This->ipsite)
2318 IOleDocumentView_SetInPlaceSite(&This->basedoc.IOleDocumentView_iface, NULL);
2319 if(This->undomgr)
2320 IOleUndoManager_Release(This->undomgr);
2321 if(This->tooltips_hwnd)
2322 DestroyWindow(This->tooltips_hwnd);
2324 if(This->hwnd)
2325 DestroyWindow(This->hwnd);
2326 heap_free(This->mime);
2328 destroy_htmldoc(&This->basedoc);
2329 release_dispex(&This->dispex);
2331 if(This->nscontainer)
2332 NSContainer_Release(This->nscontainer);
2333 heap_free(This);
2336 return ref;
2339 static HRESULT WINAPI CustomDoc_SetUIHandler(ICustomDoc *iface, IDocHostUIHandler *pUIHandler)
2341 HTMLDocumentObj *This = impl_from_ICustomDoc(iface);
2342 IOleCommandTarget *cmdtrg;
2343 HRESULT hres;
2345 TRACE("(%p)->(%p)\n", This, pUIHandler);
2347 if(This->custom_hostui && This->hostui == pUIHandler)
2348 return S_OK;
2350 This->custom_hostui = TRUE;
2352 if(This->hostui)
2353 IDocHostUIHandler_Release(This->hostui);
2354 if(pUIHandler)
2355 IDocHostUIHandler_AddRef(pUIHandler);
2356 This->hostui = pUIHandler;
2357 if(!pUIHandler)
2358 return S_OK;
2360 hres = IDocHostUIHandler_QueryInterface(pUIHandler, &IID_IOleCommandTarget, (void**)&cmdtrg);
2361 if(SUCCEEDED(hres)) {
2362 FIXME("custom UI handler supports IOleCommandTarget\n");
2363 IOleCommandTarget_Release(cmdtrg);
2366 return S_OK;
2369 static const ICustomDocVtbl CustomDocVtbl = {
2370 CustomDoc_QueryInterface,
2371 CustomDoc_AddRef,
2372 CustomDoc_Release,
2373 CustomDoc_SetUIHandler
2376 static const tid_t HTMLDocumentObj_iface_tids[] = {
2377 IHTMLDocument2_tid,
2378 IHTMLDocument3_tid,
2379 IHTMLDocument4_tid,
2380 IHTMLDocument5_tid,
2383 static dispex_static_data_t HTMLDocumentObj_dispex = {
2384 NULL,
2385 DispHTMLDocument_tid,
2386 NULL,
2387 HTMLDocumentObj_iface_tids
2390 HRESULT HTMLDocument_Create(IUnknown *pUnkOuter, REFIID riid, void** ppvObject)
2392 HTMLDocumentObj *doc;
2393 nsIDOMWindow *nswindow = NULL;
2394 nsresult nsres;
2395 HRESULT hres;
2397 TRACE("(%p %s %p)\n", pUnkOuter, debugstr_guid(riid), ppvObject);
2399 doc = heap_alloc_zero(sizeof(HTMLDocumentObj));
2400 if(!doc)
2401 return E_OUTOFMEMORY;
2403 init_dispex(&doc->dispex, (IUnknown*)&doc->ICustomDoc_iface, &HTMLDocumentObj_dispex);
2404 init_doc(&doc->basedoc, (IUnknown*)&doc->ICustomDoc_iface, &doc->dispex.IDispatchEx_iface);
2405 TargetContainer_Init(doc);
2407 doc->ICustomDoc_iface.lpVtbl = &CustomDocVtbl;
2408 doc->ref = 1;
2409 doc->basedoc.doc_obj = doc;
2411 doc->usermode = UNKNOWN_USERMODE;
2413 hres = create_nscontainer(doc, NULL, &doc->nscontainer);
2414 if(FAILED(hres)) {
2415 ERR("Failed to init Gecko, returning CLASS_E_CLASSNOTAVAILABLE\n");
2416 htmldoc_release(&doc->basedoc);
2417 return hres;
2420 hres = htmldoc_query_interface(&doc->basedoc, riid, ppvObject);
2421 htmldoc_release(&doc->basedoc);
2422 if(FAILED(hres))
2423 return hres;
2426 nsres = nsIWebBrowser_GetContentDOMWindow(doc->nscontainer->webbrowser, &nswindow);
2427 if(NS_FAILED(nsres))
2428 ERR("GetContentDOMWindow failed: %08x\n", nsres);
2430 hres = HTMLWindow_Create(doc, nswindow, NULL /* FIXME */, &doc->basedoc.window);
2431 if(nswindow)
2432 nsIDOMWindow_Release(nswindow);
2433 if(FAILED(hres)) {
2434 htmldoc_release(&doc->basedoc);
2435 return hres;
2438 if(!doc->basedoc.doc_node && doc->basedoc.window->doc) {
2439 doc->basedoc.doc_node = doc->basedoc.window->doc;
2440 htmldoc_addref(&doc->basedoc.doc_node->basedoc);
2443 get_thread_hwnd();
2445 return S_OK;