d3dcompiler_43: Use BOOL type where appropriate.
[wine.git] / dlls / mshtml / htmldoc.c
blob0df30da617901c439ec8d9a764901f31eca60a67
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"
40 #include "binding.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
44 static inline HTMLDocument *impl_from_IHTMLDocument2(IHTMLDocument2 *iface)
46 return CONTAINING_RECORD(iface, HTMLDocument, IHTMLDocument2_iface);
49 static HRESULT WINAPI HTMLDocument_QueryInterface(IHTMLDocument2 *iface, REFIID riid, void **ppv)
51 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
53 return htmldoc_query_interface(This, riid, ppv);
56 static ULONG WINAPI HTMLDocument_AddRef(IHTMLDocument2 *iface)
58 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
60 return htmldoc_addref(This);
63 static ULONG WINAPI HTMLDocument_Release(IHTMLDocument2 *iface)
65 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
67 return htmldoc_release(This);
70 static HRESULT WINAPI HTMLDocument_GetTypeInfoCount(IHTMLDocument2 *iface, UINT *pctinfo)
72 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
74 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
77 static HRESULT WINAPI HTMLDocument_GetTypeInfo(IHTMLDocument2 *iface, UINT iTInfo,
78 LCID lcid, ITypeInfo **ppTInfo)
80 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
82 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
85 static HRESULT WINAPI HTMLDocument_GetIDsOfNames(IHTMLDocument2 *iface, REFIID riid,
86 LPOLESTR *rgszNames, UINT cNames,
87 LCID lcid, DISPID *rgDispId)
89 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
91 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
92 rgDispId);
95 static HRESULT WINAPI HTMLDocument_Invoke(IHTMLDocument2 *iface, DISPID dispIdMember,
96 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
97 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
99 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
101 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
102 pDispParams, pVarResult, pExcepInfo, puArgErr);
105 static HRESULT WINAPI HTMLDocument_get_Script(IHTMLDocument2 *iface, IDispatch **p)
107 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
109 TRACE("(%p)->(%p)\n", This, p);
111 *p = (IDispatch*)&This->window->base.IHTMLWindow2_iface;
112 IDispatch_AddRef(*p);
113 return S_OK;
116 static HRESULT WINAPI HTMLDocument_get_all(IHTMLDocument2 *iface, IHTMLElementCollection **p)
118 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
119 nsIDOMElement *nselem = NULL;
120 HTMLDOMNode *node;
121 nsresult nsres;
122 HRESULT hres;
124 TRACE("(%p)->(%p)\n", This, p);
126 if(!This->doc_node->nsdoc) {
127 WARN("NULL nsdoc\n");
128 return E_UNEXPECTED;
131 nsres = nsIDOMHTMLDocument_GetDocumentElement(This->doc_node->nsdoc, &nselem);
132 if(NS_FAILED(nsres)) {
133 ERR("GetDocumentElement failed: %08x\n", nsres);
134 return E_FAIL;
137 if(!nselem) {
138 *p = NULL;
139 return S_OK;
142 hres = get_node(This->doc_node, (nsIDOMNode*)nselem, TRUE, &node);
143 nsIDOMElement_Release(nselem);
144 if(FAILED(hres))
145 return hres;
147 *p = create_all_collection(node, TRUE);
148 node_release(node);
149 return hres;
152 static HRESULT WINAPI HTMLDocument_get_body(IHTMLDocument2 *iface, IHTMLElement **p)
154 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
155 nsIDOMHTMLElement *nsbody = NULL;
156 HTMLDOMNode *node;
157 HRESULT hres;
159 TRACE("(%p)->(%p)\n", This, p);
161 if(This->doc_node->nsdoc) {
162 nsresult nsres;
164 nsres = nsIDOMHTMLDocument_GetBody(This->doc_node->nsdoc, &nsbody);
165 if(NS_FAILED(nsres)) {
166 TRACE("Could not get body: %08x\n", nsres);
167 return E_UNEXPECTED;
171 if(!nsbody) {
172 *p = NULL;
173 return S_OK;
176 hres = get_node(This->doc_node, (nsIDOMNode*)nsbody, TRUE, &node);
177 nsIDOMHTMLElement_Release(nsbody);
178 if(FAILED(hres))
179 return hres;
181 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)p);
182 node_release(node);
183 return hres;
186 static HRESULT WINAPI HTMLDocument_get_activeElement(IHTMLDocument2 *iface, IHTMLElement **p)
188 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
189 FIXME("(%p)->(%p)\n", This, p);
190 return E_NOTIMPL;
193 static HRESULT WINAPI HTMLDocument_get_images(IHTMLDocument2 *iface, IHTMLElementCollection **p)
195 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
196 nsIDOMHTMLCollection *nscoll = NULL;
197 nsresult nsres;
199 TRACE("(%p)->(%p)\n", This, p);
201 if(!p)
202 return E_INVALIDARG;
204 *p = NULL;
206 if(!This->doc_node->nsdoc) {
207 WARN("NULL nsdoc\n");
208 return E_UNEXPECTED;
211 nsres = nsIDOMHTMLDocument_GetImages(This->doc_node->nsdoc, &nscoll);
212 if(NS_FAILED(nsres)) {
213 ERR("GetImages failed: %08x\n", nsres);
214 return E_FAIL;
217 if(nscoll) {
218 *p = create_collection_from_htmlcol(This->doc_node, nscoll);
219 nsIDOMHTMLCollection_Release(nscoll);
222 return S_OK;
225 static HRESULT WINAPI HTMLDocument_get_applets(IHTMLDocument2 *iface, IHTMLElementCollection **p)
227 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
228 nsIDOMHTMLCollection *nscoll = NULL;
229 nsresult nsres;
231 TRACE("(%p)->(%p)\n", This, p);
233 if(!p)
234 return E_INVALIDARG;
236 *p = NULL;
238 if(!This->doc_node->nsdoc) {
239 WARN("NULL nsdoc\n");
240 return E_UNEXPECTED;
243 nsres = nsIDOMHTMLDocument_GetApplets(This->doc_node->nsdoc, &nscoll);
244 if(NS_FAILED(nsres)) {
245 ERR("GetApplets failed: %08x\n", nsres);
246 return E_FAIL;
249 if(nscoll) {
250 *p = create_collection_from_htmlcol(This->doc_node, nscoll);
251 nsIDOMHTMLCollection_Release(nscoll);
254 return S_OK;
257 static HRESULT WINAPI HTMLDocument_get_links(IHTMLDocument2 *iface, IHTMLElementCollection **p)
259 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
260 nsIDOMHTMLCollection *nscoll = NULL;
261 nsresult nsres;
263 TRACE("(%p)->(%p)\n", This, p);
265 if(!p)
266 return E_INVALIDARG;
268 *p = NULL;
270 if(!This->doc_node->nsdoc) {
271 WARN("NULL nsdoc\n");
272 return E_UNEXPECTED;
275 nsres = nsIDOMHTMLDocument_GetLinks(This->doc_node->nsdoc, &nscoll);
276 if(NS_FAILED(nsres)) {
277 ERR("GetLinks failed: %08x\n", nsres);
278 return E_FAIL;
281 if(nscoll) {
282 *p = create_collection_from_htmlcol(This->doc_node, nscoll);
283 nsIDOMHTMLCollection_Release(nscoll);
286 return S_OK;
289 static HRESULT WINAPI HTMLDocument_get_forms(IHTMLDocument2 *iface, IHTMLElementCollection **p)
291 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
292 nsIDOMHTMLCollection *nscoll = NULL;
293 nsresult nsres;
295 TRACE("(%p)->(%p)\n", This, p);
297 if(!p)
298 return E_INVALIDARG;
300 *p = NULL;
302 if(!This->doc_node->nsdoc) {
303 WARN("NULL nsdoc\n");
304 return E_UNEXPECTED;
307 nsres = nsIDOMHTMLDocument_GetForms(This->doc_node->nsdoc, &nscoll);
308 if(NS_FAILED(nsres)) {
309 ERR("GetForms failed: %08x\n", nsres);
310 return E_FAIL;
313 if(nscoll) {
314 *p = create_collection_from_htmlcol(This->doc_node, nscoll);
315 nsIDOMHTMLCollection_Release(nscoll);
318 return S_OK;
321 static HRESULT WINAPI HTMLDocument_get_anchors(IHTMLDocument2 *iface, IHTMLElementCollection **p)
323 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
324 nsIDOMHTMLCollection *nscoll = NULL;
325 nsresult nsres;
327 TRACE("(%p)->(%p)\n", This, p);
329 if(!p)
330 return E_INVALIDARG;
332 *p = NULL;
334 if(!This->doc_node->nsdoc) {
335 WARN("NULL nsdoc\n");
336 return E_UNEXPECTED;
339 nsres = nsIDOMHTMLDocument_GetAnchors(This->doc_node->nsdoc, &nscoll);
340 if(NS_FAILED(nsres)) {
341 ERR("GetAnchors failed: %08x\n", nsres);
342 return E_FAIL;
345 if(nscoll) {
346 *p = create_collection_from_htmlcol(This->doc_node, nscoll);
347 nsIDOMHTMLCollection_Release(nscoll);
350 return S_OK;
353 static HRESULT WINAPI HTMLDocument_put_title(IHTMLDocument2 *iface, BSTR v)
355 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
356 nsAString nsstr;
357 nsresult nsres;
359 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
361 if(!This->doc_node->nsdoc) {
362 WARN("NULL nsdoc\n");
363 return E_UNEXPECTED;
366 nsAString_InitDepend(&nsstr, v);
367 nsres = nsIDOMHTMLDocument_SetTitle(This->doc_node->nsdoc, &nsstr);
368 nsAString_Finish(&nsstr);
369 if(NS_FAILED(nsres))
370 ERR("SetTitle failed: %08x\n", nsres);
372 return S_OK;
375 static HRESULT WINAPI HTMLDocument_get_title(IHTMLDocument2 *iface, BSTR *p)
377 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
378 const PRUnichar *ret;
379 nsAString nsstr;
380 nsresult nsres;
382 TRACE("(%p)->(%p)\n", This, p);
384 if(!This->doc_node->nsdoc) {
385 WARN("NULL nsdoc\n");
386 return E_UNEXPECTED;
390 nsAString_Init(&nsstr, NULL);
391 nsres = nsIDOMHTMLDocument_GetTitle(This->doc_node->nsdoc, &nsstr);
392 if (NS_SUCCEEDED(nsres)) {
393 nsAString_GetData(&nsstr, &ret);
394 *p = SysAllocString(ret);
396 nsAString_Finish(&nsstr);
398 if(NS_FAILED(nsres)) {
399 ERR("GetTitle failed: %08x\n", nsres);
400 return E_FAIL;
403 return S_OK;
406 static HRESULT WINAPI HTMLDocument_get_scripts(IHTMLDocument2 *iface, IHTMLElementCollection **p)
408 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
409 nsIDOMHTMLCollection *nscoll = NULL;
410 nsresult nsres;
412 TRACE("(%p)->(%p)\n", This, p);
414 if(!p)
415 return E_INVALIDARG;
417 *p = NULL;
419 if(!This->doc_node->nsdoc) {
420 WARN("NULL nsdoc\n");
421 return E_UNEXPECTED;
424 nsres = nsIDOMHTMLDocument_GetScripts(This->doc_node->nsdoc, &nscoll);
425 if(NS_FAILED(nsres)) {
426 ERR("GetImages failed: %08x\n", nsres);
427 return E_FAIL;
430 if(nscoll) {
431 *p = create_collection_from_htmlcol(This->doc_node, nscoll);
432 nsIDOMHTMLCollection_Release(nscoll);
435 return S_OK;
438 static HRESULT WINAPI HTMLDocument_put_designMode(IHTMLDocument2 *iface, BSTR v)
440 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
441 HRESULT hres;
443 static const WCHAR onW[] = {'o','n',0};
445 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
447 if(strcmpiW(v, onW)) {
448 FIXME("Unsupported arg %s\n", debugstr_w(v));
449 return E_NOTIMPL;
452 hres = setup_edit_mode(This->doc_obj);
453 if(FAILED(hres))
454 return hres;
456 call_property_onchanged(&This->cp_container, DISPID_IHTMLDOCUMENT2_DESIGNMODE);
457 return S_OK;
460 static HRESULT WINAPI HTMLDocument_get_designMode(IHTMLDocument2 *iface, BSTR *p)
462 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
463 static WCHAR szOff[] = {'O','f','f',0};
464 FIXME("(%p)->(%p) always returning Off\n", This, p);
466 if(!p)
467 return E_INVALIDARG;
469 *p = SysAllocString(szOff);
471 return S_OK;
474 static HRESULT WINAPI HTMLDocument_get_selection(IHTMLDocument2 *iface, IHTMLSelectionObject **p)
476 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
477 nsISelection *nsselection;
478 nsresult nsres;
480 TRACE("(%p)->(%p)\n", This, p);
482 nsres = nsIDOMWindow_GetSelection(This->window->nswindow, &nsselection);
483 if(NS_FAILED(nsres)) {
484 ERR("GetSelection failed: %08x\n", nsres);
485 return E_FAIL;
488 return HTMLSelectionObject_Create(This->doc_node, nsselection, p);
491 static HRESULT WINAPI HTMLDocument_get_readyState(IHTMLDocument2 *iface, BSTR *p)
493 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
495 static const WCHAR wszUninitialized[] = {'u','n','i','n','i','t','i','a','l','i','z','e','d',0};
496 static const WCHAR wszLoading[] = {'l','o','a','d','i','n','g',0};
497 static const WCHAR wszLoaded[] = {'l','o','a','d','e','d',0};
498 static const WCHAR wszInteractive[] = {'i','n','t','e','r','a','c','t','i','v','e',0};
499 static const WCHAR wszComplete[] = {'c','o','m','p','l','e','t','e',0};
501 static const LPCWSTR readystate_str[] = {
502 wszUninitialized,
503 wszLoading,
504 wszLoaded,
505 wszInteractive,
506 wszComplete
509 TRACE("(%p)->(%p)\n", iface, p);
511 if(!p)
512 return E_POINTER;
514 *p = SysAllocString(readystate_str[This->window->readystate]);
515 return S_OK;
518 static HRESULT WINAPI HTMLDocument_get_frames(IHTMLDocument2 *iface, IHTMLFramesCollection2 **p)
520 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
522 TRACE("(%p)->(%p)\n", This, p);
524 return IHTMLWindow2_get_frames(&This->window->base.IHTMLWindow2_iface, p);
527 static HRESULT WINAPI HTMLDocument_get_embeds(IHTMLDocument2 *iface, IHTMLElementCollection **p)
529 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
530 FIXME("(%p)->(%p)\n", This, p);
531 return E_NOTIMPL;
534 static HRESULT WINAPI HTMLDocument_get_plugins(IHTMLDocument2 *iface, IHTMLElementCollection **p)
536 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
537 FIXME("(%p)->(%p)\n", This, p);
538 return E_NOTIMPL;
541 static HRESULT WINAPI HTMLDocument_put_alinkColor(IHTMLDocument2 *iface, VARIANT v)
543 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
544 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
545 return E_NOTIMPL;
548 static HRESULT WINAPI HTMLDocument_get_alinkColor(IHTMLDocument2 *iface, VARIANT *p)
550 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
551 FIXME("(%p)->(%p)\n", This, p);
552 return E_NOTIMPL;
555 static HRESULT WINAPI HTMLDocument_put_bgColor(IHTMLDocument2 *iface, VARIANT v)
557 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
558 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
559 return E_NOTIMPL;
562 static HRESULT WINAPI HTMLDocument_get_bgColor(IHTMLDocument2 *iface, VARIANT *p)
564 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
565 FIXME("(%p)->(%p)\n", This, p);
566 return E_NOTIMPL;
569 static HRESULT WINAPI HTMLDocument_put_fgColor(IHTMLDocument2 *iface, VARIANT v)
571 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
572 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
573 return E_NOTIMPL;
576 static HRESULT WINAPI HTMLDocument_get_fgColor(IHTMLDocument2 *iface, VARIANT *p)
578 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
579 FIXME("(%p)->(%p)\n", This, p);
580 return E_NOTIMPL;
583 static HRESULT WINAPI HTMLDocument_put_linkColor(IHTMLDocument2 *iface, VARIANT v)
585 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
586 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
587 return E_NOTIMPL;
590 static HRESULT WINAPI HTMLDocument_get_linkColor(IHTMLDocument2 *iface, VARIANT *p)
592 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
593 FIXME("(%p)->(%p)\n", This, p);
594 return E_NOTIMPL;
597 static HRESULT WINAPI HTMLDocument_put_vlinkColor(IHTMLDocument2 *iface, VARIANT v)
599 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
600 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
601 return E_NOTIMPL;
604 static HRESULT WINAPI HTMLDocument_get_vlinkColor(IHTMLDocument2 *iface, VARIANT *p)
606 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
607 FIXME("(%p)->(%p)\n", This, p);
608 return E_NOTIMPL;
611 static HRESULT WINAPI HTMLDocument_get_referrer(IHTMLDocument2 *iface, BSTR *p)
613 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
615 FIXME("(%p)->(%p)\n", This, p);
617 *p = NULL;
618 return S_OK;
621 static HRESULT WINAPI HTMLDocument_get_location(IHTMLDocument2 *iface, IHTMLLocation **p)
623 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
625 TRACE("(%p)->(%p)\n", This, p);
627 if(!This->doc_node->nsdoc) {
628 WARN("NULL nsdoc\n");
629 return E_UNEXPECTED;
632 return IHTMLWindow2_get_location(&This->window->base.IHTMLWindow2_iface, p);
635 static HRESULT WINAPI HTMLDocument_get_lastModified(IHTMLDocument2 *iface, BSTR *p)
637 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
638 FIXME("(%p)->(%p)\n", This, p);
639 return E_NOTIMPL;
642 static HRESULT WINAPI HTMLDocument_put_URL(IHTMLDocument2 *iface, BSTR v)
644 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
646 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
648 if(!This->window) {
649 FIXME("No window available\n");
650 return E_FAIL;
653 return navigate_url(This->window, v, This->window->uri, BINDING_NAVIGATED);
656 static HRESULT WINAPI HTMLDocument_get_URL(IHTMLDocument2 *iface, BSTR *p)
658 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
660 static const WCHAR about_blank_url[] =
661 {'a','b','o','u','t',':','b','l','a','n','k',0};
663 TRACE("(%p)->(%p)\n", iface, p);
665 *p = SysAllocString(This->window->url ? This->window->url : about_blank_url);
666 return *p ? S_OK : E_OUTOFMEMORY;
669 static HRESULT WINAPI HTMLDocument_put_domain(IHTMLDocument2 *iface, BSTR v)
671 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
672 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
673 return E_NOTIMPL;
676 static HRESULT WINAPI HTMLDocument_get_domain(IHTMLDocument2 *iface, BSTR *p)
678 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
679 HRESULT hres;
681 TRACE("(%p)->(%p)\n", This, p);
683 if(!This->window || !This->window->uri) {
684 FIXME("No current URI\n");
685 return E_FAIL;
688 hres = IUri_GetHost(This->window->uri, p);
689 return FAILED(hres) ? hres : S_OK;
692 static HRESULT WINAPI HTMLDocument_put_cookie(IHTMLDocument2 *iface, BSTR v)
694 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
695 BOOL bret;
697 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
699 bret = InternetSetCookieExW(This->window->url, NULL, v, 0, 0);
700 if(!bret) {
701 FIXME("InternetSetCookieExW failed: %u\n", GetLastError());
702 return HRESULT_FROM_WIN32(GetLastError());
705 return S_OK;
708 static HRESULT WINAPI HTMLDocument_get_cookie(IHTMLDocument2 *iface, BSTR *p)
710 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
711 DWORD size;
712 BOOL bret;
714 TRACE("(%p)->(%p)\n", This, p);
716 size = 0;
717 bret = InternetGetCookieExW(This->window->url, NULL, NULL, &size, 0, NULL);
718 if(!bret) {
719 switch(GetLastError()) {
720 case ERROR_INSUFFICIENT_BUFFER:
721 break;
722 case ERROR_NO_MORE_ITEMS:
723 *p = NULL;
724 return S_OK;
725 default:
726 FIXME("InternetGetCookieExW failed: %u\n", GetLastError());
727 return HRESULT_FROM_WIN32(GetLastError());
731 if(!size) {
732 *p = NULL;
733 return S_OK;
736 *p = SysAllocStringLen(NULL, size/sizeof(WCHAR)-1);
737 if(!*p)
738 return E_OUTOFMEMORY;
740 bret = InternetGetCookieExW(This->window->url, NULL, *p, &size, 0, NULL);
741 if(!bret) {
742 ERR("InternetGetCookieExW failed: %u\n", GetLastError());
743 return E_FAIL;
746 return S_OK;
749 static HRESULT WINAPI HTMLDocument_put_expando(IHTMLDocument2 *iface, VARIANT_BOOL v)
751 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
752 FIXME("(%p)->(%x)\n", This, v);
753 return E_NOTIMPL;
756 static HRESULT WINAPI HTMLDocument_get_expando(IHTMLDocument2 *iface, VARIANT_BOOL *p)
758 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
759 FIXME("(%p)->(%p)\n", This, p);
760 return E_NOTIMPL;
763 static HRESULT WINAPI HTMLDocument_put_charset(IHTMLDocument2 *iface, BSTR v)
765 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
766 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
767 return E_NOTIMPL;
770 static HRESULT WINAPI HTMLDocument_get_charset(IHTMLDocument2 *iface, BSTR *p)
772 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
773 nsAString charset_str;
774 nsresult nsres;
776 TRACE("(%p)->(%p)\n", This, p);
778 if(!This->doc_node->nsdoc) {
779 FIXME("NULL nsdoc\n");
780 return E_FAIL;
783 nsAString_Init(&charset_str, NULL);
784 nsres = nsIDOMHTMLDocument_GetCharacterSet(This->doc_node->nsdoc, &charset_str);
785 return return_nsstr(nsres, &charset_str, p);
788 static HRESULT WINAPI HTMLDocument_put_defaultCharset(IHTMLDocument2 *iface, BSTR v)
790 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
791 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
792 return E_NOTIMPL;
795 static HRESULT WINAPI HTMLDocument_get_defaultCharset(IHTMLDocument2 *iface, BSTR *p)
797 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
798 FIXME("(%p)->(%p)\n", This, p);
799 return E_NOTIMPL;
802 static HRESULT WINAPI HTMLDocument_get_mimeType(IHTMLDocument2 *iface, BSTR *p)
804 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
805 FIXME("(%p)->(%p)\n", This, p);
806 return E_NOTIMPL;
809 static HRESULT WINAPI HTMLDocument_get_fileSize(IHTMLDocument2 *iface, BSTR *p)
811 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
812 FIXME("(%p)->(%p)\n", This, p);
813 return E_NOTIMPL;
816 static HRESULT WINAPI HTMLDocument_get_fileCreatedDate(IHTMLDocument2 *iface, BSTR *p)
818 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
819 FIXME("(%p)->(%p)\n", This, p);
820 return E_NOTIMPL;
823 static HRESULT WINAPI HTMLDocument_get_fileModifiedDate(IHTMLDocument2 *iface, BSTR *p)
825 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
826 FIXME("(%p)->(%p)\n", This, p);
827 return E_NOTIMPL;
830 static HRESULT WINAPI HTMLDocument_get_fileUpdatedDate(IHTMLDocument2 *iface, BSTR *p)
832 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
833 FIXME("(%p)->(%p)\n", This, p);
834 return E_NOTIMPL;
837 static HRESULT WINAPI HTMLDocument_get_security(IHTMLDocument2 *iface, BSTR *p)
839 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
840 FIXME("(%p)->(%p)\n", This, p);
841 return E_NOTIMPL;
844 static HRESULT WINAPI HTMLDocument_get_protocol(IHTMLDocument2 *iface, BSTR *p)
846 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
847 FIXME("(%p)->(%p)\n", This, p);
848 return E_NOTIMPL;
851 static HRESULT WINAPI HTMLDocument_get_nameProp(IHTMLDocument2 *iface, BSTR *p)
853 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
854 FIXME("(%p)->(%p)\n", This, p);
855 return E_NOTIMPL;
858 static HRESULT document_write(HTMLDocument *This, SAFEARRAY *psarray, BOOL ln)
860 VARIANT *var, tmp;
861 JSContext *jsctx;
862 nsAString nsstr;
863 ULONG i, argc;
864 nsresult nsres;
865 HRESULT hres;
867 if(!This->doc_node->nsdoc) {
868 WARN("NULL nsdoc\n");
869 return E_UNEXPECTED;
872 if (!psarray)
873 return S_OK;
875 if(psarray->cDims != 1) {
876 FIXME("cDims=%d\n", psarray->cDims);
877 return E_INVALIDARG;
880 hres = SafeArrayAccessData(psarray, (void**)&var);
881 if(FAILED(hres)) {
882 WARN("SafeArrayAccessData failed: %08x\n", hres);
883 return hres;
886 V_VT(&tmp) = VT_EMPTY;
888 jsctx = get_context_from_document(This->doc_node->nsdoc);
889 argc = psarray->rgsabound[0].cElements;
890 for(i=0; i < argc; i++) {
891 if(V_VT(var+i) == VT_BSTR) {
892 nsAString_InitDepend(&nsstr, V_BSTR(var+i));
893 }else {
894 hres = VariantChangeTypeEx(&tmp, var+i, MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT), 0, VT_BSTR);
895 if(FAILED(hres)) {
896 WARN("Could not convert %s to string\n", debugstr_variant(var+i));
897 break;
899 nsAString_InitDepend(&nsstr, V_BSTR(&tmp));
902 if(!ln || i != argc-1)
903 nsres = nsIDOMHTMLDocument_Write(This->doc_node->nsdoc, &nsstr, jsctx);
904 else
905 nsres = nsIDOMHTMLDocument_Writeln(This->doc_node->nsdoc, &nsstr, jsctx);
906 nsAString_Finish(&nsstr);
907 if(V_VT(var+i) != VT_BSTR)
908 VariantClear(&tmp);
909 if(NS_FAILED(nsres)) {
910 ERR("Write failed: %08x\n", nsres);
911 hres = E_FAIL;
912 break;
916 SafeArrayUnaccessData(psarray);
918 return hres;
921 static HRESULT WINAPI HTMLDocument_write(IHTMLDocument2 *iface, SAFEARRAY *psarray)
923 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
925 TRACE("(%p)->(%p)\n", iface, psarray);
927 return document_write(This, psarray, FALSE);
930 static HRESULT WINAPI HTMLDocument_writeln(IHTMLDocument2 *iface, SAFEARRAY *psarray)
932 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
934 TRACE("(%p)->(%p)\n", This, psarray);
936 return document_write(This, psarray, TRUE);
939 static HRESULT WINAPI HTMLDocument_open(IHTMLDocument2 *iface, BSTR url, VARIANT name,
940 VARIANT features, VARIANT replace, IDispatch **pomWindowResult)
942 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
943 nsISupports *tmp;
944 nsresult nsres;
946 static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};
948 TRACE("(%p)->(%s %s %s %s %p)\n", This, debugstr_w(url), debugstr_variant(&name),
949 debugstr_variant(&features), debugstr_variant(&replace), pomWindowResult);
951 if(!This->doc_node->nsdoc) {
952 ERR("!nsdoc\n");
953 return E_NOTIMPL;
956 if(!url || strcmpW(url, text_htmlW) || V_VT(&name) != VT_ERROR
957 || V_VT(&features) != VT_ERROR || V_VT(&replace) != VT_ERROR)
958 FIXME("unsupported args\n");
960 nsres = nsIDOMHTMLDocument_Open(This->doc_node->nsdoc, NULL, NULL, NULL,
961 get_context_from_document(This->doc_node->nsdoc), 0, &tmp);
962 if(NS_FAILED(nsres)) {
963 ERR("Open failed: %08x\n", nsres);
964 return E_FAIL;
967 if(tmp)
968 nsISupports_Release(tmp);
970 *pomWindowResult = (IDispatch*)&This->window->base.IHTMLWindow2_iface;
971 IHTMLWindow2_AddRef(&This->window->base.IHTMLWindow2_iface);
972 return S_OK;
975 static HRESULT WINAPI HTMLDocument_close(IHTMLDocument2 *iface)
977 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
978 nsresult nsres;
980 TRACE("(%p)\n", This);
982 if(!This->doc_node->nsdoc) {
983 ERR("!nsdoc\n");
984 return E_NOTIMPL;
987 nsres = nsIDOMHTMLDocument_Close(This->doc_node->nsdoc);
988 if(NS_FAILED(nsres)) {
989 ERR("Close failed: %08x\n", nsres);
990 return E_FAIL;
993 return S_OK;
996 static HRESULT WINAPI HTMLDocument_clear(IHTMLDocument2 *iface)
998 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
999 nsresult nsres;
1001 TRACE("(%p)\n", This);
1003 nsres = nsIDOMHTMLDocument_Clear(This->doc_node->nsdoc);
1004 if(NS_FAILED(nsres)) {
1005 ERR("Clear failed: %08x\n", nsres);
1006 return E_FAIL;
1009 return S_OK;
1012 static HRESULT WINAPI HTMLDocument_queryCommandSupported(IHTMLDocument2 *iface, BSTR cmdID,
1013 VARIANT_BOOL *pfRet)
1015 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1016 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1017 return E_NOTIMPL;
1020 static HRESULT WINAPI HTMLDocument_queryCommandEnabled(IHTMLDocument2 *iface, BSTR cmdID,
1021 VARIANT_BOOL *pfRet)
1023 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1024 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1025 return E_NOTIMPL;
1028 static HRESULT WINAPI HTMLDocument_queryCommandState(IHTMLDocument2 *iface, BSTR cmdID,
1029 VARIANT_BOOL *pfRet)
1031 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1032 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1033 return E_NOTIMPL;
1036 static HRESULT WINAPI HTMLDocument_queryCommandIndeterm(IHTMLDocument2 *iface, BSTR cmdID,
1037 VARIANT_BOOL *pfRet)
1039 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1040 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1041 return E_NOTIMPL;
1044 static HRESULT WINAPI HTMLDocument_queryCommandText(IHTMLDocument2 *iface, BSTR cmdID,
1045 BSTR *pfRet)
1047 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1048 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1049 return E_NOTIMPL;
1052 static HRESULT WINAPI HTMLDocument_queryCommandValue(IHTMLDocument2 *iface, BSTR cmdID,
1053 VARIANT *pfRet)
1055 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1056 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1057 return E_NOTIMPL;
1060 static HRESULT WINAPI HTMLDocument_execCommand(IHTMLDocument2 *iface, BSTR cmdID,
1061 VARIANT_BOOL showUI, VARIANT value, VARIANT_BOOL *pfRet)
1063 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1064 FIXME("(%p)->(%s %x %s %p)\n", This, debugstr_w(cmdID), showUI, debugstr_variant(&value), pfRet);
1065 return E_NOTIMPL;
1068 static HRESULT WINAPI HTMLDocument_execCommandShowHelp(IHTMLDocument2 *iface, BSTR cmdID,
1069 VARIANT_BOOL *pfRet)
1071 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1072 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1073 return E_NOTIMPL;
1076 static HRESULT WINAPI HTMLDocument_createElement(IHTMLDocument2 *iface, BSTR eTag,
1077 IHTMLElement **newElem)
1079 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1080 HTMLElement *elem;
1081 HRESULT hres;
1083 TRACE("(%p)->(%s %p)\n", This, debugstr_w(eTag), newElem);
1085 hres = create_element(This->doc_node, eTag, &elem);
1086 if(FAILED(hres))
1087 return hres;
1089 *newElem = &elem->IHTMLElement_iface;
1090 return S_OK;
1093 static HRESULT WINAPI HTMLDocument_put_onhelp(IHTMLDocument2 *iface, VARIANT v)
1095 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1096 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1097 return E_NOTIMPL;
1100 static HRESULT WINAPI HTMLDocument_get_onhelp(IHTMLDocument2 *iface, VARIANT *p)
1102 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1103 FIXME("(%p)->(%p)\n", This, p);
1104 return E_NOTIMPL;
1107 static HRESULT WINAPI HTMLDocument_put_onclick(IHTMLDocument2 *iface, VARIANT v)
1109 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1111 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1113 return set_doc_event(This, EVENTID_CLICK, &v);
1116 static HRESULT WINAPI HTMLDocument_get_onclick(IHTMLDocument2 *iface, VARIANT *p)
1118 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1120 TRACE("(%p)->(%p)\n", This, p);
1122 return get_doc_event(This, EVENTID_CLICK, p);
1125 static HRESULT WINAPI HTMLDocument_put_ondblclick(IHTMLDocument2 *iface, VARIANT v)
1127 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1128 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1129 return E_NOTIMPL;
1132 static HRESULT WINAPI HTMLDocument_get_ondblclick(IHTMLDocument2 *iface, VARIANT *p)
1134 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1135 FIXME("(%p)->(%p)\n", This, p);
1136 return E_NOTIMPL;
1139 static HRESULT WINAPI HTMLDocument_put_onkeyup(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_KEYUP, &v);
1148 static HRESULT WINAPI HTMLDocument_get_onkeyup(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_KEYUP, p);
1157 static HRESULT WINAPI HTMLDocument_put_onkeydown(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_KEYDOWN, &v);
1166 static HRESULT WINAPI HTMLDocument_get_onkeydown(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_KEYDOWN, p);
1175 static HRESULT WINAPI HTMLDocument_put_onkeypress(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_KEYPRESS, &v);
1184 static HRESULT WINAPI HTMLDocument_get_onkeypress(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_KEYPRESS, p);
1193 static HRESULT WINAPI HTMLDocument_put_onmouseup(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_MOUSEUP, &v);
1202 static HRESULT WINAPI HTMLDocument_get_onmouseup(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_MOUSEUP, p);
1211 static HRESULT WINAPI HTMLDocument_put_onmousedown(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_MOUSEDOWN, &v);
1220 static HRESULT WINAPI HTMLDocument_get_onmousedown(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_MOUSEDOWN, p);
1229 static HRESULT WINAPI HTMLDocument_put_onmousemove(IHTMLDocument2 *iface, VARIANT v)
1231 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1233 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1235 return set_doc_event(This, EVENTID_MOUSEMOVE, &v);
1238 static HRESULT WINAPI HTMLDocument_get_onmousemove(IHTMLDocument2 *iface, VARIANT *p)
1240 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1242 TRACE("(%p)->(%p)\n", This, p);
1244 return get_doc_event(This, EVENTID_MOUSEMOVE, p);
1247 static HRESULT WINAPI HTMLDocument_put_onmouseout(IHTMLDocument2 *iface, VARIANT v)
1249 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1251 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1253 return set_doc_event(This, EVENTID_MOUSEOUT, &v);
1256 static HRESULT WINAPI HTMLDocument_get_onmouseout(IHTMLDocument2 *iface, VARIANT *p)
1258 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1260 TRACE("(%p)->(%p)\n", This, p);
1262 return get_doc_event(This, EVENTID_MOUSEOUT, p);
1265 static HRESULT WINAPI HTMLDocument_put_onmouseover(IHTMLDocument2 *iface, VARIANT v)
1267 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1269 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1271 return set_doc_event(This, EVENTID_MOUSEOVER, &v);
1274 static HRESULT WINAPI HTMLDocument_get_onmouseover(IHTMLDocument2 *iface, VARIANT *p)
1276 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1278 TRACE("(%p)->(%p)\n", This, p);
1280 return get_doc_event(This, EVENTID_MOUSEOVER, p);
1283 static HRESULT WINAPI HTMLDocument_put_onreadystatechange(IHTMLDocument2 *iface, VARIANT v)
1285 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1287 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1289 return set_doc_event(This, EVENTID_READYSTATECHANGE, &v);
1292 static HRESULT WINAPI HTMLDocument_get_onreadystatechange(IHTMLDocument2 *iface, VARIANT *p)
1294 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1296 TRACE("(%p)->(%p)\n", This, p);
1298 return get_doc_event(This, EVENTID_READYSTATECHANGE, p);
1301 static HRESULT WINAPI HTMLDocument_put_onafterupdate(IHTMLDocument2 *iface, VARIANT v)
1303 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1304 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1305 return E_NOTIMPL;
1308 static HRESULT WINAPI HTMLDocument_get_onafterupdate(IHTMLDocument2 *iface, VARIANT *p)
1310 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1311 FIXME("(%p)->(%p)\n", This, p);
1312 return E_NOTIMPL;
1315 static HRESULT WINAPI HTMLDocument_put_onrowexit(IHTMLDocument2 *iface, VARIANT v)
1317 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1318 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1319 return E_NOTIMPL;
1322 static HRESULT WINAPI HTMLDocument_get_onrowexit(IHTMLDocument2 *iface, VARIANT *p)
1324 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1325 FIXME("(%p)->(%p)\n", This, p);
1326 return E_NOTIMPL;
1329 static HRESULT WINAPI HTMLDocument_put_onrowenter(IHTMLDocument2 *iface, VARIANT v)
1331 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1332 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1333 return E_NOTIMPL;
1336 static HRESULT WINAPI HTMLDocument_get_onrowenter(IHTMLDocument2 *iface, VARIANT *p)
1338 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1339 FIXME("(%p)->(%p)\n", This, p);
1340 return E_NOTIMPL;
1343 static HRESULT WINAPI HTMLDocument_put_ondragstart(IHTMLDocument2 *iface, VARIANT v)
1345 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1347 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1349 return set_doc_event(This, EVENTID_DRAGSTART, &v);
1352 static HRESULT WINAPI HTMLDocument_get_ondragstart(IHTMLDocument2 *iface, VARIANT *p)
1354 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1356 TRACE("(%p)->(%p)\n", This, p);
1358 return get_doc_event(This, EVENTID_DRAGSTART, p);
1361 static HRESULT WINAPI HTMLDocument_put_onselectstart(IHTMLDocument2 *iface, VARIANT v)
1363 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1365 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1367 return set_doc_event(This, EVENTID_SELECTSTART, &v);
1370 static HRESULT WINAPI HTMLDocument_get_onselectstart(IHTMLDocument2 *iface, VARIANT *p)
1372 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1374 TRACE("(%p)->(%p)\n", This, p);
1376 return get_doc_event(This, EVENTID_SELECTSTART, p);
1379 static HRESULT WINAPI HTMLDocument_elementFromPoint(IHTMLDocument2 *iface, LONG x, LONG y,
1380 IHTMLElement **elementHit)
1382 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1383 nsIDOMElement *nselem;
1384 HTMLDOMNode *node;
1385 nsresult nsres;
1386 HRESULT hres;
1388 TRACE("(%p)->(%d %d %p)\n", This, x, y, elementHit);
1390 nsres = nsIDOMHTMLDocument_ElementFromPoint(This->doc_node->nsdoc, x, y, &nselem);
1391 if(NS_FAILED(nsres)) {
1392 ERR("ElementFromPoint failed: %08x\n", nsres);
1393 return E_FAIL;
1396 if(!nselem) {
1397 *elementHit = NULL;
1398 return S_OK;
1401 hres = get_node(This->doc_node, (nsIDOMNode*)nselem, TRUE, &node);
1402 nsIDOMElement_Release(nselem);
1403 if(FAILED(hres))
1404 return hres;
1406 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)elementHit);
1407 node_release(node);
1408 return hres;
1411 static HRESULT WINAPI HTMLDocument_get_parentWindow(IHTMLDocument2 *iface, IHTMLWindow2 **p)
1413 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1415 TRACE("(%p)->(%p)\n", This, p);
1417 *p = &This->window->base.IHTMLWindow2_iface;
1418 IHTMLWindow2_AddRef(*p);
1419 return S_OK;
1422 static HRESULT WINAPI HTMLDocument_get_styleSheets(IHTMLDocument2 *iface,
1423 IHTMLStyleSheetsCollection **p)
1425 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1426 nsIDOMStyleSheetList *nsstylelist;
1427 nsresult nsres;
1429 TRACE("(%p)->(%p)\n", This, p);
1431 *p = NULL;
1433 if(!This->doc_node->nsdoc) {
1434 WARN("NULL nsdoc\n");
1435 return E_UNEXPECTED;
1438 nsres = nsIDOMHTMLDocument_GetStyleSheets(This->doc_node->nsdoc, &nsstylelist);
1439 if(NS_FAILED(nsres)) {
1440 ERR("GetStyleSheets failed: %08x\n", nsres);
1441 return E_FAIL;
1444 *p = HTMLStyleSheetsCollection_Create(nsstylelist);
1445 nsIDOMStyleSheetList_Release(nsstylelist);
1447 return S_OK;
1450 static HRESULT WINAPI HTMLDocument_put_onbeforeupdate(IHTMLDocument2 *iface, VARIANT v)
1452 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1453 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1454 return E_NOTIMPL;
1457 static HRESULT WINAPI HTMLDocument_get_onbeforeupdate(IHTMLDocument2 *iface, VARIANT *p)
1459 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1460 FIXME("(%p)->(%p)\n", This, p);
1461 return E_NOTIMPL;
1464 static HRESULT WINAPI HTMLDocument_put_onerrorupdate(IHTMLDocument2 *iface, VARIANT v)
1466 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1467 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1468 return E_NOTIMPL;
1471 static HRESULT WINAPI HTMLDocument_get_onerrorupdate(IHTMLDocument2 *iface, VARIANT *p)
1473 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1474 FIXME("(%p)->(%p)\n", This, p);
1475 return E_NOTIMPL;
1478 static HRESULT WINAPI HTMLDocument_toString(IHTMLDocument2 *iface, BSTR *String)
1480 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1481 FIXME("(%p)->(%p)\n", This, String);
1482 return E_NOTIMPL;
1485 static HRESULT WINAPI HTMLDocument_createStyleSheet(IHTMLDocument2 *iface, BSTR bstrHref,
1486 LONG lIndex, IHTMLStyleSheet **ppnewStyleSheet)
1488 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1489 nsIDOMHTMLHeadElement *head_elem;
1490 IHTMLStyleElement *style_elem;
1491 HTMLElement *elem;
1492 nsresult nsres;
1493 HRESULT hres;
1495 static const WCHAR styleW[] = {'s','t','y','l','e',0};
1497 TRACE("(%p)->(%s %d %p)\n", This, debugstr_w(bstrHref), lIndex, ppnewStyleSheet);
1499 if(!This->doc_node->nsdoc) {
1500 FIXME("not a real doc object\n");
1501 return E_NOTIMPL;
1504 if(lIndex != -1)
1505 FIXME("Unsupported lIndex %d\n", lIndex);
1507 if(bstrHref) {
1508 FIXME("semi-stub for href %s\n", debugstr_w(bstrHref));
1509 *ppnewStyleSheet = HTMLStyleSheet_Create(NULL);
1510 return S_OK;
1513 hres = create_element(This->doc_node, styleW, &elem);
1514 if(FAILED(hres))
1515 return hres;
1517 nsres = nsIDOMHTMLDocument_GetHead(This->doc_node->nsdoc, &head_elem);
1518 if(NS_SUCCEEDED(nsres)) {
1519 nsIDOMNode *tmp_node;
1521 nsres = nsIDOMHTMLHeadElement_AppendChild(head_elem, (nsIDOMNode*)elem->nselem, &tmp_node);
1522 nsIDOMHTMLHeadElement_Release(head_elem);
1523 if(NS_SUCCEEDED(nsres) && tmp_node)
1524 nsIDOMNode_Release(tmp_node);
1526 if(NS_FAILED(nsres)) {
1527 IHTMLElement_Release(&elem->IHTMLElement_iface);
1528 return E_FAIL;
1531 hres = IHTMLElement_QueryInterface(&elem->IHTMLElement_iface, &IID_IHTMLStyleElement, (void**)&style_elem);
1532 assert(hres == S_OK);
1533 IHTMLElement_Release(&elem->IHTMLElement_iface);
1535 hres = IHTMLStyleElement_get_styleSheet(style_elem, ppnewStyleSheet);
1536 IHTMLStyleElement_Release(style_elem);
1537 return hres;
1540 static const IHTMLDocument2Vtbl HTMLDocumentVtbl = {
1541 HTMLDocument_QueryInterface,
1542 HTMLDocument_AddRef,
1543 HTMLDocument_Release,
1544 HTMLDocument_GetTypeInfoCount,
1545 HTMLDocument_GetTypeInfo,
1546 HTMLDocument_GetIDsOfNames,
1547 HTMLDocument_Invoke,
1548 HTMLDocument_get_Script,
1549 HTMLDocument_get_all,
1550 HTMLDocument_get_body,
1551 HTMLDocument_get_activeElement,
1552 HTMLDocument_get_images,
1553 HTMLDocument_get_applets,
1554 HTMLDocument_get_links,
1555 HTMLDocument_get_forms,
1556 HTMLDocument_get_anchors,
1557 HTMLDocument_put_title,
1558 HTMLDocument_get_title,
1559 HTMLDocument_get_scripts,
1560 HTMLDocument_put_designMode,
1561 HTMLDocument_get_designMode,
1562 HTMLDocument_get_selection,
1563 HTMLDocument_get_readyState,
1564 HTMLDocument_get_frames,
1565 HTMLDocument_get_embeds,
1566 HTMLDocument_get_plugins,
1567 HTMLDocument_put_alinkColor,
1568 HTMLDocument_get_alinkColor,
1569 HTMLDocument_put_bgColor,
1570 HTMLDocument_get_bgColor,
1571 HTMLDocument_put_fgColor,
1572 HTMLDocument_get_fgColor,
1573 HTMLDocument_put_linkColor,
1574 HTMLDocument_get_linkColor,
1575 HTMLDocument_put_vlinkColor,
1576 HTMLDocument_get_vlinkColor,
1577 HTMLDocument_get_referrer,
1578 HTMLDocument_get_location,
1579 HTMLDocument_get_lastModified,
1580 HTMLDocument_put_URL,
1581 HTMLDocument_get_URL,
1582 HTMLDocument_put_domain,
1583 HTMLDocument_get_domain,
1584 HTMLDocument_put_cookie,
1585 HTMLDocument_get_cookie,
1586 HTMLDocument_put_expando,
1587 HTMLDocument_get_expando,
1588 HTMLDocument_put_charset,
1589 HTMLDocument_get_charset,
1590 HTMLDocument_put_defaultCharset,
1591 HTMLDocument_get_defaultCharset,
1592 HTMLDocument_get_mimeType,
1593 HTMLDocument_get_fileSize,
1594 HTMLDocument_get_fileCreatedDate,
1595 HTMLDocument_get_fileModifiedDate,
1596 HTMLDocument_get_fileUpdatedDate,
1597 HTMLDocument_get_security,
1598 HTMLDocument_get_protocol,
1599 HTMLDocument_get_nameProp,
1600 HTMLDocument_write,
1601 HTMLDocument_writeln,
1602 HTMLDocument_open,
1603 HTMLDocument_close,
1604 HTMLDocument_clear,
1605 HTMLDocument_queryCommandSupported,
1606 HTMLDocument_queryCommandEnabled,
1607 HTMLDocument_queryCommandState,
1608 HTMLDocument_queryCommandIndeterm,
1609 HTMLDocument_queryCommandText,
1610 HTMLDocument_queryCommandValue,
1611 HTMLDocument_execCommand,
1612 HTMLDocument_execCommandShowHelp,
1613 HTMLDocument_createElement,
1614 HTMLDocument_put_onhelp,
1615 HTMLDocument_get_onhelp,
1616 HTMLDocument_put_onclick,
1617 HTMLDocument_get_onclick,
1618 HTMLDocument_put_ondblclick,
1619 HTMLDocument_get_ondblclick,
1620 HTMLDocument_put_onkeyup,
1621 HTMLDocument_get_onkeyup,
1622 HTMLDocument_put_onkeydown,
1623 HTMLDocument_get_onkeydown,
1624 HTMLDocument_put_onkeypress,
1625 HTMLDocument_get_onkeypress,
1626 HTMLDocument_put_onmouseup,
1627 HTMLDocument_get_onmouseup,
1628 HTMLDocument_put_onmousedown,
1629 HTMLDocument_get_onmousedown,
1630 HTMLDocument_put_onmousemove,
1631 HTMLDocument_get_onmousemove,
1632 HTMLDocument_put_onmouseout,
1633 HTMLDocument_get_onmouseout,
1634 HTMLDocument_put_onmouseover,
1635 HTMLDocument_get_onmouseover,
1636 HTMLDocument_put_onreadystatechange,
1637 HTMLDocument_get_onreadystatechange,
1638 HTMLDocument_put_onafterupdate,
1639 HTMLDocument_get_onafterupdate,
1640 HTMLDocument_put_onrowexit,
1641 HTMLDocument_get_onrowexit,
1642 HTMLDocument_put_onrowenter,
1643 HTMLDocument_get_onrowenter,
1644 HTMLDocument_put_ondragstart,
1645 HTMLDocument_get_ondragstart,
1646 HTMLDocument_put_onselectstart,
1647 HTMLDocument_get_onselectstart,
1648 HTMLDocument_elementFromPoint,
1649 HTMLDocument_get_parentWindow,
1650 HTMLDocument_get_styleSheets,
1651 HTMLDocument_put_onbeforeupdate,
1652 HTMLDocument_get_onbeforeupdate,
1653 HTMLDocument_put_onerrorupdate,
1654 HTMLDocument_get_onerrorupdate,
1655 HTMLDocument_toString,
1656 HTMLDocument_createStyleSheet
1659 static void HTMLDocument_on_advise(IUnknown *iface, cp_static_data_t *cp)
1661 HTMLDocument *This = impl_from_IHTMLDocument2((IHTMLDocument2*)iface);
1663 if(This->window)
1664 update_cp_events(This->window->base.inner_window, &This->doc_node->node.event_target, cp, This->doc_node->node.nsnode);
1667 static inline HTMLDocument *impl_from_ISupportErrorInfo(ISupportErrorInfo *iface)
1669 return CONTAINING_RECORD(iface, HTMLDocument, ISupportErrorInfo_iface);
1672 static HRESULT WINAPI SupportErrorInfo_QueryInterface(ISupportErrorInfo *iface, REFIID riid, void **ppv)
1674 HTMLDocument *This = impl_from_ISupportErrorInfo(iface);
1675 return htmldoc_query_interface(This, riid, ppv);
1678 static ULONG WINAPI SupportErrorInfo_AddRef(ISupportErrorInfo *iface)
1680 HTMLDocument *This = impl_from_ISupportErrorInfo(iface);
1681 return htmldoc_addref(This);
1684 static ULONG WINAPI SupportErrorInfo_Release(ISupportErrorInfo *iface)
1686 HTMLDocument *This = impl_from_ISupportErrorInfo(iface);
1687 return htmldoc_release(This);
1690 static HRESULT WINAPI SupportErrorInfo_InterfaceSupportsErrorInfo(ISupportErrorInfo *iface, REFIID riid)
1692 FIXME("(%p)->(%s)\n", iface, debugstr_guid(riid));
1693 return S_FALSE;
1696 static const ISupportErrorInfoVtbl SupportErrorInfoVtbl = {
1697 SupportErrorInfo_QueryInterface,
1698 SupportErrorInfo_AddRef,
1699 SupportErrorInfo_Release,
1700 SupportErrorInfo_InterfaceSupportsErrorInfo
1703 static inline HTMLDocument *impl_from_IDispatchEx(IDispatchEx *iface)
1705 return CONTAINING_RECORD(iface, HTMLDocument, IDispatchEx_iface);
1708 static HRESULT dispid_from_elem_name(HTMLDocumentNode *This, BSTR name, DISPID *dispid)
1710 nsIDOMNodeList *node_list;
1711 nsAString name_str;
1712 UINT32 len;
1713 unsigned i;
1714 nsresult nsres;
1716 if(!This->nsdoc)
1717 return DISP_E_UNKNOWNNAME;
1719 nsAString_InitDepend(&name_str, name);
1720 nsres = nsIDOMHTMLDocument_GetElementsByName(This->nsdoc, &name_str, &node_list);
1721 nsAString_Finish(&name_str);
1722 if(NS_FAILED(nsres))
1723 return E_FAIL;
1725 nsres = nsIDOMNodeList_GetLength(node_list, &len);
1726 nsIDOMNodeList_Release(node_list);
1727 if(NS_FAILED(nsres))
1728 return E_FAIL;
1730 if(!len)
1731 return DISP_E_UNKNOWNNAME;
1733 for(i=0; i < This->elem_vars_cnt; i++) {
1734 if(!strcmpW(name, This->elem_vars[i])) {
1735 *dispid = MSHTML_DISPID_CUSTOM_MIN+i;
1736 return S_OK;
1740 if(This->elem_vars_cnt == This->elem_vars_size) {
1741 WCHAR **new_vars;
1743 if(This->elem_vars_size) {
1744 new_vars = heap_realloc(This->elem_vars, This->elem_vars_size*2*sizeof(WCHAR*));
1745 if(!new_vars)
1746 return E_OUTOFMEMORY;
1747 This->elem_vars_size *= 2;
1748 }else {
1749 new_vars = heap_alloc(16*sizeof(WCHAR*));
1750 if(!new_vars)
1751 return E_OUTOFMEMORY;
1752 This->elem_vars_size = 16;
1755 This->elem_vars = new_vars;
1758 This->elem_vars[This->elem_vars_cnt] = heap_strdupW(name);
1759 if(!This->elem_vars[This->elem_vars_cnt])
1760 return E_OUTOFMEMORY;
1762 *dispid = MSHTML_DISPID_CUSTOM_MIN+This->elem_vars_cnt++;
1763 return S_OK;
1766 static HRESULT WINAPI DocDispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
1768 HTMLDocument *This = impl_from_IDispatchEx(iface);
1770 return htmldoc_query_interface(This, riid, ppv);
1773 static ULONG WINAPI DocDispatchEx_AddRef(IDispatchEx *iface)
1775 HTMLDocument *This = impl_from_IDispatchEx(iface);
1777 return htmldoc_addref(This);
1780 static ULONG WINAPI DocDispatchEx_Release(IDispatchEx *iface)
1782 HTMLDocument *This = impl_from_IDispatchEx(iface);
1784 return htmldoc_release(This);
1787 static HRESULT WINAPI DocDispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
1789 HTMLDocument *This = impl_from_IDispatchEx(iface);
1791 return IDispatchEx_GetTypeInfoCount(This->dispex, pctinfo);
1794 static HRESULT WINAPI DocDispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
1795 LCID lcid, ITypeInfo **ppTInfo)
1797 HTMLDocument *This = impl_from_IDispatchEx(iface);
1799 return IDispatchEx_GetTypeInfo(This->dispex, iTInfo, lcid, ppTInfo);
1802 static HRESULT WINAPI DocDispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
1803 LPOLESTR *rgszNames, UINT cNames,
1804 LCID lcid, DISPID *rgDispId)
1806 HTMLDocument *This = impl_from_IDispatchEx(iface);
1808 return IDispatchEx_GetIDsOfNames(This->dispex, riid, rgszNames, cNames, lcid, rgDispId);
1811 static HRESULT WINAPI DocDispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
1812 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1813 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1815 HTMLDocument *This = impl_from_IDispatchEx(iface);
1817 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1818 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1820 switch(dispIdMember) {
1821 case DISPID_READYSTATE:
1822 TRACE("DISPID_READYSTATE\n");
1824 if(!(wFlags & DISPATCH_PROPERTYGET))
1825 return E_INVALIDARG;
1827 V_VT(pVarResult) = VT_I4;
1828 V_I4(pVarResult) = This->window->readystate;
1829 return S_OK;
1832 return IDispatchEx_Invoke(This->dispex, dispIdMember, riid, lcid, wFlags, pDispParams,
1833 pVarResult, pExcepInfo, puArgErr);
1836 static HRESULT WINAPI DocDispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
1838 HTMLDocument *This = impl_from_IDispatchEx(iface);
1839 HRESULT hres;
1841 hres = IDispatchEx_GetDispID(This->dispex, bstrName, grfdex, pid);
1842 if(hres != DISP_E_UNKNOWNNAME)
1843 return hres;
1845 return dispid_from_elem_name(This->doc_node, bstrName, pid);
1848 static HRESULT WINAPI DocDispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1849 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1851 HTMLDocument *This = impl_from_IDispatchEx(iface);
1853 if(This->window && id == DISPID_IHTMLDOCUMENT2_LOCATION && (wFlags & DISPATCH_PROPERTYPUT))
1854 return IDispatchEx_InvokeEx(&This->window->base.IDispatchEx_iface, DISPID_IHTMLWINDOW2_LOCATION,
1855 lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1858 return IDispatchEx_InvokeEx(This->dispex, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1861 static HRESULT WINAPI DocDispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
1863 HTMLDocument *This = impl_from_IDispatchEx(iface);
1865 return IDispatchEx_DeleteMemberByName(This->dispex, bstrName, grfdex);
1868 static HRESULT WINAPI DocDispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
1870 HTMLDocument *This = impl_from_IDispatchEx(iface);
1872 return IDispatchEx_DeleteMemberByDispID(This->dispex, id);
1875 static HRESULT WINAPI DocDispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
1877 HTMLDocument *This = impl_from_IDispatchEx(iface);
1879 return IDispatchEx_GetMemberProperties(This->dispex, id, grfdexFetch, pgrfdex);
1882 static HRESULT WINAPI DocDispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
1884 HTMLDocument *This = impl_from_IDispatchEx(iface);
1886 return IDispatchEx_GetMemberName(This->dispex, id, pbstrName);
1889 static HRESULT WINAPI DocDispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
1891 HTMLDocument *This = impl_from_IDispatchEx(iface);
1893 return IDispatchEx_GetNextDispID(This->dispex, grfdex, id, pid);
1896 static HRESULT WINAPI DocDispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
1898 HTMLDocument *This = impl_from_IDispatchEx(iface);
1900 return IDispatchEx_GetNameSpaceParent(This->dispex, ppunk);
1903 static const IDispatchExVtbl DocDispatchExVtbl = {
1904 DocDispatchEx_QueryInterface,
1905 DocDispatchEx_AddRef,
1906 DocDispatchEx_Release,
1907 DocDispatchEx_GetTypeInfoCount,
1908 DocDispatchEx_GetTypeInfo,
1909 DocDispatchEx_GetIDsOfNames,
1910 DocDispatchEx_Invoke,
1911 DocDispatchEx_GetDispID,
1912 DocDispatchEx_InvokeEx,
1913 DocDispatchEx_DeleteMemberByName,
1914 DocDispatchEx_DeleteMemberByDispID,
1915 DocDispatchEx_GetMemberProperties,
1916 DocDispatchEx_GetMemberName,
1917 DocDispatchEx_GetNextDispID,
1918 DocDispatchEx_GetNameSpaceParent
1921 static inline HTMLDocument *impl_from_IProvideClassInfo(IProvideClassInfo *iface)
1923 return CONTAINING_RECORD(iface, HTMLDocument, IProvideClassInfo_iface);
1926 static HRESULT WINAPI ProvideClassInfo_QueryInterface(IProvideClassInfo *iface,
1927 REFIID riid, void **ppv)
1929 HTMLDocument *This = impl_from_IProvideClassInfo(iface);
1930 return htmldoc_query_interface(This, riid, ppv);
1933 static ULONG WINAPI ProvideClassInfo_AddRef(IProvideClassInfo *iface)
1935 HTMLDocument *This = impl_from_IProvideClassInfo(iface);
1936 return htmldoc_addref(This);
1939 static ULONG WINAPI ProvideClassInfo_Release(IProvideClassInfo *iface)
1941 HTMLDocument *This = impl_from_IProvideClassInfo(iface);
1942 return htmldoc_release(This);
1945 static HRESULT WINAPI ProvideClassInfo_GetClassInfo(IProvideClassInfo* iface,
1946 ITypeInfo **ppTI)
1948 HTMLDocument *This = impl_from_IProvideClassInfo(iface);
1949 TRACE("(%p)->(%p)\n", This, ppTI);
1950 return get_htmldoc_classinfo(ppTI);
1953 static const IProvideClassInfoVtbl ProvideClassInfoVtbl = {
1954 ProvideClassInfo_QueryInterface,
1955 ProvideClassInfo_AddRef,
1956 ProvideClassInfo_Release,
1957 ProvideClassInfo_GetClassInfo
1960 static BOOL htmldoc_qi(HTMLDocument *This, REFIID riid, void **ppv)
1962 *ppv = NULL;
1964 if(IsEqualGUID(&IID_IUnknown, riid)) {
1965 TRACE("(%p)->(IID_IUnknown, %p)\n", This, ppv);
1966 *ppv = &This->IHTMLDocument2_iface;
1967 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1968 TRACE("(%p)->(IID_IDispatch, %p)\n", This, ppv);
1969 *ppv = &This->IDispatchEx_iface;
1970 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
1971 TRACE("(%p)->(IID_IDispatchEx, %p)\n", This, ppv);
1972 *ppv = &This->IDispatchEx_iface;
1973 }else if(IsEqualGUID(&IID_IHTMLDocument, riid)) {
1974 TRACE("(%p)->(IID_IHTMLDocument, %p)\n", This, ppv);
1975 *ppv = &This->IHTMLDocument2_iface;
1976 }else if(IsEqualGUID(&IID_IHTMLDocument2, riid)) {
1977 TRACE("(%p)->(IID_IHTMLDocument2, %p)\n", This, ppv);
1978 *ppv = &This->IHTMLDocument2_iface;
1979 }else if(IsEqualGUID(&IID_IHTMLDocument3, riid)) {
1980 TRACE("(%p)->(IID_IHTMLDocument3, %p)\n", This, ppv);
1981 *ppv = &This->IHTMLDocument3_iface;
1982 }else if(IsEqualGUID(&IID_IHTMLDocument4, riid)) {
1983 TRACE("(%p)->(IID_IHTMLDocument4, %p)\n", This, ppv);
1984 *ppv = &This->IHTMLDocument4_iface;
1985 }else if(IsEqualGUID(&IID_IHTMLDocument5, riid)) {
1986 TRACE("(%p)->(IID_IHTMLDocument5, %p)\n", This, ppv);
1987 *ppv = &This->IHTMLDocument5_iface;
1988 }else if(IsEqualGUID(&IID_IHTMLDocument6, riid)) {
1989 TRACE("(%p)->(IID_IHTMLDocument6, %p)\n", This, ppv);
1990 *ppv = &This->IHTMLDocument6_iface;
1991 }else if(IsEqualGUID(&IID_IPersist, riid)) {
1992 TRACE("(%p)->(IID_IPersist, %p)\n", This, ppv);
1993 *ppv = &This->IPersistFile_iface;
1994 }else if(IsEqualGUID(&IID_IPersistMoniker, riid)) {
1995 TRACE("(%p)->(IID_IPersistMoniker, %p)\n", This, ppv);
1996 *ppv = &This->IPersistMoniker_iface;
1997 }else if(IsEqualGUID(&IID_IPersistFile, riid)) {
1998 TRACE("(%p)->(IID_IPersistFile, %p)\n", This, ppv);
1999 *ppv = &This->IPersistFile_iface;
2000 }else if(IsEqualGUID(&IID_IMonikerProp, riid)) {
2001 TRACE("(%p)->(IID_IMonikerProp, %p)\n", This, ppv);
2002 *ppv = &This->IMonikerProp_iface;
2003 }else if(IsEqualGUID(&IID_IOleObject, riid)) {
2004 TRACE("(%p)->(IID_IOleObject, %p)\n", This, ppv);
2005 *ppv = &This->IOleObject_iface;
2006 }else if(IsEqualGUID(&IID_IOleDocument, riid)) {
2007 TRACE("(%p)->(IID_IOleDocument, %p)\n", This, ppv);
2008 *ppv = &This->IOleDocument_iface;
2009 }else if(IsEqualGUID(&IID_IOleDocumentView, riid)) {
2010 TRACE("(%p)->(IID_IOleDocumentView, %p)\n", This, ppv);
2011 *ppv = &This->IOleDocumentView_iface;
2012 }else if(IsEqualGUID(&IID_IOleInPlaceActiveObject, riid)) {
2013 TRACE("(%p)->(IID_IOleInPlaceActiveObject, %p)\n", This, ppv);
2014 *ppv = &This->IOleInPlaceActiveObject_iface;
2015 }else if(IsEqualGUID(&IID_IViewObject, riid)) {
2016 TRACE("(%p)->(IID_IViewObject, %p)\n", This, ppv);
2017 *ppv = &This->IViewObjectEx_iface;
2018 }else if(IsEqualGUID(&IID_IViewObject2, riid)) {
2019 TRACE("(%p)->(IID_IViewObject2, %p)\n", This, ppv);
2020 *ppv = &This->IViewObjectEx_iface;
2021 }else if(IsEqualGUID(&IID_IViewObjectEx, riid)) {
2022 TRACE("(%p)->(IID_IViewObjectEx, %p)\n", This, ppv);
2023 *ppv = &This->IViewObjectEx_iface;
2024 }else if(IsEqualGUID(&IID_IOleWindow, riid)) {
2025 TRACE("(%p)->(IID_IOleWindow, %p)\n", This, ppv);
2026 *ppv = &This->IOleInPlaceActiveObject_iface;
2027 }else if(IsEqualGUID(&IID_IOleInPlaceObject, riid)) {
2028 TRACE("(%p)->(IID_IOleInPlaceObject, %p)\n", This, ppv);
2029 *ppv = &This->IOleInPlaceObjectWindowless_iface;
2030 }else if(IsEqualGUID(&IID_IOleInPlaceObjectWindowless, riid)) {
2031 TRACE("(%p)->(IID_IOleInPlaceObjectWindowless, %p)\n", This, ppv);
2032 *ppv = &This->IOleInPlaceObjectWindowless_iface;
2033 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
2034 TRACE("(%p)->(IID_IServiceProvider, %p)\n", This, ppv);
2035 *ppv = &This->IServiceProvider_iface;
2036 }else if(IsEqualGUID(&IID_IOleCommandTarget, riid)) {
2037 TRACE("(%p)->(IID_IOleCommandTarget, %p)\n", This, ppv);
2038 *ppv = &This->IOleCommandTarget_iface;
2039 }else if(IsEqualGUID(&IID_IOleControl, riid)) {
2040 TRACE("(%p)->(IID_IOleControl, %p)\n", This, ppv);
2041 *ppv = &This->IOleControl_iface;
2042 }else if(IsEqualGUID(&IID_IHlinkTarget, riid)) {
2043 TRACE("(%p)->(IID_IHlinkTarget, %p)\n", This, ppv);
2044 *ppv = &This->IHlinkTarget_iface;
2045 }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
2046 TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppv);
2047 *ppv = &This->cp_container.IConnectionPointContainer_iface;
2048 }else if(IsEqualGUID(&IID_IPersistStreamInit, riid)) {
2049 TRACE("(%p)->(IID_IPersistStreamInit %p)\n", This, ppv);
2050 *ppv = &This->IPersistStreamInit_iface;
2051 }else if(IsEqualGUID(&DIID_DispHTMLDocument, riid)) {
2052 TRACE("(%p)->(DIID_DispHTMLDocument %p)\n", This, ppv);
2053 *ppv = &This->IHTMLDocument2_iface;
2054 }else if(IsEqualGUID(&IID_ISupportErrorInfo, riid)) {
2055 TRACE("(%p)->(IID_ISupportErrorInfo %p)\n", This, ppv);
2056 *ppv = &This->ISupportErrorInfo_iface;
2057 }else if(IsEqualGUID(&IID_IPersistHistory, riid)) {
2058 TRACE("(%p)->(IID_IPersistHistory %p)\n", This, ppv);
2059 *ppv = &This->IPersistHistory_iface;
2060 }else if(IsEqualGUID(&CLSID_CMarkup, riid)) {
2061 FIXME("(%p)->(CLSID_CMarkup %p)\n", This, ppv);
2062 *ppv = NULL;
2063 }else if(IsEqualGUID(&IID_IRunnableObject, riid)) {
2064 TRACE("(%p)->(IID_IRunnableObject %p) returning NULL\n", This, ppv);
2065 *ppv = NULL;
2066 }else if(IsEqualGUID(&IID_IPersistPropertyBag, riid)) {
2067 TRACE("(%p)->(IID_IPersistPropertyBag %p) returning NULL\n", This, ppv);
2068 *ppv = NULL;
2069 }else if(IsEqualGUID(&IID_IMarshal, riid)) {
2070 TRACE("(%p)->(IID_IMarshal %p) returning NULL\n", This, ppv);
2071 *ppv = NULL;
2072 }else if(IsEqualGUID(&IID_IExternalConnection, riid)) {
2073 TRACE("(%p)->(IID_IExternalConnection %p) returning NULL\n", This, ppv);
2074 *ppv = NULL;
2075 }else if(IsEqualGUID(&IID_IStdMarshalInfo, riid)) {
2076 TRACE("(%p)->(IID_IStdMarshalInfo %p) returning NULL\n", This, ppv);
2077 *ppv = NULL;
2078 }else if(IsEqualGUID(&IID_IObjectWithSite, riid)) {
2079 TRACE("(%p)->(IID_IObjectWithSite %p)\n", This, ppv);
2080 *ppv = &This->IObjectWithSite_iface;
2081 }else if(IsEqualGUID(&IID_IOleContainer, riid)) {
2082 TRACE("(%p)->(IID_IOleContainer %p)\n", This, ppv);
2083 *ppv = &This->IOleContainer_iface;
2084 }else if(IsEqualGUID(&IID_IObjectSafety, riid)) {
2085 TRACE("(%p)->(IID_IObjectSafety %p)\n", This, ppv);
2086 *ppv = &This->IObjectSafety_iface;
2087 }else if(IsEqualGUID(&IID_IProvideClassInfo, riid)) {
2088 TRACE("(%p)->(IID_IProvideClassInfo, %p)\n", This, ppv);
2089 *ppv = &This->IProvideClassInfo_iface;
2090 }else {
2091 return FALSE;
2094 if(*ppv)
2095 IUnknown_AddRef((IUnknown*)*ppv);
2096 return TRUE;
2099 static cp_static_data_t HTMLDocumentEvents_data = { HTMLDocumentEvents_tid, HTMLDocument_on_advise };
2101 static const cpc_entry_t HTMLDocument_cpc[] = {
2102 {&IID_IDispatch, &HTMLDocumentEvents_data},
2103 {&IID_IPropertyNotifySink},
2104 {&DIID_HTMLDocumentEvents, &HTMLDocumentEvents_data},
2105 {&DIID_HTMLDocumentEvents2},
2106 {NULL}
2109 static void init_doc(HTMLDocument *doc, IUnknown *unk_impl, IDispatchEx *dispex)
2111 doc->IHTMLDocument2_iface.lpVtbl = &HTMLDocumentVtbl;
2112 doc->IDispatchEx_iface.lpVtbl = &DocDispatchExVtbl;
2113 doc->ISupportErrorInfo_iface.lpVtbl = &SupportErrorInfoVtbl;
2114 doc->IProvideClassInfo_iface.lpVtbl = &ProvideClassInfoVtbl;
2116 doc->unk_impl = unk_impl;
2117 doc->dispex = dispex;
2118 doc->task_magic = get_task_target_magic();
2120 HTMLDocument_HTMLDocument3_Init(doc);
2121 HTMLDocument_HTMLDocument5_Init(doc);
2122 HTMLDocument_Persist_Init(doc);
2123 HTMLDocument_OleCmd_Init(doc);
2124 HTMLDocument_OleObj_Init(doc);
2125 HTMLDocument_View_Init(doc);
2126 HTMLDocument_Window_Init(doc);
2127 HTMLDocument_Service_Init(doc);
2128 HTMLDocument_Hlink_Init(doc);
2130 ConnectionPointContainer_Init(&doc->cp_container, (IUnknown*)&doc->IHTMLDocument2_iface, HTMLDocument_cpc);
2133 static void destroy_htmldoc(HTMLDocument *This)
2135 remove_target_tasks(This->task_magic);
2137 ConnectionPointContainer_Destroy(&This->cp_container);
2140 static inline HTMLDocumentNode *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
2142 return CONTAINING_RECORD(iface, HTMLDocumentNode, node);
2145 static HRESULT HTMLDocumentNode_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
2147 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2149 if(htmldoc_qi(&This->basedoc, riid, ppv))
2150 return *ppv ? S_OK : E_NOINTERFACE;
2152 if(IsEqualGUID(&IID_IInternetHostSecurityManager, riid)) {
2153 TRACE("(%p)->(IID_IInternetHostSecurityManager %p)\n", This, ppv);
2154 *ppv = &This->IInternetHostSecurityManager_iface;
2155 }else {
2156 return HTMLDOMNode_QI(&This->node, riid, ppv);
2159 IUnknown_AddRef((IUnknown*)*ppv);
2160 return S_OK;
2163 static void HTMLDocumentNode_destructor(HTMLDOMNode *iface)
2165 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2166 unsigned i;
2168 for(i=0; i < This->elem_vars_cnt; i++)
2169 heap_free(This->elem_vars[i]);
2170 heap_free(This->elem_vars);
2172 detach_events(This);
2173 if(This->body_event_target)
2174 release_event_target(This->body_event_target);
2175 if(This->catmgr)
2176 ICatInformation_Release(This->catmgr);
2178 detach_selection(This);
2179 detach_ranges(This);
2181 while(!list_empty(&This->plugin_hosts))
2182 detach_plugin_host(LIST_ENTRY(list_head(&This->plugin_hosts), PluginHost, entry));
2184 if(This->nsnode_selector) {
2185 nsIDOMNodeSelector_Release(This->nsnode_selector);
2186 This->nsnode_selector = NULL;
2189 if(This->nsdoc) {
2190 assert(!This->window);
2191 release_document_mutation(This);
2192 nsIDOMHTMLDocument_Release(This->nsdoc);
2193 }else if(This->window) {
2194 /* document fragments own reference to inner window */
2195 IHTMLWindow2_Release(&This->window->base.IHTMLWindow2_iface);
2196 This->window = NULL;
2199 heap_free(This->event_vector);
2200 destroy_htmldoc(&This->basedoc);
2203 static HRESULT HTMLDocumentNode_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
2205 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2206 FIXME("%p\n", This);
2207 return E_NOTIMPL;
2210 static void HTMLDocumentNode_traverse(HTMLDOMNode *iface, nsCycleCollectionTraversalCallback *cb)
2212 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2214 if(This->nsnode_selector)
2215 note_cc_edge((nsISupports*)This->nsnode_selector, "This->nsnode_selector", cb);
2216 if(This->nsdoc)
2217 note_cc_edge((nsISupports*)This->nsdoc, "This->nsdoc", cb);
2220 static void HTMLDocumentNode_unlink(HTMLDOMNode *iface)
2222 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2224 if(This->nsnode_selector) {
2225 nsIDOMNodeSelector_Release(This->nsnode_selector);
2226 This->nsnode_selector = NULL;
2229 if(This->nsdoc) {
2230 nsIDOMHTMLDocument *nsdoc = This->nsdoc;
2232 release_document_mutation(This);
2233 This->nsdoc = NULL;
2234 nsIDOMHTMLDocument_Release(nsdoc);
2235 This->window = NULL;
2239 static const NodeImplVtbl HTMLDocumentNodeImplVtbl = {
2240 HTMLDocumentNode_QI,
2241 HTMLDocumentNode_destructor,
2242 HTMLDocument_cpc,
2243 HTMLDocumentNode_clone,
2244 NULL,
2245 NULL,
2246 NULL,
2247 NULL,
2248 NULL,
2249 NULL,
2250 NULL,
2251 NULL,
2252 NULL,
2253 NULL,
2254 NULL,
2255 HTMLDocumentNode_traverse,
2256 HTMLDocumentNode_unlink
2259 static HRESULT HTMLDocumentFragment_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
2261 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2262 HTMLDocumentNode *new_node;
2263 HRESULT hres;
2265 hres = create_document_fragment(nsnode, This->node.doc, &new_node);
2266 if(FAILED(hres))
2267 return hres;
2269 *ret = &new_node->node;
2270 return S_OK;
2273 static inline HTMLDocumentNode *impl_from_DispatchEx(DispatchEx *iface)
2275 return CONTAINING_RECORD(iface, HTMLDocumentNode, node.dispex);
2278 static HRESULT HTMLDocumentNode_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
2279 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2281 HTMLDocumentNode *This = impl_from_DispatchEx(dispex);
2282 nsIDOMNodeList *node_list;
2283 nsAString name_str;
2284 nsIDOMNode *nsnode;
2285 HTMLDOMNode *node;
2286 unsigned i;
2287 nsresult nsres;
2288 HRESULT hres;
2290 if(flags != DISPATCH_PROPERTYGET && flags != (DISPATCH_METHOD|DISPATCH_PROPERTYGET)) {
2291 FIXME("unsupported flags %x\n", flags);
2292 return E_NOTIMPL;
2295 i = id - MSHTML_DISPID_CUSTOM_MIN;
2297 if(!This->nsdoc || i >= This->elem_vars_cnt)
2298 return DISP_E_UNKNOWNNAME;
2300 nsAString_InitDepend(&name_str, This->elem_vars[i]);
2301 nsres = nsIDOMHTMLDocument_GetElementsByName(This->nsdoc, &name_str, &node_list);
2302 nsAString_Finish(&name_str);
2303 if(NS_FAILED(nsres))
2304 return E_FAIL;
2306 nsres = nsIDOMNodeList_Item(node_list, 0, &nsnode);
2307 nsIDOMNodeList_Release(node_list);
2308 if(NS_FAILED(nsres) || !nsnode)
2309 return DISP_E_UNKNOWNNAME;
2311 hres = get_node(This, nsnode, TRUE, &node);
2312 if(FAILED(hres))
2313 return hres;
2315 V_VT(res) = VT_DISPATCH;
2316 V_DISPATCH(res) = (IDispatch*)&node->IHTMLDOMNode_iface;
2317 return S_OK;
2321 static const dispex_static_data_vtbl_t HTMLDocumentNode_dispex_vtbl = {
2322 NULL,
2323 NULL,
2324 HTMLDocumentNode_invoke,
2325 NULL
2328 static const NodeImplVtbl HTMLDocumentFragmentImplVtbl = {
2329 HTMLDocumentNode_QI,
2330 HTMLDocumentNode_destructor,
2331 HTMLDocument_cpc,
2332 HTMLDocumentFragment_clone
2335 static const tid_t HTMLDocumentNode_iface_tids[] = {
2336 IHTMLDOMNode_tid,
2337 IHTMLDOMNode2_tid,
2338 IHTMLDocument2_tid,
2339 IHTMLDocument3_tid,
2340 IHTMLDocument4_tid,
2341 IHTMLDocument5_tid,
2345 static dispex_static_data_t HTMLDocumentNode_dispex = {
2346 &HTMLDocumentNode_dispex_vtbl,
2347 DispHTMLDocument_tid,
2348 NULL,
2349 HTMLDocumentNode_iface_tids
2352 static HTMLDocumentNode *alloc_doc_node(HTMLDocumentObj *doc_obj, HTMLInnerWindow *window)
2354 HTMLDocumentNode *doc;
2356 doc = heap_alloc_zero(sizeof(HTMLDocumentNode));
2357 if(!doc)
2358 return NULL;
2360 doc->ref = 1;
2361 doc->basedoc.doc_node = doc;
2362 doc->basedoc.doc_obj = doc_obj;
2363 doc->basedoc.window = window->base.outer_window;
2364 doc->window = window;
2366 init_dispex(&doc->node.dispex, (IUnknown*)&doc->node.IHTMLDOMNode_iface,
2367 &HTMLDocumentNode_dispex);
2368 init_doc(&doc->basedoc, (IUnknown*)&doc->node.IHTMLDOMNode_iface,
2369 &doc->node.dispex.IDispatchEx_iface);
2370 HTMLDocumentNode_SecMgr_Init(doc);
2372 list_init(&doc->selection_list);
2373 list_init(&doc->range_list);
2374 list_init(&doc->plugin_hosts);
2376 return doc;
2379 HRESULT create_doc_from_nsdoc(nsIDOMHTMLDocument *nsdoc, HTMLDocumentObj *doc_obj, HTMLInnerWindow *window, HTMLDocumentNode **ret)
2381 HTMLDocumentNode *doc;
2382 nsresult nsres;
2384 doc = alloc_doc_node(doc_obj, window);
2385 if(!doc)
2386 return E_OUTOFMEMORY;
2388 if(!doc_obj->basedoc.window || window->base.outer_window == doc_obj->basedoc.window)
2389 doc->basedoc.cp_container.forward_container = &doc_obj->basedoc.cp_container;
2391 HTMLDOMNode_Init(doc, &doc->node, (nsIDOMNode*)nsdoc);
2393 nsIDOMHTMLDocument_AddRef(nsdoc);
2394 doc->nsdoc = nsdoc;
2396 nsres = nsIDOMHTMLDocument_QueryInterface(nsdoc, &IID_nsIDOMNodeSelector, (void**)&doc->nsnode_selector);
2397 assert(nsres == NS_OK);
2399 init_document_mutation(doc);
2400 doc_init_events(doc);
2402 doc->node.vtbl = &HTMLDocumentNodeImplVtbl;
2403 doc->node.cp_container = &doc->basedoc.cp_container;
2405 *ret = doc;
2406 return S_OK;
2409 HRESULT create_document_fragment(nsIDOMNode *nsnode, HTMLDocumentNode *doc_node, HTMLDocumentNode **ret)
2411 HTMLDocumentNode *doc_frag;
2413 doc_frag = alloc_doc_node(doc_node->basedoc.doc_obj, doc_node->window);
2414 if(!doc_frag)
2415 return E_OUTOFMEMORY;
2417 IHTMLWindow2_AddRef(&doc_frag->window->base.IHTMLWindow2_iface);
2419 HTMLDOMNode_Init(doc_node, &doc_frag->node, nsnode);
2420 doc_frag->node.vtbl = &HTMLDocumentFragmentImplVtbl;
2421 doc_frag->node.cp_container = &doc_frag->basedoc.cp_container;
2423 *ret = doc_frag;
2424 return S_OK;
2427 /**********************************************************
2428 * ICustomDoc implementation
2431 static inline HTMLDocumentObj *impl_from_ICustomDoc(ICustomDoc *iface)
2433 return CONTAINING_RECORD(iface, HTMLDocumentObj, ICustomDoc_iface);
2436 static HRESULT WINAPI CustomDoc_QueryInterface(ICustomDoc *iface, REFIID riid, void **ppv)
2438 HTMLDocumentObj *This = impl_from_ICustomDoc(iface);
2440 if(htmldoc_qi(&This->basedoc, riid, ppv))
2441 return *ppv ? S_OK : E_NOINTERFACE;
2443 if(IsEqualGUID(&IID_ICustomDoc, riid)) {
2444 TRACE("(%p)->(IID_ICustomDoc %p)\n", This, ppv);
2445 *ppv = &This->ICustomDoc_iface;
2446 }else if(IsEqualGUID(&IID_ITargetContainer, riid)) {
2447 TRACE("(%p)->(IID_ITargetContainer %p)\n", This, ppv);
2448 *ppv = &This->ITargetContainer_iface;
2449 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
2450 return *ppv ? S_OK : E_NOINTERFACE;
2451 }else {
2452 FIXME("Unimplemented interface %s\n", debugstr_guid(riid));
2453 *ppv = NULL;
2454 return E_NOINTERFACE;
2457 IUnknown_AddRef((IUnknown*)*ppv);
2458 return S_OK;
2461 static ULONG WINAPI CustomDoc_AddRef(ICustomDoc *iface)
2463 HTMLDocumentObj *This = impl_from_ICustomDoc(iface);
2464 ULONG ref = InterlockedIncrement(&This->ref);
2466 TRACE("(%p) ref = %u\n", This, ref);
2468 return ref;
2471 static ULONG WINAPI CustomDoc_Release(ICustomDoc *iface)
2473 HTMLDocumentObj *This = impl_from_ICustomDoc(iface);
2474 ULONG ref = InterlockedDecrement(&This->ref);
2476 TRACE("(%p) ref = %u\n", This, ref);
2478 if(!ref) {
2479 nsIDOMWindowUtils *window_utils = NULL;
2481 if(This->basedoc.window && This->basedoc.window->nswindow)
2482 get_nsinterface((nsISupports*)This->basedoc.window->nswindow, &IID_nsIDOMWindowUtils, (void**)&window_utils);
2484 if(This->basedoc.doc_node) {
2485 This->basedoc.doc_node->basedoc.doc_obj = NULL;
2486 htmldoc_release(&This->basedoc.doc_node->basedoc);
2488 if(This->basedoc.window) {
2489 This->basedoc.window->doc_obj = NULL;
2490 IHTMLWindow2_Release(&This->basedoc.window->base.IHTMLWindow2_iface);
2492 if(This->basedoc.advise_holder)
2493 IOleAdviseHolder_Release(This->basedoc.advise_holder);
2495 if(This->view_sink)
2496 IAdviseSink_Release(This->view_sink);
2497 if(This->client)
2498 IOleObject_SetClientSite(&This->basedoc.IOleObject_iface, NULL);
2499 if(This->hostui)
2500 ICustomDoc_SetUIHandler(&This->ICustomDoc_iface, NULL);
2501 if(This->in_place_active)
2502 IOleInPlaceObjectWindowless_InPlaceDeactivate(&This->basedoc.IOleInPlaceObjectWindowless_iface);
2503 if(This->ipsite)
2504 IOleDocumentView_SetInPlaceSite(&This->basedoc.IOleDocumentView_iface, NULL);
2505 if(This->undomgr)
2506 IOleUndoManager_Release(This->undomgr);
2507 if(This->tooltips_hwnd)
2508 DestroyWindow(This->tooltips_hwnd);
2510 if(This->hwnd)
2511 DestroyWindow(This->hwnd);
2512 heap_free(This->mime);
2514 destroy_htmldoc(&This->basedoc);
2515 release_dispex(&This->dispex);
2517 if(This->nscontainer)
2518 NSContainer_Release(This->nscontainer);
2519 heap_free(This);
2521 /* Force cycle collection */
2522 if(window_utils) {
2523 nsIDOMWindowUtils_CycleCollect(window_utils, NULL, 0);
2524 nsIDOMWindowUtils_Release(window_utils);
2528 return ref;
2531 static HRESULT WINAPI CustomDoc_SetUIHandler(ICustomDoc *iface, IDocHostUIHandler *pUIHandler)
2533 HTMLDocumentObj *This = impl_from_ICustomDoc(iface);
2534 IOleCommandTarget *cmdtrg;
2535 HRESULT hres;
2537 TRACE("(%p)->(%p)\n", This, pUIHandler);
2539 if(This->custom_hostui && This->hostui == pUIHandler)
2540 return S_OK;
2542 This->custom_hostui = TRUE;
2544 if(This->hostui)
2545 IDocHostUIHandler_Release(This->hostui);
2546 if(pUIHandler)
2547 IDocHostUIHandler_AddRef(pUIHandler);
2548 This->hostui = pUIHandler;
2549 if(!pUIHandler)
2550 return S_OK;
2552 hres = IDocHostUIHandler_QueryInterface(pUIHandler, &IID_IOleCommandTarget, (void**)&cmdtrg);
2553 if(SUCCEEDED(hres)) {
2554 FIXME("custom UI handler supports IOleCommandTarget\n");
2555 IOleCommandTarget_Release(cmdtrg);
2558 return S_OK;
2561 static const ICustomDocVtbl CustomDocVtbl = {
2562 CustomDoc_QueryInterface,
2563 CustomDoc_AddRef,
2564 CustomDoc_Release,
2565 CustomDoc_SetUIHandler
2568 static const tid_t HTMLDocumentObj_iface_tids[] = {
2569 IHTMLDocument2_tid,
2570 IHTMLDocument3_tid,
2571 IHTMLDocument4_tid,
2572 IHTMLDocument5_tid,
2575 static dispex_static_data_t HTMLDocumentObj_dispex = {
2576 NULL,
2577 DispHTMLDocument_tid,
2578 NULL,
2579 HTMLDocumentObj_iface_tids
2582 HRESULT HTMLDocument_Create(IUnknown *pUnkOuter, REFIID riid, void** ppvObject)
2584 HTMLDocumentObj *doc;
2585 nsIDOMWindow *nswindow = NULL;
2586 nsresult nsres;
2587 HRESULT hres;
2589 TRACE("(%p %s %p)\n", pUnkOuter, debugstr_guid(riid), ppvObject);
2591 doc = heap_alloc_zero(sizeof(HTMLDocumentObj));
2592 if(!doc)
2593 return E_OUTOFMEMORY;
2595 init_dispex(&doc->dispex, (IUnknown*)&doc->ICustomDoc_iface, &HTMLDocumentObj_dispex);
2596 init_doc(&doc->basedoc, (IUnknown*)&doc->ICustomDoc_iface, &doc->dispex.IDispatchEx_iface);
2597 TargetContainer_Init(doc);
2599 doc->ICustomDoc_iface.lpVtbl = &CustomDocVtbl;
2600 doc->ref = 1;
2601 doc->basedoc.doc_obj = doc;
2603 doc->usermode = UNKNOWN_USERMODE;
2605 init_binding_ui(doc);
2607 hres = create_nscontainer(doc, &doc->nscontainer);
2608 if(FAILED(hres)) {
2609 ERR("Failed to init Gecko, returning CLASS_E_CLASSNOTAVAILABLE\n");
2610 htmldoc_release(&doc->basedoc);
2611 return hres;
2614 hres = htmldoc_query_interface(&doc->basedoc, riid, ppvObject);
2615 htmldoc_release(&doc->basedoc);
2616 if(FAILED(hres))
2617 return hres;
2619 nsres = nsIWebBrowser_GetContentDOMWindow(doc->nscontainer->webbrowser, &nswindow);
2620 if(NS_FAILED(nsres))
2621 ERR("GetContentDOMWindow failed: %08x\n", nsres);
2623 hres = HTMLOuterWindow_Create(doc, nswindow, NULL /* FIXME */, &doc->basedoc.window);
2624 if(nswindow)
2625 nsIDOMWindow_Release(nswindow);
2626 if(FAILED(hres)) {
2627 htmldoc_release(&doc->basedoc);
2628 return hres;
2631 if(!doc->basedoc.doc_node && doc->basedoc.window->base.inner_window->doc) {
2632 doc->basedoc.doc_node = doc->basedoc.window->base.inner_window->doc;
2633 htmldoc_addref(&doc->basedoc.doc_node->basedoc);
2636 get_thread_hwnd();
2638 return S_OK;