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
35 #include "wine/debug.h"
37 #include "mshtml_private.h"
38 #include "htmlevent.h"
39 #include "pluginhost.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,
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);
116 static HRESULT WINAPI HTMLDocument_get_all(IHTMLDocument2 *iface, IHTMLElementCollection **p)
118 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
119 nsIDOMElement *nselem = NULL;
124 TRACE("(%p)->(%p)\n", This, p);
126 if(!This->doc_node->nsdoc) {
127 WARN("NULL nsdoc\n");
131 nsres = nsIDOMHTMLDocument_GetDocumentElement(This->doc_node->nsdoc, &nselem);
132 if(NS_FAILED(nsres)) {
133 ERR("GetDocumentElement failed: %08x\n", nsres);
142 hres = get_node(This->doc_node, (nsIDOMNode*)nselem, TRUE, &node);
143 nsIDOMElement_Release(nselem);
147 *p = create_all_collection(node, TRUE);
152 static HRESULT WINAPI HTMLDocument_get_body(IHTMLDocument2 *iface, IHTMLElement **p)
154 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
155 nsIDOMHTMLElement *nsbody = NULL;
159 TRACE("(%p)->(%p)\n", This, p);
161 if(This->doc_node->nsdoc) {
164 nsres = nsIDOMHTMLDocument_GetBody(This->doc_node->nsdoc, &nsbody);
165 if(NS_FAILED(nsres)) {
166 TRACE("Could not get body: %08x\n", nsres);
176 hres = get_node(This->doc_node, (nsIDOMNode*)nsbody, TRUE, &node);
177 nsIDOMHTMLElement_Release(nsbody);
181 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)p);
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);
193 static HRESULT WINAPI HTMLDocument_get_images(IHTMLDocument2 *iface, IHTMLElementCollection **p)
195 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
196 nsIDOMHTMLCollection *nscoll = NULL;
199 TRACE("(%p)->(%p)\n", This, p);
206 if(!This->doc_node->nsdoc) {
207 WARN("NULL nsdoc\n");
211 nsres = nsIDOMHTMLDocument_GetImages(This->doc_node->nsdoc, &nscoll);
212 if(NS_FAILED(nsres)) {
213 ERR("GetImages failed: %08x\n", nsres);
218 *p = create_collection_from_htmlcol(This->doc_node, nscoll);
219 nsIDOMHTMLCollection_Release(nscoll);
225 static HRESULT WINAPI HTMLDocument_get_applets(IHTMLDocument2 *iface, IHTMLElementCollection **p)
227 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
228 nsIDOMHTMLCollection *nscoll = NULL;
231 TRACE("(%p)->(%p)\n", This, p);
238 if(!This->doc_node->nsdoc) {
239 WARN("NULL nsdoc\n");
243 nsres = nsIDOMHTMLDocument_GetApplets(This->doc_node->nsdoc, &nscoll);
244 if(NS_FAILED(nsres)) {
245 ERR("GetApplets failed: %08x\n", nsres);
250 *p = create_collection_from_htmlcol(This->doc_node, nscoll);
251 nsIDOMHTMLCollection_Release(nscoll);
257 static HRESULT WINAPI HTMLDocument_get_links(IHTMLDocument2 *iface, IHTMLElementCollection **p)
259 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
260 nsIDOMHTMLCollection *nscoll = NULL;
263 TRACE("(%p)->(%p)\n", This, p);
270 if(!This->doc_node->nsdoc) {
271 WARN("NULL nsdoc\n");
275 nsres = nsIDOMHTMLDocument_GetLinks(This->doc_node->nsdoc, &nscoll);
276 if(NS_FAILED(nsres)) {
277 ERR("GetLinks failed: %08x\n", nsres);
282 *p = create_collection_from_htmlcol(This->doc_node, nscoll);
283 nsIDOMHTMLCollection_Release(nscoll);
289 static HRESULT WINAPI HTMLDocument_get_forms(IHTMLDocument2 *iface, IHTMLElementCollection **p)
291 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
292 nsIDOMHTMLCollection *nscoll = NULL;
295 TRACE("(%p)->(%p)\n", This, p);
302 if(!This->doc_node->nsdoc) {
303 WARN("NULL nsdoc\n");
307 nsres = nsIDOMHTMLDocument_GetForms(This->doc_node->nsdoc, &nscoll);
308 if(NS_FAILED(nsres)) {
309 ERR("GetForms failed: %08x\n", nsres);
314 *p = create_collection_from_htmlcol(This->doc_node, nscoll);
315 nsIDOMHTMLCollection_Release(nscoll);
321 static HRESULT WINAPI HTMLDocument_get_anchors(IHTMLDocument2 *iface, IHTMLElementCollection **p)
323 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
324 nsIDOMHTMLCollection *nscoll = NULL;
327 TRACE("(%p)->(%p)\n", This, p);
334 if(!This->doc_node->nsdoc) {
335 WARN("NULL nsdoc\n");
339 nsres = nsIDOMHTMLDocument_GetAnchors(This->doc_node->nsdoc, &nscoll);
340 if(NS_FAILED(nsres)) {
341 ERR("GetAnchors failed: %08x\n", nsres);
346 *p = create_collection_from_htmlcol(This->doc_node, nscoll);
347 nsIDOMHTMLCollection_Release(nscoll);
353 static HRESULT WINAPI HTMLDocument_put_title(IHTMLDocument2 *iface, BSTR v)
355 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
359 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
361 if(!This->doc_node->nsdoc) {
362 WARN("NULL nsdoc\n");
366 nsAString_InitDepend(&nsstr, v);
367 nsres = nsIDOMHTMLDocument_SetTitle(This->doc_node->nsdoc, &nsstr);
368 nsAString_Finish(&nsstr);
370 ERR("SetTitle failed: %08x\n", nsres);
375 static HRESULT WINAPI HTMLDocument_get_title(IHTMLDocument2 *iface, BSTR *p)
377 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
378 const PRUnichar *ret;
382 TRACE("(%p)->(%p)\n", This, p);
384 if(!This->doc_node->nsdoc) {
385 WARN("NULL nsdoc\n");
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);
406 static HRESULT WINAPI HTMLDocument_get_scripts(IHTMLDocument2 *iface, IHTMLElementCollection **p)
408 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
409 FIXME("(%p)->(%p)\n", This, p);
413 static HRESULT WINAPI HTMLDocument_put_designMode(IHTMLDocument2 *iface, BSTR v)
415 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
418 static const WCHAR onW[] = {'o','n',0};
420 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
422 if(strcmpiW(v, onW)) {
423 FIXME("Unsupported arg %s\n", debugstr_w(v));
427 hres = setup_edit_mode(This->doc_obj);
431 call_property_onchanged(&This->cp_container, 1014);
435 static HRESULT WINAPI HTMLDocument_get_designMode(IHTMLDocument2 *iface, BSTR *p)
437 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
438 static WCHAR szOff[] = {'O','f','f',0};
439 FIXME("(%p)->(%p) always returning Off\n", This, p);
444 *p = SysAllocString(szOff);
449 static HRESULT WINAPI HTMLDocument_get_selection(IHTMLDocument2 *iface, IHTMLSelectionObject **p)
451 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
452 nsISelection *nsselection;
455 TRACE("(%p)->(%p)\n", This, p);
457 nsres = nsIDOMWindow_GetSelection(This->window->nswindow, &nsselection);
458 if(NS_FAILED(nsres)) {
459 ERR("GetSelection failed: %08x\n", nsres);
463 return HTMLSelectionObject_Create(This->doc_node, nsselection, p);
466 static HRESULT WINAPI HTMLDocument_get_readyState(IHTMLDocument2 *iface, BSTR *p)
468 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
470 static const WCHAR wszUninitialized[] = {'u','n','i','n','i','t','i','a','l','i','z','e','d',0};
471 static const WCHAR wszLoading[] = {'l','o','a','d','i','n','g',0};
472 static const WCHAR wszLoaded[] = {'l','o','a','d','e','d',0};
473 static const WCHAR wszInteractive[] = {'i','n','t','e','r','a','c','t','i','v','e',0};
474 static const WCHAR wszComplete[] = {'c','o','m','p','l','e','t','e',0};
476 static const LPCWSTR readystate_str[] = {
484 TRACE("(%p)->(%p)\n", iface, p);
489 *p = SysAllocString(readystate_str[This->window->readystate]);
493 static HRESULT WINAPI HTMLDocument_get_frames(IHTMLDocument2 *iface, IHTMLFramesCollection2 **p)
495 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
497 TRACE("(%p)->(%p)\n", This, p);
499 return IHTMLWindow2_get_frames(&This->window->base.IHTMLWindow2_iface, p);
502 static HRESULT WINAPI HTMLDocument_get_embeds(IHTMLDocument2 *iface, IHTMLElementCollection **p)
504 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
505 FIXME("(%p)->(%p)\n", This, p);
509 static HRESULT WINAPI HTMLDocument_get_plugins(IHTMLDocument2 *iface, IHTMLElementCollection **p)
511 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
512 FIXME("(%p)->(%p)\n", This, p);
516 static HRESULT WINAPI HTMLDocument_put_alinkColor(IHTMLDocument2 *iface, VARIANT v)
518 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
519 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
523 static HRESULT WINAPI HTMLDocument_get_alinkColor(IHTMLDocument2 *iface, VARIANT *p)
525 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
526 FIXME("(%p)->(%p)\n", This, p);
530 static HRESULT WINAPI HTMLDocument_put_bgColor(IHTMLDocument2 *iface, VARIANT v)
532 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
533 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
537 static HRESULT WINAPI HTMLDocument_get_bgColor(IHTMLDocument2 *iface, VARIANT *p)
539 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
540 FIXME("(%p)->(%p)\n", This, p);
544 static HRESULT WINAPI HTMLDocument_put_fgColor(IHTMLDocument2 *iface, VARIANT v)
546 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
547 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
551 static HRESULT WINAPI HTMLDocument_get_fgColor(IHTMLDocument2 *iface, VARIANT *p)
553 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
554 FIXME("(%p)->(%p)\n", This, p);
558 static HRESULT WINAPI HTMLDocument_put_linkColor(IHTMLDocument2 *iface, VARIANT v)
560 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
561 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
565 static HRESULT WINAPI HTMLDocument_get_linkColor(IHTMLDocument2 *iface, VARIANT *p)
567 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
568 FIXME("(%p)->(%p)\n", This, p);
572 static HRESULT WINAPI HTMLDocument_put_vlinkColor(IHTMLDocument2 *iface, VARIANT v)
574 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
575 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
579 static HRESULT WINAPI HTMLDocument_get_vlinkColor(IHTMLDocument2 *iface, VARIANT *p)
581 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
582 FIXME("(%p)->(%p)\n", This, p);
586 static HRESULT WINAPI HTMLDocument_get_referrer(IHTMLDocument2 *iface, BSTR *p)
588 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
590 FIXME("(%p)->(%p)\n", This, p);
596 static HRESULT WINAPI HTMLDocument_get_location(IHTMLDocument2 *iface, IHTMLLocation **p)
598 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
600 TRACE("(%p)->(%p)\n", This, p);
602 if(!This->doc_node->nsdoc) {
603 WARN("NULL nsdoc\n");
607 return IHTMLWindow2_get_location(&This->window->base.IHTMLWindow2_iface, p);
610 static HRESULT WINAPI HTMLDocument_get_lastModified(IHTMLDocument2 *iface, BSTR *p)
612 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
613 FIXME("(%p)->(%p)\n", This, p);
617 static HRESULT WINAPI HTMLDocument_put_URL(IHTMLDocument2 *iface, BSTR v)
619 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
621 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
624 FIXME("No window available\n");
628 return navigate_url(This->window, v, This->window->uri, BINDING_NAVIGATED);
631 static HRESULT WINAPI HTMLDocument_get_URL(IHTMLDocument2 *iface, BSTR *p)
633 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
635 static const WCHAR about_blank_url[] =
636 {'a','b','o','u','t',':','b','l','a','n','k',0};
638 TRACE("(%p)->(%p)\n", iface, p);
640 *p = SysAllocString(This->window->url ? This->window->url : about_blank_url);
641 return *p ? S_OK : E_OUTOFMEMORY;
644 static HRESULT WINAPI HTMLDocument_put_domain(IHTMLDocument2 *iface, BSTR v)
646 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
647 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
651 static HRESULT WINAPI HTMLDocument_get_domain(IHTMLDocument2 *iface, BSTR *p)
653 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
656 TRACE("(%p)->(%p)\n", This, p);
658 if(!This->window || !This->window->uri) {
659 FIXME("No current URI\n");
663 hres = IUri_GetHost(This->window->uri, p);
664 return FAILED(hres) ? hres : S_OK;
667 static HRESULT WINAPI HTMLDocument_put_cookie(IHTMLDocument2 *iface, BSTR v)
669 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
672 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
674 bret = InternetSetCookieExW(This->window->url, NULL, v, 0, 0);
676 FIXME("InternetSetCookieExW failed: %u\n", GetLastError());
677 return HRESULT_FROM_WIN32(GetLastError());
683 static HRESULT WINAPI HTMLDocument_get_cookie(IHTMLDocument2 *iface, BSTR *p)
685 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
689 TRACE("(%p)->(%p)\n", This, p);
692 bret = InternetGetCookieExW(This->window->url, NULL, NULL, &size, 0, NULL);
694 switch(GetLastError()) {
695 case ERROR_INSUFFICIENT_BUFFER:
697 case ERROR_NO_MORE_ITEMS:
701 FIXME("InternetGetCookieExW failed: %u\n", GetLastError());
702 return HRESULT_FROM_WIN32(GetLastError());
711 *p = SysAllocStringLen(NULL, size-1);
713 return E_OUTOFMEMORY;
715 bret = InternetGetCookieExW(This->window->url, NULL, *p, &size, 0, NULL);
717 ERR("InternetGetCookieExW failed: %u\n", GetLastError());
724 static HRESULT WINAPI HTMLDocument_put_expando(IHTMLDocument2 *iface, VARIANT_BOOL v)
726 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
727 FIXME("(%p)->(%x)\n", This, v);
731 static HRESULT WINAPI HTMLDocument_get_expando(IHTMLDocument2 *iface, VARIANT_BOOL *p)
733 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
734 FIXME("(%p)->(%p)\n", This, p);
738 static HRESULT WINAPI HTMLDocument_put_charset(IHTMLDocument2 *iface, BSTR v)
740 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
741 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
745 static HRESULT WINAPI HTMLDocument_get_charset(IHTMLDocument2 *iface, BSTR *p)
747 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
748 nsAString charset_str;
751 TRACE("(%p)->(%p)\n", This, p);
753 if(!This->doc_node->nsdoc) {
754 FIXME("NULL nsdoc\n");
758 nsAString_Init(&charset_str, NULL);
759 nsres = nsIDOMHTMLDocument_GetCharacterSet(This->doc_node->nsdoc, &charset_str);
760 return return_nsstr(nsres, &charset_str, p);
763 static HRESULT WINAPI HTMLDocument_put_defaultCharset(IHTMLDocument2 *iface, BSTR v)
765 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
766 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
770 static HRESULT WINAPI HTMLDocument_get_defaultCharset(IHTMLDocument2 *iface, BSTR *p)
772 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
773 FIXME("(%p)->(%p)\n", This, p);
777 static HRESULT WINAPI HTMLDocument_get_mimeType(IHTMLDocument2 *iface, BSTR *p)
779 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
780 FIXME("(%p)->(%p)\n", This, p);
784 static HRESULT WINAPI HTMLDocument_get_fileSize(IHTMLDocument2 *iface, BSTR *p)
786 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
787 FIXME("(%p)->(%p)\n", This, p);
791 static HRESULT WINAPI HTMLDocument_get_fileCreatedDate(IHTMLDocument2 *iface, BSTR *p)
793 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
794 FIXME("(%p)->(%p)\n", This, p);
798 static HRESULT WINAPI HTMLDocument_get_fileModifiedDate(IHTMLDocument2 *iface, BSTR *p)
800 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
801 FIXME("(%p)->(%p)\n", This, p);
805 static HRESULT WINAPI HTMLDocument_get_fileUpdatedDate(IHTMLDocument2 *iface, BSTR *p)
807 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
808 FIXME("(%p)->(%p)\n", This, p);
812 static HRESULT WINAPI HTMLDocument_get_security(IHTMLDocument2 *iface, BSTR *p)
814 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
815 FIXME("(%p)->(%p)\n", This, p);
819 static HRESULT WINAPI HTMLDocument_get_protocol(IHTMLDocument2 *iface, BSTR *p)
821 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
822 FIXME("(%p)->(%p)\n", This, p);
826 static HRESULT WINAPI HTMLDocument_get_nameProp(IHTMLDocument2 *iface, BSTR *p)
828 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
829 FIXME("(%p)->(%p)\n", This, p);
833 static HRESULT document_write(HTMLDocument *This, SAFEARRAY *psarray, BOOL ln)
841 if(!This->doc_node->nsdoc) {
842 WARN("NULL nsdoc\n");
849 if(psarray->cDims != 1) {
850 FIXME("cDims=%d\n", psarray->cDims);
854 hres = SafeArrayAccessData(psarray, (void**)&var);
856 WARN("SafeArrayAccessData failed: %08x\n", hres);
860 V_VT(&tmp) = VT_EMPTY;
862 argc = psarray->rgsabound[0].cElements;
863 for(i=0; i < argc; i++) {
864 if(V_VT(var+i) == VT_BSTR) {
865 nsAString_InitDepend(&nsstr, V_BSTR(var+i));
867 hres = VariantChangeTypeEx(&tmp, var+i, MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT), 0, VT_BSTR);
869 WARN("Could not convert %s to string\n", debugstr_variant(var+i));
872 nsAString_InitDepend(&nsstr, V_BSTR(&tmp));
875 if(!ln || i != argc-1)
876 nsres = nsIDOMHTMLDocument_Write(This->doc_node->nsdoc, &nsstr, NULL /* FIXME! */);
878 nsres = nsIDOMHTMLDocument_Writeln(This->doc_node->nsdoc, &nsstr, NULL /* FIXME! */);
879 nsAString_Finish(&nsstr);
880 if(V_VT(var+i) != VT_BSTR)
882 if(NS_FAILED(nsres)) {
883 ERR("Write failed: %08x\n", nsres);
889 SafeArrayUnaccessData(psarray);
894 static HRESULT WINAPI HTMLDocument_write(IHTMLDocument2 *iface, SAFEARRAY *psarray)
896 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
898 TRACE("(%p)->(%p)\n", iface, psarray);
900 return document_write(This, psarray, FALSE);
903 static HRESULT WINAPI HTMLDocument_writeln(IHTMLDocument2 *iface, SAFEARRAY *psarray)
905 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
907 TRACE("(%p)->(%p)\n", This, psarray);
909 return document_write(This, psarray, TRUE);
912 static HRESULT WINAPI HTMLDocument_open(IHTMLDocument2 *iface, BSTR url, VARIANT name,
913 VARIANT features, VARIANT replace, IDispatch **pomWindowResult)
915 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
919 static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};
921 TRACE("(%p)->(%s %s %s %s %p)\n", This, debugstr_w(url), debugstr_variant(&name),
922 debugstr_variant(&features), debugstr_variant(&replace), pomWindowResult);
924 if(!This->doc_node->nsdoc) {
929 if(!url || strcmpW(url, text_htmlW) || V_VT(&name) != VT_ERROR
930 || V_VT(&features) != VT_ERROR || V_VT(&replace) != VT_ERROR)
931 FIXME("unsupported args\n");
933 nsres = nsIDOMHTMLDocument_Open(This->doc_node->nsdoc, NULL, NULL, NULL, NULL, 0, &tmp);
934 if(NS_FAILED(nsres)) {
935 ERR("Open failed: %08x\n", nsres);
940 nsISupports_Release(tmp);
942 *pomWindowResult = (IDispatch*)&This->window->base.IHTMLWindow2_iface;
943 IHTMLWindow2_AddRef(&This->window->base.IHTMLWindow2_iface);
947 static HRESULT WINAPI HTMLDocument_close(IHTMLDocument2 *iface)
949 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
952 TRACE("(%p)\n", This);
954 if(!This->doc_node->nsdoc) {
959 nsres = nsIDOMHTMLDocument_Close(This->doc_node->nsdoc);
960 if(NS_FAILED(nsres)) {
961 ERR("Close failed: %08x\n", nsres);
968 static HRESULT WINAPI HTMLDocument_clear(IHTMLDocument2 *iface)
970 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
973 TRACE("(%p)\n", This);
975 nsres = nsIDOMHTMLDocument_Clear(This->doc_node->nsdoc);
976 if(NS_FAILED(nsres)) {
977 ERR("Clear failed: %08x\n", nsres);
984 static HRESULT WINAPI HTMLDocument_queryCommandSupported(IHTMLDocument2 *iface, BSTR cmdID,
987 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
988 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
992 static HRESULT WINAPI HTMLDocument_queryCommandEnabled(IHTMLDocument2 *iface, BSTR cmdID,
995 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
996 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1000 static HRESULT WINAPI HTMLDocument_queryCommandState(IHTMLDocument2 *iface, BSTR cmdID,
1001 VARIANT_BOOL *pfRet)
1003 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1004 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1008 static HRESULT WINAPI HTMLDocument_queryCommandIndeterm(IHTMLDocument2 *iface, BSTR cmdID,
1009 VARIANT_BOOL *pfRet)
1011 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1012 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1016 static HRESULT WINAPI HTMLDocument_queryCommandText(IHTMLDocument2 *iface, BSTR cmdID,
1019 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1020 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1024 static HRESULT WINAPI HTMLDocument_queryCommandValue(IHTMLDocument2 *iface, BSTR cmdID,
1027 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1028 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1032 static HRESULT WINAPI HTMLDocument_execCommand(IHTMLDocument2 *iface, BSTR cmdID,
1033 VARIANT_BOOL showUI, VARIANT value, VARIANT_BOOL *pfRet)
1035 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1036 FIXME("(%p)->(%s %x %s %p)\n", This, debugstr_w(cmdID), showUI, debugstr_variant(&value), pfRet);
1040 static HRESULT WINAPI HTMLDocument_execCommandShowHelp(IHTMLDocument2 *iface, BSTR cmdID,
1041 VARIANT_BOOL *pfRet)
1043 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1044 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1048 static HRESULT WINAPI HTMLDocument_createElement(IHTMLDocument2 *iface, BSTR eTag,
1049 IHTMLElement **newElem)
1051 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1055 TRACE("(%p)->(%s %p)\n", This, debugstr_w(eTag), newElem);
1057 hres = create_element(This->doc_node, eTag, &elem);
1061 *newElem = &elem->IHTMLElement_iface;
1065 static HRESULT WINAPI HTMLDocument_put_onhelp(IHTMLDocument2 *iface, VARIANT v)
1067 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1068 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1072 static HRESULT WINAPI HTMLDocument_get_onhelp(IHTMLDocument2 *iface, VARIANT *p)
1074 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1075 FIXME("(%p)->(%p)\n", This, p);
1079 static HRESULT WINAPI HTMLDocument_put_onclick(IHTMLDocument2 *iface, VARIANT v)
1081 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1083 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1085 return set_doc_event(This, EVENTID_CLICK, &v);
1088 static HRESULT WINAPI HTMLDocument_get_onclick(IHTMLDocument2 *iface, VARIANT *p)
1090 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1092 TRACE("(%p)->(%p)\n", This, p);
1094 return get_doc_event(This, EVENTID_CLICK, p);
1097 static HRESULT WINAPI HTMLDocument_put_ondblclick(IHTMLDocument2 *iface, VARIANT v)
1099 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1100 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1104 static HRESULT WINAPI HTMLDocument_get_ondblclick(IHTMLDocument2 *iface, VARIANT *p)
1106 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1107 FIXME("(%p)->(%p)\n", This, p);
1111 static HRESULT WINAPI HTMLDocument_put_onkeyup(IHTMLDocument2 *iface, VARIANT v)
1113 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1115 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1117 return set_doc_event(This, EVENTID_KEYUP, &v);
1120 static HRESULT WINAPI HTMLDocument_get_onkeyup(IHTMLDocument2 *iface, VARIANT *p)
1122 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1124 TRACE("(%p)->(%p)\n", This, p);
1126 return get_doc_event(This, EVENTID_KEYUP, p);
1129 static HRESULT WINAPI HTMLDocument_put_onkeydown(IHTMLDocument2 *iface, VARIANT v)
1131 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1133 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1135 return set_doc_event(This, EVENTID_KEYDOWN, &v);
1138 static HRESULT WINAPI HTMLDocument_get_onkeydown(IHTMLDocument2 *iface, VARIANT *p)
1140 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1142 TRACE("(%p)->(%p)\n", This, p);
1144 return get_doc_event(This, EVENTID_KEYDOWN, p);
1147 static HRESULT WINAPI HTMLDocument_put_onkeypress(IHTMLDocument2 *iface, VARIANT v)
1149 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1151 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1153 return set_doc_event(This, EVENTID_KEYPRESS, &v);
1156 static HRESULT WINAPI HTMLDocument_get_onkeypress(IHTMLDocument2 *iface, VARIANT *p)
1158 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1160 TRACE("(%p)->(%p)\n", This, p);
1162 return get_doc_event(This, EVENTID_KEYPRESS, p);
1165 static HRESULT WINAPI HTMLDocument_put_onmouseup(IHTMLDocument2 *iface, VARIANT v)
1167 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1169 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1171 return set_doc_event(This, EVENTID_MOUSEUP, &v);
1174 static HRESULT WINAPI HTMLDocument_get_onmouseup(IHTMLDocument2 *iface, VARIANT *p)
1176 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1178 TRACE("(%p)->(%p)\n", This, p);
1180 return get_doc_event(This, EVENTID_MOUSEUP, p);
1183 static HRESULT WINAPI HTMLDocument_put_onmousedown(IHTMLDocument2 *iface, VARIANT v)
1185 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1187 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1189 return set_doc_event(This, EVENTID_MOUSEDOWN, &v);
1192 static HRESULT WINAPI HTMLDocument_get_onmousedown(IHTMLDocument2 *iface, VARIANT *p)
1194 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1196 TRACE("(%p)->(%p)\n", This, p);
1198 return get_doc_event(This, EVENTID_MOUSEDOWN, p);
1201 static HRESULT WINAPI HTMLDocument_put_onmousemove(IHTMLDocument2 *iface, VARIANT v)
1203 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1205 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1207 return set_doc_event(This, EVENTID_MOUSEMOVE, &v);
1210 static HRESULT WINAPI HTMLDocument_get_onmousemove(IHTMLDocument2 *iface, VARIANT *p)
1212 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1214 TRACE("(%p)->(%p)\n", This, p);
1216 return get_doc_event(This, EVENTID_MOUSEMOVE, p);
1219 static HRESULT WINAPI HTMLDocument_put_onmouseout(IHTMLDocument2 *iface, VARIANT v)
1221 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1223 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1225 return set_doc_event(This, EVENTID_MOUSEOUT, &v);
1228 static HRESULT WINAPI HTMLDocument_get_onmouseout(IHTMLDocument2 *iface, VARIANT *p)
1230 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1232 TRACE("(%p)->(%p)\n", This, p);
1234 return get_doc_event(This, EVENTID_MOUSEOUT, p);
1237 static HRESULT WINAPI HTMLDocument_put_onmouseover(IHTMLDocument2 *iface, VARIANT v)
1239 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1241 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1243 return set_doc_event(This, EVENTID_MOUSEOVER, &v);
1246 static HRESULT WINAPI HTMLDocument_get_onmouseover(IHTMLDocument2 *iface, VARIANT *p)
1248 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1250 TRACE("(%p)->(%p)\n", This, p);
1252 return get_doc_event(This, EVENTID_MOUSEOVER, p);
1255 static HRESULT WINAPI HTMLDocument_put_onreadystatechange(IHTMLDocument2 *iface, VARIANT v)
1257 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1259 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1261 return set_doc_event(This, EVENTID_READYSTATECHANGE, &v);
1264 static HRESULT WINAPI HTMLDocument_get_onreadystatechange(IHTMLDocument2 *iface, VARIANT *p)
1266 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1268 TRACE("(%p)->(%p)\n", This, p);
1270 return get_doc_event(This, EVENTID_READYSTATECHANGE, p);
1273 static HRESULT WINAPI HTMLDocument_put_onafterupdate(IHTMLDocument2 *iface, VARIANT v)
1275 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1276 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1280 static HRESULT WINAPI HTMLDocument_get_onafterupdate(IHTMLDocument2 *iface, VARIANT *p)
1282 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1283 FIXME("(%p)->(%p)\n", This, p);
1287 static HRESULT WINAPI HTMLDocument_put_onrowexit(IHTMLDocument2 *iface, VARIANT v)
1289 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1290 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1294 static HRESULT WINAPI HTMLDocument_get_onrowexit(IHTMLDocument2 *iface, VARIANT *p)
1296 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1297 FIXME("(%p)->(%p)\n", This, p);
1301 static HRESULT WINAPI HTMLDocument_put_onrowenter(IHTMLDocument2 *iface, VARIANT v)
1303 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1304 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1308 static HRESULT WINAPI HTMLDocument_get_onrowenter(IHTMLDocument2 *iface, VARIANT *p)
1310 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1311 FIXME("(%p)->(%p)\n", This, p);
1315 static HRESULT WINAPI HTMLDocument_put_ondragstart(IHTMLDocument2 *iface, VARIANT v)
1317 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1319 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1321 return set_doc_event(This, EVENTID_DRAGSTART, &v);
1324 static HRESULT WINAPI HTMLDocument_get_ondragstart(IHTMLDocument2 *iface, VARIANT *p)
1326 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1328 TRACE("(%p)->(%p)\n", This, p);
1330 return get_doc_event(This, EVENTID_DRAGSTART, p);
1333 static HRESULT WINAPI HTMLDocument_put_onselectstart(IHTMLDocument2 *iface, VARIANT v)
1335 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1337 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1339 return set_doc_event(This, EVENTID_SELECTSTART, &v);
1342 static HRESULT WINAPI HTMLDocument_get_onselectstart(IHTMLDocument2 *iface, VARIANT *p)
1344 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1346 TRACE("(%p)->(%p)\n", This, p);
1348 return get_doc_event(This, EVENTID_SELECTSTART, p);
1351 static HRESULT WINAPI HTMLDocument_elementFromPoint(IHTMLDocument2 *iface, LONG x, LONG y,
1352 IHTMLElement **elementHit)
1354 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1355 nsIDOMElement *nselem;
1360 TRACE("(%p)->(%d %d %p)\n", This, x, y, elementHit);
1362 nsres = nsIDOMHTMLDocument_ElementFromPoint(This->doc_node->nsdoc, x, y, &nselem);
1363 if(NS_FAILED(nsres)) {
1364 ERR("ElementFromPoint failed: %08x\n", nsres);
1373 hres = get_node(This->doc_node, (nsIDOMNode*)nselem, TRUE, &node);
1374 nsIDOMElement_Release(nselem);
1378 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)elementHit);
1383 static HRESULT WINAPI HTMLDocument_get_parentWindow(IHTMLDocument2 *iface, IHTMLWindow2 **p)
1385 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1387 TRACE("(%p)->(%p)\n", This, p);
1389 *p = &This->window->base.IHTMLWindow2_iface;
1390 IHTMLWindow2_AddRef(*p);
1394 static HRESULT WINAPI HTMLDocument_get_styleSheets(IHTMLDocument2 *iface,
1395 IHTMLStyleSheetsCollection **p)
1397 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1398 nsIDOMStyleSheetList *nsstylelist;
1401 TRACE("(%p)->(%p)\n", This, p);
1405 if(!This->doc_node->nsdoc) {
1406 WARN("NULL nsdoc\n");
1407 return E_UNEXPECTED;
1410 nsres = nsIDOMHTMLDocument_GetStyleSheets(This->doc_node->nsdoc, &nsstylelist);
1411 if(NS_FAILED(nsres)) {
1412 ERR("GetStyleSheets failed: %08x\n", nsres);
1416 *p = HTMLStyleSheetsCollection_Create(nsstylelist);
1417 nsIDOMStyleSheetList_Release(nsstylelist);
1422 static HRESULT WINAPI HTMLDocument_put_onbeforeupdate(IHTMLDocument2 *iface, VARIANT v)
1424 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1425 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1429 static HRESULT WINAPI HTMLDocument_get_onbeforeupdate(IHTMLDocument2 *iface, VARIANT *p)
1431 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1432 FIXME("(%p)->(%p)\n", This, p);
1436 static HRESULT WINAPI HTMLDocument_put_onerrorupdate(IHTMLDocument2 *iface, VARIANT v)
1438 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1439 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1443 static HRESULT WINAPI HTMLDocument_get_onerrorupdate(IHTMLDocument2 *iface, VARIANT *p)
1445 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1446 FIXME("(%p)->(%p)\n", This, p);
1450 static HRESULT WINAPI HTMLDocument_toString(IHTMLDocument2 *iface, BSTR *String)
1452 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1453 FIXME("(%p)->(%p)\n", This, String);
1457 static HRESULT WINAPI HTMLDocument_createStyleSheet(IHTMLDocument2 *iface, BSTR bstrHref,
1458 LONG lIndex, IHTMLStyleSheet **ppnewStyleSheet)
1460 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1461 nsIDOMHTMLHeadElement *head_elem;
1462 IHTMLStyleElement *style_elem;
1467 static const WCHAR styleW[] = {'s','t','y','l','e',0};
1469 TRACE("(%p)->(%s %d %p)\n", This, debugstr_w(bstrHref), lIndex, ppnewStyleSheet);
1471 if(!This->doc_node->nsdoc) {
1472 FIXME("not a real doc object\n");
1477 FIXME("Unsupported lIndex %d\n", lIndex);
1480 FIXME("semi-stub for href %s\n", debugstr_w(bstrHref));
1481 *ppnewStyleSheet = HTMLStyleSheet_Create(NULL);
1485 hres = create_element(This->doc_node, styleW, &elem);
1489 nsres = nsIDOMHTMLDocument_GetHead(This->doc_node->nsdoc, &head_elem);
1490 if(NS_SUCCEEDED(nsres)) {
1491 nsIDOMNode *tmp_node;
1493 nsres = nsIDOMHTMLHeadElement_AppendChild(head_elem, (nsIDOMNode*)elem->nselem, &tmp_node);
1494 nsIDOMHTMLHeadElement_Release(head_elem);
1495 if(NS_SUCCEEDED(nsres) && tmp_node)
1496 nsIDOMNode_Release(tmp_node);
1498 if(NS_FAILED(nsres)) {
1499 IHTMLElement_Release(&elem->IHTMLElement_iface);
1503 hres = IHTMLElement_QueryInterface(&elem->IHTMLElement_iface, &IID_IHTMLStyleElement, (void**)&style_elem);
1504 assert(hres == S_OK);
1505 IHTMLElement_Release(&elem->IHTMLElement_iface);
1507 hres = IHTMLStyleElement_get_styleSheet(style_elem, ppnewStyleSheet);
1508 IHTMLStyleElement_Release(style_elem);
1512 static const IHTMLDocument2Vtbl HTMLDocumentVtbl = {
1513 HTMLDocument_QueryInterface,
1514 HTMLDocument_AddRef,
1515 HTMLDocument_Release,
1516 HTMLDocument_GetTypeInfoCount,
1517 HTMLDocument_GetTypeInfo,
1518 HTMLDocument_GetIDsOfNames,
1519 HTMLDocument_Invoke,
1520 HTMLDocument_get_Script,
1521 HTMLDocument_get_all,
1522 HTMLDocument_get_body,
1523 HTMLDocument_get_activeElement,
1524 HTMLDocument_get_images,
1525 HTMLDocument_get_applets,
1526 HTMLDocument_get_links,
1527 HTMLDocument_get_forms,
1528 HTMLDocument_get_anchors,
1529 HTMLDocument_put_title,
1530 HTMLDocument_get_title,
1531 HTMLDocument_get_scripts,
1532 HTMLDocument_put_designMode,
1533 HTMLDocument_get_designMode,
1534 HTMLDocument_get_selection,
1535 HTMLDocument_get_readyState,
1536 HTMLDocument_get_frames,
1537 HTMLDocument_get_embeds,
1538 HTMLDocument_get_plugins,
1539 HTMLDocument_put_alinkColor,
1540 HTMLDocument_get_alinkColor,
1541 HTMLDocument_put_bgColor,
1542 HTMLDocument_get_bgColor,
1543 HTMLDocument_put_fgColor,
1544 HTMLDocument_get_fgColor,
1545 HTMLDocument_put_linkColor,
1546 HTMLDocument_get_linkColor,
1547 HTMLDocument_put_vlinkColor,
1548 HTMLDocument_get_vlinkColor,
1549 HTMLDocument_get_referrer,
1550 HTMLDocument_get_location,
1551 HTMLDocument_get_lastModified,
1552 HTMLDocument_put_URL,
1553 HTMLDocument_get_URL,
1554 HTMLDocument_put_domain,
1555 HTMLDocument_get_domain,
1556 HTMLDocument_put_cookie,
1557 HTMLDocument_get_cookie,
1558 HTMLDocument_put_expando,
1559 HTMLDocument_get_expando,
1560 HTMLDocument_put_charset,
1561 HTMLDocument_get_charset,
1562 HTMLDocument_put_defaultCharset,
1563 HTMLDocument_get_defaultCharset,
1564 HTMLDocument_get_mimeType,
1565 HTMLDocument_get_fileSize,
1566 HTMLDocument_get_fileCreatedDate,
1567 HTMLDocument_get_fileModifiedDate,
1568 HTMLDocument_get_fileUpdatedDate,
1569 HTMLDocument_get_security,
1570 HTMLDocument_get_protocol,
1571 HTMLDocument_get_nameProp,
1573 HTMLDocument_writeln,
1577 HTMLDocument_queryCommandSupported,
1578 HTMLDocument_queryCommandEnabled,
1579 HTMLDocument_queryCommandState,
1580 HTMLDocument_queryCommandIndeterm,
1581 HTMLDocument_queryCommandText,
1582 HTMLDocument_queryCommandValue,
1583 HTMLDocument_execCommand,
1584 HTMLDocument_execCommandShowHelp,
1585 HTMLDocument_createElement,
1586 HTMLDocument_put_onhelp,
1587 HTMLDocument_get_onhelp,
1588 HTMLDocument_put_onclick,
1589 HTMLDocument_get_onclick,
1590 HTMLDocument_put_ondblclick,
1591 HTMLDocument_get_ondblclick,
1592 HTMLDocument_put_onkeyup,
1593 HTMLDocument_get_onkeyup,
1594 HTMLDocument_put_onkeydown,
1595 HTMLDocument_get_onkeydown,
1596 HTMLDocument_put_onkeypress,
1597 HTMLDocument_get_onkeypress,
1598 HTMLDocument_put_onmouseup,
1599 HTMLDocument_get_onmouseup,
1600 HTMLDocument_put_onmousedown,
1601 HTMLDocument_get_onmousedown,
1602 HTMLDocument_put_onmousemove,
1603 HTMLDocument_get_onmousemove,
1604 HTMLDocument_put_onmouseout,
1605 HTMLDocument_get_onmouseout,
1606 HTMLDocument_put_onmouseover,
1607 HTMLDocument_get_onmouseover,
1608 HTMLDocument_put_onreadystatechange,
1609 HTMLDocument_get_onreadystatechange,
1610 HTMLDocument_put_onafterupdate,
1611 HTMLDocument_get_onafterupdate,
1612 HTMLDocument_put_onrowexit,
1613 HTMLDocument_get_onrowexit,
1614 HTMLDocument_put_onrowenter,
1615 HTMLDocument_get_onrowenter,
1616 HTMLDocument_put_ondragstart,
1617 HTMLDocument_get_ondragstart,
1618 HTMLDocument_put_onselectstart,
1619 HTMLDocument_get_onselectstart,
1620 HTMLDocument_elementFromPoint,
1621 HTMLDocument_get_parentWindow,
1622 HTMLDocument_get_styleSheets,
1623 HTMLDocument_put_onbeforeupdate,
1624 HTMLDocument_get_onbeforeupdate,
1625 HTMLDocument_put_onerrorupdate,
1626 HTMLDocument_get_onerrorupdate,
1627 HTMLDocument_toString,
1628 HTMLDocument_createStyleSheet
1631 static void HTMLDocument_on_advise(IUnknown *iface, cp_static_data_t *cp)
1633 HTMLDocument *This = impl_from_IHTMLDocument2((IHTMLDocument2*)iface);
1636 update_cp_events(This->window->base.inner_window, &This->doc_node->node.event_target, cp, This->doc_node->node.nsnode);
1639 static inline HTMLDocument *impl_from_ISupportErrorInfo(ISupportErrorInfo *iface)
1641 return CONTAINING_RECORD(iface, HTMLDocument, ISupportErrorInfo_iface);
1644 static HRESULT WINAPI SupportErrorInfo_QueryInterface(ISupportErrorInfo *iface, REFIID riid, void **ppv)
1646 HTMLDocument *This = impl_from_ISupportErrorInfo(iface);
1647 return htmldoc_query_interface(This, riid, ppv);
1650 static ULONG WINAPI SupportErrorInfo_AddRef(ISupportErrorInfo *iface)
1652 HTMLDocument *This = impl_from_ISupportErrorInfo(iface);
1653 return htmldoc_addref(This);
1656 static ULONG WINAPI SupportErrorInfo_Release(ISupportErrorInfo *iface)
1658 HTMLDocument *This = impl_from_ISupportErrorInfo(iface);
1659 return htmldoc_release(This);
1662 static HRESULT WINAPI SupportErrorInfo_InterfaceSupportsErrorInfo(ISupportErrorInfo *iface, REFIID riid)
1664 FIXME("(%p)->(%s)\n", iface, debugstr_guid(riid));
1668 static const ISupportErrorInfoVtbl SupportErrorInfoVtbl = {
1669 SupportErrorInfo_QueryInterface,
1670 SupportErrorInfo_AddRef,
1671 SupportErrorInfo_Release,
1672 SupportErrorInfo_InterfaceSupportsErrorInfo
1675 static inline HTMLDocument *impl_from_IDispatchEx(IDispatchEx *iface)
1677 return CONTAINING_RECORD(iface, HTMLDocument, IDispatchEx_iface);
1680 static HRESULT dispid_from_elem_name(HTMLDocumentNode *This, BSTR name, DISPID *dispid)
1682 nsIDOMNodeList *node_list;
1689 return DISP_E_UNKNOWNNAME;
1691 nsAString_InitDepend(&name_str, name);
1692 nsres = nsIDOMHTMLDocument_GetElementsByName(This->nsdoc, &name_str, &node_list);
1693 nsAString_Finish(&name_str);
1694 if(NS_FAILED(nsres))
1697 nsres = nsIDOMNodeList_GetLength(node_list, &len);
1698 nsIDOMNodeList_Release(node_list);
1699 if(NS_FAILED(nsres))
1703 return DISP_E_UNKNOWNNAME;
1705 for(i=0; i < This->elem_vars_cnt; i++) {
1706 if(!strcmpW(name, This->elem_vars[i])) {
1707 *dispid = MSHTML_DISPID_CUSTOM_MIN+i;
1712 if(This->elem_vars_cnt == This->elem_vars_size) {
1715 if(This->elem_vars_size) {
1716 new_vars = heap_realloc(This->elem_vars, This->elem_vars_size*2*sizeof(WCHAR*));
1718 return E_OUTOFMEMORY;
1719 This->elem_vars_size *= 2;
1721 new_vars = heap_alloc(16*sizeof(WCHAR*));
1723 return E_OUTOFMEMORY;
1724 This->elem_vars_size = 16;
1727 This->elem_vars = new_vars;
1730 This->elem_vars[This->elem_vars_cnt] = heap_strdupW(name);
1731 if(!This->elem_vars[This->elem_vars_cnt])
1732 return E_OUTOFMEMORY;
1734 *dispid = MSHTML_DISPID_CUSTOM_MIN+This->elem_vars_cnt++;
1738 static HRESULT WINAPI DocDispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
1740 HTMLDocument *This = impl_from_IDispatchEx(iface);
1742 return htmldoc_query_interface(This, riid, ppv);
1745 static ULONG WINAPI DocDispatchEx_AddRef(IDispatchEx *iface)
1747 HTMLDocument *This = impl_from_IDispatchEx(iface);
1749 return htmldoc_addref(This);
1752 static ULONG WINAPI DocDispatchEx_Release(IDispatchEx *iface)
1754 HTMLDocument *This = impl_from_IDispatchEx(iface);
1756 return htmldoc_release(This);
1759 static HRESULT WINAPI DocDispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
1761 HTMLDocument *This = impl_from_IDispatchEx(iface);
1763 return IDispatchEx_GetTypeInfoCount(This->dispex, pctinfo);
1766 static HRESULT WINAPI DocDispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
1767 LCID lcid, ITypeInfo **ppTInfo)
1769 HTMLDocument *This = impl_from_IDispatchEx(iface);
1771 return IDispatchEx_GetTypeInfo(This->dispex, iTInfo, lcid, ppTInfo);
1774 static HRESULT WINAPI DocDispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
1775 LPOLESTR *rgszNames, UINT cNames,
1776 LCID lcid, DISPID *rgDispId)
1778 HTMLDocument *This = impl_from_IDispatchEx(iface);
1780 return IDispatchEx_GetIDsOfNames(This->dispex, riid, rgszNames, cNames, lcid, rgDispId);
1783 static HRESULT WINAPI DocDispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
1784 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1785 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1787 HTMLDocument *This = impl_from_IDispatchEx(iface);
1789 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1790 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1792 switch(dispIdMember) {
1793 case DISPID_READYSTATE:
1794 TRACE("DISPID_READYSTATE\n");
1796 if(!(wFlags & DISPATCH_PROPERTYGET))
1797 return E_INVALIDARG;
1799 V_VT(pVarResult) = VT_I4;
1800 V_I4(pVarResult) = This->window->readystate;
1804 return IDispatchEx_Invoke(This->dispex, dispIdMember, riid, lcid, wFlags, pDispParams,
1805 pVarResult, pExcepInfo, puArgErr);
1808 static HRESULT WINAPI DocDispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
1810 HTMLDocument *This = impl_from_IDispatchEx(iface);
1813 hres = IDispatchEx_GetDispID(This->dispex, bstrName, grfdex, pid);
1814 if(hres != DISP_E_UNKNOWNNAME)
1817 return dispid_from_elem_name(This->doc_node, bstrName, pid);
1820 static HRESULT WINAPI DocDispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1821 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1823 HTMLDocument *This = impl_from_IDispatchEx(iface);
1825 if(This->window && id == DISPID_IHTMLDOCUMENT2_LOCATION && (wFlags & DISPATCH_PROPERTYPUT))
1826 return IDispatchEx_InvokeEx(&This->window->base.IDispatchEx_iface, DISPID_IHTMLWINDOW2_LOCATION,
1827 lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1830 return IDispatchEx_InvokeEx(This->dispex, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1833 static HRESULT WINAPI DocDispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
1835 HTMLDocument *This = impl_from_IDispatchEx(iface);
1837 return IDispatchEx_DeleteMemberByName(This->dispex, bstrName, grfdex);
1840 static HRESULT WINAPI DocDispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
1842 HTMLDocument *This = impl_from_IDispatchEx(iface);
1844 return IDispatchEx_DeleteMemberByDispID(This->dispex, id);
1847 static HRESULT WINAPI DocDispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
1849 HTMLDocument *This = impl_from_IDispatchEx(iface);
1851 return IDispatchEx_GetMemberProperties(This->dispex, id, grfdexFetch, pgrfdex);
1854 static HRESULT WINAPI DocDispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
1856 HTMLDocument *This = impl_from_IDispatchEx(iface);
1858 return IDispatchEx_GetMemberName(This->dispex, id, pbstrName);
1861 static HRESULT WINAPI DocDispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
1863 HTMLDocument *This = impl_from_IDispatchEx(iface);
1865 return IDispatchEx_GetNextDispID(This->dispex, grfdex, id, pid);
1868 static HRESULT WINAPI DocDispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
1870 HTMLDocument *This = impl_from_IDispatchEx(iface);
1872 return IDispatchEx_GetNameSpaceParent(This->dispex, ppunk);
1875 static const IDispatchExVtbl DocDispatchExVtbl = {
1876 DocDispatchEx_QueryInterface,
1877 DocDispatchEx_AddRef,
1878 DocDispatchEx_Release,
1879 DocDispatchEx_GetTypeInfoCount,
1880 DocDispatchEx_GetTypeInfo,
1881 DocDispatchEx_GetIDsOfNames,
1882 DocDispatchEx_Invoke,
1883 DocDispatchEx_GetDispID,
1884 DocDispatchEx_InvokeEx,
1885 DocDispatchEx_DeleteMemberByName,
1886 DocDispatchEx_DeleteMemberByDispID,
1887 DocDispatchEx_GetMemberProperties,
1888 DocDispatchEx_GetMemberName,
1889 DocDispatchEx_GetNextDispID,
1890 DocDispatchEx_GetNameSpaceParent
1893 static inline HTMLDocument *impl_from_IProvideClassInfo(IProvideClassInfo *iface)
1895 return CONTAINING_RECORD(iface, HTMLDocument, IProvideClassInfo_iface);
1898 static HRESULT WINAPI ProvideClassInfo_QueryInterface(IProvideClassInfo *iface,
1899 REFIID riid, void **ppv)
1901 HTMLDocument *This = impl_from_IProvideClassInfo(iface);
1902 return htmldoc_query_interface(This, riid, ppv);
1905 static ULONG WINAPI ProvideClassInfo_AddRef(IProvideClassInfo *iface)
1907 HTMLDocument *This = impl_from_IProvideClassInfo(iface);
1908 return htmldoc_addref(This);
1911 static ULONG WINAPI ProvideClassInfo_Release(IProvideClassInfo *iface)
1913 HTMLDocument *This = impl_from_IProvideClassInfo(iface);
1914 return htmldoc_release(This);
1917 static HRESULT WINAPI ProvideClassInfo_GetClassInfo(IProvideClassInfo* iface,
1920 HTMLDocument *This = impl_from_IProvideClassInfo(iface);
1921 TRACE("(%p)->(%p)\n", This, ppTI);
1922 return get_htmldoc_classinfo(ppTI);
1925 static const IProvideClassInfoVtbl ProvideClassInfoVtbl = {
1926 ProvideClassInfo_QueryInterface,
1927 ProvideClassInfo_AddRef,
1928 ProvideClassInfo_Release,
1929 ProvideClassInfo_GetClassInfo
1932 static BOOL htmldoc_qi(HTMLDocument *This, REFIID riid, void **ppv)
1936 if(IsEqualGUID(&IID_IUnknown, riid)) {
1937 TRACE("(%p)->(IID_IUnknown, %p)\n", This, ppv);
1938 *ppv = &This->IHTMLDocument2_iface;
1939 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1940 TRACE("(%p)->(IID_IDispatch, %p)\n", This, ppv);
1941 *ppv = &This->IDispatchEx_iface;
1942 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
1943 TRACE("(%p)->(IID_IDispatchEx, %p)\n", This, ppv);
1944 *ppv = &This->IDispatchEx_iface;
1945 }else if(IsEqualGUID(&IID_IHTMLDocument, riid)) {
1946 TRACE("(%p)->(IID_IHTMLDocument, %p)\n", This, ppv);
1947 *ppv = &This->IHTMLDocument2_iface;
1948 }else if(IsEqualGUID(&IID_IHTMLDocument2, riid)) {
1949 TRACE("(%p)->(IID_IHTMLDocument2, %p)\n", This, ppv);
1950 *ppv = &This->IHTMLDocument2_iface;
1951 }else if(IsEqualGUID(&IID_IHTMLDocument3, riid)) {
1952 TRACE("(%p)->(IID_IHTMLDocument3, %p)\n", This, ppv);
1953 *ppv = &This->IHTMLDocument3_iface;
1954 }else if(IsEqualGUID(&IID_IHTMLDocument4, riid)) {
1955 TRACE("(%p)->(IID_IHTMLDocument4, %p)\n", This, ppv);
1956 *ppv = &This->IHTMLDocument4_iface;
1957 }else if(IsEqualGUID(&IID_IHTMLDocument5, riid)) {
1958 TRACE("(%p)->(IID_IHTMLDocument5, %p)\n", This, ppv);
1959 *ppv = &This->IHTMLDocument5_iface;
1960 }else if(IsEqualGUID(&IID_IHTMLDocument6, riid)) {
1961 TRACE("(%p)->(IID_IHTMLDocument6, %p)\n", This, ppv);
1962 *ppv = &This->IHTMLDocument6_iface;
1963 }else if(IsEqualGUID(&IID_IPersist, riid)) {
1964 TRACE("(%p)->(IID_IPersist, %p)\n", This, ppv);
1965 *ppv = &This->IPersistFile_iface;
1966 }else if(IsEqualGUID(&IID_IPersistMoniker, riid)) {
1967 TRACE("(%p)->(IID_IPersistMoniker, %p)\n", This, ppv);
1968 *ppv = &This->IPersistMoniker_iface;
1969 }else if(IsEqualGUID(&IID_IPersistFile, riid)) {
1970 TRACE("(%p)->(IID_IPersistFile, %p)\n", This, ppv);
1971 *ppv = &This->IPersistFile_iface;
1972 }else if(IsEqualGUID(&IID_IMonikerProp, riid)) {
1973 TRACE("(%p)->(IID_IMonikerProp, %p)\n", This, ppv);
1974 *ppv = &This->IMonikerProp_iface;
1975 }else if(IsEqualGUID(&IID_IOleObject, riid)) {
1976 TRACE("(%p)->(IID_IOleObject, %p)\n", This, ppv);
1977 *ppv = &This->IOleObject_iface;
1978 }else if(IsEqualGUID(&IID_IOleDocument, riid)) {
1979 TRACE("(%p)->(IID_IOleDocument, %p)\n", This, ppv);
1980 *ppv = &This->IOleDocument_iface;
1981 }else if(IsEqualGUID(&IID_IOleDocumentView, riid)) {
1982 TRACE("(%p)->(IID_IOleDocumentView, %p)\n", This, ppv);
1983 *ppv = &This->IOleDocumentView_iface;
1984 }else if(IsEqualGUID(&IID_IOleInPlaceActiveObject, riid)) {
1985 TRACE("(%p)->(IID_IOleInPlaceActiveObject, %p)\n", This, ppv);
1986 *ppv = &This->IOleInPlaceActiveObject_iface;
1987 }else if(IsEqualGUID(&IID_IViewObject, riid)) {
1988 TRACE("(%p)->(IID_IViewObject, %p)\n", This, ppv);
1989 *ppv = &This->IViewObjectEx_iface;
1990 }else if(IsEqualGUID(&IID_IViewObject2, riid)) {
1991 TRACE("(%p)->(IID_IViewObject2, %p)\n", This, ppv);
1992 *ppv = &This->IViewObjectEx_iface;
1993 }else if(IsEqualGUID(&IID_IViewObjectEx, riid)) {
1994 TRACE("(%p)->(IID_IViewObjectEx, %p)\n", This, ppv);
1995 *ppv = &This->IViewObjectEx_iface;
1996 }else if(IsEqualGUID(&IID_IOleWindow, riid)) {
1997 TRACE("(%p)->(IID_IOleWindow, %p)\n", This, ppv);
1998 *ppv = &This->IOleInPlaceActiveObject_iface;
1999 }else if(IsEqualGUID(&IID_IOleInPlaceObject, riid)) {
2000 TRACE("(%p)->(IID_IOleInPlaceObject, %p)\n", This, ppv);
2001 *ppv = &This->IOleInPlaceObjectWindowless_iface;
2002 }else if(IsEqualGUID(&IID_IOleInPlaceObjectWindowless, riid)) {
2003 TRACE("(%p)->(IID_IOleInPlaceObjectWindowless, %p)\n", This, ppv);
2004 *ppv = &This->IOleInPlaceObjectWindowless_iface;
2005 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
2006 TRACE("(%p)->(IID_IServiceProvider, %p)\n", This, ppv);
2007 *ppv = &This->IServiceProvider_iface;
2008 }else if(IsEqualGUID(&IID_IOleCommandTarget, riid)) {
2009 TRACE("(%p)->(IID_IOleCommandTarget, %p)\n", This, ppv);
2010 *ppv = &This->IOleCommandTarget_iface;
2011 }else if(IsEqualGUID(&IID_IOleControl, riid)) {
2012 TRACE("(%p)->(IID_IOleControl, %p)\n", This, ppv);
2013 *ppv = &This->IOleControl_iface;
2014 }else if(IsEqualGUID(&IID_IHlinkTarget, riid)) {
2015 TRACE("(%p)->(IID_IHlinkTarget, %p)\n", This, ppv);
2016 *ppv = &This->IHlinkTarget_iface;
2017 }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
2018 TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppv);
2019 *ppv = &This->cp_container.IConnectionPointContainer_iface;
2020 }else if(IsEqualGUID(&IID_IPersistStreamInit, riid)) {
2021 TRACE("(%p)->(IID_IPersistStreamInit %p)\n", This, ppv);
2022 *ppv = &This->IPersistStreamInit_iface;
2023 }else if(IsEqualGUID(&DIID_DispHTMLDocument, riid)) {
2024 TRACE("(%p)->(DIID_DispHTMLDocument %p)\n", This, ppv);
2025 *ppv = &This->IHTMLDocument2_iface;
2026 }else if(IsEqualGUID(&IID_ISupportErrorInfo, riid)) {
2027 TRACE("(%p)->(IID_ISupportErrorInfo %p)\n", This, ppv);
2028 *ppv = &This->ISupportErrorInfo_iface;
2029 }else if(IsEqualGUID(&IID_IPersistHistory, riid)) {
2030 TRACE("(%p)->(IID_IPersistHistory %p)\n", This, ppv);
2031 *ppv = &This->IPersistHistory_iface;
2032 }else if(IsEqualGUID(&CLSID_CMarkup, riid)) {
2033 FIXME("(%p)->(CLSID_CMarkup %p)\n", This, ppv);
2035 }else if(IsEqualGUID(&IID_IRunnableObject, riid)) {
2036 TRACE("(%p)->(IID_IRunnableObject %p) returning NULL\n", This, ppv);
2038 }else if(IsEqualGUID(&IID_IPersistPropertyBag, riid)) {
2039 TRACE("(%p)->(IID_IPersistPropertyBag %p) returning NULL\n", This, ppv);
2041 }else if(IsEqualGUID(&IID_IMarshal, riid)) {
2042 TRACE("(%p)->(IID_IMarshal %p) returning NULL\n", This, ppv);
2044 }else if(IsEqualGUID(&IID_IExternalConnection, riid)) {
2045 TRACE("(%p)->(IID_IExternalConnection %p) returning NULL\n", This, ppv);
2047 }else if(IsEqualGUID(&IID_IStdMarshalInfo, riid)) {
2048 TRACE("(%p)->(IID_IStdMarshalInfo %p) returning NULL\n", This, ppv);
2050 }else if(IsEqualGUID(&IID_IObjectWithSite, riid)) {
2051 TRACE("(%p)->(IID_IObjectWithSite %p)\n", This, ppv);
2052 *ppv = &This->IObjectWithSite_iface;
2053 }else if(IsEqualGUID(&IID_IOleContainer, riid)) {
2054 TRACE("(%p)->(IID_IOleContainer %p)\n", This, ppv);
2055 *ppv = &This->IOleContainer_iface;
2056 }else if(IsEqualGUID(&IID_IObjectSafety, riid)) {
2057 TRACE("(%p)->(IID_IObjectSafety %p)\n", This, ppv);
2058 *ppv = &This->IObjectSafety_iface;
2059 }else if(IsEqualGUID(&IID_IProvideClassInfo, riid)) {
2060 TRACE("(%p)->(IID_IProvideClassInfo, %p)\n", This, ppv);
2061 *ppv = &This->IProvideClassInfo_iface;
2067 IUnknown_AddRef((IUnknown*)*ppv);
2071 static cp_static_data_t HTMLDocumentEvents_data = { HTMLDocumentEvents_tid, HTMLDocument_on_advise };
2073 static const cpc_entry_t HTMLDocument_cpc[] = {
2074 {&IID_IDispatch, &HTMLDocumentEvents_data},
2075 {&IID_IPropertyNotifySink},
2076 {&DIID_HTMLDocumentEvents, &HTMLDocumentEvents_data},
2077 {&DIID_HTMLDocumentEvents2},
2081 static void init_doc(HTMLDocument *doc, IUnknown *unk_impl, IDispatchEx *dispex)
2083 doc->IHTMLDocument2_iface.lpVtbl = &HTMLDocumentVtbl;
2084 doc->IDispatchEx_iface.lpVtbl = &DocDispatchExVtbl;
2085 doc->ISupportErrorInfo_iface.lpVtbl = &SupportErrorInfoVtbl;
2086 doc->IProvideClassInfo_iface.lpVtbl = &ProvideClassInfoVtbl;
2088 doc->unk_impl = unk_impl;
2089 doc->dispex = dispex;
2090 doc->task_magic = get_task_target_magic();
2092 HTMLDocument_HTMLDocument3_Init(doc);
2093 HTMLDocument_HTMLDocument5_Init(doc);
2094 HTMLDocument_Persist_Init(doc);
2095 HTMLDocument_OleCmd_Init(doc);
2096 HTMLDocument_OleObj_Init(doc);
2097 HTMLDocument_View_Init(doc);
2098 HTMLDocument_Window_Init(doc);
2099 HTMLDocument_Service_Init(doc);
2100 HTMLDocument_Hlink_Init(doc);
2102 ConnectionPointContainer_Init(&doc->cp_container, (IUnknown*)&doc->IHTMLDocument2_iface, HTMLDocument_cpc);
2105 static void destroy_htmldoc(HTMLDocument *This)
2107 remove_target_tasks(This->task_magic);
2109 ConnectionPointContainer_Destroy(&This->cp_container);
2112 static inline HTMLDocumentNode *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
2114 return CONTAINING_RECORD(iface, HTMLDocumentNode, node);
2117 static HRESULT HTMLDocumentNode_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
2119 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2121 if(htmldoc_qi(&This->basedoc, riid, ppv))
2122 return *ppv ? S_OK : E_NOINTERFACE;
2124 if(IsEqualGUID(&IID_IInternetHostSecurityManager, riid)) {
2125 TRACE("(%p)->(IID_IInternetHostSecurityManager %p)\n", This, ppv);
2126 *ppv = &This->IInternetHostSecurityManager_iface;
2128 return HTMLDOMNode_QI(&This->node, riid, ppv);
2131 IUnknown_AddRef((IUnknown*)*ppv);
2135 static void HTMLDocumentNode_destructor(HTMLDOMNode *iface)
2137 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2140 for(i=0; i < This->elem_vars_cnt; i++)
2141 heap_free(This->elem_vars[i]);
2142 heap_free(This->elem_vars);
2144 detach_events(This);
2145 if(This->body_event_target)
2146 release_event_target(This->body_event_target);
2148 ICatInformation_Release(This->catmgr);
2150 detach_selection(This);
2151 detach_ranges(This);
2153 while(!list_empty(&This->plugin_hosts))
2154 detach_plugin_host(LIST_ENTRY(list_head(&This->plugin_hosts), PluginHost, entry));
2156 if(This->nsnode_selector) {
2157 nsIDOMNodeSelector_Release(This->nsnode_selector);
2158 This->nsnode_selector = NULL;
2162 assert(!This->window);
2163 release_document_mutation(This);
2164 nsIDOMHTMLDocument_Release(This->nsdoc);
2165 }else if(This->window) {
2166 /* document fragments own reference to inner window */
2167 IHTMLWindow2_Release(&This->window->base.IHTMLWindow2_iface);
2168 This->window = NULL;
2171 heap_free(This->event_vector);
2172 destroy_htmldoc(&This->basedoc);
2175 static HRESULT HTMLDocumentNode_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
2177 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2178 FIXME("%p\n", This);
2182 static void HTMLDocumentNode_traverse(HTMLDOMNode *iface, nsCycleCollectionTraversalCallback *cb)
2184 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2186 if(This->nsnode_selector)
2187 note_cc_edge((nsISupports*)This->nsnode_selector, "This->nsnode_selector", cb);
2189 note_cc_edge((nsISupports*)This->nsdoc, "This->nsdoc", cb);
2192 static void HTMLDocumentNode_unlink(HTMLDOMNode *iface)
2194 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2196 if(This->nsnode_selector) {
2197 nsIDOMNodeSelector_Release(This->nsnode_selector);
2198 This->nsnode_selector = NULL;
2202 nsIDOMHTMLDocument *nsdoc = This->nsdoc;
2204 release_document_mutation(This);
2206 nsIDOMHTMLDocument_Release(nsdoc);
2207 This->window = NULL;
2211 static const NodeImplVtbl HTMLDocumentNodeImplVtbl = {
2212 HTMLDocumentNode_QI,
2213 HTMLDocumentNode_destructor,
2215 HTMLDocumentNode_clone,
2227 HTMLDocumentNode_traverse,
2228 HTMLDocumentNode_unlink
2231 static HRESULT HTMLDocumentFragment_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
2233 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2234 HTMLDocumentNode *new_node;
2237 hres = create_document_fragment(nsnode, This->node.doc, &new_node);
2241 *ret = &new_node->node;
2245 static inline HTMLDocumentNode *impl_from_DispatchEx(DispatchEx *iface)
2247 return CONTAINING_RECORD(iface, HTMLDocumentNode, node.dispex);
2250 static HRESULT HTMLDocumentNode_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
2251 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2253 HTMLDocumentNode *This = impl_from_DispatchEx(dispex);
2254 nsIDOMNodeList *node_list;
2262 if(flags != DISPATCH_PROPERTYGET && flags != (DISPATCH_METHOD|DISPATCH_PROPERTYGET)) {
2263 FIXME("unsupported flags %x\n", flags);
2267 i = id - MSHTML_DISPID_CUSTOM_MIN;
2269 if(!This->nsdoc || i >= This->elem_vars_cnt)
2270 return DISP_E_UNKNOWNNAME;
2272 nsAString_InitDepend(&name_str, This->elem_vars[i]);
2273 nsres = nsIDOMHTMLDocument_GetElementsByName(This->nsdoc, &name_str, &node_list);
2274 nsAString_Finish(&name_str);
2275 if(NS_FAILED(nsres))
2278 nsres = nsIDOMNodeList_Item(node_list, 0, &nsnode);
2279 nsIDOMNodeList_Release(node_list);
2280 if(NS_FAILED(nsres) || !nsnode)
2281 return DISP_E_UNKNOWNNAME;
2283 hres = get_node(This, nsnode, TRUE, &node);
2287 V_VT(res) = VT_DISPATCH;
2288 V_DISPATCH(res) = (IDispatch*)&node->IHTMLDOMNode_iface;
2293 static const dispex_static_data_vtbl_t HTMLDocumentNode_dispex_vtbl = {
2296 HTMLDocumentNode_invoke,
2300 static const NodeImplVtbl HTMLDocumentFragmentImplVtbl = {
2301 HTMLDocumentNode_QI,
2302 HTMLDocumentNode_destructor,
2304 HTMLDocumentFragment_clone
2307 static const tid_t HTMLDocumentNode_iface_tids[] = {
2317 static dispex_static_data_t HTMLDocumentNode_dispex = {
2318 &HTMLDocumentNode_dispex_vtbl,
2319 DispHTMLDocument_tid,
2321 HTMLDocumentNode_iface_tids
2324 static HTMLDocumentNode *alloc_doc_node(HTMLDocumentObj *doc_obj, HTMLInnerWindow *window)
2326 HTMLDocumentNode *doc;
2328 doc = heap_alloc_zero(sizeof(HTMLDocumentNode));
2333 doc->basedoc.doc_node = doc;
2334 doc->basedoc.doc_obj = doc_obj;
2335 doc->basedoc.window = window->base.outer_window;
2336 doc->window = window;
2338 init_dispex(&doc->node.dispex, (IUnknown*)&doc->node.IHTMLDOMNode_iface,
2339 &HTMLDocumentNode_dispex);
2340 init_doc(&doc->basedoc, (IUnknown*)&doc->node.IHTMLDOMNode_iface,
2341 &doc->node.dispex.IDispatchEx_iface);
2342 HTMLDocumentNode_SecMgr_Init(doc);
2344 list_init(&doc->selection_list);
2345 list_init(&doc->range_list);
2346 list_init(&doc->plugin_hosts);
2351 HRESULT create_doc_from_nsdoc(nsIDOMHTMLDocument *nsdoc, HTMLDocumentObj *doc_obj, HTMLInnerWindow *window, HTMLDocumentNode **ret)
2353 HTMLDocumentNode *doc;
2356 doc = alloc_doc_node(doc_obj, window);
2358 return E_OUTOFMEMORY;
2360 if(!doc_obj->basedoc.window || window->base.outer_window == doc_obj->basedoc.window)
2361 doc->basedoc.cp_container.forward_container = &doc_obj->basedoc.cp_container;
2363 HTMLDOMNode_Init(doc, &doc->node, (nsIDOMNode*)nsdoc);
2365 nsIDOMHTMLDocument_AddRef(nsdoc);
2368 nsres = nsIDOMHTMLDocument_QueryInterface(nsdoc, &IID_nsIDOMNodeSelector, (void**)&doc->nsnode_selector);
2369 assert(nsres == NS_OK);
2371 init_document_mutation(doc);
2372 doc_init_events(doc);
2374 doc->node.vtbl = &HTMLDocumentNodeImplVtbl;
2375 doc->node.cp_container = &doc->basedoc.cp_container;
2381 HRESULT create_document_fragment(nsIDOMNode *nsnode, HTMLDocumentNode *doc_node, HTMLDocumentNode **ret)
2383 HTMLDocumentNode *doc_frag;
2385 doc_frag = alloc_doc_node(doc_node->basedoc.doc_obj, doc_node->window);
2387 return E_OUTOFMEMORY;
2389 IHTMLWindow2_AddRef(&doc_frag->window->base.IHTMLWindow2_iface);
2391 HTMLDOMNode_Init(doc_node, &doc_frag->node, nsnode);
2392 doc_frag->node.vtbl = &HTMLDocumentFragmentImplVtbl;
2393 doc_frag->node.cp_container = &doc_frag->basedoc.cp_container;
2399 /**********************************************************
2400 * ICustomDoc implementation
2403 static inline HTMLDocumentObj *impl_from_ICustomDoc(ICustomDoc *iface)
2405 return CONTAINING_RECORD(iface, HTMLDocumentObj, ICustomDoc_iface);
2408 static HRESULT WINAPI CustomDoc_QueryInterface(ICustomDoc *iface, REFIID riid, void **ppv)
2410 HTMLDocumentObj *This = impl_from_ICustomDoc(iface);
2412 if(htmldoc_qi(&This->basedoc, riid, ppv))
2413 return *ppv ? S_OK : E_NOINTERFACE;
2415 if(IsEqualGUID(&IID_ICustomDoc, riid)) {
2416 TRACE("(%p)->(IID_ICustomDoc %p)\n", This, ppv);
2417 *ppv = &This->ICustomDoc_iface;
2418 }else if(IsEqualGUID(&IID_ITargetContainer, riid)) {
2419 TRACE("(%p)->(IID_ITargetContainer %p)\n", This, ppv);
2420 *ppv = &This->ITargetContainer_iface;
2421 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
2422 return *ppv ? S_OK : E_NOINTERFACE;
2424 FIXME("Unimplemented interface %s\n", debugstr_guid(riid));
2426 return E_NOINTERFACE;
2429 IUnknown_AddRef((IUnknown*)*ppv);
2433 static ULONG WINAPI CustomDoc_AddRef(ICustomDoc *iface)
2435 HTMLDocumentObj *This = impl_from_ICustomDoc(iface);
2436 ULONG ref = InterlockedIncrement(&This->ref);
2438 TRACE("(%p) ref = %u\n", This, ref);
2443 static ULONG WINAPI CustomDoc_Release(ICustomDoc *iface)
2445 HTMLDocumentObj *This = impl_from_ICustomDoc(iface);
2446 ULONG ref = InterlockedDecrement(&This->ref);
2448 TRACE("(%p) ref = %u\n", This, ref);
2451 nsIDOMWindowUtils *window_utils = NULL;
2453 if(This->basedoc.window && This->basedoc.window->nswindow)
2454 get_nsinterface((nsISupports*)This->basedoc.window->nswindow, &IID_nsIDOMWindowUtils, (void**)&window_utils);
2456 if(This->basedoc.doc_node) {
2457 This->basedoc.doc_node->basedoc.doc_obj = NULL;
2458 htmldoc_release(&This->basedoc.doc_node->basedoc);
2460 if(This->basedoc.window) {
2461 This->basedoc.window->doc_obj = NULL;
2462 IHTMLWindow2_Release(&This->basedoc.window->base.IHTMLWindow2_iface);
2464 if(This->basedoc.advise_holder)
2465 IOleAdviseHolder_Release(This->basedoc.advise_holder);
2468 IAdviseSink_Release(This->view_sink);
2470 IOleObject_SetClientSite(&This->basedoc.IOleObject_iface, NULL);
2472 ICustomDoc_SetUIHandler(&This->ICustomDoc_iface, NULL);
2473 if(This->in_place_active)
2474 IOleInPlaceObjectWindowless_InPlaceDeactivate(&This->basedoc.IOleInPlaceObjectWindowless_iface);
2476 IOleDocumentView_SetInPlaceSite(&This->basedoc.IOleDocumentView_iface, NULL);
2478 IOleUndoManager_Release(This->undomgr);
2479 if(This->tooltips_hwnd)
2480 DestroyWindow(This->tooltips_hwnd);
2483 DestroyWindow(This->hwnd);
2484 heap_free(This->mime);
2486 destroy_htmldoc(&This->basedoc);
2487 release_dispex(&This->dispex);
2489 if(This->nscontainer)
2490 NSContainer_Release(This->nscontainer);
2493 /* Force cycle collection */
2495 nsIDOMWindowUtils_CycleCollect(window_utils, NULL, 0);
2496 nsIDOMWindowUtils_Release(window_utils);
2503 static HRESULT WINAPI CustomDoc_SetUIHandler(ICustomDoc *iface, IDocHostUIHandler *pUIHandler)
2505 HTMLDocumentObj *This = impl_from_ICustomDoc(iface);
2506 IOleCommandTarget *cmdtrg;
2509 TRACE("(%p)->(%p)\n", This, pUIHandler);
2511 if(This->custom_hostui && This->hostui == pUIHandler)
2514 This->custom_hostui = TRUE;
2517 IDocHostUIHandler_Release(This->hostui);
2519 IDocHostUIHandler_AddRef(pUIHandler);
2520 This->hostui = pUIHandler;
2524 hres = IDocHostUIHandler_QueryInterface(pUIHandler, &IID_IOleCommandTarget, (void**)&cmdtrg);
2525 if(SUCCEEDED(hres)) {
2526 FIXME("custom UI handler supports IOleCommandTarget\n");
2527 IOleCommandTarget_Release(cmdtrg);
2533 static const ICustomDocVtbl CustomDocVtbl = {
2534 CustomDoc_QueryInterface,
2537 CustomDoc_SetUIHandler
2540 static const tid_t HTMLDocumentObj_iface_tids[] = {
2547 static dispex_static_data_t HTMLDocumentObj_dispex = {
2549 DispHTMLDocument_tid,
2551 HTMLDocumentObj_iface_tids
2554 HRESULT HTMLDocument_Create(IUnknown *pUnkOuter, REFIID riid, void** ppvObject)
2556 HTMLDocumentObj *doc;
2557 nsIDOMWindow *nswindow = NULL;
2561 TRACE("(%p %s %p)\n", pUnkOuter, debugstr_guid(riid), ppvObject);
2563 doc = heap_alloc_zero(sizeof(HTMLDocumentObj));
2565 return E_OUTOFMEMORY;
2567 init_dispex(&doc->dispex, (IUnknown*)&doc->ICustomDoc_iface, &HTMLDocumentObj_dispex);
2568 init_doc(&doc->basedoc, (IUnknown*)&doc->ICustomDoc_iface, &doc->dispex.IDispatchEx_iface);
2569 TargetContainer_Init(doc);
2571 doc->ICustomDoc_iface.lpVtbl = &CustomDocVtbl;
2573 doc->basedoc.doc_obj = doc;
2575 doc->usermode = UNKNOWN_USERMODE;
2577 init_binding_ui(doc);
2579 hres = create_nscontainer(doc, &doc->nscontainer);
2581 ERR("Failed to init Gecko, returning CLASS_E_CLASSNOTAVAILABLE\n");
2582 htmldoc_release(&doc->basedoc);
2586 hres = htmldoc_query_interface(&doc->basedoc, riid, ppvObject);
2587 htmldoc_release(&doc->basedoc);
2591 nsres = nsIWebBrowser_GetContentDOMWindow(doc->nscontainer->webbrowser, &nswindow);
2592 if(NS_FAILED(nsres))
2593 ERR("GetContentDOMWindow failed: %08x\n", nsres);
2595 hres = HTMLOuterWindow_Create(doc, nswindow, NULL /* FIXME */, &doc->basedoc.window);
2597 nsIDOMWindow_Release(nswindow);
2599 htmldoc_release(&doc->basedoc);
2603 if(!doc->basedoc.doc_node && doc->basedoc.window->base.inner_window->doc) {
2604 doc->basedoc.doc_node = doc->basedoc.window->base.inner_window->doc;
2605 htmldoc_addref(&doc->basedoc.doc_node->basedoc);