mshtml: Store MSHTML node reference in Gecko node object and get rid of all node...
[wine/multimedia.git] / dlls / mshtml / htmldoc.c
blobf9e11ce9b5be076841a9faf008d4e52e4b60be6d
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>
23 #include <assert.h>
25 #define COBJMACROS
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "wininet.h"
31 #include "ole2.h"
32 #include "perhist.h"
33 #include "mshtmdid.h"
35 #include "wine/debug.h"
37 #include "mshtml_private.h"
38 #include "htmlevent.h"
39 #include "pluginhost.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
43 static inline HTMLDocument *impl_from_IHTMLDocument2(IHTMLDocument2 *iface)
45 return CONTAINING_RECORD(iface, HTMLDocument, IHTMLDocument2_iface);
48 static HRESULT WINAPI HTMLDocument_QueryInterface(IHTMLDocument2 *iface, REFIID riid, void **ppv)
50 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
52 return htmldoc_query_interface(This, riid, ppv);
55 static ULONG WINAPI HTMLDocument_AddRef(IHTMLDocument2 *iface)
57 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
59 return htmldoc_addref(This);
62 static ULONG WINAPI HTMLDocument_Release(IHTMLDocument2 *iface)
64 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
66 return htmldoc_release(This);
69 static HRESULT WINAPI HTMLDocument_GetTypeInfoCount(IHTMLDocument2 *iface, UINT *pctinfo)
71 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
73 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
76 static HRESULT WINAPI HTMLDocument_GetTypeInfo(IHTMLDocument2 *iface, UINT iTInfo,
77 LCID lcid, ITypeInfo **ppTInfo)
79 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
81 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
84 static HRESULT WINAPI HTMLDocument_GetIDsOfNames(IHTMLDocument2 *iface, REFIID riid,
85 LPOLESTR *rgszNames, UINT cNames,
86 LCID lcid, DISPID *rgDispId)
88 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
90 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
91 rgDispId);
94 static HRESULT WINAPI HTMLDocument_Invoke(IHTMLDocument2 *iface, DISPID dispIdMember,
95 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
96 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
98 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
100 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
101 pDispParams, pVarResult, pExcepInfo, puArgErr);
104 static HRESULT WINAPI HTMLDocument_get_Script(IHTMLDocument2 *iface, IDispatch **p)
106 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
108 TRACE("(%p)->(%p)\n", This, p);
110 *p = (IDispatch*)&This->window->base.IHTMLWindow2_iface;
111 IDispatch_AddRef(*p);
112 return S_OK;
115 static HRESULT WINAPI HTMLDocument_get_all(IHTMLDocument2 *iface, IHTMLElementCollection **p)
117 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
118 nsIDOMElement *nselem = NULL;
119 HTMLDOMNode *node;
120 nsresult nsres;
121 HRESULT hres;
123 TRACE("(%p)->(%p)\n", This, p);
125 if(!This->doc_node->nsdoc) {
126 WARN("NULL nsdoc\n");
127 return E_UNEXPECTED;
130 nsres = nsIDOMHTMLDocument_GetDocumentElement(This->doc_node->nsdoc, &nselem);
131 if(NS_FAILED(nsres)) {
132 ERR("GetDocumentElement failed: %08x\n", nsres);
133 return E_FAIL;
136 if(!nselem) {
137 *p = NULL;
138 return S_OK;
141 hres = get_node(This->doc_node, (nsIDOMNode*)nselem, TRUE, &node);
142 nsIDOMElement_Release(nselem);
143 if(FAILED(hres))
144 return hres;
146 *p = create_all_collection(node, TRUE);
147 node_release(node);
148 return hres;
151 static HRESULT WINAPI HTMLDocument_get_body(IHTMLDocument2 *iface, IHTMLElement **p)
153 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
154 nsIDOMHTMLElement *nsbody = NULL;
155 HTMLDOMNode *node;
156 HRESULT hres;
158 TRACE("(%p)->(%p)\n", This, p);
160 if(This->doc_node->nsdoc) {
161 nsresult nsres;
163 nsres = nsIDOMHTMLDocument_GetBody(This->doc_node->nsdoc, &nsbody);
164 if(NS_FAILED(nsres)) {
165 TRACE("Could not get body: %08x\n", nsres);
166 return E_UNEXPECTED;
170 if(!nsbody) {
171 *p = NULL;
172 return S_OK;
175 hres = get_node(This->doc_node, (nsIDOMNode*)nsbody, TRUE, &node);
176 nsIDOMHTMLElement_Release(nsbody);
177 if(FAILED(hres))
178 return hres;
180 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)p);
181 node_release(node);
182 return hres;
185 static HRESULT WINAPI HTMLDocument_get_activeElement(IHTMLDocument2 *iface, IHTMLElement **p)
187 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
188 FIXME("(%p)->(%p)\n", This, p);
189 return E_NOTIMPL;
192 static HRESULT WINAPI HTMLDocument_get_images(IHTMLDocument2 *iface, IHTMLElementCollection **p)
194 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
195 nsIDOMHTMLCollection *nscoll = NULL;
196 nsresult nsres;
198 TRACE("(%p)->(%p)\n", This, p);
200 if(!p)
201 return E_INVALIDARG;
203 *p = NULL;
205 if(!This->doc_node->nsdoc) {
206 WARN("NULL nsdoc\n");
207 return E_UNEXPECTED;
210 nsres = nsIDOMHTMLDocument_GetImages(This->doc_node->nsdoc, &nscoll);
211 if(NS_FAILED(nsres)) {
212 ERR("GetImages failed: %08x\n", nsres);
213 return E_FAIL;
216 if(nscoll) {
217 *p = create_collection_from_htmlcol(This->doc_node, nscoll);
218 nsIDOMElement_Release(nscoll);
221 return S_OK;
224 static HRESULT WINAPI HTMLDocument_get_applets(IHTMLDocument2 *iface, IHTMLElementCollection **p)
226 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
227 nsIDOMHTMLCollection *nscoll = NULL;
228 nsresult nsres;
230 TRACE("(%p)->(%p)\n", This, p);
232 if(!p)
233 return E_INVALIDARG;
235 *p = NULL;
237 if(!This->doc_node->nsdoc) {
238 WARN("NULL nsdoc\n");
239 return E_UNEXPECTED;
242 nsres = nsIDOMHTMLDocument_GetApplets(This->doc_node->nsdoc, &nscoll);
243 if(NS_FAILED(nsres)) {
244 ERR("GetApplets failed: %08x\n", nsres);
245 return E_FAIL;
248 if(nscoll) {
249 *p = create_collection_from_htmlcol(This->doc_node, nscoll);
250 nsIDOMElement_Release(nscoll);
253 return S_OK;
256 static HRESULT WINAPI HTMLDocument_get_links(IHTMLDocument2 *iface, IHTMLElementCollection **p)
258 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
259 nsIDOMHTMLCollection *nscoll = NULL;
260 nsresult nsres;
262 TRACE("(%p)->(%p)\n", This, p);
264 if(!p)
265 return E_INVALIDARG;
267 *p = NULL;
269 if(!This->doc_node->nsdoc) {
270 WARN("NULL nsdoc\n");
271 return E_UNEXPECTED;
274 nsres = nsIDOMHTMLDocument_GetLinks(This->doc_node->nsdoc, &nscoll);
275 if(NS_FAILED(nsres)) {
276 ERR("GetLinks failed: %08x\n", nsres);
277 return E_FAIL;
280 if(nscoll) {
281 *p = create_collection_from_htmlcol(This->doc_node, nscoll);
282 nsIDOMElement_Release(nscoll);
285 return S_OK;
288 static HRESULT WINAPI HTMLDocument_get_forms(IHTMLDocument2 *iface, IHTMLElementCollection **p)
290 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
291 nsIDOMHTMLCollection *nscoll = NULL;
292 nsresult nsres;
294 TRACE("(%p)->(%p)\n", This, p);
296 if(!p)
297 return E_INVALIDARG;
299 *p = NULL;
301 if(!This->doc_node->nsdoc) {
302 WARN("NULL nsdoc\n");
303 return E_UNEXPECTED;
306 nsres = nsIDOMHTMLDocument_GetForms(This->doc_node->nsdoc, &nscoll);
307 if(NS_FAILED(nsres)) {
308 ERR("GetForms failed: %08x\n", nsres);
309 return E_FAIL;
312 if(nscoll) {
313 *p = create_collection_from_htmlcol(This->doc_node, nscoll);
314 nsIDOMElement_Release(nscoll);
317 return S_OK;
320 static HRESULT WINAPI HTMLDocument_get_anchors(IHTMLDocument2 *iface, IHTMLElementCollection **p)
322 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
323 nsIDOMHTMLCollection *nscoll = NULL;
324 nsresult nsres;
326 TRACE("(%p)->(%p)\n", This, p);
328 if(!p)
329 return E_INVALIDARG;
331 *p = NULL;
333 if(!This->doc_node->nsdoc) {
334 WARN("NULL nsdoc\n");
335 return E_UNEXPECTED;
338 nsres = nsIDOMHTMLDocument_GetAnchors(This->doc_node->nsdoc, &nscoll);
339 if(NS_FAILED(nsres)) {
340 ERR("GetAnchors failed: %08x\n", nsres);
341 return E_FAIL;
344 if(nscoll) {
345 *p = create_collection_from_htmlcol(This->doc_node, nscoll);
346 nsIDOMElement_Release(nscoll);
349 return S_OK;
352 static HRESULT WINAPI HTMLDocument_put_title(IHTMLDocument2 *iface, BSTR v)
354 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
355 nsAString nsstr;
356 nsresult nsres;
358 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
360 if(!This->doc_node->nsdoc) {
361 WARN("NULL nsdoc\n");
362 return E_UNEXPECTED;
365 nsAString_InitDepend(&nsstr, v);
366 nsres = nsIDOMHTMLDocument_SetTitle(This->doc_node->nsdoc, &nsstr);
367 nsAString_Finish(&nsstr);
368 if(NS_FAILED(nsres))
369 ERR("SetTitle failed: %08x\n", nsres);
371 return S_OK;
374 static HRESULT WINAPI HTMLDocument_get_title(IHTMLDocument2 *iface, BSTR *p)
376 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
377 const PRUnichar *ret;
378 nsAString nsstr;
379 nsresult nsres;
381 TRACE("(%p)->(%p)\n", This, p);
383 if(!This->doc_node->nsdoc) {
384 WARN("NULL nsdoc\n");
385 return E_UNEXPECTED;
389 nsAString_Init(&nsstr, NULL);
390 nsres = nsIDOMHTMLDocument_GetTitle(This->doc_node->nsdoc, &nsstr);
391 if (NS_SUCCEEDED(nsres)) {
392 nsAString_GetData(&nsstr, &ret);
393 *p = SysAllocString(ret);
395 nsAString_Finish(&nsstr);
397 if(NS_FAILED(nsres)) {
398 ERR("GetTitle failed: %08x\n", nsres);
399 return E_FAIL;
402 return S_OK;
405 static HRESULT WINAPI HTMLDocument_get_scripts(IHTMLDocument2 *iface, IHTMLElementCollection **p)
407 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
408 FIXME("(%p)->(%p)\n", This, p);
409 return E_NOTIMPL;
412 static HRESULT WINAPI HTMLDocument_put_designMode(IHTMLDocument2 *iface, BSTR v)
414 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
415 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
416 return E_NOTIMPL;
419 static HRESULT WINAPI HTMLDocument_get_designMode(IHTMLDocument2 *iface, BSTR *p)
421 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
422 static WCHAR szOff[] = {'O','f','f',0};
423 FIXME("(%p)->(%p) always returning Off\n", This, p);
425 if(!p)
426 return E_INVALIDARG;
428 *p = SysAllocString(szOff);
430 return S_OK;
433 static HRESULT WINAPI HTMLDocument_get_selection(IHTMLDocument2 *iface, IHTMLSelectionObject **p)
435 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
436 nsISelection *nsselection;
437 nsresult nsres;
439 TRACE("(%p)->(%p)\n", This, p);
441 nsres = nsIDOMWindow_GetSelection(This->window->nswindow, &nsselection);
442 if(NS_FAILED(nsres)) {
443 ERR("GetSelection failed: %08x\n", nsres);
444 return E_FAIL;
447 return HTMLSelectionObject_Create(This->doc_node, nsselection, p);
450 static HRESULT WINAPI HTMLDocument_get_readyState(IHTMLDocument2 *iface, BSTR *p)
452 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
454 static const WCHAR wszUninitialized[] = {'u','n','i','n','i','t','i','a','l','i','z','e','d',0};
455 static const WCHAR wszLoading[] = {'l','o','a','d','i','n','g',0};
456 static const WCHAR wszLoaded[] = {'l','o','a','d','e','d',0};
457 static const WCHAR wszInteractive[] = {'i','n','t','e','r','a','c','t','i','v','e',0};
458 static const WCHAR wszComplete[] = {'c','o','m','p','l','e','t','e',0};
460 static const LPCWSTR readystate_str[] = {
461 wszUninitialized,
462 wszLoading,
463 wszLoaded,
464 wszInteractive,
465 wszComplete
468 TRACE("(%p)->(%p)\n", iface, p);
470 if(!p)
471 return E_POINTER;
473 *p = SysAllocString(readystate_str[This->window->readystate]);
474 return S_OK;
477 static HRESULT WINAPI HTMLDocument_get_frames(IHTMLDocument2 *iface, IHTMLFramesCollection2 **p)
479 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
481 TRACE("(%p)->(%p)\n", This, p);
483 return IHTMLWindow2_get_frames(&This->window->base.IHTMLWindow2_iface, p);
486 static HRESULT WINAPI HTMLDocument_get_embeds(IHTMLDocument2 *iface, IHTMLElementCollection **p)
488 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
489 FIXME("(%p)->(%p)\n", This, p);
490 return E_NOTIMPL;
493 static HRESULT WINAPI HTMLDocument_get_plugins(IHTMLDocument2 *iface, IHTMLElementCollection **p)
495 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
496 FIXME("(%p)->(%p)\n", This, p);
497 return E_NOTIMPL;
500 static HRESULT WINAPI HTMLDocument_put_alinkColor(IHTMLDocument2 *iface, VARIANT v)
502 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
503 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
504 return E_NOTIMPL;
507 static HRESULT WINAPI HTMLDocument_get_alinkColor(IHTMLDocument2 *iface, VARIANT *p)
509 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
510 FIXME("(%p)->(%p)\n", This, p);
511 return E_NOTIMPL;
514 static HRESULT WINAPI HTMLDocument_put_bgColor(IHTMLDocument2 *iface, VARIANT v)
516 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
517 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
518 return E_NOTIMPL;
521 static HRESULT WINAPI HTMLDocument_get_bgColor(IHTMLDocument2 *iface, VARIANT *p)
523 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
524 FIXME("(%p)->(%p)\n", This, p);
525 return E_NOTIMPL;
528 static HRESULT WINAPI HTMLDocument_put_fgColor(IHTMLDocument2 *iface, VARIANT v)
530 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
531 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
532 return E_NOTIMPL;
535 static HRESULT WINAPI HTMLDocument_get_fgColor(IHTMLDocument2 *iface, VARIANT *p)
537 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
538 FIXME("(%p)->(%p)\n", This, p);
539 return E_NOTIMPL;
542 static HRESULT WINAPI HTMLDocument_put_linkColor(IHTMLDocument2 *iface, VARIANT v)
544 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
545 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
546 return E_NOTIMPL;
549 static HRESULT WINAPI HTMLDocument_get_linkColor(IHTMLDocument2 *iface, VARIANT *p)
551 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
552 FIXME("(%p)->(%p)\n", This, p);
553 return E_NOTIMPL;
556 static HRESULT WINAPI HTMLDocument_put_vlinkColor(IHTMLDocument2 *iface, VARIANT v)
558 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
559 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
560 return E_NOTIMPL;
563 static HRESULT WINAPI HTMLDocument_get_vlinkColor(IHTMLDocument2 *iface, VARIANT *p)
565 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
566 FIXME("(%p)->(%p)\n", This, p);
567 return E_NOTIMPL;
570 static HRESULT WINAPI HTMLDocument_get_referrer(IHTMLDocument2 *iface, BSTR *p)
572 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
574 FIXME("(%p)->(%p)\n", This, p);
576 *p = NULL;
577 return S_OK;
580 static HRESULT WINAPI HTMLDocument_get_location(IHTMLDocument2 *iface, IHTMLLocation **p)
582 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
584 TRACE("(%p)->(%p)\n", This, p);
586 if(!This->doc_node->nsdoc) {
587 WARN("NULL nsdoc\n");
588 return E_UNEXPECTED;
591 return IHTMLWindow2_get_location(&This->window->base.IHTMLWindow2_iface, p);
594 static HRESULT WINAPI HTMLDocument_get_lastModified(IHTMLDocument2 *iface, BSTR *p)
596 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
597 FIXME("(%p)->(%p)\n", This, p);
598 return E_NOTIMPL;
601 static HRESULT WINAPI HTMLDocument_put_URL(IHTMLDocument2 *iface, BSTR v)
603 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
605 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
607 if(!This->window) {
608 FIXME("No window available\n");
609 return E_FAIL;
612 return navigate_url(This->window, v, This->window->url);
615 static HRESULT WINAPI HTMLDocument_get_URL(IHTMLDocument2 *iface, BSTR *p)
617 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
619 static const WCHAR about_blank_url[] =
620 {'a','b','o','u','t',':','b','l','a','n','k',0};
622 TRACE("(%p)->(%p)\n", iface, p);
624 *p = SysAllocString(This->window->url ? This->window->url : about_blank_url);
625 return *p ? S_OK : E_OUTOFMEMORY;
628 static HRESULT WINAPI HTMLDocument_put_domain(IHTMLDocument2 *iface, BSTR v)
630 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
631 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
632 return E_NOTIMPL;
635 static HRESULT WINAPI HTMLDocument_get_domain(IHTMLDocument2 *iface, BSTR *p)
637 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
638 HRESULT hres;
640 TRACE("(%p)->(%p)\n", This, p);
642 if(!This->window || !This->window->uri) {
643 FIXME("No current URI\n");
644 return E_FAIL;
647 hres = IUri_GetHost(This->window->uri, p);
648 return FAILED(hres) ? hres : S_OK;
651 static HRESULT WINAPI HTMLDocument_put_cookie(IHTMLDocument2 *iface, BSTR v)
653 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
654 BOOL bret;
656 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
658 bret = InternetSetCookieExW(This->window->url, NULL, v, 0, 0);
659 if(!bret) {
660 FIXME("InternetSetCookieExW failed: %u\n", GetLastError());
661 return HRESULT_FROM_WIN32(GetLastError());
664 return S_OK;
667 static HRESULT WINAPI HTMLDocument_get_cookie(IHTMLDocument2 *iface, BSTR *p)
669 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
670 DWORD size;
671 BOOL bret;
673 TRACE("(%p)->(%p)\n", This, p);
675 size = 0;
676 bret = InternetGetCookieExW(This->window->url, NULL, NULL, &size, 0, NULL);
677 if(!bret) {
678 switch(GetLastError()) {
679 case ERROR_INSUFFICIENT_BUFFER:
680 break;
681 case ERROR_NO_MORE_ITEMS:
682 *p = NULL;
683 return S_OK;
684 default:
685 FIXME("InternetGetCookieExW failed: %u\n", GetLastError());
686 return HRESULT_FROM_WIN32(GetLastError());
690 if(!size) {
691 *p = NULL;
692 return S_OK;
695 *p = SysAllocStringLen(NULL, size-1);
696 if(!*p)
697 return E_OUTOFMEMORY;
699 bret = InternetGetCookieExW(This->window->url, NULL, *p, &size, 0, NULL);
700 if(!bret) {
701 ERR("InternetGetCookieExW failed: %u\n", GetLastError());
702 return E_FAIL;
705 return S_OK;
708 static HRESULT WINAPI HTMLDocument_put_expando(IHTMLDocument2 *iface, VARIANT_BOOL v)
710 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
711 FIXME("(%p)->(%x)\n", This, v);
712 return E_NOTIMPL;
715 static HRESULT WINAPI HTMLDocument_get_expando(IHTMLDocument2 *iface, VARIANT_BOOL *p)
717 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
718 FIXME("(%p)->(%p)\n", This, p);
719 return E_NOTIMPL;
722 static HRESULT WINAPI HTMLDocument_put_charset(IHTMLDocument2 *iface, BSTR v)
724 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
725 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
726 return E_NOTIMPL;
729 static HRESULT WINAPI HTMLDocument_get_charset(IHTMLDocument2 *iface, BSTR *p)
731 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
732 FIXME("(%p)->(%p)\n", This, p);
733 return E_NOTIMPL;
736 static HRESULT WINAPI HTMLDocument_put_defaultCharset(IHTMLDocument2 *iface, BSTR v)
738 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
739 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
740 return E_NOTIMPL;
743 static HRESULT WINAPI HTMLDocument_get_defaultCharset(IHTMLDocument2 *iface, BSTR *p)
745 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
746 FIXME("(%p)->(%p)\n", This, p);
747 return E_NOTIMPL;
750 static HRESULT WINAPI HTMLDocument_get_mimeType(IHTMLDocument2 *iface, BSTR *p)
752 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
753 FIXME("(%p)->(%p)\n", This, p);
754 return E_NOTIMPL;
757 static HRESULT WINAPI HTMLDocument_get_fileSize(IHTMLDocument2 *iface, BSTR *p)
759 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
760 FIXME("(%p)->(%p)\n", This, p);
761 return E_NOTIMPL;
764 static HRESULT WINAPI HTMLDocument_get_fileCreatedDate(IHTMLDocument2 *iface, BSTR *p)
766 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
767 FIXME("(%p)->(%p)\n", This, p);
768 return E_NOTIMPL;
771 static HRESULT WINAPI HTMLDocument_get_fileModifiedDate(IHTMLDocument2 *iface, BSTR *p)
773 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
774 FIXME("(%p)->(%p)\n", This, p);
775 return E_NOTIMPL;
778 static HRESULT WINAPI HTMLDocument_get_fileUpdatedDate(IHTMLDocument2 *iface, BSTR *p)
780 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
781 FIXME("(%p)->(%p)\n", This, p);
782 return E_NOTIMPL;
785 static HRESULT WINAPI HTMLDocument_get_security(IHTMLDocument2 *iface, BSTR *p)
787 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
788 FIXME("(%p)->(%p)\n", This, p);
789 return E_NOTIMPL;
792 static HRESULT WINAPI HTMLDocument_get_protocol(IHTMLDocument2 *iface, BSTR *p)
794 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
795 FIXME("(%p)->(%p)\n", This, p);
796 return E_NOTIMPL;
799 static HRESULT WINAPI HTMLDocument_get_nameProp(IHTMLDocument2 *iface, BSTR *p)
801 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
802 FIXME("(%p)->(%p)\n", This, p);
803 return E_NOTIMPL;
806 static HRESULT document_write(HTMLDocument *This, SAFEARRAY *psarray, BOOL ln)
808 VARIANT *var, tmp;
809 nsAString nsstr;
810 ULONG i, argc;
811 nsresult nsres;
812 HRESULT hres;
814 if(!This->doc_node->nsdoc) {
815 WARN("NULL nsdoc\n");
816 return E_UNEXPECTED;
819 if (!psarray)
820 return S_OK;
822 if(psarray->cDims != 1) {
823 FIXME("cDims=%d\n", psarray->cDims);
824 return E_INVALIDARG;
827 hres = SafeArrayAccessData(psarray, (void**)&var);
828 if(FAILED(hres)) {
829 WARN("SafeArrayAccessData failed: %08x\n", hres);
830 return hres;
833 V_VT(&tmp) = VT_EMPTY;
835 argc = psarray->rgsabound[0].cElements;
836 for(i=0; i < argc; i++) {
837 if(V_VT(var+i) == VT_BSTR) {
838 nsAString_InitDepend(&nsstr, V_BSTR(var+i));
839 }else {
840 hres = VariantChangeTypeEx(&tmp, var+i, MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT), 0, VT_BSTR);
841 if(FAILED(hres)) {
842 WARN("Could not convert %s to string\n", debugstr_variant(var+i));
843 break;
845 nsAString_InitDepend(&nsstr, V_BSTR(&tmp));
848 if(!ln || i != argc-1)
849 nsres = nsIDOMHTMLDocument_Write(This->doc_node->nsdoc, &nsstr, NULL /* FIXME! */);
850 else
851 nsres = nsIDOMHTMLDocument_Writeln(This->doc_node->nsdoc, &nsstr, NULL /* FIXME! */);
852 nsAString_Finish(&nsstr);
853 if(V_VT(var+i) != VT_BSTR)
854 VariantClear(&tmp);
855 if(NS_FAILED(nsres)) {
856 ERR("Write failed: %08x\n", nsres);
857 hres = E_FAIL;
858 break;
862 SafeArrayUnaccessData(psarray);
864 return hres;
867 static HRESULT WINAPI HTMLDocument_write(IHTMLDocument2 *iface, SAFEARRAY *psarray)
869 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
871 TRACE("(%p)->(%p)\n", iface, psarray);
873 return document_write(This, psarray, FALSE);
876 static HRESULT WINAPI HTMLDocument_writeln(IHTMLDocument2 *iface, SAFEARRAY *psarray)
878 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
880 TRACE("(%p)->(%p)\n", This, psarray);
882 return document_write(This, psarray, TRUE);
885 static HRESULT WINAPI HTMLDocument_open(IHTMLDocument2 *iface, BSTR url, VARIANT name,
886 VARIANT features, VARIANT replace, IDispatch **pomWindowResult)
888 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
889 nsISupports *tmp;
890 nsresult nsres;
892 static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};
894 TRACE("(%p)->(%s %s %s %s %p)\n", This, debugstr_w(url), debugstr_variant(&name),
895 debugstr_variant(&features), debugstr_variant(&replace), pomWindowResult);
897 if(!This->doc_node->nsdoc) {
898 ERR("!nsdoc\n");
899 return E_NOTIMPL;
902 if(!url || strcmpW(url, text_htmlW) || V_VT(&name) != VT_ERROR
903 || V_VT(&features) != VT_ERROR || V_VT(&replace) != VT_ERROR)
904 FIXME("unsupported args\n");
906 nsres = nsIDOMHTMLDocument_Open(This->doc_node->nsdoc, NULL, NULL, NULL, NULL, 0, &tmp);
907 if(NS_FAILED(nsres)) {
908 ERR("Open failed: %08x\n", nsres);
909 return E_FAIL;
912 if(tmp)
913 nsISupports_Release(tmp);
915 *pomWindowResult = (IDispatch*)&This->window->base.IHTMLWindow2_iface;
916 IHTMLWindow2_AddRef(&This->window->base.IHTMLWindow2_iface);
917 return S_OK;
920 static HRESULT WINAPI HTMLDocument_close(IHTMLDocument2 *iface)
922 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
923 nsresult nsres;
925 TRACE("(%p)\n", This);
927 if(!This->doc_node->nsdoc) {
928 ERR("!nsdoc\n");
929 return E_NOTIMPL;
932 nsres = nsIDOMHTMLDocument_Close(This->doc_node->nsdoc);
933 if(NS_FAILED(nsres)) {
934 ERR("Close failed: %08x\n", nsres);
935 return E_FAIL;
938 return S_OK;
941 static HRESULT WINAPI HTMLDocument_clear(IHTMLDocument2 *iface)
943 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
944 nsresult nsres;
946 TRACE("(%p)\n", This);
948 nsres = nsIDOMHTMLDocument_Clear(This->doc_node->nsdoc);
949 if(NS_FAILED(nsres)) {
950 ERR("Clear failed: %08x\n", nsres);
951 return E_FAIL;
954 return S_OK;
957 static HRESULT WINAPI HTMLDocument_queryCommandSupported(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_queryCommandEnabled(IHTMLDocument2 *iface, BSTR cmdID,
966 VARIANT_BOOL *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_queryCommandState(IHTMLDocument2 *iface, BSTR cmdID,
974 VARIANT_BOOL *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_queryCommandIndeterm(IHTMLDocument2 *iface, BSTR cmdID,
982 VARIANT_BOOL *pfRet)
984 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
985 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
986 return E_NOTIMPL;
989 static HRESULT WINAPI HTMLDocument_queryCommandText(IHTMLDocument2 *iface, BSTR cmdID,
990 BSTR *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_queryCommandValue(IHTMLDocument2 *iface, BSTR cmdID,
998 VARIANT *pfRet)
1000 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1001 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1002 return E_NOTIMPL;
1005 static HRESULT WINAPI HTMLDocument_execCommand(IHTMLDocument2 *iface, BSTR cmdID,
1006 VARIANT_BOOL showUI, VARIANT value, VARIANT_BOOL *pfRet)
1008 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1009 FIXME("(%p)->(%s %x %s %p)\n", This, debugstr_w(cmdID), showUI, debugstr_variant(&value), pfRet);
1010 return E_NOTIMPL;
1013 static HRESULT WINAPI HTMLDocument_execCommandShowHelp(IHTMLDocument2 *iface, BSTR cmdID,
1014 VARIANT_BOOL *pfRet)
1016 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1017 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1018 return E_NOTIMPL;
1021 static HRESULT WINAPI HTMLDocument_createElement(IHTMLDocument2 *iface, BSTR eTag,
1022 IHTMLElement **newElem)
1024 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1025 nsIDOMHTMLElement *nselem;
1026 HTMLElement *elem;
1027 HRESULT hres;
1029 TRACE("(%p)->(%s %p)\n", This, debugstr_w(eTag), newElem);
1031 hres = create_nselem(This->doc_node, eTag, &nselem);
1032 if(FAILED(hres))
1033 return hres;
1035 hres = HTMLElement_Create(This->doc_node, (nsIDOMNode*)nselem, TRUE, &elem);
1036 nsIDOMHTMLElement_Release(nselem);
1037 if(FAILED(hres))
1038 return hres;
1040 *newElem = &elem->IHTMLElement_iface;
1041 return S_OK;
1044 static HRESULT WINAPI HTMLDocument_put_onhelp(IHTMLDocument2 *iface, VARIANT v)
1046 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1047 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1048 return E_NOTIMPL;
1051 static HRESULT WINAPI HTMLDocument_get_onhelp(IHTMLDocument2 *iface, VARIANT *p)
1053 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1054 FIXME("(%p)->(%p)\n", This, p);
1055 return E_NOTIMPL;
1058 static HRESULT WINAPI HTMLDocument_put_onclick(IHTMLDocument2 *iface, VARIANT v)
1060 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1062 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1064 return set_doc_event(This, EVENTID_CLICK, &v);
1067 static HRESULT WINAPI HTMLDocument_get_onclick(IHTMLDocument2 *iface, VARIANT *p)
1069 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1071 TRACE("(%p)->(%p)\n", This, p);
1073 return get_doc_event(This, EVENTID_CLICK, p);
1076 static HRESULT WINAPI HTMLDocument_put_ondblclick(IHTMLDocument2 *iface, VARIANT v)
1078 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1079 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1080 return E_NOTIMPL;
1083 static HRESULT WINAPI HTMLDocument_get_ondblclick(IHTMLDocument2 *iface, VARIANT *p)
1085 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1086 FIXME("(%p)->(%p)\n", This, p);
1087 return E_NOTIMPL;
1090 static HRESULT WINAPI HTMLDocument_put_onkeyup(IHTMLDocument2 *iface, VARIANT v)
1092 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1094 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1096 return set_doc_event(This, EVENTID_KEYUP, &v);
1099 static HRESULT WINAPI HTMLDocument_get_onkeyup(IHTMLDocument2 *iface, VARIANT *p)
1101 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1103 TRACE("(%p)->(%p)\n", This, p);
1105 return get_doc_event(This, EVENTID_KEYUP, p);
1108 static HRESULT WINAPI HTMLDocument_put_onkeydown(IHTMLDocument2 *iface, VARIANT v)
1110 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1112 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1114 return set_doc_event(This, EVENTID_KEYDOWN, &v);
1117 static HRESULT WINAPI HTMLDocument_get_onkeydown(IHTMLDocument2 *iface, VARIANT *p)
1119 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1121 TRACE("(%p)->(%p)\n", This, p);
1123 return get_doc_event(This, EVENTID_KEYDOWN, p);
1126 static HRESULT WINAPI HTMLDocument_put_onkeypress(IHTMLDocument2 *iface, VARIANT v)
1128 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1130 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1132 return set_doc_event(This, EVENTID_KEYPRESS, &v);
1135 static HRESULT WINAPI HTMLDocument_get_onkeypress(IHTMLDocument2 *iface, VARIANT *p)
1137 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1139 TRACE("(%p)->(%p)\n", This, p);
1141 return get_doc_event(This, EVENTID_KEYPRESS, p);
1144 static HRESULT WINAPI HTMLDocument_put_onmouseup(IHTMLDocument2 *iface, VARIANT v)
1146 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1148 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1150 return set_doc_event(This, EVENTID_MOUSEUP, &v);
1153 static HRESULT WINAPI HTMLDocument_get_onmouseup(IHTMLDocument2 *iface, VARIANT *p)
1155 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1157 TRACE("(%p)->(%p)\n", This, p);
1159 return get_doc_event(This, EVENTID_MOUSEUP, p);
1162 static HRESULT WINAPI HTMLDocument_put_onmousedown(IHTMLDocument2 *iface, VARIANT v)
1164 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1166 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1168 return set_doc_event(This, EVENTID_MOUSEDOWN, &v);
1171 static HRESULT WINAPI HTMLDocument_get_onmousedown(IHTMLDocument2 *iface, VARIANT *p)
1173 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1175 TRACE("(%p)->(%p)\n", This, p);
1177 return get_doc_event(This, EVENTID_MOUSEDOWN, p);
1180 static HRESULT WINAPI HTMLDocument_put_onmousemove(IHTMLDocument2 *iface, VARIANT v)
1182 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1184 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1186 return set_doc_event(This, EVENTID_MOUSEMOVE, &v);
1189 static HRESULT WINAPI HTMLDocument_get_onmousemove(IHTMLDocument2 *iface, VARIANT *p)
1191 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1193 TRACE("(%p)->(%p)\n", This, p);
1195 return get_doc_event(This, EVENTID_MOUSEMOVE, p);
1198 static HRESULT WINAPI HTMLDocument_put_onmouseout(IHTMLDocument2 *iface, VARIANT v)
1200 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1202 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1204 return set_doc_event(This, EVENTID_MOUSEOUT, &v);
1207 static HRESULT WINAPI HTMLDocument_get_onmouseout(IHTMLDocument2 *iface, VARIANT *p)
1209 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1211 TRACE("(%p)->(%p)\n", This, p);
1213 return get_doc_event(This, EVENTID_MOUSEOUT, p);
1216 static HRESULT WINAPI HTMLDocument_put_onmouseover(IHTMLDocument2 *iface, VARIANT v)
1218 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1220 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1222 return set_doc_event(This, EVENTID_MOUSEOVER, &v);
1225 static HRESULT WINAPI HTMLDocument_get_onmouseover(IHTMLDocument2 *iface, VARIANT *p)
1227 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1229 TRACE("(%p)->(%p)\n", This, p);
1231 return get_doc_event(This, EVENTID_MOUSEOVER, p);
1234 static HRESULT WINAPI HTMLDocument_put_onreadystatechange(IHTMLDocument2 *iface, VARIANT v)
1236 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1238 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1240 return set_doc_event(This, EVENTID_READYSTATECHANGE, &v);
1243 static HRESULT WINAPI HTMLDocument_get_onreadystatechange(IHTMLDocument2 *iface, VARIANT *p)
1245 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1247 TRACE("(%p)->(%p)\n", This, p);
1249 return get_doc_event(This, EVENTID_READYSTATECHANGE, p);
1252 static HRESULT WINAPI HTMLDocument_put_onafterupdate(IHTMLDocument2 *iface, VARIANT v)
1254 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1255 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1256 return E_NOTIMPL;
1259 static HRESULT WINAPI HTMLDocument_get_onafterupdate(IHTMLDocument2 *iface, VARIANT *p)
1261 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1262 FIXME("(%p)->(%p)\n", This, p);
1263 return E_NOTIMPL;
1266 static HRESULT WINAPI HTMLDocument_put_onrowexit(IHTMLDocument2 *iface, VARIANT v)
1268 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1269 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1270 return E_NOTIMPL;
1273 static HRESULT WINAPI HTMLDocument_get_onrowexit(IHTMLDocument2 *iface, VARIANT *p)
1275 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1276 FIXME("(%p)->(%p)\n", This, p);
1277 return E_NOTIMPL;
1280 static HRESULT WINAPI HTMLDocument_put_onrowenter(IHTMLDocument2 *iface, VARIANT v)
1282 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1283 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1284 return E_NOTIMPL;
1287 static HRESULT WINAPI HTMLDocument_get_onrowenter(IHTMLDocument2 *iface, VARIANT *p)
1289 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1290 FIXME("(%p)->(%p)\n", This, p);
1291 return E_NOTIMPL;
1294 static HRESULT WINAPI HTMLDocument_put_ondragstart(IHTMLDocument2 *iface, VARIANT v)
1296 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1298 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1300 return set_doc_event(This, EVENTID_DRAGSTART, &v);
1303 static HRESULT WINAPI HTMLDocument_get_ondragstart(IHTMLDocument2 *iface, VARIANT *p)
1305 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1307 TRACE("(%p)->(%p)\n", This, p);
1309 return get_doc_event(This, EVENTID_DRAGSTART, p);
1312 static HRESULT WINAPI HTMLDocument_put_onselectstart(IHTMLDocument2 *iface, VARIANT v)
1314 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1316 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1318 return set_doc_event(This, EVENTID_SELECTSTART, &v);
1321 static HRESULT WINAPI HTMLDocument_get_onselectstart(IHTMLDocument2 *iface, VARIANT *p)
1323 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1325 TRACE("(%p)->(%p)\n", This, p);
1327 return get_doc_event(This, EVENTID_SELECTSTART, p);
1330 static HRESULT WINAPI HTMLDocument_elementFromPoint(IHTMLDocument2 *iface, LONG x, LONG y,
1331 IHTMLElement **elementHit)
1333 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1334 nsIDOMElement *nselem;
1335 HTMLDOMNode *node;
1336 nsresult nsres;
1337 HRESULT hres;
1339 TRACE("(%p)->(%d %d %p)\n", This, x, y, elementHit);
1341 nsres = nsIDOMHTMLDocument_ElementFromPoint(This->doc_node->nsdoc, x, y, &nselem);
1342 if(NS_FAILED(nsres)) {
1343 ERR("ElementFromPoint failed: %08x\n", nsres);
1344 return E_FAIL;
1347 if(!nselem) {
1348 *elementHit = NULL;
1349 return S_OK;
1352 hres = get_node(This->doc_node, (nsIDOMNode*)nselem, TRUE, &node);
1353 nsIDOMElement_Release(nselem);
1354 if(FAILED(hres))
1355 return hres;
1357 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)elementHit);
1358 node_release(node);
1359 return hres;
1362 static HRESULT WINAPI HTMLDocument_get_parentWindow(IHTMLDocument2 *iface, IHTMLWindow2 **p)
1364 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1366 TRACE("(%p)->(%p)\n", This, p);
1368 *p = &This->window->base.IHTMLWindow2_iface;
1369 IHTMLWindow2_AddRef(*p);
1370 return S_OK;
1373 static HRESULT WINAPI HTMLDocument_get_styleSheets(IHTMLDocument2 *iface,
1374 IHTMLStyleSheetsCollection **p)
1376 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1377 nsIDOMStyleSheetList *nsstylelist;
1378 nsresult nsres;
1380 TRACE("(%p)->(%p)\n", This, p);
1382 *p = NULL;
1384 if(!This->doc_node->nsdoc) {
1385 WARN("NULL nsdoc\n");
1386 return E_UNEXPECTED;
1389 nsres = nsIDOMHTMLDocument_GetStyleSheets(This->doc_node->nsdoc, &nsstylelist);
1390 if(NS_FAILED(nsres)) {
1391 ERR("GetStyleSheets failed: %08x\n", nsres);
1392 return E_FAIL;
1395 *p = HTMLStyleSheetsCollection_Create(nsstylelist);
1396 nsIDOMStyleSheetList_Release(nsstylelist);
1398 return S_OK;
1401 static HRESULT WINAPI HTMLDocument_put_onbeforeupdate(IHTMLDocument2 *iface, VARIANT v)
1403 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1404 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1405 return E_NOTIMPL;
1408 static HRESULT WINAPI HTMLDocument_get_onbeforeupdate(IHTMLDocument2 *iface, VARIANT *p)
1410 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1411 FIXME("(%p)->(%p)\n", This, p);
1412 return E_NOTIMPL;
1415 static HRESULT WINAPI HTMLDocument_put_onerrorupdate(IHTMLDocument2 *iface, VARIANT v)
1417 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1418 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1419 return E_NOTIMPL;
1422 static HRESULT WINAPI HTMLDocument_get_onerrorupdate(IHTMLDocument2 *iface, VARIANT *p)
1424 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1425 FIXME("(%p)->(%p)\n", This, p);
1426 return E_NOTIMPL;
1429 static HRESULT WINAPI HTMLDocument_toString(IHTMLDocument2 *iface, BSTR *String)
1431 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1432 FIXME("(%p)->(%p)\n", This, String);
1433 return E_NOTIMPL;
1436 static HRESULT WINAPI HTMLDocument_createStyleSheet(IHTMLDocument2 *iface, BSTR bstrHref,
1437 LONG lIndex, IHTMLStyleSheet **ppnewStyleSheet)
1439 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1441 FIXME("(%p)->(%s %d %p) semi-stub\n", This, debugstr_w(bstrHref), lIndex, ppnewStyleSheet);
1443 *ppnewStyleSheet = HTMLStyleSheet_Create(NULL);
1444 return S_OK;
1447 static const IHTMLDocument2Vtbl HTMLDocumentVtbl = {
1448 HTMLDocument_QueryInterface,
1449 HTMLDocument_AddRef,
1450 HTMLDocument_Release,
1451 HTMLDocument_GetTypeInfoCount,
1452 HTMLDocument_GetTypeInfo,
1453 HTMLDocument_GetIDsOfNames,
1454 HTMLDocument_Invoke,
1455 HTMLDocument_get_Script,
1456 HTMLDocument_get_all,
1457 HTMLDocument_get_body,
1458 HTMLDocument_get_activeElement,
1459 HTMLDocument_get_images,
1460 HTMLDocument_get_applets,
1461 HTMLDocument_get_links,
1462 HTMLDocument_get_forms,
1463 HTMLDocument_get_anchors,
1464 HTMLDocument_put_title,
1465 HTMLDocument_get_title,
1466 HTMLDocument_get_scripts,
1467 HTMLDocument_put_designMode,
1468 HTMLDocument_get_designMode,
1469 HTMLDocument_get_selection,
1470 HTMLDocument_get_readyState,
1471 HTMLDocument_get_frames,
1472 HTMLDocument_get_embeds,
1473 HTMLDocument_get_plugins,
1474 HTMLDocument_put_alinkColor,
1475 HTMLDocument_get_alinkColor,
1476 HTMLDocument_put_bgColor,
1477 HTMLDocument_get_bgColor,
1478 HTMLDocument_put_fgColor,
1479 HTMLDocument_get_fgColor,
1480 HTMLDocument_put_linkColor,
1481 HTMLDocument_get_linkColor,
1482 HTMLDocument_put_vlinkColor,
1483 HTMLDocument_get_vlinkColor,
1484 HTMLDocument_get_referrer,
1485 HTMLDocument_get_location,
1486 HTMLDocument_get_lastModified,
1487 HTMLDocument_put_URL,
1488 HTMLDocument_get_URL,
1489 HTMLDocument_put_domain,
1490 HTMLDocument_get_domain,
1491 HTMLDocument_put_cookie,
1492 HTMLDocument_get_cookie,
1493 HTMLDocument_put_expando,
1494 HTMLDocument_get_expando,
1495 HTMLDocument_put_charset,
1496 HTMLDocument_get_charset,
1497 HTMLDocument_put_defaultCharset,
1498 HTMLDocument_get_defaultCharset,
1499 HTMLDocument_get_mimeType,
1500 HTMLDocument_get_fileSize,
1501 HTMLDocument_get_fileCreatedDate,
1502 HTMLDocument_get_fileModifiedDate,
1503 HTMLDocument_get_fileUpdatedDate,
1504 HTMLDocument_get_security,
1505 HTMLDocument_get_protocol,
1506 HTMLDocument_get_nameProp,
1507 HTMLDocument_write,
1508 HTMLDocument_writeln,
1509 HTMLDocument_open,
1510 HTMLDocument_close,
1511 HTMLDocument_clear,
1512 HTMLDocument_queryCommandSupported,
1513 HTMLDocument_queryCommandEnabled,
1514 HTMLDocument_queryCommandState,
1515 HTMLDocument_queryCommandIndeterm,
1516 HTMLDocument_queryCommandText,
1517 HTMLDocument_queryCommandValue,
1518 HTMLDocument_execCommand,
1519 HTMLDocument_execCommandShowHelp,
1520 HTMLDocument_createElement,
1521 HTMLDocument_put_onhelp,
1522 HTMLDocument_get_onhelp,
1523 HTMLDocument_put_onclick,
1524 HTMLDocument_get_onclick,
1525 HTMLDocument_put_ondblclick,
1526 HTMLDocument_get_ondblclick,
1527 HTMLDocument_put_onkeyup,
1528 HTMLDocument_get_onkeyup,
1529 HTMLDocument_put_onkeydown,
1530 HTMLDocument_get_onkeydown,
1531 HTMLDocument_put_onkeypress,
1532 HTMLDocument_get_onkeypress,
1533 HTMLDocument_put_onmouseup,
1534 HTMLDocument_get_onmouseup,
1535 HTMLDocument_put_onmousedown,
1536 HTMLDocument_get_onmousedown,
1537 HTMLDocument_put_onmousemove,
1538 HTMLDocument_get_onmousemove,
1539 HTMLDocument_put_onmouseout,
1540 HTMLDocument_get_onmouseout,
1541 HTMLDocument_put_onmouseover,
1542 HTMLDocument_get_onmouseover,
1543 HTMLDocument_put_onreadystatechange,
1544 HTMLDocument_get_onreadystatechange,
1545 HTMLDocument_put_onafterupdate,
1546 HTMLDocument_get_onafterupdate,
1547 HTMLDocument_put_onrowexit,
1548 HTMLDocument_get_onrowexit,
1549 HTMLDocument_put_onrowenter,
1550 HTMLDocument_get_onrowenter,
1551 HTMLDocument_put_ondragstart,
1552 HTMLDocument_get_ondragstart,
1553 HTMLDocument_put_onselectstart,
1554 HTMLDocument_get_onselectstart,
1555 HTMLDocument_elementFromPoint,
1556 HTMLDocument_get_parentWindow,
1557 HTMLDocument_get_styleSheets,
1558 HTMLDocument_put_onbeforeupdate,
1559 HTMLDocument_get_onbeforeupdate,
1560 HTMLDocument_put_onerrorupdate,
1561 HTMLDocument_get_onerrorupdate,
1562 HTMLDocument_toString,
1563 HTMLDocument_createStyleSheet
1566 static void HTMLDocument_on_advise(IUnknown *iface, cp_static_data_t *cp)
1568 HTMLDocument *This = impl_from_IHTMLDocument2((IHTMLDocument2*)iface);
1570 if(This->window)
1571 update_cp_events(This->window->base.inner_window, &This->doc_node->node.event_target, cp, This->doc_node->node.nsnode);
1574 static inline HTMLDocument *impl_from_ISupportErrorInfo(ISupportErrorInfo *iface)
1576 return CONTAINING_RECORD(iface, HTMLDocument, ISupportErrorInfo_iface);
1579 static HRESULT WINAPI SupportErrorInfo_QueryInterface(ISupportErrorInfo *iface, REFIID riid, void **ppv)
1581 HTMLDocument *This = impl_from_ISupportErrorInfo(iface);
1582 return htmldoc_query_interface(This, riid, ppv);
1585 static ULONG WINAPI SupportErrorInfo_AddRef(ISupportErrorInfo *iface)
1587 HTMLDocument *This = impl_from_ISupportErrorInfo(iface);
1588 return htmldoc_addref(This);
1591 static ULONG WINAPI SupportErrorInfo_Release(ISupportErrorInfo *iface)
1593 HTMLDocument *This = impl_from_ISupportErrorInfo(iface);
1594 return htmldoc_release(This);
1597 static HRESULT WINAPI SupportErrorInfo_InterfaceSupportsErrorInfo(ISupportErrorInfo *iface, REFIID riid)
1599 FIXME("(%p)->(%s)\n", iface, debugstr_guid(riid));
1600 return S_FALSE;
1603 static const ISupportErrorInfoVtbl SupportErrorInfoVtbl = {
1604 SupportErrorInfo_QueryInterface,
1605 SupportErrorInfo_AddRef,
1606 SupportErrorInfo_Release,
1607 SupportErrorInfo_InterfaceSupportsErrorInfo
1610 static inline HTMLDocument *impl_from_IDispatchEx(IDispatchEx *iface)
1612 return CONTAINING_RECORD(iface, HTMLDocument, IDispatchEx_iface);
1615 static HRESULT dispid_from_elem_name(HTMLDocumentNode *This, BSTR name, DISPID *dispid)
1617 nsIDOMNodeList *node_list;
1618 nsAString name_str;
1619 PRUint32 len;
1620 unsigned i;
1621 nsresult nsres;
1623 if(!This->nsdoc)
1624 return DISP_E_UNKNOWNNAME;
1626 nsAString_InitDepend(&name_str, name);
1627 nsres = nsIDOMHTMLDocument_GetElementsByName(This->nsdoc, &name_str, &node_list);
1628 nsAString_Finish(&name_str);
1629 if(NS_FAILED(nsres))
1630 return E_FAIL;
1632 nsres = nsIDOMNodeList_GetLength(node_list, &len);
1633 nsIDOMNodeList_Release(node_list);
1634 if(NS_FAILED(nsres))
1635 return E_FAIL;
1637 if(!len)
1638 return DISP_E_UNKNOWNNAME;
1640 for(i=0; i < This->elem_vars_cnt; i++) {
1641 if(!strcmpW(name, This->elem_vars[i])) {
1642 *dispid = MSHTML_DISPID_CUSTOM_MIN+i;
1643 return S_OK;
1647 if(This->elem_vars_cnt == This->elem_vars_size) {
1648 WCHAR **new_vars;
1650 if(This->elem_vars_size) {
1651 new_vars = heap_realloc(This->elem_vars, This->elem_vars_size*2*sizeof(WCHAR*));
1652 if(!new_vars)
1653 return E_OUTOFMEMORY;
1654 This->elem_vars_size *= 2;
1655 }else {
1656 new_vars = heap_alloc(16*sizeof(WCHAR*));
1657 if(!new_vars)
1658 return E_OUTOFMEMORY;
1659 This->elem_vars_size = 16;
1662 This->elem_vars = new_vars;
1665 This->elem_vars[This->elem_vars_cnt] = heap_strdupW(name);
1666 if(!This->elem_vars[This->elem_vars_cnt])
1667 return E_OUTOFMEMORY;
1669 *dispid = MSHTML_DISPID_CUSTOM_MIN+This->elem_vars_cnt++;
1670 return S_OK;
1673 static HRESULT WINAPI DocDispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
1675 HTMLDocument *This = impl_from_IDispatchEx(iface);
1677 return htmldoc_query_interface(This, riid, ppv);
1680 static ULONG WINAPI DocDispatchEx_AddRef(IDispatchEx *iface)
1682 HTMLDocument *This = impl_from_IDispatchEx(iface);
1684 return htmldoc_addref(This);
1687 static ULONG WINAPI DocDispatchEx_Release(IDispatchEx *iface)
1689 HTMLDocument *This = impl_from_IDispatchEx(iface);
1691 return htmldoc_release(This);
1694 static HRESULT WINAPI DocDispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
1696 HTMLDocument *This = impl_from_IDispatchEx(iface);
1698 return IDispatchEx_GetTypeInfoCount(This->dispex, pctinfo);
1701 static HRESULT WINAPI DocDispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
1702 LCID lcid, ITypeInfo **ppTInfo)
1704 HTMLDocument *This = impl_from_IDispatchEx(iface);
1706 return IDispatchEx_GetTypeInfo(This->dispex, iTInfo, lcid, ppTInfo);
1709 static HRESULT WINAPI DocDispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
1710 LPOLESTR *rgszNames, UINT cNames,
1711 LCID lcid, DISPID *rgDispId)
1713 HTMLDocument *This = impl_from_IDispatchEx(iface);
1715 return IDispatchEx_GetIDsOfNames(This->dispex, riid, rgszNames, cNames, lcid, rgDispId);
1718 static HRESULT WINAPI DocDispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
1719 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1720 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1722 HTMLDocument *This = impl_from_IDispatchEx(iface);
1724 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1725 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1727 switch(dispIdMember) {
1728 case DISPID_READYSTATE:
1729 TRACE("DISPID_READYSTATE\n");
1731 if(!(wFlags & DISPATCH_PROPERTYGET))
1732 return E_INVALIDARG;
1734 V_VT(pVarResult) = VT_I4;
1735 V_I4(pVarResult) = This->window->readystate;
1736 return S_OK;
1739 return IDispatchEx_Invoke(This->dispex, dispIdMember, riid, lcid, wFlags, pDispParams,
1740 pVarResult, pExcepInfo, puArgErr);
1743 static HRESULT WINAPI DocDispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
1745 HTMLDocument *This = impl_from_IDispatchEx(iface);
1746 HRESULT hres;
1748 hres = IDispatchEx_GetDispID(This->dispex, bstrName, grfdex, pid);
1749 if(hres != DISP_E_UNKNOWNNAME)
1750 return hres;
1752 return dispid_from_elem_name(This->doc_node, bstrName, pid);
1755 static HRESULT WINAPI DocDispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1756 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1758 HTMLDocument *This = impl_from_IDispatchEx(iface);
1760 if(This->window && id == DISPID_IHTMLDOCUMENT2_LOCATION && (wFlags & DISPATCH_PROPERTYPUT))
1761 return IDispatchEx_InvokeEx(&This->window->base.IDispatchEx_iface, DISPID_IHTMLWINDOW2_LOCATION,
1762 lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1765 return IDispatchEx_InvokeEx(This->dispex, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1768 static HRESULT WINAPI DocDispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
1770 HTMLDocument *This = impl_from_IDispatchEx(iface);
1772 return IDispatchEx_DeleteMemberByName(This->dispex, bstrName, grfdex);
1775 static HRESULT WINAPI DocDispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
1777 HTMLDocument *This = impl_from_IDispatchEx(iface);
1779 return IDispatchEx_DeleteMemberByDispID(This->dispex, id);
1782 static HRESULT WINAPI DocDispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
1784 HTMLDocument *This = impl_from_IDispatchEx(iface);
1786 return IDispatchEx_GetMemberProperties(This->dispex, id, grfdexFetch, pgrfdex);
1789 static HRESULT WINAPI DocDispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
1791 HTMLDocument *This = impl_from_IDispatchEx(iface);
1793 return IDispatchEx_GetMemberName(This->dispex, id, pbstrName);
1796 static HRESULT WINAPI DocDispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
1798 HTMLDocument *This = impl_from_IDispatchEx(iface);
1800 return IDispatchEx_GetNextDispID(This->dispex, grfdex, id, pid);
1803 static HRESULT WINAPI DocDispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
1805 HTMLDocument *This = impl_from_IDispatchEx(iface);
1807 return IDispatchEx_GetNameSpaceParent(This->dispex, ppunk);
1810 static const IDispatchExVtbl DocDispatchExVtbl = {
1811 DocDispatchEx_QueryInterface,
1812 DocDispatchEx_AddRef,
1813 DocDispatchEx_Release,
1814 DocDispatchEx_GetTypeInfoCount,
1815 DocDispatchEx_GetTypeInfo,
1816 DocDispatchEx_GetIDsOfNames,
1817 DocDispatchEx_Invoke,
1818 DocDispatchEx_GetDispID,
1819 DocDispatchEx_InvokeEx,
1820 DocDispatchEx_DeleteMemberByName,
1821 DocDispatchEx_DeleteMemberByDispID,
1822 DocDispatchEx_GetMemberProperties,
1823 DocDispatchEx_GetMemberName,
1824 DocDispatchEx_GetNextDispID,
1825 DocDispatchEx_GetNameSpaceParent
1828 static inline HTMLDocument *impl_from_IProvideClassInfo(IProvideClassInfo *iface)
1830 return CONTAINING_RECORD(iface, HTMLDocument, IProvideClassInfo_iface);
1833 static HRESULT WINAPI ProvideClassInfo_QueryInterface(IProvideClassInfo *iface,
1834 REFIID riid, void **ppv)
1836 HTMLDocument *This = impl_from_IProvideClassInfo(iface);
1837 return htmldoc_query_interface(This, riid, ppv);
1840 static ULONG WINAPI ProvideClassInfo_AddRef(IProvideClassInfo *iface)
1842 HTMLDocument *This = impl_from_IProvideClassInfo(iface);
1843 return htmldoc_addref(This);
1846 static ULONG WINAPI ProvideClassInfo_Release(IProvideClassInfo *iface)
1848 HTMLDocument *This = impl_from_IProvideClassInfo(iface);
1849 return htmldoc_release(This);
1852 static HRESULT WINAPI ProvideClassInfo_GetClassInfo(IProvideClassInfo* iface,
1853 ITypeInfo **ppTI)
1855 HTMLDocument *This = impl_from_IProvideClassInfo(iface);
1856 TRACE("(%p)->(%p)\n", This, ppTI);
1857 return get_htmldoc_classinfo(ppTI);
1860 static const IProvideClassInfoVtbl ProvideClassInfoVtbl = {
1861 ProvideClassInfo_QueryInterface,
1862 ProvideClassInfo_AddRef,
1863 ProvideClassInfo_Release,
1864 ProvideClassInfo_GetClassInfo
1867 static BOOL htmldoc_qi(HTMLDocument *This, REFIID riid, void **ppv)
1869 *ppv = NULL;
1871 if(IsEqualGUID(&IID_IUnknown, riid)) {
1872 TRACE("(%p)->(IID_IUnknown, %p)\n", This, ppv);
1873 *ppv = &This->IHTMLDocument2_iface;
1874 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1875 TRACE("(%p)->(IID_IDispatch, %p)\n", This, ppv);
1876 *ppv = &This->IDispatchEx_iface;
1877 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
1878 TRACE("(%p)->(IID_IDispatchEx, %p)\n", This, ppv);
1879 *ppv = &This->IDispatchEx_iface;
1880 }else if(IsEqualGUID(&IID_IHTMLDocument, riid)) {
1881 TRACE("(%p)->(IID_IHTMLDocument, %p)\n", This, ppv);
1882 *ppv = &This->IHTMLDocument2_iface;
1883 }else if(IsEqualGUID(&IID_IHTMLDocument2, riid)) {
1884 TRACE("(%p)->(IID_IHTMLDocument2, %p)\n", This, ppv);
1885 *ppv = &This->IHTMLDocument2_iface;
1886 }else if(IsEqualGUID(&IID_IHTMLDocument3, riid)) {
1887 TRACE("(%p)->(IID_IHTMLDocument3, %p)\n", This, ppv);
1888 *ppv = &This->IHTMLDocument3_iface;
1889 }else if(IsEqualGUID(&IID_IHTMLDocument4, riid)) {
1890 TRACE("(%p)->(IID_IHTMLDocument4, %p)\n", This, ppv);
1891 *ppv = &This->IHTMLDocument4_iface;
1892 }else if(IsEqualGUID(&IID_IHTMLDocument5, riid)) {
1893 TRACE("(%p)->(IID_IHTMLDocument5, %p)\n", This, ppv);
1894 *ppv = &This->IHTMLDocument5_iface;
1895 }else if(IsEqualGUID(&IID_IHTMLDocument6, riid)) {
1896 TRACE("(%p)->(IID_IHTMLDocument6, %p)\n", This, ppv);
1897 *ppv = &This->IHTMLDocument6_iface;
1898 }else if(IsEqualGUID(&IID_IPersist, riid)) {
1899 TRACE("(%p)->(IID_IPersist, %p)\n", This, ppv);
1900 *ppv = &This->IPersistFile_iface;
1901 }else if(IsEqualGUID(&IID_IPersistMoniker, riid)) {
1902 TRACE("(%p)->(IID_IPersistMoniker, %p)\n", This, ppv);
1903 *ppv = &This->IPersistMoniker_iface;
1904 }else if(IsEqualGUID(&IID_IPersistFile, riid)) {
1905 TRACE("(%p)->(IID_IPersistFile, %p)\n", This, ppv);
1906 *ppv = &This->IPersistFile_iface;
1907 }else if(IsEqualGUID(&IID_IMonikerProp, riid)) {
1908 TRACE("(%p)->(IID_IMonikerProp, %p)\n", This, ppv);
1909 *ppv = &This->IMonikerProp_iface;
1910 }else if(IsEqualGUID(&IID_IOleObject, riid)) {
1911 TRACE("(%p)->(IID_IOleObject, %p)\n", This, ppv);
1912 *ppv = &This->IOleObject_iface;
1913 }else if(IsEqualGUID(&IID_IOleDocument, riid)) {
1914 TRACE("(%p)->(IID_IOleDocument, %p)\n", This, ppv);
1915 *ppv = &This->IOleDocument_iface;
1916 }else if(IsEqualGUID(&IID_IOleDocumentView, riid)) {
1917 TRACE("(%p)->(IID_IOleDocumentView, %p)\n", This, ppv);
1918 *ppv = &This->IOleDocumentView_iface;
1919 }else if(IsEqualGUID(&IID_IOleInPlaceActiveObject, riid)) {
1920 TRACE("(%p)->(IID_IOleInPlaceActiveObject, %p)\n", This, ppv);
1921 *ppv = &This->IOleInPlaceActiveObject_iface;
1922 }else if(IsEqualGUID(&IID_IViewObject, riid)) {
1923 TRACE("(%p)->(IID_IViewObject, %p)\n", This, ppv);
1924 *ppv = &This->IViewObjectEx_iface;
1925 }else if(IsEqualGUID(&IID_IViewObject2, riid)) {
1926 TRACE("(%p)->(IID_IViewObject2, %p)\n", This, ppv);
1927 *ppv = &This->IViewObjectEx_iface;
1928 }else if(IsEqualGUID(&IID_IViewObjectEx, riid)) {
1929 TRACE("(%p)->(IID_IViewObjectEx, %p)\n", This, ppv);
1930 *ppv = &This->IViewObjectEx_iface;
1931 }else if(IsEqualGUID(&IID_IOleWindow, riid)) {
1932 TRACE("(%p)->(IID_IOleWindow, %p)\n", This, ppv);
1933 *ppv = &This->IOleInPlaceActiveObject_iface;
1934 }else if(IsEqualGUID(&IID_IOleInPlaceObject, riid)) {
1935 TRACE("(%p)->(IID_IOleInPlaceObject, %p)\n", This, ppv);
1936 *ppv = &This->IOleInPlaceObjectWindowless_iface;
1937 }else if(IsEqualGUID(&IID_IOleInPlaceObjectWindowless, riid)) {
1938 TRACE("(%p)->(IID_IOleInPlaceObjectWindowless, %p)\n", This, ppv);
1939 *ppv = &This->IOleInPlaceObjectWindowless_iface;
1940 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
1941 TRACE("(%p)->(IID_IServiceProvider, %p)\n", This, ppv);
1942 *ppv = &This->IServiceProvider_iface;
1943 }else if(IsEqualGUID(&IID_IOleCommandTarget, riid)) {
1944 TRACE("(%p)->(IID_IOleCommandTarget, %p)\n", This, ppv);
1945 *ppv = &This->IOleCommandTarget_iface;
1946 }else if(IsEqualGUID(&IID_IOleControl, riid)) {
1947 TRACE("(%p)->(IID_IOleControl, %p)\n", This, ppv);
1948 *ppv = &This->IOleControl_iface;
1949 }else if(IsEqualGUID(&IID_IHlinkTarget, riid)) {
1950 TRACE("(%p)->(IID_IHlinkTarget, %p)\n", This, ppv);
1951 *ppv = &This->IHlinkTarget_iface;
1952 }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
1953 TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppv);
1954 *ppv = &This->cp_container.IConnectionPointContainer_iface;
1955 }else if(IsEqualGUID(&IID_IPersistStreamInit, riid)) {
1956 TRACE("(%p)->(IID_IPersistStreamInit %p)\n", This, ppv);
1957 *ppv = &This->IPersistStreamInit_iface;
1958 }else if(IsEqualGUID(&DIID_DispHTMLDocument, riid)) {
1959 TRACE("(%p)->(DIID_DispHTMLDocument %p)\n", This, ppv);
1960 *ppv = &This->IHTMLDocument2_iface;
1961 }else if(IsEqualGUID(&IID_ISupportErrorInfo, riid)) {
1962 TRACE("(%p)->(IID_ISupportErrorInfo %p)\n", This, ppv);
1963 *ppv = &This->ISupportErrorInfo_iface;
1964 }else if(IsEqualGUID(&IID_IPersistHistory, riid)) {
1965 TRACE("(%p)->(IID_IPersistHistory %p)\n", This, ppv);
1966 *ppv = &This->IPersistHistory_iface;
1967 }else if(IsEqualGUID(&CLSID_CMarkup, riid)) {
1968 FIXME("(%p)->(CLSID_CMarkup %p)\n", This, ppv);
1969 *ppv = NULL;
1970 }else if(IsEqualGUID(&IID_IRunnableObject, riid)) {
1971 TRACE("(%p)->(IID_IRunnableObject %p) returning NULL\n", This, ppv);
1972 *ppv = NULL;
1973 }else if(IsEqualGUID(&IID_IPersistPropertyBag, riid)) {
1974 TRACE("(%p)->(IID_IPersistPropertyBag %p) returning NULL\n", This, ppv);
1975 *ppv = NULL;
1976 }else if(IsEqualGUID(&IID_IMarshal, riid)) {
1977 TRACE("(%p)->(IID_IMarshal %p) returning NULL\n", This, ppv);
1978 *ppv = NULL;
1979 }else if(IsEqualGUID(&IID_IExternalConnection, riid)) {
1980 TRACE("(%p)->(IID_IExternalConnection %p) returning NULL\n", This, ppv);
1981 *ppv = NULL;
1982 }else if(IsEqualGUID(&IID_IStdMarshalInfo, riid)) {
1983 TRACE("(%p)->(IID_IStdMarshalInfo %p) returning NULL\n", This, ppv);
1984 *ppv = NULL;
1985 }else if(IsEqualGUID(&IID_IObjectWithSite, riid)) {
1986 TRACE("(%p)->(IID_IObjectWithSite %p)\n", This, ppv);
1987 *ppv = &This->IObjectWithSite_iface;
1988 }else if(IsEqualGUID(&IID_IOleContainer, riid)) {
1989 TRACE("(%p)->(IID_IOleContainer %p)\n", This, ppv);
1990 *ppv = &This->IOleContainer_iface;
1991 }else if(IsEqualGUID(&IID_IObjectSafety, riid)) {
1992 TRACE("(%p)->(IID_IObjectSafety %p)\n", This, ppv);
1993 *ppv = &This->IObjectSafety_iface;
1994 }else if(IsEqualGUID(&IID_IProvideClassInfo, riid)) {
1995 TRACE("(%p)->(IID_IProvideClassInfo, %p)\n", This, ppv);
1996 *ppv = &This->IProvideClassInfo_iface;
1997 }else {
1998 return FALSE;
2001 if(*ppv)
2002 IUnknown_AddRef((IUnknown*)*ppv);
2003 return TRUE;
2006 static cp_static_data_t HTMLDocumentEvents_data = { HTMLDocumentEvents_tid, HTMLDocument_on_advise };
2008 static void init_doc(HTMLDocument *doc, IUnknown *unk_impl, IDispatchEx *dispex)
2010 doc->IHTMLDocument2_iface.lpVtbl = &HTMLDocumentVtbl;
2011 doc->IDispatchEx_iface.lpVtbl = &DocDispatchExVtbl;
2012 doc->ISupportErrorInfo_iface.lpVtbl = &SupportErrorInfoVtbl;
2013 doc->IProvideClassInfo_iface.lpVtbl = &ProvideClassInfoVtbl;
2015 doc->unk_impl = unk_impl;
2016 doc->dispex = dispex;
2017 doc->task_magic = get_task_target_magic();
2019 HTMLDocument_HTMLDocument3_Init(doc);
2020 HTMLDocument_HTMLDocument5_Init(doc);
2021 HTMLDocument_Persist_Init(doc);
2022 HTMLDocument_OleCmd_Init(doc);
2023 HTMLDocument_OleObj_Init(doc);
2024 HTMLDocument_View_Init(doc);
2025 HTMLDocument_Window_Init(doc);
2026 HTMLDocument_Service_Init(doc);
2027 HTMLDocument_Hlink_Init(doc);
2029 ConnectionPointContainer_Init(&doc->cp_container, (IUnknown*)&doc->IHTMLDocument2_iface);
2030 ConnectionPoint_Init(&doc->cp_dispatch, &doc->cp_container, &IID_IDispatch, &HTMLDocumentEvents_data);
2031 ConnectionPoint_Init(&doc->cp_propnotif, &doc->cp_container, &IID_IPropertyNotifySink, NULL);
2032 ConnectionPoint_Init(&doc->cp_htmldocevents, &doc->cp_container, &DIID_HTMLDocumentEvents, &HTMLDocumentEvents_data);
2033 ConnectionPoint_Init(&doc->cp_htmldocevents2, &doc->cp_container, &DIID_HTMLDocumentEvents2, NULL);
2036 static void destroy_htmldoc(HTMLDocument *This)
2038 remove_target_tasks(This->task_magic);
2040 ConnectionPointContainer_Destroy(&This->cp_container);
2043 static inline HTMLDocumentNode *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
2045 return CONTAINING_RECORD(iface, HTMLDocumentNode, node);
2048 static HRESULT HTMLDocumentNode_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
2050 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2052 if(htmldoc_qi(&This->basedoc, riid, ppv))
2053 return *ppv ? S_OK : E_NOINTERFACE;
2055 if(IsEqualGUID(&IID_IInternetHostSecurityManager, riid)) {
2056 TRACE("(%p)->(IID_IInternetHostSecurityManager %p)\n", This, ppv);
2057 *ppv = &This->IInternetHostSecurityManager_iface;
2058 }else {
2059 return HTMLDOMNode_QI(&This->node, riid, ppv);
2062 IUnknown_AddRef((IUnknown*)*ppv);
2063 return S_OK;
2066 static void HTMLDocumentNode_destructor(HTMLDOMNode *iface)
2068 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2069 unsigned i;
2071 for(i=0; i < This->elem_vars_cnt; i++)
2072 heap_free(This->elem_vars[i]);
2073 heap_free(This->elem_vars);
2075 detach_events(This);
2076 if(This->body_event_target)
2077 release_event_target(This->body_event_target);
2078 if(This->catmgr)
2079 ICatInformation_Release(This->catmgr);
2081 detach_selection(This);
2082 detach_ranges(This);
2084 while(!list_empty(&This->plugin_hosts))
2085 detach_plugin_host(LIST_ENTRY(list_head(&This->plugin_hosts), PluginHost, entry));
2087 if(This->nsdoc) {
2088 release_document_mutation(This);
2089 nsIDOMHTMLDocument_Release(This->nsdoc);
2092 heap_free(This->event_vector);
2093 destroy_htmldoc(&This->basedoc);
2096 static HRESULT HTMLDocumentNode_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
2098 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2099 FIXME("%p\n", This);
2100 return E_NOTIMPL;
2103 static void HTMLDocumentNode_traverse(HTMLDOMNode *iface, nsCycleCollectionTraversalCallback *cb)
2105 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2107 if(This->nsdoc)
2108 note_cc_edge((nsISupports*)This->nsdoc, "This->nsdoc", cb);
2111 static void HTMLDocumentNode_unlink(HTMLDOMNode *iface)
2113 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2115 if(This->nsdoc) {
2116 nsIDOMHTMLDocument *nsdoc = This->nsdoc;
2118 release_document_mutation(This);
2119 This->nsdoc = NULL;
2120 nsIDOMHTMLDocument_Release(nsdoc);
2124 static const NodeImplVtbl HTMLDocumentNodeImplVtbl = {
2125 HTMLDocumentNode_QI,
2126 HTMLDocumentNode_destructor,
2127 HTMLDocumentNode_clone,
2128 NULL,
2129 NULL,
2130 NULL,
2131 NULL,
2132 NULL,
2133 NULL,
2134 NULL,
2135 NULL,
2136 NULL,
2137 NULL,
2138 NULL,
2139 HTMLDocumentNode_traverse,
2140 HTMLDocumentNode_unlink
2143 static HRESULT HTMLDocumentFragment_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
2145 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2146 HTMLDocumentNode *new_node;
2147 HRESULT hres;
2149 hres = create_document_fragment(nsnode, This->node.doc, &new_node);
2150 if(FAILED(hres))
2151 return hres;
2153 *ret = &new_node->node;
2154 return S_OK;
2157 static inline HTMLDocumentNode *impl_from_DispatchEx(DispatchEx *iface)
2159 return CONTAINING_RECORD(iface, HTMLDocumentNode, node.dispex);
2162 static HRESULT HTMLDocumentNode_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
2163 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2165 HTMLDocumentNode *This = impl_from_DispatchEx(dispex);
2166 nsIDOMNodeList *node_list;
2167 nsAString name_str;
2168 nsIDOMNode *nsnode;
2169 HTMLDOMNode *node;
2170 unsigned i;
2171 nsresult nsres;
2172 HRESULT hres;
2174 if(flags != DISPATCH_PROPERTYGET) {
2175 FIXME("unsupported flags %x\n", flags);
2176 return E_NOTIMPL;
2179 i = id - MSHTML_DISPID_CUSTOM_MIN;
2181 if(!This->nsdoc || i >= This->elem_vars_cnt)
2182 return DISP_E_UNKNOWNNAME;
2184 nsAString_InitDepend(&name_str, This->elem_vars[i]);
2185 nsres = nsIDOMHTMLDocument_GetElementsByName(This->nsdoc, &name_str, &node_list);
2186 nsAString_Finish(&name_str);
2187 if(NS_FAILED(nsres))
2188 return E_FAIL;
2190 nsres = nsIDOMNodeList_Item(node_list, 0, &nsnode);
2191 nsIDOMNodeList_Release(node_list);
2192 if(NS_FAILED(nsres) || !nsnode)
2193 return DISP_E_UNKNOWNNAME;
2195 hres = get_node(This, nsnode, TRUE, &node);
2196 if(FAILED(hres))
2197 return hres;
2199 V_VT(res) = VT_DISPATCH;
2200 V_DISPATCH(res) = (IDispatch*)&node->IHTMLDOMNode_iface;
2201 return S_OK;
2205 static const dispex_static_data_vtbl_t HTMLDocumentNode_dispex_vtbl = {
2206 NULL,
2207 NULL,
2208 HTMLDocumentNode_invoke,
2209 NULL
2212 static const NodeImplVtbl HTMLDocumentFragmentImplVtbl = {
2213 HTMLDocumentNode_QI,
2214 HTMLDocumentNode_destructor,
2215 HTMLDocumentFragment_clone
2218 static const tid_t HTMLDocumentNode_iface_tids[] = {
2219 IHTMLDOMNode_tid,
2220 IHTMLDOMNode2_tid,
2221 IHTMLDocument2_tid,
2222 IHTMLDocument3_tid,
2223 IHTMLDocument4_tid,
2224 IHTMLDocument5_tid,
2228 static dispex_static_data_t HTMLDocumentNode_dispex = {
2229 &HTMLDocumentNode_dispex_vtbl,
2230 DispHTMLDocument_tid,
2231 NULL,
2232 HTMLDocumentNode_iface_tids
2235 static HTMLDocumentNode *alloc_doc_node(HTMLDocumentObj *doc_obj, HTMLOuterWindow *window)
2237 HTMLDocumentNode *doc;
2239 doc = heap_alloc_zero(sizeof(HTMLDocumentNode));
2240 if(!doc)
2241 return NULL;
2243 doc->ref = 1;
2244 doc->basedoc.doc_node = doc;
2245 doc->basedoc.doc_obj = doc_obj;
2246 doc->basedoc.window = window;
2248 init_dispex(&doc->node.dispex, (IUnknown*)&doc->node.IHTMLDOMNode_iface,
2249 &HTMLDocumentNode_dispex);
2250 init_doc(&doc->basedoc, (IUnknown*)&doc->node.IHTMLDOMNode_iface,
2251 &doc->node.dispex.IDispatchEx_iface);
2252 HTMLDocumentNode_SecMgr_Init(doc);
2254 list_init(&doc->selection_list);
2255 list_init(&doc->range_list);
2256 list_init(&doc->plugin_hosts);
2258 return doc;
2261 HRESULT create_doc_from_nsdoc(nsIDOMHTMLDocument *nsdoc, HTMLDocumentObj *doc_obj, HTMLOuterWindow *window, HTMLDocumentNode **ret)
2263 HTMLDocumentNode *doc;
2265 doc = alloc_doc_node(doc_obj, window);
2266 if(!doc)
2267 return E_OUTOFMEMORY;
2269 if(!doc_obj->basedoc.window || window == doc_obj->basedoc.window)
2270 doc->basedoc.cp_container.forward_container = &doc_obj->basedoc.cp_container;
2272 HTMLDOMNode_Init(doc, &doc->node, (nsIDOMNode*)nsdoc);
2274 nsIDOMHTMLDocument_AddRef(nsdoc);
2275 doc->nsdoc = nsdoc;
2277 init_document_mutation(doc);
2278 doc_init_events(doc);
2280 doc->node.vtbl = &HTMLDocumentNodeImplVtbl;
2281 doc->node.cp_container = &doc->basedoc.cp_container;
2283 *ret = doc;
2284 return S_OK;
2287 HRESULT create_document_fragment(nsIDOMNode *nsnode, HTMLDocumentNode *doc_node, HTMLDocumentNode **ret)
2289 HTMLDocumentNode *doc_frag;
2291 doc_frag = alloc_doc_node(doc_node->basedoc.doc_obj, doc_node->basedoc.window);
2292 if(!doc_frag)
2293 return E_OUTOFMEMORY;
2295 HTMLDOMNode_Init(doc_node, &doc_frag->node, nsnode);
2296 doc_frag->node.vtbl = &HTMLDocumentFragmentImplVtbl;
2297 doc_frag->node.cp_container = &doc_frag->basedoc.cp_container;
2299 *ret = doc_frag;
2300 return S_OK;
2303 /**********************************************************
2304 * ICustomDoc implementation
2307 static inline HTMLDocumentObj *impl_from_ICustomDoc(ICustomDoc *iface)
2309 return CONTAINING_RECORD(iface, HTMLDocumentObj, ICustomDoc_iface);
2312 static HRESULT WINAPI CustomDoc_QueryInterface(ICustomDoc *iface, REFIID riid, void **ppv)
2314 HTMLDocumentObj *This = impl_from_ICustomDoc(iface);
2316 if(htmldoc_qi(&This->basedoc, riid, ppv))
2317 return *ppv ? S_OK : E_NOINTERFACE;
2319 if(IsEqualGUID(&IID_ICustomDoc, riid)) {
2320 TRACE("(%p)->(IID_ICustomDoc %p)\n", This, ppv);
2321 *ppv = &This->ICustomDoc_iface;
2322 }else if(IsEqualGUID(&IID_ITargetContainer, riid)) {
2323 TRACE("(%p)->(IID_ITargetContainer %p)\n", This, ppv);
2324 *ppv = &This->ITargetContainer_iface;
2325 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
2326 return *ppv ? S_OK : E_NOINTERFACE;
2327 }else {
2328 FIXME("Unimplemented interface %s\n", debugstr_guid(riid));
2329 *ppv = NULL;
2330 return E_NOINTERFACE;
2333 IUnknown_AddRef((IUnknown*)*ppv);
2334 return S_OK;
2337 static ULONG WINAPI CustomDoc_AddRef(ICustomDoc *iface)
2339 HTMLDocumentObj *This = impl_from_ICustomDoc(iface);
2340 ULONG ref = InterlockedIncrement(&This->ref);
2342 TRACE("(%p) ref = %u\n", This, ref);
2344 return ref;
2347 static ULONG WINAPI CustomDoc_Release(ICustomDoc *iface)
2349 HTMLDocumentObj *This = impl_from_ICustomDoc(iface);
2350 ULONG ref = InterlockedDecrement(&This->ref);
2352 TRACE("(%p) ref = %u\n", This, ref);
2354 if(!ref) {
2355 nsIDOMWindowUtils *window_utils = NULL;
2357 if(This->basedoc.window && This->basedoc.window->nswindow)
2358 get_nsinterface((nsISupports*)This->basedoc.window->nswindow, &IID_nsIDOMWindowUtils, (void**)&window_utils);
2360 if(This->basedoc.doc_node) {
2361 This->basedoc.doc_node->basedoc.doc_obj = NULL;
2362 htmldoc_release(&This->basedoc.doc_node->basedoc);
2364 if(This->basedoc.window) {
2365 This->basedoc.window->doc_obj = NULL;
2366 IHTMLWindow2_Release(&This->basedoc.window->base.IHTMLWindow2_iface);
2368 if(This->basedoc.advise_holder)
2369 IOleAdviseHolder_Release(This->basedoc.advise_holder);
2371 if(This->view_sink)
2372 IAdviseSink_Release(This->view_sink);
2373 if(This->client)
2374 IOleObject_SetClientSite(&This->basedoc.IOleObject_iface, NULL);
2375 if(This->hostui)
2376 ICustomDoc_SetUIHandler(&This->ICustomDoc_iface, NULL);
2377 if(This->in_place_active)
2378 IOleInPlaceObjectWindowless_InPlaceDeactivate(&This->basedoc.IOleInPlaceObjectWindowless_iface);
2379 if(This->ipsite)
2380 IOleDocumentView_SetInPlaceSite(&This->basedoc.IOleDocumentView_iface, NULL);
2381 if(This->undomgr)
2382 IOleUndoManager_Release(This->undomgr);
2383 if(This->tooltips_hwnd)
2384 DestroyWindow(This->tooltips_hwnd);
2386 if(This->hwnd)
2387 DestroyWindow(This->hwnd);
2388 heap_free(This->mime);
2390 destroy_htmldoc(&This->basedoc);
2391 release_dispex(&This->dispex);
2393 if(This->nscontainer)
2394 NSContainer_Release(This->nscontainer);
2395 heap_free(This);
2397 /* Force cycle collection */
2398 if(window_utils) {
2399 nsIDOMWindowUtils_CycleCollect(window_utils, NULL, 0);
2400 nsIDOMWindowUtils_Release(window_utils);
2404 return ref;
2407 static HRESULT WINAPI CustomDoc_SetUIHandler(ICustomDoc *iface, IDocHostUIHandler *pUIHandler)
2409 HTMLDocumentObj *This = impl_from_ICustomDoc(iface);
2410 IOleCommandTarget *cmdtrg;
2411 HRESULT hres;
2413 TRACE("(%p)->(%p)\n", This, pUIHandler);
2415 if(This->custom_hostui && This->hostui == pUIHandler)
2416 return S_OK;
2418 This->custom_hostui = TRUE;
2420 if(This->hostui)
2421 IDocHostUIHandler_Release(This->hostui);
2422 if(pUIHandler)
2423 IDocHostUIHandler_AddRef(pUIHandler);
2424 This->hostui = pUIHandler;
2425 if(!pUIHandler)
2426 return S_OK;
2428 hres = IDocHostUIHandler_QueryInterface(pUIHandler, &IID_IOleCommandTarget, (void**)&cmdtrg);
2429 if(SUCCEEDED(hres)) {
2430 FIXME("custom UI handler supports IOleCommandTarget\n");
2431 IOleCommandTarget_Release(cmdtrg);
2434 return S_OK;
2437 static const ICustomDocVtbl CustomDocVtbl = {
2438 CustomDoc_QueryInterface,
2439 CustomDoc_AddRef,
2440 CustomDoc_Release,
2441 CustomDoc_SetUIHandler
2444 static const tid_t HTMLDocumentObj_iface_tids[] = {
2445 IHTMLDocument2_tid,
2446 IHTMLDocument3_tid,
2447 IHTMLDocument4_tid,
2448 IHTMLDocument5_tid,
2451 static dispex_static_data_t HTMLDocumentObj_dispex = {
2452 NULL,
2453 DispHTMLDocument_tid,
2454 NULL,
2455 HTMLDocumentObj_iface_tids
2458 HRESULT HTMLDocument_Create(IUnknown *pUnkOuter, REFIID riid, void** ppvObject)
2460 HTMLDocumentObj *doc;
2461 nsIDOMWindow *nswindow = NULL;
2462 nsresult nsres;
2463 HRESULT hres;
2465 TRACE("(%p %s %p)\n", pUnkOuter, debugstr_guid(riid), ppvObject);
2467 doc = heap_alloc_zero(sizeof(HTMLDocumentObj));
2468 if(!doc)
2469 return E_OUTOFMEMORY;
2471 init_dispex(&doc->dispex, (IUnknown*)&doc->ICustomDoc_iface, &HTMLDocumentObj_dispex);
2472 init_doc(&doc->basedoc, (IUnknown*)&doc->ICustomDoc_iface, &doc->dispex.IDispatchEx_iface);
2473 TargetContainer_Init(doc);
2475 doc->ICustomDoc_iface.lpVtbl = &CustomDocVtbl;
2476 doc->ref = 1;
2477 doc->basedoc.doc_obj = doc;
2479 doc->usermode = UNKNOWN_USERMODE;
2481 init_binding_ui(doc);
2483 hres = create_nscontainer(doc, &doc->nscontainer);
2484 if(FAILED(hres)) {
2485 ERR("Failed to init Gecko, returning CLASS_E_CLASSNOTAVAILABLE\n");
2486 htmldoc_release(&doc->basedoc);
2487 return hres;
2490 hres = htmldoc_query_interface(&doc->basedoc, riid, ppvObject);
2491 htmldoc_release(&doc->basedoc);
2492 if(FAILED(hres))
2493 return hres;
2495 nsres = nsIWebBrowser_GetContentDOMWindow(doc->nscontainer->webbrowser, &nswindow);
2496 if(NS_FAILED(nsres))
2497 ERR("GetContentDOMWindow failed: %08x\n", nsres);
2499 hres = HTMLOuterWindow_Create(doc, nswindow, NULL /* FIXME */, &doc->basedoc.window);
2500 if(nswindow)
2501 nsIDOMWindow_Release(nswindow);
2502 if(FAILED(hres)) {
2503 htmldoc_release(&doc->basedoc);
2504 return hres;
2507 if(!doc->basedoc.doc_node && doc->basedoc.window->base.inner_window->doc) {
2508 doc->basedoc.doc_node = doc->basedoc.window->base.inner_window->doc;
2509 htmldoc_addref(&doc->basedoc.doc_node->basedoc);
2512 get_thread_hwnd();
2514 return S_OK;