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,
267 static const tid_t HTMLDOMChildrenCollection_iface_tids[] = {
268 IHTMLDOMChildrenCollection_tid,
272 static dispex_static_data_t HTMLDOMChildrenCollection_dispex = {
273 &HTMLDOMChildrenCollection_dispex_vtbl,
274 DispDOMChildrenCollection_tid,
276 HTMLDOMChildrenCollection_iface_tids
279 static IHTMLDOMChildrenCollection *create_child_collection(HTMLDocumentNode *doc, nsIDOMNodeList *nslist)
281 HTMLDOMChildrenCollection *ret;
283 ret = heap_alloc_zero(sizeof(*ret));
284 ret->IHTMLDOMChildrenCollection_iface.lpVtbl = &HTMLDOMChildrenCollectionVtbl;
287 nsIDOMNodeList_AddRef(nslist);
288 ret->nslist = nslist;
291 init_dispex(&ret->dispex, (IUnknown*)&ret->IHTMLDOMChildrenCollection_iface,
292 &HTMLDOMChildrenCollection_dispex);
294 return &ret->IHTMLDOMChildrenCollection_iface;
297 static inline HTMLDOMNode *impl_from_IHTMLDOMNode(IHTMLDOMNode *iface)
299 return CONTAINING_RECORD(iface, HTMLDOMNode, IHTMLDOMNode_iface);
302 static HRESULT WINAPI HTMLDOMNode_QueryInterface(IHTMLDOMNode *iface,
303 REFIID riid, void **ppv)
305 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
307 return This->vtbl->qi(This, riid, ppv);
310 static ULONG WINAPI HTMLDOMNode_AddRef(IHTMLDOMNode *iface)
312 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
313 LONG ref = InterlockedIncrement(&This->ref);
315 TRACE("(%p) ref=%d\n", This, ref);
320 static ULONG WINAPI HTMLDOMNode_Release(IHTMLDOMNode *iface)
322 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
323 LONG ref = InterlockedDecrement(&This->ref);
325 TRACE("(%p) ref=%d\n", This, ref);
328 This->vtbl->destructor(This);
329 release_dispex(&This->dispex);
336 static HRESULT WINAPI HTMLDOMNode_GetTypeInfoCount(IHTMLDOMNode *iface, UINT *pctinfo)
338 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
339 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
342 static HRESULT WINAPI HTMLDOMNode_GetTypeInfo(IHTMLDOMNode *iface, UINT iTInfo,
343 LCID lcid, ITypeInfo **ppTInfo)
345 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
346 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
349 static HRESULT WINAPI HTMLDOMNode_GetIDsOfNames(IHTMLDOMNode *iface, REFIID riid,
350 LPOLESTR *rgszNames, UINT cNames,
351 LCID lcid, DISPID *rgDispId)
353 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
354 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
358 static HRESULT WINAPI HTMLDOMNode_Invoke(IHTMLDOMNode *iface, DISPID dispIdMember,
359 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
360 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
362 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
363 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
364 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
367 static HRESULT WINAPI HTMLDOMNode_get_nodeType(IHTMLDOMNode *iface, LONG *p)
369 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
372 TRACE("(%p)->(%p)\n", This, p);
374 nsIDOMNode_GetNodeType(This->nsnode, &type);
389 case DOCUMENT_FRAGMENT_NODE:
395 * According to MSDN only ELEMENT_NODE and TEXT_NODE are supported.
396 * It needs more tests.
398 FIXME("type %u\n", type);
405 static HRESULT WINAPI HTMLDOMNode_get_parentNode(IHTMLDOMNode *iface, IHTMLDOMNode **p)
407 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
413 TRACE("(%p)->(%p)\n", This, p);
415 nsres = nsIDOMNode_GetParentNode(This->nsnode, &nsnode);
416 if(NS_FAILED(nsres)) {
417 ERR("GetParentNode failed: %08x\n", nsres);
426 hres = get_node(This->doc, nsnode, TRUE, &node);
427 nsIDOMNode_Release(nsnode);
431 *p = &node->IHTMLDOMNode_iface;
432 IHTMLDOMNode_AddRef(*p);
436 static HRESULT WINAPI HTMLDOMNode_hasChildNodes(IHTMLDOMNode *iface, VARIANT_BOOL *fChildren)
438 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
439 PRBool has_child = FALSE;
442 TRACE("(%p)->(%p)\n", This, fChildren);
444 nsres = nsIDOMNode_HasChildNodes(This->nsnode, &has_child);
446 ERR("HasChildNodes failed: %08x\n", nsres);
448 *fChildren = has_child ? VARIANT_TRUE : VARIANT_FALSE;
452 static HRESULT WINAPI HTMLDOMNode_get_childNodes(IHTMLDOMNode *iface, IDispatch **p)
454 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
455 nsIDOMNodeList *nslist;
458 TRACE("(%p)->(%p)\n", This, p);
460 nsres = nsIDOMNode_GetChildNodes(This->nsnode, &nslist);
461 if(NS_FAILED(nsres)) {
462 ERR("GetChildNodes failed: %08x\n", nsres);
466 *p = (IDispatch*)create_child_collection(This->doc, nslist);
467 nsIDOMNodeList_Release(nslist);
472 static HRESULT WINAPI HTMLDOMNode_get_attributes(IHTMLDOMNode *iface, IDispatch **p)
474 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
475 HTMLAttributeCollection *col;
478 TRACE("(%p)->(%p)\n", This, p);
480 if(This->vtbl->get_attr_col) {
481 hres = This->vtbl->get_attr_col(This, &col);
485 *p = (IDispatch*)&col->IHTMLAttributeCollection_iface;
493 static HRESULT WINAPI HTMLDOMNode_insertBefore(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
494 VARIANT refChild, IHTMLDOMNode **node)
496 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
497 nsIDOMNode *nsnode, *nsref = NULL;
498 HTMLDOMNode *new_child;
499 HTMLDOMNode *node_obj;
503 TRACE("(%p)->(%p %s %p)\n", This, newChild, debugstr_variant(&refChild), node);
505 new_child = get_node_obj(This->doc, (IUnknown*)newChild);
507 ERR("invalid newChild\n");
511 switch(V_VT(&refChild)) {
515 HTMLDOMNode *ref_node;
517 ref_node = get_node_obj(This->doc, (IUnknown*)V_DISPATCH(&refChild));
519 ERR("unvalid node\n");
523 nsref = ref_node->nsnode;
527 FIXME("unimplemented vt %d\n", V_VT(&refChild));
531 nsres = nsIDOMNode_InsertBefore(This->nsnode, new_child->nsnode, nsref, &nsnode);
532 if(NS_FAILED(nsres)) {
533 ERR("InsertBefore failed: %08x\n", nsres);
537 hres = get_node(This->doc, nsnode, TRUE, &node_obj);
538 nsIDOMNode_Release(nsnode);
542 *node = &node_obj->IHTMLDOMNode_iface;
543 IHTMLDOMNode_AddRef(*node);
547 static HRESULT WINAPI HTMLDOMNode_removeChild(IHTMLDOMNode *iface, IHTMLDOMNode *oldChild,
550 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
551 HTMLDOMNode *node_obj;
556 TRACE("(%p)->(%p %p)\n", This, oldChild, node);
558 node_obj = get_node_obj(This->doc, (IUnknown*)oldChild);
562 nsres = nsIDOMNode_RemoveChild(This->nsnode, node_obj->nsnode, &nsnode);
563 if(NS_FAILED(nsres)) {
564 ERR("RemoveChild failed: %08x\n", nsres);
568 hres = get_node(This->doc, nsnode, TRUE, &node_obj);
569 nsIDOMNode_Release(nsnode);
573 /* FIXME: Make sure that node != newChild */
574 *node = &node_obj->IHTMLDOMNode_iface;
575 IHTMLDOMNode_AddRef(*node);
579 static HRESULT WINAPI HTMLDOMNode_replaceChild(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
580 IHTMLDOMNode *oldChild, IHTMLDOMNode **node)
582 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
583 FIXME("(%p)->(%p %p %p)\n", This, newChild, oldChild, node);
587 static HRESULT WINAPI HTMLDOMNode_cloneNode(IHTMLDOMNode *iface, VARIANT_BOOL fDeep,
588 IHTMLDOMNode **clonedNode)
590 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
591 HTMLDOMNode *new_node;
596 TRACE("(%p)->(%x %p)\n", This, fDeep, clonedNode);
598 nsres = nsIDOMNode_CloneNode(This->nsnode, fDeep != VARIANT_FALSE, &nsnode);
599 if(NS_FAILED(nsres) || !nsnode) {
600 ERR("CloneNode failed: %08x\n", nsres);
604 hres = This->vtbl->clone(This, nsnode, &new_node);
608 *clonedNode = &new_node->IHTMLDOMNode_iface;
612 static HRESULT WINAPI HTMLDOMNode_removeNode(IHTMLDOMNode *iface, VARIANT_BOOL fDeep,
613 IHTMLDOMNode **removed)
615 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
616 FIXME("(%p)->(%x %p)\n", This, fDeep, removed);
620 static HRESULT WINAPI HTMLDOMNode_swapNode(IHTMLDOMNode *iface, IHTMLDOMNode *otherNode,
621 IHTMLDOMNode **swappedNode)
623 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
624 FIXME("(%p)->(%p %p)\n", This, otherNode, swappedNode);
628 static HRESULT WINAPI HTMLDOMNode_replaceNode(IHTMLDOMNode *iface, IHTMLDOMNode *replacement,
629 IHTMLDOMNode **replaced)
631 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
632 FIXME("(%p)->(%p %p)\n", This, replacement, replaced);
636 static HRESULT WINAPI HTMLDOMNode_appendChild(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
639 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
640 HTMLDOMNode *node_obj;
645 TRACE("(%p)->(%p %p)\n", This, newChild, node);
647 node_obj = get_node_obj(This->doc, (IUnknown*)newChild);
651 nsres = nsIDOMNode_AppendChild(This->nsnode, node_obj->nsnode, &nsnode);
652 if(NS_FAILED(nsres)) {
653 WARN("AppendChild failed: %08x\n", nsres);
654 nsnode = node_obj->nsnode;
657 hres = get_node(This->doc, nsnode, TRUE, &node_obj);
658 nsIDOMNode_Release(nsnode);
662 /* FIXME: Make sure that node != newChild */
663 *node = &node_obj->IHTMLDOMNode_iface;
664 IHTMLDOMNode_AddRef(*node);
668 static HRESULT WINAPI HTMLDOMNode_get_nodeName(IHTMLDOMNode *iface, BSTR *p)
670 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
672 TRACE("(%p)->(%p)\n", This, p);
678 const PRUnichar *name;
681 nsAString_Init(&name_str, NULL);
682 nsres = nsIDOMNode_GetNodeName(This->nsnode, &name_str);
684 if(NS_SUCCEEDED(nsres)) {
685 nsAString_GetData(&name_str, &name);
686 *p = SysAllocString(name);
688 ERR("GetNodeName failed: %08x\n", nsres);
691 nsAString_Finish(&name_str);
697 static HRESULT WINAPI HTMLDOMNode_put_nodeValue(IHTMLDOMNode *iface, VARIANT v)
699 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
701 TRACE("(%p)->()\n", This);
707 TRACE("bstr %s\n", debugstr_w(V_BSTR(&v)));
709 nsAString_InitDepend(&val_str, V_BSTR(&v));
710 nsIDOMNode_SetNodeValue(This->nsnode, &val_str);
711 nsAString_Finish(&val_str);
717 FIXME("unsupported vt %d\n", V_VT(&v));
723 static HRESULT WINAPI HTMLDOMNode_get_nodeValue(IHTMLDOMNode *iface, VARIANT *p)
725 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
726 const PRUnichar *val;
729 TRACE("(%p)->(%p)\n", This, p);
731 nsAString_Init(&val_str, NULL);
732 nsIDOMNode_GetNodeValue(This->nsnode, &val_str);
733 nsAString_GetData(&val_str, &val);
737 V_BSTR(p) = SysAllocString(val);
742 nsAString_Finish(&val_str);
747 static HRESULT WINAPI HTMLDOMNode_get_firstChild(IHTMLDOMNode *iface, IHTMLDOMNode **p)
749 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
750 nsIDOMNode *nschild = NULL;
754 TRACE("(%p)->(%p)\n", This, p);
756 nsIDOMNode_GetFirstChild(This->nsnode, &nschild);
762 hres = get_node(This->doc, nschild, TRUE, &node);
763 nsIDOMNode_Release(nschild);
767 *p = &node->IHTMLDOMNode_iface;
768 IHTMLDOMNode_AddRef(*p);
772 static HRESULT WINAPI HTMLDOMNode_get_lastChild(IHTMLDOMNode *iface, IHTMLDOMNode **p)
774 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
775 nsIDOMNode *nschild = NULL;
779 TRACE("(%p)->(%p)\n", This, p);
781 nsIDOMNode_GetLastChild(This->nsnode, &nschild);
787 hres = get_node(This->doc, nschild, TRUE, &node);
788 nsIDOMNode_Release(nschild);
792 *p = &node->IHTMLDOMNode_iface;
793 IHTMLDOMNode_AddRef(*p);
797 static HRESULT WINAPI HTMLDOMNode_get_previousSibling(IHTMLDOMNode *iface, IHTMLDOMNode **p)
799 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
800 nsIDOMNode *nschild = NULL;
804 TRACE("(%p)->(%p)\n", This, p);
806 nsIDOMNode_GetPreviousSibling(This->nsnode, &nschild);
812 hres = get_node(This->doc, nschild, TRUE, &node);
813 nsIDOMNode_Release(nschild);
817 *p = &node->IHTMLDOMNode_iface;
818 IHTMLDOMNode_AddRef(*p);
822 static HRESULT WINAPI HTMLDOMNode_get_nextSibling(IHTMLDOMNode *iface, IHTMLDOMNode **p)
824 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
825 nsIDOMNode *nssibling = NULL;
829 TRACE("(%p)->(%p)\n", This, p);
831 nsIDOMNode_GetNextSibling(This->nsnode, &nssibling);
837 hres = get_node(This->doc, nssibling, TRUE, &node);
838 nsIDOMNode_Release(nssibling);
842 *p = &node->IHTMLDOMNode_iface;
843 IHTMLDOMNode_AddRef(*p);
847 static const IHTMLDOMNodeVtbl HTMLDOMNodeVtbl = {
848 HTMLDOMNode_QueryInterface,
851 HTMLDOMNode_GetTypeInfoCount,
852 HTMLDOMNode_GetTypeInfo,
853 HTMLDOMNode_GetIDsOfNames,
855 HTMLDOMNode_get_nodeType,
856 HTMLDOMNode_get_parentNode,
857 HTMLDOMNode_hasChildNodes,
858 HTMLDOMNode_get_childNodes,
859 HTMLDOMNode_get_attributes,
860 HTMLDOMNode_insertBefore,
861 HTMLDOMNode_removeChild,
862 HTMLDOMNode_replaceChild,
863 HTMLDOMNode_cloneNode,
864 HTMLDOMNode_removeNode,
865 HTMLDOMNode_swapNode,
866 HTMLDOMNode_replaceNode,
867 HTMLDOMNode_appendChild,
868 HTMLDOMNode_get_nodeName,
869 HTMLDOMNode_put_nodeValue,
870 HTMLDOMNode_get_nodeValue,
871 HTMLDOMNode_get_firstChild,
872 HTMLDOMNode_get_lastChild,
873 HTMLDOMNode_get_previousSibling,
874 HTMLDOMNode_get_nextSibling
877 static inline HTMLDOMNode *impl_from_IHTMLDOMNode2(IHTMLDOMNode2 *iface)
879 return CONTAINING_RECORD(iface, HTMLDOMNode, IHTMLDOMNode2_iface);
882 static HRESULT WINAPI HTMLDOMNode2_QueryInterface(IHTMLDOMNode2 *iface,
883 REFIID riid, void **ppv)
885 HTMLDOMNode *This = impl_from_IHTMLDOMNode2(iface);
887 return IHTMLDOMNode_QueryInterface(&This->IHTMLDOMNode_iface, riid, ppv);
890 static ULONG WINAPI HTMLDOMNode2_AddRef(IHTMLDOMNode2 *iface)
892 HTMLDOMNode *This = impl_from_IHTMLDOMNode2(iface);
894 return IHTMLDOMNode_AddRef(&This->IHTMLDOMNode_iface);
897 static ULONG WINAPI HTMLDOMNode2_Release(IHTMLDOMNode2 *iface)
899 HTMLDOMNode *This = impl_from_IHTMLDOMNode2(iface);
901 return IHTMLDOMNode_Release(&This->IHTMLDOMNode_iface);
904 static HRESULT WINAPI HTMLDOMNode2_GetTypeInfoCount(IHTMLDOMNode2 *iface, UINT *pctinfo)
906 HTMLDOMNode *This = impl_from_IHTMLDOMNode2(iface);
907 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
910 static HRESULT WINAPI HTMLDOMNode2_GetTypeInfo(IHTMLDOMNode2 *iface, UINT iTInfo,
911 LCID lcid, ITypeInfo **ppTInfo)
913 HTMLDOMNode *This = impl_from_IHTMLDOMNode2(iface);
914 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
917 static HRESULT WINAPI HTMLDOMNode2_GetIDsOfNames(IHTMLDOMNode2 *iface, REFIID riid,
918 LPOLESTR *rgszNames, UINT cNames,
919 LCID lcid, DISPID *rgDispId)
921 HTMLDOMNode *This = impl_from_IHTMLDOMNode2(iface);
922 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
926 static HRESULT WINAPI HTMLDOMNode2_Invoke(IHTMLDOMNode2 *iface, DISPID dispIdMember,
927 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
928 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
930 HTMLDOMNode *This = impl_from_IHTMLDOMNode2(iface);
931 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
932 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
935 static HRESULT WINAPI HTMLDOMNode2_get_ownerDocument(IHTMLDOMNode2 *iface, IDispatch **p)
937 HTMLDOMNode *This = impl_from_IHTMLDOMNode2(iface);
939 TRACE("(%p)->(%p)\n", This, p);
941 /* FIXME: Better check for document node */
942 if(This == &This->doc->node) {
945 *p = (IDispatch*)&This->doc->basedoc.IHTMLDocument2_iface;
946 IDispatch_AddRef(*p);
951 static const IHTMLDOMNode2Vtbl HTMLDOMNode2Vtbl = {
952 HTMLDOMNode2_QueryInterface,
954 HTMLDOMNode2_Release,
955 HTMLDOMNode2_GetTypeInfoCount,
956 HTMLDOMNode2_GetTypeInfo,
957 HTMLDOMNode2_GetIDsOfNames,
959 HTMLDOMNode2_get_ownerDocument
962 HRESULT HTMLDOMNode_QI(HTMLDOMNode *This, REFIID riid, void **ppv)
966 if(IsEqualGUID(&IID_IUnknown, riid)) {
967 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
968 *ppv = &This->IHTMLDOMNode_iface;
969 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
970 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
971 *ppv = &This->IHTMLDOMNode_iface;
972 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
973 if(This->dispex.data) {
974 TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
975 *ppv = &This->dispex.IDispatchEx_iface;
977 FIXME("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
978 return E_NOINTERFACE;
980 }else if(IsEqualGUID(&IID_IHTMLDOMNode, riid)) {
981 TRACE("(%p)->(IID_IHTMLDOMNode %p)\n", This, ppv);
982 *ppv = &This->IHTMLDOMNode_iface;
983 }else if(IsEqualGUID(&IID_IHTMLDOMNode2, riid)) {
984 TRACE("(%p)->(IID_IHTMLDOMNode2 %p)\n", This, ppv);
985 *ppv = &This->IHTMLDOMNode2_iface;
986 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
987 return *ppv ? S_OK : E_NOINTERFACE;
991 IUnknown_AddRef((IUnknown*)*ppv);
995 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
996 return E_NOINTERFACE;
999 void HTMLDOMNode_destructor(HTMLDOMNode *This)
1002 nsIDOMNode_Release(This->nsnode);
1003 if(This->event_target)
1004 release_event_target(This->event_target);
1007 static HRESULT HTMLDOMNode_clone(HTMLDOMNode *This, nsIDOMNode *nsnode, HTMLDOMNode **ret)
1011 hres = create_node(This->doc, nsnode, ret);
1015 IHTMLDOMNode_AddRef(&(*ret)->IHTMLDOMNode_iface);
1019 static const NodeImplVtbl HTMLDOMNodeImplVtbl = {
1021 HTMLDOMNode_destructor,
1025 void HTMLDOMNode_Init(HTMLDocumentNode *doc, HTMLDOMNode *node, nsIDOMNode *nsnode)
1027 node->IHTMLDOMNode_iface.lpVtbl = &HTMLDOMNodeVtbl;
1028 node->IHTMLDOMNode2_iface.lpVtbl = &HTMLDOMNode2Vtbl;
1033 nsIDOMNode_AddRef(nsnode);
1034 node->nsnode = nsnode;
1036 node->next = doc->nodes;
1040 static HRESULT create_node(HTMLDocumentNode *doc, nsIDOMNode *nsnode, HTMLDOMNode **ret)
1045 nsIDOMNode_GetNodeType(nsnode, &node_type);
1048 case ELEMENT_NODE: {
1050 hres = HTMLElement_Create(doc, nsnode, FALSE, &elem);
1057 hres = HTMLDOMTextNode_Create(doc, nsnode, ret);
1061 case COMMENT_NODE: {
1062 HTMLElement *comment;
1063 hres = HTMLCommentElement_Create(doc, nsnode, &comment);
1066 *ret = &comment->node;
1069 case ATTRIBUTE_NODE:
1070 ERR("Called on attribute node\n");
1071 return E_UNEXPECTED;
1075 node = heap_alloc_zero(sizeof(HTMLDOMNode));
1077 return E_OUTOFMEMORY;
1079 node->vtbl = &HTMLDOMNodeImplVtbl;
1080 HTMLDOMNode_Init(doc, node, nsnode);
1085 TRACE("type %d ret %p\n", node_type, *ret);
1091 * List looks really ugly here. We should use a better data structure or
1092 * (better) find a way to store HTMLDOMelement pointer in nsIDOMNode.
1095 HRESULT get_node(HTMLDocumentNode *This, nsIDOMNode *nsnode, BOOL create, HTMLDOMNode **ret)
1097 HTMLDOMNode *iter = This->nodes;
1100 if(iter->nsnode == nsnode)
1105 if(iter || !create) {
1110 return create_node(This, nsnode, ret);
1115 * We should use better way for getting node object (like private interface)
1116 * or avoid it at all.
1118 static HTMLDOMNode *get_node_obj(HTMLDocumentNode *This, IUnknown *iface)
1120 HTMLDOMNode *iter = This->nodes;
1123 IUnknown_QueryInterface(iface, &IID_IHTMLDOMNode, (void**)&node);
1124 IHTMLDOMNode_Release(node);
1127 if(&iter->IHTMLDOMNode_iface == node)
1132 FIXME("Not found %p\n", iface);
1136 void release_nodes(HTMLDocumentNode *This)
1138 HTMLDOMNode *iter, *next;
1143 for(iter = This->nodes; iter; iter = next) {
1146 if(&This->node != iter)
1147 IHTMLDOMNode_Release(&iter->IHTMLDOMNode_iface);