mshtml: COM cleanup for the IMonikerProp iface.
[wine/multimedia.git] / dlls / mshtml / htmldoc.c
blob486eefad6543aecf9228eb59e1c5d5ac76f2b5e9
1 /*
2 * Copyright 2005-2009 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "config.h"
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "wininet.h"
30 #include "ole2.h"
31 #include "perhist.h"
32 #include "mshtmdid.h"
34 #include "wine/debug.h"
36 #include "mshtml_private.h"
37 #include "htmlevent.h"
38 #include "pluginhost.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
42 static inline HTMLDocument *impl_from_IHTMLDocument2(IHTMLDocument2 *iface)
44 return CONTAINING_RECORD(iface, HTMLDocument, IHTMLDocument2_iface);
47 static HRESULT WINAPI HTMLDocument_QueryInterface(IHTMLDocument2 *iface, REFIID riid, void **ppv)
49 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
51 return htmldoc_query_interface(This, riid, ppv);
54 static ULONG WINAPI HTMLDocument_AddRef(IHTMLDocument2 *iface)
56 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
58 return htmldoc_addref(This);
61 static ULONG WINAPI HTMLDocument_Release(IHTMLDocument2 *iface)
63 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
65 return htmldoc_release(This);
68 static HRESULT WINAPI HTMLDocument_GetTypeInfoCount(IHTMLDocument2 *iface, UINT *pctinfo)
70 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
72 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(This), pctinfo);
75 static HRESULT WINAPI HTMLDocument_GetTypeInfo(IHTMLDocument2 *iface, UINT iTInfo,
76 LCID lcid, ITypeInfo **ppTInfo)
78 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
80 return IDispatchEx_GetTypeInfo(DISPATCHEX(This), iTInfo, lcid, ppTInfo);
83 static HRESULT WINAPI HTMLDocument_GetIDsOfNames(IHTMLDocument2 *iface, REFIID riid,
84 LPOLESTR *rgszNames, UINT cNames,
85 LCID lcid, DISPID *rgDispId)
87 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
89 return IDispatchEx_GetIDsOfNames(DISPATCHEX(This), riid, rgszNames, cNames, lcid, rgDispId);
92 static HRESULT WINAPI HTMLDocument_Invoke(IHTMLDocument2 *iface, DISPID dispIdMember,
93 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
94 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
96 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
98 return IDispatchEx_Invoke(DISPATCHEX(This), dispIdMember, riid, lcid, wFlags, pDispParams,
99 pVarResult, pExcepInfo, puArgErr);
102 static HRESULT WINAPI HTMLDocument_get_Script(IHTMLDocument2 *iface, IDispatch **p)
104 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
106 TRACE("(%p)->(%p)\n", This, p);
108 *p = (IDispatch*)HTMLWINDOW2(This->window);
109 IDispatch_AddRef(*p);
110 return S_OK;
113 static HRESULT WINAPI HTMLDocument_get_all(IHTMLDocument2 *iface, IHTMLElementCollection **p)
115 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
116 nsIDOMElement *nselem = NULL;
117 HTMLDOMNode *node;
118 nsresult nsres;
119 HRESULT hres;
121 TRACE("(%p)->(%p)\n", This, p);
123 if(!This->doc_node->nsdoc) {
124 WARN("NULL nsdoc\n");
125 return E_UNEXPECTED;
128 nsres = nsIDOMHTMLDocument_GetDocumentElement(This->doc_node->nsdoc, &nselem);
129 if(NS_FAILED(nsres)) {
130 ERR("GetDocumentElement failed: %08x\n", nsres);
131 return E_FAIL;
134 if(!nselem) {
135 *p = NULL;
136 return S_OK;
139 hres = get_node(This->doc_node, (nsIDOMNode*)nselem, TRUE, &node);
140 if(SUCCEEDED(hres))
141 *p = create_all_collection(node, TRUE);
142 nsIDOMElement_Release(nselem);
143 return hres;
146 static HRESULT WINAPI HTMLDocument_get_body(IHTMLDocument2 *iface, IHTMLElement **p)
148 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
149 nsIDOMHTMLElement *nsbody = NULL;
150 HTMLDOMNode *node;
151 HRESULT hres;
153 TRACE("(%p)->(%p)\n", This, p);
155 if(This->doc_node->nsdoc) {
156 nsresult nsres;
158 nsres = nsIDOMHTMLDocument_GetBody(This->doc_node->nsdoc, &nsbody);
159 if(NS_FAILED(nsres)) {
160 TRACE("Could not get body: %08x\n", nsres);
161 return E_UNEXPECTED;
165 if(!nsbody) {
166 *p = NULL;
167 return S_OK;
170 hres = get_node(This->doc_node, (nsIDOMNode*)nsbody, TRUE, &node);
171 nsIDOMHTMLElement_Release(nsbody);
172 if(FAILED(hres))
173 return hres;
175 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(node), &IID_IHTMLElement, (void**)p);
178 static HRESULT WINAPI HTMLDocument_get_activeElement(IHTMLDocument2 *iface, IHTMLElement **p)
180 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
181 FIXME("(%p)->(%p)\n", This, p);
182 return E_NOTIMPL;
185 static HRESULT WINAPI HTMLDocument_get_images(IHTMLDocument2 *iface, IHTMLElementCollection **p)
187 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
188 nsIDOMHTMLCollection *nscoll = NULL;
189 nsresult nsres;
191 TRACE("(%p)->(%p)\n", This, p);
193 if(!p)
194 return E_INVALIDARG;
196 *p = NULL;
198 if(!This->doc_node->nsdoc) {
199 WARN("NULL nsdoc\n");
200 return E_UNEXPECTED;
203 nsres = nsIDOMHTMLDocument_GetImages(This->doc_node->nsdoc, &nscoll);
204 if(NS_FAILED(nsres)) {
205 ERR("GetImages failed: %08x\n", nsres);
206 return E_FAIL;
209 if(nscoll) {
210 *p = create_collection_from_htmlcol(This->doc_node, (IUnknown*)&This->IHTMLDocument2_iface, nscoll);
211 nsIDOMElement_Release(nscoll);
214 return S_OK;
217 static HRESULT WINAPI HTMLDocument_get_applets(IHTMLDocument2 *iface, IHTMLElementCollection **p)
219 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
220 nsIDOMHTMLCollection *nscoll = NULL;
221 nsresult nsres;
223 TRACE("(%p)->(%p)\n", This, p);
225 if(!p)
226 return E_INVALIDARG;
228 *p = NULL;
230 if(!This->doc_node->nsdoc) {
231 WARN("NULL nsdoc\n");
232 return E_UNEXPECTED;
235 nsres = nsIDOMHTMLDocument_GetApplets(This->doc_node->nsdoc, &nscoll);
236 if(NS_FAILED(nsres)) {
237 ERR("GetApplets failed: %08x\n", nsres);
238 return E_FAIL;
241 if(nscoll) {
242 *p = create_collection_from_htmlcol(This->doc_node, (IUnknown*)&This->IHTMLDocument2_iface, nscoll);
243 nsIDOMElement_Release(nscoll);
246 return S_OK;
249 static HRESULT WINAPI HTMLDocument_get_links(IHTMLDocument2 *iface, IHTMLElementCollection **p)
251 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
252 nsIDOMHTMLCollection *nscoll = NULL;
253 nsresult nsres;
255 TRACE("(%p)->(%p)\n", This, p);
257 if(!p)
258 return E_INVALIDARG;
260 *p = NULL;
262 if(!This->doc_node->nsdoc) {
263 WARN("NULL nsdoc\n");
264 return E_UNEXPECTED;
267 nsres = nsIDOMHTMLDocument_GetLinks(This->doc_node->nsdoc, &nscoll);
268 if(NS_FAILED(nsres)) {
269 ERR("GetLinks failed: %08x\n", nsres);
270 return E_FAIL;
273 if(nscoll) {
274 *p = create_collection_from_htmlcol(This->doc_node, (IUnknown*)&This->IHTMLDocument2_iface, nscoll);
275 nsIDOMElement_Release(nscoll);
278 return S_OK;
281 static HRESULT WINAPI HTMLDocument_get_forms(IHTMLDocument2 *iface, IHTMLElementCollection **p)
283 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
284 nsIDOMHTMLCollection *nscoll = NULL;
285 nsresult nsres;
287 TRACE("(%p)->(%p)\n", This, p);
289 if(!p)
290 return E_INVALIDARG;
292 *p = NULL;
294 if(!This->doc_node->nsdoc) {
295 WARN("NULL nsdoc\n");
296 return E_UNEXPECTED;
299 nsres = nsIDOMHTMLDocument_GetForms(This->doc_node->nsdoc, &nscoll);
300 if(NS_FAILED(nsres)) {
301 ERR("GetForms failed: %08x\n", nsres);
302 return E_FAIL;
305 if(nscoll) {
306 *p = create_collection_from_htmlcol(This->doc_node, (IUnknown*)&This->IHTMLDocument2_iface, nscoll);
307 nsIDOMElement_Release(nscoll);
310 return S_OK;
313 static HRESULT WINAPI HTMLDocument_get_anchors(IHTMLDocument2 *iface, IHTMLElementCollection **p)
315 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
316 nsIDOMHTMLCollection *nscoll = NULL;
317 nsresult nsres;
319 TRACE("(%p)->(%p)\n", This, p);
321 if(!p)
322 return E_INVALIDARG;
324 *p = NULL;
326 if(!This->doc_node->nsdoc) {
327 WARN("NULL nsdoc\n");
328 return E_UNEXPECTED;
331 nsres = nsIDOMHTMLDocument_GetAnchors(This->doc_node->nsdoc, &nscoll);
332 if(NS_FAILED(nsres)) {
333 ERR("GetAnchors failed: %08x\n", nsres);
334 return E_FAIL;
337 if(nscoll) {
338 *p = create_collection_from_htmlcol(This->doc_node, (IUnknown*)&This->IHTMLDocument2_iface, nscoll);
339 nsIDOMElement_Release(nscoll);
342 return S_OK;
345 static HRESULT WINAPI HTMLDocument_put_title(IHTMLDocument2 *iface, BSTR v)
347 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
348 nsAString nsstr;
349 nsresult nsres;
351 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
353 if(!This->doc_node->nsdoc) {
354 WARN("NULL nsdoc\n");
355 return E_UNEXPECTED;
358 nsAString_InitDepend(&nsstr, v);
359 nsres = nsIDOMHTMLDocument_SetTitle(This->doc_node->nsdoc, &nsstr);
360 nsAString_Finish(&nsstr);
361 if(NS_FAILED(nsres))
362 ERR("SetTitle failed: %08x\n", nsres);
364 return S_OK;
367 static HRESULT WINAPI HTMLDocument_get_title(IHTMLDocument2 *iface, BSTR *p)
369 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
370 const PRUnichar *ret;
371 nsAString nsstr;
372 nsresult nsres;
374 TRACE("(%p)->(%p)\n", This, p);
376 if(!This->doc_node->nsdoc) {
377 WARN("NULL nsdoc\n");
378 return E_UNEXPECTED;
382 nsAString_Init(&nsstr, NULL);
383 nsres = nsIDOMHTMLDocument_GetTitle(This->doc_node->nsdoc, &nsstr);
384 if (NS_SUCCEEDED(nsres)) {
385 nsAString_GetData(&nsstr, &ret);
386 *p = SysAllocString(ret);
388 nsAString_Finish(&nsstr);
390 if(NS_FAILED(nsres)) {
391 ERR("GetTitle failed: %08x\n", nsres);
392 return E_FAIL;
395 return S_OK;
398 static HRESULT WINAPI HTMLDocument_get_scripts(IHTMLDocument2 *iface, IHTMLElementCollection **p)
400 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
401 FIXME("(%p)->(%p)\n", This, p);
402 return E_NOTIMPL;
405 static HRESULT WINAPI HTMLDocument_put_designMode(IHTMLDocument2 *iface, BSTR v)
407 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
408 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
409 return E_NOTIMPL;
412 static HRESULT WINAPI HTMLDocument_get_designMode(IHTMLDocument2 *iface, BSTR *p)
414 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
415 static WCHAR szOff[] = {'O','f','f',0};
416 FIXME("(%p)->(%p) always returning Off\n", This, p);
418 if(!p)
419 return E_INVALIDARG;
421 *p = SysAllocString(szOff);
423 return S_OK;
426 static HRESULT WINAPI HTMLDocument_get_selection(IHTMLDocument2 *iface, IHTMLSelectionObject **p)
428 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
429 nsISelection *nsselection;
430 nsresult nsres;
432 TRACE("(%p)->(%p)\n", This, p);
434 nsres = nsIDOMWindow_GetSelection(This->window->nswindow, &nsselection);
435 if(NS_FAILED(nsres)) {
436 ERR("GetSelection failed: %08x\n", nsres);
437 return E_FAIL;
440 return HTMLSelectionObject_Create(This->doc_node, nsselection, p);
443 static HRESULT WINAPI HTMLDocument_get_readyState(IHTMLDocument2 *iface, BSTR *p)
445 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
447 static const WCHAR wszUninitialized[] = {'u','n','i','n','i','t','i','a','l','i','z','e','d',0};
448 static const WCHAR wszLoading[] = {'l','o','a','d','i','n','g',0};
449 static const WCHAR wszLoaded[] = {'l','o','a','d','e','d',0};
450 static const WCHAR wszInteractive[] = {'i','n','t','e','r','a','c','t','i','v','e',0};
451 static const WCHAR wszComplete[] = {'c','o','m','p','l','e','t','e',0};
453 static const LPCWSTR readystate_str[] = {
454 wszUninitialized,
455 wszLoading,
456 wszLoaded,
457 wszInteractive,
458 wszComplete
461 TRACE("(%p)->(%p)\n", iface, p);
463 if(!p)
464 return E_POINTER;
466 *p = SysAllocString(readystate_str[This->window->readystate]);
467 return S_OK;
470 static HRESULT WINAPI HTMLDocument_get_frames(IHTMLDocument2 *iface, IHTMLFramesCollection2 **p)
472 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
473 FIXME("(%p)->(%p)\n", This, p);
474 return E_NOTIMPL;
477 static HRESULT WINAPI HTMLDocument_get_embeds(IHTMLDocument2 *iface, IHTMLElementCollection **p)
479 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
480 FIXME("(%p)->(%p)\n", This, p);
481 return E_NOTIMPL;
484 static HRESULT WINAPI HTMLDocument_get_plugins(IHTMLDocument2 *iface, IHTMLElementCollection **p)
486 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
487 FIXME("(%p)->(%p)\n", This, p);
488 return E_NOTIMPL;
491 static HRESULT WINAPI HTMLDocument_put_alinkColor(IHTMLDocument2 *iface, VARIANT v)
493 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
494 FIXME("(%p)\n", This);
495 return E_NOTIMPL;
498 static HRESULT WINAPI HTMLDocument_get_alinkColor(IHTMLDocument2 *iface, VARIANT *p)
500 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
501 FIXME("(%p)->(%p)\n", This, p);
502 return E_NOTIMPL;
505 static HRESULT WINAPI HTMLDocument_put_bgColor(IHTMLDocument2 *iface, VARIANT v)
507 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
508 FIXME("(%p)\n", This);
509 return E_NOTIMPL;
512 static HRESULT WINAPI HTMLDocument_get_bgColor(IHTMLDocument2 *iface, VARIANT *p)
514 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
515 FIXME("(%p)->(%p)\n", This, p);
516 return E_NOTIMPL;
519 static HRESULT WINAPI HTMLDocument_put_fgColor(IHTMLDocument2 *iface, VARIANT v)
521 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
522 FIXME("(%p)\n", This);
523 return E_NOTIMPL;
526 static HRESULT WINAPI HTMLDocument_get_fgColor(IHTMLDocument2 *iface, VARIANT *p)
528 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
529 FIXME("(%p)->(%p)\n", This, p);
530 return E_NOTIMPL;
533 static HRESULT WINAPI HTMLDocument_put_linkColor(IHTMLDocument2 *iface, VARIANT v)
535 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
536 FIXME("(%p)->()\n", This);
537 return E_NOTIMPL;
540 static HRESULT WINAPI HTMLDocument_get_linkColor(IHTMLDocument2 *iface, VARIANT *p)
542 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
543 FIXME("(%p)->(%p)\n", This, p);
544 return E_NOTIMPL;
547 static HRESULT WINAPI HTMLDocument_put_vlinkColor(IHTMLDocument2 *iface, VARIANT v)
549 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
550 FIXME("(%p)\n", This);
551 return E_NOTIMPL;
554 static HRESULT WINAPI HTMLDocument_get_vlinkColor(IHTMLDocument2 *iface, VARIANT *p)
556 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
557 FIXME("(%p)->(%p)\n", This, p);
558 return E_NOTIMPL;
561 static HRESULT WINAPI HTMLDocument_get_referrer(IHTMLDocument2 *iface, BSTR *p)
563 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
565 FIXME("(%p)->(%p)\n", This, p);
567 *p = NULL;
568 return S_OK;
571 static HRESULT WINAPI HTMLDocument_get_location(IHTMLDocument2 *iface, IHTMLLocation **p)
573 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
575 TRACE("(%p)->(%p)\n", This, p);
577 if(!This->doc_node->nsdoc) {
578 WARN("NULL nsdoc\n");
579 return E_UNEXPECTED;
582 return IHTMLWindow2_get_location(HTMLWINDOW2(This->window), p);
585 static HRESULT WINAPI HTMLDocument_get_lastModified(IHTMLDocument2 *iface, BSTR *p)
587 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
588 FIXME("(%p)->(%p)\n", This, p);
589 return E_NOTIMPL;
592 static HRESULT WINAPI HTMLDocument_put_URL(IHTMLDocument2 *iface, BSTR v)
594 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
595 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
596 return E_NOTIMPL;
599 static HRESULT WINAPI HTMLDocument_get_URL(IHTMLDocument2 *iface, BSTR *p)
601 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
603 static const WCHAR about_blank_url[] =
604 {'a','b','o','u','t',':','b','l','a','n','k',0};
606 TRACE("(%p)->(%p)\n", iface, p);
608 *p = SysAllocString(This->window->url ? This->window->url : about_blank_url);
609 return *p ? S_OK : E_OUTOFMEMORY;
612 static HRESULT WINAPI HTMLDocument_put_domain(IHTMLDocument2 *iface, BSTR v)
614 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
615 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
616 return E_NOTIMPL;
619 static HRESULT WINAPI HTMLDocument_get_domain(IHTMLDocument2 *iface, BSTR *p)
621 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
622 FIXME("(%p)->(%p)\n", This, p);
623 return E_NOTIMPL;
626 static HRESULT WINAPI HTMLDocument_put_cookie(IHTMLDocument2 *iface, BSTR v)
628 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
629 BOOL bret;
631 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
633 bret = InternetSetCookieExW(This->window->url, NULL, v, 0, 0);
634 if(!bret) {
635 FIXME("InternetSetCookieExW failed: %u\n", GetLastError());
636 return HRESULT_FROM_WIN32(GetLastError());
639 return S_OK;
642 static HRESULT WINAPI HTMLDocument_get_cookie(IHTMLDocument2 *iface, BSTR *p)
644 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
645 DWORD size;
646 BOOL bret;
648 TRACE("(%p)->(%p)\n", This, p);
650 size = 0;
651 bret = InternetGetCookieExW(This->window->url, NULL, NULL, &size, 0, NULL);
652 if(!bret) {
653 switch(GetLastError()) {
654 case ERROR_INSUFFICIENT_BUFFER:
655 break;
656 case ERROR_NO_MORE_ITEMS:
657 *p = NULL;
658 return S_OK;
659 default:
660 FIXME("InternetGetCookieExW failed: %u\n", GetLastError());
661 return HRESULT_FROM_WIN32(GetLastError());
665 if(!size) {
666 *p = NULL;
667 return S_OK;
670 *p = SysAllocStringLen(NULL, size-1);
671 if(!*p)
672 return E_OUTOFMEMORY;
674 bret = InternetGetCookieExW(This->window->url, NULL, *p, &size, 0, NULL);
675 if(!bret) {
676 ERR("InternetGetCookieExW failed: %u\n", GetLastError());
677 return E_FAIL;
680 return S_OK;
683 static HRESULT WINAPI HTMLDocument_put_expando(IHTMLDocument2 *iface, VARIANT_BOOL v)
685 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
686 FIXME("(%p)->(%x)\n", This, v);
687 return E_NOTIMPL;
690 static HRESULT WINAPI HTMLDocument_get_expando(IHTMLDocument2 *iface, VARIANT_BOOL *p)
692 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
693 FIXME("(%p)->(%p)\n", This, p);
694 return E_NOTIMPL;
697 static HRESULT WINAPI HTMLDocument_put_charset(IHTMLDocument2 *iface, BSTR v)
699 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
700 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
701 return E_NOTIMPL;
704 static HRESULT WINAPI HTMLDocument_get_charset(IHTMLDocument2 *iface, BSTR *p)
706 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
707 FIXME("(%p)->(%p)\n", This, p);
708 return E_NOTIMPL;
711 static HRESULT WINAPI HTMLDocument_put_defaultCharset(IHTMLDocument2 *iface, BSTR v)
713 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
714 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
715 return E_NOTIMPL;
718 static HRESULT WINAPI HTMLDocument_get_defaultCharset(IHTMLDocument2 *iface, BSTR *p)
720 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
721 FIXME("(%p)->(%p)\n", This, p);
722 return E_NOTIMPL;
725 static HRESULT WINAPI HTMLDocument_get_mimeType(IHTMLDocument2 *iface, BSTR *p)
727 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
728 FIXME("(%p)->(%p)\n", This, p);
729 return E_NOTIMPL;
732 static HRESULT WINAPI HTMLDocument_get_fileSize(IHTMLDocument2 *iface, BSTR *p)
734 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
735 FIXME("(%p)->(%p)\n", This, p);
736 return E_NOTIMPL;
739 static HRESULT WINAPI HTMLDocument_get_fileCreatedDate(IHTMLDocument2 *iface, BSTR *p)
741 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
742 FIXME("(%p)->(%p)\n", This, p);
743 return E_NOTIMPL;
746 static HRESULT WINAPI HTMLDocument_get_fileModifiedDate(IHTMLDocument2 *iface, BSTR *p)
748 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
749 FIXME("(%p)->(%p)\n", This, p);
750 return E_NOTIMPL;
753 static HRESULT WINAPI HTMLDocument_get_fileUpdatedDate(IHTMLDocument2 *iface, BSTR *p)
755 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
756 FIXME("(%p)->(%p)\n", This, p);
757 return E_NOTIMPL;
760 static HRESULT WINAPI HTMLDocument_get_security(IHTMLDocument2 *iface, BSTR *p)
762 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
763 FIXME("(%p)->(%p)\n", This, p);
764 return E_NOTIMPL;
767 static HRESULT WINAPI HTMLDocument_get_protocol(IHTMLDocument2 *iface, BSTR *p)
769 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
770 FIXME("(%p)->(%p)\n", This, p);
771 return E_NOTIMPL;
774 static HRESULT WINAPI HTMLDocument_get_nameProp(IHTMLDocument2 *iface, BSTR *p)
776 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
777 FIXME("(%p)->(%p)\n", This, p);
778 return E_NOTIMPL;
781 static HRESULT document_write(HTMLDocument *This, SAFEARRAY *psarray, BOOL ln)
783 nsAString nsstr;
784 VARIANT *var;
785 ULONG i, argc;
786 nsresult nsres;
787 HRESULT hres;
789 if(!This->doc_node->nsdoc) {
790 WARN("NULL nsdoc\n");
791 return E_UNEXPECTED;
794 if (!psarray)
795 return S_OK;
797 if(psarray->cDims != 1) {
798 FIXME("cDims=%d\n", psarray->cDims);
799 return E_INVALIDARG;
802 hres = SafeArrayAccessData(psarray, (void**)&var);
803 if(FAILED(hres)) {
804 WARN("SafeArrayAccessData failed: %08x\n", hres);
805 return hres;
808 nsAString_Init(&nsstr, NULL);
810 argc = psarray->rgsabound[0].cElements;
811 for(i=0; i < argc; i++) {
812 if(V_VT(var+i) == VT_BSTR) {
813 nsAString_SetData(&nsstr, V_BSTR(var+i));
814 if(!ln || i != argc-1)
815 nsres = nsIDOMHTMLDocument_Write(This->doc_node->nsdoc, &nsstr);
816 else
817 nsres = nsIDOMHTMLDocument_Writeln(This->doc_node->nsdoc, &nsstr);
818 if(NS_FAILED(nsres))
819 ERR("Write failed: %08x\n", nsres);
820 }else {
821 FIXME("vt=%d\n", V_VT(var+i));
825 nsAString_Finish(&nsstr);
826 SafeArrayUnaccessData(psarray);
828 return S_OK;
831 static HRESULT WINAPI HTMLDocument_write(IHTMLDocument2 *iface, SAFEARRAY *psarray)
833 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
835 TRACE("(%p)->(%p)\n", iface, psarray);
837 return document_write(This, psarray, FALSE);
840 static HRESULT WINAPI HTMLDocument_writeln(IHTMLDocument2 *iface, SAFEARRAY *psarray)
842 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
844 TRACE("(%p)->(%p)\n", This, psarray);
846 return document_write(This, psarray, TRUE);
849 static HRESULT WINAPI HTMLDocument_open(IHTMLDocument2 *iface, BSTR url, VARIANT name,
850 VARIANT features, VARIANT replace, IDispatch **pomWindowResult)
852 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
853 nsresult nsres;
855 static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};
857 TRACE("(%p)->(%s %s %s %s %p)\n", This, debugstr_w(url), debugstr_variant(&name),
858 debugstr_variant(&features), debugstr_variant(&replace), pomWindowResult);
860 if(!This->doc_node->nsdoc) {
861 ERR("!nsdoc\n");
862 return E_NOTIMPL;
865 if(!url || strcmpW(url, text_htmlW) || V_VT(&name) != VT_ERROR
866 || V_VT(&features) != VT_ERROR || V_VT(&replace) != VT_ERROR)
867 FIXME("unsupported args\n");
869 nsres = nsIDOMHTMLDocument_Open(This->doc_node->nsdoc);
870 if(NS_FAILED(nsres)) {
871 ERR("Open failed: %08x\n", nsres);
872 return E_FAIL;
875 *pomWindowResult = (IDispatch*)HTMLWINDOW2(This->window);
876 IHTMLWindow2_AddRef(HTMLWINDOW2(This->window));
877 return S_OK;
880 static HRESULT WINAPI HTMLDocument_close(IHTMLDocument2 *iface)
882 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
883 nsresult nsres;
885 TRACE("(%p)\n", This);
887 if(!This->doc_node->nsdoc) {
888 ERR("!nsdoc\n");
889 return E_NOTIMPL;
892 nsres = nsIDOMHTMLDocument_Close(This->doc_node->nsdoc);
893 if(NS_FAILED(nsres)) {
894 ERR("Close failed: %08x\n", nsres);
895 return E_FAIL;
898 return S_OK;
901 static HRESULT WINAPI HTMLDocument_clear(IHTMLDocument2 *iface)
903 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
904 nsIDOMNSHTMLDocument *nsdoc;
905 nsresult nsres;
907 TRACE("(%p)\n", This);
909 nsres = nsIDOMHTMLDocument_QueryInterface(This->doc_node->nsdoc, &IID_nsIDOMNSHTMLDocument, (void**)&nsdoc);
910 if(NS_FAILED(nsres)) {
911 ERR("Could not get nsIDOMNSHTMLDocument iface: %08x\n", nsres);
912 return E_FAIL;
915 nsres = nsIDOMNSHTMLDocument_Clear(nsdoc);
916 nsIDOMNSHTMLDocument_Release(nsdoc);
917 if(NS_FAILED(nsres)) {
918 ERR("Clear failed: %08x\n", nsres);
919 return E_FAIL;
922 return S_OK;
925 static HRESULT WINAPI HTMLDocument_queryCommandSupported(IHTMLDocument2 *iface, BSTR cmdID,
926 VARIANT_BOOL *pfRet)
928 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
929 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
930 return E_NOTIMPL;
933 static HRESULT WINAPI HTMLDocument_queryCommandEnabled(IHTMLDocument2 *iface, BSTR cmdID,
934 VARIANT_BOOL *pfRet)
936 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
937 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
938 return E_NOTIMPL;
941 static HRESULT WINAPI HTMLDocument_queryCommandState(IHTMLDocument2 *iface, BSTR cmdID,
942 VARIANT_BOOL *pfRet)
944 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
945 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
946 return E_NOTIMPL;
949 static HRESULT WINAPI HTMLDocument_queryCommandIndeterm(IHTMLDocument2 *iface, BSTR cmdID,
950 VARIANT_BOOL *pfRet)
952 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
953 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
954 return E_NOTIMPL;
957 static HRESULT WINAPI HTMLDocument_queryCommandText(IHTMLDocument2 *iface, BSTR cmdID,
958 BSTR *pfRet)
960 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
961 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
962 return E_NOTIMPL;
965 static HRESULT WINAPI HTMLDocument_queryCommandValue(IHTMLDocument2 *iface, BSTR cmdID,
966 VARIANT *pfRet)
968 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
969 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
970 return E_NOTIMPL;
973 static HRESULT WINAPI HTMLDocument_execCommand(IHTMLDocument2 *iface, BSTR cmdID,
974 VARIANT_BOOL showUI, VARIANT value, VARIANT_BOOL *pfRet)
976 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
977 FIXME("(%p)->(%s %x %p)\n", This, debugstr_w(cmdID), showUI, pfRet);
978 return E_NOTIMPL;
981 static HRESULT WINAPI HTMLDocument_execCommandShowHelp(IHTMLDocument2 *iface, BSTR cmdID,
982 VARIANT_BOOL *pfRet)
984 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
985 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
986 return E_NOTIMPL;
989 static HRESULT WINAPI HTMLDocument_createElement(IHTMLDocument2 *iface, BSTR eTag,
990 IHTMLElement **newElem)
992 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
993 nsIDOMHTMLElement *nselem;
994 HTMLElement *elem;
995 HRESULT hres;
997 TRACE("(%p)->(%s %p)\n", This, debugstr_w(eTag), newElem);
999 hres = create_nselem(This->doc_node, eTag, &nselem);
1000 if(FAILED(hres))
1001 return hres;
1003 hres = HTMLElement_Create(This->doc_node, (nsIDOMNode*)nselem, TRUE, &elem);
1004 nsIDOMHTMLElement_Release(nselem);
1005 if(FAILED(hres))
1006 return hres;
1008 *newElem = HTMLELEM(elem);
1009 IHTMLElement_AddRef(HTMLELEM(elem));
1010 return S_OK;
1013 static HRESULT WINAPI HTMLDocument_put_onhelp(IHTMLDocument2 *iface, VARIANT v)
1015 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1016 FIXME("(%p)\n", This);
1017 return E_NOTIMPL;
1020 static HRESULT WINAPI HTMLDocument_get_onhelp(IHTMLDocument2 *iface, VARIANT *p)
1022 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1023 FIXME("(%p)->(%p)\n", This, p);
1024 return E_NOTIMPL;
1027 static HRESULT WINAPI HTMLDocument_put_onclick(IHTMLDocument2 *iface, VARIANT v)
1029 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1031 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1033 return set_doc_event(This, EVENTID_CLICK, &v);
1036 static HRESULT WINAPI HTMLDocument_get_onclick(IHTMLDocument2 *iface, VARIANT *p)
1038 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1040 TRACE("(%p)->(%p)\n", This, p);
1042 return get_doc_event(This, EVENTID_CLICK, p);
1045 static HRESULT WINAPI HTMLDocument_put_ondblclick(IHTMLDocument2 *iface, VARIANT v)
1047 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1048 FIXME("(%p)\n", This);
1049 return E_NOTIMPL;
1052 static HRESULT WINAPI HTMLDocument_get_ondblclick(IHTMLDocument2 *iface, VARIANT *p)
1054 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1055 FIXME("(%p)->(%p)\n", This, p);
1056 return E_NOTIMPL;
1059 static HRESULT WINAPI HTMLDocument_put_onkeyup(IHTMLDocument2 *iface, VARIANT v)
1061 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1063 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1065 return set_doc_event(This, EVENTID_KEYUP, &v);
1068 static HRESULT WINAPI HTMLDocument_get_onkeyup(IHTMLDocument2 *iface, VARIANT *p)
1070 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1072 TRACE("(%p)->(%p)\n", This, p);
1074 return get_doc_event(This, EVENTID_KEYUP, p);
1077 static HRESULT WINAPI HTMLDocument_put_onkeydown(IHTMLDocument2 *iface, VARIANT v)
1079 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1081 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1083 return set_doc_event(This, EVENTID_KEYDOWN, &v);
1086 static HRESULT WINAPI HTMLDocument_get_onkeydown(IHTMLDocument2 *iface, VARIANT *p)
1088 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1090 TRACE("(%p)->(%p)\n", This, p);
1092 return get_doc_event(This, EVENTID_KEYDOWN, p);
1095 static HRESULT WINAPI HTMLDocument_put_onkeypress(IHTMLDocument2 *iface, VARIANT v)
1097 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1098 FIXME("(%p)\n", This);
1099 return E_NOTIMPL;
1102 static HRESULT WINAPI HTMLDocument_get_onkeypress(IHTMLDocument2 *iface, VARIANT *p)
1104 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1105 FIXME("(%p)->(%p)\n", This, p);
1106 return E_NOTIMPL;
1109 static HRESULT WINAPI HTMLDocument_put_onmouseup(IHTMLDocument2 *iface, VARIANT v)
1111 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1113 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1115 return set_doc_event(This, EVENTID_MOUSEUP, &v);
1118 static HRESULT WINAPI HTMLDocument_get_onmouseup(IHTMLDocument2 *iface, VARIANT *p)
1120 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1122 TRACE("(%p)->(%p)\n", This, p);
1124 return get_doc_event(This, EVENTID_MOUSEUP, p);
1127 static HRESULT WINAPI HTMLDocument_put_onmousedown(IHTMLDocument2 *iface, VARIANT v)
1129 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1131 TRACE("(%p)->()\n", This);
1133 return set_doc_event(This, EVENTID_MOUSEDOWN, &v);
1136 static HRESULT WINAPI HTMLDocument_get_onmousedown(IHTMLDocument2 *iface, VARIANT *p)
1138 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1140 TRACE("(%p)->(%p)\n", This, p);
1142 return get_doc_event(This, EVENTID_MOUSEDOWN, p);
1145 static HRESULT WINAPI HTMLDocument_put_onmousemove(IHTMLDocument2 *iface, VARIANT v)
1147 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1148 FIXME("(%p)\n", This);
1149 return E_NOTIMPL;
1152 static HRESULT WINAPI HTMLDocument_get_onmousemove(IHTMLDocument2 *iface, VARIANT *p)
1154 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1155 FIXME("(%p)->(%p)\n", This, p);
1156 return E_NOTIMPL;
1159 static HRESULT WINAPI HTMLDocument_put_onmouseout(IHTMLDocument2 *iface, VARIANT v)
1161 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1163 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1165 return set_doc_event(This, EVENTID_MOUSEOUT, &v);
1168 static HRESULT WINAPI HTMLDocument_get_onmouseout(IHTMLDocument2 *iface, VARIANT *p)
1170 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1172 TRACE("(%p)->(%p)\n", This, p);
1174 return get_doc_event(This, EVENTID_MOUSEOUT, p);
1177 static HRESULT WINAPI HTMLDocument_put_onmouseover(IHTMLDocument2 *iface, VARIANT v)
1179 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1181 TRACE("(%p)\n", This);
1183 return set_doc_event(This, EVENTID_MOUSEOVER, &v);
1186 static HRESULT WINAPI HTMLDocument_get_onmouseover(IHTMLDocument2 *iface, VARIANT *p)
1188 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1190 TRACE("(%p)->(%p)\n", This, p);
1192 return get_doc_event(This, EVENTID_MOUSEOVER, p);
1195 static HRESULT WINAPI HTMLDocument_put_onreadystatechange(IHTMLDocument2 *iface, VARIANT v)
1197 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1199 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1201 return set_doc_event(This, EVENTID_READYSTATECHANGE, &v);
1204 static HRESULT WINAPI HTMLDocument_get_onreadystatechange(IHTMLDocument2 *iface, VARIANT *p)
1206 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1208 TRACE("(%p)->(%p)\n", This, p);
1210 return get_doc_event(This, EVENTID_READYSTATECHANGE, p);
1213 static HRESULT WINAPI HTMLDocument_put_onafterupdate(IHTMLDocument2 *iface, VARIANT v)
1215 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1216 FIXME("(%p)\n", This);
1217 return E_NOTIMPL;
1220 static HRESULT WINAPI HTMLDocument_get_onafterupdate(IHTMLDocument2 *iface, VARIANT *p)
1222 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1223 FIXME("(%p)->(%p)\n", This, p);
1224 return E_NOTIMPL;
1227 static HRESULT WINAPI HTMLDocument_put_onrowexit(IHTMLDocument2 *iface, VARIANT v)
1229 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1230 FIXME("(%p)\n", This);
1231 return E_NOTIMPL;
1234 static HRESULT WINAPI HTMLDocument_get_onrowexit(IHTMLDocument2 *iface, VARIANT *p)
1236 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1237 FIXME("(%p)->(%p)\n", This, p);
1238 return E_NOTIMPL;
1241 static HRESULT WINAPI HTMLDocument_put_onrowenter(IHTMLDocument2 *iface, VARIANT v)
1243 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1244 FIXME("(%p)\n", This);
1245 return E_NOTIMPL;
1248 static HRESULT WINAPI HTMLDocument_get_onrowenter(IHTMLDocument2 *iface, VARIANT *p)
1250 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1251 FIXME("(%p)->(%p)\n", This, p);
1252 return E_NOTIMPL;
1255 static HRESULT WINAPI HTMLDocument_put_ondragstart(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_DRAGSTART, &v);
1264 static HRESULT WINAPI HTMLDocument_get_ondragstart(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_DRAGSTART, p);
1273 static HRESULT WINAPI HTMLDocument_put_onselectstart(IHTMLDocument2 *iface, VARIANT v)
1275 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1277 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1279 return set_doc_event(This, EVENTID_SELECTSTART, &v);
1282 static HRESULT WINAPI HTMLDocument_get_onselectstart(IHTMLDocument2 *iface, VARIANT *p)
1284 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1286 TRACE("(%p)->(%p)\n", This, p);
1288 return get_doc_event(This, EVENTID_SELECTSTART, p);
1291 static HRESULT WINAPI HTMLDocument_elementFromPoint(IHTMLDocument2 *iface, LONG x, LONG y,
1292 IHTMLElement **elementHit)
1294 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1295 FIXME("(%p)->(%d %d %p)\n", This, x, y, elementHit);
1296 return E_NOTIMPL;
1299 static HRESULT WINAPI HTMLDocument_get_parentWindow(IHTMLDocument2 *iface, IHTMLWindow2 **p)
1301 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1303 TRACE("(%p)->(%p)\n", This, p);
1305 *p = HTMLWINDOW2(This->window);
1306 IHTMLWindow2_AddRef(*p);
1307 return S_OK;
1310 static HRESULT WINAPI HTMLDocument_get_styleSheets(IHTMLDocument2 *iface,
1311 IHTMLStyleSheetsCollection **p)
1313 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1314 nsIDOMStyleSheetList *nsstylelist;
1315 nsIDOMDocumentStyle *nsdocstyle;
1316 nsresult nsres;
1318 TRACE("(%p)->(%p)\n", This, p);
1320 *p = NULL;
1322 if(!This->doc_node->nsdoc) {
1323 WARN("NULL nsdoc\n");
1324 return E_UNEXPECTED;
1327 nsIDOMHTMLDocument_QueryInterface(This->doc_node->nsdoc, &IID_nsIDOMDocumentStyle, (void**)&nsdocstyle);
1328 nsres = nsIDOMDocumentStyle_GetStyleSheets(nsdocstyle, &nsstylelist);
1329 nsIDOMDocumentStyle_Release(nsdocstyle);
1330 if(NS_FAILED(nsres)) {
1331 ERR("GetStyleSheets failed: %08x\n", nsres);
1332 return E_FAIL;
1335 *p = HTMLStyleSheetsCollection_Create(nsstylelist);
1336 nsIDOMDocumentStyle_Release(nsstylelist);
1338 return S_OK;
1341 static HRESULT WINAPI HTMLDocument_put_onbeforeupdate(IHTMLDocument2 *iface, VARIANT v)
1343 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1344 FIXME("(%p)\n", This);
1345 return E_NOTIMPL;
1348 static HRESULT WINAPI HTMLDocument_get_onbeforeupdate(IHTMLDocument2 *iface, VARIANT *p)
1350 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1351 FIXME("(%p)->(%p)\n", This, p);
1352 return E_NOTIMPL;
1355 static HRESULT WINAPI HTMLDocument_put_onerrorupdate(IHTMLDocument2 *iface, VARIANT v)
1357 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1358 FIXME("(%p)\n", This);
1359 return E_NOTIMPL;
1362 static HRESULT WINAPI HTMLDocument_get_onerrorupdate(IHTMLDocument2 *iface, VARIANT *p)
1364 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1365 FIXME("(%p)->(%p)\n", This, p);
1366 return E_NOTIMPL;
1369 static HRESULT WINAPI HTMLDocument_toString(IHTMLDocument2 *iface, BSTR *String)
1371 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1372 FIXME("(%p)->(%p)\n", This, String);
1373 return E_NOTIMPL;
1376 static HRESULT WINAPI HTMLDocument_createStyleSheet(IHTMLDocument2 *iface, BSTR bstrHref,
1377 LONG lIndex, IHTMLStyleSheet **ppnewStyleSheet)
1379 HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1381 FIXME("(%p)->(%s %d %p) semi-stub\n", This, debugstr_w(bstrHref), lIndex, ppnewStyleSheet);
1383 *ppnewStyleSheet = HTMLStyleSheet_Create(NULL);
1384 return S_OK;
1387 static const IHTMLDocument2Vtbl HTMLDocumentVtbl = {
1388 HTMLDocument_QueryInterface,
1389 HTMLDocument_AddRef,
1390 HTMLDocument_Release,
1391 HTMLDocument_GetTypeInfoCount,
1392 HTMLDocument_GetTypeInfo,
1393 HTMLDocument_GetIDsOfNames,
1394 HTMLDocument_Invoke,
1395 HTMLDocument_get_Script,
1396 HTMLDocument_get_all,
1397 HTMLDocument_get_body,
1398 HTMLDocument_get_activeElement,
1399 HTMLDocument_get_images,
1400 HTMLDocument_get_applets,
1401 HTMLDocument_get_links,
1402 HTMLDocument_get_forms,
1403 HTMLDocument_get_anchors,
1404 HTMLDocument_put_title,
1405 HTMLDocument_get_title,
1406 HTMLDocument_get_scripts,
1407 HTMLDocument_put_designMode,
1408 HTMLDocument_get_designMode,
1409 HTMLDocument_get_selection,
1410 HTMLDocument_get_readyState,
1411 HTMLDocument_get_frames,
1412 HTMLDocument_get_embeds,
1413 HTMLDocument_get_plugins,
1414 HTMLDocument_put_alinkColor,
1415 HTMLDocument_get_alinkColor,
1416 HTMLDocument_put_bgColor,
1417 HTMLDocument_get_bgColor,
1418 HTMLDocument_put_fgColor,
1419 HTMLDocument_get_fgColor,
1420 HTMLDocument_put_linkColor,
1421 HTMLDocument_get_linkColor,
1422 HTMLDocument_put_vlinkColor,
1423 HTMLDocument_get_vlinkColor,
1424 HTMLDocument_get_referrer,
1425 HTMLDocument_get_location,
1426 HTMLDocument_get_lastModified,
1427 HTMLDocument_put_URL,
1428 HTMLDocument_get_URL,
1429 HTMLDocument_put_domain,
1430 HTMLDocument_get_domain,
1431 HTMLDocument_put_cookie,
1432 HTMLDocument_get_cookie,
1433 HTMLDocument_put_expando,
1434 HTMLDocument_get_expando,
1435 HTMLDocument_put_charset,
1436 HTMLDocument_get_charset,
1437 HTMLDocument_put_defaultCharset,
1438 HTMLDocument_get_defaultCharset,
1439 HTMLDocument_get_mimeType,
1440 HTMLDocument_get_fileSize,
1441 HTMLDocument_get_fileCreatedDate,
1442 HTMLDocument_get_fileModifiedDate,
1443 HTMLDocument_get_fileUpdatedDate,
1444 HTMLDocument_get_security,
1445 HTMLDocument_get_protocol,
1446 HTMLDocument_get_nameProp,
1447 HTMLDocument_write,
1448 HTMLDocument_writeln,
1449 HTMLDocument_open,
1450 HTMLDocument_close,
1451 HTMLDocument_clear,
1452 HTMLDocument_queryCommandSupported,
1453 HTMLDocument_queryCommandEnabled,
1454 HTMLDocument_queryCommandState,
1455 HTMLDocument_queryCommandIndeterm,
1456 HTMLDocument_queryCommandText,
1457 HTMLDocument_queryCommandValue,
1458 HTMLDocument_execCommand,
1459 HTMLDocument_execCommandShowHelp,
1460 HTMLDocument_createElement,
1461 HTMLDocument_put_onhelp,
1462 HTMLDocument_get_onhelp,
1463 HTMLDocument_put_onclick,
1464 HTMLDocument_get_onclick,
1465 HTMLDocument_put_ondblclick,
1466 HTMLDocument_get_ondblclick,
1467 HTMLDocument_put_onkeyup,
1468 HTMLDocument_get_onkeyup,
1469 HTMLDocument_put_onkeydown,
1470 HTMLDocument_get_onkeydown,
1471 HTMLDocument_put_onkeypress,
1472 HTMLDocument_get_onkeypress,
1473 HTMLDocument_put_onmouseup,
1474 HTMLDocument_get_onmouseup,
1475 HTMLDocument_put_onmousedown,
1476 HTMLDocument_get_onmousedown,
1477 HTMLDocument_put_onmousemove,
1478 HTMLDocument_get_onmousemove,
1479 HTMLDocument_put_onmouseout,
1480 HTMLDocument_get_onmouseout,
1481 HTMLDocument_put_onmouseover,
1482 HTMLDocument_get_onmouseover,
1483 HTMLDocument_put_onreadystatechange,
1484 HTMLDocument_get_onreadystatechange,
1485 HTMLDocument_put_onafterupdate,
1486 HTMLDocument_get_onafterupdate,
1487 HTMLDocument_put_onrowexit,
1488 HTMLDocument_get_onrowexit,
1489 HTMLDocument_put_onrowenter,
1490 HTMLDocument_get_onrowenter,
1491 HTMLDocument_put_ondragstart,
1492 HTMLDocument_get_ondragstart,
1493 HTMLDocument_put_onselectstart,
1494 HTMLDocument_get_onselectstart,
1495 HTMLDocument_elementFromPoint,
1496 HTMLDocument_get_parentWindow,
1497 HTMLDocument_get_styleSheets,
1498 HTMLDocument_put_onbeforeupdate,
1499 HTMLDocument_get_onbeforeupdate,
1500 HTMLDocument_put_onerrorupdate,
1501 HTMLDocument_get_onerrorupdate,
1502 HTMLDocument_toString,
1503 HTMLDocument_createStyleSheet
1506 static void HTMLDocument_on_advise(IUnknown *iface, cp_static_data_t *cp)
1508 HTMLDocument *This = impl_from_IHTMLDocument2((IHTMLDocument2*)iface);
1510 if(This->window)
1511 update_cp_events(This->window, &This->doc_node->node.event_target, cp, This->doc_node->node.nsnode);
1514 #define SUPPINFO_THIS(iface) DEFINE_THIS(HTMLDocument, SupportErrorInfo, iface)
1516 static HRESULT WINAPI SupportErrorInfo_QueryInterface(ISupportErrorInfo *iface, REFIID riid, void **ppv)
1518 HTMLDocument *This = SUPPINFO_THIS(iface);
1519 return htmldoc_query_interface(This, riid, ppv);
1522 static ULONG WINAPI SupportErrorInfo_AddRef(ISupportErrorInfo *iface)
1524 HTMLDocument *This = SUPPINFO_THIS(iface);
1525 return htmldoc_addref(This);
1528 static ULONG WINAPI SupportErrorInfo_Release(ISupportErrorInfo *iface)
1530 HTMLDocument *This = SUPPINFO_THIS(iface);
1531 return htmldoc_release(This);
1534 static HRESULT WINAPI SupportErrorInfo_InterfaceSupportsErrorInfo(ISupportErrorInfo *iface, REFIID riid)
1536 FIXME("(%p)->(%s)\n", iface, debugstr_guid(riid));
1537 return S_FALSE;
1540 static const ISupportErrorInfoVtbl SupportErrorInfoVtbl = {
1541 SupportErrorInfo_QueryInterface,
1542 SupportErrorInfo_AddRef,
1543 SupportErrorInfo_Release,
1544 SupportErrorInfo_InterfaceSupportsErrorInfo
1547 #define DISPEX_THIS(iface) DEFINE_THIS(HTMLDocument, IDispatchEx, iface)
1549 static HRESULT WINAPI DocDispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
1551 HTMLDocument *This = DISPEX_THIS(iface);
1553 return htmldoc_query_interface(This, riid, ppv);
1556 static ULONG WINAPI DocDispatchEx_AddRef(IDispatchEx *iface)
1558 HTMLDocument *This = DISPEX_THIS(iface);
1560 return htmldoc_addref(This);
1563 static ULONG WINAPI DocDispatchEx_Release(IDispatchEx *iface)
1565 HTMLDocument *This = DISPEX_THIS(iface);
1567 return htmldoc_release(This);
1570 static HRESULT WINAPI DocDispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
1572 HTMLDocument *This = DISPEX_THIS(iface);
1574 return IDispatchEx_GetTypeInfoCount(This->dispex, pctinfo);
1577 static HRESULT WINAPI DocDispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
1578 LCID lcid, ITypeInfo **ppTInfo)
1580 HTMLDocument *This = DISPEX_THIS(iface);
1582 return IDispatchEx_GetTypeInfo(This->dispex, iTInfo, lcid, ppTInfo);
1585 static HRESULT WINAPI DocDispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
1586 LPOLESTR *rgszNames, UINT cNames,
1587 LCID lcid, DISPID *rgDispId)
1589 HTMLDocument *This = DISPEX_THIS(iface);
1591 return IDispatchEx_GetIDsOfNames(This->dispex, riid, rgszNames, cNames, lcid, rgDispId);
1594 static HRESULT WINAPI DocDispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
1595 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1596 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1598 HTMLDocument *This = DISPEX_THIS(iface);
1600 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1601 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1603 switch(dispIdMember) {
1604 case DISPID_READYSTATE:
1605 TRACE("DISPID_READYSTATE\n");
1607 if(!(wFlags & DISPATCH_PROPERTYGET))
1608 return E_INVALIDARG;
1610 V_VT(pVarResult) = VT_I4;
1611 V_I4(pVarResult) = This->window->readystate;
1612 return S_OK;
1615 return IDispatchEx_Invoke(This->dispex, dispIdMember, riid, lcid, wFlags, pDispParams,
1616 pVarResult, pExcepInfo, puArgErr);
1619 static HRESULT WINAPI DocDispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
1621 HTMLDocument *This = DISPEX_THIS(iface);
1623 return IDispatchEx_GetDispID(This->dispex, bstrName, grfdex, pid);
1626 static HRESULT WINAPI DocDispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1627 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1629 HTMLDocument *This = DISPEX_THIS(iface);
1631 if(This->window && id == DISPID_IHTMLDOCUMENT2_LOCATION && (wFlags & DISPATCH_PROPERTYPUT))
1632 return IDispatchEx_InvokeEx(DISPATCHEX(This->window), DISPID_IHTMLWINDOW2_LOCATION, lcid, wFlags,
1633 pdp, pvarRes, pei, pspCaller);
1636 return IDispatchEx_InvokeEx(This->dispex, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1639 static HRESULT WINAPI DocDispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
1641 HTMLDocument *This = DISPEX_THIS(iface);
1643 return IDispatchEx_DeleteMemberByName(This->dispex, bstrName, grfdex);
1646 static HRESULT WINAPI DocDispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
1648 HTMLDocument *This = DISPEX_THIS(iface);
1650 return IDispatchEx_DeleteMemberByDispID(This->dispex, id);
1653 static HRESULT WINAPI DocDispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
1655 HTMLDocument *This = DISPEX_THIS(iface);
1657 return IDispatchEx_GetMemberProperties(This->dispex, id, grfdexFetch, pgrfdex);
1660 static HRESULT WINAPI DocDispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
1662 HTMLDocument *This = DISPEX_THIS(iface);
1664 return IDispatchEx_GetMemberName(This->dispex, id, pbstrName);
1667 static HRESULT WINAPI DocDispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
1669 HTMLDocument *This = DISPEX_THIS(iface);
1671 return IDispatchEx_GetNextDispID(This->dispex, grfdex, id, pid);
1674 static HRESULT WINAPI DocDispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
1676 HTMLDocument *This = DISPEX_THIS(iface);
1678 return IDispatchEx_GetNameSpaceParent(This->dispex, ppunk);
1681 #undef DISPEX_THIS
1683 static const IDispatchExVtbl DocDispatchExVtbl = {
1684 DocDispatchEx_QueryInterface,
1685 DocDispatchEx_AddRef,
1686 DocDispatchEx_Release,
1687 DocDispatchEx_GetTypeInfoCount,
1688 DocDispatchEx_GetTypeInfo,
1689 DocDispatchEx_GetIDsOfNames,
1690 DocDispatchEx_Invoke,
1691 DocDispatchEx_GetDispID,
1692 DocDispatchEx_InvokeEx,
1693 DocDispatchEx_DeleteMemberByName,
1694 DocDispatchEx_DeleteMemberByDispID,
1695 DocDispatchEx_GetMemberProperties,
1696 DocDispatchEx_GetMemberName,
1697 DocDispatchEx_GetNextDispID,
1698 DocDispatchEx_GetNameSpaceParent
1701 static BOOL htmldoc_qi(HTMLDocument *This, REFIID riid, void **ppv)
1703 *ppv = NULL;
1705 if(IsEqualGUID(&IID_IUnknown, riid)) {
1706 TRACE("(%p)->(IID_IUnknown, %p)\n", This, ppv);
1707 *ppv = &This->IHTMLDocument2_iface;
1708 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1709 TRACE("(%p)->(IID_IDispatch, %p)\n", This, ppv);
1710 *ppv = DISPATCHEX(This);
1711 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
1712 TRACE("(%p)->(IID_IDispatchEx, %p)\n", This, ppv);
1713 *ppv = DISPATCHEX(This);
1714 }else if(IsEqualGUID(&IID_IHTMLDocument, riid)) {
1715 TRACE("(%p)->(IID_IHTMLDocument, %p)\n", This, ppv);
1716 *ppv = &This->IHTMLDocument2_iface;
1717 }else if(IsEqualGUID(&IID_IHTMLDocument2, riid)) {
1718 TRACE("(%p)->(IID_IHTMLDocument2, %p)\n", This, ppv);
1719 *ppv = &This->IHTMLDocument2_iface;
1720 }else if(IsEqualGUID(&IID_IHTMLDocument3, riid)) {
1721 TRACE("(%p)->(IID_IHTMLDocument3, %p)\n", This, ppv);
1722 *ppv = &This->IHTMLDocument3_iface;
1723 }else if(IsEqualGUID(&IID_IHTMLDocument4, riid)) {
1724 TRACE("(%p)->(IID_IHTMLDocument4, %p)\n", This, ppv);
1725 *ppv = &This->IHTMLDocument4_iface;
1726 }else if(IsEqualGUID(&IID_IHTMLDocument5, riid)) {
1727 TRACE("(%p)->(IID_IHTMLDocument5, %p)\n", This, ppv);
1728 *ppv = &This->IHTMLDocument5_iface;
1729 }else if(IsEqualGUID(&IID_IHTMLDocument6, riid)) {
1730 TRACE("(%p)->(IID_IHTMLDocument6, %p)\n", This, ppv);
1731 *ppv = &This->IHTMLDocument6_iface;
1732 }else if(IsEqualGUID(&IID_IPersist, riid)) {
1733 TRACE("(%p)->(IID_IPersist, %p)\n", This, ppv);
1734 *ppv = &This->IPersistFile_iface;
1735 }else if(IsEqualGUID(&IID_IPersistMoniker, riid)) {
1736 TRACE("(%p)->(IID_IPersistMoniker, %p)\n", This, ppv);
1737 *ppv = &This->IPersistMoniker_iface;
1738 }else if(IsEqualGUID(&IID_IPersistFile, riid)) {
1739 TRACE("(%p)->(IID_IPersistFile, %p)\n", This, ppv);
1740 *ppv = &This->IPersistFile_iface;
1741 }else if(IsEqualGUID(&IID_IMonikerProp, riid)) {
1742 TRACE("(%p)->(IID_IMonikerProp, %p)\n", This, ppv);
1743 *ppv = &This->IMonikerProp_iface;
1744 }else if(IsEqualGUID(&IID_IOleObject, riid)) {
1745 TRACE("(%p)->(IID_IOleObject, %p)\n", This, ppv);
1746 *ppv = OLEOBJ(This);
1747 }else if(IsEqualGUID(&IID_IOleDocument, riid)) {
1748 TRACE("(%p)->(IID_IOleDocument, %p)\n", This, ppv);
1749 *ppv = OLEDOC(This);
1750 }else if(IsEqualGUID(&IID_IOleDocumentView, riid)) {
1751 TRACE("(%p)->(IID_IOleDocumentView, %p)\n", This, ppv);
1752 *ppv = DOCVIEW(This);
1753 }else if(IsEqualGUID(&IID_IOleInPlaceActiveObject, riid)) {
1754 TRACE("(%p)->(IID_IOleInPlaceActiveObject, %p)\n", This, ppv);
1755 *ppv = ACTOBJ(This);
1756 }else if(IsEqualGUID(&IID_IViewObject, riid)) {
1757 TRACE("(%p)->(IID_IViewObject, %p)\n", This, ppv);
1758 *ppv = VIEWOBJ(This);
1759 }else if(IsEqualGUID(&IID_IViewObject2, riid)) {
1760 TRACE("(%p)->(IID_IViewObject2, %p)\n", This, ppv);
1761 *ppv = VIEWOBJ2(This);
1762 }else if(IsEqualGUID(&IID_IViewObjectEx, riid)) {
1763 TRACE("(%p)->(IID_IViewObjectEx, %p)\n", This, ppv);
1764 *ppv = VIEWOBJEX(This);
1765 }else if(IsEqualGUID(&IID_IOleWindow, riid)) {
1766 TRACE("(%p)->(IID_IOleWindow, %p)\n", This, ppv);
1767 *ppv = OLEWIN(This);
1768 }else if(IsEqualGUID(&IID_IOleInPlaceObject, riid)) {
1769 TRACE("(%p)->(IID_IOleInPlaceObject, %p)\n", This, ppv);
1770 *ppv = INPLACEOBJ(This);
1771 }else if(IsEqualGUID(&IID_IOleInPlaceObjectWindowless, riid)) {
1772 TRACE("(%p)->(IID_IOleInPlaceObjectWindowless, %p)\n", This, ppv);
1773 *ppv = INPLACEWIN(This);
1774 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
1775 TRACE("(%p)->(IID_IServiceProvider, %p)\n", This, ppv);
1776 *ppv = SERVPROV(This);
1777 }else if(IsEqualGUID(&IID_IOleCommandTarget, riid)) {
1778 TRACE("(%p)->(IID_IOleCommandTarget, %p)\n", This, ppv);
1779 *ppv = CMDTARGET(This);
1780 }else if(IsEqualGUID(&IID_IOleControl, riid)) {
1781 TRACE("(%p)->(IID_IOleControl, %p)\n", This, ppv);
1782 *ppv = CONTROL(This);
1783 }else if(IsEqualGUID(&IID_IHlinkTarget, riid)) {
1784 TRACE("(%p)->(IID_IHlinkTarget, %p)\n", This, ppv);
1785 *ppv = HLNKTARGET(This);
1786 }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
1787 TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppv);
1788 *ppv = CONPTCONT(&This->cp_container);
1789 }else if(IsEqualGUID(&IID_IPersistStreamInit, riid)) {
1790 TRACE("(%p)->(IID_IPersistStreamInit %p)\n", This, ppv);
1791 *ppv = &This->IPersistStreamInit_iface;
1792 }else if(IsEqualGUID(&DIID_DispHTMLDocument, riid)) {
1793 TRACE("(%p)->(DIID_DispHTMLDocument %p)\n", This, ppv);
1794 *ppv = &This->IHTMLDocument2_iface;
1795 }else if(IsEqualGUID(&IID_ISupportErrorInfo, riid)) {
1796 TRACE("(%p)->(IID_ISupportErrorInfo %p)\n", This, ppv);
1797 *ppv = SUPPERRINFO(This);
1798 }else if(IsEqualGUID(&IID_IPersistHistory, riid)) {
1799 TRACE("(%p)->(IID_IPersistHistory %p)\n", This, ppv);
1800 *ppv = &This->IPersistHistory_iface;
1801 }else if(IsEqualGUID(&CLSID_CMarkup, riid)) {
1802 FIXME("(%p)->(CLSID_CMarkup %p)\n", This, ppv);
1803 *ppv = NULL;
1804 }else if(IsEqualGUID(&IID_IRunnableObject, riid)) {
1805 TRACE("(%p)->(IID_IRunnableObject %p) returning NULL\n", This, ppv);
1806 *ppv = NULL;
1807 }else if(IsEqualGUID(&IID_IPersistPropertyBag, riid)) {
1808 TRACE("(%p)->(IID_IPersistPropertyBag %p) returning NULL\n", This, ppv);
1809 *ppv = NULL;
1810 }else if(IsEqualGUID(&IID_IMarshal, riid)) {
1811 TRACE("(%p)->(IID_IMarshal %p) returning NULL\n", This, ppv);
1812 *ppv = NULL;
1813 }else if(IsEqualGUID(&IID_IExternalConnection, riid)) {
1814 TRACE("(%p)->(IID_IExternalConnection %p) returning NULL\n", This, ppv);
1815 *ppv = NULL;
1816 }else if(IsEqualGUID(&IID_IStdMarshalInfo, riid)) {
1817 TRACE("(%p)->(IID_IStdMarshalInfo %p) returning NULL\n", This, ppv);
1818 *ppv = NULL;
1819 }else if(IsEqualGUID(&IID_IObjectWithSite, riid)) {
1820 TRACE("(%p)->(IID_IObjectWithSite %p)\n", This, ppv);
1821 *ppv = OBJSITE(This);
1822 }else if(IsEqualGUID(&IID_IOleContainer, riid)) {
1823 TRACE("(%p)->(IID_IOleContainer %p)\n", This, ppv);
1824 *ppv = &This->IOleContainer_iface;
1825 }else {
1826 return FALSE;
1829 if(*ppv)
1830 IUnknown_AddRef((IUnknown*)*ppv);
1831 return TRUE;
1834 static cp_static_data_t HTMLDocumentEvents_data = { HTMLDocumentEvents_tid, HTMLDocument_on_advise };
1836 static void init_doc(HTMLDocument *doc, IUnknown *unk_impl, IDispatchEx *dispex)
1838 doc->IHTMLDocument2_iface.lpVtbl = &HTMLDocumentVtbl;
1839 doc->lpIDispatchExVtbl = &DocDispatchExVtbl;
1840 doc->lpSupportErrorInfoVtbl = &SupportErrorInfoVtbl;
1842 doc->unk_impl = unk_impl;
1843 doc->dispex = dispex;
1844 doc->task_magic = get_task_target_magic();
1846 HTMLDocument_HTMLDocument3_Init(doc);
1847 HTMLDocument_HTMLDocument5_Init(doc);
1848 HTMLDocument_Persist_Init(doc);
1849 HTMLDocument_OleCmd_Init(doc);
1850 HTMLDocument_OleObj_Init(doc);
1851 HTMLDocument_View_Init(doc);
1852 HTMLDocument_Window_Init(doc);
1853 HTMLDocument_Service_Init(doc);
1854 HTMLDocument_Hlink_Init(doc);
1856 ConnectionPointContainer_Init(&doc->cp_container, (IUnknown*)&doc->IHTMLDocument2_iface);
1857 ConnectionPoint_Init(&doc->cp_dispatch, &doc->cp_container, &IID_IDispatch, NULL);
1858 ConnectionPoint_Init(&doc->cp_propnotif, &doc->cp_container, &IID_IPropertyNotifySink, NULL);
1859 ConnectionPoint_Init(&doc->cp_htmldocevents, &doc->cp_container, &DIID_HTMLDocumentEvents, &HTMLDocumentEvents_data);
1860 ConnectionPoint_Init(&doc->cp_htmldocevents2, &doc->cp_container, &DIID_HTMLDocumentEvents2, NULL);
1863 static void destroy_htmldoc(HTMLDocument *This)
1865 remove_target_tasks(This->task_magic);
1867 ConnectionPointContainer_Destroy(&This->cp_container);
1870 #define HTMLDOCNODE_NODE_THIS(iface) DEFINE_THIS2(HTMLDocumentNode, node, iface)
1872 static HRESULT HTMLDocumentNode_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
1874 HTMLDocumentNode *This = HTMLDOCNODE_NODE_THIS(iface);
1876 if(htmldoc_qi(&This->basedoc, riid, ppv))
1877 return *ppv ? S_OK : E_NOINTERFACE;
1879 if(IsEqualGUID(&IID_IInternetHostSecurityManager, riid)) {
1880 TRACE("(%p)->(IID_IInternetHostSecurityManager %p)\n", This, ppv);
1881 *ppv = HOSTSECMGR(This);
1882 }else {
1883 return HTMLDOMNode_QI(&This->node, riid, ppv);
1886 IUnknown_AddRef((IUnknown*)*ppv);
1887 return S_OK;
1890 static void HTMLDocumentNode_destructor(HTMLDOMNode *iface)
1892 HTMLDocumentNode *This = HTMLDOCNODE_NODE_THIS(iface);
1894 if(This->body_event_target)
1895 release_event_target(This->body_event_target);
1896 if(This->nsevent_listener)
1897 release_nsevents(This);
1898 if(This->catmgr)
1899 ICatInformation_Release(This->catmgr);
1900 if(This->secmgr)
1901 IInternetSecurityManager_Release(This->secmgr);
1903 detach_selection(This);
1904 detach_ranges(This);
1905 release_nodes(This);
1907 while(!list_empty(&This->plugin_hosts))
1908 detach_plugin_host(LIST_ENTRY(list_head(&This->plugin_hosts), PluginHost, entry));
1910 if(This->nsdoc) {
1911 release_mutation(This);
1912 nsIDOMHTMLDocument_Release(This->nsdoc);
1915 heap_free(This->event_vector);
1916 destroy_htmldoc(&This->basedoc);
1919 static HRESULT HTMLDocumentNode_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
1921 HTMLDocumentNode *This = HTMLDOCNODE_NODE_THIS(iface);
1922 FIXME("%p\n", This);
1923 return E_NOTIMPL;
1926 static const NodeImplVtbl HTMLDocumentNodeImplVtbl = {
1927 HTMLDocumentNode_QI,
1928 HTMLDocumentNode_destructor,
1929 HTMLDocumentNode_clone
1932 static HRESULT HTMLDocumentFragment_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
1934 HTMLDocumentNode *This = HTMLDOCNODE_NODE_THIS(iface);
1935 HTMLDocumentNode *new_node;
1936 HRESULT hres;
1938 hres = create_document_fragment(nsnode, This->node.doc, &new_node);
1939 if(FAILED(hres))
1940 return hres;
1942 *ret = &new_node->node;
1943 return S_OK;
1946 #undef HTMLDOCNODE_NODE_THIS
1948 static const NodeImplVtbl HTMLDocumentFragmentImplVtbl = {
1949 HTMLDocumentNode_QI,
1950 HTMLDocumentNode_destructor,
1951 HTMLDocumentFragment_clone
1954 static const tid_t HTMLDocumentNode_iface_tids[] = {
1955 IHTMLDOMNode_tid,
1956 IHTMLDOMNode2_tid,
1957 IHTMLDocument2_tid,
1958 IHTMLDocument3_tid,
1959 IHTMLDocument4_tid,
1960 IHTMLDocument5_tid,
1964 static dispex_static_data_t HTMLDocumentNode_dispex = {
1965 NULL,
1966 DispHTMLDocument_tid,
1967 NULL,
1968 HTMLDocumentNode_iface_tids
1971 static HTMLDocumentNode *alloc_doc_node(HTMLDocumentObj *doc_obj, HTMLWindow *window)
1973 HTMLDocumentNode *doc;
1975 doc = heap_alloc_zero(sizeof(HTMLDocumentNode));
1976 if(!doc)
1977 return NULL;
1979 doc->ref = 1;
1980 doc->basedoc.doc_node = doc;
1981 doc->basedoc.doc_obj = doc_obj;
1982 doc->basedoc.window = window;
1984 init_dispex(&doc->node.dispex, (IUnknown*)HTMLDOMNODE(&doc->node), &HTMLDocumentNode_dispex);
1985 init_doc(&doc->basedoc, (IUnknown*)HTMLDOMNODE(&doc->node), DISPATCHEX(&doc->node.dispex));
1986 HTMLDocumentNode_SecMgr_Init(doc);
1988 init_nsevents(doc);
1990 list_init(&doc->bindings);
1991 list_init(&doc->selection_list);
1992 list_init(&doc->range_list);
1993 list_init(&doc->plugin_hosts);
1995 return doc;
1998 HRESULT create_doc_from_nsdoc(nsIDOMHTMLDocument *nsdoc, HTMLDocumentObj *doc_obj, HTMLWindow *window, HTMLDocumentNode **ret)
2000 HTMLDocumentNode *doc;
2001 HRESULT hres;
2003 doc = alloc_doc_node(doc_obj, window);
2004 if(!doc)
2005 return E_OUTOFMEMORY;
2007 if(window == doc_obj->basedoc.window)
2008 doc->basedoc.cp_container.forward_container = &doc_obj->basedoc.cp_container;
2010 nsIDOMHTMLDocument_AddRef(nsdoc);
2011 doc->nsdoc = nsdoc;
2012 init_mutation(doc);
2014 HTMLDOMNode_Init(doc, &doc->node, (nsIDOMNode*)nsdoc);
2015 doc->node.vtbl = &HTMLDocumentNodeImplVtbl;
2016 doc->node.cp_container = &doc->basedoc.cp_container;
2018 hres = CoInternetCreateSecurityManager(NULL, &doc->secmgr, 0);
2019 if(FAILED(hres)) {
2020 htmldoc_release(&doc->basedoc);
2021 return hres;
2024 *ret = doc;
2025 return S_OK;
2028 HRESULT create_document_fragment(nsIDOMNode *nsnode, HTMLDocumentNode *doc_node, HTMLDocumentNode **ret)
2030 HTMLDocumentNode *doc_frag;
2032 doc_frag = alloc_doc_node(doc_node->basedoc.doc_obj, doc_node->basedoc.window);
2033 if(!doc_frag)
2034 return E_OUTOFMEMORY;
2036 HTMLDOMNode_Init(doc_node, &doc_frag->node, nsnode);
2037 doc_frag->node.vtbl = &HTMLDocumentFragmentImplVtbl;
2038 doc_frag->node.cp_container = &doc_frag->basedoc.cp_container;
2040 htmldoc_addref(&doc_frag->basedoc);
2041 *ret = doc_frag;
2042 return S_OK;
2045 /**********************************************************
2046 * ICustomDoc implementation
2049 #define CUSTOMDOC_THIS(iface) DEFINE_THIS(HTMLDocumentObj, CustomDoc, iface)
2051 static HRESULT WINAPI CustomDoc_QueryInterface(ICustomDoc *iface, REFIID riid, void **ppv)
2053 HTMLDocumentObj *This = CUSTOMDOC_THIS(iface);
2055 if(htmldoc_qi(&This->basedoc, riid, ppv))
2056 return *ppv ? S_OK : E_NOINTERFACE;
2058 if(IsEqualGUID(&IID_ICustomDoc, riid)) {
2059 TRACE("(%p)->(IID_ICustomDoc %p)\n", This, ppv);
2060 *ppv = CUSTOMDOC(This);
2061 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
2062 return *ppv ? S_OK : E_NOINTERFACE;
2063 }else {
2064 FIXME("Unimplemented interface %s\n", debugstr_guid(riid));
2065 *ppv = NULL;
2066 return E_NOINTERFACE;
2069 IUnknown_AddRef((IUnknown*)*ppv);
2070 return S_OK;
2073 static ULONG WINAPI CustomDoc_AddRef(ICustomDoc *iface)
2075 HTMLDocumentObj *This = CUSTOMDOC_THIS(iface);
2076 ULONG ref = InterlockedIncrement(&This->ref);
2078 TRACE("(%p) ref = %u\n", This, ref);
2080 return ref;
2083 static ULONG WINAPI CustomDoc_Release(ICustomDoc *iface)
2085 HTMLDocumentObj *This = CUSTOMDOC_THIS(iface);
2086 ULONG ref = InterlockedDecrement(&This->ref);
2088 TRACE("(%p) ref = %u\n", This, ref);
2090 if(!ref) {
2091 if(This->basedoc.doc_node) {
2092 This->basedoc.doc_node->basedoc.doc_obj = NULL;
2093 htmldoc_release(&This->basedoc.doc_node->basedoc);
2095 if(This->basedoc.window) {
2096 This->basedoc.window->doc_obj = NULL;
2097 IHTMLWindow2_Release(HTMLWINDOW2(This->basedoc.window));
2099 if(This->basedoc.advise_holder)
2100 IOleAdviseHolder_Release(This->basedoc.advise_holder);
2102 if(This->view_sink)
2103 IAdviseSink_Release(This->view_sink);
2104 if(This->client)
2105 IOleObject_SetClientSite(OLEOBJ(&This->basedoc), NULL);
2106 if(This->hostui)
2107 ICustomDoc_SetUIHandler(CUSTOMDOC(This), NULL);
2108 if(This->in_place_active)
2109 IOleInPlaceObjectWindowless_InPlaceDeactivate(INPLACEWIN(&This->basedoc));
2110 if(This->ipsite)
2111 IOleDocumentView_SetInPlaceSite(DOCVIEW(&This->basedoc), NULL);
2112 if(This->undomgr)
2113 IOleUndoManager_Release(This->undomgr);
2114 if(This->tooltips_hwnd)
2115 DestroyWindow(This->tooltips_hwnd);
2117 if(This->hwnd)
2118 DestroyWindow(This->hwnd);
2119 heap_free(This->mime);
2121 destroy_htmldoc(&This->basedoc);
2122 release_dispex(&This->dispex);
2124 if(This->nscontainer)
2125 NSContainer_Release(This->nscontainer);
2126 heap_free(This);
2129 return ref;
2132 static HRESULT WINAPI CustomDoc_SetUIHandler(ICustomDoc *iface, IDocHostUIHandler *pUIHandler)
2134 HTMLDocumentObj *This = CUSTOMDOC_THIS(iface);
2135 IOleCommandTarget *cmdtrg;
2136 HRESULT hres;
2138 TRACE("(%p)->(%p)\n", This, pUIHandler);
2140 if(This->custom_hostui && This->hostui == pUIHandler)
2141 return S_OK;
2143 This->custom_hostui = TRUE;
2145 if(This->hostui)
2146 IDocHostUIHandler_Release(This->hostui);
2147 if(pUIHandler)
2148 IDocHostUIHandler_AddRef(pUIHandler);
2149 This->hostui = pUIHandler;
2150 if(!pUIHandler)
2151 return S_OK;
2153 hres = IDocHostUIHandler_QueryInterface(pUIHandler, &IID_IOleCommandTarget, (void**)&cmdtrg);
2154 if(SUCCEEDED(hres)) {
2155 FIXME("custom UI handler supports IOleCommandTarget\n");
2156 IOleCommandTarget_Release(cmdtrg);
2159 return S_OK;
2162 #undef CUSTOMDOC_THIS
2164 static const ICustomDocVtbl CustomDocVtbl = {
2165 CustomDoc_QueryInterface,
2166 CustomDoc_AddRef,
2167 CustomDoc_Release,
2168 CustomDoc_SetUIHandler
2171 static const tid_t HTMLDocumentObj_iface_tids[] = {
2172 IHTMLDocument2_tid,
2173 IHTMLDocument3_tid,
2174 IHTMLDocument4_tid,
2175 IHTMLDocument5_tid,
2178 static dispex_static_data_t HTMLDocumentObj_dispex = {
2179 NULL,
2180 DispHTMLDocument_tid,
2181 NULL,
2182 HTMLDocumentObj_iface_tids
2185 HRESULT HTMLDocument_Create(IUnknown *pUnkOuter, REFIID riid, void** ppvObject)
2187 HTMLDocumentObj *doc;
2188 nsIDOMWindow *nswindow = NULL;
2189 nsresult nsres;
2190 HRESULT hres;
2192 TRACE("(%p %s %p)\n", pUnkOuter, debugstr_guid(riid), ppvObject);
2194 doc = heap_alloc_zero(sizeof(HTMLDocumentObj));
2195 if(!doc)
2196 return E_OUTOFMEMORY;
2198 init_dispex(&doc->dispex, (IUnknown*)CUSTOMDOC(doc), &HTMLDocumentObj_dispex);
2199 init_doc(&doc->basedoc, (IUnknown*)CUSTOMDOC(doc), DISPATCHEX(&doc->dispex));
2201 doc->lpCustomDocVtbl = &CustomDocVtbl;
2202 doc->ref = 1;
2203 doc->basedoc.doc_obj = doc;
2205 doc->usermode = UNKNOWN_USERMODE;
2207 doc->nscontainer = NSContainer_Create(doc, NULL);
2208 if(!doc->nscontainer) {
2209 ERR("Failed to init Gecko, returning CLASS_E_CLASSNOTAVAILABLE\n");
2210 htmldoc_release(&doc->basedoc);
2211 return CLASS_E_CLASSNOTAVAILABLE;
2214 hres = htmldoc_query_interface(&doc->basedoc, riid, ppvObject);
2215 htmldoc_release(&doc->basedoc);
2216 if(FAILED(hres))
2217 return hres;
2220 nsres = nsIWebBrowser_GetContentDOMWindow(doc->nscontainer->webbrowser, &nswindow);
2221 if(NS_FAILED(nsres))
2222 ERR("GetContentDOMWindow failed: %08x\n", nsres);
2224 hres = HTMLWindow_Create(doc, nswindow, NULL /* FIXME */, &doc->basedoc.window);
2225 if(nswindow)
2226 nsIDOMWindow_Release(nswindow);
2227 if(FAILED(hres)) {
2228 htmldoc_release(&doc->basedoc);
2229 return hres;
2232 if(!doc->basedoc.doc_node && doc->basedoc.window->doc) {
2233 doc->basedoc.doc_node = doc->basedoc.window->doc;
2234 htmldoc_addref(&doc->basedoc.doc_node->basedoc);
2237 get_thread_hwnd();
2239 return S_OK;