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);
416 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
420 static HRESULT WINAPI HTMLDocument_get_designMode(IHTMLDocument2 *iface, BSTR *p)
422 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
423 static WCHAR szOff[] = {'O','f','f',0};
424 FIXME("(%p)->(%p) always returning Off\n", This, p);
429 *p = SysAllocString(szOff);
434 static HRESULT WINAPI HTMLDocument_get_selection(IHTMLDocument2 *iface, IHTMLSelectionObject **p)
436 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
437 nsISelection *nsselection;
440 TRACE("(%p)->(%p)\n", This, p);
442 nsres = nsIDOMWindow_GetSelection(This->window->nswindow, &nsselection);
443 if(NS_FAILED(nsres)) {
444 ERR("GetSelection failed: %08x\n", nsres);
448 return HTMLSelectionObject_Create(This->doc_node, nsselection, p);
451 static HRESULT WINAPI HTMLDocument_get_readyState(IHTMLDocument2 *iface, BSTR *p)
453 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
455 static const WCHAR wszUninitialized[] = {'u','n','i','n','i','t','i','a','l','i','z','e','d',0};
456 static const WCHAR wszLoading[] = {'l','o','a','d','i','n','g',0};
457 static const WCHAR wszLoaded[] = {'l','o','a','d','e','d',0};
458 static const WCHAR wszInteractive[] = {'i','n','t','e','r','a','c','t','i','v','e',0};
459 static const WCHAR wszComplete[] = {'c','o','m','p','l','e','t','e',0};
461 static const LPCWSTR readystate_str[] = {
469 TRACE("(%p)->(%p)\n", iface, p);
474 *p = SysAllocString(readystate_str[This->window->readystate]);
478 static HRESULT WINAPI HTMLDocument_get_frames(IHTMLDocument2 *iface, IHTMLFramesCollection2 **p)
480 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
482 TRACE("(%p)->(%p)\n", This, p);
484 return IHTMLWindow2_get_frames(&This->window->base.IHTMLWindow2_iface, p);
487 static HRESULT WINAPI HTMLDocument_get_embeds(IHTMLDocument2 *iface, IHTMLElementCollection **p)
489 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
490 FIXME("(%p)->(%p)\n", This, p);
494 static HRESULT WINAPI HTMLDocument_get_plugins(IHTMLDocument2 *iface, IHTMLElementCollection **p)
496 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
497 FIXME("(%p)->(%p)\n", This, p);
501 static HRESULT WINAPI HTMLDocument_put_alinkColor(IHTMLDocument2 *iface, VARIANT v)
503 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
504 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
508 static HRESULT WINAPI HTMLDocument_get_alinkColor(IHTMLDocument2 *iface, VARIANT *p)
510 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
511 FIXME("(%p)->(%p)\n", This, p);
515 static HRESULT WINAPI HTMLDocument_put_bgColor(IHTMLDocument2 *iface, VARIANT v)
517 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
518 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
522 static HRESULT WINAPI HTMLDocument_get_bgColor(IHTMLDocument2 *iface, VARIANT *p)
524 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
525 FIXME("(%p)->(%p)\n", This, p);
529 static HRESULT WINAPI HTMLDocument_put_fgColor(IHTMLDocument2 *iface, VARIANT v)
531 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
532 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
536 static HRESULT WINAPI HTMLDocument_get_fgColor(IHTMLDocument2 *iface, VARIANT *p)
538 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
539 FIXME("(%p)->(%p)\n", This, p);
543 static HRESULT WINAPI HTMLDocument_put_linkColor(IHTMLDocument2 *iface, VARIANT v)
545 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
546 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
550 static HRESULT WINAPI HTMLDocument_get_linkColor(IHTMLDocument2 *iface, VARIANT *p)
552 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
553 FIXME("(%p)->(%p)\n", This, p);
557 static HRESULT WINAPI HTMLDocument_put_vlinkColor(IHTMLDocument2 *iface, VARIANT v)
559 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
560 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
564 static HRESULT WINAPI HTMLDocument_get_vlinkColor(IHTMLDocument2 *iface, VARIANT *p)
566 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
567 FIXME("(%p)->(%p)\n", This, p);
571 static HRESULT WINAPI HTMLDocument_get_referrer(IHTMLDocument2 *iface, BSTR *p)
573 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
575 FIXME("(%p)->(%p)\n", This, p);
581 static HRESULT WINAPI HTMLDocument_get_location(IHTMLDocument2 *iface, IHTMLLocation **p)
583 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
585 TRACE("(%p)->(%p)\n", This, p);
587 if(!This->doc_node->nsdoc) {
588 WARN("NULL nsdoc\n");
592 return IHTMLWindow2_get_location(&This->window->base.IHTMLWindow2_iface, p);
595 static HRESULT WINAPI HTMLDocument_get_lastModified(IHTMLDocument2 *iface, BSTR *p)
597 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
598 FIXME("(%p)->(%p)\n", This, p);
602 static HRESULT WINAPI HTMLDocument_put_URL(IHTMLDocument2 *iface, BSTR v)
604 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
606 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
609 FIXME("No window available\n");
613 return navigate_url(This->window, v, This->window->uri, BINDING_NAVIGATED);
616 static HRESULT WINAPI HTMLDocument_get_URL(IHTMLDocument2 *iface, BSTR *p)
618 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
620 static const WCHAR about_blank_url[] =
621 {'a','b','o','u','t',':','b','l','a','n','k',0};
623 TRACE("(%p)->(%p)\n", iface, p);
625 *p = SysAllocString(This->window->url ? This->window->url : about_blank_url);
626 return *p ? S_OK : E_OUTOFMEMORY;
629 static HRESULT WINAPI HTMLDocument_put_domain(IHTMLDocument2 *iface, BSTR v)
631 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
632 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
636 static HRESULT WINAPI HTMLDocument_get_domain(IHTMLDocument2 *iface, BSTR *p)
638 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
641 TRACE("(%p)->(%p)\n", This, p);
643 if(!This->window || !This->window->uri) {
644 FIXME("No current URI\n");
648 hres = IUri_GetHost(This->window->uri, p);
649 return FAILED(hres) ? hres : S_OK;
652 static HRESULT WINAPI HTMLDocument_put_cookie(IHTMLDocument2 *iface, BSTR v)
654 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
657 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
659 bret = InternetSetCookieExW(This->window->url, NULL, v, 0, 0);
661 FIXME("InternetSetCookieExW failed: %u\n", GetLastError());
662 return HRESULT_FROM_WIN32(GetLastError());
668 static HRESULT WINAPI HTMLDocument_get_cookie(IHTMLDocument2 *iface, BSTR *p)
670 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
674 TRACE("(%p)->(%p)\n", This, p);
677 bret = InternetGetCookieExW(This->window->url, NULL, NULL, &size, 0, NULL);
679 switch(GetLastError()) {
680 case ERROR_INSUFFICIENT_BUFFER:
682 case ERROR_NO_MORE_ITEMS:
686 FIXME("InternetGetCookieExW failed: %u\n", GetLastError());
687 return HRESULT_FROM_WIN32(GetLastError());
696 *p = SysAllocStringLen(NULL, size-1);
698 return E_OUTOFMEMORY;
700 bret = InternetGetCookieExW(This->window->url, NULL, *p, &size, 0, NULL);
702 ERR("InternetGetCookieExW failed: %u\n", GetLastError());
709 static HRESULT WINAPI HTMLDocument_put_expando(IHTMLDocument2 *iface, VARIANT_BOOL v)
711 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
712 FIXME("(%p)->(%x)\n", This, v);
716 static HRESULT WINAPI HTMLDocument_get_expando(IHTMLDocument2 *iface, VARIANT_BOOL *p)
718 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
719 FIXME("(%p)->(%p)\n", This, p);
723 static HRESULT WINAPI HTMLDocument_put_charset(IHTMLDocument2 *iface, BSTR v)
725 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
726 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
730 static HRESULT WINAPI HTMLDocument_get_charset(IHTMLDocument2 *iface, BSTR *p)
732 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
733 nsAString charset_str;
736 TRACE("(%p)->(%p)\n", This, p);
738 if(!This->doc_node->nsdoc) {
739 FIXME("NULL nsdoc\n");
743 nsAString_Init(&charset_str, NULL);
744 nsres = nsIDOMHTMLDocument_GetCharacterSet(This->doc_node->nsdoc, &charset_str);
745 return return_nsstr(nsres, &charset_str, p);
748 static HRESULT WINAPI HTMLDocument_put_defaultCharset(IHTMLDocument2 *iface, BSTR v)
750 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
751 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
755 static HRESULT WINAPI HTMLDocument_get_defaultCharset(IHTMLDocument2 *iface, BSTR *p)
757 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
758 FIXME("(%p)->(%p)\n", This, p);
762 static HRESULT WINAPI HTMLDocument_get_mimeType(IHTMLDocument2 *iface, BSTR *p)
764 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
765 FIXME("(%p)->(%p)\n", This, p);
769 static HRESULT WINAPI HTMLDocument_get_fileSize(IHTMLDocument2 *iface, BSTR *p)
771 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
772 FIXME("(%p)->(%p)\n", This, p);
776 static HRESULT WINAPI HTMLDocument_get_fileCreatedDate(IHTMLDocument2 *iface, BSTR *p)
778 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
779 FIXME("(%p)->(%p)\n", This, p);
783 static HRESULT WINAPI HTMLDocument_get_fileModifiedDate(IHTMLDocument2 *iface, BSTR *p)
785 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
786 FIXME("(%p)->(%p)\n", This, p);
790 static HRESULT WINAPI HTMLDocument_get_fileUpdatedDate(IHTMLDocument2 *iface, BSTR *p)
792 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
793 FIXME("(%p)->(%p)\n", This, p);
797 static HRESULT WINAPI HTMLDocument_get_security(IHTMLDocument2 *iface, BSTR *p)
799 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
800 FIXME("(%p)->(%p)\n", This, p);
804 static HRESULT WINAPI HTMLDocument_get_protocol(IHTMLDocument2 *iface, BSTR *p)
806 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
807 FIXME("(%p)->(%p)\n", This, p);
811 static HRESULT WINAPI HTMLDocument_get_nameProp(IHTMLDocument2 *iface, BSTR *p)
813 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
814 FIXME("(%p)->(%p)\n", This, p);
818 static HRESULT document_write(HTMLDocument *This, SAFEARRAY *psarray, BOOL ln)
826 if(!This->doc_node->nsdoc) {
827 WARN("NULL nsdoc\n");
834 if(psarray->cDims != 1) {
835 FIXME("cDims=%d\n", psarray->cDims);
839 hres = SafeArrayAccessData(psarray, (void**)&var);
841 WARN("SafeArrayAccessData failed: %08x\n", hres);
845 V_VT(&tmp) = VT_EMPTY;
847 argc = psarray->rgsabound[0].cElements;
848 for(i=0; i < argc; i++) {
849 if(V_VT(var+i) == VT_BSTR) {
850 nsAString_InitDepend(&nsstr, V_BSTR(var+i));
852 hres = VariantChangeTypeEx(&tmp, var+i, MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT), 0, VT_BSTR);
854 WARN("Could not convert %s to string\n", debugstr_variant(var+i));
857 nsAString_InitDepend(&nsstr, V_BSTR(&tmp));
860 if(!ln || i != argc-1)
861 nsres = nsIDOMHTMLDocument_Write(This->doc_node->nsdoc, &nsstr, NULL /* FIXME! */);
863 nsres = nsIDOMHTMLDocument_Writeln(This->doc_node->nsdoc, &nsstr, NULL /* FIXME! */);
864 nsAString_Finish(&nsstr);
865 if(V_VT(var+i) != VT_BSTR)
867 if(NS_FAILED(nsres)) {
868 ERR("Write failed: %08x\n", nsres);
874 SafeArrayUnaccessData(psarray);
879 static HRESULT WINAPI HTMLDocument_write(IHTMLDocument2 *iface, SAFEARRAY *psarray)
881 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
883 TRACE("(%p)->(%p)\n", iface, psarray);
885 return document_write(This, psarray, FALSE);
888 static HRESULT WINAPI HTMLDocument_writeln(IHTMLDocument2 *iface, SAFEARRAY *psarray)
890 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
892 TRACE("(%p)->(%p)\n", This, psarray);
894 return document_write(This, psarray, TRUE);
897 static HRESULT WINAPI HTMLDocument_open(IHTMLDocument2 *iface, BSTR url, VARIANT name,
898 VARIANT features, VARIANT replace, IDispatch **pomWindowResult)
900 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
904 static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};
906 TRACE("(%p)->(%s %s %s %s %p)\n", This, debugstr_w(url), debugstr_variant(&name),
907 debugstr_variant(&features), debugstr_variant(&replace), pomWindowResult);
909 if(!This->doc_node->nsdoc) {
914 if(!url || strcmpW(url, text_htmlW) || V_VT(&name) != VT_ERROR
915 || V_VT(&features) != VT_ERROR || V_VT(&replace) != VT_ERROR)
916 FIXME("unsupported args\n");
918 nsres = nsIDOMHTMLDocument_Open(This->doc_node->nsdoc, NULL, NULL, NULL, NULL, 0, &tmp);
919 if(NS_FAILED(nsres)) {
920 ERR("Open failed: %08x\n", nsres);
925 nsISupports_Release(tmp);
927 *pomWindowResult = (IDispatch*)&This->window->base.IHTMLWindow2_iface;
928 IHTMLWindow2_AddRef(&This->window->base.IHTMLWindow2_iface);
932 static HRESULT WINAPI HTMLDocument_close(IHTMLDocument2 *iface)
934 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
937 TRACE("(%p)\n", This);
939 if(!This->doc_node->nsdoc) {
944 nsres = nsIDOMHTMLDocument_Close(This->doc_node->nsdoc);
945 if(NS_FAILED(nsres)) {
946 ERR("Close failed: %08x\n", nsres);
953 static HRESULT WINAPI HTMLDocument_clear(IHTMLDocument2 *iface)
955 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
958 TRACE("(%p)\n", This);
960 nsres = nsIDOMHTMLDocument_Clear(This->doc_node->nsdoc);
961 if(NS_FAILED(nsres)) {
962 ERR("Clear failed: %08x\n", nsres);
969 static HRESULT WINAPI HTMLDocument_queryCommandSupported(IHTMLDocument2 *iface, BSTR cmdID,
972 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
973 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
977 static HRESULT WINAPI HTMLDocument_queryCommandEnabled(IHTMLDocument2 *iface, BSTR cmdID,
980 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
981 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
985 static HRESULT WINAPI HTMLDocument_queryCommandState(IHTMLDocument2 *iface, BSTR cmdID,
988 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
989 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
993 static HRESULT WINAPI HTMLDocument_queryCommandIndeterm(IHTMLDocument2 *iface, BSTR cmdID,
996 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
997 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1001 static HRESULT WINAPI HTMLDocument_queryCommandText(IHTMLDocument2 *iface, BSTR cmdID,
1004 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1005 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1009 static HRESULT WINAPI HTMLDocument_queryCommandValue(IHTMLDocument2 *iface, BSTR cmdID,
1012 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1013 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1017 static HRESULT WINAPI HTMLDocument_execCommand(IHTMLDocument2 *iface, BSTR cmdID,
1018 VARIANT_BOOL showUI, VARIANT value, VARIANT_BOOL *pfRet)
1020 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1021 FIXME("(%p)->(%s %x %s %p)\n", This, debugstr_w(cmdID), showUI, debugstr_variant(&value), pfRet);
1025 static HRESULT WINAPI HTMLDocument_execCommandShowHelp(IHTMLDocument2 *iface, BSTR cmdID,
1026 VARIANT_BOOL *pfRet)
1028 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1029 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1033 static HRESULT WINAPI HTMLDocument_createElement(IHTMLDocument2 *iface, BSTR eTag,
1034 IHTMLElement **newElem)
1036 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1040 TRACE("(%p)->(%s %p)\n", This, debugstr_w(eTag), newElem);
1042 hres = create_element(This->doc_node, eTag, &elem);
1046 *newElem = &elem->IHTMLElement_iface;
1050 static HRESULT WINAPI HTMLDocument_put_onhelp(IHTMLDocument2 *iface, VARIANT v)
1052 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1053 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1057 static HRESULT WINAPI HTMLDocument_get_onhelp(IHTMLDocument2 *iface, VARIANT *p)
1059 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1060 FIXME("(%p)->(%p)\n", This, p);
1064 static HRESULT WINAPI HTMLDocument_put_onclick(IHTMLDocument2 *iface, VARIANT v)
1066 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1068 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1070 return set_doc_event(This, EVENTID_CLICK, &v);
1073 static HRESULT WINAPI HTMLDocument_get_onclick(IHTMLDocument2 *iface, VARIANT *p)
1075 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1077 TRACE("(%p)->(%p)\n", This, p);
1079 return get_doc_event(This, EVENTID_CLICK, p);
1082 static HRESULT WINAPI HTMLDocument_put_ondblclick(IHTMLDocument2 *iface, VARIANT v)
1084 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1085 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1089 static HRESULT WINAPI HTMLDocument_get_ondblclick(IHTMLDocument2 *iface, VARIANT *p)
1091 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1092 FIXME("(%p)->(%p)\n", This, p);
1096 static HRESULT WINAPI HTMLDocument_put_onkeyup(IHTMLDocument2 *iface, VARIANT v)
1098 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1100 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1102 return set_doc_event(This, EVENTID_KEYUP, &v);
1105 static HRESULT WINAPI HTMLDocument_get_onkeyup(IHTMLDocument2 *iface, VARIANT *p)
1107 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1109 TRACE("(%p)->(%p)\n", This, p);
1111 return get_doc_event(This, EVENTID_KEYUP, p);
1114 static HRESULT WINAPI HTMLDocument_put_onkeydown(IHTMLDocument2 *iface, VARIANT v)
1116 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1118 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1120 return set_doc_event(This, EVENTID_KEYDOWN, &v);
1123 static HRESULT WINAPI HTMLDocument_get_onkeydown(IHTMLDocument2 *iface, VARIANT *p)
1125 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1127 TRACE("(%p)->(%p)\n", This, p);
1129 return get_doc_event(This, EVENTID_KEYDOWN, p);
1132 static HRESULT WINAPI HTMLDocument_put_onkeypress(IHTMLDocument2 *iface, VARIANT v)
1134 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1136 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1138 return set_doc_event(This, EVENTID_KEYPRESS, &v);
1141 static HRESULT WINAPI HTMLDocument_get_onkeypress(IHTMLDocument2 *iface, VARIANT *p)
1143 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1145 TRACE("(%p)->(%p)\n", This, p);
1147 return get_doc_event(This, EVENTID_KEYPRESS, p);
1150 static HRESULT WINAPI HTMLDocument_put_onmouseup(IHTMLDocument2 *iface, VARIANT v)
1152 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1154 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1156 return set_doc_event(This, EVENTID_MOUSEUP, &v);
1159 static HRESULT WINAPI HTMLDocument_get_onmouseup(IHTMLDocument2 *iface, VARIANT *p)
1161 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1163 TRACE("(%p)->(%p)\n", This, p);
1165 return get_doc_event(This, EVENTID_MOUSEUP, p);
1168 static HRESULT WINAPI HTMLDocument_put_onmousedown(IHTMLDocument2 *iface, VARIANT v)
1170 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1172 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1174 return set_doc_event(This, EVENTID_MOUSEDOWN, &v);
1177 static HRESULT WINAPI HTMLDocument_get_onmousedown(IHTMLDocument2 *iface, VARIANT *p)
1179 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1181 TRACE("(%p)->(%p)\n", This, p);
1183 return get_doc_event(This, EVENTID_MOUSEDOWN, p);
1186 static HRESULT WINAPI HTMLDocument_put_onmousemove(IHTMLDocument2 *iface, VARIANT v)
1188 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1190 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1192 return set_doc_event(This, EVENTID_MOUSEMOVE, &v);
1195 static HRESULT WINAPI HTMLDocument_get_onmousemove(IHTMLDocument2 *iface, VARIANT *p)
1197 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1199 TRACE("(%p)->(%p)\n", This, p);
1201 return get_doc_event(This, EVENTID_MOUSEMOVE, p);
1204 static HRESULT WINAPI HTMLDocument_put_onmouseout(IHTMLDocument2 *iface, VARIANT v)
1206 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1208 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1210 return set_doc_event(This, EVENTID_MOUSEOUT, &v);
1213 static HRESULT WINAPI HTMLDocument_get_onmouseout(IHTMLDocument2 *iface, VARIANT *p)
1215 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1217 TRACE("(%p)->(%p)\n", This, p);
1219 return get_doc_event(This, EVENTID_MOUSEOUT, p);
1222 static HRESULT WINAPI HTMLDocument_put_onmouseover(IHTMLDocument2 *iface, VARIANT v)
1224 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1226 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1228 return set_doc_event(This, EVENTID_MOUSEOVER, &v);
1231 static HRESULT WINAPI HTMLDocument_get_onmouseover(IHTMLDocument2 *iface, VARIANT *p)
1233 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1235 TRACE("(%p)->(%p)\n", This, p);
1237 return get_doc_event(This, EVENTID_MOUSEOVER, p);
1240 static HRESULT WINAPI HTMLDocument_put_onreadystatechange(IHTMLDocument2 *iface, VARIANT v)
1242 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1244 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1246 return set_doc_event(This, EVENTID_READYSTATECHANGE, &v);
1249 static HRESULT WINAPI HTMLDocument_get_onreadystatechange(IHTMLDocument2 *iface, VARIANT *p)
1251 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1253 TRACE("(%p)->(%p)\n", This, p);
1255 return get_doc_event(This, EVENTID_READYSTATECHANGE, p);
1258 static HRESULT WINAPI HTMLDocument_put_onafterupdate(IHTMLDocument2 *iface, VARIANT v)
1260 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1261 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1265 static HRESULT WINAPI HTMLDocument_get_onafterupdate(IHTMLDocument2 *iface, VARIANT *p)
1267 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1268 FIXME("(%p)->(%p)\n", This, p);
1272 static HRESULT WINAPI HTMLDocument_put_onrowexit(IHTMLDocument2 *iface, VARIANT v)
1274 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1275 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1279 static HRESULT WINAPI HTMLDocument_get_onrowexit(IHTMLDocument2 *iface, VARIANT *p)
1281 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1282 FIXME("(%p)->(%p)\n", This, p);
1286 static HRESULT WINAPI HTMLDocument_put_onrowenter(IHTMLDocument2 *iface, VARIANT v)
1288 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1289 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1293 static HRESULT WINAPI HTMLDocument_get_onrowenter(IHTMLDocument2 *iface, VARIANT *p)
1295 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1296 FIXME("(%p)->(%p)\n", This, p);
1300 static HRESULT WINAPI HTMLDocument_put_ondragstart(IHTMLDocument2 *iface, VARIANT v)
1302 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1304 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1306 return set_doc_event(This, EVENTID_DRAGSTART, &v);
1309 static HRESULT WINAPI HTMLDocument_get_ondragstart(IHTMLDocument2 *iface, VARIANT *p)
1311 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1313 TRACE("(%p)->(%p)\n", This, p);
1315 return get_doc_event(This, EVENTID_DRAGSTART, p);
1318 static HRESULT WINAPI HTMLDocument_put_onselectstart(IHTMLDocument2 *iface, VARIANT v)
1320 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1322 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1324 return set_doc_event(This, EVENTID_SELECTSTART, &v);
1327 static HRESULT WINAPI HTMLDocument_get_onselectstart(IHTMLDocument2 *iface, VARIANT *p)
1329 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1331 TRACE("(%p)->(%p)\n", This, p);
1333 return get_doc_event(This, EVENTID_SELECTSTART, p);
1336 static HRESULT WINAPI HTMLDocument_elementFromPoint(IHTMLDocument2 *iface, LONG x, LONG y,
1337 IHTMLElement **elementHit)
1339 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1340 nsIDOMElement *nselem;
1345 TRACE("(%p)->(%d %d %p)\n", This, x, y, elementHit);
1347 nsres = nsIDOMHTMLDocument_ElementFromPoint(This->doc_node->nsdoc, x, y, &nselem);
1348 if(NS_FAILED(nsres)) {
1349 ERR("ElementFromPoint failed: %08x\n", nsres);
1358 hres = get_node(This->doc_node, (nsIDOMNode*)nselem, TRUE, &node);
1359 nsIDOMElement_Release(nselem);
1363 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)elementHit);
1368 static HRESULT WINAPI HTMLDocument_get_parentWindow(IHTMLDocument2 *iface, IHTMLWindow2 **p)
1370 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1372 TRACE("(%p)->(%p)\n", This, p);
1374 *p = &This->window->base.IHTMLWindow2_iface;
1375 IHTMLWindow2_AddRef(*p);
1379 static HRESULT WINAPI HTMLDocument_get_styleSheets(IHTMLDocument2 *iface,
1380 IHTMLStyleSheetsCollection **p)
1382 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1383 nsIDOMStyleSheetList *nsstylelist;
1386 TRACE("(%p)->(%p)\n", This, p);
1390 if(!This->doc_node->nsdoc) {
1391 WARN("NULL nsdoc\n");
1392 return E_UNEXPECTED;
1395 nsres = nsIDOMHTMLDocument_GetStyleSheets(This->doc_node->nsdoc, &nsstylelist);
1396 if(NS_FAILED(nsres)) {
1397 ERR("GetStyleSheets failed: %08x\n", nsres);
1401 *p = HTMLStyleSheetsCollection_Create(nsstylelist);
1402 nsIDOMStyleSheetList_Release(nsstylelist);
1407 static HRESULT WINAPI HTMLDocument_put_onbeforeupdate(IHTMLDocument2 *iface, VARIANT v)
1409 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1410 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1414 static HRESULT WINAPI HTMLDocument_get_onbeforeupdate(IHTMLDocument2 *iface, VARIANT *p)
1416 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1417 FIXME("(%p)->(%p)\n", This, p);
1421 static HRESULT WINAPI HTMLDocument_put_onerrorupdate(IHTMLDocument2 *iface, VARIANT v)
1423 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1424 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1428 static HRESULT WINAPI HTMLDocument_get_onerrorupdate(IHTMLDocument2 *iface, VARIANT *p)
1430 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1431 FIXME("(%p)->(%p)\n", This, p);
1435 static HRESULT WINAPI HTMLDocument_toString(IHTMLDocument2 *iface, BSTR *String)
1437 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1438 FIXME("(%p)->(%p)\n", This, String);
1442 static HRESULT WINAPI HTMLDocument_createStyleSheet(IHTMLDocument2 *iface, BSTR bstrHref,
1443 LONG lIndex, IHTMLStyleSheet **ppnewStyleSheet)
1445 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1446 nsIDOMHTMLHeadElement *head_elem;
1447 IHTMLStyleElement *style_elem;
1452 static const WCHAR styleW[] = {'s','t','y','l','e',0};
1454 TRACE("(%p)->(%s %d %p)\n", This, debugstr_w(bstrHref), lIndex, ppnewStyleSheet);
1456 if(!This->doc_node->nsdoc) {
1457 FIXME("not a real doc object\n");
1462 FIXME("Unsupported lIndex %d\n", lIndex);
1465 FIXME("semi-stub for href %s\n", debugstr_w(bstrHref));
1466 *ppnewStyleSheet = HTMLStyleSheet_Create(NULL);
1470 hres = create_element(This->doc_node, styleW, &elem);
1474 nsres = nsIDOMHTMLDocument_GetHead(This->doc_node->nsdoc, &head_elem);
1475 if(NS_SUCCEEDED(nsres)) {
1476 nsIDOMNode *tmp_node;
1478 nsres = nsIDOMHTMLHeadElement_AppendChild(head_elem, (nsIDOMNode*)elem->nselem, &tmp_node);
1479 nsIDOMHTMLHeadElement_Release(head_elem);
1480 if(NS_SUCCEEDED(nsres) && tmp_node)
1481 nsIDOMNode_Release(tmp_node);
1483 if(NS_FAILED(nsres)) {
1484 IHTMLElement_Release(&elem->IHTMLElement_iface);
1488 hres = IHTMLElement_QueryInterface(&elem->IHTMLElement_iface, &IID_IHTMLStyleElement, (void**)&style_elem);
1489 assert(hres == S_OK);
1490 IHTMLElement_Release(&elem->IHTMLElement_iface);
1492 hres = IHTMLStyleElement_get_styleSheet(style_elem, ppnewStyleSheet);
1493 IHTMLStyleElement_Release(style_elem);
1497 static const IHTMLDocument2Vtbl HTMLDocumentVtbl = {
1498 HTMLDocument_QueryInterface,
1499 HTMLDocument_AddRef,
1500 HTMLDocument_Release,
1501 HTMLDocument_GetTypeInfoCount,
1502 HTMLDocument_GetTypeInfo,
1503 HTMLDocument_GetIDsOfNames,
1504 HTMLDocument_Invoke,
1505 HTMLDocument_get_Script,
1506 HTMLDocument_get_all,
1507 HTMLDocument_get_body,
1508 HTMLDocument_get_activeElement,
1509 HTMLDocument_get_images,
1510 HTMLDocument_get_applets,
1511 HTMLDocument_get_links,
1512 HTMLDocument_get_forms,
1513 HTMLDocument_get_anchors,
1514 HTMLDocument_put_title,
1515 HTMLDocument_get_title,
1516 HTMLDocument_get_scripts,
1517 HTMLDocument_put_designMode,
1518 HTMLDocument_get_designMode,
1519 HTMLDocument_get_selection,
1520 HTMLDocument_get_readyState,
1521 HTMLDocument_get_frames,
1522 HTMLDocument_get_embeds,
1523 HTMLDocument_get_plugins,
1524 HTMLDocument_put_alinkColor,
1525 HTMLDocument_get_alinkColor,
1526 HTMLDocument_put_bgColor,
1527 HTMLDocument_get_bgColor,
1528 HTMLDocument_put_fgColor,
1529 HTMLDocument_get_fgColor,
1530 HTMLDocument_put_linkColor,
1531 HTMLDocument_get_linkColor,
1532 HTMLDocument_put_vlinkColor,
1533 HTMLDocument_get_vlinkColor,
1534 HTMLDocument_get_referrer,
1535 HTMLDocument_get_location,
1536 HTMLDocument_get_lastModified,
1537 HTMLDocument_put_URL,
1538 HTMLDocument_get_URL,
1539 HTMLDocument_put_domain,
1540 HTMLDocument_get_domain,
1541 HTMLDocument_put_cookie,
1542 HTMLDocument_get_cookie,
1543 HTMLDocument_put_expando,
1544 HTMLDocument_get_expando,
1545 HTMLDocument_put_charset,
1546 HTMLDocument_get_charset,
1547 HTMLDocument_put_defaultCharset,
1548 HTMLDocument_get_defaultCharset,
1549 HTMLDocument_get_mimeType,
1550 HTMLDocument_get_fileSize,
1551 HTMLDocument_get_fileCreatedDate,
1552 HTMLDocument_get_fileModifiedDate,
1553 HTMLDocument_get_fileUpdatedDate,
1554 HTMLDocument_get_security,
1555 HTMLDocument_get_protocol,
1556 HTMLDocument_get_nameProp,
1558 HTMLDocument_writeln,
1562 HTMLDocument_queryCommandSupported,
1563 HTMLDocument_queryCommandEnabled,
1564 HTMLDocument_queryCommandState,
1565 HTMLDocument_queryCommandIndeterm,
1566 HTMLDocument_queryCommandText,
1567 HTMLDocument_queryCommandValue,
1568 HTMLDocument_execCommand,
1569 HTMLDocument_execCommandShowHelp,
1570 HTMLDocument_createElement,
1571 HTMLDocument_put_onhelp,
1572 HTMLDocument_get_onhelp,
1573 HTMLDocument_put_onclick,
1574 HTMLDocument_get_onclick,
1575 HTMLDocument_put_ondblclick,
1576 HTMLDocument_get_ondblclick,
1577 HTMLDocument_put_onkeyup,
1578 HTMLDocument_get_onkeyup,
1579 HTMLDocument_put_onkeydown,
1580 HTMLDocument_get_onkeydown,
1581 HTMLDocument_put_onkeypress,
1582 HTMLDocument_get_onkeypress,
1583 HTMLDocument_put_onmouseup,
1584 HTMLDocument_get_onmouseup,
1585 HTMLDocument_put_onmousedown,
1586 HTMLDocument_get_onmousedown,
1587 HTMLDocument_put_onmousemove,
1588 HTMLDocument_get_onmousemove,
1589 HTMLDocument_put_onmouseout,
1590 HTMLDocument_get_onmouseout,
1591 HTMLDocument_put_onmouseover,
1592 HTMLDocument_get_onmouseover,
1593 HTMLDocument_put_onreadystatechange,
1594 HTMLDocument_get_onreadystatechange,
1595 HTMLDocument_put_onafterupdate,
1596 HTMLDocument_get_onafterupdate,
1597 HTMLDocument_put_onrowexit,
1598 HTMLDocument_get_onrowexit,
1599 HTMLDocument_put_onrowenter,
1600 HTMLDocument_get_onrowenter,
1601 HTMLDocument_put_ondragstart,
1602 HTMLDocument_get_ondragstart,
1603 HTMLDocument_put_onselectstart,
1604 HTMLDocument_get_onselectstart,
1605 HTMLDocument_elementFromPoint,
1606 HTMLDocument_get_parentWindow,
1607 HTMLDocument_get_styleSheets,
1608 HTMLDocument_put_onbeforeupdate,
1609 HTMLDocument_get_onbeforeupdate,
1610 HTMLDocument_put_onerrorupdate,
1611 HTMLDocument_get_onerrorupdate,
1612 HTMLDocument_toString,
1613 HTMLDocument_createStyleSheet
1616 static void HTMLDocument_on_advise(IUnknown *iface, cp_static_data_t *cp)
1618 HTMLDocument *This = impl_from_IHTMLDocument2((IHTMLDocument2*)iface);
1621 update_cp_events(This->window->base.inner_window, &This->doc_node->node.event_target, cp, This->doc_node->node.nsnode);
1624 static inline HTMLDocument *impl_from_ISupportErrorInfo(ISupportErrorInfo *iface)
1626 return CONTAINING_RECORD(iface, HTMLDocument, ISupportErrorInfo_iface);
1629 static HRESULT WINAPI SupportErrorInfo_QueryInterface(ISupportErrorInfo *iface, REFIID riid, void **ppv)
1631 HTMLDocument *This = impl_from_ISupportErrorInfo(iface);
1632 return htmldoc_query_interface(This, riid, ppv);
1635 static ULONG WINAPI SupportErrorInfo_AddRef(ISupportErrorInfo *iface)
1637 HTMLDocument *This = impl_from_ISupportErrorInfo(iface);
1638 return htmldoc_addref(This);
1641 static ULONG WINAPI SupportErrorInfo_Release(ISupportErrorInfo *iface)
1643 HTMLDocument *This = impl_from_ISupportErrorInfo(iface);
1644 return htmldoc_release(This);
1647 static HRESULT WINAPI SupportErrorInfo_InterfaceSupportsErrorInfo(ISupportErrorInfo *iface, REFIID riid)
1649 FIXME("(%p)->(%s)\n", iface, debugstr_guid(riid));
1653 static const ISupportErrorInfoVtbl SupportErrorInfoVtbl = {
1654 SupportErrorInfo_QueryInterface,
1655 SupportErrorInfo_AddRef,
1656 SupportErrorInfo_Release,
1657 SupportErrorInfo_InterfaceSupportsErrorInfo
1660 static inline HTMLDocument *impl_from_IDispatchEx(IDispatchEx *iface)
1662 return CONTAINING_RECORD(iface, HTMLDocument, IDispatchEx_iface);
1665 static HRESULT dispid_from_elem_name(HTMLDocumentNode *This, BSTR name, DISPID *dispid)
1667 nsIDOMNodeList *node_list;
1674 return DISP_E_UNKNOWNNAME;
1676 nsAString_InitDepend(&name_str, name);
1677 nsres = nsIDOMHTMLDocument_GetElementsByName(This->nsdoc, &name_str, &node_list);
1678 nsAString_Finish(&name_str);
1679 if(NS_FAILED(nsres))
1682 nsres = nsIDOMNodeList_GetLength(node_list, &len);
1683 nsIDOMNodeList_Release(node_list);
1684 if(NS_FAILED(nsres))
1688 return DISP_E_UNKNOWNNAME;
1690 for(i=0; i < This->elem_vars_cnt; i++) {
1691 if(!strcmpW(name, This->elem_vars[i])) {
1692 *dispid = MSHTML_DISPID_CUSTOM_MIN+i;
1697 if(This->elem_vars_cnt == This->elem_vars_size) {
1700 if(This->elem_vars_size) {
1701 new_vars = heap_realloc(This->elem_vars, This->elem_vars_size*2*sizeof(WCHAR*));
1703 return E_OUTOFMEMORY;
1704 This->elem_vars_size *= 2;
1706 new_vars = heap_alloc(16*sizeof(WCHAR*));
1708 return E_OUTOFMEMORY;
1709 This->elem_vars_size = 16;
1712 This->elem_vars = new_vars;
1715 This->elem_vars[This->elem_vars_cnt] = heap_strdupW(name);
1716 if(!This->elem_vars[This->elem_vars_cnt])
1717 return E_OUTOFMEMORY;
1719 *dispid = MSHTML_DISPID_CUSTOM_MIN+This->elem_vars_cnt++;
1723 static HRESULT WINAPI DocDispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
1725 HTMLDocument *This = impl_from_IDispatchEx(iface);
1727 return htmldoc_query_interface(This, riid, ppv);
1730 static ULONG WINAPI DocDispatchEx_AddRef(IDispatchEx *iface)
1732 HTMLDocument *This = impl_from_IDispatchEx(iface);
1734 return htmldoc_addref(This);
1737 static ULONG WINAPI DocDispatchEx_Release(IDispatchEx *iface)
1739 HTMLDocument *This = impl_from_IDispatchEx(iface);
1741 return htmldoc_release(This);
1744 static HRESULT WINAPI DocDispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
1746 HTMLDocument *This = impl_from_IDispatchEx(iface);
1748 return IDispatchEx_GetTypeInfoCount(This->dispex, pctinfo);
1751 static HRESULT WINAPI DocDispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
1752 LCID lcid, ITypeInfo **ppTInfo)
1754 HTMLDocument *This = impl_from_IDispatchEx(iface);
1756 return IDispatchEx_GetTypeInfo(This->dispex, iTInfo, lcid, ppTInfo);
1759 static HRESULT WINAPI DocDispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
1760 LPOLESTR *rgszNames, UINT cNames,
1761 LCID lcid, DISPID *rgDispId)
1763 HTMLDocument *This = impl_from_IDispatchEx(iface);
1765 return IDispatchEx_GetIDsOfNames(This->dispex, riid, rgszNames, cNames, lcid, rgDispId);
1768 static HRESULT WINAPI DocDispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
1769 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1770 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1772 HTMLDocument *This = impl_from_IDispatchEx(iface);
1774 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1775 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1777 switch(dispIdMember) {
1778 case DISPID_READYSTATE:
1779 TRACE("DISPID_READYSTATE\n");
1781 if(!(wFlags & DISPATCH_PROPERTYGET))
1782 return E_INVALIDARG;
1784 V_VT(pVarResult) = VT_I4;
1785 V_I4(pVarResult) = This->window->readystate;
1789 return IDispatchEx_Invoke(This->dispex, dispIdMember, riid, lcid, wFlags, pDispParams,
1790 pVarResult, pExcepInfo, puArgErr);
1793 static HRESULT WINAPI DocDispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
1795 HTMLDocument *This = impl_from_IDispatchEx(iface);
1798 hres = IDispatchEx_GetDispID(This->dispex, bstrName, grfdex, pid);
1799 if(hres != DISP_E_UNKNOWNNAME)
1802 return dispid_from_elem_name(This->doc_node, bstrName, pid);
1805 static HRESULT WINAPI DocDispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1806 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1808 HTMLDocument *This = impl_from_IDispatchEx(iface);
1810 if(This->window && id == DISPID_IHTMLDOCUMENT2_LOCATION && (wFlags & DISPATCH_PROPERTYPUT))
1811 return IDispatchEx_InvokeEx(&This->window->base.IDispatchEx_iface, DISPID_IHTMLWINDOW2_LOCATION,
1812 lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1815 return IDispatchEx_InvokeEx(This->dispex, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1818 static HRESULT WINAPI DocDispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
1820 HTMLDocument *This = impl_from_IDispatchEx(iface);
1822 return IDispatchEx_DeleteMemberByName(This->dispex, bstrName, grfdex);
1825 static HRESULT WINAPI DocDispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
1827 HTMLDocument *This = impl_from_IDispatchEx(iface);
1829 return IDispatchEx_DeleteMemberByDispID(This->dispex, id);
1832 static HRESULT WINAPI DocDispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
1834 HTMLDocument *This = impl_from_IDispatchEx(iface);
1836 return IDispatchEx_GetMemberProperties(This->dispex, id, grfdexFetch, pgrfdex);
1839 static HRESULT WINAPI DocDispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
1841 HTMLDocument *This = impl_from_IDispatchEx(iface);
1843 return IDispatchEx_GetMemberName(This->dispex, id, pbstrName);
1846 static HRESULT WINAPI DocDispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
1848 HTMLDocument *This = impl_from_IDispatchEx(iface);
1850 return IDispatchEx_GetNextDispID(This->dispex, grfdex, id, pid);
1853 static HRESULT WINAPI DocDispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
1855 HTMLDocument *This = impl_from_IDispatchEx(iface);
1857 return IDispatchEx_GetNameSpaceParent(This->dispex, ppunk);
1860 static const IDispatchExVtbl DocDispatchExVtbl = {
1861 DocDispatchEx_QueryInterface,
1862 DocDispatchEx_AddRef,
1863 DocDispatchEx_Release,
1864 DocDispatchEx_GetTypeInfoCount,
1865 DocDispatchEx_GetTypeInfo,
1866 DocDispatchEx_GetIDsOfNames,
1867 DocDispatchEx_Invoke,
1868 DocDispatchEx_GetDispID,
1869 DocDispatchEx_InvokeEx,
1870 DocDispatchEx_DeleteMemberByName,
1871 DocDispatchEx_DeleteMemberByDispID,
1872 DocDispatchEx_GetMemberProperties,
1873 DocDispatchEx_GetMemberName,
1874 DocDispatchEx_GetNextDispID,
1875 DocDispatchEx_GetNameSpaceParent
1878 static inline HTMLDocument *impl_from_IProvideClassInfo(IProvideClassInfo *iface)
1880 return CONTAINING_RECORD(iface, HTMLDocument, IProvideClassInfo_iface);
1883 static HRESULT WINAPI ProvideClassInfo_QueryInterface(IProvideClassInfo *iface,
1884 REFIID riid, void **ppv)
1886 HTMLDocument *This = impl_from_IProvideClassInfo(iface);
1887 return htmldoc_query_interface(This, riid, ppv);
1890 static ULONG WINAPI ProvideClassInfo_AddRef(IProvideClassInfo *iface)
1892 HTMLDocument *This = impl_from_IProvideClassInfo(iface);
1893 return htmldoc_addref(This);
1896 static ULONG WINAPI ProvideClassInfo_Release(IProvideClassInfo *iface)
1898 HTMLDocument *This = impl_from_IProvideClassInfo(iface);
1899 return htmldoc_release(This);
1902 static HRESULT WINAPI ProvideClassInfo_GetClassInfo(IProvideClassInfo* iface,
1905 HTMLDocument *This = impl_from_IProvideClassInfo(iface);
1906 TRACE("(%p)->(%p)\n", This, ppTI);
1907 return get_htmldoc_classinfo(ppTI);
1910 static const IProvideClassInfoVtbl ProvideClassInfoVtbl = {
1911 ProvideClassInfo_QueryInterface,
1912 ProvideClassInfo_AddRef,
1913 ProvideClassInfo_Release,
1914 ProvideClassInfo_GetClassInfo
1917 static BOOL htmldoc_qi(HTMLDocument *This, REFIID riid, void **ppv)
1921 if(IsEqualGUID(&IID_IUnknown, riid)) {
1922 TRACE("(%p)->(IID_IUnknown, %p)\n", This, ppv);
1923 *ppv = &This->IHTMLDocument2_iface;
1924 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1925 TRACE("(%p)->(IID_IDispatch, %p)\n", This, ppv);
1926 *ppv = &This->IDispatchEx_iface;
1927 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
1928 TRACE("(%p)->(IID_IDispatchEx, %p)\n", This, ppv);
1929 *ppv = &This->IDispatchEx_iface;
1930 }else if(IsEqualGUID(&IID_IHTMLDocument, riid)) {
1931 TRACE("(%p)->(IID_IHTMLDocument, %p)\n", This, ppv);
1932 *ppv = &This->IHTMLDocument2_iface;
1933 }else if(IsEqualGUID(&IID_IHTMLDocument2, riid)) {
1934 TRACE("(%p)->(IID_IHTMLDocument2, %p)\n", This, ppv);
1935 *ppv = &This->IHTMLDocument2_iface;
1936 }else if(IsEqualGUID(&IID_IHTMLDocument3, riid)) {
1937 TRACE("(%p)->(IID_IHTMLDocument3, %p)\n", This, ppv);
1938 *ppv = &This->IHTMLDocument3_iface;
1939 }else if(IsEqualGUID(&IID_IHTMLDocument4, riid)) {
1940 TRACE("(%p)->(IID_IHTMLDocument4, %p)\n", This, ppv);
1941 *ppv = &This->IHTMLDocument4_iface;
1942 }else if(IsEqualGUID(&IID_IHTMLDocument5, riid)) {
1943 TRACE("(%p)->(IID_IHTMLDocument5, %p)\n", This, ppv);
1944 *ppv = &This->IHTMLDocument5_iface;
1945 }else if(IsEqualGUID(&IID_IHTMLDocument6, riid)) {
1946 TRACE("(%p)->(IID_IHTMLDocument6, %p)\n", This, ppv);
1947 *ppv = &This->IHTMLDocument6_iface;
1948 }else if(IsEqualGUID(&IID_IPersist, riid)) {
1949 TRACE("(%p)->(IID_IPersist, %p)\n", This, ppv);
1950 *ppv = &This->IPersistFile_iface;
1951 }else if(IsEqualGUID(&IID_IPersistMoniker, riid)) {
1952 TRACE("(%p)->(IID_IPersistMoniker, %p)\n", This, ppv);
1953 *ppv = &This->IPersistMoniker_iface;
1954 }else if(IsEqualGUID(&IID_IPersistFile, riid)) {
1955 TRACE("(%p)->(IID_IPersistFile, %p)\n", This, ppv);
1956 *ppv = &This->IPersistFile_iface;
1957 }else if(IsEqualGUID(&IID_IMonikerProp, riid)) {
1958 TRACE("(%p)->(IID_IMonikerProp, %p)\n", This, ppv);
1959 *ppv = &This->IMonikerProp_iface;
1960 }else if(IsEqualGUID(&IID_IOleObject, riid)) {
1961 TRACE("(%p)->(IID_IOleObject, %p)\n", This, ppv);
1962 *ppv = &This->IOleObject_iface;
1963 }else if(IsEqualGUID(&IID_IOleDocument, riid)) {
1964 TRACE("(%p)->(IID_IOleDocument, %p)\n", This, ppv);
1965 *ppv = &This->IOleDocument_iface;
1966 }else if(IsEqualGUID(&IID_IOleDocumentView, riid)) {
1967 TRACE("(%p)->(IID_IOleDocumentView, %p)\n", This, ppv);
1968 *ppv = &This->IOleDocumentView_iface;
1969 }else if(IsEqualGUID(&IID_IOleInPlaceActiveObject, riid)) {
1970 TRACE("(%p)->(IID_IOleInPlaceActiveObject, %p)\n", This, ppv);
1971 *ppv = &This->IOleInPlaceActiveObject_iface;
1972 }else if(IsEqualGUID(&IID_IViewObject, riid)) {
1973 TRACE("(%p)->(IID_IViewObject, %p)\n", This, ppv);
1974 *ppv = &This->IViewObjectEx_iface;
1975 }else if(IsEqualGUID(&IID_IViewObject2, riid)) {
1976 TRACE("(%p)->(IID_IViewObject2, %p)\n", This, ppv);
1977 *ppv = &This->IViewObjectEx_iface;
1978 }else if(IsEqualGUID(&IID_IViewObjectEx, riid)) {
1979 TRACE("(%p)->(IID_IViewObjectEx, %p)\n", This, ppv);
1980 *ppv = &This->IViewObjectEx_iface;
1981 }else if(IsEqualGUID(&IID_IOleWindow, riid)) {
1982 TRACE("(%p)->(IID_IOleWindow, %p)\n", This, ppv);
1983 *ppv = &This->IOleInPlaceActiveObject_iface;
1984 }else if(IsEqualGUID(&IID_IOleInPlaceObject, riid)) {
1985 TRACE("(%p)->(IID_IOleInPlaceObject, %p)\n", This, ppv);
1986 *ppv = &This->IOleInPlaceObjectWindowless_iface;
1987 }else if(IsEqualGUID(&IID_IOleInPlaceObjectWindowless, riid)) {
1988 TRACE("(%p)->(IID_IOleInPlaceObjectWindowless, %p)\n", This, ppv);
1989 *ppv = &This->IOleInPlaceObjectWindowless_iface;
1990 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
1991 TRACE("(%p)->(IID_IServiceProvider, %p)\n", This, ppv);
1992 *ppv = &This->IServiceProvider_iface;
1993 }else if(IsEqualGUID(&IID_IOleCommandTarget, riid)) {
1994 TRACE("(%p)->(IID_IOleCommandTarget, %p)\n", This, ppv);
1995 *ppv = &This->IOleCommandTarget_iface;
1996 }else if(IsEqualGUID(&IID_IOleControl, riid)) {
1997 TRACE("(%p)->(IID_IOleControl, %p)\n", This, ppv);
1998 *ppv = &This->IOleControl_iface;
1999 }else if(IsEqualGUID(&IID_IHlinkTarget, riid)) {
2000 TRACE("(%p)->(IID_IHlinkTarget, %p)\n", This, ppv);
2001 *ppv = &This->IHlinkTarget_iface;
2002 }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
2003 TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppv);
2004 *ppv = &This->cp_container.IConnectionPointContainer_iface;
2005 }else if(IsEqualGUID(&IID_IPersistStreamInit, riid)) {
2006 TRACE("(%p)->(IID_IPersistStreamInit %p)\n", This, ppv);
2007 *ppv = &This->IPersistStreamInit_iface;
2008 }else if(IsEqualGUID(&DIID_DispHTMLDocument, riid)) {
2009 TRACE("(%p)->(DIID_DispHTMLDocument %p)\n", This, ppv);
2010 *ppv = &This->IHTMLDocument2_iface;
2011 }else if(IsEqualGUID(&IID_ISupportErrorInfo, riid)) {
2012 TRACE("(%p)->(IID_ISupportErrorInfo %p)\n", This, ppv);
2013 *ppv = &This->ISupportErrorInfo_iface;
2014 }else if(IsEqualGUID(&IID_IPersistHistory, riid)) {
2015 TRACE("(%p)->(IID_IPersistHistory %p)\n", This, ppv);
2016 *ppv = &This->IPersistHistory_iface;
2017 }else if(IsEqualGUID(&CLSID_CMarkup, riid)) {
2018 FIXME("(%p)->(CLSID_CMarkup %p)\n", This, ppv);
2020 }else if(IsEqualGUID(&IID_IRunnableObject, riid)) {
2021 TRACE("(%p)->(IID_IRunnableObject %p) returning NULL\n", This, ppv);
2023 }else if(IsEqualGUID(&IID_IPersistPropertyBag, riid)) {
2024 TRACE("(%p)->(IID_IPersistPropertyBag %p) returning NULL\n", This, ppv);
2026 }else if(IsEqualGUID(&IID_IMarshal, riid)) {
2027 TRACE("(%p)->(IID_IMarshal %p) returning NULL\n", This, ppv);
2029 }else if(IsEqualGUID(&IID_IExternalConnection, riid)) {
2030 TRACE("(%p)->(IID_IExternalConnection %p) returning NULL\n", This, ppv);
2032 }else if(IsEqualGUID(&IID_IStdMarshalInfo, riid)) {
2033 TRACE("(%p)->(IID_IStdMarshalInfo %p) returning NULL\n", This, ppv);
2035 }else if(IsEqualGUID(&IID_IObjectWithSite, riid)) {
2036 TRACE("(%p)->(IID_IObjectWithSite %p)\n", This, ppv);
2037 *ppv = &This->IObjectWithSite_iface;
2038 }else if(IsEqualGUID(&IID_IOleContainer, riid)) {
2039 TRACE("(%p)->(IID_IOleContainer %p)\n", This, ppv);
2040 *ppv = &This->IOleContainer_iface;
2041 }else if(IsEqualGUID(&IID_IObjectSafety, riid)) {
2042 TRACE("(%p)->(IID_IObjectSafety %p)\n", This, ppv);
2043 *ppv = &This->IObjectSafety_iface;
2044 }else if(IsEqualGUID(&IID_IProvideClassInfo, riid)) {
2045 TRACE("(%p)->(IID_IProvideClassInfo, %p)\n", This, ppv);
2046 *ppv = &This->IProvideClassInfo_iface;
2052 IUnknown_AddRef((IUnknown*)*ppv);
2056 static cp_static_data_t HTMLDocumentEvents_data = { HTMLDocumentEvents_tid, HTMLDocument_on_advise };
2058 static void init_doc(HTMLDocument *doc, IUnknown *unk_impl, IDispatchEx *dispex)
2060 doc->IHTMLDocument2_iface.lpVtbl = &HTMLDocumentVtbl;
2061 doc->IDispatchEx_iface.lpVtbl = &DocDispatchExVtbl;
2062 doc->ISupportErrorInfo_iface.lpVtbl = &SupportErrorInfoVtbl;
2063 doc->IProvideClassInfo_iface.lpVtbl = &ProvideClassInfoVtbl;
2065 doc->unk_impl = unk_impl;
2066 doc->dispex = dispex;
2067 doc->task_magic = get_task_target_magic();
2069 HTMLDocument_HTMLDocument3_Init(doc);
2070 HTMLDocument_HTMLDocument5_Init(doc);
2071 HTMLDocument_Persist_Init(doc);
2072 HTMLDocument_OleCmd_Init(doc);
2073 HTMLDocument_OleObj_Init(doc);
2074 HTMLDocument_View_Init(doc);
2075 HTMLDocument_Window_Init(doc);
2076 HTMLDocument_Service_Init(doc);
2077 HTMLDocument_Hlink_Init(doc);
2079 ConnectionPointContainer_Init(&doc->cp_container, (IUnknown*)&doc->IHTMLDocument2_iface);
2080 ConnectionPoint_Init(&doc->cp_dispatch, &doc->cp_container, &IID_IDispatch, &HTMLDocumentEvents_data);
2081 ConnectionPoint_Init(&doc->cp_propnotif, &doc->cp_container, &IID_IPropertyNotifySink, NULL);
2082 ConnectionPoint_Init(&doc->cp_htmldocevents, &doc->cp_container, &DIID_HTMLDocumentEvents, &HTMLDocumentEvents_data);
2083 ConnectionPoint_Init(&doc->cp_htmldocevents2, &doc->cp_container, &DIID_HTMLDocumentEvents2, NULL);
2086 static void destroy_htmldoc(HTMLDocument *This)
2088 remove_target_tasks(This->task_magic);
2090 ConnectionPointContainer_Destroy(&This->cp_container);
2093 static inline HTMLDocumentNode *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
2095 return CONTAINING_RECORD(iface, HTMLDocumentNode, node);
2098 static HRESULT HTMLDocumentNode_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
2100 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2102 if(htmldoc_qi(&This->basedoc, riid, ppv))
2103 return *ppv ? S_OK : E_NOINTERFACE;
2105 if(IsEqualGUID(&IID_IInternetHostSecurityManager, riid)) {
2106 TRACE("(%p)->(IID_IInternetHostSecurityManager %p)\n", This, ppv);
2107 *ppv = &This->IInternetHostSecurityManager_iface;
2109 return HTMLDOMNode_QI(&This->node, riid, ppv);
2112 IUnknown_AddRef((IUnknown*)*ppv);
2116 static void HTMLDocumentNode_destructor(HTMLDOMNode *iface)
2118 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2121 for(i=0; i < This->elem_vars_cnt; i++)
2122 heap_free(This->elem_vars[i]);
2123 heap_free(This->elem_vars);
2125 detach_events(This);
2126 if(This->body_event_target)
2127 release_event_target(This->body_event_target);
2129 ICatInformation_Release(This->catmgr);
2131 detach_selection(This);
2132 detach_ranges(This);
2134 while(!list_empty(&This->plugin_hosts))
2135 detach_plugin_host(LIST_ENTRY(list_head(&This->plugin_hosts), PluginHost, entry));
2137 if(This->nsnode_selector) {
2138 nsIDOMNodeSelector_Release(This->nsnode_selector);
2139 This->nsnode_selector = NULL;
2143 assert(!This->window);
2144 release_document_mutation(This);
2145 nsIDOMHTMLDocument_Release(This->nsdoc);
2146 }else if(This->window) {
2147 /* document fragments own reference to inner window */
2148 IHTMLWindow2_Release(&This->window->base.IHTMLWindow2_iface);
2149 This->window = NULL;
2152 heap_free(This->event_vector);
2153 destroy_htmldoc(&This->basedoc);
2156 static HRESULT HTMLDocumentNode_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
2158 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2159 FIXME("%p\n", This);
2163 static void HTMLDocumentNode_traverse(HTMLDOMNode *iface, nsCycleCollectionTraversalCallback *cb)
2165 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2167 if(This->nsnode_selector)
2168 note_cc_edge((nsISupports*)This->nsnode_selector, "This->nsnode_selector", cb);
2170 note_cc_edge((nsISupports*)This->nsdoc, "This->nsdoc", cb);
2173 static void HTMLDocumentNode_unlink(HTMLDOMNode *iface)
2175 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2177 if(This->nsnode_selector) {
2178 nsIDOMNodeSelector_Release(This->nsnode_selector);
2179 This->nsnode_selector = NULL;
2183 nsIDOMHTMLDocument *nsdoc = This->nsdoc;
2185 release_document_mutation(This);
2187 nsIDOMHTMLDocument_Release(nsdoc);
2188 This->window = NULL;
2192 static const NodeImplVtbl HTMLDocumentNodeImplVtbl = {
2193 HTMLDocumentNode_QI,
2194 HTMLDocumentNode_destructor,
2195 HTMLDocumentNode_clone,
2207 HTMLDocumentNode_traverse,
2208 HTMLDocumentNode_unlink
2211 static HRESULT HTMLDocumentFragment_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
2213 HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
2214 HTMLDocumentNode *new_node;
2217 hres = create_document_fragment(nsnode, This->node.doc, &new_node);
2221 *ret = &new_node->node;
2225 static inline HTMLDocumentNode *impl_from_DispatchEx(DispatchEx *iface)
2227 return CONTAINING_RECORD(iface, HTMLDocumentNode, node.dispex);
2230 static HRESULT HTMLDocumentNode_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
2231 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2233 HTMLDocumentNode *This = impl_from_DispatchEx(dispex);
2234 nsIDOMNodeList *node_list;
2242 if(flags != DISPATCH_PROPERTYGET && flags != (DISPATCH_METHOD|DISPATCH_PROPERTYGET)) {
2243 FIXME("unsupported flags %x\n", flags);
2247 i = id - MSHTML_DISPID_CUSTOM_MIN;
2249 if(!This->nsdoc || i >= This->elem_vars_cnt)
2250 return DISP_E_UNKNOWNNAME;
2252 nsAString_InitDepend(&name_str, This->elem_vars[i]);
2253 nsres = nsIDOMHTMLDocument_GetElementsByName(This->nsdoc, &name_str, &node_list);
2254 nsAString_Finish(&name_str);
2255 if(NS_FAILED(nsres))
2258 nsres = nsIDOMNodeList_Item(node_list, 0, &nsnode);
2259 nsIDOMNodeList_Release(node_list);
2260 if(NS_FAILED(nsres) || !nsnode)
2261 return DISP_E_UNKNOWNNAME;
2263 hres = get_node(This, nsnode, TRUE, &node);
2267 V_VT(res) = VT_DISPATCH;
2268 V_DISPATCH(res) = (IDispatch*)&node->IHTMLDOMNode_iface;
2273 static const dispex_static_data_vtbl_t HTMLDocumentNode_dispex_vtbl = {
2276 HTMLDocumentNode_invoke,
2280 static const NodeImplVtbl HTMLDocumentFragmentImplVtbl = {
2281 HTMLDocumentNode_QI,
2282 HTMLDocumentNode_destructor,
2283 HTMLDocumentFragment_clone
2286 static const tid_t HTMLDocumentNode_iface_tids[] = {
2296 static dispex_static_data_t HTMLDocumentNode_dispex = {
2297 &HTMLDocumentNode_dispex_vtbl,
2298 DispHTMLDocument_tid,
2300 HTMLDocumentNode_iface_tids
2303 static HTMLDocumentNode *alloc_doc_node(HTMLDocumentObj *doc_obj, HTMLInnerWindow *window)
2305 HTMLDocumentNode *doc;
2307 doc = heap_alloc_zero(sizeof(HTMLDocumentNode));
2312 doc->basedoc.doc_node = doc;
2313 doc->basedoc.doc_obj = doc_obj;
2314 doc->basedoc.window = window->base.outer_window;
2315 doc->window = window;
2317 init_dispex(&doc->node.dispex, (IUnknown*)&doc->node.IHTMLDOMNode_iface,
2318 &HTMLDocumentNode_dispex);
2319 init_doc(&doc->basedoc, (IUnknown*)&doc->node.IHTMLDOMNode_iface,
2320 &doc->node.dispex.IDispatchEx_iface);
2321 HTMLDocumentNode_SecMgr_Init(doc);
2323 list_init(&doc->selection_list);
2324 list_init(&doc->range_list);
2325 list_init(&doc->plugin_hosts);
2330 HRESULT create_doc_from_nsdoc(nsIDOMHTMLDocument *nsdoc, HTMLDocumentObj *doc_obj, HTMLInnerWindow *window, HTMLDocumentNode **ret)
2332 HTMLDocumentNode *doc;
2335 doc = alloc_doc_node(doc_obj, window);
2337 return E_OUTOFMEMORY;
2339 if(!doc_obj->basedoc.window || window->base.outer_window == doc_obj->basedoc.window)
2340 doc->basedoc.cp_container.forward_container = &doc_obj->basedoc.cp_container;
2342 HTMLDOMNode_Init(doc, &doc->node, (nsIDOMNode*)nsdoc);
2344 nsIDOMHTMLDocument_AddRef(nsdoc);
2347 nsres = nsIDOMHTMLDocument_QueryInterface(nsdoc, &IID_nsIDOMNodeSelector, (void**)&doc->nsnode_selector);
2348 assert(nsres == NS_OK);
2350 init_document_mutation(doc);
2351 doc_init_events(doc);
2353 doc->node.vtbl = &HTMLDocumentNodeImplVtbl;
2354 doc->node.cp_container = &doc->basedoc.cp_container;
2360 HRESULT create_document_fragment(nsIDOMNode *nsnode, HTMLDocumentNode *doc_node, HTMLDocumentNode **ret)
2362 HTMLDocumentNode *doc_frag;
2364 doc_frag = alloc_doc_node(doc_node->basedoc.doc_obj, doc_node->window);
2366 return E_OUTOFMEMORY;
2368 IHTMLWindow2_AddRef(&doc_frag->window->base.IHTMLWindow2_iface);
2370 HTMLDOMNode_Init(doc_node, &doc_frag->node, nsnode);
2371 doc_frag->node.vtbl = &HTMLDocumentFragmentImplVtbl;
2372 doc_frag->node.cp_container = &doc_frag->basedoc.cp_container;
2378 /**********************************************************
2379 * ICustomDoc implementation
2382 static inline HTMLDocumentObj *impl_from_ICustomDoc(ICustomDoc *iface)
2384 return CONTAINING_RECORD(iface, HTMLDocumentObj, ICustomDoc_iface);
2387 static HRESULT WINAPI CustomDoc_QueryInterface(ICustomDoc *iface, REFIID riid, void **ppv)
2389 HTMLDocumentObj *This = impl_from_ICustomDoc(iface);
2391 if(htmldoc_qi(&This->basedoc, riid, ppv))
2392 return *ppv ? S_OK : E_NOINTERFACE;
2394 if(IsEqualGUID(&IID_ICustomDoc, riid)) {
2395 TRACE("(%p)->(IID_ICustomDoc %p)\n", This, ppv);
2396 *ppv = &This->ICustomDoc_iface;
2397 }else if(IsEqualGUID(&IID_ITargetContainer, riid)) {
2398 TRACE("(%p)->(IID_ITargetContainer %p)\n", This, ppv);
2399 *ppv = &This->ITargetContainer_iface;
2400 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
2401 return *ppv ? S_OK : E_NOINTERFACE;
2403 FIXME("Unimplemented interface %s\n", debugstr_guid(riid));
2405 return E_NOINTERFACE;
2408 IUnknown_AddRef((IUnknown*)*ppv);
2412 static ULONG WINAPI CustomDoc_AddRef(ICustomDoc *iface)
2414 HTMLDocumentObj *This = impl_from_ICustomDoc(iface);
2415 ULONG ref = InterlockedIncrement(&This->ref);
2417 TRACE("(%p) ref = %u\n", This, ref);
2422 static ULONG WINAPI CustomDoc_Release(ICustomDoc *iface)
2424 HTMLDocumentObj *This = impl_from_ICustomDoc(iface);
2425 ULONG ref = InterlockedDecrement(&This->ref);
2427 TRACE("(%p) ref = %u\n", This, ref);
2430 nsIDOMWindowUtils *window_utils = NULL;
2432 if(This->basedoc.window && This->basedoc.window->nswindow)
2433 get_nsinterface((nsISupports*)This->basedoc.window->nswindow, &IID_nsIDOMWindowUtils, (void**)&window_utils);
2435 if(This->basedoc.doc_node) {
2436 This->basedoc.doc_node->basedoc.doc_obj = NULL;
2437 htmldoc_release(&This->basedoc.doc_node->basedoc);
2439 if(This->basedoc.window) {
2440 This->basedoc.window->doc_obj = NULL;
2441 IHTMLWindow2_Release(&This->basedoc.window->base.IHTMLWindow2_iface);
2443 if(This->basedoc.advise_holder)
2444 IOleAdviseHolder_Release(This->basedoc.advise_holder);
2447 IAdviseSink_Release(This->view_sink);
2449 IOleObject_SetClientSite(&This->basedoc.IOleObject_iface, NULL);
2451 ICustomDoc_SetUIHandler(&This->ICustomDoc_iface, NULL);
2452 if(This->in_place_active)
2453 IOleInPlaceObjectWindowless_InPlaceDeactivate(&This->basedoc.IOleInPlaceObjectWindowless_iface);
2455 IOleDocumentView_SetInPlaceSite(&This->basedoc.IOleDocumentView_iface, NULL);
2457 IOleUndoManager_Release(This->undomgr);
2458 if(This->tooltips_hwnd)
2459 DestroyWindow(This->tooltips_hwnd);
2462 DestroyWindow(This->hwnd);
2463 heap_free(This->mime);
2465 destroy_htmldoc(&This->basedoc);
2466 release_dispex(&This->dispex);
2468 if(This->nscontainer)
2469 NSContainer_Release(This->nscontainer);
2472 /* Force cycle collection */
2474 nsIDOMWindowUtils_CycleCollect(window_utils, NULL, 0);
2475 nsIDOMWindowUtils_Release(window_utils);
2482 static HRESULT WINAPI CustomDoc_SetUIHandler(ICustomDoc *iface, IDocHostUIHandler *pUIHandler)
2484 HTMLDocumentObj *This = impl_from_ICustomDoc(iface);
2485 IOleCommandTarget *cmdtrg;
2488 TRACE("(%p)->(%p)\n", This, pUIHandler);
2490 if(This->custom_hostui && This->hostui == pUIHandler)
2493 This->custom_hostui = TRUE;
2496 IDocHostUIHandler_Release(This->hostui);
2498 IDocHostUIHandler_AddRef(pUIHandler);
2499 This->hostui = pUIHandler;
2503 hres = IDocHostUIHandler_QueryInterface(pUIHandler, &IID_IOleCommandTarget, (void**)&cmdtrg);
2504 if(SUCCEEDED(hres)) {
2505 FIXME("custom UI handler supports IOleCommandTarget\n");
2506 IOleCommandTarget_Release(cmdtrg);
2512 static const ICustomDocVtbl CustomDocVtbl = {
2513 CustomDoc_QueryInterface,
2516 CustomDoc_SetUIHandler
2519 static const tid_t HTMLDocumentObj_iface_tids[] = {
2526 static dispex_static_data_t HTMLDocumentObj_dispex = {
2528 DispHTMLDocument_tid,
2530 HTMLDocumentObj_iface_tids
2533 HRESULT HTMLDocument_Create(IUnknown *pUnkOuter, REFIID riid, void** ppvObject)
2535 HTMLDocumentObj *doc;
2536 nsIDOMWindow *nswindow = NULL;
2540 TRACE("(%p %s %p)\n", pUnkOuter, debugstr_guid(riid), ppvObject);
2542 doc = heap_alloc_zero(sizeof(HTMLDocumentObj));
2544 return E_OUTOFMEMORY;
2546 init_dispex(&doc->dispex, (IUnknown*)&doc->ICustomDoc_iface, &HTMLDocumentObj_dispex);
2547 init_doc(&doc->basedoc, (IUnknown*)&doc->ICustomDoc_iface, &doc->dispex.IDispatchEx_iface);
2548 TargetContainer_Init(doc);
2550 doc->ICustomDoc_iface.lpVtbl = &CustomDocVtbl;
2552 doc->basedoc.doc_obj = doc;
2554 doc->usermode = UNKNOWN_USERMODE;
2556 init_binding_ui(doc);
2558 hres = create_nscontainer(doc, &doc->nscontainer);
2560 ERR("Failed to init Gecko, returning CLASS_E_CLASSNOTAVAILABLE\n");
2561 htmldoc_release(&doc->basedoc);
2565 hres = htmldoc_query_interface(&doc->basedoc, riid, ppvObject);
2566 htmldoc_release(&doc->basedoc);
2570 nsres = nsIWebBrowser_GetContentDOMWindow(doc->nscontainer->webbrowser, &nswindow);
2571 if(NS_FAILED(nsres))
2572 ERR("GetContentDOMWindow failed: %08x\n", nsres);
2574 hres = HTMLOuterWindow_Create(doc, nswindow, NULL /* FIXME */, &doc->basedoc.window);
2576 nsIDOMWindow_Release(nswindow);
2578 htmldoc_release(&doc->basedoc);
2582 if(!doc->basedoc.doc_node && doc->basedoc.window->base.inner_window->doc) {
2583 doc->basedoc.doc_node = doc->basedoc.window->base.inner_window->doc;
2584 htmldoc_addref(&doc->basedoc.doc_node->basedoc);