mshtml: Added get_childNodes implementation.
[wine/multimedia.git] / dlls / mshtml / htmlnode.c
blob0f3e8480598f13ef10a6bb5d2ee83a9f3f93c344
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 const IHTMLDOMChildrenCollectionVtbl *lpIHTMLDOMChildrenCollectionVtbl;
37 LONG ref;
39 /* FIXME: implement weak reference */
40 HTMLDocument *doc;
42 nsIDOMNodeList *nslist;
43 } HTMLDOMChildrenCollection;
45 #define HTMLCHILDCOL(x) ((IHTMLDOMChildrenCollection*) &(x)->lpIHTMLDOMChildrenCollectionVtbl)
47 #define HTMLCHILDCOL_THIS(iface) DEFINE_THIS(HTMLDOMChildrenCollection, IHTMLDOMChildrenCollection, iface)
49 static HRESULT WINAPI HTMLDOMChildrenCollection_QueryInterface(IHTMLDOMChildrenCollection *iface, REFIID riid, void **ppv)
51 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
53 *ppv = NULL;
55 if(IsEqualGUID(&IID_IUnknown, riid)) {
56 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
57 *ppv = HTMLCHILDCOL(This);
58 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
59 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
60 *ppv = HTMLCHILDCOL(This);
61 }else if(IsEqualGUID(&IID_IHTMLDOMChildrenCollection, riid)) {
62 TRACE("(%p)->(IID_IHTMLDOMChildrenCollection %p)\n", This, ppv);
63 *ppv = HTMLCHILDCOL(This);
66 if(*ppv) {
67 IUnknown_AddRef((IUnknown*)*ppv);
68 return S_OK;
71 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
72 return E_NOINTERFACE;
75 static ULONG WINAPI HTMLDOMChildrenCollection_AddRef(IHTMLDOMChildrenCollection *iface)
77 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
78 LONG ref = InterlockedIncrement(&This->ref);
80 TRACE("(%p) ref=%d\n", This, ref);
82 return ref;
85 static ULONG WINAPI HTMLDOMChildrenCollection_Release(IHTMLDOMChildrenCollection *iface)
87 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
88 LONG ref = InterlockedDecrement(&This->ref);
90 TRACE("(%p) ref=%d\n", This, ref);
92 if(!ref) {
93 nsIDOMNodeList_Release(This->nslist);
94 heap_free(This);
97 return ref;
100 static HRESULT WINAPI HTMLDOMChildrenCollection_GetTypeInfoCount(IHTMLDOMChildrenCollection *iface, UINT *pctinfo)
102 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
103 FIXME("(%p)->(%p)\n", This, pctinfo);
104 return E_NOTIMPL;
107 static HRESULT WINAPI HTMLDOMChildrenCollection_GetTypeInfo(IHTMLDOMChildrenCollection *iface, UINT iTInfo,
108 LCID lcid, ITypeInfo **ppTInfo)
110 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
111 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
112 return E_NOTIMPL;
115 static HRESULT WINAPI HTMLDOMChildrenCollection_GetIDsOfNames(IHTMLDOMChildrenCollection *iface, REFIID riid,
116 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
118 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
119 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
120 lcid, rgDispId);
121 return E_NOTIMPL;
124 static HRESULT WINAPI HTMLDOMChildrenCollection_Invoke(IHTMLDOMChildrenCollection *iface, DISPID dispIdMember,
125 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
126 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
128 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
129 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
130 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
131 return E_NOTIMPL;
134 static HRESULT WINAPI HTMLDOMChildrenCollection_get_length(IHTMLDOMChildrenCollection *iface, long *p)
136 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
137 FIXME("(%p)->(%p)\n", This, p);
138 return E_NOTIMPL;
141 static HRESULT WINAPI HTMLDOMChildrenCollection__newEnum(IHTMLDOMChildrenCollection *iface, IUnknown **p)
143 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
144 FIXME("(%p)->(%p)\n", This, p);
145 return E_NOTIMPL;
148 static HRESULT WINAPI HTMLDOMChildrenCollection_item(IHTMLDOMChildrenCollection *iface, long index, IDispatch **ppItem)
150 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
151 FIXME("(%p)->(%ld %p)\n", This, index, ppItem);
152 return E_NOTIMPL;
155 #undef HTMLCHILDCOL_THIS
157 static const IHTMLDOMChildrenCollectionVtbl HTMLDOMChildrenCollectionVtbl = {
158 HTMLDOMChildrenCollection_QueryInterface,
159 HTMLDOMChildrenCollection_AddRef,
160 HTMLDOMChildrenCollection_Release,
161 HTMLDOMChildrenCollection_GetTypeInfoCount,
162 HTMLDOMChildrenCollection_GetTypeInfo,
163 HTMLDOMChildrenCollection_GetIDsOfNames,
164 HTMLDOMChildrenCollection_Invoke,
165 HTMLDOMChildrenCollection_get_length,
166 HTMLDOMChildrenCollection__newEnum,
167 HTMLDOMChildrenCollection_item
170 static IHTMLDOMChildrenCollection *create_child_collection(HTMLDocument *doc, nsIDOMNodeList *nslist)
172 HTMLDOMChildrenCollection *ret;
174 ret = heap_alloc_zero(sizeof(*ret));
175 ret->lpIHTMLDOMChildrenCollectionVtbl = &HTMLDOMChildrenCollectionVtbl;
176 ret->ref = 1;
178 nsIDOMNodeList_AddRef(nslist);
179 ret->nslist = nslist;
180 ret->doc = doc;
182 return HTMLCHILDCOL(ret);
185 #define HTMLDOMNODE_THIS(iface) DEFINE_THIS(HTMLDOMNode, HTMLDOMNode, iface)
187 static HRESULT WINAPI HTMLDOMNode_QueryInterface(IHTMLDOMNode *iface,
188 REFIID riid, void **ppv)
190 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
192 return This->vtbl->qi(This, riid, ppv);
195 static ULONG WINAPI HTMLDOMNode_AddRef(IHTMLDOMNode *iface)
197 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
198 LONG ref = InterlockedIncrement(&This->ref);
200 TRACE("(%p) ref=%d\n", This, ref);
202 return ref;
205 static ULONG WINAPI HTMLDOMNode_Release(IHTMLDOMNode *iface)
207 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
208 LONG ref = InterlockedDecrement(&This->ref);
210 TRACE("(%p) ref=%d\n", This, ref);
212 if(!ref) {
213 This->vtbl->destructor(This);
214 heap_free(This);
217 return ref;
220 static HRESULT WINAPI HTMLDOMNode_GetTypeInfoCount(IHTMLDOMNode *iface, UINT *pctinfo)
222 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
223 FIXME("(%p)->(%p)\n", This, pctinfo);
224 return E_NOTIMPL;
227 static HRESULT WINAPI HTMLDOMNode_GetTypeInfo(IHTMLDOMNode *iface, UINT iTInfo,
228 LCID lcid, ITypeInfo **ppTInfo)
230 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
231 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
232 return E_NOTIMPL;
235 static HRESULT WINAPI HTMLDOMNode_GetIDsOfNames(IHTMLDOMNode *iface, REFIID riid,
236 LPOLESTR *rgszNames, UINT cNames,
237 LCID lcid, DISPID *rgDispId)
239 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
240 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
241 lcid, rgDispId);
242 return E_NOTIMPL;
245 static HRESULT WINAPI HTMLDOMNode_Invoke(IHTMLDOMNode *iface, DISPID dispIdMember,
246 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
247 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
249 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
250 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
251 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
252 return E_NOTIMPL;
255 static HRESULT WINAPI HTMLDOMNode_get_nodeType(IHTMLDOMNode *iface, long *p)
257 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
258 PRUint16 type = -1;
260 TRACE("(%p)->(%p)\n", This, p);
262 nsIDOMNode_GetNodeType(This->nsnode, &type);
264 switch(type) {
265 case ELEMENT_NODE:
266 *p = 1;
267 break;
268 case TEXT_NODE:
269 *p = 3;
270 break;
271 case COMMENT_NODE:
272 *p = 8;
273 break;
274 default:
276 * FIXME:
277 * According to MSDN only ELEMENT_NODE and TEXT_NODE are supported.
278 * It needs more tests.
280 FIXME("type %u\n", type);
281 *p = 0;
284 return S_OK;
287 static HRESULT WINAPI HTMLDOMNode_get_parentNode(IHTMLDOMNode *iface, IHTMLDOMNode **p)
289 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
290 FIXME("(%p)->(%p)\n", This, p);
291 return E_NOTIMPL;
294 static HRESULT WINAPI HTMLDOMNode_hasChildNodes(IHTMLDOMNode *iface, VARIANT_BOOL *fChildren)
296 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
297 FIXME("(%p)->(%p)\n", This, fChildren);
298 return E_NOTIMPL;
301 static HRESULT WINAPI HTMLDOMNode_get_childNodes(IHTMLDOMNode *iface, IDispatch **p)
303 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
304 nsIDOMNodeList *nslist;
305 nsresult nsres;
307 TRACE("(%p)->(%p)\n", This, p);
309 nsres = nsIDOMNode_GetChildNodes(This->nsnode, &nslist);
310 if(NS_FAILED(nsres)) {
311 ERR("GetChildNodes failed: %08x\n", nsres);
312 return E_FAIL;
315 *p = (IDispatch*)create_child_collection(This->doc, nslist);
316 nsIDOMNodeList_Release(nslist);
318 return S_OK;
321 static HRESULT WINAPI HTMLDOMNode_get_attributes(IHTMLDOMNode *iface, IDispatch **p)
323 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
324 FIXME("(%p)->(%p)\n", This, p);
325 return E_NOTIMPL;
328 static HRESULT WINAPI HTMLDOMNode_insertBefore(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
329 VARIANT refChild, IHTMLDOMNode **node)
331 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
332 FIXME("(%p)->(%p v %p)\n", This, newChild, node);
333 return E_NOTIMPL;
336 static HRESULT WINAPI HTMLDOMNode_removeChild(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
337 IHTMLDOMNode **node)
339 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
340 FIXME("(%p)->(%p %p)\n", This, newChild, node);
341 return E_NOTIMPL;
344 static HRESULT WINAPI HTMLDOMNode_replaceChild(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
345 IHTMLDOMNode *oldChild, IHTMLDOMNode **node)
347 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
348 FIXME("(%p)->(%p %p %p)\n", This, newChild, oldChild, node);
349 return E_NOTIMPL;
352 static HRESULT WINAPI HTMLDOMNode_cloneNode(IHTMLDOMNode *iface, VARIANT_BOOL fDeep,
353 IHTMLDOMNode **clonedNode)
355 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
356 FIXME("(%p)->(%x %p)\n", This, fDeep, clonedNode);
357 return E_NOTIMPL;
360 static HRESULT WINAPI HTMLDOMNode_removeNode(IHTMLDOMNode *iface, VARIANT_BOOL fDeep,
361 IHTMLDOMNode **removed)
363 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
364 FIXME("(%p)->(%x %p)\n", This, fDeep, removed);
365 return E_NOTIMPL;
368 static HRESULT WINAPI HTMLDOMNode_swapNode(IHTMLDOMNode *iface, IHTMLDOMNode *otherNode,
369 IHTMLDOMNode **swappedNode)
371 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
372 FIXME("(%p)->(%p %p)\n", This, otherNode, swappedNode);
373 return E_NOTIMPL;
376 static HRESULT WINAPI HTMLDOMNode_replaceNode(IHTMLDOMNode *iface, IHTMLDOMNode *replacement,
377 IHTMLDOMNode **replaced)
379 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
380 FIXME("(%p)->(%p %p)\n", This, replacement, replaced);
381 return E_NOTIMPL;
384 static HRESULT WINAPI HTMLDOMNode_appendChild(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
385 IHTMLDOMNode **node)
387 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
388 FIXME("(%p)->(%p %p)\n", This, newChild, node);
389 return E_NOTIMPL;
392 static HRESULT WINAPI HTMLDOMNode_get_nodeName(IHTMLDOMNode *iface, BSTR *p)
394 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
396 TRACE("(%p)->(%p)\n", This, p);
398 *p = NULL;
400 if(This->nsnode) {
401 nsAString name_str;
402 const PRUnichar *name;
403 nsresult nsres;
405 nsAString_Init(&name_str, NULL);
406 nsres = nsIDOMNode_GetNodeName(This->nsnode, &name_str);
408 if(NS_SUCCEEDED(nsres)) {
409 nsAString_GetData(&name_str, &name);
410 *p = SysAllocString(name);
411 }else {
412 ERR("GetNodeName failed: %08x\n", nsres);
415 nsAString_Finish(&name_str);
418 return S_OK;
421 static HRESULT WINAPI HTMLDOMNode_put_nodeValue(IHTMLDOMNode *iface, VARIANT v)
423 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
424 FIXME("(%p)->()\n", This);
425 return E_NOTIMPL;
428 static HRESULT WINAPI HTMLDOMNode_get_nodeValue(IHTMLDOMNode *iface, VARIANT *p)
430 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
431 FIXME("(%p)->(%p)\n", This, p);
432 return E_NOTIMPL;
435 static HRESULT WINAPI HTMLDOMNode_get_firstChild(IHTMLDOMNode *iface, IHTMLDOMNode **p)
437 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
438 nsIDOMNode *nschild = NULL;
440 TRACE("(%p)->(%p)\n", This, p);
442 nsIDOMNode_GetFirstChild(This->nsnode, &nschild);
443 if(nschild) {
444 *p = HTMLDOMNODE(get_node(This->doc, nschild, TRUE));
445 IHTMLDOMNode_AddRef(*p);
446 }else {
447 *p = NULL;
450 return S_OK;
453 static HRESULT WINAPI HTMLDOMNode_get_lastChild(IHTMLDOMNode *iface, IHTMLDOMNode **p)
455 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
456 FIXME("(%p)->(%p)\n", This, p);
457 return E_NOTIMPL;
460 static HRESULT WINAPI HTMLDOMNode_get_previousSibling(IHTMLDOMNode *iface, IHTMLDOMNode **p)
462 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
463 FIXME("(%p)->(%p)\n", This, p);
464 return E_NOTIMPL;
467 static HRESULT WINAPI HTMLDOMNode_get_nextSibling(IHTMLDOMNode *iface, IHTMLDOMNode **p)
469 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
470 FIXME("(%p)->(%p)\n", This, p);
471 return E_NOTIMPL;
474 #undef HTMLDOMNODE_THIS
476 static const IHTMLDOMNodeVtbl HTMLDOMNodeVtbl = {
477 HTMLDOMNode_QueryInterface,
478 HTMLDOMNode_AddRef,
479 HTMLDOMNode_Release,
480 HTMLDOMNode_GetTypeInfoCount,
481 HTMLDOMNode_GetTypeInfo,
482 HTMLDOMNode_GetIDsOfNames,
483 HTMLDOMNode_Invoke,
484 HTMLDOMNode_get_nodeType,
485 HTMLDOMNode_get_parentNode,
486 HTMLDOMNode_hasChildNodes,
487 HTMLDOMNode_get_childNodes,
488 HTMLDOMNode_get_attributes,
489 HTMLDOMNode_insertBefore,
490 HTMLDOMNode_removeChild,
491 HTMLDOMNode_replaceChild,
492 HTMLDOMNode_cloneNode,
493 HTMLDOMNode_removeNode,
494 HTMLDOMNode_swapNode,
495 HTMLDOMNode_replaceNode,
496 HTMLDOMNode_appendChild,
497 HTMLDOMNode_get_nodeName,
498 HTMLDOMNode_put_nodeValue,
499 HTMLDOMNode_get_nodeValue,
500 HTMLDOMNode_get_firstChild,
501 HTMLDOMNode_get_lastChild,
502 HTMLDOMNode_get_previousSibling,
503 HTMLDOMNode_get_nextSibling
506 #define HTMLDOMNODE2_THIS(iface) DEFINE_THIS(HTMLDOMNode, HTMLDOMNode2, iface)
508 static HRESULT WINAPI HTMLDOMNode2_QueryInterface(IHTMLDOMNode2 *iface,
509 REFIID riid, void **ppv)
511 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
513 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(This), riid, ppv);
516 static ULONG WINAPI HTMLDOMNode2_AddRef(IHTMLDOMNode2 *iface)
518 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
520 return IHTMLDOMNode_AddRef(HTMLDOMNODE(This));
523 static ULONG WINAPI HTMLDOMNode2_Release(IHTMLDOMNode2 *iface)
525 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
527 return IHTMLDOMNode_Release(HTMLDOMNODE(This));
530 static HRESULT WINAPI HTMLDOMNode2_GetTypeInfoCount(IHTMLDOMNode2 *iface, UINT *pctinfo)
532 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
533 FIXME("(%p)->(%p)\n", This, pctinfo);
534 return E_NOTIMPL;
537 static HRESULT WINAPI HTMLDOMNode2_GetTypeInfo(IHTMLDOMNode2 *iface, UINT iTInfo,
538 LCID lcid, ITypeInfo **ppTInfo)
540 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
541 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
542 return E_NOTIMPL;
545 static HRESULT WINAPI HTMLDOMNode2_GetIDsOfNames(IHTMLDOMNode2 *iface, REFIID riid,
546 LPOLESTR *rgszNames, UINT cNames,
547 LCID lcid, DISPID *rgDispId)
549 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
550 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
551 lcid, rgDispId);
552 return E_NOTIMPL;
555 static HRESULT WINAPI HTMLDOMNode2_Invoke(IHTMLDOMNode2 *iface, DISPID dispIdMember,
556 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
557 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
559 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
560 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
561 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
562 return E_NOTIMPL;
565 static HRESULT WINAPI HTMLDOMNode2_get_ownerDocument(IHTMLDOMNode2 *iface, IDispatch **p)
567 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
568 FIXME("(%p)->(%p)\n", This, p);
569 return E_NOTIMPL;
572 #undef HTMLDOMNODE2_THIS
574 static const IHTMLDOMNode2Vtbl HTMLDOMNode2Vtbl = {
575 HTMLDOMNode2_QueryInterface,
576 HTMLDOMNode2_AddRef,
577 HTMLDOMNode2_Release,
578 HTMLDOMNode2_GetTypeInfoCount,
579 HTMLDOMNode2_GetTypeInfo,
580 HTMLDOMNode2_GetIDsOfNames,
581 HTMLDOMNode2_Invoke,
582 HTMLDOMNode2_get_ownerDocument
585 HRESULT HTMLDOMNode_QI(HTMLDOMNode *This, REFIID riid, void **ppv)
587 *ppv = NULL;
589 if(IsEqualGUID(&IID_IUnknown, riid)) {
590 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
591 *ppv = HTMLDOMNODE(This);
592 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
593 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
594 *ppv = HTMLDOMNODE(This);
595 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
596 if(This->dispex.data) {
597 TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
598 *ppv = DISPATCHEX(&This->dispex);
599 }else {
600 FIXME("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
601 return E_NOINTERFACE;
603 }else if(IsEqualGUID(&IID_IHTMLDOMNode, riid)) {
604 TRACE("(%p)->(IID_IHTMLDOMNode %p)\n", This, ppv);
605 *ppv = HTMLDOMNODE(This);
606 }else if(IsEqualGUID(&IID_IHTMLDOMNode2, riid)) {
607 TRACE("(%p)->(IID_IHTMLDOMNode2 %p)\n", This, ppv);
608 *ppv = HTMLDOMNODE2(This);
611 if(*ppv) {
612 IUnknown_AddRef((IUnknown*)*ppv);
613 return S_OK;
616 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
617 return E_NOINTERFACE;
620 void HTMLDOMNode_destructor(HTMLDOMNode *This)
622 if(This->nsnode)
623 nsIDOMNode_Release(This->nsnode);
624 if(This->event_target)
625 release_event_target(This->event_target);
628 static const NodeImplVtbl HTMLDOMNodeImplVtbl = {
629 HTMLDOMNode_QI,
630 HTMLDOMNode_destructor
633 static HTMLDOMNode *create_node(HTMLDocument *doc, nsIDOMNode *nsnode)
635 HTMLDOMNode *ret;
636 PRUint16 node_type;
638 nsIDOMNode_GetNodeType(nsnode, &node_type);
640 switch(node_type) {
641 case ELEMENT_NODE:
642 ret = &HTMLElement_Create(nsnode)->node;
643 break;
644 case TEXT_NODE:
645 ret = HTMLDOMTextNode_Create(nsnode);
646 break;
647 default:
648 ret = heap_alloc_zero(sizeof(HTMLDOMNode));
649 ret->vtbl = &HTMLDOMNodeImplVtbl;
652 ret->lpHTMLDOMNodeVtbl = &HTMLDOMNodeVtbl;
653 ret->lpHTMLDOMNode2Vtbl = &HTMLDOMNode2Vtbl;
654 ret->ref = 1;
655 ret->doc = doc;
657 nsIDOMNode_AddRef(nsnode);
658 ret->nsnode = nsnode;
660 TRACE("type %d ret %p\n", node_type, ret);
662 return ret;
666 * FIXME
667 * List looks really ugly here. We should use a better data structure or
668 * (better) find a way to store HTMLDOMelement pointer in nsIDOMNode.
671 HTMLDOMNode *get_node(HTMLDocument *This, nsIDOMNode *nsnode, BOOL create)
673 HTMLDOMNode *iter = This->nodes, *ret;
675 while(iter) {
676 if(iter->nsnode == nsnode)
677 break;
678 iter = iter->next;
681 if(iter || !create)
682 return iter;
684 ret = create_node(This, nsnode);
686 ret->next = This->nodes;
687 This->nodes = ret;
689 return ret;
692 void release_nodes(HTMLDocument *This)
694 HTMLDOMNode *iter, *next;
696 if(!This->nodes)
697 return;
699 for(iter = This->nodes; iter; iter = next) {
700 next = iter->next;
701 iter->doc = NULL;
702 IHTMLDOMNode_Release(HTMLDOMNODE(iter));