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 const IHTMLDOMChildrenCollectionVtbl *lpIHTMLDOMChildrenCollectionVtbl;
44 /* FIXME: implement weak reference */
45 HTMLDocumentNode *doc;
47 nsIDOMNodeList *nslist;
48 } HTMLDOMChildrenCollection;
50 #define HTMLCHILDCOL(x) ((IHTMLDOMChildrenCollection*) &(x)->lpIHTMLDOMChildrenCollectionVtbl)
52 #define HTMLCHILDCOL_THIS(iface) DEFINE_THIS(HTMLDOMChildrenCollection, IHTMLDOMChildrenCollection, iface)
54 static HRESULT WINAPI HTMLDOMChildrenCollection_QueryInterface(IHTMLDOMChildrenCollection *iface, REFIID riid, void **ppv)
56 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
60 if(IsEqualGUID(&IID_IUnknown, riid)) {
61 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
62 *ppv = HTMLCHILDCOL(This);
63 }else if(IsEqualGUID(&IID_IHTMLDOMChildrenCollection, riid)) {
64 TRACE("(%p)->(IID_IHTMLDOMChildrenCollection %p)\n", This, ppv);
65 *ppv = HTMLCHILDCOL(This);
66 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
67 return *ppv ? S_OK : E_NOINTERFACE;
71 IUnknown_AddRef((IUnknown*)*ppv);
75 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
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);
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);
97 nsIDOMNodeList_Release(This->nslist);
104 static HRESULT WINAPI HTMLDOMChildrenCollection_GetTypeInfoCount(IHTMLDOMChildrenCollection *iface, UINT *pctinfo)
106 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
107 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->dispex), pctinfo);
110 static HRESULT WINAPI HTMLDOMChildrenCollection_GetTypeInfo(IHTMLDOMChildrenCollection *iface, UINT iTInfo,
111 LCID lcid, ITypeInfo **ppTInfo)
113 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
114 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
117 static HRESULT WINAPI HTMLDOMChildrenCollection_GetIDsOfNames(IHTMLDOMChildrenCollection *iface, REFIID riid,
118 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
120 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
121 return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->dispex), riid, rgszNames, cNames, lcid, rgDispId);
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 return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid,
130 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
133 static HRESULT WINAPI HTMLDOMChildrenCollection_get_length(IHTMLDOMChildrenCollection *iface, LONG *p)
135 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
138 TRACE("(%p)->(%p)\n", This, p);
140 nsIDOMNodeList_GetLength(This->nslist, &length);
145 static HRESULT WINAPI HTMLDOMChildrenCollection__newEnum(IHTMLDOMChildrenCollection *iface, IUnknown **p)
147 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
148 FIXME("(%p)->(%p)\n", This, p);
152 static HRESULT WINAPI HTMLDOMChildrenCollection_item(IHTMLDOMChildrenCollection *iface, LONG index, IDispatch **ppItem)
154 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
155 nsIDOMNode *nsnode = NULL;
161 TRACE("(%p)->(%d %p)\n", This, index, ppItem);
168 nsIDOMNodeList_GetLength(This->nslist, &length);
169 if(index < 0 || index >= length)
172 nsres = nsIDOMNodeList_Item(This->nslist, index, &nsnode);
173 if(NS_FAILED(nsres) || !nsnode) {
174 ERR("Item failed: %08x\n", nsres);
178 hres = get_node(This->doc, nsnode, TRUE, &node);
182 *ppItem = (IDispatch*)&node->IHTMLDOMNode_iface;
183 IDispatch_AddRef(*ppItem);
187 #undef HTMLCHILDCOL_THIS
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(HTMLCHILDCOL(This), id - DISPID_CHILDCOL_0, &disp);
246 V_VT(res) = VT_DISPATCH;
247 V_DISPATCH(res) = disp;
252 FIXME("unimplemented flags %x\n", flags);
259 static const dispex_static_data_vtbl_t HTMLDOMChildrenCollection_dispex_vtbl = {
261 HTMLDOMChildrenCollection_get_dispid,
262 HTMLDOMChildrenCollection_invoke
265 static const tid_t HTMLDOMChildrenCollection_iface_tids[] = {
266 IHTMLDOMChildrenCollection_tid,
270 static dispex_static_data_t HTMLDOMChildrenCollection_dispex = {
271 &HTMLDOMChildrenCollection_dispex_vtbl,
272 DispDOMChildrenCollection_tid,
274 HTMLDOMChildrenCollection_iface_tids
277 static IHTMLDOMChildrenCollection *create_child_collection(HTMLDocumentNode *doc, nsIDOMNodeList *nslist)
279 HTMLDOMChildrenCollection *ret;
281 ret = heap_alloc_zero(sizeof(*ret));
282 ret->lpIHTMLDOMChildrenCollectionVtbl = &HTMLDOMChildrenCollectionVtbl;
285 nsIDOMNodeList_AddRef(nslist);
286 ret->nslist = nslist;
289 init_dispex(&ret->dispex, (IUnknown*)HTMLCHILDCOL(ret), &HTMLDOMChildrenCollection_dispex);
291 return HTMLCHILDCOL(ret);
294 static inline HTMLDOMNode *impl_from_IHTMLDOMNode(IHTMLDOMNode *iface)
296 return CONTAINING_RECORD(iface, HTMLDOMNode, IHTMLDOMNode_iface);
299 static HRESULT WINAPI HTMLDOMNode_QueryInterface(IHTMLDOMNode *iface,
300 REFIID riid, void **ppv)
302 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
304 return This->vtbl->qi(This, riid, ppv);
307 static ULONG WINAPI HTMLDOMNode_AddRef(IHTMLDOMNode *iface)
309 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
310 LONG ref = InterlockedIncrement(&This->ref);
312 TRACE("(%p) ref=%d\n", This, ref);
317 static ULONG WINAPI HTMLDOMNode_Release(IHTMLDOMNode *iface)
319 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
320 LONG ref = InterlockedDecrement(&This->ref);
322 TRACE("(%p) ref=%d\n", This, ref);
325 This->vtbl->destructor(This);
326 release_dispex(&This->dispex);
333 static HRESULT WINAPI HTMLDOMNode_GetTypeInfoCount(IHTMLDOMNode *iface, UINT *pctinfo)
335 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
336 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->dispex), pctinfo);
339 static HRESULT WINAPI HTMLDOMNode_GetTypeInfo(IHTMLDOMNode *iface, UINT iTInfo,
340 LCID lcid, ITypeInfo **ppTInfo)
342 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
343 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
346 static HRESULT WINAPI HTMLDOMNode_GetIDsOfNames(IHTMLDOMNode *iface, REFIID riid,
347 LPOLESTR *rgszNames, UINT cNames,
348 LCID lcid, DISPID *rgDispId)
350 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
351 return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->dispex), riid, rgszNames, cNames, lcid, rgDispId);
354 static HRESULT WINAPI HTMLDOMNode_Invoke(IHTMLDOMNode *iface, DISPID dispIdMember,
355 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
356 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
358 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
359 return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid,
360 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
363 static HRESULT WINAPI HTMLDOMNode_get_nodeType(IHTMLDOMNode *iface, LONG *p)
365 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
368 TRACE("(%p)->(%p)\n", This, p);
370 nsIDOMNode_GetNodeType(This->nsnode, &type);
385 case DOCUMENT_FRAGMENT_NODE:
391 * According to MSDN only ELEMENT_NODE and TEXT_NODE are supported.
392 * It needs more tests.
394 FIXME("type %u\n", type);
401 static HRESULT WINAPI HTMLDOMNode_get_parentNode(IHTMLDOMNode *iface, IHTMLDOMNode **p)
403 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
409 TRACE("(%p)->(%p)\n", This, p);
411 nsres = nsIDOMNode_GetParentNode(This->nsnode, &nsnode);
412 if(NS_FAILED(nsres)) {
413 ERR("GetParentNode failed: %08x\n", nsres);
422 hres = get_node(This->doc, nsnode, TRUE, &node);
423 nsIDOMNode_Release(nsnode);
427 *p = &node->IHTMLDOMNode_iface;
428 IHTMLDOMNode_AddRef(*p);
432 static HRESULT WINAPI HTMLDOMNode_hasChildNodes(IHTMLDOMNode *iface, VARIANT_BOOL *fChildren)
434 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
435 PRBool has_child = FALSE;
438 TRACE("(%p)->(%p)\n", This, fChildren);
440 nsres = nsIDOMNode_HasChildNodes(This->nsnode, &has_child);
442 ERR("HasChildNodes failed: %08x\n", nsres);
444 *fChildren = has_child ? VARIANT_TRUE : VARIANT_FALSE;
448 static HRESULT WINAPI HTMLDOMNode_get_childNodes(IHTMLDOMNode *iface, IDispatch **p)
450 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
451 nsIDOMNodeList *nslist;
454 TRACE("(%p)->(%p)\n", This, p);
456 nsres = nsIDOMNode_GetChildNodes(This->nsnode, &nslist);
457 if(NS_FAILED(nsres)) {
458 ERR("GetChildNodes failed: %08x\n", nsres);
462 *p = (IDispatch*)create_child_collection(This->doc, nslist);
463 nsIDOMNodeList_Release(nslist);
468 static HRESULT WINAPI HTMLDOMNode_get_attributes(IHTMLDOMNode *iface, IDispatch **p)
470 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
471 FIXME("(%p)->(%p)\n", This, p);
475 static HRESULT WINAPI HTMLDOMNode_insertBefore(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
476 VARIANT refChild, IHTMLDOMNode **node)
478 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
479 nsIDOMNode *nsnode, *nsref = NULL;
480 HTMLDOMNode *new_child;
481 HTMLDOMNode *node_obj;
485 TRACE("(%p)->(%p %s %p)\n", This, newChild, debugstr_variant(&refChild), node);
487 new_child = get_node_obj(This->doc, (IUnknown*)newChild);
489 ERR("invalid newChild\n");
493 switch(V_VT(&refChild)) {
497 HTMLDOMNode *ref_node;
499 ref_node = get_node_obj(This->doc, (IUnknown*)V_DISPATCH(&refChild));
501 ERR("unvalid node\n");
505 nsref = ref_node->nsnode;
509 FIXME("unimplemented vt %d\n", V_VT(&refChild));
513 nsres = nsIDOMNode_InsertBefore(This->nsnode, new_child->nsnode, nsref, &nsnode);
514 if(NS_FAILED(nsres)) {
515 ERR("InsertBefore failed: %08x\n", nsres);
519 hres = get_node(This->doc, nsnode, TRUE, &node_obj);
520 nsIDOMNode_Release(nsnode);
524 *node = &node_obj->IHTMLDOMNode_iface;
525 IHTMLDOMNode_AddRef(*node);
529 static HRESULT WINAPI HTMLDOMNode_removeChild(IHTMLDOMNode *iface, IHTMLDOMNode *oldChild,
532 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
533 HTMLDOMNode *node_obj;
538 TRACE("(%p)->(%p %p)\n", This, oldChild, node);
540 node_obj = get_node_obj(This->doc, (IUnknown*)oldChild);
544 nsres = nsIDOMNode_RemoveChild(This->nsnode, node_obj->nsnode, &nsnode);
545 if(NS_FAILED(nsres)) {
546 ERR("RemoveChild failed: %08x\n", nsres);
550 hres = get_node(This->doc, nsnode, TRUE, &node_obj);
551 nsIDOMNode_Release(nsnode);
555 /* FIXME: Make sure that node != newChild */
556 *node = &node_obj->IHTMLDOMNode_iface;
557 IHTMLDOMNode_AddRef(*node);
561 static HRESULT WINAPI HTMLDOMNode_replaceChild(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
562 IHTMLDOMNode *oldChild, IHTMLDOMNode **node)
564 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
565 FIXME("(%p)->(%p %p %p)\n", This, newChild, oldChild, node);
569 static HRESULT WINAPI HTMLDOMNode_cloneNode(IHTMLDOMNode *iface, VARIANT_BOOL fDeep,
570 IHTMLDOMNode **clonedNode)
572 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
573 HTMLDOMNode *new_node;
578 TRACE("(%p)->(%x %p)\n", This, fDeep, clonedNode);
580 nsres = nsIDOMNode_CloneNode(This->nsnode, fDeep != VARIANT_FALSE, &nsnode);
581 if(NS_FAILED(nsres) || !nsnode) {
582 ERR("CloneNode failed: %08x\n", nsres);
586 hres = This->vtbl->clone(This, nsnode, &new_node);
590 *clonedNode = &new_node->IHTMLDOMNode_iface;
594 static HRESULT WINAPI HTMLDOMNode_removeNode(IHTMLDOMNode *iface, VARIANT_BOOL fDeep,
595 IHTMLDOMNode **removed)
597 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
598 FIXME("(%p)->(%x %p)\n", This, fDeep, removed);
602 static HRESULT WINAPI HTMLDOMNode_swapNode(IHTMLDOMNode *iface, IHTMLDOMNode *otherNode,
603 IHTMLDOMNode **swappedNode)
605 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
606 FIXME("(%p)->(%p %p)\n", This, otherNode, swappedNode);
610 static HRESULT WINAPI HTMLDOMNode_replaceNode(IHTMLDOMNode *iface, IHTMLDOMNode *replacement,
611 IHTMLDOMNode **replaced)
613 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
614 FIXME("(%p)->(%p %p)\n", This, replacement, replaced);
618 static HRESULT WINAPI HTMLDOMNode_appendChild(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
621 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
622 HTMLDOMNode *node_obj;
627 TRACE("(%p)->(%p %p)\n", This, newChild, node);
629 node_obj = get_node_obj(This->doc, (IUnknown*)newChild);
633 nsres = nsIDOMNode_AppendChild(This->nsnode, node_obj->nsnode, &nsnode);
634 if(NS_FAILED(nsres)) {
635 WARN("AppendChild failed: %08x\n", nsres);
636 nsnode = node_obj->nsnode;
639 hres = get_node(This->doc, nsnode, TRUE, &node_obj);
640 nsIDOMNode_Release(nsnode);
644 /* FIXME: Make sure that node != newChild */
645 *node = &node_obj->IHTMLDOMNode_iface;
646 IHTMLDOMNode_AddRef(*node);
650 static HRESULT WINAPI HTMLDOMNode_get_nodeName(IHTMLDOMNode *iface, BSTR *p)
652 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
654 TRACE("(%p)->(%p)\n", This, p);
660 const PRUnichar *name;
663 nsAString_Init(&name_str, NULL);
664 nsres = nsIDOMNode_GetNodeName(This->nsnode, &name_str);
666 if(NS_SUCCEEDED(nsres)) {
667 nsAString_GetData(&name_str, &name);
668 *p = SysAllocString(name);
670 ERR("GetNodeName failed: %08x\n", nsres);
673 nsAString_Finish(&name_str);
679 static HRESULT WINAPI HTMLDOMNode_put_nodeValue(IHTMLDOMNode *iface, VARIANT v)
681 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
683 TRACE("(%p)->()\n", This);
689 TRACE("bstr %s\n", debugstr_w(V_BSTR(&v)));
691 nsAString_InitDepend(&val_str, V_BSTR(&v));
692 nsIDOMNode_SetNodeValue(This->nsnode, &val_str);
693 nsAString_Finish(&val_str);
699 FIXME("unsupported vt %d\n", V_VT(&v));
705 static HRESULT WINAPI HTMLDOMNode_get_nodeValue(IHTMLDOMNode *iface, VARIANT *p)
707 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
708 const PRUnichar *val;
711 TRACE("(%p)->(%p)\n", This, p);
713 nsAString_Init(&val_str, NULL);
714 nsIDOMNode_GetNodeValue(This->nsnode, &val_str);
715 nsAString_GetData(&val_str, &val);
719 V_BSTR(p) = SysAllocString(val);
724 nsAString_Finish(&val_str);
729 static HRESULT WINAPI HTMLDOMNode_get_firstChild(IHTMLDOMNode *iface, IHTMLDOMNode **p)
731 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
732 nsIDOMNode *nschild = NULL;
736 TRACE("(%p)->(%p)\n", This, p);
738 nsIDOMNode_GetFirstChild(This->nsnode, &nschild);
744 hres = get_node(This->doc, nschild, TRUE, &node);
745 nsIDOMNode_Release(nschild);
749 *p = &node->IHTMLDOMNode_iface;
750 IHTMLDOMNode_AddRef(*p);
754 static HRESULT WINAPI HTMLDOMNode_get_lastChild(IHTMLDOMNode *iface, IHTMLDOMNode **p)
756 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
757 nsIDOMNode *nschild = NULL;
761 TRACE("(%p)->(%p)\n", This, p);
763 nsIDOMNode_GetLastChild(This->nsnode, &nschild);
769 hres = get_node(This->doc, nschild, TRUE, &node);
770 nsIDOMNode_Release(nschild);
774 *p = &node->IHTMLDOMNode_iface;
775 IHTMLDOMNode_AddRef(*p);
779 static HRESULT WINAPI HTMLDOMNode_get_previousSibling(IHTMLDOMNode *iface, IHTMLDOMNode **p)
781 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
782 FIXME("(%p)->(%p)\n", This, p);
786 static HRESULT WINAPI HTMLDOMNode_get_nextSibling(IHTMLDOMNode *iface, IHTMLDOMNode **p)
788 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
789 nsIDOMNode *nssibling = NULL;
793 TRACE("(%p)->(%p)\n", This, p);
795 nsIDOMNode_GetNextSibling(This->nsnode, &nssibling);
801 hres = get_node(This->doc, nssibling, TRUE, &node);
802 nsIDOMNode_Release(nssibling);
806 *p = &node->IHTMLDOMNode_iface;
807 IHTMLDOMNode_AddRef(*p);
811 static const IHTMLDOMNodeVtbl HTMLDOMNodeVtbl = {
812 HTMLDOMNode_QueryInterface,
815 HTMLDOMNode_GetTypeInfoCount,
816 HTMLDOMNode_GetTypeInfo,
817 HTMLDOMNode_GetIDsOfNames,
819 HTMLDOMNode_get_nodeType,
820 HTMLDOMNode_get_parentNode,
821 HTMLDOMNode_hasChildNodes,
822 HTMLDOMNode_get_childNodes,
823 HTMLDOMNode_get_attributes,
824 HTMLDOMNode_insertBefore,
825 HTMLDOMNode_removeChild,
826 HTMLDOMNode_replaceChild,
827 HTMLDOMNode_cloneNode,
828 HTMLDOMNode_removeNode,
829 HTMLDOMNode_swapNode,
830 HTMLDOMNode_replaceNode,
831 HTMLDOMNode_appendChild,
832 HTMLDOMNode_get_nodeName,
833 HTMLDOMNode_put_nodeValue,
834 HTMLDOMNode_get_nodeValue,
835 HTMLDOMNode_get_firstChild,
836 HTMLDOMNode_get_lastChild,
837 HTMLDOMNode_get_previousSibling,
838 HTMLDOMNode_get_nextSibling
841 static inline HTMLDOMNode *impl_from_IHTMLDOMNode2(IHTMLDOMNode2 *iface)
843 return CONTAINING_RECORD(iface, HTMLDOMNode, IHTMLDOMNode2_iface);
846 static HRESULT WINAPI HTMLDOMNode2_QueryInterface(IHTMLDOMNode2 *iface,
847 REFIID riid, void **ppv)
849 HTMLDOMNode *This = impl_from_IHTMLDOMNode2(iface);
851 return IHTMLDOMNode_QueryInterface(&This->IHTMLDOMNode_iface, riid, ppv);
854 static ULONG WINAPI HTMLDOMNode2_AddRef(IHTMLDOMNode2 *iface)
856 HTMLDOMNode *This = impl_from_IHTMLDOMNode2(iface);
858 return IHTMLDOMNode_AddRef(&This->IHTMLDOMNode_iface);
861 static ULONG WINAPI HTMLDOMNode2_Release(IHTMLDOMNode2 *iface)
863 HTMLDOMNode *This = impl_from_IHTMLDOMNode2(iface);
865 return IHTMLDOMNode_Release(&This->IHTMLDOMNode_iface);
868 static HRESULT WINAPI HTMLDOMNode2_GetTypeInfoCount(IHTMLDOMNode2 *iface, UINT *pctinfo)
870 HTMLDOMNode *This = impl_from_IHTMLDOMNode2(iface);
871 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->dispex), pctinfo);
874 static HRESULT WINAPI HTMLDOMNode2_GetTypeInfo(IHTMLDOMNode2 *iface, UINT iTInfo,
875 LCID lcid, ITypeInfo **ppTInfo)
877 HTMLDOMNode *This = impl_from_IHTMLDOMNode2(iface);
878 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
881 static HRESULT WINAPI HTMLDOMNode2_GetIDsOfNames(IHTMLDOMNode2 *iface, REFIID riid,
882 LPOLESTR *rgszNames, UINT cNames,
883 LCID lcid, DISPID *rgDispId)
885 HTMLDOMNode *This = impl_from_IHTMLDOMNode2(iface);
886 return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->dispex), riid, rgszNames, cNames, lcid, rgDispId);
889 static HRESULT WINAPI HTMLDOMNode2_Invoke(IHTMLDOMNode2 *iface, DISPID dispIdMember,
890 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
891 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
893 HTMLDOMNode *This = impl_from_IHTMLDOMNode2(iface);
894 return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid,
895 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
898 static HRESULT WINAPI HTMLDOMNode2_get_ownerDocument(IHTMLDOMNode2 *iface, IDispatch **p)
900 HTMLDOMNode *This = impl_from_IHTMLDOMNode2(iface);
902 TRACE("(%p)->(%p)\n", This, p);
904 /* FIXME: Better check for document node */
905 if(This == &This->doc->node) {
908 *p = (IDispatch*)&This->doc->basedoc.IHTMLDocument2_iface;
909 IDispatch_AddRef(*p);
914 static const IHTMLDOMNode2Vtbl HTMLDOMNode2Vtbl = {
915 HTMLDOMNode2_QueryInterface,
917 HTMLDOMNode2_Release,
918 HTMLDOMNode2_GetTypeInfoCount,
919 HTMLDOMNode2_GetTypeInfo,
920 HTMLDOMNode2_GetIDsOfNames,
922 HTMLDOMNode2_get_ownerDocument
925 HRESULT HTMLDOMNode_QI(HTMLDOMNode *This, REFIID riid, void **ppv)
929 if(IsEqualGUID(&IID_IUnknown, riid)) {
930 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
931 *ppv = &This->IHTMLDOMNode_iface;
932 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
933 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
934 *ppv = &This->IHTMLDOMNode_iface;
935 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
936 if(This->dispex.data) {
937 TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
938 *ppv = DISPATCHEX(&This->dispex);
940 FIXME("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
941 return E_NOINTERFACE;
943 }else if(IsEqualGUID(&IID_IHTMLDOMNode, riid)) {
944 TRACE("(%p)->(IID_IHTMLDOMNode %p)\n", This, ppv);
945 *ppv = &This->IHTMLDOMNode_iface;
946 }else if(IsEqualGUID(&IID_IHTMLDOMNode2, riid)) {
947 TRACE("(%p)->(IID_IHTMLDOMNode2 %p)\n", This, ppv);
948 *ppv = &This->IHTMLDOMNode2_iface;
949 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
950 return *ppv ? S_OK : E_NOINTERFACE;
954 IUnknown_AddRef((IUnknown*)*ppv);
958 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
959 return E_NOINTERFACE;
962 void HTMLDOMNode_destructor(HTMLDOMNode *This)
965 nsIDOMNode_Release(This->nsnode);
966 if(This->event_target)
967 release_event_target(This->event_target);
970 static HRESULT HTMLDOMNode_clone(HTMLDOMNode *This, nsIDOMNode *nsnode, HTMLDOMNode **ret)
974 hres = create_node(This->doc, nsnode, ret);
978 IHTMLDOMNode_AddRef(&(*ret)->IHTMLDOMNode_iface);
982 static const NodeImplVtbl HTMLDOMNodeImplVtbl = {
984 HTMLDOMNode_destructor,
988 void HTMLDOMNode_Init(HTMLDocumentNode *doc, HTMLDOMNode *node, nsIDOMNode *nsnode)
990 node->IHTMLDOMNode_iface.lpVtbl = &HTMLDOMNodeVtbl;
991 node->IHTMLDOMNode2_iface.lpVtbl = &HTMLDOMNode2Vtbl;
996 nsIDOMNode_AddRef(nsnode);
997 node->nsnode = nsnode;
999 node->next = doc->nodes;
1003 static HRESULT create_node(HTMLDocumentNode *doc, nsIDOMNode *nsnode, HTMLDOMNode **ret)
1008 nsIDOMNode_GetNodeType(nsnode, &node_type);
1011 case ELEMENT_NODE: {
1013 hres = HTMLElement_Create(doc, nsnode, FALSE, &elem);
1020 hres = HTMLDOMTextNode_Create(doc, nsnode, ret);
1024 case COMMENT_NODE: {
1025 HTMLElement *comment;
1026 hres = HTMLCommentElement_Create(doc, nsnode, &comment);
1029 *ret = &comment->node;
1035 node = heap_alloc_zero(sizeof(HTMLDOMNode));
1037 return E_OUTOFMEMORY;
1039 node->vtbl = &HTMLDOMNodeImplVtbl;
1040 HTMLDOMNode_Init(doc, node, nsnode);
1045 TRACE("type %d ret %p\n", node_type, *ret);
1051 * List looks really ugly here. We should use a better data structure or
1052 * (better) find a way to store HTMLDOMelement pointer in nsIDOMNode.
1055 HRESULT get_node(HTMLDocumentNode *This, nsIDOMNode *nsnode, BOOL create, HTMLDOMNode **ret)
1057 HTMLDOMNode *iter = This->nodes;
1060 if(iter->nsnode == nsnode)
1065 if(iter || !create) {
1070 return create_node(This, nsnode, ret);
1075 * We should use better way for getting node object (like private interface)
1076 * or avoid it at all.
1078 static HTMLDOMNode *get_node_obj(HTMLDocumentNode *This, IUnknown *iface)
1080 HTMLDOMNode *iter = This->nodes;
1083 IUnknown_QueryInterface(iface, &IID_IHTMLDOMNode, (void**)&node);
1084 IHTMLDOMNode_Release(node);
1087 if(&iter->IHTMLDOMNode_iface == node)
1092 FIXME("Not found %p\n", iface);
1096 void release_nodes(HTMLDocumentNode *This)
1098 HTMLDOMNode *iter, *next;
1103 for(iter = This->nodes; iter; iter = next) {
1106 if(&This->node != iter)
1107 IHTMLDOMNode_Release(&iter->IHTMLDOMNode_iface);