[MSHTML]
[reactos.git] / reactos / dll / win32 / mshtml / htmldoc.c
1 /*
2 * Copyright 2005-2009 Jacek Caban for CodeWeavers
3 *
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.
8 *
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.
13 *
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
17 */
18
19 #include "config.h"
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #define COBJMACROS
25
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"
33
34 #include "wine/debug.h"
35
36 #include "mshtml_private.h"
37 #include "htmlevent.h"
38
39 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
40
41 #define HTMLDOC_THIS(iface) DEFINE_THIS(HTMLDocument, HTMLDocument2, iface)
42
43 static HRESULT WINAPI HTMLDocument_QueryInterface(IHTMLDocument2 *iface, REFIID riid, void **ppv)
44 {
45 HTMLDocument *This = HTMLDOC_THIS(iface);
46
47 return htmldoc_query_interface(This, riid, ppv);
48 }
49
50 static ULONG WINAPI HTMLDocument_AddRef(IHTMLDocument2 *iface)
51 {
52 HTMLDocument *This = HTMLDOC_THIS(iface);
53
54 return htmldoc_addref(This);
55 }
56
57 static ULONG WINAPI HTMLDocument_Release(IHTMLDocument2 *iface)
58 {
59 HTMLDocument *This = HTMLDOC_THIS(iface);
60
61 return htmldoc_release(This);
62 }
63
64 static HRESULT WINAPI HTMLDocument_GetTypeInfoCount(IHTMLDocument2 *iface, UINT *pctinfo)
65 {
66 HTMLDocument *This = HTMLDOC_THIS(iface);
67
68 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(This), pctinfo);
69 }
70
71 static HRESULT WINAPI HTMLDocument_GetTypeInfo(IHTMLDocument2 *iface, UINT iTInfo,
72 LCID lcid, ITypeInfo **ppTInfo)
73 {
74 HTMLDocument *This = HTMLDOC_THIS(iface);
75
76 return IDispatchEx_GetTypeInfo(DISPATCHEX(This), iTInfo, lcid, ppTInfo);
77 }
78
79 static HRESULT WINAPI HTMLDocument_GetIDsOfNames(IHTMLDocument2 *iface, REFIID riid,
80 LPOLESTR *rgszNames, UINT cNames,
81 LCID lcid, DISPID *rgDispId)
82 {
83 HTMLDocument *This = HTMLDOC_THIS(iface);
84
85 return IDispatchEx_GetIDsOfNames(DISPATCHEX(This), riid, rgszNames, cNames, lcid, rgDispId);
86 }
87
88 static HRESULT WINAPI HTMLDocument_Invoke(IHTMLDocument2 *iface, DISPID dispIdMember,
89 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
90 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
91 {
92 HTMLDocument *This = HTMLDOC_THIS(iface);
93
94 return IDispatchEx_Invoke(DISPATCHEX(This), dispIdMember, riid, lcid, wFlags, pDispParams,
95 pVarResult, pExcepInfo, puArgErr);
96 }
97
98 static HRESULT WINAPI HTMLDocument_get_Script(IHTMLDocument2 *iface, IDispatch **p)
99 {
100 HTMLDocument *This = HTMLDOC_THIS(iface);
101
102 TRACE("(%p)->(%p)\n", This, p);
103
104 *p = (IDispatch*)HTMLWINDOW2(This->window);
105 IDispatch_AddRef(*p);
106 return S_OK;
107 }
108
109 static HRESULT WINAPI HTMLDocument_get_all(IHTMLDocument2 *iface, IHTMLElementCollection **p)
110 {
111 HTMLDocument *This = HTMLDOC_THIS(iface);
112 nsIDOMElement *nselem = NULL;
113 nsresult nsres;
114
115 TRACE("(%p)->(%p)\n", This, p);
116
117 if(!This->doc_node->nsdoc) {
118 WARN("NULL nsdoc\n");
119 return E_UNEXPECTED;
120 }
121
122 nsres = nsIDOMHTMLDocument_GetDocumentElement(This->doc_node->nsdoc, &nselem);
123 if(NS_FAILED(nsres)) {
124 ERR("GetDocumentElement failed: %08x\n", nsres);
125 return E_FAIL;
126 }
127
128 if(nselem) {
129 *p = create_all_collection(get_node(This->doc_node, (nsIDOMNode*)nselem, TRUE), TRUE);
130 nsIDOMElement_Release(nselem);
131 }else {
132 *p = NULL;
133 }
134
135 return S_OK;
136 }
137
138 static HRESULT WINAPI HTMLDocument_get_body(IHTMLDocument2 *iface, IHTMLElement **p)
139 {
140 HTMLDocument *This = HTMLDOC_THIS(iface);
141 nsIDOMHTMLElement *nsbody = NULL;
142 HTMLDOMNode *node;
143 nsresult nsres;
144
145 TRACE("(%p)->(%p)\n", This, p);
146
147 if(!This->doc_node->nsdoc) {
148 WARN("NULL nsdoc\n");
149 return E_UNEXPECTED;
150 }
151
152 nsres = nsIDOMHTMLDocument_GetBody(This->doc_node->nsdoc, &nsbody);
153 if(NS_FAILED(nsres)) {
154 TRACE("Could not get body: %08x\n", nsres);
155 return E_UNEXPECTED;
156 }
157
158 if(nsbody) {
159 node = get_node(This->doc_node, (nsIDOMNode*)nsbody, TRUE);
160 nsIDOMHTMLElement_Release(nsbody);
161
162 IHTMLDOMNode_QueryInterface(HTMLDOMNODE(node), &IID_IHTMLElement, (void**)p);
163 }else {
164 *p = NULL;
165 }
166
167 TRACE("*p = %p\n", *p);
168 return S_OK;
169 }
170
171 static HRESULT WINAPI HTMLDocument_get_activeElement(IHTMLDocument2 *iface, IHTMLElement **p)
172 {
173 HTMLDocument *This = HTMLDOC_THIS(iface);
174 FIXME("(%p)->(%p)\n", This, p);
175 return E_NOTIMPL;
176 }
177
178 static HRESULT WINAPI HTMLDocument_get_images(IHTMLDocument2 *iface, IHTMLElementCollection **p)
179 {
180 HTMLDocument *This = HTMLDOC_THIS(iface);
181 nsIDOMHTMLCollection *nscoll = NULL;
182 nsresult nsres;
183
184 TRACE("(%p)->(%p)\n", This, p);
185
186 if(!p)
187 return E_INVALIDARG;
188
189 *p = NULL;
190
191 if(!This->doc_node->nsdoc) {
192 WARN("NULL nsdoc\n");
193 return E_UNEXPECTED;
194 }
195
196 nsres = nsIDOMHTMLDocument_GetImages(This->doc_node->nsdoc, &nscoll);
197 if(NS_FAILED(nsres)) {
198 ERR("GetImages failed: %08x\n", nsres);
199 return E_FAIL;
200 }
201
202 if(nscoll) {
203 *p = create_collection_from_htmlcol(This->doc_node, (IUnknown*)HTMLDOC(This), nscoll);
204 nsIDOMElement_Release(nscoll);
205 }
206
207 return S_OK;
208 }
209
210 static HRESULT WINAPI HTMLDocument_get_applets(IHTMLDocument2 *iface, IHTMLElementCollection **p)
211 {
212 HTMLDocument *This = HTMLDOC_THIS(iface);
213 nsIDOMHTMLCollection *nscoll = NULL;
214 nsresult nsres;
215
216 TRACE("(%p)->(%p)\n", This, p);
217
218 if(!p)
219 return E_INVALIDARG;
220
221 *p = NULL;
222
223 if(!This->doc_node->nsdoc) {
224 WARN("NULL nsdoc\n");
225 return E_UNEXPECTED;
226 }
227
228 nsres = nsIDOMHTMLDocument_GetApplets(This->doc_node->nsdoc, &nscoll);
229 if(NS_FAILED(nsres)) {
230 ERR("GetApplets failed: %08x\n", nsres);
231 return E_FAIL;
232 }
233
234 if(nscoll) {
235 *p = create_collection_from_htmlcol(This->doc_node, (IUnknown*)HTMLDOC(This), nscoll);
236 nsIDOMElement_Release(nscoll);
237 }
238
239 return S_OK;
240 }
241
242 static HRESULT WINAPI HTMLDocument_get_links(IHTMLDocument2 *iface, IHTMLElementCollection **p)
243 {
244 HTMLDocument *This = HTMLDOC_THIS(iface);
245 nsIDOMHTMLCollection *nscoll = NULL;
246 nsresult nsres;
247
248 TRACE("(%p)->(%p)\n", This, p);
249
250 if(!p)
251 return E_INVALIDARG;
252
253 *p = NULL;
254
255 if(!This->doc_node->nsdoc) {
256 WARN("NULL nsdoc\n");
257 return E_UNEXPECTED;
258 }
259
260 nsres = nsIDOMHTMLDocument_GetLinks(This->doc_node->nsdoc, &nscoll);
261 if(NS_FAILED(nsres)) {
262 ERR("GetLinks failed: %08x\n", nsres);
263 return E_FAIL;
264 }
265
266 if(nscoll) {
267 *p = create_collection_from_htmlcol(This->doc_node, (IUnknown*)HTMLDOC(This), nscoll);
268 nsIDOMElement_Release(nscoll);
269 }
270
271 return S_OK;
272 }
273
274 static HRESULT WINAPI HTMLDocument_get_forms(IHTMLDocument2 *iface, IHTMLElementCollection **p)
275 {
276 HTMLDocument *This = HTMLDOC_THIS(iface);
277 nsIDOMHTMLCollection *nscoll = NULL;
278 nsresult nsres;
279
280 TRACE("(%p)->(%p)\n", This, p);
281
282 if(!p)
283 return E_INVALIDARG;
284
285 *p = NULL;
286
287 if(!This->doc_node->nsdoc) {
288 WARN("NULL nsdoc\n");
289 return E_UNEXPECTED;
290 }
291
292 nsres = nsIDOMHTMLDocument_GetForms(This->doc_node->nsdoc, &nscoll);
293 if(NS_FAILED(nsres)) {
294 ERR("GetForms failed: %08x\n", nsres);
295 return E_FAIL;
296 }
297
298 if(nscoll) {
299 *p = create_collection_from_htmlcol(This->doc_node, (IUnknown*)HTMLDOC(This), nscoll);
300 nsIDOMElement_Release(nscoll);
301 }
302
303 return S_OK;
304 }
305
306 static HRESULT WINAPI HTMLDocument_get_anchors(IHTMLDocument2 *iface, IHTMLElementCollection **p)
307 {
308 HTMLDocument *This = HTMLDOC_THIS(iface);
309 nsIDOMHTMLCollection *nscoll = NULL;
310 nsresult nsres;
311
312 TRACE("(%p)->(%p)\n", This, p);
313
314 if(!p)
315 return E_INVALIDARG;
316
317 *p = NULL;
318
319 if(!This->doc_node->nsdoc) {
320 WARN("NULL nsdoc\n");
321 return E_UNEXPECTED;
322 }
323
324 nsres = nsIDOMHTMLDocument_GetAnchors(This->doc_node->nsdoc, &nscoll);
325 if(NS_FAILED(nsres)) {
326 ERR("GetAnchors failed: %08x\n", nsres);
327 return E_FAIL;
328 }
329
330 if(nscoll) {
331 *p = create_collection_from_htmlcol(This->doc_node, (IUnknown*)HTMLDOC(This), nscoll);
332 nsIDOMElement_Release(nscoll);
333 }
334
335 return S_OK;
336 }
337
338 static HRESULT WINAPI HTMLDocument_put_title(IHTMLDocument2 *iface, BSTR v)
339 {
340 HTMLDocument *This = HTMLDOC_THIS(iface);
341 nsAString nsstr;
342 nsresult nsres;
343
344 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
345
346 if(!This->doc_node->nsdoc) {
347 WARN("NULL nsdoc\n");
348 return E_UNEXPECTED;
349 }
350
351 nsAString_InitDepend(&nsstr, v);
352 nsres = nsIDOMHTMLDocument_SetTitle(This->doc_node->nsdoc, &nsstr);
353 nsAString_Finish(&nsstr);
354 if(NS_FAILED(nsres))
355 ERR("SetTitle failed: %08x\n", nsres);
356
357 return S_OK;
358 }
359
360 static HRESULT WINAPI HTMLDocument_get_title(IHTMLDocument2 *iface, BSTR *p)
361 {
362 HTMLDocument *This = HTMLDOC_THIS(iface);
363 const PRUnichar *ret;
364 nsAString nsstr;
365 nsresult nsres;
366
367 TRACE("(%p)->(%p)\n", This, p);
368
369 if(!This->doc_node->nsdoc) {
370 WARN("NULL nsdoc\n");
371 return E_UNEXPECTED;
372 }
373
374
375 nsAString_Init(&nsstr, NULL);
376 nsres = nsIDOMHTMLDocument_GetTitle(This->doc_node->nsdoc, &nsstr);
377 if (NS_SUCCEEDED(nsres)) {
378 nsAString_GetData(&nsstr, &ret);
379 *p = SysAllocString(ret);
380 }
381 nsAString_Finish(&nsstr);
382
383 if(NS_FAILED(nsres)) {
384 ERR("GetTitle failed: %08x\n", nsres);
385 return E_FAIL;
386 }
387
388 return S_OK;
389 }
390
391 static HRESULT WINAPI HTMLDocument_get_scripts(IHTMLDocument2 *iface, IHTMLElementCollection **p)
392 {
393 HTMLDocument *This = HTMLDOC_THIS(iface);
394 FIXME("(%p)->(%p)\n", This, p);
395 return E_NOTIMPL;
396 }
397
398 static HRESULT WINAPI HTMLDocument_put_designMode(IHTMLDocument2 *iface, BSTR v)
399 {
400 HTMLDocument *This = HTMLDOC_THIS(iface);
401 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
402 return E_NOTIMPL;
403 }
404
405 static HRESULT WINAPI HTMLDocument_get_designMode(IHTMLDocument2 *iface, BSTR *p)
406 {
407 HTMLDocument *This = HTMLDOC_THIS(iface);
408 static WCHAR szOff[] = {'O','f','f',0};
409 FIXME("(%p)->(%p) always returning Off\n", This, p);
410
411 if(!p)
412 return E_INVALIDARG;
413
414 *p = SysAllocString(szOff);
415
416 return S_OK;
417 }
418
419 static HRESULT WINAPI HTMLDocument_get_selection(IHTMLDocument2 *iface, IHTMLSelectionObject **p)
420 {
421 HTMLDocument *This = HTMLDOC_THIS(iface);
422 nsISelection *nsselection;
423 nsresult nsres;
424
425 TRACE("(%p)->(%p)\n", This, p);
426
427 nsres = nsIDOMWindow_GetSelection(This->window->nswindow, &nsselection);
428 if(NS_FAILED(nsres)) {
429 ERR("GetSelection failed: %08x\n", nsres);
430 return E_FAIL;
431 }
432
433 return HTMLSelectionObject_Create(This->doc_node, nsselection, p);
434 }
435
436 static HRESULT WINAPI HTMLDocument_get_readyState(IHTMLDocument2 *iface, BSTR *p)
437 {
438 HTMLDocument *This = HTMLDOC_THIS(iface);
439
440 static const WCHAR wszUninitialized[] = {'u','n','i','n','i','t','i','a','l','i','z','e','d',0};
441 static const WCHAR wszLoading[] = {'l','o','a','d','i','n','g',0};
442 static const WCHAR wszLoaded[] = {'l','o','a','d','e','d',0};
443 static const WCHAR wszInteractive[] = {'i','n','t','e','r','a','c','t','i','v','e',0};
444 static const WCHAR wszComplete[] = {'c','o','m','p','l','e','t','e',0};
445
446 static const LPCWSTR readystate_str[] = {
447 wszUninitialized,
448 wszLoading,
449 wszLoaded,
450 wszInteractive,
451 wszComplete
452 };
453
454 TRACE("(%p)->(%p)\n", iface, p);
455
456 if(!p)
457 return E_POINTER;
458
459 *p = SysAllocString(readystate_str[This->window->readystate]);
460 return S_OK;
461 }
462
463 static HRESULT WINAPI HTMLDocument_get_frames(IHTMLDocument2 *iface, IHTMLFramesCollection2 **p)
464 {
465 HTMLDocument *This = HTMLDOC_THIS(iface);
466 FIXME("(%p)->(%p)\n", This, p);
467 return E_NOTIMPL;
468 }
469
470 static HRESULT WINAPI HTMLDocument_get_embeds(IHTMLDocument2 *iface, IHTMLElementCollection **p)
471 {
472 HTMLDocument *This = HTMLDOC_THIS(iface);
473 FIXME("(%p)->(%p)\n", This, p);
474 return E_NOTIMPL;
475 }
476
477 static HRESULT WINAPI HTMLDocument_get_plugins(IHTMLDocument2 *iface, IHTMLElementCollection **p)
478 {
479 HTMLDocument *This = HTMLDOC_THIS(iface);
480 FIXME("(%p)->(%p)\n", This, p);
481 return E_NOTIMPL;
482 }
483
484 static HRESULT WINAPI HTMLDocument_put_alinkColor(IHTMLDocument2 *iface, VARIANT v)
485 {
486 HTMLDocument *This = HTMLDOC_THIS(iface);
487 FIXME("(%p)\n", This);
488 return E_NOTIMPL;
489 }
490
491 static HRESULT WINAPI HTMLDocument_get_alinkColor(IHTMLDocument2 *iface, VARIANT *p)
492 {
493 HTMLDocument *This = HTMLDOC_THIS(iface);
494 FIXME("(%p)->(%p)\n", This, p);
495 return E_NOTIMPL;
496 }
497
498 static HRESULT WINAPI HTMLDocument_put_bgColor(IHTMLDocument2 *iface, VARIANT v)
499 {
500 HTMLDocument *This = HTMLDOC_THIS(iface);
501 FIXME("(%p)\n", This);
502 return E_NOTIMPL;
503 }
504
505 static HRESULT WINAPI HTMLDocument_get_bgColor(IHTMLDocument2 *iface, VARIANT *p)
506 {
507 HTMLDocument *This = HTMLDOC_THIS(iface);
508 FIXME("(%p)->(%p)\n", This, p);
509 return E_NOTIMPL;
510 }
511
512 static HRESULT WINAPI HTMLDocument_put_fgColor(IHTMLDocument2 *iface, VARIANT v)
513 {
514 HTMLDocument *This = HTMLDOC_THIS(iface);
515 FIXME("(%p)\n", This);
516 return E_NOTIMPL;
517 }
518
519 static HRESULT WINAPI HTMLDocument_get_fgColor(IHTMLDocument2 *iface, VARIANT *p)
520 {
521 HTMLDocument *This = HTMLDOC_THIS(iface);
522 FIXME("(%p)->(%p)\n", This, p);
523 return E_NOTIMPL;
524 }
525
526 static HRESULT WINAPI HTMLDocument_put_linkColor(IHTMLDocument2 *iface, VARIANT v)
527 {
528 HTMLDocument *This = HTMLDOC_THIS(iface);
529 FIXME("(%p)->()\n", This);
530 return E_NOTIMPL;
531 }
532
533 static HRESULT WINAPI HTMLDocument_get_linkColor(IHTMLDocument2 *iface, VARIANT *p)
534 {
535 HTMLDocument *This = HTMLDOC_THIS(iface);
536 FIXME("(%p)->(%p)\n", This, p);
537 return E_NOTIMPL;
538 }
539
540 static HRESULT WINAPI HTMLDocument_put_vlinkColor(IHTMLDocument2 *iface, VARIANT v)
541 {
542 HTMLDocument *This = HTMLDOC_THIS(iface);
543 FIXME("(%p)\n", This);
544 return E_NOTIMPL;
545 }
546
547 static HRESULT WINAPI HTMLDocument_get_vlinkColor(IHTMLDocument2 *iface, VARIANT *p)
548 {
549 HTMLDocument *This = HTMLDOC_THIS(iface);
550 FIXME("(%p)->(%p)\n", This, p);
551 return E_NOTIMPL;
552 }
553
554 static HRESULT WINAPI HTMLDocument_get_referrer(IHTMLDocument2 *iface, BSTR *p)
555 {
556 HTMLDocument *This = HTMLDOC_THIS(iface);
557
558 FIXME("(%p)->(%p)\n", This, p);
559
560 *p = NULL;
561 return S_OK;
562 }
563
564 static HRESULT WINAPI HTMLDocument_get_location(IHTMLDocument2 *iface, IHTMLLocation **p)
565 {
566 HTMLDocument *This = HTMLDOC_THIS(iface);
567
568 TRACE("(%p)->(%p)\n", This, p);
569
570 return IHTMLWindow2_get_location(HTMLWINDOW2(This->window), p);
571 }
572
573 static HRESULT WINAPI HTMLDocument_get_lastModified(IHTMLDocument2 *iface, BSTR *p)
574 {
575 HTMLDocument *This = HTMLDOC_THIS(iface);
576 FIXME("(%p)->(%p)\n", This, p);
577 return E_NOTIMPL;
578 }
579
580 static HRESULT WINAPI HTMLDocument_put_URL(IHTMLDocument2 *iface, BSTR v)
581 {
582 HTMLDocument *This = HTMLDOC_THIS(iface);
583 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
584 return E_NOTIMPL;
585 }
586
587 static HRESULT WINAPI HTMLDocument_get_URL(IHTMLDocument2 *iface, BSTR *p)
588 {
589 HTMLDocument *This = HTMLDOC_THIS(iface);
590
591 static const WCHAR about_blank_url[] =
592 {'a','b','o','u','t',':','b','l','a','n','k',0};
593
594 TRACE("(%p)->(%p)\n", iface, p);
595
596 *p = SysAllocString(This->window->url ? This->window->url : about_blank_url);
597 return *p ? S_OK : E_OUTOFMEMORY;
598 }
599
600 static HRESULT WINAPI HTMLDocument_put_domain(IHTMLDocument2 *iface, BSTR v)
601 {
602 HTMLDocument *This = HTMLDOC_THIS(iface);
603 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
604 return E_NOTIMPL;
605 }
606
607 static HRESULT WINAPI HTMLDocument_get_domain(IHTMLDocument2 *iface, BSTR *p)
608 {
609 HTMLDocument *This = HTMLDOC_THIS(iface);
610 FIXME("(%p)->(%p)\n", This, p);
611 return E_NOTIMPL;
612 }
613
614 static HRESULT WINAPI HTMLDocument_put_cookie(IHTMLDocument2 *iface, BSTR v)
615 {
616 HTMLDocument *This = HTMLDOC_THIS(iface);
617 BOOL bret;
618
619 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
620
621 bret = InternetSetCookieExW(This->window->url, NULL, v, 0, 0);
622 if(!bret) {
623 FIXME("InternetSetCookieExW failed: %u\n", GetLastError());
624 return HRESULT_FROM_WIN32(GetLastError());
625 }
626
627 return S_OK;
628 }
629
630 static HRESULT WINAPI HTMLDocument_get_cookie(IHTMLDocument2 *iface, BSTR *p)
631 {
632 HTMLDocument *This = HTMLDOC_THIS(iface);
633 DWORD size;
634 BOOL bret;
635
636 TRACE("(%p)->(%p)\n", This, p);
637
638 size = 0;
639 bret = InternetGetCookieExW(This->window->url, NULL, NULL, &size, 0, NULL);
640 if(!bret) {
641 switch(GetLastError()) {
642 case ERROR_INSUFFICIENT_BUFFER:
643 break;
644 case ERROR_NO_MORE_ITEMS:
645 *p = NULL;
646 return S_OK;
647 default:
648 FIXME("InternetGetCookieExW failed: %u\n", GetLastError());
649 return HRESULT_FROM_WIN32(GetLastError());
650 }
651 }
652
653 if(!size) {
654 *p = NULL;
655 return S_OK;
656 }
657
658 *p = SysAllocStringLen(NULL, size-1);
659 if(!*p)
660 return E_OUTOFMEMORY;
661
662 bret = InternetGetCookieExW(This->window->url, NULL, *p, &size, 0, NULL);
663 if(!bret) {
664 ERR("InternetGetCookieExW failed: %u\n", GetLastError());
665 return E_FAIL;
666 }
667
668 return S_OK;
669 }
670
671 static HRESULT WINAPI HTMLDocument_put_expando(IHTMLDocument2 *iface, VARIANT_BOOL v)
672 {
673 HTMLDocument *This = HTMLDOC_THIS(iface);
674 FIXME("(%p)->(%x)\n", This, v);
675 return E_NOTIMPL;
676 }
677
678 static HRESULT WINAPI HTMLDocument_get_expando(IHTMLDocument2 *iface, VARIANT_BOOL *p)
679 {
680 HTMLDocument *This = HTMLDOC_THIS(iface);
681 FIXME("(%p)->(%p)\n", This, p);
682 return E_NOTIMPL;
683 }
684
685 static HRESULT WINAPI HTMLDocument_put_charset(IHTMLDocument2 *iface, BSTR v)
686 {
687 HTMLDocument *This = HTMLDOC_THIS(iface);
688 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
689 return E_NOTIMPL;
690 }
691
692 static HRESULT WINAPI HTMLDocument_get_charset(IHTMLDocument2 *iface, BSTR *p)
693 {
694 HTMLDocument *This = HTMLDOC_THIS(iface);
695 FIXME("(%p)->(%p)\n", This, p);
696 return E_NOTIMPL;
697 }
698
699 static HRESULT WINAPI HTMLDocument_put_defaultCharset(IHTMLDocument2 *iface, BSTR v)
700 {
701 HTMLDocument *This = HTMLDOC_THIS(iface);
702 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
703 return E_NOTIMPL;
704 }
705
706 static HRESULT WINAPI HTMLDocument_get_defaultCharset(IHTMLDocument2 *iface, BSTR *p)
707 {
708 HTMLDocument *This = HTMLDOC_THIS(iface);
709 FIXME("(%p)->(%p)\n", This, p);
710 return E_NOTIMPL;
711 }
712
713 static HRESULT WINAPI HTMLDocument_get_mimeType(IHTMLDocument2 *iface, BSTR *p)
714 {
715 HTMLDocument *This = HTMLDOC_THIS(iface);
716 FIXME("(%p)->(%p)\n", This, p);
717 return E_NOTIMPL;
718 }
719
720 static HRESULT WINAPI HTMLDocument_get_fileSize(IHTMLDocument2 *iface, BSTR *p)
721 {
722 HTMLDocument *This = HTMLDOC_THIS(iface);
723 FIXME("(%p)->(%p)\n", This, p);
724 return E_NOTIMPL;
725 }
726
727 static HRESULT WINAPI HTMLDocument_get_fileCreatedDate(IHTMLDocument2 *iface, BSTR *p)
728 {
729 HTMLDocument *This = HTMLDOC_THIS(iface);
730 FIXME("(%p)->(%p)\n", This, p);
731 return E_NOTIMPL;
732 }
733
734 static HRESULT WINAPI HTMLDocument_get_fileModifiedDate(IHTMLDocument2 *iface, BSTR *p)
735 {
736 HTMLDocument *This = HTMLDOC_THIS(iface);
737 FIXME("(%p)->(%p)\n", This, p);
738 return E_NOTIMPL;
739 }
740
741 static HRESULT WINAPI HTMLDocument_get_fileUpdatedDate(IHTMLDocument2 *iface, BSTR *p)
742 {
743 HTMLDocument *This = HTMLDOC_THIS(iface);
744 FIXME("(%p)->(%p)\n", This, p);
745 return E_NOTIMPL;
746 }
747
748 static HRESULT WINAPI HTMLDocument_get_security(IHTMLDocument2 *iface, BSTR *p)
749 {
750 HTMLDocument *This = HTMLDOC_THIS(iface);
751 FIXME("(%p)->(%p)\n", This, p);
752 return E_NOTIMPL;
753 }
754
755 static HRESULT WINAPI HTMLDocument_get_protocol(IHTMLDocument2 *iface, BSTR *p)
756 {
757 HTMLDocument *This = HTMLDOC_THIS(iface);
758 FIXME("(%p)->(%p)\n", This, p);
759 return E_NOTIMPL;
760 }
761
762 static HRESULT WINAPI HTMLDocument_get_nameProp(IHTMLDocument2 *iface, BSTR *p)
763 {
764 HTMLDocument *This = HTMLDOC_THIS(iface);
765 FIXME("(%p)->(%p)\n", This, p);
766 return E_NOTIMPL;
767 }
768
769 static HRESULT document_write(HTMLDocument *This, SAFEARRAY *psarray, BOOL ln)
770 {
771 nsAString nsstr;
772 VARIANT *var;
773 ULONG i, argc;
774 nsresult nsres;
775 HRESULT hres;
776
777 if(!This->doc_node->nsdoc) {
778 WARN("NULL nsdoc\n");
779 return E_UNEXPECTED;
780 }
781
782 if (!psarray)
783 return S_OK;
784
785 if(psarray->cDims != 1) {
786 FIXME("cDims=%d\n", psarray->cDims);
787 return E_INVALIDARG;
788 }
789
790 hres = SafeArrayAccessData(psarray, (void**)&var);
791 if(FAILED(hres)) {
792 WARN("SafeArrayAccessData failed: %08x\n", hres);
793 return hres;
794 }
795
796 nsAString_Init(&nsstr, NULL);
797
798 argc = psarray->rgsabound[0].cElements;
799 for(i=0; i < argc; i++) {
800 if(V_VT(var+i) == VT_BSTR) {
801 nsAString_SetData(&nsstr, V_BSTR(var+i));
802 if(!ln || i != argc-1)
803 nsres = nsIDOMHTMLDocument_Write(This->doc_node->nsdoc, &nsstr);
804 else
805 nsres = nsIDOMHTMLDocument_Writeln(This->doc_node->nsdoc, &nsstr);
806 if(NS_FAILED(nsres))
807 ERR("Write failed: %08x\n", nsres);
808 }else {
809 FIXME("vt=%d\n", V_VT(var+i));
810 }
811 }
812
813 nsAString_Finish(&nsstr);
814 SafeArrayUnaccessData(psarray);
815
816 return S_OK;
817 }
818
819 static HRESULT WINAPI HTMLDocument_write(IHTMLDocument2 *iface, SAFEARRAY *psarray)
820 {
821 HTMLDocument *This = HTMLDOC_THIS(iface);
822
823 TRACE("(%p)->(%p)\n", iface, psarray);
824
825 return document_write(This, psarray, FALSE);
826 }
827
828 static HRESULT WINAPI HTMLDocument_writeln(IHTMLDocument2 *iface, SAFEARRAY *psarray)
829 {
830 HTMLDocument *This = HTMLDOC_THIS(iface);
831
832 TRACE("(%p)->(%p)\n", This, psarray);
833
834 return document_write(This, psarray, TRUE);
835 }
836
837 static HRESULT WINAPI HTMLDocument_open(IHTMLDocument2 *iface, BSTR url, VARIANT name,
838 VARIANT features, VARIANT replace, IDispatch **pomWindowResult)
839 {
840 HTMLDocument *This = HTMLDOC_THIS(iface);
841 nsresult nsres;
842
843 static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};
844
845 TRACE("(%p)->(%s %s %s %s %p)\n", This, debugstr_w(url), debugstr_variant(&name),
846 debugstr_variant(&features), debugstr_variant(&replace), pomWindowResult);
847
848 if(!This->doc_node->nsdoc) {
849 ERR("!nsdoc\n");
850 return E_NOTIMPL;
851 }
852
853 if(!url || strcmpW(url, text_htmlW) || V_VT(&name) != VT_ERROR
854 || V_VT(&features) != VT_ERROR || V_VT(&replace) != VT_ERROR)
855 FIXME("unsupported args\n");
856
857 nsres = nsIDOMHTMLDocument_Open(This->doc_node->nsdoc);
858 if(NS_FAILED(nsres)) {
859 ERR("Open failed: %08x\n", nsres);
860 return E_FAIL;
861 }
862
863 *pomWindowResult = (IDispatch*)HTMLWINDOW2(This->window);
864 IHTMLWindow2_AddRef(HTMLWINDOW2(This->window));
865 return S_OK;
866 }
867
868 static HRESULT WINAPI HTMLDocument_close(IHTMLDocument2 *iface)
869 {
870 HTMLDocument *This = HTMLDOC_THIS(iface);
871 nsresult nsres;
872
873 TRACE("(%p)\n", This);
874
875 if(!This->doc_node->nsdoc) {
876 ERR("!nsdoc\n");
877 return E_NOTIMPL;
878 }
879
880 nsres = nsIDOMHTMLDocument_Close(This->doc_node->nsdoc);
881 if(NS_FAILED(nsres)) {
882 ERR("Close failed: %08x\n", nsres);
883 return E_FAIL;
884 }
885
886 return S_OK;
887 }
888
889 static HRESULT WINAPI HTMLDocument_clear(IHTMLDocument2 *iface)
890 {
891 HTMLDocument *This = HTMLDOC_THIS(iface);
892 FIXME("(%p)\n", This);
893 return E_NOTIMPL;
894 }
895
896 static HRESULT WINAPI HTMLDocument_queryCommandSupported(IHTMLDocument2 *iface, BSTR cmdID,
897 VARIANT_BOOL *pfRet)
898 {
899 HTMLDocument *This = HTMLDOC_THIS(iface);
900 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
901 return E_NOTIMPL;
902 }
903
904 static HRESULT WINAPI HTMLDocument_queryCommandEnabled(IHTMLDocument2 *iface, BSTR cmdID,
905 VARIANT_BOOL *pfRet)
906 {
907 HTMLDocument *This = HTMLDOC_THIS(iface);
908 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
909 return E_NOTIMPL;
910 }
911
912 static HRESULT WINAPI HTMLDocument_queryCommandState(IHTMLDocument2 *iface, BSTR cmdID,
913 VARIANT_BOOL *pfRet)
914 {
915 HTMLDocument *This = HTMLDOC_THIS(iface);
916 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
917 return E_NOTIMPL;
918 }
919
920 static HRESULT WINAPI HTMLDocument_queryCommandIndeterm(IHTMLDocument2 *iface, BSTR cmdID,
921 VARIANT_BOOL *pfRet)
922 {
923 HTMLDocument *This = HTMLDOC_THIS(iface);
924 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
925 return E_NOTIMPL;
926 }
927
928 static HRESULT WINAPI HTMLDocument_queryCommandText(IHTMLDocument2 *iface, BSTR cmdID,
929 BSTR *pfRet)
930 {
931 HTMLDocument *This = HTMLDOC_THIS(iface);
932 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
933 return E_NOTIMPL;
934 }
935
936 static HRESULT WINAPI HTMLDocument_queryCommandValue(IHTMLDocument2 *iface, BSTR cmdID,
937 VARIANT *pfRet)
938 {
939 HTMLDocument *This = HTMLDOC_THIS(iface);
940 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
941 return E_NOTIMPL;
942 }
943
944 static HRESULT WINAPI HTMLDocument_execCommand(IHTMLDocument2 *iface, BSTR cmdID,
945 VARIANT_BOOL showUI, VARIANT value, VARIANT_BOOL *pfRet)
946 {
947 HTMLDocument *This = HTMLDOC_THIS(iface);
948 FIXME("(%p)->(%s %x %p)\n", This, debugstr_w(cmdID), showUI, pfRet);
949 return E_NOTIMPL;
950 }
951
952 static HRESULT WINAPI HTMLDocument_execCommandShowHelp(IHTMLDocument2 *iface, BSTR cmdID,
953 VARIANT_BOOL *pfRet)
954 {
955 HTMLDocument *This = HTMLDOC_THIS(iface);
956 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
957 return E_NOTIMPL;
958 }
959
960 static HRESULT WINAPI HTMLDocument_createElement(IHTMLDocument2 *iface, BSTR eTag,
961 IHTMLElement **newElem)
962 {
963 HTMLDocument *This = HTMLDOC_THIS(iface);
964 nsIDOMHTMLElement *nselem;
965 HTMLElement *elem;
966 HRESULT hres;
967
968 TRACE("(%p)->(%s %p)\n", This, debugstr_w(eTag), newElem);
969
970 hres = create_nselem(This->doc_node, eTag, &nselem);
971 if(FAILED(hres))
972 return hres;
973
974 elem = HTMLElement_Create(This->doc_node, (nsIDOMNode*)nselem, TRUE);
975 nsIDOMHTMLElement_Release(nselem);
976
977 *newElem = HTMLELEM(elem);
978 IHTMLElement_AddRef(HTMLELEM(elem));
979 return S_OK;
980 }
981
982 static HRESULT WINAPI HTMLDocument_put_onhelp(IHTMLDocument2 *iface, VARIANT v)
983 {
984 HTMLDocument *This = HTMLDOC_THIS(iface);
985 FIXME("(%p)\n", This);
986 return E_NOTIMPL;
987 }
988
989 static HRESULT WINAPI HTMLDocument_get_onhelp(IHTMLDocument2 *iface, VARIANT *p)
990 {
991 HTMLDocument *This = HTMLDOC_THIS(iface);
992 FIXME("(%p)->(%p)\n", This, p);
993 return E_NOTIMPL;
994 }
995
996 static HRESULT WINAPI HTMLDocument_put_onclick(IHTMLDocument2 *iface, VARIANT v)
997 {
998 HTMLDocument *This = HTMLDOC_THIS(iface);
999
1000 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1001
1002 return set_doc_event(This, EVENTID_CLICK, &v);
1003 }
1004
1005 static HRESULT WINAPI HTMLDocument_get_onclick(IHTMLDocument2 *iface, VARIANT *p)
1006 {
1007 HTMLDocument *This = HTMLDOC_THIS(iface);
1008
1009 TRACE("(%p)->(%p)\n", This, p);
1010
1011 return get_doc_event(This, EVENTID_CLICK, p);
1012 }
1013
1014 static HRESULT WINAPI HTMLDocument_put_ondblclick(IHTMLDocument2 *iface, VARIANT v)
1015 {
1016 HTMLDocument *This = HTMLDOC_THIS(iface);
1017 FIXME("(%p)\n", This);
1018 return E_NOTIMPL;
1019 }
1020
1021 static HRESULT WINAPI HTMLDocument_get_ondblclick(IHTMLDocument2 *iface, VARIANT *p)
1022 {
1023 HTMLDocument *This = HTMLDOC_THIS(iface);
1024 FIXME("(%p)->(%p)\n", This, p);
1025 return E_NOTIMPL;
1026 }
1027
1028 static HRESULT WINAPI HTMLDocument_put_onkeyup(IHTMLDocument2 *iface, VARIANT v)
1029 {
1030 HTMLDocument *This = HTMLDOC_THIS(iface);
1031
1032 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1033
1034 return set_doc_event(This, EVENTID_KEYUP, &v);
1035 }
1036
1037 static HRESULT WINAPI HTMLDocument_get_onkeyup(IHTMLDocument2 *iface, VARIANT *p)
1038 {
1039 HTMLDocument *This = HTMLDOC_THIS(iface);
1040
1041 TRACE("(%p)->(%p)\n", This, p);
1042
1043 return get_doc_event(This, EVENTID_KEYUP, p);
1044 }
1045
1046 static HRESULT WINAPI HTMLDocument_put_onkeydown(IHTMLDocument2 *iface, VARIANT v)
1047 {
1048 HTMLDocument *This = HTMLDOC_THIS(iface);
1049
1050 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1051
1052 return set_doc_event(This, EVENTID_KEYDOWN, &v);
1053 }
1054
1055 static HRESULT WINAPI HTMLDocument_get_onkeydown(IHTMLDocument2 *iface, VARIANT *p)
1056 {
1057 HTMLDocument *This = HTMLDOC_THIS(iface);
1058
1059 TRACE("(%p)->(%p)\n", This, p);
1060
1061 return get_doc_event(This, EVENTID_KEYDOWN, p);
1062 }
1063
1064 static HRESULT WINAPI HTMLDocument_put_onkeypress(IHTMLDocument2 *iface, VARIANT v)
1065 {
1066 HTMLDocument *This = HTMLDOC_THIS(iface);
1067 FIXME("(%p)\n", This);
1068 return E_NOTIMPL;
1069 }
1070
1071 static HRESULT WINAPI HTMLDocument_get_onkeypress(IHTMLDocument2 *iface, VARIANT *p)
1072 {
1073 HTMLDocument *This = HTMLDOC_THIS(iface);
1074 FIXME("(%p)->(%p)\n", This, p);
1075 return E_NOTIMPL;
1076 }
1077
1078 static HRESULT WINAPI HTMLDocument_put_onmouseup(IHTMLDocument2 *iface, VARIANT v)
1079 {
1080 HTMLDocument *This = HTMLDOC_THIS(iface);
1081
1082 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1083
1084 return set_doc_event(This, EVENTID_MOUSEUP, &v);
1085 }
1086
1087 static HRESULT WINAPI HTMLDocument_get_onmouseup(IHTMLDocument2 *iface, VARIANT *p)
1088 {
1089 HTMLDocument *This = HTMLDOC_THIS(iface);
1090
1091 TRACE("(%p)->(%p)\n", This, p);
1092
1093 return get_doc_event(This, EVENTID_MOUSEUP, p);
1094 }
1095
1096 static HRESULT WINAPI HTMLDocument_put_onmousedown(IHTMLDocument2 *iface, VARIANT v)
1097 {
1098 HTMLDocument *This = HTMLDOC_THIS(iface);
1099
1100 TRACE("(%p)->()\n", This);
1101
1102 return set_doc_event(This, EVENTID_MOUSEDOWN, &v);
1103 }
1104
1105 static HRESULT WINAPI HTMLDocument_get_onmousedown(IHTMLDocument2 *iface, VARIANT *p)
1106 {
1107 HTMLDocument *This = HTMLDOC_THIS(iface);
1108
1109 TRACE("(%p)->(%p)\n", This, p);
1110
1111 return get_doc_event(This, EVENTID_MOUSEDOWN, p);
1112 }
1113
1114 static HRESULT WINAPI HTMLDocument_put_onmousemove(IHTMLDocument2 *iface, VARIANT v)
1115 {
1116 HTMLDocument *This = HTMLDOC_THIS(iface);
1117 FIXME("(%p)\n", This);
1118 return E_NOTIMPL;
1119 }
1120
1121 static HRESULT WINAPI HTMLDocument_get_onmousemove(IHTMLDocument2 *iface, VARIANT *p)
1122 {
1123 HTMLDocument *This = HTMLDOC_THIS(iface);
1124 FIXME("(%p)->(%p)\n", This, p);
1125 return E_NOTIMPL;
1126 }
1127
1128 static HRESULT WINAPI HTMLDocument_put_onmouseout(IHTMLDocument2 *iface, VARIANT v)
1129 {
1130 HTMLDocument *This = HTMLDOC_THIS(iface);
1131
1132 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1133
1134 return set_doc_event(This, EVENTID_MOUSEOUT, &v);
1135 }
1136
1137 static HRESULT WINAPI HTMLDocument_get_onmouseout(IHTMLDocument2 *iface, VARIANT *p)
1138 {
1139 HTMLDocument *This = HTMLDOC_THIS(iface);
1140
1141 TRACE("(%p)->(%p)\n", This, p);
1142
1143 return get_doc_event(This, EVENTID_MOUSEOUT, p);
1144 }
1145
1146 static HRESULT WINAPI HTMLDocument_put_onmouseover(IHTMLDocument2 *iface, VARIANT v)
1147 {
1148 HTMLDocument *This = HTMLDOC_THIS(iface);
1149
1150 TRACE("(%p)\n", This);
1151
1152 return set_doc_event(This, EVENTID_MOUSEOVER, &v);
1153 }
1154
1155 static HRESULT WINAPI HTMLDocument_get_onmouseover(IHTMLDocument2 *iface, VARIANT *p)
1156 {
1157 HTMLDocument *This = HTMLDOC_THIS(iface);
1158
1159 TRACE("(%p)->(%p)\n", This, p);
1160
1161 return get_doc_event(This, EVENTID_MOUSEOVER, p);
1162 }
1163
1164 static HRESULT WINAPI HTMLDocument_put_onreadystatechange(IHTMLDocument2 *iface, VARIANT v)
1165 {
1166 HTMLDocument *This = HTMLDOC_THIS(iface);
1167
1168 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1169
1170 return set_doc_event(This, EVENTID_READYSTATECHANGE, &v);
1171 }
1172
1173 static HRESULT WINAPI HTMLDocument_get_onreadystatechange(IHTMLDocument2 *iface, VARIANT *p)
1174 {
1175 HTMLDocument *This = HTMLDOC_THIS(iface);
1176
1177 TRACE("(%p)->(%p)\n", This, p);
1178
1179 return get_doc_event(This, EVENTID_READYSTATECHANGE, p);
1180 }
1181
1182 static HRESULT WINAPI HTMLDocument_put_onafterupdate(IHTMLDocument2 *iface, VARIANT v)
1183 {
1184 HTMLDocument *This = HTMLDOC_THIS(iface);
1185 FIXME("(%p)\n", This);
1186 return E_NOTIMPL;
1187 }
1188
1189 static HRESULT WINAPI HTMLDocument_get_onafterupdate(IHTMLDocument2 *iface, VARIANT *p)
1190 {
1191 HTMLDocument *This = HTMLDOC_THIS(iface);
1192 FIXME("(%p)->(%p)\n", This, p);
1193 return E_NOTIMPL;
1194 }
1195
1196 static HRESULT WINAPI HTMLDocument_put_onrowexit(IHTMLDocument2 *iface, VARIANT v)
1197 {
1198 HTMLDocument *This = HTMLDOC_THIS(iface);
1199 FIXME("(%p)\n", This);
1200 return E_NOTIMPL;
1201 }
1202
1203 static HRESULT WINAPI HTMLDocument_get_onrowexit(IHTMLDocument2 *iface, VARIANT *p)
1204 {
1205 HTMLDocument *This = HTMLDOC_THIS(iface);
1206 FIXME("(%p)->(%p)\n", This, p);
1207 return E_NOTIMPL;
1208 }
1209
1210 static HRESULT WINAPI HTMLDocument_put_onrowenter(IHTMLDocument2 *iface, VARIANT v)
1211 {
1212 HTMLDocument *This = HTMLDOC_THIS(iface);
1213 FIXME("(%p)\n", This);
1214 return E_NOTIMPL;
1215 }
1216
1217 static HRESULT WINAPI HTMLDocument_get_onrowenter(IHTMLDocument2 *iface, VARIANT *p)
1218 {
1219 HTMLDocument *This = HTMLDOC_THIS(iface);
1220 FIXME("(%p)->(%p)\n", This, p);
1221 return E_NOTIMPL;
1222 }
1223
1224 static HRESULT WINAPI HTMLDocument_put_ondragstart(IHTMLDocument2 *iface, VARIANT v)
1225 {
1226 HTMLDocument *This = HTMLDOC_THIS(iface);
1227
1228 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1229
1230 return set_doc_event(This, EVENTID_DRAGSTART, &v);
1231 }
1232
1233 static HRESULT WINAPI HTMLDocument_get_ondragstart(IHTMLDocument2 *iface, VARIANT *p)
1234 {
1235 HTMLDocument *This = HTMLDOC_THIS(iface);
1236
1237 TRACE("(%p)->(%p)\n", This, p);
1238
1239 return get_doc_event(This, EVENTID_DRAGSTART, p);
1240 }
1241
1242 static HRESULT WINAPI HTMLDocument_put_onselectstart(IHTMLDocument2 *iface, VARIANT v)
1243 {
1244 HTMLDocument *This = HTMLDOC_THIS(iface);
1245
1246 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1247
1248 return set_doc_event(This, EVENTID_SELECTSTART, &v);
1249 }
1250
1251 static HRESULT WINAPI HTMLDocument_get_onselectstart(IHTMLDocument2 *iface, VARIANT *p)
1252 {
1253 HTMLDocument *This = HTMLDOC_THIS(iface);
1254
1255 TRACE("(%p)->(%p)\n", This, p);
1256
1257 return get_doc_event(This, EVENTID_SELECTSTART, p);
1258 }
1259
1260 static HRESULT WINAPI HTMLDocument_elementFromPoint(IHTMLDocument2 *iface, LONG x, LONG y,
1261 IHTMLElement **elementHit)
1262 {
1263 HTMLDocument *This = HTMLDOC_THIS(iface);
1264 FIXME("(%p)->(%d %d %p)\n", This, x, y, elementHit);
1265 return E_NOTIMPL;
1266 }
1267
1268 static HRESULT WINAPI HTMLDocument_get_parentWindow(IHTMLDocument2 *iface, IHTMLWindow2 **p)
1269 {
1270 HTMLDocument *This = HTMLDOC_THIS(iface);
1271
1272 TRACE("(%p)->(%p)\n", This, p);
1273
1274 *p = HTMLWINDOW2(This->window);
1275 IHTMLWindow2_AddRef(*p);
1276 return S_OK;
1277 }
1278
1279 static HRESULT WINAPI HTMLDocument_get_styleSheets(IHTMLDocument2 *iface,
1280 IHTMLStyleSheetsCollection **p)
1281 {
1282 HTMLDocument *This = HTMLDOC_THIS(iface);
1283 nsIDOMStyleSheetList *nsstylelist;
1284 nsIDOMDocumentStyle *nsdocstyle;
1285 nsresult nsres;
1286
1287 TRACE("(%p)->(%p)\n", This, p);
1288
1289 *p = NULL;
1290
1291 if(!This->doc_node->nsdoc) {
1292 WARN("NULL nsdoc\n");
1293 return E_UNEXPECTED;
1294 }
1295
1296 nsIDOMHTMLDocument_QueryInterface(This->doc_node->nsdoc, &IID_nsIDOMDocumentStyle, (void**)&nsdocstyle);
1297 nsres = nsIDOMDocumentStyle_GetStyleSheets(nsdocstyle, &nsstylelist);
1298 nsIDOMDocumentStyle_Release(nsdocstyle);
1299 if(NS_FAILED(nsres)) {
1300 ERR("GetStyleSheets failed: %08x\n", nsres);
1301 return E_FAIL;
1302 }
1303
1304 *p = HTMLStyleSheetsCollection_Create(nsstylelist);
1305 nsIDOMDocumentStyle_Release(nsstylelist);
1306
1307 return S_OK;
1308 }
1309
1310 static HRESULT WINAPI HTMLDocument_put_onbeforeupdate(IHTMLDocument2 *iface, VARIANT v)
1311 {
1312 HTMLDocument *This = HTMLDOC_THIS(iface);
1313 FIXME("(%p)\n", This);
1314 return E_NOTIMPL;
1315 }
1316
1317 static HRESULT WINAPI HTMLDocument_get_onbeforeupdate(IHTMLDocument2 *iface, VARIANT *p)
1318 {
1319 HTMLDocument *This = HTMLDOC_THIS(iface);
1320 FIXME("(%p)->(%p)\n", This, p);
1321 return E_NOTIMPL;
1322 }
1323
1324 static HRESULT WINAPI HTMLDocument_put_onerrorupdate(IHTMLDocument2 *iface, VARIANT v)
1325 {
1326 HTMLDocument *This = HTMLDOC_THIS(iface);
1327 FIXME("(%p)\n", This);
1328 return E_NOTIMPL;
1329 }
1330
1331 static HRESULT WINAPI HTMLDocument_get_onerrorupdate(IHTMLDocument2 *iface, VARIANT *p)
1332 {
1333 HTMLDocument *This = HTMLDOC_THIS(iface);
1334 FIXME("(%p)->(%p)\n", This, p);
1335 return E_NOTIMPL;
1336 }
1337
1338 static HRESULT WINAPI HTMLDocument_toString(IHTMLDocument2 *iface, BSTR *String)
1339 {
1340 HTMLDocument *This = HTMLDOC_THIS(iface);
1341 FIXME("(%p)->(%p)\n", This, String);
1342 return E_NOTIMPL;
1343 }
1344
1345 static HRESULT WINAPI HTMLDocument_createStyleSheet(IHTMLDocument2 *iface, BSTR bstrHref,
1346 LONG lIndex, IHTMLStyleSheet **ppnewStyleSheet)
1347 {
1348 HTMLDocument *This = HTMLDOC_THIS(iface);
1349
1350 FIXME("(%p)->(%s %d %p) semi-stub\n", This, debugstr_w(bstrHref), lIndex, ppnewStyleSheet);
1351
1352 *ppnewStyleSheet = HTMLStyleSheet_Create(NULL);
1353 return S_OK;
1354 }
1355
1356 static const IHTMLDocument2Vtbl HTMLDocumentVtbl = {
1357 HTMLDocument_QueryInterface,
1358 HTMLDocument_AddRef,
1359 HTMLDocument_Release,
1360 HTMLDocument_GetTypeInfoCount,
1361 HTMLDocument_GetTypeInfo,
1362 HTMLDocument_GetIDsOfNames,
1363 HTMLDocument_Invoke,
1364 HTMLDocument_get_Script,
1365 HTMLDocument_get_all,
1366 HTMLDocument_get_body,
1367 HTMLDocument_get_activeElement,
1368 HTMLDocument_get_images,
1369 HTMLDocument_get_applets,
1370 HTMLDocument_get_links,
1371 HTMLDocument_get_forms,
1372 HTMLDocument_get_anchors,
1373 HTMLDocument_put_title,
1374 HTMLDocument_get_title,
1375 HTMLDocument_get_scripts,
1376 HTMLDocument_put_designMode,
1377 HTMLDocument_get_designMode,
1378 HTMLDocument_get_selection,
1379 HTMLDocument_get_readyState,
1380 HTMLDocument_get_frames,
1381 HTMLDocument_get_embeds,
1382 HTMLDocument_get_plugins,
1383 HTMLDocument_put_alinkColor,
1384 HTMLDocument_get_alinkColor,
1385 HTMLDocument_put_bgColor,
1386 HTMLDocument_get_bgColor,
1387 HTMLDocument_put_fgColor,
1388 HTMLDocument_get_fgColor,
1389 HTMLDocument_put_linkColor,
1390 HTMLDocument_get_linkColor,
1391 HTMLDocument_put_vlinkColor,
1392 HTMLDocument_get_vlinkColor,
1393 HTMLDocument_get_referrer,
1394 HTMLDocument_get_location,
1395 HTMLDocument_get_lastModified,
1396 HTMLDocument_put_URL,
1397 HTMLDocument_get_URL,
1398 HTMLDocument_put_domain,
1399 HTMLDocument_get_domain,
1400 HTMLDocument_put_cookie,
1401 HTMLDocument_get_cookie,
1402 HTMLDocument_put_expando,
1403 HTMLDocument_get_expando,
1404 HTMLDocument_put_charset,
1405 HTMLDocument_get_charset,
1406 HTMLDocument_put_defaultCharset,
1407 HTMLDocument_get_defaultCharset,
1408 HTMLDocument_get_mimeType,
1409 HTMLDocument_get_fileSize,
1410 HTMLDocument_get_fileCreatedDate,
1411 HTMLDocument_get_fileModifiedDate,
1412 HTMLDocument_get_fileUpdatedDate,
1413 HTMLDocument_get_security,
1414 HTMLDocument_get_protocol,
1415 HTMLDocument_get_nameProp,
1416 HTMLDocument_write,
1417 HTMLDocument_writeln,
1418 HTMLDocument_open,
1419 HTMLDocument_close,
1420 HTMLDocument_clear,
1421 HTMLDocument_queryCommandSupported,
1422 HTMLDocument_queryCommandEnabled,
1423 HTMLDocument_queryCommandState,
1424 HTMLDocument_queryCommandIndeterm,
1425 HTMLDocument_queryCommandText,
1426 HTMLDocument_queryCommandValue,
1427 HTMLDocument_execCommand,
1428 HTMLDocument_execCommandShowHelp,
1429 HTMLDocument_createElement,
1430 HTMLDocument_put_onhelp,
1431 HTMLDocument_get_onhelp,
1432 HTMLDocument_put_onclick,
1433 HTMLDocument_get_onclick,
1434 HTMLDocument_put_ondblclick,
1435 HTMLDocument_get_ondblclick,
1436 HTMLDocument_put_onkeyup,
1437 HTMLDocument_get_onkeyup,
1438 HTMLDocument_put_onkeydown,
1439 HTMLDocument_get_onkeydown,
1440 HTMLDocument_put_onkeypress,
1441 HTMLDocument_get_onkeypress,
1442 HTMLDocument_put_onmouseup,
1443 HTMLDocument_get_onmouseup,
1444 HTMLDocument_put_onmousedown,
1445 HTMLDocument_get_onmousedown,
1446 HTMLDocument_put_onmousemove,
1447 HTMLDocument_get_onmousemove,
1448 HTMLDocument_put_onmouseout,
1449 HTMLDocument_get_onmouseout,
1450 HTMLDocument_put_onmouseover,
1451 HTMLDocument_get_onmouseover,
1452 HTMLDocument_put_onreadystatechange,
1453 HTMLDocument_get_onreadystatechange,
1454 HTMLDocument_put_onafterupdate,
1455 HTMLDocument_get_onafterupdate,
1456 HTMLDocument_put_onrowexit,
1457 HTMLDocument_get_onrowexit,
1458 HTMLDocument_put_onrowenter,
1459 HTMLDocument_get_onrowenter,
1460 HTMLDocument_put_ondragstart,
1461 HTMLDocument_get_ondragstart,
1462 HTMLDocument_put_onselectstart,
1463 HTMLDocument_get_onselectstart,
1464 HTMLDocument_elementFromPoint,
1465 HTMLDocument_get_parentWindow,
1466 HTMLDocument_get_styleSheets,
1467 HTMLDocument_put_onbeforeupdate,
1468 HTMLDocument_get_onbeforeupdate,
1469 HTMLDocument_put_onerrorupdate,
1470 HTMLDocument_get_onerrorupdate,
1471 HTMLDocument_toString,
1472 HTMLDocument_createStyleSheet
1473 };
1474
1475 static void HTMLDocument_on_advise(IUnknown *iface, cp_static_data_t *cp)
1476 {
1477 HTMLDocument *This = HTMLDOC_THIS(iface);
1478
1479 if(This->window)
1480 update_cp_events(This->window, &This->doc_node->node.event_target, cp, This->doc_node->node.nsnode);
1481 }
1482
1483 #undef HTMLDOC_THIS
1484
1485 #define SUPPINFO_THIS(iface) DEFINE_THIS(HTMLDocument, SupportErrorInfo, iface)
1486
1487 static HRESULT WINAPI SupportErrorInfo_QueryInterface(ISupportErrorInfo *iface, REFIID riid, void **ppv)
1488 {
1489 HTMLDocument *This = SUPPINFO_THIS(iface);
1490 return IHTMLDocument_QueryInterface(HTMLDOC(This), riid, ppv);
1491 }
1492
1493 static ULONG WINAPI SupportErrorInfo_AddRef(ISupportErrorInfo *iface)
1494 {
1495 HTMLDocument *This = SUPPINFO_THIS(iface);
1496 return IHTMLDocument_AddRef(HTMLDOC(This));
1497 }
1498
1499 static ULONG WINAPI SupportErrorInfo_Release(ISupportErrorInfo *iface)
1500 {
1501 HTMLDocument *This = SUPPINFO_THIS(iface);
1502 return IHTMLDocument_Release(HTMLDOC(This));
1503 }
1504
1505 static HRESULT WINAPI SupportErrorInfo_InterfaceSupportsErrorInfo(ISupportErrorInfo *iface, REFIID riid)
1506 {
1507 FIXME("(%p)->(%s)\n", iface, debugstr_guid(riid));
1508 return S_FALSE;
1509 }
1510
1511 static const ISupportErrorInfoVtbl SupportErrorInfoVtbl = {
1512 SupportErrorInfo_QueryInterface,
1513 SupportErrorInfo_AddRef,
1514 SupportErrorInfo_Release,
1515 SupportErrorInfo_InterfaceSupportsErrorInfo
1516 };
1517
1518 #define DISPEX_THIS(iface) DEFINE_THIS(HTMLDocument, IDispatchEx, iface)
1519
1520 static HRESULT WINAPI DocDispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
1521 {
1522 HTMLDocument *This = DISPEX_THIS(iface);
1523
1524 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppv);
1525 }
1526
1527 static ULONG WINAPI DocDispatchEx_AddRef(IDispatchEx *iface)
1528 {
1529 HTMLDocument *This = DISPEX_THIS(iface);
1530
1531 return IHTMLDocument2_AddRef(HTMLDOC(This));
1532 }
1533
1534 static ULONG WINAPI DocDispatchEx_Release(IDispatchEx *iface)
1535 {
1536 HTMLDocument *This = DISPEX_THIS(iface);
1537
1538 return IHTMLDocument2_Release(HTMLDOC(This));
1539 }
1540
1541 static HRESULT WINAPI DocDispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
1542 {
1543 HTMLDocument *This = DISPEX_THIS(iface);
1544
1545 return IDispatchEx_GetTypeInfoCount(This->dispex, pctinfo);
1546 }
1547
1548 static HRESULT WINAPI DocDispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
1549 LCID lcid, ITypeInfo **ppTInfo)
1550 {
1551 HTMLDocument *This = DISPEX_THIS(iface);
1552
1553 return IDispatchEx_GetTypeInfo(This->dispex, iTInfo, lcid, ppTInfo);
1554 }
1555
1556 static HRESULT WINAPI DocDispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
1557 LPOLESTR *rgszNames, UINT cNames,
1558 LCID lcid, DISPID *rgDispId)
1559 {
1560 HTMLDocument *This = DISPEX_THIS(iface);
1561
1562 return IDispatchEx_GetIDsOfNames(This->dispex, riid, rgszNames, cNames, lcid, rgDispId);
1563 }
1564
1565 static HRESULT WINAPI DocDispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
1566 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1567 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1568 {
1569 HTMLDocument *This = DISPEX_THIS(iface);
1570
1571 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1572 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1573
1574 switch(dispIdMember) {
1575 case DISPID_READYSTATE:
1576 TRACE("DISPID_READYSTATE\n");
1577
1578 if(!(wFlags & DISPATCH_PROPERTYGET))
1579 return E_INVALIDARG;
1580
1581 V_VT(pVarResult) = VT_I4;
1582 V_I4(pVarResult) = This->window->readystate;
1583 return S_OK;
1584 }
1585
1586 return IDispatchEx_Invoke(This->dispex, dispIdMember, riid, lcid, wFlags, pDispParams,
1587 pVarResult, pExcepInfo, puArgErr);
1588 }
1589
1590 static HRESULT WINAPI DocDispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
1591 {
1592 HTMLDocument *This = DISPEX_THIS(iface);
1593
1594 return IDispatchEx_GetDispID(This->dispex, bstrName, grfdex, pid);
1595 }
1596
1597 static HRESULT WINAPI DocDispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1598 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1599 {
1600 HTMLDocument *This = DISPEX_THIS(iface);
1601
1602 if(This->window && id == DISPID_IHTMLDOCUMENT2_LOCATION && (wFlags & DISPATCH_PROPERTYPUT))
1603 return IDispatchEx_InvokeEx(DISPATCHEX(This->window), DISPID_IHTMLWINDOW2_LOCATION, lcid, wFlags,
1604 pdp, pvarRes, pei, pspCaller);
1605
1606
1607 return IDispatchEx_InvokeEx(This->dispex, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1608 }
1609
1610 static HRESULT WINAPI DocDispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
1611 {
1612 HTMLDocument *This = DISPEX_THIS(iface);
1613
1614 return IDispatchEx_DeleteMemberByName(This->dispex, bstrName, grfdex);
1615 }
1616
1617 static HRESULT WINAPI DocDispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
1618 {
1619 HTMLDocument *This = DISPEX_THIS(iface);
1620
1621 return IDispatchEx_DeleteMemberByDispID(This->dispex, id);
1622 }
1623
1624 static HRESULT WINAPI DocDispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
1625 {
1626 HTMLDocument *This = DISPEX_THIS(iface);
1627
1628 return IDispatchEx_GetMemberProperties(This->dispex, id, grfdexFetch, pgrfdex);
1629 }
1630
1631 static HRESULT WINAPI DocDispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
1632 {
1633 HTMLDocument *This = DISPEX_THIS(iface);
1634
1635 return IDispatchEx_GetMemberName(This->dispex, id, pbstrName);
1636 }
1637
1638 static HRESULT WINAPI DocDispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
1639 {
1640 HTMLDocument *This = DISPEX_THIS(iface);
1641
1642 return IDispatchEx_GetNextDispID(This->dispex, grfdex, id, pid);
1643 }
1644
1645 static HRESULT WINAPI DocDispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
1646 {
1647 HTMLDocument *This = DISPEX_THIS(iface);
1648
1649 return IDispatchEx_GetNameSpaceParent(This->dispex, ppunk);
1650 }
1651
1652 #undef DISPEX_THIS
1653
1654 static const IDispatchExVtbl DocDispatchExVtbl = {
1655 DocDispatchEx_QueryInterface,
1656 DocDispatchEx_AddRef,
1657 DocDispatchEx_Release,
1658 DocDispatchEx_GetTypeInfoCount,
1659 DocDispatchEx_GetTypeInfo,
1660 DocDispatchEx_GetIDsOfNames,
1661 DocDispatchEx_Invoke,
1662 DocDispatchEx_GetDispID,
1663 DocDispatchEx_InvokeEx,
1664 DocDispatchEx_DeleteMemberByName,
1665 DocDispatchEx_DeleteMemberByDispID,
1666 DocDispatchEx_GetMemberProperties,
1667 DocDispatchEx_GetMemberName,
1668 DocDispatchEx_GetNextDispID,
1669 DocDispatchEx_GetNameSpaceParent
1670 };
1671
1672 static BOOL htmldoc_qi(HTMLDocument *This, REFIID riid, void **ppv)
1673 {
1674 *ppv = NULL;
1675
1676 if(IsEqualGUID(&IID_IUnknown, riid)) {
1677 TRACE("(%p)->(IID_IUnknown, %p)\n", This, ppv);
1678 *ppv = HTMLDOC(This);
1679 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1680 TRACE("(%p)->(IID_IDispatch, %p)\n", This, ppv);
1681 *ppv = DISPATCHEX(This);
1682 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
1683 TRACE("(%p)->(IID_IDispatchEx, %p)\n", This, ppv);
1684 *ppv = DISPATCHEX(This);
1685 }else if(IsEqualGUID(&IID_IHTMLDocument, riid)) {
1686 TRACE("(%p)->(IID_IHTMLDocument, %p)\n", This, ppv);
1687 *ppv = HTMLDOC(This);
1688 }else if(IsEqualGUID(&IID_IHTMLDocument2, riid)) {
1689 TRACE("(%p)->(IID_IHTMLDocument2, %p)\n", This, ppv);
1690 *ppv = HTMLDOC(This);
1691 }else if(IsEqualGUID(&IID_IHTMLDocument3, riid)) {
1692 TRACE("(%p)->(IID_IHTMLDocument3, %p)\n", This, ppv);
1693 *ppv = HTMLDOC3(This);
1694 }else if(IsEqualGUID(&IID_IHTMLDocument4, riid)) {
1695 TRACE("(%p)->(IID_IHTMLDocument4, %p)\n", This, ppv);
1696 *ppv = HTMLDOC4(This);
1697 }else if(IsEqualGUID(&IID_IHTMLDocument5, riid)) {
1698 TRACE("(%p)->(IID_IHTMLDocument5, %p)\n", This, ppv);
1699 *ppv = HTMLDOC5(This);
1700 }else if(IsEqualGUID(&IID_IHTMLDocument6, riid)) {
1701 TRACE("(%p)->(IID_IHTMLDocument6, %p)\n", This, ppv);
1702 *ppv = HTMLDOC6(This);
1703 }else if(IsEqualGUID(&IID_IPersist, riid)) {
1704 TRACE("(%p)->(IID_IPersist, %p)\n", This, ppv);
1705 *ppv = PERSIST(This);
1706 }else if(IsEqualGUID(&IID_IPersistMoniker, riid)) {
1707 TRACE("(%p)->(IID_IPersistMoniker, %p)\n", This, ppv);
1708 *ppv = PERSISTMON(This);
1709 }else if(IsEqualGUID(&IID_IPersistFile, riid)) {
1710 TRACE("(%p)->(IID_IPersistFile, %p)\n", This, ppv);
1711 *ppv = PERSISTFILE(This);
1712 }else if(IsEqualGUID(&IID_IMonikerProp, riid)) {
1713 TRACE("(%p)->(IID_IMonikerProp, %p)\n", This, ppv);
1714 *ppv = MONPROP(This);
1715 }else if(IsEqualGUID(&IID_IOleObject, riid)) {
1716 TRACE("(%p)->(IID_IOleObject, %p)\n", This, ppv);
1717 *ppv = OLEOBJ(This);
1718 }else if(IsEqualGUID(&IID_IOleDocument, riid)) {
1719 TRACE("(%p)->(IID_IOleDocument, %p)\n", This, ppv);
1720 *ppv = OLEDOC(This);
1721 }else if(IsEqualGUID(&IID_IOleDocumentView, riid)) {
1722 TRACE("(%p)->(IID_IOleDocumentView, %p)\n", This, ppv);
1723 *ppv = DOCVIEW(This);
1724 }else if(IsEqualGUID(&IID_IOleInPlaceActiveObject, riid)) {
1725 TRACE("(%p)->(IID_IOleInPlaceActiveObject, %p)\n", This, ppv);
1726 *ppv = ACTOBJ(This);
1727 }else if(IsEqualGUID(&IID_IViewObject, riid)) {
1728 TRACE("(%p)->(IID_IViewObject, %p)\n", This, ppv);
1729 *ppv = VIEWOBJ(This);
1730 }else if(IsEqualGUID(&IID_IViewObject2, riid)) {
1731 TRACE("(%p)->(IID_IViewObject2, %p)\n", This, ppv);
1732 *ppv = VIEWOBJ2(This);
1733 }else if(IsEqualGUID(&IID_IViewObjectEx, riid)) {
1734 TRACE("(%p)->(IID_IViewObjectEx, %p)\n", This, ppv);
1735 *ppv = VIEWOBJEX(This);
1736 }else if(IsEqualGUID(&IID_IOleWindow, riid)) {
1737 TRACE("(%p)->(IID_IOleWindow, %p)\n", This, ppv);
1738 *ppv = OLEWIN(This);
1739 }else if(IsEqualGUID(&IID_IOleInPlaceObject, riid)) {
1740 TRACE("(%p)->(IID_IOleInPlaceObject, %p)\n", This, ppv);
1741 *ppv = INPLACEOBJ(This);
1742 }else if(IsEqualGUID(&IID_IOleInPlaceObjectWindowless, riid)) {
1743 TRACE("(%p)->(IID_IOleInPlaceObjectWindowless, %p)\n", This, ppv);
1744 *ppv = INPLACEWIN(This);
1745 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
1746 TRACE("(%p)->(IID_IServiceProvider, %p)\n", This, ppv);
1747 *ppv = SERVPROV(This);
1748 }else if(IsEqualGUID(&IID_IOleCommandTarget, riid)) {
1749 TRACE("(%p)->(IID_IOleCommandTarget, %p)\n", This, ppv);
1750 *ppv = CMDTARGET(This);
1751 }else if(IsEqualGUID(&IID_IOleControl, riid)) {
1752 TRACE("(%p)->(IID_IOleControl, %p)\n", This, ppv);
1753 *ppv = CONTROL(This);
1754 }else if(IsEqualGUID(&IID_IHlinkTarget, riid)) {
1755 TRACE("(%p)->(IID_IHlinkTarget, %p)\n", This, ppv);
1756 *ppv = HLNKTARGET(This);
1757 }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
1758 TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppv);
1759 *ppv = CONPTCONT(&This->cp_container);
1760 }else if(IsEqualGUID(&IID_IPersistStreamInit, riid)) {
1761 TRACE("(%p)->(IID_IPersistStreamInit %p)\n", This, ppv);
1762 *ppv = PERSTRINIT(This);
1763 }else if(IsEqualGUID(&DIID_DispHTMLDocument, riid)) {
1764 TRACE("(%p)->(DIID_DispHTMLDocument %p)\n", This, ppv);
1765 *ppv = HTMLDOC(This);
1766 }else if(IsEqualGUID(&IID_ISupportErrorInfo, riid)) {
1767 TRACE("(%p)->(IID_ISupportErrorInfo %p)\n", This, ppv);
1768 *ppv = SUPPERRINFO(This);
1769 }else if(IsEqualGUID(&IID_IPersistHistory, riid)) {
1770 TRACE("(%p)->(IID_IPersistHistory %p)\n", This, ppv);
1771 *ppv = PERSISTHIST(This);
1772 }else if(IsEqualGUID(&CLSID_CMarkup, riid)) {
1773 FIXME("(%p)->(CLSID_CMarkup %p)\n", This, ppv);
1774 *ppv = NULL;
1775 }else if(IsEqualGUID(&IID_IRunnableObject, riid)) {
1776 TRACE("(%p)->(IID_IRunnableObject %p) returning NULL\n", This, ppv);
1777 *ppv = NULL;
1778 }else if(IsEqualGUID(&IID_IPersistPropertyBag, riid)) {
1779 TRACE("(%p)->(IID_IPersistPropertyBag %p) returning NULL\n", This, ppv);
1780 *ppv = NULL;
1781 }else if(IsEqualGUID(&IID_IMarshal, riid)) {
1782 TRACE("(%p)->(IID_IMarshal %p) returning NULL\n", This, ppv);
1783 *ppv = NULL;
1784 }else if(IsEqualGUID(&IID_IExternalConnection, riid)) {
1785 TRACE("(%p)->(IID_IExternalConnection %p) returning NULL\n", This, ppv);
1786 *ppv = NULL;
1787 }else if(IsEqualGUID(&IID_IStdMarshalInfo, riid)) {
1788 TRACE("(%p)->(IID_IStdMarshalInfo %p) returning NULL\n", This, ppv);
1789 *ppv = NULL;
1790 }else if(IsEqualGUID(&IID_IObjectWithSite, riid)) {
1791 TRACE("(%p)->(IID_IObjectWithSite %p)\n", This, ppv);
1792 *ppv = OBJSITE(This);
1793 }else {
1794 return FALSE;
1795 }
1796
1797 if(*ppv)
1798 IUnknown_AddRef((IUnknown*)*ppv);
1799 return TRUE;
1800 }
1801
1802 static cp_static_data_t HTMLDocumentEvents_data = { HTMLDocumentEvents_tid, HTMLDocument_on_advise };
1803
1804 static void init_doc(HTMLDocument *doc, IUnknown *unk_impl, IDispatchEx *dispex)
1805 {
1806 doc->lpHTMLDocument2Vtbl = &HTMLDocumentVtbl;
1807 doc->lpIDispatchExVtbl = &DocDispatchExVtbl;
1808 doc->lpSupportErrorInfoVtbl = &SupportErrorInfoVtbl;
1809
1810 doc->unk_impl = unk_impl;
1811 doc->dispex = dispex;
1812 doc->task_magic = get_task_target_magic();
1813
1814 HTMLDocument_HTMLDocument3_Init(doc);
1815 HTMLDocument_HTMLDocument5_Init(doc);
1816 HTMLDocument_Persist_Init(doc);
1817 HTMLDocument_OleCmd_Init(doc);
1818 HTMLDocument_OleObj_Init(doc);
1819 HTMLDocument_View_Init(doc);
1820 HTMLDocument_Window_Init(doc);
1821 HTMLDocument_Service_Init(doc);
1822 HTMLDocument_Hlink_Init(doc);
1823
1824 ConnectionPointContainer_Init(&doc->cp_container, (IUnknown*)HTMLDOC(doc));
1825 ConnectionPoint_Init(&doc->cp_dispatch, &doc->cp_container, &IID_IDispatch, NULL);
1826 ConnectionPoint_Init(&doc->cp_propnotif, &doc->cp_container, &IID_IPropertyNotifySink, NULL);
1827 ConnectionPoint_Init(&doc->cp_htmldocevents, &doc->cp_container, &DIID_HTMLDocumentEvents, &HTMLDocumentEvents_data);
1828 ConnectionPoint_Init(&doc->cp_htmldocevents2, &doc->cp_container, &DIID_HTMLDocumentEvents2, NULL);
1829 }
1830
1831 static void destroy_htmldoc(HTMLDocument *This)
1832 {
1833 remove_target_tasks(This->task_magic);
1834
1835 ConnectionPointContainer_Destroy(&This->cp_container);
1836 }
1837
1838 #define HTMLDOCNODE_NODE_THIS(iface) DEFINE_THIS2(HTMLDocumentNode, node, iface)
1839
1840 static HRESULT HTMLDocumentNode_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
1841 {
1842 HTMLDocumentNode *This = HTMLDOCNODE_NODE_THIS(iface);
1843
1844 if(htmldoc_qi(&This->basedoc, riid, ppv))
1845 return *ppv ? S_OK : E_NOINTERFACE;
1846
1847 if(IsEqualGUID(&IID_IInternetHostSecurityManager, riid)) {
1848 TRACE("(%p)->(IID_IInternetHostSecurityManager %p)\n", This, ppv);
1849 *ppv = HOSTSECMGR(This);
1850 }else {
1851 return HTMLDOMNode_QI(&This->node, riid, ppv);
1852 }
1853
1854 IUnknown_AddRef((IUnknown*)*ppv);
1855 return S_OK;
1856 }
1857
1858 static void HTMLDocumentNode_destructor(HTMLDOMNode *iface)
1859 {
1860 HTMLDocumentNode *This = HTMLDOCNODE_NODE_THIS(iface);
1861
1862 if(This->body_event_target)
1863 release_event_target(This->body_event_target);
1864 if(This->nsevent_listener)
1865 release_nsevents(This);
1866 if(This->catmgr)
1867 ICatInformation_Release(This->catmgr);
1868 if(This->secmgr)
1869 IInternetSecurityManager_Release(This->secmgr);
1870
1871 detach_selection(This);
1872 detach_ranges(This);
1873 release_nodes(This);
1874
1875 if(This->nsdoc) {
1876 release_mutation(This);
1877 nsIDOMHTMLDocument_Release(This->nsdoc);
1878 }
1879
1880 heap_free(This->event_vector);
1881 destroy_htmldoc(&This->basedoc);
1882 }
1883
1884 #undef HTMLDOCNODE_NODE_THIS
1885
1886 static const NodeImplVtbl HTMLDocumentNodeImplVtbl = {
1887 HTMLDocumentNode_QI,
1888 HTMLDocumentNode_destructor
1889 };
1890
1891 static const tid_t HTMLDocumentNode_iface_tids[] = {
1892 IHTMLDOMNode_tid,
1893 IHTMLDOMNode2_tid,
1894 IHTMLDocument2_tid,
1895 IHTMLDocument3_tid,
1896 IHTMLDocument4_tid,
1897 IHTMLDocument5_tid,
1898 0
1899 };
1900
1901 static dispex_static_data_t HTMLDocumentNode_dispex = {
1902 NULL,
1903 DispHTMLDocument_tid,
1904 NULL,
1905 HTMLDocumentNode_iface_tids
1906 };
1907
1908 HRESULT create_doc_from_nsdoc(nsIDOMHTMLDocument *nsdoc, HTMLDocumentObj *doc_obj, HTMLWindow *window, HTMLDocumentNode **ret)
1909 {
1910 HTMLDocumentNode *doc;
1911 HRESULT hres;
1912
1913 doc = heap_alloc_zero(sizeof(HTMLDocumentNode));
1914 if(!doc)
1915 return E_OUTOFMEMORY;
1916
1917 doc->basedoc.doc_node = doc;
1918 doc->basedoc.doc_obj = doc_obj;
1919
1920 init_dispex(&doc->node.dispex, (IUnknown*)HTMLDOMNODE(&doc->node), &HTMLDocumentNode_dispex);
1921 init_doc(&doc->basedoc, (IUnknown*)HTMLDOMNODE(&doc->node), DISPATCHEX(&doc->node.dispex));
1922 HTMLDocumentNode_SecMgr_Init(doc);
1923 doc->ref = 1;
1924
1925 doc->basedoc.window = window;
1926 if(window == doc_obj->basedoc.window)
1927 doc->basedoc.cp_container.forward_container = &doc_obj->basedoc.cp_container;
1928
1929 nsIDOMHTMLDocument_AddRef(nsdoc);
1930 doc->nsdoc = nsdoc;
1931 init_mutation(doc);
1932 init_nsevents(doc);
1933
1934 list_init(&doc->bindings);
1935 list_init(&doc->selection_list);
1936 list_init(&doc->range_list);
1937
1938 HTMLDOMNode_Init(doc, &doc->node, (nsIDOMNode*)nsdoc);
1939 doc->node.vtbl = &HTMLDocumentNodeImplVtbl;
1940 doc->node.cp_container = &doc->basedoc.cp_container;
1941
1942 hres = CoInternetCreateSecurityManager(NULL, &doc->secmgr, 0);
1943 if(FAILED(hres)) {
1944 htmldoc_release(&doc->basedoc);
1945 return hres;
1946 }
1947
1948 *ret = doc;
1949 return S_OK;
1950 }
1951
1952 /**********************************************************
1953 * ICustomDoc implementation
1954 */
1955
1956 #define CUSTOMDOC_THIS(iface) DEFINE_THIS(HTMLDocumentObj, CustomDoc, iface)
1957
1958 static HRESULT WINAPI CustomDoc_QueryInterface(ICustomDoc *iface, REFIID riid, void **ppv)
1959 {
1960 HTMLDocumentObj *This = CUSTOMDOC_THIS(iface);
1961
1962 if(htmldoc_qi(&This->basedoc, riid, ppv))
1963 return *ppv ? S_OK : E_NOINTERFACE;
1964
1965 if(IsEqualGUID(&IID_ICustomDoc, riid)) {
1966 TRACE("(%p)->(IID_ICustomDoc %p)\n", This, ppv);
1967 *ppv = CUSTOMDOC(This);
1968 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
1969 return *ppv ? S_OK : E_NOINTERFACE;
1970 }else {
1971 FIXME("Unimplemented interface %s\n", debugstr_guid(riid));
1972 *ppv = NULL;
1973 return E_NOINTERFACE;
1974 }
1975
1976 IUnknown_AddRef((IUnknown*)*ppv);
1977 return S_OK;
1978 }
1979
1980 static ULONG WINAPI CustomDoc_AddRef(ICustomDoc *iface)
1981 {
1982 HTMLDocumentObj *This = CUSTOMDOC_THIS(iface);
1983 ULONG ref = InterlockedIncrement(&This->ref);
1984
1985 TRACE("(%p) ref = %u\n", This, ref);
1986
1987 return ref;
1988 }
1989
1990 static ULONG WINAPI CustomDoc_Release(ICustomDoc *iface)
1991 {
1992 HTMLDocumentObj *This = CUSTOMDOC_THIS(iface);
1993 ULONG ref = InterlockedDecrement(&This->ref);
1994
1995 TRACE("(%p) ref = %u\n", This, ref);
1996
1997 if(!ref) {
1998 if(This->basedoc.doc_node) {
1999 This->basedoc.doc_node->basedoc.doc_obj = NULL;
2000 IHTMLDocument2_Release(HTMLDOC(&This->basedoc.doc_node->basedoc));
2001 }
2002 if(This->basedoc.window) {
2003 This->basedoc.window->doc_obj = NULL;
2004 IHTMLWindow2_Release(HTMLWINDOW2(This->basedoc.window));
2005 }
2006 if(This->basedoc.advise_holder)
2007 IOleAdviseHolder_Release(This->basedoc.advise_holder);
2008
2009 if(This->view_sink)
2010 IAdviseSink_Release(This->view_sink);
2011 if(This->client)
2012 IOleObject_SetClientSite(OLEOBJ(&This->basedoc), NULL);
2013 if(This->in_place_active)
2014 IOleInPlaceObjectWindowless_InPlaceDeactivate(INPLACEWIN(&This->basedoc));
2015 if(This->ipsite)
2016 IOleDocumentView_SetInPlaceSite(DOCVIEW(&This->basedoc), NULL);
2017 if(This->undomgr)
2018 IOleUndoManager_Release(This->undomgr);
2019 if(This->tooltips_hwnd)
2020 DestroyWindow(This->tooltips_hwnd);
2021
2022 if(This->hwnd)
2023 DestroyWindow(This->hwnd);
2024 heap_free(This->mime);
2025
2026 destroy_htmldoc(&This->basedoc);
2027 release_dispex(&This->dispex);
2028
2029 if(This->nscontainer)
2030 NSContainer_Release(This->nscontainer);
2031 heap_free(This);
2032 }
2033
2034 return ref;
2035 }
2036
2037 static HRESULT WINAPI CustomDoc_SetUIHandler(ICustomDoc *iface, IDocHostUIHandler *pUIHandler)
2038 {
2039 HTMLDocumentObj *This = CUSTOMDOC_THIS(iface);
2040 FIXME("(%p)->(%p)\n", This, pUIHandler);
2041 return E_NOTIMPL;
2042 }
2043
2044 #undef CUSTOMDOC_THIS
2045
2046 static const ICustomDocVtbl CustomDocVtbl = {
2047 CustomDoc_QueryInterface,
2048 CustomDoc_AddRef,
2049 CustomDoc_Release,
2050 CustomDoc_SetUIHandler
2051 };
2052
2053 static const tid_t HTMLDocumentObj_iface_tids[] = {
2054 IHTMLDocument2_tid,
2055 IHTMLDocument3_tid,
2056 IHTMLDocument4_tid,
2057 IHTMLDocument5_tid,
2058 0
2059 };
2060 static dispex_static_data_t HTMLDocumentObj_dispex = {
2061 NULL,
2062 DispHTMLDocument_tid,
2063 NULL,
2064 HTMLDocumentObj_iface_tids
2065 };
2066
2067 HRESULT HTMLDocument_Create(IUnknown *pUnkOuter, REFIID riid, void** ppvObject)
2068 {
2069 HTMLDocumentObj *doc;
2070 nsIDOMWindow *nswindow = NULL;
2071 nsresult nsres;
2072 HRESULT hres;
2073
2074 TRACE("(%p %s %p)\n", pUnkOuter, debugstr_guid(riid), ppvObject);
2075
2076 doc = heap_alloc_zero(sizeof(HTMLDocumentObj));
2077 if(!doc)
2078 return E_OUTOFMEMORY;
2079
2080 init_dispex(&doc->dispex, (IUnknown*)CUSTOMDOC(doc), &HTMLDocumentObj_dispex);
2081 init_doc(&doc->basedoc, (IUnknown*)CUSTOMDOC(doc), DISPATCHEX(&doc->dispex));
2082
2083 doc->lpCustomDocVtbl = &CustomDocVtbl;
2084 doc->ref = 1;
2085 doc->basedoc.doc_obj = doc;
2086
2087 doc->usermode = UNKNOWN_USERMODE;
2088
2089 doc->nscontainer = NSContainer_Create(doc, NULL);
2090 if(!doc->nscontainer) {
2091 ERR("Failed to init Gecko, returning CLASS_E_CLASSNOTAVAILABLE\n");
2092 htmldoc_release(&doc->basedoc);
2093 return CLASS_E_CLASSNOTAVAILABLE;
2094 }
2095
2096 hres = htmldoc_query_interface(&doc->basedoc, riid, ppvObject);
2097 htmldoc_release(&doc->basedoc);
2098 if(FAILED(hres))
2099 return hres;
2100
2101
2102 nsres = nsIWebBrowser_GetContentDOMWindow(doc->nscontainer->webbrowser, &nswindow);
2103 if(NS_FAILED(nsres))
2104 ERR("GetContentDOMWindow failed: %08x\n", nsres);
2105
2106 hres = HTMLWindow_Create(doc, nswindow, NULL /* FIXME */, &doc->basedoc.window);
2107 if(nswindow)
2108 nsIDOMWindow_Release(nswindow);
2109 if(FAILED(hres)) {
2110 IHTMLDocument_Release(HTMLDOC(&doc->basedoc));
2111 return hres;
2112 }
2113
2114 if(!doc->basedoc.doc_node && doc->basedoc.window->doc) {
2115 doc->basedoc.doc_node = doc->basedoc.window->doc;
2116 htmldoc_addref(&doc->basedoc.doc_node->basedoc);
2117 }
2118
2119 get_thread_hwnd();
2120
2121 return S_OK;
2122 }