3a4de0c0a69e559ffed785d202e1c1cc536317ee
[reactos.git] / reactos / dll / win32 / mshtml / htmldoc3.c
1 /*
2 * Copyright 2005 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 #define WIN32_NO_STATUS
20 #define _INC_WINDOWS
21
22 #include <config.h>
23
24 #include <stdarg.h>
25 //#include <stdio.h>
26 #include <assert.h>
27
28 #define COBJMACROS
29
30 #include <windef.h>
31 #include <winbase.h>
32 //#include "winuser.h"
33 #include <ole2.h>
34
35 #include <wine/debug.h>
36
37 #include "mshtml_private.h"
38 #include "htmlevent.h"
39
40 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
41
42 HRESULT get_doc_elem_by_id(HTMLDocumentNode *doc, const WCHAR *id, HTMLElement **ret)
43 {
44 nsIDOMNodeList *nsnode_list;
45 nsIDOMElement *nselem;
46 nsIDOMNode *nsnode;
47 nsAString id_str;
48 nsresult nsres;
49 HRESULT hres;
50
51 if(!doc->nsdoc) {
52 WARN("NULL nsdoc\n");
53 return E_UNEXPECTED;
54 }
55
56 nsAString_InitDepend(&id_str, id);
57 /* get element by id attribute */
58 nsres = nsIDOMHTMLDocument_GetElementById(doc->nsdoc, &id_str, &nselem);
59 if(FAILED(nsres)) {
60 ERR("GetElementById failed: %08x\n", nsres);
61 nsAString_Finish(&id_str);
62 return E_FAIL;
63 }
64
65 /* get first element by name attribute */
66 nsres = nsIDOMHTMLDocument_GetElementsByName(doc->nsdoc, &id_str, &nsnode_list);
67 nsAString_Finish(&id_str);
68 if(FAILED(nsres)) {
69 ERR("getElementsByName failed: %08x\n", nsres);
70 if(nselem)
71 nsIDOMElement_Release(nselem);
72 return E_FAIL;
73 }
74
75 nsres = nsIDOMNodeList_Item(nsnode_list, 0, &nsnode);
76 nsIDOMNodeList_Release(nsnode_list);
77 assert(nsres == NS_OK);
78
79 if(nsnode && nselem) {
80 UINT16 pos;
81
82 nsres = nsIDOMNode_CompareDocumentPosition(nsnode, (nsIDOMNode*)nselem, &pos);
83 if(NS_FAILED(nsres)) {
84 FIXME("CompareDocumentPosition failed: 0x%08x\n", nsres);
85 nsIDOMNode_Release(nsnode);
86 nsIDOMElement_Release(nselem);
87 return E_FAIL;
88 }
89
90 TRACE("CompareDocumentPosition gave: 0x%x\n", pos);
91 if(!(pos & (DOCUMENT_POSITION_PRECEDING | DOCUMENT_POSITION_CONTAINS))) {
92 nsIDOMElement_Release(nselem);
93 nselem = NULL;
94 }
95 }
96
97 if(nsnode) {
98 if(!nselem) {
99 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMElement, (void**)&nselem);
100 assert(nsres == NS_OK);
101 }
102 nsIDOMNode_Release(nsnode);
103 }
104
105 if(!nselem) {
106 *ret = NULL;
107 return S_OK;
108 }
109
110 hres = get_elem(doc, nselem, ret);
111 nsIDOMElement_Release(nselem);
112 return hres;
113 }
114
115 static inline HTMLDocument *impl_from_IHTMLDocument3(IHTMLDocument3 *iface)
116 {
117 return CONTAINING_RECORD(iface, HTMLDocument, IHTMLDocument3_iface);
118 }
119
120 static HRESULT WINAPI HTMLDocument3_QueryInterface(IHTMLDocument3 *iface,
121 REFIID riid, void **ppv)
122 {
123 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
124 return htmldoc_query_interface(This, riid, ppv);
125 }
126
127 static ULONG WINAPI HTMLDocument3_AddRef(IHTMLDocument3 *iface)
128 {
129 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
130 return htmldoc_addref(This);
131 }
132
133 static ULONG WINAPI HTMLDocument3_Release(IHTMLDocument3 *iface)
134 {
135 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
136 return htmldoc_release(This);
137 }
138
139 static HRESULT WINAPI HTMLDocument3_GetTypeInfoCount(IHTMLDocument3 *iface, UINT *pctinfo)
140 {
141 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
142 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
143 }
144
145 static HRESULT WINAPI HTMLDocument3_GetTypeInfo(IHTMLDocument3 *iface, UINT iTInfo,
146 LCID lcid, ITypeInfo **ppTInfo)
147 {
148 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
149 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
150 }
151
152 static HRESULT WINAPI HTMLDocument3_GetIDsOfNames(IHTMLDocument3 *iface, REFIID riid,
153 LPOLESTR *rgszNames, UINT cNames,
154 LCID lcid, DISPID *rgDispId)
155 {
156 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
157 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
158 rgDispId);
159 }
160
161 static HRESULT WINAPI HTMLDocument3_Invoke(IHTMLDocument3 *iface, DISPID dispIdMember,
162 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
163 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
164 {
165 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
166 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
167 pDispParams, pVarResult, pExcepInfo, puArgErr);
168 }
169
170 static HRESULT WINAPI HTMLDocument3_releaseCapture(IHTMLDocument3 *iface)
171 {
172 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
173 FIXME("(%p)\n", This);
174 return E_NOTIMPL;
175 }
176
177 static HRESULT WINAPI HTMLDocument3_recalc(IHTMLDocument3 *iface, VARIANT_BOOL fForce)
178 {
179 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
180 FIXME("(%p)->(%x)\n", This, fForce);
181 return E_NOTIMPL;
182 }
183
184 static HRESULT WINAPI HTMLDocument3_createTextNode(IHTMLDocument3 *iface, BSTR text,
185 IHTMLDOMNode **newTextNode)
186 {
187 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
188 nsIDOMText *nstext;
189 HTMLDOMNode *node;
190 nsAString text_str;
191 nsresult nsres;
192 HRESULT hres;
193
194 TRACE("(%p)->(%s %p)\n", This, debugstr_w(text), newTextNode);
195
196 if(!This->doc_node->nsdoc) {
197 WARN("NULL nsdoc\n");
198 return E_UNEXPECTED;
199 }
200
201 nsAString_InitDepend(&text_str, text);
202 nsres = nsIDOMHTMLDocument_CreateTextNode(This->doc_node->nsdoc, &text_str, &nstext);
203 nsAString_Finish(&text_str);
204 if(NS_FAILED(nsres)) {
205 ERR("CreateTextNode failed: %08x\n", nsres);
206 return E_FAIL;
207 }
208
209 hres = HTMLDOMTextNode_Create(This->doc_node, (nsIDOMNode*)nstext, &node);
210 nsIDOMText_Release(nstext);
211 if(FAILED(hres))
212 return hres;
213
214 *newTextNode = &node->IHTMLDOMNode_iface;
215 return S_OK;
216 }
217
218 static HRESULT WINAPI HTMLDocument3_get_documentElement(IHTMLDocument3 *iface, IHTMLElement **p)
219 {
220 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
221 nsIDOMElement *nselem = NULL;
222 HTMLDOMNode *node;
223 nsresult nsres;
224 HRESULT hres;
225
226 TRACE("(%p)->(%p)\n", This, p);
227
228 if(This->window->readystate == READYSTATE_UNINITIALIZED) {
229 *p = NULL;
230 return S_OK;
231 }
232
233 if(!This->doc_node->nsdoc) {
234 WARN("NULL nsdoc\n");
235 return E_UNEXPECTED;
236 }
237
238 nsres = nsIDOMHTMLDocument_GetDocumentElement(This->doc_node->nsdoc, &nselem);
239 if(NS_FAILED(nsres)) {
240 ERR("GetDocumentElement failed: %08x\n", nsres);
241 return E_FAIL;
242 }
243
244 if(!nselem) {
245 *p = NULL;
246 return S_OK;
247 }
248
249 hres = get_node(This->doc_node, (nsIDOMNode *)nselem, TRUE, &node);
250 nsIDOMElement_Release(nselem);
251 if(FAILED(hres))
252 return hres;
253
254 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)p);
255 node_release(node);
256 return hres;
257 }
258
259 static HRESULT WINAPI HTMLDocument3_uniqueID(IHTMLDocument3 *iface, BSTR *p)
260 {
261 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
262 FIXME("(%p)->(%p)\n", This, p);
263 return E_NOTIMPL;
264 }
265
266 static HRESULT WINAPI HTMLDocument3_attachEvent(IHTMLDocument3 *iface, BSTR event,
267 IDispatch* pDisp, VARIANT_BOOL *pfResult)
268 {
269 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
270
271 TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(event), pDisp, pfResult);
272
273 return attach_event(&This->doc_node->node.event_target, This->doc_node->node.nsnode, This, event, pDisp, pfResult);
274 }
275
276 static HRESULT WINAPI HTMLDocument3_detachEvent(IHTMLDocument3 *iface, BSTR event,
277 IDispatch *pDisp)
278 {
279 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
280
281 TRACE("(%p)->(%s %p)\n", This, debugstr_w(event), pDisp);
282
283 return detach_event(This->doc_node->node.event_target, This, event, pDisp);
284 }
285
286 static HRESULT WINAPI HTMLDocument3_put_onrowsdelete(IHTMLDocument3 *iface, VARIANT v)
287 {
288 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
289 FIXME("(%p)->()\n", This);
290 return E_NOTIMPL;
291 }
292
293 static HRESULT WINAPI HTMLDocument3_get_onrowsdelete(IHTMLDocument3 *iface, VARIANT *p)
294 {
295 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
296 FIXME("(%p)->(%p)\n", This, p);
297 return E_NOTIMPL;
298 }
299
300 static HRESULT WINAPI HTMLDocument3_put_onrowsinserted(IHTMLDocument3 *iface, VARIANT v)
301 {
302 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
303 FIXME("(%p)->()\n", This);
304 return E_NOTIMPL;
305 }
306
307 static HRESULT WINAPI HTMLDocument3_get_onrowsinserted(IHTMLDocument3 *iface, VARIANT *p)
308 {
309 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
310 FIXME("(%p)->(%p)\n", This, p);
311 return E_NOTIMPL;
312 }
313
314 static HRESULT WINAPI HTMLDocument3_put_oncellchange(IHTMLDocument3 *iface, VARIANT v)
315 {
316 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
317 FIXME("(%p)->()\n", This);
318 return E_NOTIMPL;
319 }
320
321 static HRESULT WINAPI HTMLDocument3_get_oncellchange(IHTMLDocument3 *iface, VARIANT *p)
322 {
323 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
324 FIXME("(%p)->(%p)\n", This, p);
325 return E_NOTIMPL;
326 }
327
328 static HRESULT WINAPI HTMLDocument3_put_ondatasetchanged(IHTMLDocument3 *iface, VARIANT v)
329 {
330 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
331 FIXME("(%p)->()\n", This);
332 return E_NOTIMPL;
333 }
334
335 static HRESULT WINAPI HTMLDocument3_get_ondatasetchanged(IHTMLDocument3 *iface, VARIANT *p)
336 {
337 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
338 FIXME("(%p)->(%p)\n", This, p);
339 return E_NOTIMPL;
340 }
341
342 static HRESULT WINAPI HTMLDocument3_put_ondataavailable(IHTMLDocument3 *iface, VARIANT v)
343 {
344 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
345 FIXME("(%p)->()\n", This);
346 return E_NOTIMPL;
347 }
348
349 static HRESULT WINAPI HTMLDocument3_get_ondataavailable(IHTMLDocument3 *iface, VARIANT *p)
350 {
351 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
352 FIXME("(%p)->(%p)\n", This, p);
353 return E_NOTIMPL;
354 }
355
356 static HRESULT WINAPI HTMLDocument3_put_ondatasetcomplete(IHTMLDocument3 *iface, VARIANT v)
357 {
358 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
359 FIXME("(%p)->()\n", This);
360 return E_NOTIMPL;
361 }
362
363 static HRESULT WINAPI HTMLDocument3_get_ondatasetcomplete(IHTMLDocument3 *iface, VARIANT *p)
364 {
365 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
366 FIXME("(%p)->(%p)\n", This, p);
367 return E_NOTIMPL;
368 }
369
370 static HRESULT WINAPI HTMLDocument3_put_onpropertychange(IHTMLDocument3 *iface, VARIANT v)
371 {
372 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
373 FIXME("(%p)->()\n", This);
374 return E_NOTIMPL;
375 }
376
377 static HRESULT WINAPI HTMLDocument3_get_onpropertychange(IHTMLDocument3 *iface, VARIANT *p)
378 {
379 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
380 FIXME("(%p)->(%p)\n", This, p);
381 return E_NOTIMPL;
382 }
383
384 static HRESULT WINAPI HTMLDocument3_put_dir(IHTMLDocument3 *iface, BSTR v)
385 {
386 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
387 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
388 return E_NOTIMPL;
389 }
390
391 static HRESULT WINAPI HTMLDocument3_get_dir(IHTMLDocument3 *iface, BSTR *p)
392 {
393 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
394 FIXME("(%p)->(%p)\n", This, p);
395 return E_NOTIMPL;
396 }
397
398 static HRESULT WINAPI HTMLDocument3_put_oncontextmenu(IHTMLDocument3 *iface, VARIANT v)
399 {
400 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
401
402 TRACE("(%p)->()\n", This);
403
404 return set_doc_event(This, EVENTID_CONTEXTMENU, &v);
405 }
406
407 static HRESULT WINAPI HTMLDocument3_get_oncontextmenu(IHTMLDocument3 *iface, VARIANT *p)
408 {
409 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
410
411 TRACE("(%p)->(%p)\n", This, p);
412
413 return get_doc_event(This, EVENTID_CONTEXTMENU, p);
414 }
415
416 static HRESULT WINAPI HTMLDocument3_put_onstop(IHTMLDocument3 *iface, VARIANT v)
417 {
418 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
419 FIXME("(%p)->()\n", This);
420 return E_NOTIMPL;
421 }
422
423 static HRESULT WINAPI HTMLDocument3_get_onstop(IHTMLDocument3 *iface, VARIANT *p)
424 {
425 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
426 FIXME("(%p)->(%p)\n", This, p);
427 return E_NOTIMPL;
428 }
429
430 static HRESULT WINAPI HTMLDocument3_createDocumentFragment(IHTMLDocument3 *iface,
431 IHTMLDocument2 **ppNewDoc)
432 {
433 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
434 nsIDOMDocumentFragment *doc_frag;
435 HTMLDocumentNode *docnode;
436 nsresult nsres;
437 HRESULT hres;
438
439 TRACE("(%p)->(%p)\n", This, ppNewDoc);
440
441 if(!This->doc_node->nsdoc) {
442 FIXME("NULL nsdoc\n");
443 return E_NOTIMPL;
444 }
445
446 nsres = nsIDOMHTMLDocument_CreateDocumentFragment(This->doc_node->nsdoc, &doc_frag);
447 if(NS_FAILED(nsres)) {
448 ERR("CreateDocumentFragment failed: %08x\n", nsres);
449 return E_FAIL;
450 }
451
452 hres = create_document_fragment((nsIDOMNode*)doc_frag, This->doc_node, &docnode);
453 nsIDOMDocumentFragment_Release(doc_frag);
454 if(FAILED(hres))
455 return hres;
456
457 *ppNewDoc = &docnode->basedoc.IHTMLDocument2_iface;
458 return S_OK;
459 }
460
461 static HRESULT WINAPI HTMLDocument3_get_parentDocument(IHTMLDocument3 *iface,
462 IHTMLDocument2 **p)
463 {
464 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
465 FIXME("(%p)->(%p)\n", This, p);
466 return E_NOTIMPL;
467 }
468
469 static HRESULT WINAPI HTMLDocument3_put_enableDownload(IHTMLDocument3 *iface,
470 VARIANT_BOOL v)
471 {
472 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
473 FIXME("(%p)->(%x)\n", This, v);
474 return E_NOTIMPL;
475 }
476
477 static HRESULT WINAPI HTMLDocument3_get_enableDownload(IHTMLDocument3 *iface,
478 VARIANT_BOOL *p)
479 {
480 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
481 FIXME("(%p)->(%p)\n", This, p);
482 return E_NOTIMPL;
483 }
484
485 static HRESULT WINAPI HTMLDocument3_put_baseUrl(IHTMLDocument3 *iface, BSTR v)
486 {
487 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
488 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
489 return E_NOTIMPL;
490 }
491
492 static HRESULT WINAPI HTMLDocument3_get_baseUrl(IHTMLDocument3 *iface, BSTR *p)
493 {
494 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
495 FIXME("(%p)->(%p)\n", This, p);
496 return E_NOTIMPL;
497 }
498
499 static HRESULT WINAPI HTMLDocument3_get_childNodes(IHTMLDocument3 *iface, IDispatch **p)
500 {
501 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
502
503 TRACE("(%p)->(%p)\n", This, p);
504
505 return IHTMLDOMNode_get_childNodes(&This->doc_node->node.IHTMLDOMNode_iface, p);
506 }
507
508 static HRESULT WINAPI HTMLDocument3_put_inheritStyleSheets(IHTMLDocument3 *iface,
509 VARIANT_BOOL v)
510 {
511 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
512 FIXME("(%p)->()\n", This);
513 return E_NOTIMPL;
514 }
515
516 static HRESULT WINAPI HTMLDocument3_get_inheritStyleSheets(IHTMLDocument3 *iface,
517 VARIANT_BOOL *p)
518 {
519 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
520 FIXME("(%p)->(%p)\n", This, p);
521 return E_NOTIMPL;
522 }
523
524 static HRESULT WINAPI HTMLDocument3_put_onbeforeeditfocus(IHTMLDocument3 *iface, VARIANT v)
525 {
526 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
527 FIXME("(%p)->()\n", This);
528 return E_NOTIMPL;
529 }
530
531 static HRESULT WINAPI HTMLDocument3_get_onbeforeeditfocus(IHTMLDocument3 *iface, VARIANT *p)
532 {
533 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
534 FIXME("(%p)->(%p)\n", This, p);
535 return E_NOTIMPL;
536 }
537
538 static HRESULT WINAPI HTMLDocument3_getElementsByName(IHTMLDocument3 *iface, BSTR v,
539 IHTMLElementCollection **ppelColl)
540 {
541 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
542 FIXME("(%p)->(%s %p)\n", This, debugstr_w(v), ppelColl);
543 return E_NOTIMPL;
544 }
545
546
547 static HRESULT WINAPI HTMLDocument3_getElementById(IHTMLDocument3 *iface, BSTR v,
548 IHTMLElement **pel)
549 {
550 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
551 HTMLElement *elem;
552 HRESULT hres;
553
554 TRACE("(%p)->(%s %p)\n", This, debugstr_w(v), pel);
555
556 hres = get_doc_elem_by_id(This->doc_node, v, &elem);
557 if(FAILED(hres) || !elem) {
558 *pel = NULL;
559 return hres;
560 }
561
562 *pel = &elem->IHTMLElement_iface;
563 return S_OK;
564 }
565
566
567 static HRESULT WINAPI HTMLDocument3_getElementsByTagName(IHTMLDocument3 *iface, BSTR v,
568 IHTMLElementCollection **pelColl)
569 {
570 HTMLDocument *This = impl_from_IHTMLDocument3(iface);
571 nsIDOMNodeList *nslist;
572 nsAString id_str;
573 nsresult nsres;
574
575 TRACE("(%p)->(%s %p)\n", This, debugstr_w(v), pelColl);
576
577 if(!This->doc_node->nsdoc) {
578 WARN("NULL nsdoc\n");
579 return E_UNEXPECTED;
580 }
581
582 nsAString_InitDepend(&id_str, v);
583 nsres = nsIDOMHTMLDocument_GetElementsByTagName(This->doc_node->nsdoc, &id_str, &nslist);
584 nsAString_Finish(&id_str);
585 if(FAILED(nsres)) {
586 ERR("GetElementByName failed: %08x\n", nsres);
587 return E_FAIL;
588 }
589
590 *pelColl = create_collection_from_nodelist(This->doc_node, nslist);
591 nsIDOMNodeList_Release(nslist);
592
593 return S_OK;
594 }
595
596 static const IHTMLDocument3Vtbl HTMLDocument3Vtbl = {
597 HTMLDocument3_QueryInterface,
598 HTMLDocument3_AddRef,
599 HTMLDocument3_Release,
600 HTMLDocument3_GetTypeInfoCount,
601 HTMLDocument3_GetTypeInfo,
602 HTMLDocument3_GetIDsOfNames,
603 HTMLDocument3_Invoke,
604 HTMLDocument3_releaseCapture,
605 HTMLDocument3_recalc,
606 HTMLDocument3_createTextNode,
607 HTMLDocument3_get_documentElement,
608 HTMLDocument3_uniqueID,
609 HTMLDocument3_attachEvent,
610 HTMLDocument3_detachEvent,
611 HTMLDocument3_put_onrowsdelete,
612 HTMLDocument3_get_onrowsdelete,
613 HTMLDocument3_put_onrowsinserted,
614 HTMLDocument3_get_onrowsinserted,
615 HTMLDocument3_put_oncellchange,
616 HTMLDocument3_get_oncellchange,
617 HTMLDocument3_put_ondatasetchanged,
618 HTMLDocument3_get_ondatasetchanged,
619 HTMLDocument3_put_ondataavailable,
620 HTMLDocument3_get_ondataavailable,
621 HTMLDocument3_put_ondatasetcomplete,
622 HTMLDocument3_get_ondatasetcomplete,
623 HTMLDocument3_put_onpropertychange,
624 HTMLDocument3_get_onpropertychange,
625 HTMLDocument3_put_dir,
626 HTMLDocument3_get_dir,
627 HTMLDocument3_put_oncontextmenu,
628 HTMLDocument3_get_oncontextmenu,
629 HTMLDocument3_put_onstop,
630 HTMLDocument3_get_onstop,
631 HTMLDocument3_createDocumentFragment,
632 HTMLDocument3_get_parentDocument,
633 HTMLDocument3_put_enableDownload,
634 HTMLDocument3_get_enableDownload,
635 HTMLDocument3_put_baseUrl,
636 HTMLDocument3_get_baseUrl,
637 HTMLDocument3_get_childNodes,
638 HTMLDocument3_put_inheritStyleSheets,
639 HTMLDocument3_get_inheritStyleSheets,
640 HTMLDocument3_put_onbeforeeditfocus,
641 HTMLDocument3_get_onbeforeeditfocus,
642 HTMLDocument3_getElementsByName,
643 HTMLDocument3_getElementById,
644 HTMLDocument3_getElementsByTagName
645 };
646
647 static inline HTMLDocument *impl_from_IHTMLDocument4(IHTMLDocument4 *iface)
648 {
649 return CONTAINING_RECORD(iface, HTMLDocument, IHTMLDocument4_iface);
650 }
651
652 static HRESULT WINAPI HTMLDocument4_QueryInterface(IHTMLDocument4 *iface,
653 REFIID riid, void **ppv)
654 {
655 HTMLDocument *This = impl_from_IHTMLDocument4(iface);
656 return htmldoc_query_interface(This, riid, ppv);
657 }
658
659 static ULONG WINAPI HTMLDocument4_AddRef(IHTMLDocument4 *iface)
660 {
661 HTMLDocument *This = impl_from_IHTMLDocument4(iface);
662 return htmldoc_addref(This);
663 }
664
665 static ULONG WINAPI HTMLDocument4_Release(IHTMLDocument4 *iface)
666 {
667 HTMLDocument *This = impl_from_IHTMLDocument4(iface);
668 return htmldoc_release(This);
669 }
670
671 static HRESULT WINAPI HTMLDocument4_GetTypeInfoCount(IHTMLDocument4 *iface, UINT *pctinfo)
672 {
673 HTMLDocument *This = impl_from_IHTMLDocument4(iface);
674 return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
675 }
676
677 static HRESULT WINAPI HTMLDocument4_GetTypeInfo(IHTMLDocument4 *iface, UINT iTInfo,
678 LCID lcid, ITypeInfo **ppTInfo)
679 {
680 HTMLDocument *This = impl_from_IHTMLDocument4(iface);
681 return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
682 }
683
684 static HRESULT WINAPI HTMLDocument4_GetIDsOfNames(IHTMLDocument4 *iface, REFIID riid,
685 LPOLESTR *rgszNames, UINT cNames,
686 LCID lcid, DISPID *rgDispId)
687 {
688 HTMLDocument *This = impl_from_IHTMLDocument4(iface);
689 return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
690 rgDispId);
691 }
692
693 static HRESULT WINAPI HTMLDocument4_Invoke(IHTMLDocument4 *iface, DISPID dispIdMember,
694 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
695 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
696 {
697 HTMLDocument *This = impl_from_IHTMLDocument4(iface);
698 return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
699 pDispParams, pVarResult, pExcepInfo, puArgErr);
700 }
701
702 static HRESULT WINAPI HTMLDocument4_focus(IHTMLDocument4 *iface)
703 {
704 HTMLDocument *This = impl_from_IHTMLDocument4(iface);
705 nsIDOMHTMLElement *nsbody;
706 nsresult nsres;
707
708 TRACE("(%p)->()\n", This);
709
710 nsres = nsIDOMHTMLDocument_GetBody(This->doc_node->nsdoc, &nsbody);
711 if(NS_FAILED(nsres) || !nsbody) {
712 ERR("GetBody failed: %08x\n", nsres);
713 return E_FAIL;
714 }
715
716 nsres = nsIDOMHTMLElement_Focus(nsbody);
717 nsIDOMHTMLElement_Release(nsbody);
718 if(NS_FAILED(nsres)) {
719 ERR("Focus failed: %08x\n", nsres);
720 return E_FAIL;
721 }
722
723 return S_OK;
724 }
725
726 static HRESULT WINAPI HTMLDocument4_hasFocus(IHTMLDocument4 *iface, VARIANT_BOOL *pfFocus)
727 {
728 HTMLDocument *This = impl_from_IHTMLDocument4(iface);
729 FIXME("(%p)->(%p)\n", This, pfFocus);
730 return E_NOTIMPL;
731 }
732
733 static HRESULT WINAPI HTMLDocument4_put_onselectionchange(IHTMLDocument4 *iface, VARIANT v)
734 {
735 HTMLDocument *This = impl_from_IHTMLDocument4(iface);
736 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
737 return E_NOTIMPL;
738 }
739
740 static HRESULT WINAPI HTMLDocument4_get_onselectionchange(IHTMLDocument4 *iface, VARIANT *p)
741 {
742 HTMLDocument *This = impl_from_IHTMLDocument4(iface);
743 FIXME("(%p)->(%p)\n", This, p);
744 return E_NOTIMPL;
745 }
746
747 static HRESULT WINAPI HTMLDocument4_get_namespace(IHTMLDocument4 *iface, IDispatch **p)
748 {
749 HTMLDocument *This = impl_from_IHTMLDocument4(iface);
750 FIXME("(%p)->(%p)\n", This, p);
751 return E_NOTIMPL;
752 }
753
754 static HRESULT WINAPI HTMLDocument4_createDocumentFromUrl(IHTMLDocument4 *iface, BSTR bstrUrl,
755 BSTR bstrOptions, IHTMLDocument2 **newDoc)
756 {
757 HTMLDocument *This = impl_from_IHTMLDocument4(iface);
758 FIXME("(%p)->(%s %s %p)\n", This, debugstr_w(bstrUrl), debugstr_w(bstrOptions), newDoc);
759 return E_NOTIMPL;
760 }
761
762 static HRESULT WINAPI HTMLDocument4_put_media(IHTMLDocument4 *iface, BSTR v)
763 {
764 HTMLDocument *This = impl_from_IHTMLDocument4(iface);
765 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
766 return E_NOTIMPL;
767 }
768
769 static HRESULT WINAPI HTMLDocument4_get_media(IHTMLDocument4 *iface, BSTR *p)
770 {
771 HTMLDocument *This = impl_from_IHTMLDocument4(iface);
772 FIXME("(%p)->(%p)\n", This, p);
773 return E_NOTIMPL;
774 }
775
776 static HRESULT WINAPI HTMLDocument4_createEventObject(IHTMLDocument4 *iface,
777 VARIANT *pvarEventObject, IHTMLEventObj **ppEventObj)
778 {
779 HTMLDocument *This = impl_from_IHTMLDocument4(iface);
780
781 TRACE("(%p)->(%s %p)\n", This, debugstr_variant(pvarEventObject), ppEventObj);
782
783 if(pvarEventObject && V_VT(pvarEventObject) != VT_ERROR && V_VT(pvarEventObject) != VT_EMPTY) {
784 FIXME("unsupported pvarEventObject %s\n", debugstr_variant(pvarEventObject));
785 return E_NOTIMPL;
786 }
787
788 return create_event_obj(ppEventObj);
789 }
790
791 static HRESULT WINAPI HTMLDocument4_fireEvent(IHTMLDocument4 *iface, BSTR bstrEventName,
792 VARIANT *pvarEventObject, VARIANT_BOOL *pfCanceled)
793 {
794 HTMLDocument *This = impl_from_IHTMLDocument4(iface);
795
796 TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(bstrEventName), pvarEventObject, pfCanceled);
797
798 return dispatch_event(&This->doc_node->node, bstrEventName, pvarEventObject, pfCanceled);
799 }
800
801 static HRESULT WINAPI HTMLDocument4_createRenderStyle(IHTMLDocument4 *iface, BSTR v,
802 IHTMLRenderStyle **ppIHTMLRenderStyle)
803 {
804 HTMLDocument *This = impl_from_IHTMLDocument4(iface);
805 FIXME("(%p)->(%s %p)\n", This, debugstr_w(v), ppIHTMLRenderStyle);
806 return E_NOTIMPL;
807 }
808
809 static HRESULT WINAPI HTMLDocument4_put_oncontrolselect(IHTMLDocument4 *iface, VARIANT v)
810 {
811 HTMLDocument *This = impl_from_IHTMLDocument4(iface);
812 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
813 return E_NOTIMPL;
814 }
815
816 static HRESULT WINAPI HTMLDocument4_get_oncontrolselect(IHTMLDocument4 *iface, VARIANT *p)
817 {
818 HTMLDocument *This = impl_from_IHTMLDocument4(iface);
819 FIXME("(%p)->(%p)\n", This, p);
820 return E_NOTIMPL;
821 }
822
823 static HRESULT WINAPI HTMLDocument4_get_URLEncoded(IHTMLDocument4 *iface, BSTR *p)
824 {
825 HTMLDocument *This = impl_from_IHTMLDocument4(iface);
826 FIXME("(%p)->(%p)\n", This, p);
827 return E_NOTIMPL;
828 }
829
830 static const IHTMLDocument4Vtbl HTMLDocument4Vtbl = {
831 HTMLDocument4_QueryInterface,
832 HTMLDocument4_AddRef,
833 HTMLDocument4_Release,
834 HTMLDocument4_GetTypeInfoCount,
835 HTMLDocument4_GetTypeInfo,
836 HTMLDocument4_GetIDsOfNames,
837 HTMLDocument4_Invoke,
838 HTMLDocument4_focus,
839 HTMLDocument4_hasFocus,
840 HTMLDocument4_put_onselectionchange,
841 HTMLDocument4_get_onselectionchange,
842 HTMLDocument4_get_namespace,
843 HTMLDocument4_createDocumentFromUrl,
844 HTMLDocument4_put_media,
845 HTMLDocument4_get_media,
846 HTMLDocument4_createEventObject,
847 HTMLDocument4_fireEvent,
848 HTMLDocument4_createRenderStyle,
849 HTMLDocument4_put_oncontrolselect,
850 HTMLDocument4_get_oncontrolselect,
851 HTMLDocument4_get_URLEncoded
852 };
853
854 void HTMLDocument_HTMLDocument3_Init(HTMLDocument *This)
855 {
856 This->IHTMLDocument3_iface.lpVtbl = &HTMLDocument3Vtbl;
857 This->IHTMLDocument4_iface.lpVtbl = &HTMLDocument4Vtbl;
858 }