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
28 #include "wine/debug.h"
30 #include "mshtml_private.h"
31 #include "htmlevent.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
35 static HTMLDOMNode *get_node_obj(HTMLDocumentNode*,IUnknown*);
36 static HRESULT create_node(HTMLDocumentNode*,nsIDOMNode*,HTMLDOMNode**);
40 IHTMLDOMChildrenCollection IHTMLDOMChildrenCollection_iface;
44 /* FIXME: implement weak reference */
45 HTMLDocumentNode *doc;
47 nsIDOMNodeList *nslist;
48 } HTMLDOMChildrenCollection;
50 static inline HTMLDOMChildrenCollection *impl_from_IHTMLDOMChildrenCollection(IHTMLDOMChildrenCollection *iface)
52 return CONTAINING_RECORD(iface, HTMLDOMChildrenCollection, IHTMLDOMChildrenCollection_iface);
55 static HRESULT WINAPI HTMLDOMChildrenCollection_QueryInterface(IHTMLDOMChildrenCollection *iface, REFIID riid, void **ppv)
57 HTMLDOMChildrenCollection *This = impl_from_IHTMLDOMChildrenCollection(iface);
61 if(IsEqualGUID(&IID_IUnknown, riid)) {
62 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
63 *ppv = &This->IHTMLDOMChildrenCollection_iface;
64 }else if(IsEqualGUID(&IID_IHTMLDOMChildrenCollection, riid)) {
65 TRACE("(%p)->(IID_IHTMLDOMChildrenCollection %p)\n", This, ppv);
66 *ppv = &This->IHTMLDOMChildrenCollection_iface;
67 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
68 return *ppv ? S_OK : E_NOINTERFACE;
72 IUnknown_AddRef((IUnknown*)*ppv);
76 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
80 static ULONG WINAPI HTMLDOMChildrenCollection_AddRef(IHTMLDOMChildrenCollection *iface)
82 HTMLDOMChildrenCollection *This = impl_from_IHTMLDOMChildrenCollection(iface);
83 LONG ref = InterlockedIncrement(&This->ref);
85 TRACE("(%p) ref=%d\n", This, ref);
90 static ULONG WINAPI HTMLDOMChildrenCollection_Release(IHTMLDOMChildrenCollection *iface)
92 HTMLDOMChildrenCollection *This = impl_from_IHTMLDOMChildrenCollection(iface);
93 LONG ref = InterlockedDecrement(&This->ref);
95 TRACE("(%p) ref=%d\n", This, ref);
98 nsIDOMNodeList_Release(This->nslist);
105 static HRESULT WINAPI HTMLDOMChildrenCollection_GetTypeInfoCount(IHTMLDOMChildrenCollection *iface, UINT *pctinfo)
107 HTMLDOMChildrenCollection *This = impl_from_IHTMLDOMChildrenCollection(iface);
108 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
111 static HRESULT WINAPI HTMLDOMChildrenCollection_GetTypeInfo(IHTMLDOMChildrenCollection *iface, UINT iTInfo,
112 LCID lcid, ITypeInfo **ppTInfo)
114 HTMLDOMChildrenCollection *This = impl_from_IHTMLDOMChildrenCollection(iface);
115 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
118 static HRESULT WINAPI HTMLDOMChildrenCollection_GetIDsOfNames(IHTMLDOMChildrenCollection *iface, REFIID riid,
119 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
121 HTMLDOMChildrenCollection *This = impl_from_IHTMLDOMChildrenCollection(iface);
122 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
126 static HRESULT WINAPI HTMLDOMChildrenCollection_Invoke(IHTMLDOMChildrenCollection *iface, DISPID dispIdMember,
127 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
128 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
130 HTMLDOMChildrenCollection *This = impl_from_IHTMLDOMChildrenCollection(iface);
131 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
132 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
135 static HRESULT WINAPI HTMLDOMChildrenCollection_get_length(IHTMLDOMChildrenCollection *iface, LONG *p)
137 HTMLDOMChildrenCollection *This = impl_from_IHTMLDOMChildrenCollection(iface);
140 TRACE("(%p)->(%p)\n", This, p);
142 nsIDOMNodeList_GetLength(This->nslist, &length);
147 static HRESULT WINAPI HTMLDOMChildrenCollection__newEnum(IHTMLDOMChildrenCollection *iface, IUnknown **p)
149 HTMLDOMChildrenCollection *This = impl_from_IHTMLDOMChildrenCollection(iface);
150 FIXME("(%p)->(%p)\n", This, p);
154 static HRESULT WINAPI HTMLDOMChildrenCollection_item(IHTMLDOMChildrenCollection *iface, LONG index, IDispatch **ppItem)
156 HTMLDOMChildrenCollection *This = impl_from_IHTMLDOMChildrenCollection(iface);
157 nsIDOMNode *nsnode = NULL;
163 TRACE("(%p)->(%d %p)\n", This, index, ppItem);
170 nsIDOMNodeList_GetLength(This->nslist, &length);
171 if(index < 0 || index >= length)
174 nsres = nsIDOMNodeList_Item(This->nslist, index, &nsnode);
175 if(NS_FAILED(nsres) || !nsnode) {
176 ERR("Item failed: %08x\n", nsres);
180 hres = get_node(This->doc, nsnode, TRUE, &node);
184 *ppItem = (IDispatch*)&node->IHTMLDOMNode_iface;
185 IDispatch_AddRef(*ppItem);
189 static const IHTMLDOMChildrenCollectionVtbl HTMLDOMChildrenCollectionVtbl = {
190 HTMLDOMChildrenCollection_QueryInterface,
191 HTMLDOMChildrenCollection_AddRef,
192 HTMLDOMChildrenCollection_Release,
193 HTMLDOMChildrenCollection_GetTypeInfoCount,
194 HTMLDOMChildrenCollection_GetTypeInfo,
195 HTMLDOMChildrenCollection_GetIDsOfNames,
196 HTMLDOMChildrenCollection_Invoke,
197 HTMLDOMChildrenCollection_get_length,
198 HTMLDOMChildrenCollection__newEnum,
199 HTMLDOMChildrenCollection_item
202 static inline HTMLDOMChildrenCollection *impl_from_DispatchEx(DispatchEx *iface)
204 return CONTAINING_RECORD(iface, HTMLDOMChildrenCollection, dispex);
207 #define DISPID_CHILDCOL_0 MSHTML_DISPID_CUSTOM_MIN
209 static HRESULT HTMLDOMChildrenCollection_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
211 HTMLDOMChildrenCollection *This = impl_from_DispatchEx(dispex);
216 for(ptr = name; *ptr && isdigitW(*ptr); ptr++)
217 idx = idx*10 + (*ptr-'0');
219 return DISP_E_UNKNOWNNAME;
221 nsIDOMNodeList_GetLength(This->nslist, &len);
223 return DISP_E_UNKNOWNNAME;
225 *dispid = DISPID_CHILDCOL_0 + idx;
226 TRACE("ret %x\n", *dispid);
230 static HRESULT HTMLDOMChildrenCollection_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
231 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
233 HTMLDOMChildrenCollection *This = impl_from_DispatchEx(dispex);
235 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
238 case DISPATCH_PROPERTYGET: {
239 IDispatch *disp = NULL;
242 hres = IHTMLDOMChildrenCollection_item(&This->IHTMLDOMChildrenCollection_iface,
243 id - DISPID_CHILDCOL_0, &disp);
247 V_VT(res) = VT_DISPATCH;
248 V_DISPATCH(res) = disp;
253 FIXME("unimplemented flags %x\n", flags);
260 static const dispex_static_data_vtbl_t HTMLDOMChildrenCollection_dispex_vtbl = {
262 HTMLDOMChildrenCollection_get_dispid,
263 HTMLDOMChildrenCollection_invoke
266 static const tid_t HTMLDOMChildrenCollection_iface_tids[] = {
267 IHTMLDOMChildrenCollection_tid,
271 static dispex_static_data_t HTMLDOMChildrenCollection_dispex = {
272 &HTMLDOMChildrenCollection_dispex_vtbl,
273 DispDOMChildrenCollection_tid,
275 HTMLDOMChildrenCollection_iface_tids
278 static IHTMLDOMChildrenCollection *create_child_collection(HTMLDocumentNode *doc, nsIDOMNodeList *nslist)
280 HTMLDOMChildrenCollection *ret;
282 ret = heap_alloc_zero(sizeof(*ret));
283 ret->IHTMLDOMChildrenCollection_iface.lpVtbl = &HTMLDOMChildrenCollectionVtbl;
286 nsIDOMNodeList_AddRef(nslist);
287 ret->nslist = nslist;
290 init_dispex(&ret->dispex, (IUnknown*)&ret->IHTMLDOMChildrenCollection_iface,
291 &HTMLDOMChildrenCollection_dispex);
293 return &ret->IHTMLDOMChildrenCollection_iface;
296 static inline HTMLDOMNode *impl_from_IHTMLDOMNode(IHTMLDOMNode *iface)
298 return CONTAINING_RECORD(iface, HTMLDOMNode, IHTMLDOMNode_iface);
301 static HRESULT WINAPI HTMLDOMNode_QueryInterface(IHTMLDOMNode *iface,
302 REFIID riid, void **ppv)
304 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
306 return This->vtbl->qi(This, riid, ppv);
309 static ULONG WINAPI HTMLDOMNode_AddRef(IHTMLDOMNode *iface)
311 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
312 LONG ref = InterlockedIncrement(&This->ref);
314 TRACE("(%p) ref=%d\n", This, ref);
319 static ULONG WINAPI HTMLDOMNode_Release(IHTMLDOMNode *iface)
321 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
322 LONG ref = InterlockedDecrement(&This->ref);
324 TRACE("(%p) ref=%d\n", This, ref);
327 This->vtbl->destructor(This);
328 release_dispex(&This->dispex);
335 static HRESULT WINAPI HTMLDOMNode_GetTypeInfoCount(IHTMLDOMNode *iface, UINT *pctinfo)
337 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
338 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
341 static HRESULT WINAPI HTMLDOMNode_GetTypeInfo(IHTMLDOMNode *iface, UINT iTInfo,
342 LCID lcid, ITypeInfo **ppTInfo)
344 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
345 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
348 static HRESULT WINAPI HTMLDOMNode_GetIDsOfNames(IHTMLDOMNode *iface, REFIID riid,
349 LPOLESTR *rgszNames, UINT cNames,
350 LCID lcid, DISPID *rgDispId)
352 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
353 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
357 static HRESULT WINAPI HTMLDOMNode_Invoke(IHTMLDOMNode *iface, DISPID dispIdMember,
358 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
359 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
361 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
362 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
363 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
366 static HRESULT WINAPI HTMLDOMNode_get_nodeType(IHTMLDOMNode *iface, LONG *p)
368 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
371 TRACE("(%p)->(%p)\n", This, p);
373 nsIDOMNode_GetNodeType(This->nsnode, &type);
388 case DOCUMENT_FRAGMENT_NODE:
394 * According to MSDN only ELEMENT_NODE and TEXT_NODE are supported.
395 * It needs more tests.
397 FIXME("type %u\n", type);
404 static HRESULT WINAPI HTMLDOMNode_get_parentNode(IHTMLDOMNode *iface, IHTMLDOMNode **p)
406 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
412 TRACE("(%p)->(%p)\n", This, p);
414 nsres = nsIDOMNode_GetParentNode(This->nsnode, &nsnode);
415 if(NS_FAILED(nsres)) {
416 ERR("GetParentNode failed: %08x\n", nsres);
425 hres = get_node(This->doc, nsnode, TRUE, &node);
426 nsIDOMNode_Release(nsnode);
430 *p = &node->IHTMLDOMNode_iface;
431 IHTMLDOMNode_AddRef(*p);
435 static HRESULT WINAPI HTMLDOMNode_hasChildNodes(IHTMLDOMNode *iface, VARIANT_BOOL *fChildren)
437 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
438 PRBool has_child = FALSE;
441 TRACE("(%p)->(%p)\n", This, fChildren);
443 nsres = nsIDOMNode_HasChildNodes(This->nsnode, &has_child);
445 ERR("HasChildNodes failed: %08x\n", nsres);
447 *fChildren = has_child ? VARIANT_TRUE : VARIANT_FALSE;
451 static HRESULT WINAPI HTMLDOMNode_get_childNodes(IHTMLDOMNode *iface, IDispatch **p)
453 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
454 nsIDOMNodeList *nslist;
457 TRACE("(%p)->(%p)\n", This, p);
459 nsres = nsIDOMNode_GetChildNodes(This->nsnode, &nslist);
460 if(NS_FAILED(nsres)) {
461 ERR("GetChildNodes failed: %08x\n", nsres);
465 *p = (IDispatch*)create_child_collection(This->doc, nslist);
466 nsIDOMNodeList_Release(nslist);
471 static HRESULT WINAPI HTMLDOMNode_get_attributes(IHTMLDOMNode *iface, IDispatch **p)
473 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
474 FIXME("(%p)->(%p)\n", This, p);
478 static HRESULT WINAPI HTMLDOMNode_insertBefore(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
479 VARIANT refChild, IHTMLDOMNode **node)
481 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
482 nsIDOMNode *nsnode, *nsref = NULL;
483 HTMLDOMNode *new_child;
484 HTMLDOMNode *node_obj;
488 TRACE("(%p)->(%p %s %p)\n", This, newChild, debugstr_variant(&refChild), node);
490 new_child = get_node_obj(This->doc, (IUnknown*)newChild);
492 ERR("invalid newChild\n");
496 switch(V_VT(&refChild)) {
500 HTMLDOMNode *ref_node;
502 ref_node = get_node_obj(This->doc, (IUnknown*)V_DISPATCH(&refChild));
504 ERR("unvalid node\n");
508 nsref = ref_node->nsnode;
512 FIXME("unimplemented vt %d\n", V_VT(&refChild));
516 nsres = nsIDOMNode_InsertBefore(This->nsnode, new_child->nsnode, nsref, &nsnode);
517 if(NS_FAILED(nsres)) {
518 ERR("InsertBefore failed: %08x\n", nsres);
522 hres = get_node(This->doc, nsnode, TRUE, &node_obj);
523 nsIDOMNode_Release(nsnode);
527 *node = &node_obj->IHTMLDOMNode_iface;
528 IHTMLDOMNode_AddRef(*node);
532 static HRESULT WINAPI HTMLDOMNode_removeChild(IHTMLDOMNode *iface, IHTMLDOMNode *oldChild,
535 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
536 HTMLDOMNode *node_obj;
541 TRACE("(%p)->(%p %p)\n", This, oldChild, node);
543 node_obj = get_node_obj(This->doc, (IUnknown*)oldChild);
547 nsres = nsIDOMNode_RemoveChild(This->nsnode, node_obj->nsnode, &nsnode);
548 if(NS_FAILED(nsres)) {
549 ERR("RemoveChild failed: %08x\n", nsres);
553 hres = get_node(This->doc, nsnode, TRUE, &node_obj);
554 nsIDOMNode_Release(nsnode);
558 /* FIXME: Make sure that node != newChild */
559 *node = &node_obj->IHTMLDOMNode_iface;
560 IHTMLDOMNode_AddRef(*node);
564 static HRESULT WINAPI HTMLDOMNode_replaceChild(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
565 IHTMLDOMNode *oldChild, IHTMLDOMNode **node)
567 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
568 FIXME("(%p)->(%p %p %p)\n", This, newChild, oldChild, node);
572 static HRESULT WINAPI HTMLDOMNode_cloneNode(IHTMLDOMNode *iface, VARIANT_BOOL fDeep,
573 IHTMLDOMNode **clonedNode)
575 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
576 HTMLDOMNode *new_node;
581 TRACE("(%p)->(%x %p)\n", This, fDeep, clonedNode);
583 nsres = nsIDOMNode_CloneNode(This->nsnode, fDeep != VARIANT_FALSE, &nsnode);
584 if(NS_FAILED(nsres) || !nsnode) {
585 ERR("CloneNode failed: %08x\n", nsres);
589 hres = This->vtbl->clone(This, nsnode, &new_node);
593 *clonedNode = &new_node->IHTMLDOMNode_iface;
597 static HRESULT WINAPI HTMLDOMNode_removeNode(IHTMLDOMNode *iface, VARIANT_BOOL fDeep,
598 IHTMLDOMNode **removed)
600 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
601 FIXME("(%p)->(%x %p)\n", This, fDeep, removed);
605 static HRESULT WINAPI HTMLDOMNode_swapNode(IHTMLDOMNode *iface, IHTMLDOMNode *otherNode,
606 IHTMLDOMNode **swappedNode)
608 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
609 FIXME("(%p)->(%p %p)\n", This, otherNode, swappedNode);
613 static HRESULT WINAPI HTMLDOMNode_replaceNode(IHTMLDOMNode *iface, IHTMLDOMNode *replacement,
614 IHTMLDOMNode **replaced)
616 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
617 FIXME("(%p)->(%p %p)\n", This, replacement, replaced);
621 static HRESULT WINAPI HTMLDOMNode_appendChild(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
624 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
625 HTMLDOMNode *node_obj;
630 TRACE("(%p)->(%p %p)\n", This, newChild, node);
632 node_obj = get_node_obj(This->doc, (IUnknown*)newChild);
636 nsres = nsIDOMNode_AppendChild(This->nsnode, node_obj->nsnode, &nsnode);
637 if(NS_FAILED(nsres)) {
638 WARN("AppendChild failed: %08x\n", nsres);
639 nsnode = node_obj->nsnode;
642 hres = get_node(This->doc, nsnode, TRUE, &node_obj);
643 nsIDOMNode_Release(nsnode);
647 /* FIXME: Make sure that node != newChild */
648 *node = &node_obj->IHTMLDOMNode_iface;
649 IHTMLDOMNode_AddRef(*node);
653 static HRESULT WINAPI HTMLDOMNode_get_nodeName(IHTMLDOMNode *iface, BSTR *p)
655 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
657 TRACE("(%p)->(%p)\n", This, p);
663 const PRUnichar *name;
666 nsAString_Init(&name_str, NULL);
667 nsres = nsIDOMNode_GetNodeName(This->nsnode, &name_str);
669 if(NS_SUCCEEDED(nsres)) {
670 nsAString_GetData(&name_str, &name);
671 *p = SysAllocString(name);
673 ERR("GetNodeName failed: %08x\n", nsres);
676 nsAString_Finish(&name_str);
682 static HRESULT WINAPI HTMLDOMNode_put_nodeValue(IHTMLDOMNode *iface, VARIANT v)
684 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
686 TRACE("(%p)->()\n", This);
692 TRACE("bstr %s\n", debugstr_w(V_BSTR(&v)));
694 nsAString_InitDepend(&val_str, V_BSTR(&v));
695 nsIDOMNode_SetNodeValue(This->nsnode, &val_str);
696 nsAString_Finish(&val_str);
702 FIXME("unsupported vt %d\n", V_VT(&v));
708 static HRESULT WINAPI HTMLDOMNode_get_nodeValue(IHTMLDOMNode *iface, VARIANT *p)
710 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
711 const PRUnichar *val;
714 TRACE("(%p)->(%p)\n", This, p);
716 nsAString_Init(&val_str, NULL);
717 nsIDOMNode_GetNodeValue(This->nsnode, &val_str);
718 nsAString_GetData(&val_str, &val);
722 V_BSTR(p) = SysAllocString(val);
727 nsAString_Finish(&val_str);
732 static HRESULT WINAPI HTMLDOMNode_get_firstChild(IHTMLDOMNode *iface, IHTMLDOMNode **p)
734 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
735 nsIDOMNode *nschild = NULL;
739 TRACE("(%p)->(%p)\n", This, p);
741 nsIDOMNode_GetFirstChild(This->nsnode, &nschild);
747 hres = get_node(This->doc, nschild, TRUE, &node);
748 nsIDOMNode_Release(nschild);
752 *p = &node->IHTMLDOMNode_iface;
753 IHTMLDOMNode_AddRef(*p);
757 static HRESULT WINAPI HTMLDOMNode_get_lastChild(IHTMLDOMNode *iface, IHTMLDOMNode **p)
759 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
760 nsIDOMNode *nschild = NULL;
764 TRACE("(%p)->(%p)\n", This, p);
766 nsIDOMNode_GetLastChild(This->nsnode, &nschild);
772 hres = get_node(This->doc, nschild, TRUE, &node);
773 nsIDOMNode_Release(nschild);
777 *p = &node->IHTMLDOMNode_iface;
778 IHTMLDOMNode_AddRef(*p);
782 static HRESULT WINAPI HTMLDOMNode_get_previousSibling(IHTMLDOMNode *iface, IHTMLDOMNode **p)
784 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
785 FIXME("(%p)->(%p)\n", This, p);
789 static HRESULT WINAPI HTMLDOMNode_get_nextSibling(IHTMLDOMNode *iface, IHTMLDOMNode **p)
791 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
792 nsIDOMNode *nssibling = NULL;
796 TRACE("(%p)->(%p)\n", This, p);
798 nsIDOMNode_GetNextSibling(This->nsnode, &nssibling);
804 hres = get_node(This->doc, nssibling, TRUE, &node);
805 nsIDOMNode_Release(nssibling);
809 *p = &node->IHTMLDOMNode_iface;
810 IHTMLDOMNode_AddRef(*p);
814 static const IHTMLDOMNodeVtbl HTMLDOMNodeVtbl = {
815 HTMLDOMNode_QueryInterface,
818 HTMLDOMNode_GetTypeInfoCount,
819 HTMLDOMNode_GetTypeInfo,
820 HTMLDOMNode_GetIDsOfNames,
822 HTMLDOMNode_get_nodeType,
823 HTMLDOMNode_get_parentNode,
824 HTMLDOMNode_hasChildNodes,
825 HTMLDOMNode_get_childNodes,
826 HTMLDOMNode_get_attributes,
827 HTMLDOMNode_insertBefore,
828 HTMLDOMNode_removeChild,
829 HTMLDOMNode_replaceChild,
830 HTMLDOMNode_cloneNode,
831 HTMLDOMNode_removeNode,
832 HTMLDOMNode_swapNode,
833 HTMLDOMNode_replaceNode,
834 HTMLDOMNode_appendChild,
835 HTMLDOMNode_get_nodeName,
836 HTMLDOMNode_put_nodeValue,
837 HTMLDOMNode_get_nodeValue,
838 HTMLDOMNode_get_firstChild,
839 HTMLDOMNode_get_lastChild,
840 HTMLDOMNode_get_previousSibling,
841 HTMLDOMNode_get_nextSibling
844 static inline HTMLDOMNode *impl_from_IHTMLDOMNode2(IHTMLDOMNode2 *iface)
846 return CONTAINING_RECORD(iface, HTMLDOMNode, IHTMLDOMNode2_iface);
849 static HRESULT WINAPI HTMLDOMNode2_QueryInterface(IHTMLDOMNode2 *iface,
850 REFIID riid, void **ppv)
852 HTMLDOMNode *This = impl_from_IHTMLDOMNode2(iface);
854 return IHTMLDOMNode_QueryInterface(&This->IHTMLDOMNode_iface, riid, ppv);
857 static ULONG WINAPI HTMLDOMNode2_AddRef(IHTMLDOMNode2 *iface)
859 HTMLDOMNode *This = impl_from_IHTMLDOMNode2(iface);
861 return IHTMLDOMNode_AddRef(&This->IHTMLDOMNode_iface);
864 static ULONG WINAPI HTMLDOMNode2_Release(IHTMLDOMNode2 *iface)
866 HTMLDOMNode *This = impl_from_IHTMLDOMNode2(iface);
868 return IHTMLDOMNode_Release(&This->IHTMLDOMNode_iface);
871 static HRESULT WINAPI HTMLDOMNode2_GetTypeInfoCount(IHTMLDOMNode2 *iface, UINT *pctinfo)
873 HTMLDOMNode *This = impl_from_IHTMLDOMNode2(iface);
874 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
877 static HRESULT WINAPI HTMLDOMNode2_GetTypeInfo(IHTMLDOMNode2 *iface, UINT iTInfo,
878 LCID lcid, ITypeInfo **ppTInfo)
880 HTMLDOMNode *This = impl_from_IHTMLDOMNode2(iface);
881 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
884 static HRESULT WINAPI HTMLDOMNode2_GetIDsOfNames(IHTMLDOMNode2 *iface, REFIID riid,
885 LPOLESTR *rgszNames, UINT cNames,
886 LCID lcid, DISPID *rgDispId)
888 HTMLDOMNode *This = impl_from_IHTMLDOMNode2(iface);
889 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
893 static HRESULT WINAPI HTMLDOMNode2_Invoke(IHTMLDOMNode2 *iface, DISPID dispIdMember,
894 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
895 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
897 HTMLDOMNode *This = impl_from_IHTMLDOMNode2(iface);
898 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
899 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
902 static HRESULT WINAPI HTMLDOMNode2_get_ownerDocument(IHTMLDOMNode2 *iface, IDispatch **p)
904 HTMLDOMNode *This = impl_from_IHTMLDOMNode2(iface);
906 TRACE("(%p)->(%p)\n", This, p);
908 /* FIXME: Better check for document node */
909 if(This == &This->doc->node) {
912 *p = (IDispatch*)&This->doc->basedoc.IHTMLDocument2_iface;
913 IDispatch_AddRef(*p);
918 static const IHTMLDOMNode2Vtbl HTMLDOMNode2Vtbl = {
919 HTMLDOMNode2_QueryInterface,
921 HTMLDOMNode2_Release,
922 HTMLDOMNode2_GetTypeInfoCount,
923 HTMLDOMNode2_GetTypeInfo,
924 HTMLDOMNode2_GetIDsOfNames,
926 HTMLDOMNode2_get_ownerDocument
929 HRESULT HTMLDOMNode_QI(HTMLDOMNode *This, REFIID riid, void **ppv)
933 if(IsEqualGUID(&IID_IUnknown, riid)) {
934 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
935 *ppv = &This->IHTMLDOMNode_iface;
936 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
937 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
938 *ppv = &This->IHTMLDOMNode_iface;
939 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
940 if(This->dispex.data) {
941 TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
942 *ppv = &This->dispex.IDispatchEx_iface;
944 FIXME("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
945 return E_NOINTERFACE;
947 }else if(IsEqualGUID(&IID_IHTMLDOMNode, riid)) {
948 TRACE("(%p)->(IID_IHTMLDOMNode %p)\n", This, ppv);
949 *ppv = &This->IHTMLDOMNode_iface;
950 }else if(IsEqualGUID(&IID_IHTMLDOMNode2, riid)) {
951 TRACE("(%p)->(IID_IHTMLDOMNode2 %p)\n", This, ppv);
952 *ppv = &This->IHTMLDOMNode2_iface;
953 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
954 return *ppv ? S_OK : E_NOINTERFACE;
958 IUnknown_AddRef((IUnknown*)*ppv);
962 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
963 return E_NOINTERFACE;
966 void HTMLDOMNode_destructor(HTMLDOMNode *This)
969 nsIDOMNode_Release(This->nsnode);
970 if(This->event_target)
971 release_event_target(This->event_target);
974 static HRESULT HTMLDOMNode_clone(HTMLDOMNode *This, nsIDOMNode *nsnode, HTMLDOMNode **ret)
978 hres = create_node(This->doc, nsnode, ret);
982 IHTMLDOMNode_AddRef(&(*ret)->IHTMLDOMNode_iface);
986 static const NodeImplVtbl HTMLDOMNodeImplVtbl = {
988 HTMLDOMNode_destructor,
992 void HTMLDOMNode_Init(HTMLDocumentNode *doc, HTMLDOMNode *node, nsIDOMNode *nsnode)
994 node->IHTMLDOMNode_iface.lpVtbl = &HTMLDOMNodeVtbl;
995 node->IHTMLDOMNode2_iface.lpVtbl = &HTMLDOMNode2Vtbl;
1000 nsIDOMNode_AddRef(nsnode);
1001 node->nsnode = nsnode;
1003 node->next = doc->nodes;
1007 static HRESULT create_node(HTMLDocumentNode *doc, nsIDOMNode *nsnode, HTMLDOMNode **ret)
1012 nsIDOMNode_GetNodeType(nsnode, &node_type);
1015 case ELEMENT_NODE: {
1017 hres = HTMLElement_Create(doc, nsnode, FALSE, &elem);
1024 hres = HTMLDOMTextNode_Create(doc, nsnode, ret);
1028 case COMMENT_NODE: {
1029 HTMLElement *comment;
1030 hres = HTMLCommentElement_Create(doc, nsnode, &comment);
1033 *ret = &comment->node;
1039 node = heap_alloc_zero(sizeof(HTMLDOMNode));
1041 return E_OUTOFMEMORY;
1043 node->vtbl = &HTMLDOMNodeImplVtbl;
1044 HTMLDOMNode_Init(doc, node, nsnode);
1049 TRACE("type %d ret %p\n", node_type, *ret);
1055 * List looks really ugly here. We should use a better data structure or
1056 * (better) find a way to store HTMLDOMelement pointer in nsIDOMNode.
1059 HRESULT get_node(HTMLDocumentNode *This, nsIDOMNode *nsnode, BOOL create, HTMLDOMNode **ret)
1061 HTMLDOMNode *iter = This->nodes;
1064 if(iter->nsnode == nsnode)
1069 if(iter || !create) {
1074 return create_node(This, nsnode, ret);
1079 * We should use better way for getting node object (like private interface)
1080 * or avoid it at all.
1082 static HTMLDOMNode *get_node_obj(HTMLDocumentNode *This, IUnknown *iface)
1084 HTMLDOMNode *iter = This->nodes;
1087 IUnknown_QueryInterface(iface, &IID_IHTMLDOMNode, (void**)&node);
1088 IHTMLDOMNode_Release(node);
1091 if(&iter->IHTMLDOMNode_iface == node)
1096 FIXME("Not found %p\n", iface);
1100 void release_nodes(HTMLDocumentNode *This)
1102 HTMLDOMNode *iter, *next;
1107 for(iter = This->nodes; iter; iter = next) {
1110 if(&This->node != iter)
1111 IHTMLDOMNode_Release(&iter->IHTMLDOMNode_iface);