8adfdb14b431acdd2945ebe4682cac3d7ecc719b
[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 FIXME("(%p)->(%p)\n", This, p);
558 return E_NOTIMPL;
559 }
560
561 static HRESULT WINAPI HTMLDocument_get_location(IHTMLDocument2 *iface, IHTMLLocation **p)
562 {
563 HTMLDocument *This = HTMLDOC_THIS(iface);
564
565 TRACE("(%p)->(%p)\n", This, p);
566
567 return IHTMLWindow2_get_location(HTMLWINDOW2(This->window), p);
568 }
569
570 static HRESULT WINAPI HTMLDocument_get_lastModified(IHTMLDocument2 *iface, BSTR *p)
571 {
572 HTMLDocument *This = HTMLDOC_THIS(iface);
573 FIXME("(%p)->(%p)\n", This, p);
574 return E_NOTIMPL;
575 }
576
577 static HRESULT WINAPI HTMLDocument_put_URL(IHTMLDocument2 *iface, BSTR v)
578 {
579 HTMLDocument *This = HTMLDOC_THIS(iface);
580 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
581 return E_NOTIMPL;
582 }
583
584 static HRESULT WINAPI HTMLDocument_get_URL(IHTMLDocument2 *iface, BSTR *p)
585 {
586 HTMLDocument *This = HTMLDOC_THIS(iface);
587
588 static const WCHAR about_blank_url[] =
589 {'a','b','o','u','t',':','b','l','a','n','k',0};
590
591 TRACE("(%p)->(%p)\n", iface, p);
592
593 *p = SysAllocString(This->window->url ? This->window->url : about_blank_url);
594 return *p ? S_OK : E_OUTOFMEMORY;
595 }
596
597 static HRESULT WINAPI HTMLDocument_put_domain(IHTMLDocument2 *iface, BSTR v)
598 {
599 HTMLDocument *This = HTMLDOC_THIS(iface);
600 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
601 return E_NOTIMPL;
602 }
603
604 static HRESULT WINAPI HTMLDocument_get_domain(IHTMLDocument2 *iface, BSTR *p)
605 {
606 HTMLDocument *This = HTMLDOC_THIS(iface);
607 FIXME("(%p)->(%p)\n", This, p);
608 return E_NOTIMPL;
609 }
610
611 static HRESULT WINAPI HTMLDocument_put_cookie(IHTMLDocument2 *iface, BSTR v)
612 {
613 HTMLDocument *This = HTMLDOC_THIS(iface);
614 BOOL bret;
615
616 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
617
618 bret = InternetSetCookieExW(This->window->url, NULL, v, 0, 0);
619 if(!bret) {
620 FIXME("InternetSetCookieExW failed: %u\n", GetLastError());
621 return HRESULT_FROM_WIN32(GetLastError());
622 }
623
624 return S_OK;
625 }
626
627 static HRESULT WINAPI HTMLDocument_get_cookie(IHTMLDocument2 *iface, BSTR *p)
628 {
629 HTMLDocument *This = HTMLDOC_THIS(iface);
630 DWORD size;
631 BOOL bret;
632
633 TRACE("(%p)->(%p)\n", This, p);
634
635 size = 0;
636 bret = InternetGetCookieExW(This->window->url, NULL, NULL, &size, 0, NULL);
637 if(!bret) {
638 switch(GetLastError()) {
639 case ERROR_INSUFFICIENT_BUFFER:
640 break;
641 case ERROR_NO_MORE_ITEMS:
642 *p = NULL;
643 return S_OK;
644 default:
645 FIXME("InternetGetCookieExW failed: %u\n", GetLastError());
646 return HRESULT_FROM_WIN32(GetLastError());
647 }
648 }
649
650 if(!size) {
651 *p = NULL;
652 return S_OK;
653 }
654
655 *p = SysAllocStringLen(NULL, size-1);
656 if(!*p)
657 return E_OUTOFMEMORY;
658
659 bret = InternetGetCookieExW(This->window->url, NULL, *p, &size, 0, NULL);
660 if(!bret) {
661 ERR("InternetGetCookieExW failed: %u\n", GetLastError());
662 return E_FAIL;
663 }
664
665 return S_OK;
666 }
667
668 static HRESULT WINAPI HTMLDocument_put_expando(IHTMLDocument2 *iface, VARIANT_BOOL v)
669 {
670 HTMLDocument *This = HTMLDOC_THIS(iface);
671 FIXME("(%p)->(%x)\n", This, v);
672 return E_NOTIMPL;
673 }
674
675 static HRESULT WINAPI HTMLDocument_get_expando(IHTMLDocument2 *iface, VARIANT_BOOL *p)
676 {
677 HTMLDocument *This = HTMLDOC_THIS(iface);
678 FIXME("(%p)->(%p)\n", This, p);
679 return E_NOTIMPL;
680 }
681
682 static HRESULT WINAPI HTMLDocument_put_charset(IHTMLDocument2 *iface, BSTR v)
683 {
684 HTMLDocument *This = HTMLDOC_THIS(iface);
685 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
686 return E_NOTIMPL;
687 }
688
689 static HRESULT WINAPI HTMLDocument_get_charset(IHTMLDocument2 *iface, BSTR *p)
690 {
691 HTMLDocument *This = HTMLDOC_THIS(iface);
692 FIXME("(%p)->(%p)\n", This, p);
693 return E_NOTIMPL;
694 }
695
696 static HRESULT WINAPI HTMLDocument_put_defaultCharset(IHTMLDocument2 *iface, BSTR v)
697 {
698 HTMLDocument *This = HTMLDOC_THIS(iface);
699 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
700 return E_NOTIMPL;
701 }
702
703 static HRESULT WINAPI HTMLDocument_get_defaultCharset(IHTMLDocument2 *iface, BSTR *p)
704 {
705 HTMLDocument *This = HTMLDOC_THIS(iface);
706 FIXME("(%p)->(%p)\n", This, p);
707 return E_NOTIMPL;
708 }
709
710 static HRESULT WINAPI HTMLDocument_get_mimeType(IHTMLDocument2 *iface, BSTR *p)
711 {
712 HTMLDocument *This = HTMLDOC_THIS(iface);
713 FIXME("(%p)->(%p)\n", This, p);
714 return E_NOTIMPL;
715 }
716
717 static HRESULT WINAPI HTMLDocument_get_fileSize(IHTMLDocument2 *iface, BSTR *p)
718 {
719 HTMLDocument *This = HTMLDOC_THIS(iface);
720 FIXME("(%p)->(%p)\n", This, p);
721 return E_NOTIMPL;
722 }
723
724 static HRESULT WINAPI HTMLDocument_get_fileCreatedDate(IHTMLDocument2 *iface, BSTR *p)
725 {
726 HTMLDocument *This = HTMLDOC_THIS(iface);
727 FIXME("(%p)->(%p)\n", This, p);
728 return E_NOTIMPL;
729 }
730
731 static HRESULT WINAPI HTMLDocument_get_fileModifiedDate(IHTMLDocument2 *iface, BSTR *p)
732 {
733 HTMLDocument *This = HTMLDOC_THIS(iface);
734 FIXME("(%p)->(%p)\n", This, p);
735 return E_NOTIMPL;
736 }
737
738 static HRESULT WINAPI HTMLDocument_get_fileUpdatedDate(IHTMLDocument2 *iface, BSTR *p)
739 {
740 HTMLDocument *This = HTMLDOC_THIS(iface);
741 FIXME("(%p)->(%p)\n", This, p);
742 return E_NOTIMPL;
743 }
744
745 static HRESULT WINAPI HTMLDocument_get_security(IHTMLDocument2 *iface, BSTR *p)
746 {
747 HTMLDocument *This = HTMLDOC_THIS(iface);
748 FIXME("(%p)->(%p)\n", This, p);
749 return E_NOTIMPL;
750 }
751
752 static HRESULT WINAPI HTMLDocument_get_protocol(IHTMLDocument2 *iface, BSTR *p)
753 {
754 HTMLDocument *This = HTMLDOC_THIS(iface);
755 FIXME("(%p)->(%p)\n", This, p);
756 return E_NOTIMPL;
757 }
758
759 static HRESULT WINAPI HTMLDocument_get_nameProp(IHTMLDocument2 *iface, BSTR *p)
760 {
761 HTMLDocument *This = HTMLDOC_THIS(iface);
762 FIXME("(%p)->(%p)\n", This, p);
763 return E_NOTIMPL;
764 }
765
766 static HRESULT document_write(HTMLDocument *This, SAFEARRAY *psarray, BOOL ln)
767 {
768 nsAString nsstr;
769 VARIANT *var;
770 ULONG i, argc;
771 nsresult nsres;
772 HRESULT hres;
773
774 if(!This->doc_node->nsdoc) {
775 WARN("NULL nsdoc\n");
776 return E_UNEXPECTED;
777 }
778
779 if (!psarray)
780 return S_OK;
781
782 if(psarray->cDims != 1) {
783 FIXME("cDims=%d\n", psarray->cDims);
784 return E_INVALIDARG;
785 }
786
787 hres = SafeArrayAccessData(psarray, (void**)&var);
788 if(FAILED(hres)) {
789 WARN("SafeArrayAccessData failed: %08x\n", hres);
790 return hres;
791 }
792
793 nsAString_Init(&nsstr, NULL);
794
795 argc = psarray->rgsabound[0].cElements;
796 for(i=0; i < argc; i++) {
797 if(V_VT(var+i) == VT_BSTR) {
798 nsAString_SetData(&nsstr, V_BSTR(var+i));
799 if(!ln || i != argc-1)
800 nsres = nsIDOMHTMLDocument_Write(This->doc_node->nsdoc, &nsstr);
801 else
802 nsres = nsIDOMHTMLDocument_Writeln(This->doc_node->nsdoc, &nsstr);
803 if(NS_FAILED(nsres))
804 ERR("Write failed: %08x\n", nsres);
805 }else {
806 FIXME("vt=%d\n", V_VT(var+i));
807 }
808 }
809
810 nsAString_Finish(&nsstr);
811 SafeArrayUnaccessData(psarray);
812
813 return S_OK;
814 }
815
816 static HRESULT WINAPI HTMLDocument_write(IHTMLDocument2 *iface, SAFEARRAY *psarray)
817 {
818 HTMLDocument *This = HTMLDOC_THIS(iface);
819
820 TRACE("(%p)->(%p)\n", iface, psarray);
821
822 return document_write(This, psarray, FALSE);
823 }
824
825 static HRESULT WINAPI HTMLDocument_writeln(IHTMLDocument2 *iface, SAFEARRAY *psarray)
826 {
827 HTMLDocument *This = HTMLDOC_THIS(iface);
828
829 TRACE("(%p)->(%p)\n", This, psarray);
830
831 return document_write(This, psarray, TRUE);
832 }
833
834 static HRESULT WINAPI HTMLDocument_open(IHTMLDocument2 *iface, BSTR url, VARIANT name,
835 VARIANT features, VARIANT replace, IDispatch **pomWindowResult)
836 {
837 HTMLDocument *This = HTMLDOC_THIS(iface);
838 nsresult nsres;
839
840 static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};
841
842 TRACE("(%p)->(%s %s %s %s %p)\n", This, debugstr_w(url), debugstr_variant(&name),
843 debugstr_variant(&features), debugstr_variant(&replace), pomWindowResult);
844
845 if(!This->doc_node->nsdoc) {
846 ERR("!nsdoc\n");
847 return E_NOTIMPL;
848 }
849
850 if(!url || strcmpW(url, text_htmlW) || V_VT(&name) != VT_ERROR
851 || V_VT(&features) != VT_ERROR || V_VT(&replace) != VT_ERROR)
852 FIXME("unsupported args\n");
853
854 nsres = nsIDOMHTMLDocument_Open(This->doc_node->nsdoc);
855 if(NS_FAILED(nsres)) {
856 ERR("Open failed: %08x\n", nsres);
857 return E_FAIL;
858 }
859
860 *pomWindowResult = (IDispatch*)HTMLWINDOW2(This->window);
861 IHTMLWindow2_AddRef(HTMLWINDOW2(This->window));
862 return S_OK;
863 }
864
865 static HRESULT WINAPI HTMLDocument_close(IHTMLDocument2 *iface)
866 {
867 HTMLDocument *This = HTMLDOC_THIS(iface);
868 nsresult nsres;
869
870 TRACE("(%p)\n", This);
871
872 if(!This->doc_node->nsdoc) {
873 ERR("!nsdoc\n");
874 return E_NOTIMPL;
875 }
876
877 nsres = nsIDOMHTMLDocument_Close(This->doc_node->nsdoc);
878 if(NS_FAILED(nsres)) {
879 ERR("Close failed: %08x\n", nsres);
880 return E_FAIL;
881 }
882
883 return S_OK;
884 }
885
886 static HRESULT WINAPI HTMLDocument_clear(IHTMLDocument2 *iface)
887 {
888 HTMLDocument *This = HTMLDOC_THIS(iface);
889 FIXME("(%p)\n", This);
890 return E_NOTIMPL;
891 }
892
893 static HRESULT WINAPI HTMLDocument_queryCommandSupported(IHTMLDocument2 *iface, BSTR cmdID,
894 VARIANT_BOOL *pfRet)
895 {
896 HTMLDocument *This = HTMLDOC_THIS(iface);
897 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
898 return E_NOTIMPL;
899 }
900
901 static HRESULT WINAPI HTMLDocument_queryCommandEnabled(IHTMLDocument2 *iface, BSTR cmdID,
902 VARIANT_BOOL *pfRet)
903 {
904 HTMLDocument *This = HTMLDOC_THIS(iface);
905 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
906 return E_NOTIMPL;
907 }
908
909 static HRESULT WINAPI HTMLDocument_queryCommandState(IHTMLDocument2 *iface, BSTR cmdID,
910 VARIANT_BOOL *pfRet)
911 {
912 HTMLDocument *This = HTMLDOC_THIS(iface);
913 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
914 return E_NOTIMPL;
915 }
916
917 static HRESULT WINAPI HTMLDocument_queryCommandIndeterm(IHTMLDocument2 *iface, BSTR cmdID,
918 VARIANT_BOOL *pfRet)
919 {
920 HTMLDocument *This = HTMLDOC_THIS(iface);
921 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
922 return E_NOTIMPL;
923 }
924
925 static HRESULT WINAPI HTMLDocument_queryCommandText(IHTMLDocument2 *iface, BSTR cmdID,
926 BSTR *pfRet)
927 {
928 HTMLDocument *This = HTMLDOC_THIS(iface);
929 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
930 return E_NOTIMPL;
931 }
932
933 static HRESULT WINAPI HTMLDocument_queryCommandValue(IHTMLDocument2 *iface, BSTR cmdID,
934 VARIANT *pfRet)
935 {
936 HTMLDocument *This = HTMLDOC_THIS(iface);
937 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
938 return E_NOTIMPL;
939 }
940
941 static HRESULT WINAPI HTMLDocument_execCommand(IHTMLDocument2 *iface, BSTR cmdID,
942 VARIANT_BOOL showUI, VARIANT value, VARIANT_BOOL *pfRet)
943 {
944 HTMLDocument *This = HTMLDOC_THIS(iface);
945 FIXME("(%p)->(%s %x %p)\n", This, debugstr_w(cmdID), showUI, pfRet);
946 return E_NOTIMPL;
947 }
948
949 static HRESULT WINAPI HTMLDocument_execCommandShowHelp(IHTMLDocument2 *iface, BSTR cmdID,
950 VARIANT_BOOL *pfRet)
951 {
952 HTMLDocument *This = HTMLDOC_THIS(iface);
953 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
954 return E_NOTIMPL;
955 }
956
957 static HRESULT WINAPI HTMLDocument_createElement(IHTMLDocument2 *iface, BSTR eTag,
958 IHTMLElement **newElem)
959 {
960 HTMLDocument *This = HTMLDOC_THIS(iface);
961 nsIDOMHTMLElement *nselem;
962 HTMLElement *elem;
963 HRESULT hres;
964
965 TRACE("(%p)->(%s %p)\n", This, debugstr_w(eTag), newElem);
966
967 hres = create_nselem(This->doc_node, eTag, &nselem);
968 if(FAILED(hres))
969 return hres;
970
971 elem = HTMLElement_Create(This->doc_node, (nsIDOMNode*)nselem, TRUE);
972 nsIDOMHTMLElement_Release(nselem);
973
974 *newElem = HTMLELEM(elem);
975 IHTMLElement_AddRef(HTMLELEM(elem));
976 return S_OK;
977 }
978
979 static HRESULT WINAPI HTMLDocument_put_onhelp(IHTMLDocument2 *iface, VARIANT v)
980 {
981 HTMLDocument *This = HTMLDOC_THIS(iface);
982 FIXME("(%p)\n", This);
983 return E_NOTIMPL;
984 }
985
986 static HRESULT WINAPI HTMLDocument_get_onhelp(IHTMLDocument2 *iface, VARIANT *p)
987 {
988 HTMLDocument *This = HTMLDOC_THIS(iface);
989 FIXME("(%p)->(%p)\n", This, p);
990 return E_NOTIMPL;
991 }
992
993 static HRESULT WINAPI HTMLDocument_put_onclick(IHTMLDocument2 *iface, VARIANT v)
994 {
995 HTMLDocument *This = HTMLDOC_THIS(iface);
996
997 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
998
999 return set_doc_event(This, EVENTID_CLICK, &v);
1000 }
1001
1002 static HRESULT WINAPI HTMLDocument_get_onclick(IHTMLDocument2 *iface, VARIANT *p)
1003 {
1004 HTMLDocument *This = HTMLDOC_THIS(iface);
1005
1006 TRACE("(%p)->(%p)\n", This, p);
1007
1008 return get_doc_event(This, EVENTID_CLICK, p);
1009 }
1010
1011 static HRESULT WINAPI HTMLDocument_put_ondblclick(IHTMLDocument2 *iface, VARIANT v)
1012 {
1013 HTMLDocument *This = HTMLDOC_THIS(iface);
1014 FIXME("(%p)\n", This);
1015 return E_NOTIMPL;
1016 }
1017
1018 static HRESULT WINAPI HTMLDocument_get_ondblclick(IHTMLDocument2 *iface, VARIANT *p)
1019 {
1020 HTMLDocument *This = HTMLDOC_THIS(iface);
1021 FIXME("(%p)->(%p)\n", This, p);
1022 return E_NOTIMPL;
1023 }
1024
1025 static HRESULT WINAPI HTMLDocument_put_onkeyup(IHTMLDocument2 *iface, VARIANT v)
1026 {
1027 HTMLDocument *This = HTMLDOC_THIS(iface);
1028
1029 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1030
1031 return set_doc_event(This, EVENTID_KEYUP, &v);
1032 }
1033
1034 static HRESULT WINAPI HTMLDocument_get_onkeyup(IHTMLDocument2 *iface, VARIANT *p)
1035 {
1036 HTMLDocument *This = HTMLDOC_THIS(iface);
1037
1038 TRACE("(%p)->(%p)\n", This, p);
1039
1040 return get_doc_event(This, EVENTID_KEYUP, p);
1041 }
1042
1043 static HRESULT WINAPI HTMLDocument_put_onkeydown(IHTMLDocument2 *iface, VARIANT v)
1044 {
1045 HTMLDocument *This = HTMLDOC_THIS(iface);
1046
1047 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1048
1049 return set_doc_event(This, EVENTID_KEYDOWN, &v);
1050 }
1051
1052 static HRESULT WINAPI HTMLDocument_get_onkeydown(IHTMLDocument2 *iface, VARIANT *p)
1053 {
1054 HTMLDocument *This = HTMLDOC_THIS(iface);
1055
1056 TRACE("(%p)->(%p)\n", This, p);
1057
1058 return get_doc_event(This, EVENTID_KEYDOWN, p);
1059 }
1060
1061 static HRESULT WINAPI HTMLDocument_put_onkeypress(IHTMLDocument2 *iface, VARIANT v)
1062 {
1063 HTMLDocument *This = HTMLDOC_THIS(iface);
1064 FIXME("(%p)\n", This);
1065 return E_NOTIMPL;
1066 }
1067
1068 static HRESULT WINAPI HTMLDocument_get_onkeypress(IHTMLDocument2 *iface, VARIANT *p)
1069 {
1070 HTMLDocument *This = HTMLDOC_THIS(iface);
1071 FIXME("(%p)->(%p)\n", This, p);
1072 return E_NOTIMPL;
1073 }
1074
1075 static HRESULT WINAPI HTMLDocument_put_onmouseup(IHTMLDocument2 *iface, VARIANT v)
1076 {
1077 HTMLDocument *This = HTMLDOC_THIS(iface);
1078
1079 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1080
1081 return set_doc_event(This, EVENTID_MOUSEUP, &v);
1082 }
1083
1084 static HRESULT WINAPI HTMLDocument_get_onmouseup(IHTMLDocument2 *iface, VARIANT *p)
1085 {
1086 HTMLDocument *This = HTMLDOC_THIS(iface);
1087
1088 TRACE("(%p)->(%p)\n", This, p);
1089
1090 return get_doc_event(This, EVENTID_MOUSEUP, p);
1091 }
1092
1093 static HRESULT WINAPI HTMLDocument_put_onmousedown(IHTMLDocument2 *iface, VARIANT v)
1094 {
1095 HTMLDocument *This = HTMLDOC_THIS(iface);
1096
1097 TRACE("(%p)->()\n", This);
1098
1099 return set_doc_event(This, EVENTID_MOUSEDOWN, &v);
1100 }
1101
1102 static HRESULT WINAPI HTMLDocument_get_onmousedown(IHTMLDocument2 *iface, VARIANT *p)
1103 {
1104 HTMLDocument *This = HTMLDOC_THIS(iface);
1105
1106 TRACE("(%p)->(%p)\n", This, p);
1107
1108 return get_doc_event(This, EVENTID_MOUSEDOWN, p);
1109 }
1110
1111 static HRESULT WINAPI HTMLDocument_put_onmousemove(IHTMLDocument2 *iface, VARIANT v)
1112 {
1113 HTMLDocument *This = HTMLDOC_THIS(iface);
1114 FIXME("(%p)\n", This);
1115 return E_NOTIMPL;
1116 }
1117
1118 static HRESULT WINAPI HTMLDocument_get_onmousemove(IHTMLDocument2 *iface, VARIANT *p)
1119 {
1120 HTMLDocument *This = HTMLDOC_THIS(iface);
1121 FIXME("(%p)->(%p)\n", This, p);
1122 return E_NOTIMPL;
1123 }
1124
1125 static HRESULT WINAPI HTMLDocument_put_onmouseout(IHTMLDocument2 *iface, VARIANT v)
1126 {
1127 HTMLDocument *This = HTMLDOC_THIS(iface);
1128
1129 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1130
1131 return set_doc_event(This, EVENTID_MOUSEOUT, &v);
1132 }
1133
1134 static HRESULT WINAPI HTMLDocument_get_onmouseout(IHTMLDocument2 *iface, VARIANT *p)
1135 {
1136 HTMLDocument *This = HTMLDOC_THIS(iface);
1137
1138 TRACE("(%p)->(%p)\n", This, p);
1139
1140 return get_doc_event(This, EVENTID_MOUSEOUT, p);
1141 }
1142
1143 static HRESULT WINAPI HTMLDocument_put_onmouseover(IHTMLDocument2 *iface, VARIANT v)
1144 {
1145 HTMLDocument *This = HTMLDOC_THIS(iface);
1146
1147 TRACE("(%p)\n", This);
1148
1149 return set_doc_event(This, EVENTID_MOUSEOVER, &v);
1150 }
1151
1152 static HRESULT WINAPI HTMLDocument_get_onmouseover(IHTMLDocument2 *iface, VARIANT *p)
1153 {
1154 HTMLDocument *This = HTMLDOC_THIS(iface);
1155
1156 TRACE("(%p)->(%p)\n", This, p);
1157
1158 return get_doc_event(This, EVENTID_MOUSEOVER, p);
1159 }
1160
1161 static HRESULT WINAPI HTMLDocument_put_onreadystatechange(IHTMLDocument2 *iface, VARIANT v)
1162 {
1163 HTMLDocument *This = HTMLDOC_THIS(iface);
1164
1165 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1166
1167 return set_doc_event(This, EVENTID_READYSTATECHANGE, &v);
1168 }
1169
1170 static HRESULT WINAPI HTMLDocument_get_onreadystatechange(IHTMLDocument2 *iface, VARIANT *p)
1171 {
1172 HTMLDocument *This = HTMLDOC_THIS(iface);
1173
1174 TRACE("(%p)->(%p)\n", This, p);
1175
1176 return get_doc_event(This, EVENTID_READYSTATECHANGE, p);
1177 }
1178
1179 static HRESULT WINAPI HTMLDocument_put_onafterupdate(IHTMLDocument2 *iface, VARIANT v)
1180 {
1181 HTMLDocument *This = HTMLDOC_THIS(iface);
1182 FIXME("(%p)\n", This);
1183 return E_NOTIMPL;
1184 }
1185
1186 static HRESULT WINAPI HTMLDocument_get_onafterupdate(IHTMLDocument2 *iface, VARIANT *p)
1187 {
1188 HTMLDocument *This = HTMLDOC_THIS(iface);
1189 FIXME("(%p)->(%p)\n", This, p);
1190 return E_NOTIMPL;
1191 }
1192
1193 static HRESULT WINAPI HTMLDocument_put_onrowexit(IHTMLDocument2 *iface, VARIANT v)
1194 {
1195 HTMLDocument *This = HTMLDOC_THIS(iface);
1196 FIXME("(%p)\n", This);
1197 return E_NOTIMPL;
1198 }
1199
1200 static HRESULT WINAPI HTMLDocument_get_onrowexit(IHTMLDocument2 *iface, VARIANT *p)
1201 {
1202 HTMLDocument *This = HTMLDOC_THIS(iface);
1203 FIXME("(%p)->(%p)\n", This, p);
1204 return E_NOTIMPL;
1205 }
1206
1207 static HRESULT WINAPI HTMLDocument_put_onrowenter(IHTMLDocument2 *iface, VARIANT v)
1208 {
1209 HTMLDocument *This = HTMLDOC_THIS(iface);
1210 FIXME("(%p)\n", This);
1211 return E_NOTIMPL;
1212 }
1213
1214 static HRESULT WINAPI HTMLDocument_get_onrowenter(IHTMLDocument2 *iface, VARIANT *p)
1215 {
1216 HTMLDocument *This = HTMLDOC_THIS(iface);
1217 FIXME("(%p)->(%p)\n", This, p);
1218 return E_NOTIMPL;
1219 }
1220
1221 static HRESULT WINAPI HTMLDocument_put_ondragstart(IHTMLDocument2 *iface, VARIANT v)
1222 {
1223 HTMLDocument *This = HTMLDOC_THIS(iface);
1224
1225 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1226
1227 return set_doc_event(This, EVENTID_DRAGSTART, &v);
1228 }
1229
1230 static HRESULT WINAPI HTMLDocument_get_ondragstart(IHTMLDocument2 *iface, VARIANT *p)
1231 {
1232 HTMLDocument *This = HTMLDOC_THIS(iface);
1233
1234 TRACE("(%p)->(%p)\n", This, p);
1235
1236 return get_doc_event(This, EVENTID_DRAGSTART, p);
1237 }
1238
1239 static HRESULT WINAPI HTMLDocument_put_onselectstart(IHTMLDocument2 *iface, VARIANT v)
1240 {
1241 HTMLDocument *This = HTMLDOC_THIS(iface);
1242
1243 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1244
1245 return set_doc_event(This, EVENTID_SELECTSTART, &v);
1246 }
1247
1248 static HRESULT WINAPI HTMLDocument_get_onselectstart(IHTMLDocument2 *iface, VARIANT *p)
1249 {
1250 HTMLDocument *This = HTMLDOC_THIS(iface);
1251
1252 TRACE("(%p)->(%p)\n", This, p);
1253
1254 return get_doc_event(This, EVENTID_SELECTSTART, p);
1255 }
1256
1257 static HRESULT WINAPI HTMLDocument_elementFromPoint(IHTMLDocument2 *iface, LONG x, LONG y,
1258 IHTMLElement **elementHit)
1259 {
1260 HTMLDocument *This = HTMLDOC_THIS(iface);
1261 FIXME("(%p)->(%d %d %p)\n", This, x, y, elementHit);
1262 return E_NOTIMPL;
1263 }
1264
1265 static HRESULT WINAPI HTMLDocument_get_parentWindow(IHTMLDocument2 *iface, IHTMLWindow2 **p)
1266 {
1267 HTMLDocument *This = HTMLDOC_THIS(iface);
1268
1269 TRACE("(%p)->(%p)\n", This, p);
1270
1271 *p = HTMLWINDOW2(This->window);
1272 IHTMLWindow2_AddRef(*p);
1273 return S_OK;
1274 }
1275
1276 static HRESULT WINAPI HTMLDocument_get_styleSheets(IHTMLDocument2 *iface,
1277 IHTMLStyleSheetsCollection **p)
1278 {
1279 HTMLDocument *This = HTMLDOC_THIS(iface);
1280 nsIDOMStyleSheetList *nsstylelist;
1281 nsIDOMDocumentStyle *nsdocstyle;
1282 nsresult nsres;
1283
1284 TRACE("(%p)->(%p)\n", This, p);
1285
1286 *p = NULL;
1287
1288 if(!This->doc_node->nsdoc) {
1289 WARN("NULL nsdoc\n");
1290 return E_UNEXPECTED;
1291 }
1292
1293 nsIDOMHTMLDocument_QueryInterface(This->doc_node->nsdoc, &IID_nsIDOMDocumentStyle, (void**)&nsdocstyle);
1294 nsres = nsIDOMDocumentStyle_GetStyleSheets(nsdocstyle, &nsstylelist);
1295 nsIDOMDocumentStyle_Release(nsdocstyle);
1296 if(NS_FAILED(nsres)) {
1297 ERR("GetStyleSheets failed: %08x\n", nsres);
1298 return E_FAIL;
1299 }
1300
1301 *p = HTMLStyleSheetsCollection_Create(nsstylelist);
1302 nsIDOMDocumentStyle_Release(nsstylelist);
1303
1304 return S_OK;
1305 }
1306
1307 static HRESULT WINAPI HTMLDocument_put_onbeforeupdate(IHTMLDocument2 *iface, VARIANT v)
1308 {
1309 HTMLDocument *This = HTMLDOC_THIS(iface);
1310 FIXME("(%p)\n", This);
1311 return E_NOTIMPL;
1312 }
1313
1314 static HRESULT WINAPI HTMLDocument_get_onbeforeupdate(IHTMLDocument2 *iface, VARIANT *p)
1315 {
1316 HTMLDocument *This = HTMLDOC_THIS(iface);
1317 FIXME("(%p)->(%p)\n", This, p);
1318 return E_NOTIMPL;
1319 }
1320
1321 static HRESULT WINAPI HTMLDocument_put_onerrorupdate(IHTMLDocument2 *iface, VARIANT v)
1322 {
1323 HTMLDocument *This = HTMLDOC_THIS(iface);
1324 FIXME("(%p)\n", This);
1325 return E_NOTIMPL;
1326 }
1327
1328 static HRESULT WINAPI HTMLDocument_get_onerrorupdate(IHTMLDocument2 *iface, VARIANT *p)
1329 {
1330 HTMLDocument *This = HTMLDOC_THIS(iface);
1331 FIXME("(%p)->(%p)\n", This, p);
1332 return E_NOTIMPL;
1333 }
1334
1335 static HRESULT WINAPI HTMLDocument_toString(IHTMLDocument2 *iface, BSTR *String)
1336 {
1337 HTMLDocument *This = HTMLDOC_THIS(iface);
1338 FIXME("(%p)->(%p)\n", This, String);
1339 return E_NOTIMPL;
1340 }
1341
1342 static HRESULT WINAPI HTMLDocument_createStyleSheet(IHTMLDocument2 *iface, BSTR bstrHref,
1343 LONG lIndex, IHTMLStyleSheet **ppnewStyleSheet)
1344 {
1345 HTMLDocument *This = HTMLDOC_THIS(iface);
1346
1347 FIXME("(%p)->(%s %d %p) semi-stub\n", This, debugstr_w(bstrHref), lIndex, ppnewStyleSheet);
1348
1349 *ppnewStyleSheet = HTMLStyleSheet_Create(NULL);
1350 return S_OK;
1351 }
1352
1353 static const IHTMLDocument2Vtbl HTMLDocumentVtbl = {
1354 HTMLDocument_QueryInterface,
1355 HTMLDocument_AddRef,
1356 HTMLDocument_Release,
1357 HTMLDocument_GetTypeInfoCount,
1358 HTMLDocument_GetTypeInfo,
1359 HTMLDocument_GetIDsOfNames,
1360 HTMLDocument_Invoke,
1361 HTMLDocument_get_Script,
1362 HTMLDocument_get_all,
1363 HTMLDocument_get_body,
1364 HTMLDocument_get_activeElement,
1365 HTMLDocument_get_images,
1366 HTMLDocument_get_applets,
1367 HTMLDocument_get_links,
1368 HTMLDocument_get_forms,
1369 HTMLDocument_get_anchors,
1370 HTMLDocument_put_title,
1371 HTMLDocument_get_title,
1372 HTMLDocument_get_scripts,
1373 HTMLDocument_put_designMode,
1374 HTMLDocument_get_designMode,
1375 HTMLDocument_get_selection,
1376 HTMLDocument_get_readyState,
1377 HTMLDocument_get_frames,
1378 HTMLDocument_get_embeds,
1379 HTMLDocument_get_plugins,
1380 HTMLDocument_put_alinkColor,
1381 HTMLDocument_get_alinkColor,
1382 HTMLDocument_put_bgColor,
1383 HTMLDocument_get_bgColor,
1384 HTMLDocument_put_fgColor,
1385 HTMLDocument_get_fgColor,
1386 HTMLDocument_put_linkColor,
1387 HTMLDocument_get_linkColor,
1388 HTMLDocument_put_vlinkColor,
1389 HTMLDocument_get_vlinkColor,
1390 HTMLDocument_get_referrer,
1391 HTMLDocument_get_location,
1392 HTMLDocument_get_lastModified,
1393 HTMLDocument_put_URL,
1394 HTMLDocument_get_URL,
1395 HTMLDocument_put_domain,
1396 HTMLDocument_get_domain,
1397 HTMLDocument_put_cookie,
1398 HTMLDocument_get_cookie,
1399 HTMLDocument_put_expando,
1400 HTMLDocument_get_expando,
1401 HTMLDocument_put_charset,
1402 HTMLDocument_get_charset,
1403 HTMLDocument_put_defaultCharset,
1404 HTMLDocument_get_defaultCharset,
1405 HTMLDocument_get_mimeType,
1406 HTMLDocument_get_fileSize,
1407 HTMLDocument_get_fileCreatedDate,
1408 HTMLDocument_get_fileModifiedDate,
1409 HTMLDocument_get_fileUpdatedDate,
1410 HTMLDocument_get_security,
1411 HTMLDocument_get_protocol,
1412 HTMLDocument_get_nameProp,
1413 HTMLDocument_write,
1414 HTMLDocument_writeln,
1415 HTMLDocument_open,
1416 HTMLDocument_close,
1417 HTMLDocument_clear,
1418 HTMLDocument_queryCommandSupported,
1419 HTMLDocument_queryCommandEnabled,
1420 HTMLDocument_queryCommandState,
1421 HTMLDocument_queryCommandIndeterm,
1422 HTMLDocument_queryCommandText,
1423 HTMLDocument_queryCommandValue,
1424 HTMLDocument_execCommand,
1425 HTMLDocument_execCommandShowHelp,
1426 HTMLDocument_createElement,
1427 HTMLDocument_put_onhelp,
1428 HTMLDocument_get_onhelp,
1429 HTMLDocument_put_onclick,
1430 HTMLDocument_get_onclick,
1431 HTMLDocument_put_ondblclick,
1432 HTMLDocument_get_ondblclick,
1433 HTMLDocument_put_onkeyup,
1434 HTMLDocument_get_onkeyup,
1435 HTMLDocument_put_onkeydown,
1436 HTMLDocument_get_onkeydown,
1437 HTMLDocument_put_onkeypress,
1438 HTMLDocument_get_onkeypress,
1439 HTMLDocument_put_onmouseup,
1440 HTMLDocument_get_onmouseup,
1441 HTMLDocument_put_onmousedown,
1442 HTMLDocument_get_onmousedown,
1443 HTMLDocument_put_onmousemove,
1444 HTMLDocument_get_onmousemove,
1445 HTMLDocument_put_onmouseout,
1446 HTMLDocument_get_onmouseout,
1447 HTMLDocument_put_onmouseover,
1448 HTMLDocument_get_onmouseover,
1449 HTMLDocument_put_onreadystatechange,
1450 HTMLDocument_get_onreadystatechange,
1451 HTMLDocument_put_onafterupdate,
1452 HTMLDocument_get_onafterupdate,
1453 HTMLDocument_put_onrowexit,
1454 HTMLDocument_get_onrowexit,
1455 HTMLDocument_put_onrowenter,
1456 HTMLDocument_get_onrowenter,
1457 HTMLDocument_put_ondragstart,
1458 HTMLDocument_get_ondragstart,
1459 HTMLDocument_put_onselectstart,
1460 HTMLDocument_get_onselectstart,
1461 HTMLDocument_elementFromPoint,
1462 HTMLDocument_get_parentWindow,
1463 HTMLDocument_get_styleSheets,
1464 HTMLDocument_put_onbeforeupdate,
1465 HTMLDocument_get_onbeforeupdate,
1466 HTMLDocument_put_onerrorupdate,
1467 HTMLDocument_get_onerrorupdate,
1468 HTMLDocument_toString,
1469 HTMLDocument_createStyleSheet
1470 };
1471
1472 static void HTMLDocument_on_advise(IUnknown *iface, cp_static_data_t *cp)
1473 {
1474 HTMLDocument *This = HTMLDOC_THIS(iface);
1475
1476 if(This->window)
1477 update_cp_events(This->window, cp);
1478 }
1479
1480 #undef HTMLDOC_THIS
1481
1482 #define SUPPINFO_THIS(iface) DEFINE_THIS(HTMLDocument, SupportErrorInfo, iface)
1483
1484 static HRESULT WINAPI SupportErrorInfo_QueryInterface(ISupportErrorInfo *iface, REFIID riid, void **ppv)
1485 {
1486 HTMLDocument *This = SUPPINFO_THIS(iface);
1487 return IHTMLDocument_QueryInterface(HTMLDOC(This), riid, ppv);
1488 }
1489
1490 static ULONG WINAPI SupportErrorInfo_AddRef(ISupportErrorInfo *iface)
1491 {
1492 HTMLDocument *This = SUPPINFO_THIS(iface);
1493 return IHTMLDocument_AddRef(HTMLDOC(This));
1494 }
1495
1496 static ULONG WINAPI SupportErrorInfo_Release(ISupportErrorInfo *iface)
1497 {
1498 HTMLDocument *This = SUPPINFO_THIS(iface);
1499 return IHTMLDocument_Release(HTMLDOC(This));
1500 }
1501
1502 static HRESULT WINAPI SupportErrorInfo_InterfaceSupportsErrorInfo(ISupportErrorInfo *iface, REFIID riid)
1503 {
1504 FIXME("(%p)->(%s)\n", iface, debugstr_guid(riid));
1505 return S_FALSE;
1506 }
1507
1508 static const ISupportErrorInfoVtbl SupportErrorInfoVtbl = {
1509 SupportErrorInfo_QueryInterface,
1510 SupportErrorInfo_AddRef,
1511 SupportErrorInfo_Release,
1512 SupportErrorInfo_InterfaceSupportsErrorInfo
1513 };
1514
1515 #define DISPEX_THIS(iface) DEFINE_THIS(HTMLDocument, IDispatchEx, iface)
1516
1517 static HRESULT WINAPI DocDispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
1518 {
1519 HTMLDocument *This = DISPEX_THIS(iface);
1520
1521 return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppv);
1522 }
1523
1524 static ULONG WINAPI DocDispatchEx_AddRef(IDispatchEx *iface)
1525 {
1526 HTMLDocument *This = DISPEX_THIS(iface);
1527
1528 return IHTMLDocument2_AddRef(HTMLDOC(This));
1529 }
1530
1531 static ULONG WINAPI DocDispatchEx_Release(IDispatchEx *iface)
1532 {
1533 HTMLDocument *This = DISPEX_THIS(iface);
1534
1535 return IHTMLDocument2_Release(HTMLDOC(This));
1536 }
1537
1538 static HRESULT WINAPI DocDispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
1539 {
1540 HTMLDocument *This = DISPEX_THIS(iface);
1541
1542 return IDispatchEx_GetTypeInfoCount(This->dispex, pctinfo);
1543 }
1544
1545 static HRESULT WINAPI DocDispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
1546 LCID lcid, ITypeInfo **ppTInfo)
1547 {
1548 HTMLDocument *This = DISPEX_THIS(iface);
1549
1550 return IDispatchEx_GetTypeInfo(This->dispex, iTInfo, lcid, ppTInfo);
1551 }
1552
1553 static HRESULT WINAPI DocDispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
1554 LPOLESTR *rgszNames, UINT cNames,
1555 LCID lcid, DISPID *rgDispId)
1556 {
1557 HTMLDocument *This = DISPEX_THIS(iface);
1558
1559 return IDispatchEx_GetIDsOfNames(This->dispex, riid, rgszNames, cNames, lcid, rgDispId);
1560 }
1561
1562 static HRESULT WINAPI DocDispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
1563 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1564 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1565 {
1566 HTMLDocument *This = DISPEX_THIS(iface);
1567
1568 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1569 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1570
1571 switch(dispIdMember) {
1572 case DISPID_READYSTATE:
1573 TRACE("DISPID_READYSTATE\n");
1574
1575 if(!(wFlags & DISPATCH_PROPERTYGET))
1576 return E_INVALIDARG;
1577
1578 V_VT(pVarResult) = VT_I4;
1579 V_I4(pVarResult) = This->window->readystate;
1580 return S_OK;
1581 }
1582
1583 return IDispatchEx_Invoke(This->dispex, dispIdMember, riid, lcid, wFlags, pDispParams,
1584 pVarResult, pExcepInfo, puArgErr);
1585 }
1586
1587 static HRESULT WINAPI DocDispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
1588 {
1589 HTMLDocument *This = DISPEX_THIS(iface);
1590
1591 return IDispatchEx_GetDispID(This->dispex, bstrName, grfdex, pid);
1592 }
1593
1594 static HRESULT WINAPI DocDispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1595 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1596 {
1597 HTMLDocument *This = DISPEX_THIS(iface);
1598
1599 return IDispatchEx_InvokeEx(This->dispex, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
1600 }
1601
1602 static HRESULT WINAPI DocDispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
1603 {
1604 HTMLDocument *This = DISPEX_THIS(iface);
1605
1606 return IDispatchEx_DeleteMemberByName(This->dispex, bstrName, grfdex);
1607 }
1608
1609 static HRESULT WINAPI DocDispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
1610 {
1611 HTMLDocument *This = DISPEX_THIS(iface);
1612
1613 return IDispatchEx_DeleteMemberByDispID(This->dispex, id);
1614 }
1615
1616 static HRESULT WINAPI DocDispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
1617 {
1618 HTMLDocument *This = DISPEX_THIS(iface);
1619
1620 return IDispatchEx_GetMemberProperties(This->dispex, id, grfdexFetch, pgrfdex);
1621 }
1622
1623 static HRESULT WINAPI DocDispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
1624 {
1625 HTMLDocument *This = DISPEX_THIS(iface);
1626
1627 return IDispatchEx_GetMemberName(This->dispex, id, pbstrName);
1628 }
1629
1630 static HRESULT WINAPI DocDispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
1631 {
1632 HTMLDocument *This = DISPEX_THIS(iface);
1633
1634 return IDispatchEx_GetNextDispID(This->dispex, grfdex, id, pid);
1635 }
1636
1637 static HRESULT WINAPI DocDispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
1638 {
1639 HTMLDocument *This = DISPEX_THIS(iface);
1640
1641 return IDispatchEx_GetNameSpaceParent(This->dispex, ppunk);
1642 }
1643
1644 #undef DISPEX_THIS
1645
1646 static const IDispatchExVtbl DocDispatchExVtbl = {
1647 DocDispatchEx_QueryInterface,
1648 DocDispatchEx_AddRef,
1649 DocDispatchEx_Release,
1650 DocDispatchEx_GetTypeInfoCount,
1651 DocDispatchEx_GetTypeInfo,
1652 DocDispatchEx_GetIDsOfNames,
1653 DocDispatchEx_Invoke,
1654 DocDispatchEx_GetDispID,
1655 DocDispatchEx_InvokeEx,
1656 DocDispatchEx_DeleteMemberByName,
1657 DocDispatchEx_DeleteMemberByDispID,
1658 DocDispatchEx_GetMemberProperties,
1659 DocDispatchEx_GetMemberName,
1660 DocDispatchEx_GetNextDispID,
1661 DocDispatchEx_GetNameSpaceParent
1662 };
1663
1664 static BOOL htmldoc_qi(HTMLDocument *This, REFIID riid, void **ppv)
1665 {
1666 *ppv = NULL;
1667
1668 if(IsEqualGUID(&IID_IUnknown, riid)) {
1669 TRACE("(%p)->(IID_IUnknown, %p)\n", This, ppv);
1670 *ppv = HTMLDOC(This);
1671 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1672 TRACE("(%p)->(IID_IDispatch, %p)\n", This, ppv);
1673 *ppv = DISPATCHEX(This);
1674 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
1675 TRACE("(%p)->(IID_IDispatchEx, %p)\n", This, ppv);
1676 *ppv = DISPATCHEX(This);
1677 }else if(IsEqualGUID(&IID_IHTMLDocument, riid)) {
1678 TRACE("(%p)->(IID_IHTMLDocument, %p)\n", This, ppv);
1679 *ppv = HTMLDOC(This);
1680 }else if(IsEqualGUID(&IID_IHTMLDocument2, riid)) {
1681 TRACE("(%p)->(IID_IHTMLDocument2, %p)\n", This, ppv);
1682 *ppv = HTMLDOC(This);
1683 }else if(IsEqualGUID(&IID_IHTMLDocument3, riid)) {
1684 TRACE("(%p)->(IID_IHTMLDocument3, %p)\n", This, ppv);
1685 *ppv = HTMLDOC3(This);
1686 }else if(IsEqualGUID(&IID_IHTMLDocument4, riid)) {
1687 TRACE("(%p)->(IID_IHTMLDocument4, %p)\n", This, ppv);
1688 *ppv = HTMLDOC4(This);
1689 }else if(IsEqualGUID(&IID_IHTMLDocument5, riid)) {
1690 TRACE("(%p)->(IID_IHTMLDocument5, %p)\n", This, ppv);
1691 *ppv = HTMLDOC5(This);
1692 }else if(IsEqualGUID(&IID_IHTMLDocument6, riid)) {
1693 TRACE("(%p)->(IID_IHTMLDocument6, %p)\n", This, ppv);
1694 *ppv = HTMLDOC6(This);
1695 }else if(IsEqualGUID(&IID_IPersist, riid)) {
1696 TRACE("(%p)->(IID_IPersist, %p)\n", This, ppv);
1697 *ppv = PERSIST(This);
1698 }else if(IsEqualGUID(&IID_IPersistMoniker, riid)) {
1699 TRACE("(%p)->(IID_IPersistMoniker, %p)\n", This, ppv);
1700 *ppv = PERSISTMON(This);
1701 }else if(IsEqualGUID(&IID_IPersistFile, riid)) {
1702 TRACE("(%p)->(IID_IPersistFile, %p)\n", This, ppv);
1703 *ppv = PERSISTFILE(This);
1704 }else if(IsEqualGUID(&IID_IMonikerProp, riid)) {
1705 TRACE("(%p)->(IID_IMonikerProp, %p)\n", This, ppv);
1706 *ppv = MONPROP(This);
1707 }else if(IsEqualGUID(&IID_IOleObject, riid)) {
1708 TRACE("(%p)->(IID_IOleObject, %p)\n", This, ppv);
1709 *ppv = OLEOBJ(This);
1710 }else if(IsEqualGUID(&IID_IOleDocument, riid)) {
1711 TRACE("(%p)->(IID_IOleDocument, %p)\n", This, ppv);
1712 *ppv = OLEDOC(This);
1713 }else if(IsEqualGUID(&IID_IOleDocumentView, riid)) {
1714 TRACE("(%p)->(IID_IOleDocumentView, %p)\n", This, ppv);
1715 *ppv = DOCVIEW(This);
1716 }else if(IsEqualGUID(&IID_IOleInPlaceActiveObject, riid)) {
1717 TRACE("(%p)->(IID_IOleInPlaceActiveObject, %p)\n", This, ppv);
1718 *ppv = ACTOBJ(This);
1719 }else if(IsEqualGUID(&IID_IViewObject, riid)) {
1720 TRACE("(%p)->(IID_IViewObject, %p)\n", This, ppv);
1721 *ppv = VIEWOBJ(This);
1722 }else if(IsEqualGUID(&IID_IViewObject2, riid)) {
1723 TRACE("(%p)->(IID_IViewObject2, %p)\n", This, ppv);
1724 *ppv = VIEWOBJ2(This);
1725 }else if(IsEqualGUID(&IID_IViewObjectEx, riid)) {
1726 TRACE("(%p)->(IID_IViewObjectEx, %p)\n", This, ppv);
1727 *ppv = VIEWOBJEX(This);
1728 }else if(IsEqualGUID(&IID_IOleWindow, riid)) {
1729 TRACE("(%p)->(IID_IOleWindow, %p)\n", This, ppv);
1730 *ppv = OLEWIN(This);
1731 }else if(IsEqualGUID(&IID_IOleInPlaceObject, riid)) {
1732 TRACE("(%p)->(IID_IOleInPlaceObject, %p)\n", This, ppv);
1733 *ppv = INPLACEOBJ(This);
1734 }else if(IsEqualGUID(&IID_IOleInPlaceObjectWindowless, riid)) {
1735 TRACE("(%p)->(IID_IOleInPlaceObjectWindowless, %p)\n", This, ppv);
1736 *ppv = INPLACEWIN(This);
1737 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
1738 TRACE("(%p)->(IID_IServiceProvider, %p)\n", This, ppv);
1739 *ppv = SERVPROV(This);
1740 }else if(IsEqualGUID(&IID_IOleCommandTarget, riid)) {
1741 TRACE("(%p)->(IID_IOleCommandTarget, %p)\n", This, ppv);
1742 *ppv = CMDTARGET(This);
1743 }else if(IsEqualGUID(&IID_IOleControl, riid)) {
1744 TRACE("(%p)->(IID_IOleControl, %p)\n", This, ppv);
1745 *ppv = CONTROL(This);
1746 }else if(IsEqualGUID(&IID_IHlinkTarget, riid)) {
1747 TRACE("(%p)->(IID_IHlinkTarget, %p)\n", This, ppv);
1748 *ppv = HLNKTARGET(This);
1749 }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
1750 TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppv);
1751 *ppv = CONPTCONT(&This->cp_container);
1752 }else if(IsEqualGUID(&IID_IPersistStreamInit, riid)) {
1753 TRACE("(%p)->(IID_IPersistStreamInit %p)\n", This, ppv);
1754 *ppv = PERSTRINIT(This);
1755 }else if(IsEqualGUID(&DIID_DispHTMLDocument, riid)) {
1756 TRACE("(%p)->(DIID_DispHTMLDocument %p)\n", This, ppv);
1757 *ppv = HTMLDOC(This);
1758 }else if(IsEqualGUID(&IID_ISupportErrorInfo, riid)) {
1759 TRACE("(%p)->(IID_ISupportErrorInfo %p)\n", This, ppv);
1760 *ppv = SUPPERRINFO(This);
1761 }else if(IsEqualGUID(&IID_IPersistHistory, riid)) {
1762 TRACE("(%p)->(IID_IPersistHistory %p)\n", This, ppv);
1763 *ppv = PERSISTHIST(This);
1764 }else if(IsEqualGUID(&CLSID_CMarkup, riid)) {
1765 FIXME("(%p)->(CLSID_CMarkup %p)\n", This, ppv);
1766 *ppv = NULL;
1767 }else if(IsEqualGUID(&IID_IRunnableObject, riid)) {
1768 TRACE("(%p)->(IID_IRunnableObject %p) returning NULL\n", This, ppv);
1769 *ppv = NULL;
1770 }else if(IsEqualGUID(&IID_IPersistPropertyBag, riid)) {
1771 TRACE("(%p)->(IID_IPersistPropertyBag %p) returning NULL\n", This, ppv);
1772 *ppv = NULL;
1773 }else if(IsEqualGUID(&IID_IMarshal, riid)) {
1774 TRACE("(%p)->(IID_IMarshal %p) returning NULL\n", This, ppv);
1775 *ppv = NULL;
1776 }else if(IsEqualGUID(&IID_IExternalConnection, riid)) {
1777 TRACE("(%p)->(IID_IExternalConnection %p) returning NULL\n", This, ppv);
1778 *ppv = NULL;
1779 }else if(IsEqualGUID(&IID_IStdMarshalInfo, riid)) {
1780 TRACE("(%p)->(IID_IStdMarshalInfo %p) returning NULL\n", This, ppv);
1781 *ppv = NULL;
1782 }else if(IsEqualGUID(&IID_IObjectWithSite, riid)) {
1783 TRACE("(%p)->(IID_IObjectWithSite %p)\n", This, ppv);
1784 *ppv = OBJSITE(This);
1785 }else {
1786 return FALSE;
1787 }
1788
1789 if(*ppv)
1790 IUnknown_AddRef((IUnknown*)*ppv);
1791 return TRUE;
1792 }
1793
1794 static cp_static_data_t HTMLDocumentEvents_data = { HTMLDocumentEvents_tid, HTMLDocument_on_advise };
1795
1796 static void init_doc(HTMLDocument *doc, IUnknown *unk_impl, IDispatchEx *dispex)
1797 {
1798 doc->lpHTMLDocument2Vtbl = &HTMLDocumentVtbl;
1799 doc->lpIDispatchExVtbl = &DocDispatchExVtbl;
1800 doc->lpSupportErrorInfoVtbl = &SupportErrorInfoVtbl;
1801
1802 doc->unk_impl = unk_impl;
1803 doc->dispex = dispex;
1804 doc->task_magic = get_task_target_magic();
1805
1806 HTMLDocument_HTMLDocument3_Init(doc);
1807 HTMLDocument_HTMLDocument5_Init(doc);
1808 HTMLDocument_Persist_Init(doc);
1809 HTMLDocument_OleCmd_Init(doc);
1810 HTMLDocument_OleObj_Init(doc);
1811 HTMLDocument_View_Init(doc);
1812 HTMLDocument_Window_Init(doc);
1813 HTMLDocument_Service_Init(doc);
1814 HTMLDocument_Hlink_Init(doc);
1815
1816 ConnectionPointContainer_Init(&doc->cp_container, (IUnknown*)HTMLDOC(doc));
1817 ConnectionPoint_Init(&doc->cp_dispatch, &doc->cp_container, &IID_IDispatch, NULL);
1818 ConnectionPoint_Init(&doc->cp_propnotif, &doc->cp_container, &IID_IPropertyNotifySink, NULL);
1819 ConnectionPoint_Init(&doc->cp_htmldocevents, &doc->cp_container, &DIID_HTMLDocumentEvents, &HTMLDocumentEvents_data);
1820 ConnectionPoint_Init(&doc->cp_htmldocevents2, &doc->cp_container, &DIID_HTMLDocumentEvents2, NULL);
1821 }
1822
1823 static void destroy_htmldoc(HTMLDocument *This)
1824 {
1825 remove_target_tasks(This->task_magic);
1826
1827 ConnectionPointContainer_Destroy(&This->cp_container);
1828 }
1829
1830 #define HTMLDOCNODE_NODE_THIS(iface) DEFINE_THIS2(HTMLDocumentNode, node, iface)
1831
1832 static HRESULT HTMLDocumentNode_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
1833 {
1834 HTMLDocumentNode *This = HTMLDOCNODE_NODE_THIS(iface);
1835
1836 if(htmldoc_qi(&This->basedoc, riid, ppv))
1837 return *ppv ? S_OK : E_NOINTERFACE;
1838
1839 if(IsEqualGUID(&IID_IInternetHostSecurityManager, riid)) {
1840 TRACE("(%p)->(IID_IInternetHostSecurityManager %p)\n", This, ppv);
1841 *ppv = HOSTSECMGR(This);
1842 }else {
1843 return HTMLDOMNode_QI(&This->node, riid, ppv);
1844 }
1845
1846 IUnknown_AddRef((IUnknown*)*ppv);
1847 return S_OK;
1848 }
1849
1850 static void HTMLDocumentNode_destructor(HTMLDOMNode *iface)
1851 {
1852 HTMLDocumentNode *This = HTMLDOCNODE_NODE_THIS(iface);
1853
1854 if(This->body_event_target)
1855 release_event_target(This->body_event_target);
1856 if(This->nsevent_listener)
1857 release_nsevents(This);
1858 if(This->catmgr)
1859 ICatInformation_Release(This->catmgr);
1860 if(This->secmgr)
1861 IInternetSecurityManager_Release(This->secmgr);
1862
1863 detach_selection(This);
1864 detach_ranges(This);
1865 release_nodes(This);
1866
1867 if(This->nsdoc) {
1868 release_mutation(This);
1869 nsIDOMHTMLDocument_Release(This->nsdoc);
1870 }
1871
1872 heap_free(This->event_vector);
1873 destroy_htmldoc(&This->basedoc);
1874 }
1875
1876 #undef HTMLDOCNODE_NODE_THIS
1877
1878 static const NodeImplVtbl HTMLDocumentNodeImplVtbl = {
1879 HTMLDocumentNode_QI,
1880 HTMLDocumentNode_destructor
1881 };
1882
1883 static const tid_t HTMLDocumentNode_iface_tids[] = {
1884 IHTMLDOMNode_tid,
1885 IHTMLDOMNode2_tid,
1886 IHTMLDocument2_tid,
1887 IHTMLDocument3_tid,
1888 IHTMLDocument4_tid,
1889 IHTMLDocument5_tid,
1890 0
1891 };
1892
1893 static dispex_static_data_t HTMLDocumentNode_dispex = {
1894 NULL,
1895 DispHTMLDocument_tid,
1896 NULL,
1897 HTMLDocumentNode_iface_tids
1898 };
1899
1900 HRESULT create_doc_from_nsdoc(nsIDOMHTMLDocument *nsdoc, HTMLDocumentObj *doc_obj, HTMLWindow *window, HTMLDocumentNode **ret)
1901 {
1902 HTMLDocumentNode *doc;
1903 HRESULT hres;
1904
1905 doc = heap_alloc_zero(sizeof(HTMLDocumentNode));
1906 if(!doc)
1907 return E_OUTOFMEMORY;
1908
1909 doc->basedoc.doc_node = doc;
1910 doc->basedoc.doc_obj = doc_obj;
1911
1912 init_dispex(&doc->node.dispex, (IUnknown*)HTMLDOMNODE(&doc->node), &HTMLDocumentNode_dispex);
1913 init_doc(&doc->basedoc, (IUnknown*)HTMLDOMNODE(&doc->node), DISPATCHEX(&doc->node.dispex));
1914 HTMLDocumentNode_SecMgr_Init(doc);
1915 doc->ref = 1;
1916
1917 doc->basedoc.window = window;
1918 if(window == doc_obj->basedoc.window)
1919 doc->basedoc.cp_container.forward_container = &doc_obj->basedoc.cp_container;
1920
1921 nsIDOMHTMLDocument_AddRef(nsdoc);
1922 doc->nsdoc = nsdoc;
1923 init_mutation(doc);
1924 init_nsevents(doc);
1925
1926 list_init(&doc->bindings);
1927 list_init(&doc->selection_list);
1928 list_init(&doc->range_list);
1929
1930 HTMLDOMNode_Init(doc, &doc->node, (nsIDOMNode*)nsdoc);
1931 doc->node.vtbl = &HTMLDocumentNodeImplVtbl;
1932 doc->node.cp_container = &doc->basedoc.cp_container;
1933
1934 hres = CoInternetCreateSecurityManager(NULL, &doc->secmgr, 0);
1935 if(FAILED(hres)) {
1936 htmldoc_release(&doc->basedoc);
1937 return hres;
1938 }
1939
1940 *ret = doc;
1941 return S_OK;
1942 }
1943
1944 /**********************************************************
1945 * ICustomDoc implementation
1946 */
1947
1948 #define CUSTOMDOC_THIS(iface) DEFINE_THIS(HTMLDocumentObj, CustomDoc, iface)
1949
1950 static HRESULT WINAPI CustomDoc_QueryInterface(ICustomDoc *iface, REFIID riid, void **ppv)
1951 {
1952 HTMLDocumentObj *This = CUSTOMDOC_THIS(iface);
1953
1954 if(htmldoc_qi(&This->basedoc, riid, ppv))
1955 return *ppv ? S_OK : E_NOINTERFACE;
1956
1957 if(IsEqualGUID(&IID_ICustomDoc, riid)) {
1958 TRACE("(%p)->(IID_ICustomDoc %p)\n", This, ppv);
1959 *ppv = CUSTOMDOC(This);
1960 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
1961 return *ppv ? S_OK : E_NOINTERFACE;
1962 }else {
1963 FIXME("Unimplemented interface %s\n", debugstr_guid(riid));
1964 *ppv = NULL;
1965 return E_NOINTERFACE;
1966 }
1967
1968 IUnknown_AddRef((IUnknown*)*ppv);
1969 return S_OK;
1970 }
1971
1972 static ULONG WINAPI CustomDoc_AddRef(ICustomDoc *iface)
1973 {
1974 HTMLDocumentObj *This = CUSTOMDOC_THIS(iface);
1975 ULONG ref = InterlockedIncrement(&This->ref);
1976
1977 TRACE("(%p) ref = %u\n", This, ref);
1978
1979 return ref;
1980 }
1981
1982 static ULONG WINAPI CustomDoc_Release(ICustomDoc *iface)
1983 {
1984 HTMLDocumentObj *This = CUSTOMDOC_THIS(iface);
1985 ULONG ref = InterlockedDecrement(&This->ref);
1986
1987 TRACE("(%p) ref = %u\n", This, ref);
1988
1989 if(!ref) {
1990 if(This->basedoc.doc_node) {
1991 This->basedoc.doc_node->basedoc.doc_obj = NULL;
1992 IHTMLDocument2_Release(HTMLDOC(&This->basedoc.doc_node->basedoc));
1993 }
1994 if(This->basedoc.window) {
1995 This->basedoc.window->doc_obj = NULL;
1996 IHTMLWindow2_Release(HTMLWINDOW2(This->basedoc.window));
1997 }
1998 if(This->basedoc.advise_holder)
1999 IOleAdviseHolder_Release(This->basedoc.advise_holder);
2000
2001 if(This->view_sink)
2002 IAdviseSink_Release(This->view_sink);
2003 if(This->client)
2004 IOleObject_SetClientSite(OLEOBJ(&This->basedoc), NULL);
2005 if(This->in_place_active)
2006 IOleInPlaceObjectWindowless_InPlaceDeactivate(INPLACEWIN(&This->basedoc));
2007 if(This->ipsite)
2008 IOleDocumentView_SetInPlaceSite(DOCVIEW(&This->basedoc), NULL);
2009 if(This->undomgr)
2010 IOleUndoManager_Release(This->undomgr);
2011 if(This->tooltips_hwnd)
2012 DestroyWindow(This->tooltips_hwnd);
2013
2014 if(This->hwnd)
2015 DestroyWindow(This->hwnd);
2016 heap_free(This->mime);
2017
2018 destroy_htmldoc(&This->basedoc);
2019 release_dispex(&This->dispex);
2020
2021 if(This->nscontainer)
2022 NSContainer_Release(This->nscontainer);
2023 heap_free(This);
2024 }
2025
2026 return ref;
2027 }
2028
2029 static HRESULT WINAPI CustomDoc_SetUIHandler(ICustomDoc *iface, IDocHostUIHandler *pUIHandler)
2030 {
2031 HTMLDocumentObj *This = CUSTOMDOC_THIS(iface);
2032 FIXME("(%p)->(%p)\n", This, pUIHandler);
2033 return E_NOTIMPL;
2034 }
2035
2036 #undef CUSTOMDOC_THIS
2037
2038 static const ICustomDocVtbl CustomDocVtbl = {
2039 CustomDoc_QueryInterface,
2040 CustomDoc_AddRef,
2041 CustomDoc_Release,
2042 CustomDoc_SetUIHandler
2043 };
2044
2045 static const tid_t HTMLDocumentObj_iface_tids[] = {
2046 IHTMLDocument2_tid,
2047 IHTMLDocument3_tid,
2048 IHTMLDocument4_tid,
2049 IHTMLDocument5_tid,
2050 0
2051 };
2052 static dispex_static_data_t HTMLDocumentObj_dispex = {
2053 NULL,
2054 DispHTMLDocument_tid,
2055 NULL,
2056 HTMLDocumentObj_iface_tids
2057 };
2058
2059 HRESULT HTMLDocument_Create(IUnknown *pUnkOuter, REFIID riid, void** ppvObject)
2060 {
2061 HTMLDocumentObj *doc;
2062 nsIDOMWindow *nswindow = NULL;
2063 nsresult nsres;
2064 HRESULT hres;
2065
2066 TRACE("(%p %s %p)\n", pUnkOuter, debugstr_guid(riid), ppvObject);
2067
2068 doc = heap_alloc_zero(sizeof(HTMLDocumentObj));
2069 if(!doc)
2070 return E_OUTOFMEMORY;
2071
2072 init_dispex(&doc->dispex, (IUnknown*)CUSTOMDOC(doc), &HTMLDocumentObj_dispex);
2073 init_doc(&doc->basedoc, (IUnknown*)CUSTOMDOC(doc), DISPATCHEX(&doc->dispex));
2074
2075 doc->lpCustomDocVtbl = &CustomDocVtbl;
2076 doc->ref = 1;
2077 doc->basedoc.doc_obj = doc;
2078
2079 doc->usermode = UNKNOWN_USERMODE;
2080
2081 doc->nscontainer = NSContainer_Create(doc, NULL);
2082 if(!doc->nscontainer) {
2083 ERR("Failed to init Gecko, returning CLASS_E_CLASSNOTAVAILABLE\n");
2084 htmldoc_release(&doc->basedoc);
2085 return CLASS_E_CLASSNOTAVAILABLE;
2086 }
2087
2088 hres = htmldoc_query_interface(&doc->basedoc, riid, ppvObject);
2089 htmldoc_release(&doc->basedoc);
2090 if(FAILED(hres))
2091 return hres;
2092
2093
2094 nsres = nsIWebBrowser_GetContentDOMWindow(doc->nscontainer->webbrowser, &nswindow);
2095 if(NS_FAILED(nsres))
2096 ERR("GetContentDOMWindow failed: %08x\n", nsres);
2097
2098 hres = HTMLWindow_Create(doc, nswindow, NULL /* FIXME */, &doc->basedoc.window);
2099 if(nswindow)
2100 nsIDOMWindow_Release(nswindow);
2101 if(FAILED(hres)) {
2102 IHTMLDocument_Release(HTMLDOC(&doc->basedoc));
2103 return hres;
2104 }
2105
2106 if(!doc->basedoc.doc_node && doc->basedoc.window->doc) {
2107 doc->basedoc.doc_node = doc->basedoc.window->doc;
2108 htmldoc_addref(&doc->basedoc.doc_node->basedoc);
2109 }
2110
2111 get_thread_hwnd();
2112
2113 return S_OK;
2114 }