mshtml: Added IHTMLDOMNode::removeChild implementation.
[wine/gsoc_dplay.git] / dlls / mshtml / htmlnode.c
blob9b667a1fc8d5917fd083c291f5c4885644072700
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 static HTMLDOMNode *get_node_obj(HTMLDocument*,IUnknown*);
36 typedef struct {
37 DispatchEx dispex;
38 const IHTMLDOMChildrenCollectionVtbl *lpIHTMLDOMChildrenCollectionVtbl;
40 LONG ref;
42 /* FIXME: implement weak reference */
43 HTMLDocument *doc;
45 nsIDOMNodeList *nslist;
46 } HTMLDOMChildrenCollection;
48 #define HTMLCHILDCOL(x) ((IHTMLDOMChildrenCollection*) &(x)->lpIHTMLDOMChildrenCollectionVtbl)
50 #define HTMLCHILDCOL_THIS(iface) DEFINE_THIS(HTMLDOMChildrenCollection, IHTMLDOMChildrenCollection, iface)
52 static HRESULT WINAPI HTMLDOMChildrenCollection_QueryInterface(IHTMLDOMChildrenCollection *iface, REFIID riid, void **ppv)
54 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
56 *ppv = NULL;
58 if(IsEqualGUID(&IID_IUnknown, riid)) {
59 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
60 *ppv = HTMLCHILDCOL(This);
61 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
62 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
63 *ppv = HTMLCHILDCOL(This);
64 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
65 TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
66 *ppv = DISPATCHEX(&This->dispex);
67 }else if(IsEqualGUID(&IID_IHTMLDOMChildrenCollection, riid)) {
68 TRACE("(%p)->(IID_IHTMLDOMChildrenCollection %p)\n", This, ppv);
69 *ppv = HTMLCHILDCOL(This);
72 if(*ppv) {
73 IUnknown_AddRef((IUnknown*)*ppv);
74 return S_OK;
77 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
78 return E_NOINTERFACE;
81 static ULONG WINAPI HTMLDOMChildrenCollection_AddRef(IHTMLDOMChildrenCollection *iface)
83 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
84 LONG ref = InterlockedIncrement(&This->ref);
86 TRACE("(%p) ref=%d\n", This, ref);
88 return ref;
91 static ULONG WINAPI HTMLDOMChildrenCollection_Release(IHTMLDOMChildrenCollection *iface)
93 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
94 LONG ref = InterlockedDecrement(&This->ref);
96 TRACE("(%p) ref=%d\n", This, ref);
98 if(!ref) {
99 nsIDOMNodeList_Release(This->nslist);
100 heap_free(This);
103 return ref;
106 static HRESULT WINAPI HTMLDOMChildrenCollection_GetTypeInfoCount(IHTMLDOMChildrenCollection *iface, UINT *pctinfo)
108 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
109 FIXME("(%p)->(%p)\n", This, pctinfo);
110 return E_NOTIMPL;
113 static HRESULT WINAPI HTMLDOMChildrenCollection_GetTypeInfo(IHTMLDOMChildrenCollection *iface, UINT iTInfo,
114 LCID lcid, ITypeInfo **ppTInfo)
116 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
117 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
118 return E_NOTIMPL;
121 static HRESULT WINAPI HTMLDOMChildrenCollection_GetIDsOfNames(IHTMLDOMChildrenCollection *iface, REFIID riid,
122 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
124 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
125 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
126 lcid, rgDispId);
127 return E_NOTIMPL;
130 static HRESULT WINAPI HTMLDOMChildrenCollection_Invoke(IHTMLDOMChildrenCollection *iface, DISPID dispIdMember,
131 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
132 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
134 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
135 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
136 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
137 return E_NOTIMPL;
140 static HRESULT WINAPI HTMLDOMChildrenCollection_get_length(IHTMLDOMChildrenCollection *iface, long *p)
142 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
143 PRUint32 length=0;
145 TRACE("(%p)->(%p)\n", This, p);
147 nsIDOMNodeList_GetLength(This->nslist, &length);
148 *p = length;
149 return S_OK;
152 static HRESULT WINAPI HTMLDOMChildrenCollection__newEnum(IHTMLDOMChildrenCollection *iface, IUnknown **p)
154 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
155 FIXME("(%p)->(%p)\n", This, p);
156 return E_NOTIMPL;
159 static HRESULT WINAPI HTMLDOMChildrenCollection_item(IHTMLDOMChildrenCollection *iface, long index, IDispatch **ppItem)
161 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
162 nsIDOMNode *nsnode = NULL;
163 PRUint32 length=0;
164 nsresult nsres;
166 TRACE("(%p)->(%ld %p)\n", This, index, ppItem);
168 nsIDOMNodeList_GetLength(This->nslist, &length);
169 if(index < 0 || index >= length)
170 return E_INVALIDARG;
172 nsres = nsIDOMNodeList_Item(This->nslist, index, &nsnode);
173 if(NS_FAILED(nsres) || !nsnode) {
174 ERR("Item failed: %08x\n", nsres);
175 return E_FAIL;
178 *ppItem = (IDispatch*)get_node(This->doc, nsnode, TRUE);
179 IDispatch_AddRef(*ppItem);
180 return S_OK;
183 #define DISPID_CHILDCOL_0 MSHTML_DISPID_CUSTOM_MIN
185 static HRESULT HTMLDOMChildrenCollection_get_dispid(IUnknown *iface, BSTR name, DWORD flags, DISPID *dispid)
187 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
188 WCHAR *ptr;
189 DWORD idx=0;
190 PRUint32 len = 0;
192 for(ptr = name; *ptr && isdigitW(*ptr); ptr++)
193 idx = idx*10 + (*ptr-'0');
194 if(*ptr)
195 return DISP_E_UNKNOWNNAME;
197 nsIDOMNodeList_GetLength(This->nslist, &len);
198 if(idx >= len)
199 return DISP_E_UNKNOWNNAME;
201 *dispid = DISPID_CHILDCOL_0 + idx;
202 TRACE("ret %x\n", *dispid);
203 return S_OK;
206 static HRESULT HTMLDOMChildrenCollection_invoke(IUnknown *iface, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
207 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
209 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
211 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
213 switch(flags) {
214 case INVOKE_PROPERTYGET: {
215 IDispatch *disp = NULL;
216 HRESULT hres;
218 hres = IHTMLDOMChildrenCollection_item(HTMLCHILDCOL(This), id - DISPID_CHILDCOL_0, &disp);
219 if(0&&FAILED(hres))
220 return hres;
222 V_VT(res) = VT_DISPATCH;
223 V_DISPATCH(res) = disp;
224 break;
227 default:
228 FIXME("unimplemented flags %x\n", flags);
229 return E_NOTIMPL;
232 return S_OK;
235 #undef HTMLCHILDCOL_THIS
237 static const IHTMLDOMChildrenCollectionVtbl HTMLDOMChildrenCollectionVtbl = {
238 HTMLDOMChildrenCollection_QueryInterface,
239 HTMLDOMChildrenCollection_AddRef,
240 HTMLDOMChildrenCollection_Release,
241 HTMLDOMChildrenCollection_GetTypeInfoCount,
242 HTMLDOMChildrenCollection_GetTypeInfo,
243 HTMLDOMChildrenCollection_GetIDsOfNames,
244 HTMLDOMChildrenCollection_Invoke,
245 HTMLDOMChildrenCollection_get_length,
246 HTMLDOMChildrenCollection__newEnum,
247 HTMLDOMChildrenCollection_item
250 static const tid_t HTMLDOMChildrenCollection_iface_tids[] = {
251 IHTMLDOMChildrenCollection_tid,
255 static const dispex_static_data_vtbl_t HTMLDOMChildrenCollection_dispex_vtbl = {
256 HTMLDOMChildrenCollection_get_dispid,
257 HTMLDOMChildrenCollection_invoke
260 static dispex_static_data_t HTMLDOMChildrenCollection_dispex = {
261 &HTMLDOMChildrenCollection_dispex_vtbl,
262 DispDOMChildrenCollection_tid,
263 NULL,
264 HTMLDOMChildrenCollection_iface_tids
267 static IHTMLDOMChildrenCollection *create_child_collection(HTMLDocument *doc, nsIDOMNodeList *nslist)
269 HTMLDOMChildrenCollection *ret;
271 ret = heap_alloc_zero(sizeof(*ret));
272 ret->lpIHTMLDOMChildrenCollectionVtbl = &HTMLDOMChildrenCollectionVtbl;
273 ret->ref = 1;
275 nsIDOMNodeList_AddRef(nslist);
276 ret->nslist = nslist;
277 ret->doc = doc;
279 init_dispex(&ret->dispex, (IUnknown*)HTMLCHILDCOL(ret), &HTMLDOMChildrenCollection_dispex);
281 return HTMLCHILDCOL(ret);
284 #define HTMLDOMNODE_THIS(iface) DEFINE_THIS(HTMLDOMNode, HTMLDOMNode, iface)
286 static HRESULT WINAPI HTMLDOMNode_QueryInterface(IHTMLDOMNode *iface,
287 REFIID riid, void **ppv)
289 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
291 return This->vtbl->qi(This, riid, ppv);
294 static ULONG WINAPI HTMLDOMNode_AddRef(IHTMLDOMNode *iface)
296 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
297 LONG ref = InterlockedIncrement(&This->ref);
299 TRACE("(%p) ref=%d\n", This, ref);
301 return ref;
304 static ULONG WINAPI HTMLDOMNode_Release(IHTMLDOMNode *iface)
306 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
307 LONG ref = InterlockedDecrement(&This->ref);
309 TRACE("(%p) ref=%d\n", This, ref);
311 if(!ref) {
312 This->vtbl->destructor(This);
313 heap_free(This);
316 return ref;
319 static HRESULT WINAPI HTMLDOMNode_GetTypeInfoCount(IHTMLDOMNode *iface, UINT *pctinfo)
321 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
322 FIXME("(%p)->(%p)\n", This, pctinfo);
323 return E_NOTIMPL;
326 static HRESULT WINAPI HTMLDOMNode_GetTypeInfo(IHTMLDOMNode *iface, UINT iTInfo,
327 LCID lcid, ITypeInfo **ppTInfo)
329 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
330 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
331 return E_NOTIMPL;
334 static HRESULT WINAPI HTMLDOMNode_GetIDsOfNames(IHTMLDOMNode *iface, REFIID riid,
335 LPOLESTR *rgszNames, UINT cNames,
336 LCID lcid, DISPID *rgDispId)
338 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
339 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
340 lcid, rgDispId);
341 return E_NOTIMPL;
344 static HRESULT WINAPI HTMLDOMNode_Invoke(IHTMLDOMNode *iface, DISPID dispIdMember,
345 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
346 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
348 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
349 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
350 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
351 return E_NOTIMPL;
354 static HRESULT WINAPI HTMLDOMNode_get_nodeType(IHTMLDOMNode *iface, long *p)
356 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
357 PRUint16 type = -1;
359 TRACE("(%p)->(%p)\n", This, p);
361 nsIDOMNode_GetNodeType(This->nsnode, &type);
363 switch(type) {
364 case ELEMENT_NODE:
365 *p = 1;
366 break;
367 case TEXT_NODE:
368 *p = 3;
369 break;
370 case COMMENT_NODE:
371 *p = 8;
372 break;
373 default:
375 * FIXME:
376 * According to MSDN only ELEMENT_NODE and TEXT_NODE are supported.
377 * It needs more tests.
379 FIXME("type %u\n", type);
380 *p = 0;
383 return S_OK;
386 static HRESULT WINAPI HTMLDOMNode_get_parentNode(IHTMLDOMNode *iface, IHTMLDOMNode **p)
388 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
389 FIXME("(%p)->(%p)\n", This, p);
390 return E_NOTIMPL;
393 static HRESULT WINAPI HTMLDOMNode_hasChildNodes(IHTMLDOMNode *iface, VARIANT_BOOL *fChildren)
395 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
396 FIXME("(%p)->(%p)\n", This, fChildren);
397 return E_NOTIMPL;
400 static HRESULT WINAPI HTMLDOMNode_get_childNodes(IHTMLDOMNode *iface, IDispatch **p)
402 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
403 nsIDOMNodeList *nslist;
404 nsresult nsres;
406 TRACE("(%p)->(%p)\n", This, p);
408 nsres = nsIDOMNode_GetChildNodes(This->nsnode, &nslist);
409 if(NS_FAILED(nsres)) {
410 ERR("GetChildNodes failed: %08x\n", nsres);
411 return E_FAIL;
414 *p = (IDispatch*)create_child_collection(This->doc, nslist);
415 nsIDOMNodeList_Release(nslist);
417 return S_OK;
420 static HRESULT WINAPI HTMLDOMNode_get_attributes(IHTMLDOMNode *iface, IDispatch **p)
422 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
423 FIXME("(%p)->(%p)\n", This, p);
424 return E_NOTIMPL;
427 static HRESULT WINAPI HTMLDOMNode_insertBefore(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
428 VARIANT refChild, IHTMLDOMNode **node)
430 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
431 FIXME("(%p)->(%p v %p)\n", This, newChild, node);
432 return E_NOTIMPL;
435 static HRESULT WINAPI HTMLDOMNode_removeChild(IHTMLDOMNode *iface, IHTMLDOMNode *oldChild,
436 IHTMLDOMNode **node)
438 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
439 HTMLDOMNode *node_obj;
440 nsIDOMNode *nsnode;
441 nsresult nsres;
443 TRACE("(%p)->(%p %p)\n", This, oldChild, node);
445 node_obj = get_node_obj(This->doc, (IUnknown*)oldChild);
446 if(!node_obj)
447 return E_FAIL;
449 nsres = nsIDOMNode_RemoveChild(This->nsnode, node_obj->nsnode, &nsnode);
450 if(NS_FAILED(nsres)) {
451 ERR("RemoveChild failed: %08x\n", nsres);
452 return E_FAIL;
455 /* FIXME: Make sure that node != newChild */
456 *node = HTMLDOMNODE(get_node(This->doc, nsnode, TRUE));
457 IHTMLDOMNode_AddRef(*node);
458 return S_OK;
461 static HRESULT WINAPI HTMLDOMNode_replaceChild(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
462 IHTMLDOMNode *oldChild, IHTMLDOMNode **node)
464 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
465 FIXME("(%p)->(%p %p %p)\n", This, newChild, oldChild, node);
466 return E_NOTIMPL;
469 static HRESULT WINAPI HTMLDOMNode_cloneNode(IHTMLDOMNode *iface, VARIANT_BOOL fDeep,
470 IHTMLDOMNode **clonedNode)
472 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
473 FIXME("(%p)->(%x %p)\n", This, fDeep, clonedNode);
474 return E_NOTIMPL;
477 static HRESULT WINAPI HTMLDOMNode_removeNode(IHTMLDOMNode *iface, VARIANT_BOOL fDeep,
478 IHTMLDOMNode **removed)
480 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
481 FIXME("(%p)->(%x %p)\n", This, fDeep, removed);
482 return E_NOTIMPL;
485 static HRESULT WINAPI HTMLDOMNode_swapNode(IHTMLDOMNode *iface, IHTMLDOMNode *otherNode,
486 IHTMLDOMNode **swappedNode)
488 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
489 FIXME("(%p)->(%p %p)\n", This, otherNode, swappedNode);
490 return E_NOTIMPL;
493 static HRESULT WINAPI HTMLDOMNode_replaceNode(IHTMLDOMNode *iface, IHTMLDOMNode *replacement,
494 IHTMLDOMNode **replaced)
496 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
497 FIXME("(%p)->(%p %p)\n", This, replacement, replaced);
498 return E_NOTIMPL;
501 static HRESULT WINAPI HTMLDOMNode_appendChild(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
502 IHTMLDOMNode **node)
504 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
505 HTMLDOMNode *node_obj;
506 nsIDOMNode *nsnode;
507 nsresult nsres;
509 TRACE("(%p)->(%p %p)\n", This, newChild, node);
511 node_obj = get_node_obj(This->doc, (IUnknown*)newChild);
512 if(!node_obj)
513 return E_FAIL;
515 nsres = nsIDOMNode_AppendChild(This->nsnode, node_obj->nsnode, &nsnode);
516 if(NS_FAILED(nsres)) {
517 ERR("AppendChild failed: %08x\n", nsres);
518 return E_FAIL;
521 /* FIXME: Make sure that node != newChild */
522 *node = HTMLDOMNODE(get_node(This->doc, nsnode, TRUE));
523 IHTMLDOMNode_AddRef(*node);
524 return S_OK;
527 static HRESULT WINAPI HTMLDOMNode_get_nodeName(IHTMLDOMNode *iface, BSTR *p)
529 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
531 TRACE("(%p)->(%p)\n", This, p);
533 *p = NULL;
535 if(This->nsnode) {
536 nsAString name_str;
537 const PRUnichar *name;
538 nsresult nsres;
540 nsAString_Init(&name_str, NULL);
541 nsres = nsIDOMNode_GetNodeName(This->nsnode, &name_str);
543 if(NS_SUCCEEDED(nsres)) {
544 nsAString_GetData(&name_str, &name);
545 *p = SysAllocString(name);
546 }else {
547 ERR("GetNodeName failed: %08x\n", nsres);
550 nsAString_Finish(&name_str);
553 return S_OK;
556 static HRESULT WINAPI HTMLDOMNode_put_nodeValue(IHTMLDOMNode *iface, VARIANT v)
558 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
560 TRACE("(%p)->()\n", This);
562 switch(V_VT(&v)) {
563 case VT_BSTR: {
564 nsAString val_str;
566 TRACE("bstr %s\n", debugstr_w(V_BSTR(&v)));
568 nsAString_Init(&val_str, V_BSTR(&v));
569 nsIDOMNode_SetNodeValue(This->nsnode, &val_str);
570 nsAString_Finish(&val_str);
572 return S_OK;
575 default:
576 FIXME("unsupported vt %d\n", V_VT(&v));
579 return E_NOTIMPL;
582 static HRESULT WINAPI HTMLDOMNode_get_nodeValue(IHTMLDOMNode *iface, VARIANT *p)
584 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
585 const PRUnichar *val;
586 nsAString val_str;
588 TRACE("(%p)->(%p)\n", This, p);
590 nsAString_Init(&val_str, NULL);
591 nsIDOMNode_GetNodeValue(This->nsnode, &val_str);
592 nsAString_GetData(&val_str, &val);
594 if(*val) {
595 V_VT(p) = VT_BSTR;
596 V_BSTR(p) = SysAllocString(val);
597 }else {
598 V_VT(p) = VT_NULL;
601 nsAString_Finish(&val_str);
603 return S_OK;
606 static HRESULT WINAPI HTMLDOMNode_get_firstChild(IHTMLDOMNode *iface, IHTMLDOMNode **p)
608 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
609 nsIDOMNode *nschild = NULL;
611 TRACE("(%p)->(%p)\n", This, p);
613 nsIDOMNode_GetFirstChild(This->nsnode, &nschild);
614 if(nschild) {
615 *p = HTMLDOMNODE(get_node(This->doc, nschild, TRUE));
616 IHTMLDOMNode_AddRef(*p);
617 }else {
618 *p = NULL;
621 return S_OK;
624 static HRESULT WINAPI HTMLDOMNode_get_lastChild(IHTMLDOMNode *iface, IHTMLDOMNode **p)
626 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
627 nsIDOMNode *nschild = NULL;
629 TRACE("(%p)->(%p)\n", This, p);
631 nsIDOMNode_GetLastChild(This->nsnode, &nschild);
632 if(nschild) {
633 *p = HTMLDOMNODE(get_node(This->doc, nschild, TRUE));
634 IHTMLDOMNode_AddRef(*p);
635 }else {
636 *p = NULL;
639 return S_OK;
642 static HRESULT WINAPI HTMLDOMNode_get_previousSibling(IHTMLDOMNode *iface, IHTMLDOMNode **p)
644 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
645 FIXME("(%p)->(%p)\n", This, p);
646 return E_NOTIMPL;
649 static HRESULT WINAPI HTMLDOMNode_get_nextSibling(IHTMLDOMNode *iface, IHTMLDOMNode **p)
651 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
652 FIXME("(%p)->(%p)\n", This, p);
653 return E_NOTIMPL;
656 #undef HTMLDOMNODE_THIS
658 static const IHTMLDOMNodeVtbl HTMLDOMNodeVtbl = {
659 HTMLDOMNode_QueryInterface,
660 HTMLDOMNode_AddRef,
661 HTMLDOMNode_Release,
662 HTMLDOMNode_GetTypeInfoCount,
663 HTMLDOMNode_GetTypeInfo,
664 HTMLDOMNode_GetIDsOfNames,
665 HTMLDOMNode_Invoke,
666 HTMLDOMNode_get_nodeType,
667 HTMLDOMNode_get_parentNode,
668 HTMLDOMNode_hasChildNodes,
669 HTMLDOMNode_get_childNodes,
670 HTMLDOMNode_get_attributes,
671 HTMLDOMNode_insertBefore,
672 HTMLDOMNode_removeChild,
673 HTMLDOMNode_replaceChild,
674 HTMLDOMNode_cloneNode,
675 HTMLDOMNode_removeNode,
676 HTMLDOMNode_swapNode,
677 HTMLDOMNode_replaceNode,
678 HTMLDOMNode_appendChild,
679 HTMLDOMNode_get_nodeName,
680 HTMLDOMNode_put_nodeValue,
681 HTMLDOMNode_get_nodeValue,
682 HTMLDOMNode_get_firstChild,
683 HTMLDOMNode_get_lastChild,
684 HTMLDOMNode_get_previousSibling,
685 HTMLDOMNode_get_nextSibling
688 #define HTMLDOMNODE2_THIS(iface) DEFINE_THIS(HTMLDOMNode, HTMLDOMNode2, iface)
690 static HRESULT WINAPI HTMLDOMNode2_QueryInterface(IHTMLDOMNode2 *iface,
691 REFIID riid, void **ppv)
693 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
695 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(This), riid, ppv);
698 static ULONG WINAPI HTMLDOMNode2_AddRef(IHTMLDOMNode2 *iface)
700 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
702 return IHTMLDOMNode_AddRef(HTMLDOMNODE(This));
705 static ULONG WINAPI HTMLDOMNode2_Release(IHTMLDOMNode2 *iface)
707 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
709 return IHTMLDOMNode_Release(HTMLDOMNODE(This));
712 static HRESULT WINAPI HTMLDOMNode2_GetTypeInfoCount(IHTMLDOMNode2 *iface, UINT *pctinfo)
714 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
715 FIXME("(%p)->(%p)\n", This, pctinfo);
716 return E_NOTIMPL;
719 static HRESULT WINAPI HTMLDOMNode2_GetTypeInfo(IHTMLDOMNode2 *iface, UINT iTInfo,
720 LCID lcid, ITypeInfo **ppTInfo)
722 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
723 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
724 return E_NOTIMPL;
727 static HRESULT WINAPI HTMLDOMNode2_GetIDsOfNames(IHTMLDOMNode2 *iface, REFIID riid,
728 LPOLESTR *rgszNames, UINT cNames,
729 LCID lcid, DISPID *rgDispId)
731 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
732 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
733 lcid, rgDispId);
734 return E_NOTIMPL;
737 static HRESULT WINAPI HTMLDOMNode2_Invoke(IHTMLDOMNode2 *iface, DISPID dispIdMember,
738 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
739 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
741 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
742 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
743 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
744 return E_NOTIMPL;
747 static HRESULT WINAPI HTMLDOMNode2_get_ownerDocument(IHTMLDOMNode2 *iface, IDispatch **p)
749 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
750 FIXME("(%p)->(%p)\n", This, p);
751 return E_NOTIMPL;
754 #undef HTMLDOMNODE2_THIS
756 static const IHTMLDOMNode2Vtbl HTMLDOMNode2Vtbl = {
757 HTMLDOMNode2_QueryInterface,
758 HTMLDOMNode2_AddRef,
759 HTMLDOMNode2_Release,
760 HTMLDOMNode2_GetTypeInfoCount,
761 HTMLDOMNode2_GetTypeInfo,
762 HTMLDOMNode2_GetIDsOfNames,
763 HTMLDOMNode2_Invoke,
764 HTMLDOMNode2_get_ownerDocument
767 HRESULT HTMLDOMNode_QI(HTMLDOMNode *This, REFIID riid, void **ppv)
769 *ppv = NULL;
771 if(IsEqualGUID(&IID_IUnknown, riid)) {
772 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
773 *ppv = HTMLDOMNODE(This);
774 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
775 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
776 *ppv = HTMLDOMNODE(This);
777 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
778 if(This->dispex.data) {
779 TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
780 *ppv = DISPATCHEX(&This->dispex);
781 }else {
782 FIXME("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
783 return E_NOINTERFACE;
785 }else if(IsEqualGUID(&IID_IHTMLDOMNode, riid)) {
786 TRACE("(%p)->(IID_IHTMLDOMNode %p)\n", This, ppv);
787 *ppv = HTMLDOMNODE(This);
788 }else if(IsEqualGUID(&IID_IHTMLDOMNode2, riid)) {
789 TRACE("(%p)->(IID_IHTMLDOMNode2 %p)\n", This, ppv);
790 *ppv = HTMLDOMNODE2(This);
793 if(*ppv) {
794 IUnknown_AddRef((IUnknown*)*ppv);
795 return S_OK;
798 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
799 return E_NOINTERFACE;
802 void HTMLDOMNode_destructor(HTMLDOMNode *This)
804 if(This->nsnode)
805 nsIDOMNode_Release(This->nsnode);
806 if(This->event_target)
807 release_event_target(This->event_target);
810 static const NodeImplVtbl HTMLDOMNodeImplVtbl = {
811 HTMLDOMNode_QI,
812 HTMLDOMNode_destructor
815 void HTMLDOMNode_Init(HTMLDocument *doc, HTMLDOMNode *node, nsIDOMNode *nsnode)
817 node->lpHTMLDOMNodeVtbl = &HTMLDOMNodeVtbl;
818 node->lpHTMLDOMNode2Vtbl = &HTMLDOMNode2Vtbl;
819 node->ref = 1;
820 node->doc = doc;
822 nsIDOMNode_AddRef(nsnode);
823 node->nsnode = nsnode;
825 node->next = doc->nodes;
826 doc->nodes = node;
829 static HTMLDOMNode *create_node(HTMLDocument *doc, nsIDOMNode *nsnode)
831 HTMLDOMNode *ret;
832 PRUint16 node_type;
834 nsIDOMNode_GetNodeType(nsnode, &node_type);
836 switch(node_type) {
837 case ELEMENT_NODE:
838 ret = &HTMLElement_Create(doc, nsnode, FALSE)->node;
839 break;
840 case TEXT_NODE:
841 ret = HTMLDOMTextNode_Create(doc, nsnode);
842 break;
843 case COMMENT_NODE:
844 ret = &HTMLCommentElement_Create(doc, nsnode)->node;
845 break;
846 default:
847 ret = heap_alloc_zero(sizeof(HTMLDOMNode));
848 ret->vtbl = &HTMLDOMNodeImplVtbl;
849 HTMLDOMNode_Init(doc, ret, nsnode);
852 TRACE("type %d ret %p\n", node_type, ret);
854 return ret;
858 * FIXME
859 * List looks really ugly here. We should use a better data structure or
860 * (better) find a way to store HTMLDOMelement pointer in nsIDOMNode.
863 HTMLDOMNode *get_node(HTMLDocument *This, nsIDOMNode *nsnode, BOOL create)
865 HTMLDOMNode *iter = This->nodes;
867 while(iter) {
868 if(iter->nsnode == nsnode)
869 break;
870 iter = iter->next;
873 if(iter || !create)
874 return iter;
876 return create_node(This, nsnode);
880 * FIXME
881 * We should use better way for getting node object (like private interface)
882 * or avoid it at all.
884 static HTMLDOMNode *get_node_obj(HTMLDocument *This, IUnknown *iface)
886 HTMLDOMNode *iter = This->nodes;
887 IHTMLDOMNode *node;
889 IUnknown_QueryInterface(iface, &IID_IHTMLDOMNode, (void**)&node);
890 IHTMLDOMNode_Release(node);
892 while(iter) {
893 if(HTMLDOMNODE(iter) == node)
894 return iter;
895 iter = iter->next;
898 FIXME("Not found %p\n", iface);
899 return NULL;
902 void release_nodes(HTMLDocument *This)
904 HTMLDOMNode *iter, *next;
906 if(!This->nodes)
907 return;
909 for(iter = This->nodes; iter; iter = next) {
910 next = iter->next;
911 iter->doc = NULL;
912 IHTMLDOMNode_Release(HTMLDOMNODE(iter));