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 cpp_bool 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 refChild %s\n", debugstr_variant(&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 HTMLDOMNode *node_new;
584 HTMLDOMNode *node_old;
589 TRACE("(%p)->(%p %p %p)\n", This, newChild, oldChild, node);
591 node_new = get_node_obj(This->doc, (IUnknown*)newChild);
595 node_old = get_node_obj(This->doc, (IUnknown*)oldChild);
599 nsres = nsIDOMNode_ReplaceChild(This->nsnode, node_new->nsnode, node_old->nsnode, &nsnode);
600 if(NS_FAILED(nsres)) {
604 nsnode = node_new->nsnode;
606 hres = get_node(This->doc, nsnode, TRUE, &node_new);
607 nsIDOMNode_Release(nsnode);
611 *node = &node_new->IHTMLDOMNode_iface;
612 IHTMLDOMNode_AddRef(*node);
616 static HRESULT WINAPI HTMLDOMNode_cloneNode(IHTMLDOMNode *iface, VARIANT_BOOL fDeep,
617 IHTMLDOMNode **clonedNode)
619 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
620 HTMLDOMNode *new_node;
625 TRACE("(%p)->(%x %p)\n", This, fDeep, clonedNode);
627 nsres = nsIDOMNode_CloneNode(This->nsnode, fDeep != VARIANT_FALSE, &nsnode);
628 if(NS_FAILED(nsres) || !nsnode) {
629 ERR("CloneNode failed: %08x\n", nsres);
633 hres = This->vtbl->clone(This, nsnode, &new_node);
637 *clonedNode = &new_node->IHTMLDOMNode_iface;
641 static HRESULT WINAPI HTMLDOMNode_removeNode(IHTMLDOMNode *iface, VARIANT_BOOL fDeep,
642 IHTMLDOMNode **removed)
644 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
645 FIXME("(%p)->(%x %p)\n", This, fDeep, removed);
649 static HRESULT WINAPI HTMLDOMNode_swapNode(IHTMLDOMNode *iface, IHTMLDOMNode *otherNode,
650 IHTMLDOMNode **swappedNode)
652 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
653 FIXME("(%p)->(%p %p)\n", This, otherNode, swappedNode);
657 static HRESULT WINAPI HTMLDOMNode_replaceNode(IHTMLDOMNode *iface, IHTMLDOMNode *replacement,
658 IHTMLDOMNode **replaced)
660 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
661 FIXME("(%p)->(%p %p)\n", This, replacement, replaced);
665 static HRESULT WINAPI HTMLDOMNode_appendChild(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
668 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
669 HTMLDOMNode *node_obj;
674 TRACE("(%p)->(%p %p)\n", This, newChild, node);
676 node_obj = get_node_obj(This->doc, (IUnknown*)newChild);
680 nsres = nsIDOMNode_AppendChild(This->nsnode, node_obj->nsnode, &nsnode);
681 if(NS_FAILED(nsres)) {
682 WARN("AppendChild failed: %08x\n", nsres);
683 nsnode = node_obj->nsnode;
686 hres = get_node(This->doc, nsnode, TRUE, &node_obj);
687 nsIDOMNode_Release(nsnode);
691 /* FIXME: Make sure that node != newChild */
692 *node = &node_obj->IHTMLDOMNode_iface;
693 IHTMLDOMNode_AddRef(*node);
697 static HRESULT WINAPI HTMLDOMNode_get_nodeName(IHTMLDOMNode *iface, BSTR *p)
699 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
703 TRACE("(%p)->(%p)\n", This, p);
705 nsAString_Init(&name, NULL);
706 nsres = nsIDOMNode_GetNodeName(This->nsnode, &name);
707 return return_nsstr(nsres, &name, p);
710 static HRESULT WINAPI HTMLDOMNode_put_nodeValue(IHTMLDOMNode *iface, VARIANT v)
712 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
714 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
720 nsAString_InitDepend(&val_str, V_BSTR(&v));
721 nsIDOMNode_SetNodeValue(This->nsnode, &val_str);
722 nsAString_Finish(&val_str);
728 FIXME("unsupported value %s\n", debugstr_variant(&v));
734 static HRESULT WINAPI HTMLDOMNode_get_nodeValue(IHTMLDOMNode *iface, VARIANT *p)
736 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
737 const PRUnichar *val;
740 TRACE("(%p)->(%p)\n", This, p);
742 nsAString_Init(&val_str, NULL);
743 nsIDOMNode_GetNodeValue(This->nsnode, &val_str);
744 nsAString_GetData(&val_str, &val);
748 V_BSTR(p) = SysAllocString(val);
753 nsAString_Finish(&val_str);
758 static HRESULT WINAPI HTMLDOMNode_get_firstChild(IHTMLDOMNode *iface, IHTMLDOMNode **p)
760 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
761 nsIDOMNode *nschild = NULL;
765 TRACE("(%p)->(%p)\n", This, p);
767 nsIDOMNode_GetFirstChild(This->nsnode, &nschild);
773 hres = get_node(This->doc, nschild, TRUE, &node);
774 nsIDOMNode_Release(nschild);
778 *p = &node->IHTMLDOMNode_iface;
779 IHTMLDOMNode_AddRef(*p);
783 static HRESULT WINAPI HTMLDOMNode_get_lastChild(IHTMLDOMNode *iface, IHTMLDOMNode **p)
785 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
786 nsIDOMNode *nschild = NULL;
790 TRACE("(%p)->(%p)\n", This, p);
792 nsIDOMNode_GetLastChild(This->nsnode, &nschild);
798 hres = get_node(This->doc, nschild, TRUE, &node);
799 nsIDOMNode_Release(nschild);
803 *p = &node->IHTMLDOMNode_iface;
804 IHTMLDOMNode_AddRef(*p);
808 static HRESULT WINAPI HTMLDOMNode_get_previousSibling(IHTMLDOMNode *iface, IHTMLDOMNode **p)
810 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
811 nsIDOMNode *nschild = NULL;
815 TRACE("(%p)->(%p)\n", This, p);
817 nsIDOMNode_GetPreviousSibling(This->nsnode, &nschild);
823 hres = get_node(This->doc, nschild, TRUE, &node);
824 nsIDOMNode_Release(nschild);
828 *p = &node->IHTMLDOMNode_iface;
829 IHTMLDOMNode_AddRef(*p);
833 static HRESULT WINAPI HTMLDOMNode_get_nextSibling(IHTMLDOMNode *iface, IHTMLDOMNode **p)
835 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
836 nsIDOMNode *nssibling = NULL;
840 TRACE("(%p)->(%p)\n", This, p);
842 nsIDOMNode_GetNextSibling(This->nsnode, &nssibling);
848 hres = get_node(This->doc, nssibling, TRUE, &node);
849 nsIDOMNode_Release(nssibling);
853 *p = &node->IHTMLDOMNode_iface;
854 IHTMLDOMNode_AddRef(*p);
858 static const IHTMLDOMNodeVtbl HTMLDOMNodeVtbl = {
859 HTMLDOMNode_QueryInterface,
862 HTMLDOMNode_GetTypeInfoCount,
863 HTMLDOMNode_GetTypeInfo,
864 HTMLDOMNode_GetIDsOfNames,
866 HTMLDOMNode_get_nodeType,
867 HTMLDOMNode_get_parentNode,
868 HTMLDOMNode_hasChildNodes,
869 HTMLDOMNode_get_childNodes,
870 HTMLDOMNode_get_attributes,
871 HTMLDOMNode_insertBefore,
872 HTMLDOMNode_removeChild,
873 HTMLDOMNode_replaceChild,
874 HTMLDOMNode_cloneNode,
875 HTMLDOMNode_removeNode,
876 HTMLDOMNode_swapNode,
877 HTMLDOMNode_replaceNode,
878 HTMLDOMNode_appendChild,
879 HTMLDOMNode_get_nodeName,
880 HTMLDOMNode_put_nodeValue,
881 HTMLDOMNode_get_nodeValue,
882 HTMLDOMNode_get_firstChild,
883 HTMLDOMNode_get_lastChild,
884 HTMLDOMNode_get_previousSibling,
885 HTMLDOMNode_get_nextSibling
888 static inline HTMLDOMNode *impl_from_IHTMLDOMNode2(IHTMLDOMNode2 *iface)
890 return CONTAINING_RECORD(iface, HTMLDOMNode, IHTMLDOMNode2_iface);
893 static HRESULT WINAPI HTMLDOMNode2_QueryInterface(IHTMLDOMNode2 *iface,
894 REFIID riid, void **ppv)
896 HTMLDOMNode *This = impl_from_IHTMLDOMNode2(iface);
898 return IHTMLDOMNode_QueryInterface(&This->IHTMLDOMNode_iface, riid, ppv);
901 static ULONG WINAPI HTMLDOMNode2_AddRef(IHTMLDOMNode2 *iface)
903 HTMLDOMNode *This = impl_from_IHTMLDOMNode2(iface);
905 return IHTMLDOMNode_AddRef(&This->IHTMLDOMNode_iface);
908 static ULONG WINAPI HTMLDOMNode2_Release(IHTMLDOMNode2 *iface)
910 HTMLDOMNode *This = impl_from_IHTMLDOMNode2(iface);
912 return IHTMLDOMNode_Release(&This->IHTMLDOMNode_iface);
915 static HRESULT WINAPI HTMLDOMNode2_GetTypeInfoCount(IHTMLDOMNode2 *iface, UINT *pctinfo)
917 HTMLDOMNode *This = impl_from_IHTMLDOMNode2(iface);
918 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
921 static HRESULT WINAPI HTMLDOMNode2_GetTypeInfo(IHTMLDOMNode2 *iface, UINT iTInfo,
922 LCID lcid, ITypeInfo **ppTInfo)
924 HTMLDOMNode *This = impl_from_IHTMLDOMNode2(iface);
925 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
928 static HRESULT WINAPI HTMLDOMNode2_GetIDsOfNames(IHTMLDOMNode2 *iface, REFIID riid,
929 LPOLESTR *rgszNames, UINT cNames,
930 LCID lcid, DISPID *rgDispId)
932 HTMLDOMNode *This = impl_from_IHTMLDOMNode2(iface);
933 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
937 static HRESULT WINAPI HTMLDOMNode2_Invoke(IHTMLDOMNode2 *iface, DISPID dispIdMember,
938 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
939 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
941 HTMLDOMNode *This = impl_from_IHTMLDOMNode2(iface);
942 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
943 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
946 static HRESULT WINAPI HTMLDOMNode2_get_ownerDocument(IHTMLDOMNode2 *iface, IDispatch **p)
948 HTMLDOMNode *This = impl_from_IHTMLDOMNode2(iface);
950 TRACE("(%p)->(%p)\n", This, p);
952 /* FIXME: Better check for document node */
953 if(This == &This->doc->node) {
956 *p = (IDispatch*)&This->doc->basedoc.IHTMLDocument2_iface;
957 IDispatch_AddRef(*p);
962 static const IHTMLDOMNode2Vtbl HTMLDOMNode2Vtbl = {
963 HTMLDOMNode2_QueryInterface,
965 HTMLDOMNode2_Release,
966 HTMLDOMNode2_GetTypeInfoCount,
967 HTMLDOMNode2_GetTypeInfo,
968 HTMLDOMNode2_GetIDsOfNames,
970 HTMLDOMNode2_get_ownerDocument
973 HRESULT HTMLDOMNode_QI(HTMLDOMNode *This, REFIID riid, void **ppv)
977 if(IsEqualGUID(&IID_IUnknown, riid)) {
978 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
979 *ppv = &This->IHTMLDOMNode_iface;
980 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
981 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
982 *ppv = &This->IHTMLDOMNode_iface;
983 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
984 if(This->dispex.data) {
985 TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
986 *ppv = &This->dispex.IDispatchEx_iface;
988 FIXME("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
989 return E_NOINTERFACE;
991 }else if(IsEqualGUID(&IID_IHTMLDOMNode, riid)) {
992 TRACE("(%p)->(IID_IHTMLDOMNode %p)\n", This, ppv);
993 *ppv = &This->IHTMLDOMNode_iface;
994 }else if(IsEqualGUID(&IID_IHTMLDOMNode2, riid)) {
995 TRACE("(%p)->(IID_IHTMLDOMNode2 %p)\n", This, ppv);
996 *ppv = &This->IHTMLDOMNode2_iface;
997 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
998 return *ppv ? S_OK : E_NOINTERFACE;
1002 IUnknown_AddRef((IUnknown*)*ppv);
1006 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
1007 return E_NOINTERFACE;
1010 void HTMLDOMNode_destructor(HTMLDOMNode *This)
1013 nsIDOMNode_Release(This->nsnode);
1014 if(This->event_target)
1015 release_event_target(This->event_target);
1018 static HRESULT HTMLDOMNode_clone(HTMLDOMNode *This, nsIDOMNode *nsnode, HTMLDOMNode **ret)
1022 hres = create_node(This->doc, nsnode, ret);
1026 IHTMLDOMNode_AddRef(&(*ret)->IHTMLDOMNode_iface);
1030 static const NodeImplVtbl HTMLDOMNodeImplVtbl = {
1032 HTMLDOMNode_destructor,
1036 void HTMLDOMNode_Init(HTMLDocumentNode *doc, HTMLDOMNode *node, nsIDOMNode *nsnode)
1038 node->IHTMLDOMNode_iface.lpVtbl = &HTMLDOMNodeVtbl;
1039 node->IHTMLDOMNode2_iface.lpVtbl = &HTMLDOMNode2Vtbl;
1044 nsIDOMNode_AddRef(nsnode);
1045 node->nsnode = nsnode;
1047 node->next = doc->nodes;
1051 static HRESULT create_node(HTMLDocumentNode *doc, nsIDOMNode *nsnode, HTMLDOMNode **ret)
1056 nsIDOMNode_GetNodeType(nsnode, &node_type);
1059 case ELEMENT_NODE: {
1061 hres = HTMLElement_Create(doc, nsnode, FALSE, &elem);
1068 hres = HTMLDOMTextNode_Create(doc, nsnode, ret);
1072 case COMMENT_NODE: {
1073 HTMLElement *comment;
1074 hres = HTMLCommentElement_Create(doc, nsnode, &comment);
1077 *ret = &comment->node;
1080 case ATTRIBUTE_NODE:
1081 ERR("Called on attribute node\n");
1082 return E_UNEXPECTED;
1086 node = heap_alloc_zero(sizeof(HTMLDOMNode));
1088 return E_OUTOFMEMORY;
1090 node->vtbl = &HTMLDOMNodeImplVtbl;
1091 HTMLDOMNode_Init(doc, node, nsnode);
1096 TRACE("type %d ret %p\n", node_type, *ret);
1102 * List looks really ugly here. We should use a better data structure or
1103 * (better) find a way to store HTMLDOMelement pointer in nsIDOMNode.
1106 HRESULT get_node(HTMLDocumentNode *This, nsIDOMNode *nsnode, BOOL create, HTMLDOMNode **ret)
1108 HTMLDOMNode *iter = This->nodes;
1111 if(iter->nsnode == nsnode)
1116 if(iter || !create) {
1121 return create_node(This, nsnode, ret);
1126 * We should use better way for getting node object (like private interface)
1127 * or avoid it at all.
1129 static HTMLDOMNode *get_node_obj(HTMLDocumentNode *This, IUnknown *iface)
1131 HTMLDOMNode *iter = This->nodes;
1134 IUnknown_QueryInterface(iface, &IID_IHTMLDOMNode, (void**)&node);
1135 IHTMLDOMNode_Release(node);
1138 if(&iter->IHTMLDOMNode_iface == node)
1143 FIXME("Not found %p\n", iface);
1147 void release_nodes(HTMLDocumentNode *This)
1149 HTMLDOMNode *iter, *next;
1154 for(iter = This->nodes; iter; iter = next) {
1157 if(&This->node != iter)
1158 IHTMLDOMNode_Release(&iter->IHTMLDOMNode_iface);