mshtml: Better timer handling.
[wine/wine-jacek.git] / dlls / mshtml / htmlnode.c
blob2f37c5499c5a3673773ee2e2d46c4952e3b551c4
1 /*
2 * Copyright 2006 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "ole2.h"
28 #include "wine/debug.h"
30 #include "mshtml_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
34 typedef struct {
35 DispatchEx dispex;
36 const IHTMLDOMChildrenCollectionVtbl *lpIHTMLDOMChildrenCollectionVtbl;
38 LONG ref;
40 /* FIXME: implement weak reference */
41 HTMLDocument *doc;
43 nsIDOMNodeList *nslist;
44 } HTMLDOMChildrenCollection;
46 #define HTMLCHILDCOL(x) ((IHTMLDOMChildrenCollection*) &(x)->lpIHTMLDOMChildrenCollectionVtbl)
48 #define HTMLCHILDCOL_THIS(iface) DEFINE_THIS(HTMLDOMChildrenCollection, IHTMLDOMChildrenCollection, iface)
50 static HRESULT WINAPI HTMLDOMChildrenCollection_QueryInterface(IHTMLDOMChildrenCollection *iface, REFIID riid, void **ppv)
52 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
54 *ppv = NULL;
56 if(IsEqualGUID(&IID_IUnknown, riid)) {
57 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
58 *ppv = HTMLCHILDCOL(This);
59 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
60 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
61 *ppv = HTMLCHILDCOL(This);
62 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
63 TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
64 *ppv = DISPATCHEX(&This->dispex);
65 }else if(IsEqualGUID(&IID_IHTMLDOMChildrenCollection, riid)) {
66 TRACE("(%p)->(IID_IHTMLDOMChildrenCollection %p)\n", This, ppv);
67 *ppv = HTMLCHILDCOL(This);
70 if(*ppv) {
71 IUnknown_AddRef((IUnknown*)*ppv);
72 return S_OK;
75 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
76 return E_NOINTERFACE;
79 static ULONG WINAPI HTMLDOMChildrenCollection_AddRef(IHTMLDOMChildrenCollection *iface)
81 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
82 LONG ref = InterlockedIncrement(&This->ref);
84 TRACE("(%p) ref=%d\n", This, ref);
86 return ref;
89 static ULONG WINAPI HTMLDOMChildrenCollection_Release(IHTMLDOMChildrenCollection *iface)
91 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
92 LONG ref = InterlockedDecrement(&This->ref);
94 TRACE("(%p) ref=%d\n", This, ref);
96 if(!ref) {
97 nsIDOMNodeList_Release(This->nslist);
98 heap_free(This);
101 return ref;
104 static HRESULT WINAPI HTMLDOMChildrenCollection_GetTypeInfoCount(IHTMLDOMChildrenCollection *iface, UINT *pctinfo)
106 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
107 FIXME("(%p)->(%p)\n", This, pctinfo);
108 return E_NOTIMPL;
111 static HRESULT WINAPI HTMLDOMChildrenCollection_GetTypeInfo(IHTMLDOMChildrenCollection *iface, UINT iTInfo,
112 LCID lcid, ITypeInfo **ppTInfo)
114 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
115 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
116 return E_NOTIMPL;
119 static HRESULT WINAPI HTMLDOMChildrenCollection_GetIDsOfNames(IHTMLDOMChildrenCollection *iface, REFIID riid,
120 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
122 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
123 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
124 lcid, rgDispId);
125 return E_NOTIMPL;
128 static HRESULT WINAPI HTMLDOMChildrenCollection_Invoke(IHTMLDOMChildrenCollection *iface, DISPID dispIdMember,
129 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
130 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
132 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
133 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
134 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
135 return E_NOTIMPL;
138 static HRESULT WINAPI HTMLDOMChildrenCollection_get_length(IHTMLDOMChildrenCollection *iface, long *p)
140 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
141 PRUint32 length=0;
143 TRACE("(%p)->(%p)\n", This, p);
145 nsIDOMNodeList_GetLength(This->nslist, &length);
146 *p = length;
147 return S_OK;
150 static HRESULT WINAPI HTMLDOMChildrenCollection__newEnum(IHTMLDOMChildrenCollection *iface, IUnknown **p)
152 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
153 FIXME("(%p)->(%p)\n", This, p);
154 return E_NOTIMPL;
157 static HRESULT WINAPI HTMLDOMChildrenCollection_item(IHTMLDOMChildrenCollection *iface, long index, IDispatch **ppItem)
159 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
160 nsIDOMNode *nsnode = NULL;
161 PRUint32 length=0;
162 nsresult nsres;
164 TRACE("(%p)->(%ld %p)\n", This, index, ppItem);
166 nsIDOMNodeList_GetLength(This->nslist, &length);
167 if(index < 0 || index > length)
168 return E_INVALIDARG;
170 nsres = nsIDOMNodeList_Item(This->nslist, index, &nsnode);
171 if(NS_FAILED(nsres) || !nsnode) {
172 ERR("Item failed: %08x\n", nsres);
173 return E_FAIL;
176 *ppItem = (IDispatch*)get_node(This->doc, nsnode, TRUE);
177 IDispatch_AddRef(*ppItem);
178 return S_OK;
181 #undef HTMLCHILDCOL_THIS
183 static const IHTMLDOMChildrenCollectionVtbl HTMLDOMChildrenCollectionVtbl = {
184 HTMLDOMChildrenCollection_QueryInterface,
185 HTMLDOMChildrenCollection_AddRef,
186 HTMLDOMChildrenCollection_Release,
187 HTMLDOMChildrenCollection_GetTypeInfoCount,
188 HTMLDOMChildrenCollection_GetTypeInfo,
189 HTMLDOMChildrenCollection_GetIDsOfNames,
190 HTMLDOMChildrenCollection_Invoke,
191 HTMLDOMChildrenCollection_get_length,
192 HTMLDOMChildrenCollection__newEnum,
193 HTMLDOMChildrenCollection_item
196 static const tid_t HTMLDOMChildrenCollection_iface_tids[] = {
197 IHTMLDOMChildrenCollection_tid,
200 static dispex_static_data_t HTMLDOMChildrenCollection_dispex = {
201 NULL,
202 DispDOMChildrenCollection_tid,
203 NULL,
204 HTMLDOMChildrenCollection_iface_tids
207 static IHTMLDOMChildrenCollection *create_child_collection(HTMLDocument *doc, nsIDOMNodeList *nslist)
209 HTMLDOMChildrenCollection *ret;
211 ret = heap_alloc_zero(sizeof(*ret));
212 ret->lpIHTMLDOMChildrenCollectionVtbl = &HTMLDOMChildrenCollectionVtbl;
213 ret->ref = 1;
215 nsIDOMNodeList_AddRef(nslist);
216 ret->nslist = nslist;
217 ret->doc = doc;
219 init_dispex(&ret->dispex, (IUnknown*)HTMLCHILDCOL(ret), &HTMLDOMChildrenCollection_dispex);
221 return HTMLCHILDCOL(ret);
224 #define HTMLDOMNODE_THIS(iface) DEFINE_THIS(HTMLDOMNode, HTMLDOMNode, iface)
226 static HRESULT WINAPI HTMLDOMNode_QueryInterface(IHTMLDOMNode *iface,
227 REFIID riid, void **ppv)
229 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
231 return This->vtbl->qi(This, riid, ppv);
234 static ULONG WINAPI HTMLDOMNode_AddRef(IHTMLDOMNode *iface)
236 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
237 LONG ref = InterlockedIncrement(&This->ref);
239 TRACE("(%p) ref=%d\n", This, ref);
241 return ref;
244 static ULONG WINAPI HTMLDOMNode_Release(IHTMLDOMNode *iface)
246 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
247 LONG ref = InterlockedDecrement(&This->ref);
249 TRACE("(%p) ref=%d\n", This, ref);
251 if(!ref) {
252 This->vtbl->destructor(This);
253 heap_free(This);
256 return ref;
259 static HRESULT WINAPI HTMLDOMNode_GetTypeInfoCount(IHTMLDOMNode *iface, UINT *pctinfo)
261 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
262 FIXME("(%p)->(%p)\n", This, pctinfo);
263 return E_NOTIMPL;
266 static HRESULT WINAPI HTMLDOMNode_GetTypeInfo(IHTMLDOMNode *iface, UINT iTInfo,
267 LCID lcid, ITypeInfo **ppTInfo)
269 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
270 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
271 return E_NOTIMPL;
274 static HRESULT WINAPI HTMLDOMNode_GetIDsOfNames(IHTMLDOMNode *iface, REFIID riid,
275 LPOLESTR *rgszNames, UINT cNames,
276 LCID lcid, DISPID *rgDispId)
278 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
279 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
280 lcid, rgDispId);
281 return E_NOTIMPL;
284 static HRESULT WINAPI HTMLDOMNode_Invoke(IHTMLDOMNode *iface, DISPID dispIdMember,
285 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
286 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
288 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
289 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
290 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
291 return E_NOTIMPL;
294 static HRESULT WINAPI HTMLDOMNode_get_nodeType(IHTMLDOMNode *iface, long *p)
296 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
297 PRUint16 type = -1;
299 TRACE("(%p)->(%p)\n", This, p);
301 nsIDOMNode_GetNodeType(This->nsnode, &type);
303 switch(type) {
304 case ELEMENT_NODE:
305 *p = 1;
306 break;
307 case TEXT_NODE:
308 *p = 3;
309 break;
310 case COMMENT_NODE:
311 *p = 8;
312 break;
313 default:
315 * FIXME:
316 * According to MSDN only ELEMENT_NODE and TEXT_NODE are supported.
317 * It needs more tests.
319 FIXME("type %u\n", type);
320 *p = 0;
323 return S_OK;
326 static HRESULT WINAPI HTMLDOMNode_get_parentNode(IHTMLDOMNode *iface, IHTMLDOMNode **p)
328 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
329 FIXME("(%p)->(%p)\n", This, p);
330 return E_NOTIMPL;
333 static HRESULT WINAPI HTMLDOMNode_hasChildNodes(IHTMLDOMNode *iface, VARIANT_BOOL *fChildren)
335 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
336 FIXME("(%p)->(%p)\n", This, fChildren);
337 return E_NOTIMPL;
340 static HRESULT WINAPI HTMLDOMNode_get_childNodes(IHTMLDOMNode *iface, IDispatch **p)
342 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
343 nsIDOMNodeList *nslist;
344 nsresult nsres;
346 TRACE("(%p)->(%p)\n", This, p);
348 nsres = nsIDOMNode_GetChildNodes(This->nsnode, &nslist);
349 if(NS_FAILED(nsres)) {
350 ERR("GetChildNodes failed: %08x\n", nsres);
351 return E_FAIL;
354 *p = (IDispatch*)create_child_collection(This->doc, nslist);
355 nsIDOMNodeList_Release(nslist);
357 return S_OK;
360 static HRESULT WINAPI HTMLDOMNode_get_attributes(IHTMLDOMNode *iface, IDispatch **p)
362 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
363 FIXME("(%p)->(%p)\n", This, p);
364 return E_NOTIMPL;
367 static HRESULT WINAPI HTMLDOMNode_insertBefore(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
368 VARIANT refChild, IHTMLDOMNode **node)
370 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
371 FIXME("(%p)->(%p v %p)\n", This, newChild, node);
372 return E_NOTIMPL;
375 static HRESULT WINAPI HTMLDOMNode_removeChild(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
376 IHTMLDOMNode **node)
378 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
379 FIXME("(%p)->(%p %p)\n", This, newChild, node);
380 return E_NOTIMPL;
383 static HRESULT WINAPI HTMLDOMNode_replaceChild(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
384 IHTMLDOMNode *oldChild, IHTMLDOMNode **node)
386 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
387 FIXME("(%p)->(%p %p %p)\n", This, newChild, oldChild, node);
388 return E_NOTIMPL;
391 static HRESULT WINAPI HTMLDOMNode_cloneNode(IHTMLDOMNode *iface, VARIANT_BOOL fDeep,
392 IHTMLDOMNode **clonedNode)
394 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
395 FIXME("(%p)->(%x %p)\n", This, fDeep, clonedNode);
396 return E_NOTIMPL;
399 static HRESULT WINAPI HTMLDOMNode_removeNode(IHTMLDOMNode *iface, VARIANT_BOOL fDeep,
400 IHTMLDOMNode **removed)
402 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
403 FIXME("(%p)->(%x %p)\n", This, fDeep, removed);
404 return E_NOTIMPL;
407 static HRESULT WINAPI HTMLDOMNode_swapNode(IHTMLDOMNode *iface, IHTMLDOMNode *otherNode,
408 IHTMLDOMNode **swappedNode)
410 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
411 FIXME("(%p)->(%p %p)\n", This, otherNode, swappedNode);
412 return E_NOTIMPL;
415 static HRESULT WINAPI HTMLDOMNode_replaceNode(IHTMLDOMNode *iface, IHTMLDOMNode *replacement,
416 IHTMLDOMNode **replaced)
418 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
419 FIXME("(%p)->(%p %p)\n", This, replacement, replaced);
420 return E_NOTIMPL;
423 static HRESULT WINAPI HTMLDOMNode_appendChild(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
424 IHTMLDOMNode **node)
426 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
427 FIXME("(%p)->(%p %p)\n", This, newChild, node);
428 return E_NOTIMPL;
431 static HRESULT WINAPI HTMLDOMNode_get_nodeName(IHTMLDOMNode *iface, BSTR *p)
433 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
435 TRACE("(%p)->(%p)\n", This, p);
437 *p = NULL;
439 if(This->nsnode) {
440 nsAString name_str;
441 const PRUnichar *name;
442 nsresult nsres;
444 nsAString_Init(&name_str, NULL);
445 nsres = nsIDOMNode_GetNodeName(This->nsnode, &name_str);
447 if(NS_SUCCEEDED(nsres)) {
448 nsAString_GetData(&name_str, &name);
449 *p = SysAllocString(name);
450 }else {
451 ERR("GetNodeName failed: %08x\n", nsres);
454 nsAString_Finish(&name_str);
457 return S_OK;
460 static HRESULT WINAPI HTMLDOMNode_put_nodeValue(IHTMLDOMNode *iface, VARIANT v)
462 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
464 TRACE("(%p)->()\n", This);
466 switch(V_VT(&v)) {
467 case VT_BSTR: {
468 nsAString val_str;
470 TRACE("bstr %s\n", debugstr_w(V_BSTR(&v)));
472 nsAString_Init(&val_str, V_BSTR(&v));
473 nsIDOMNode_SetNodeValue(This->nsnode, &val_str);
474 nsAString_Finish(&val_str);
476 return S_OK;
479 default:
480 FIXME("unsupported vt %d\n", V_VT(&v));
483 return E_NOTIMPL;
486 static HRESULT WINAPI HTMLDOMNode_get_nodeValue(IHTMLDOMNode *iface, VARIANT *p)
488 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
489 const PRUnichar *val;
490 nsAString val_str;
492 TRACE("(%p)->(%p)\n", This, p);
494 nsAString_Init(&val_str, NULL);
495 nsIDOMNode_GetNodeValue(This->nsnode, &val_str);
496 nsAString_GetData(&val_str, &val);
498 if(*val) {
499 V_VT(p) = VT_BSTR;
500 V_BSTR(p) = SysAllocString(val);
501 }else {
502 V_VT(p) = VT_NULL;
505 nsAString_Finish(&val_str);
507 return S_OK;
510 static HRESULT WINAPI HTMLDOMNode_get_firstChild(IHTMLDOMNode *iface, IHTMLDOMNode **p)
512 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
513 nsIDOMNode *nschild = NULL;
515 TRACE("(%p)->(%p)\n", This, p);
517 nsIDOMNode_GetFirstChild(This->nsnode, &nschild);
518 if(nschild) {
519 *p = HTMLDOMNODE(get_node(This->doc, nschild, TRUE));
520 IHTMLDOMNode_AddRef(*p);
521 }else {
522 *p = NULL;
525 return S_OK;
528 static HRESULT WINAPI HTMLDOMNode_get_lastChild(IHTMLDOMNode *iface, IHTMLDOMNode **p)
530 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
531 FIXME("(%p)->(%p)\n", This, p);
532 return E_NOTIMPL;
535 static HRESULT WINAPI HTMLDOMNode_get_previousSibling(IHTMLDOMNode *iface, IHTMLDOMNode **p)
537 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
538 FIXME("(%p)->(%p)\n", This, p);
539 return E_NOTIMPL;
542 static HRESULT WINAPI HTMLDOMNode_get_nextSibling(IHTMLDOMNode *iface, IHTMLDOMNode **p)
544 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
545 FIXME("(%p)->(%p)\n", This, p);
546 return E_NOTIMPL;
549 #undef HTMLDOMNODE_THIS
551 static const IHTMLDOMNodeVtbl HTMLDOMNodeVtbl = {
552 HTMLDOMNode_QueryInterface,
553 HTMLDOMNode_AddRef,
554 HTMLDOMNode_Release,
555 HTMLDOMNode_GetTypeInfoCount,
556 HTMLDOMNode_GetTypeInfo,
557 HTMLDOMNode_GetIDsOfNames,
558 HTMLDOMNode_Invoke,
559 HTMLDOMNode_get_nodeType,
560 HTMLDOMNode_get_parentNode,
561 HTMLDOMNode_hasChildNodes,
562 HTMLDOMNode_get_childNodes,
563 HTMLDOMNode_get_attributes,
564 HTMLDOMNode_insertBefore,
565 HTMLDOMNode_removeChild,
566 HTMLDOMNode_replaceChild,
567 HTMLDOMNode_cloneNode,
568 HTMLDOMNode_removeNode,
569 HTMLDOMNode_swapNode,
570 HTMLDOMNode_replaceNode,
571 HTMLDOMNode_appendChild,
572 HTMLDOMNode_get_nodeName,
573 HTMLDOMNode_put_nodeValue,
574 HTMLDOMNode_get_nodeValue,
575 HTMLDOMNode_get_firstChild,
576 HTMLDOMNode_get_lastChild,
577 HTMLDOMNode_get_previousSibling,
578 HTMLDOMNode_get_nextSibling
581 #define HTMLDOMNODE2_THIS(iface) DEFINE_THIS(HTMLDOMNode, HTMLDOMNode2, iface)
583 static HRESULT WINAPI HTMLDOMNode2_QueryInterface(IHTMLDOMNode2 *iface,
584 REFIID riid, void **ppv)
586 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
588 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(This), riid, ppv);
591 static ULONG WINAPI HTMLDOMNode2_AddRef(IHTMLDOMNode2 *iface)
593 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
595 return IHTMLDOMNode_AddRef(HTMLDOMNODE(This));
598 static ULONG WINAPI HTMLDOMNode2_Release(IHTMLDOMNode2 *iface)
600 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
602 return IHTMLDOMNode_Release(HTMLDOMNODE(This));
605 static HRESULT WINAPI HTMLDOMNode2_GetTypeInfoCount(IHTMLDOMNode2 *iface, UINT *pctinfo)
607 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
608 FIXME("(%p)->(%p)\n", This, pctinfo);
609 return E_NOTIMPL;
612 static HRESULT WINAPI HTMLDOMNode2_GetTypeInfo(IHTMLDOMNode2 *iface, UINT iTInfo,
613 LCID lcid, ITypeInfo **ppTInfo)
615 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
616 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
617 return E_NOTIMPL;
620 static HRESULT WINAPI HTMLDOMNode2_GetIDsOfNames(IHTMLDOMNode2 *iface, REFIID riid,
621 LPOLESTR *rgszNames, UINT cNames,
622 LCID lcid, DISPID *rgDispId)
624 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
625 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
626 lcid, rgDispId);
627 return E_NOTIMPL;
630 static HRESULT WINAPI HTMLDOMNode2_Invoke(IHTMLDOMNode2 *iface, DISPID dispIdMember,
631 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
632 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
634 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
635 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
636 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
637 return E_NOTIMPL;
640 static HRESULT WINAPI HTMLDOMNode2_get_ownerDocument(IHTMLDOMNode2 *iface, IDispatch **p)
642 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
643 FIXME("(%p)->(%p)\n", This, p);
644 return E_NOTIMPL;
647 #undef HTMLDOMNODE2_THIS
649 static const IHTMLDOMNode2Vtbl HTMLDOMNode2Vtbl = {
650 HTMLDOMNode2_QueryInterface,
651 HTMLDOMNode2_AddRef,
652 HTMLDOMNode2_Release,
653 HTMLDOMNode2_GetTypeInfoCount,
654 HTMLDOMNode2_GetTypeInfo,
655 HTMLDOMNode2_GetIDsOfNames,
656 HTMLDOMNode2_Invoke,
657 HTMLDOMNode2_get_ownerDocument
660 HRESULT HTMLDOMNode_QI(HTMLDOMNode *This, REFIID riid, void **ppv)
662 *ppv = NULL;
664 if(IsEqualGUID(&IID_IUnknown, riid)) {
665 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
666 *ppv = HTMLDOMNODE(This);
667 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
668 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
669 *ppv = HTMLDOMNODE(This);
670 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
671 if(This->dispex.data) {
672 TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
673 *ppv = DISPATCHEX(&This->dispex);
674 }else {
675 FIXME("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
676 return E_NOINTERFACE;
678 }else if(IsEqualGUID(&IID_IHTMLDOMNode, riid)) {
679 TRACE("(%p)->(IID_IHTMLDOMNode %p)\n", This, ppv);
680 *ppv = HTMLDOMNODE(This);
681 }else if(IsEqualGUID(&IID_IHTMLDOMNode2, riid)) {
682 TRACE("(%p)->(IID_IHTMLDOMNode2 %p)\n", This, ppv);
683 *ppv = HTMLDOMNODE2(This);
686 if(*ppv) {
687 IUnknown_AddRef((IUnknown*)*ppv);
688 return S_OK;
691 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
692 return E_NOINTERFACE;
695 void HTMLDOMNode_destructor(HTMLDOMNode *This)
697 if(This->nsnode)
698 nsIDOMNode_Release(This->nsnode);
699 if(This->event_target)
700 release_event_target(This->event_target);
703 static const NodeImplVtbl HTMLDOMNodeImplVtbl = {
704 HTMLDOMNode_QI,
705 HTMLDOMNode_destructor
708 static HTMLDOMNode *create_node(HTMLDocument *doc, nsIDOMNode *nsnode)
710 HTMLDOMNode *ret;
711 PRUint16 node_type;
713 nsIDOMNode_GetNodeType(nsnode, &node_type);
715 switch(node_type) {
716 case ELEMENT_NODE:
717 ret = &HTMLElement_Create(nsnode)->node;
718 break;
719 case TEXT_NODE:
720 ret = HTMLDOMTextNode_Create(nsnode);
721 break;
722 case COMMENT_NODE:
723 ret = &HTMLCommentElement_Create(nsnode)->node;
724 break;
725 default:
726 ret = heap_alloc_zero(sizeof(HTMLDOMNode));
727 ret->vtbl = &HTMLDOMNodeImplVtbl;
730 ret->lpHTMLDOMNodeVtbl = &HTMLDOMNodeVtbl;
731 ret->lpHTMLDOMNode2Vtbl = &HTMLDOMNode2Vtbl;
732 ret->ref = 1;
733 ret->doc = doc;
735 nsIDOMNode_AddRef(nsnode);
736 ret->nsnode = nsnode;
738 TRACE("type %d ret %p\n", node_type, ret);
740 return ret;
744 * FIXME
745 * List looks really ugly here. We should use a better data structure or
746 * (better) find a way to store HTMLDOMelement pointer in nsIDOMNode.
749 HTMLDOMNode *get_node(HTMLDocument *This, nsIDOMNode *nsnode, BOOL create)
751 HTMLDOMNode *iter = This->nodes, *ret;
753 while(iter) {
754 if(iter->nsnode == nsnode)
755 break;
756 iter = iter->next;
759 if(iter || !create)
760 return iter;
762 ret = create_node(This, nsnode);
764 ret->next = This->nodes;
765 This->nodes = ret;
767 return ret;
770 void release_nodes(HTMLDocument *This)
772 HTMLDOMNode *iter, *next;
774 if(!This->nodes)
775 return;
777 for(iter = This->nodes; iter; iter = next) {
778 next = iter->next;
779 iter->doc = NULL;
780 IHTMLDOMNode_Release(HTMLDOMNODE(iter));