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"
32 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
34 static HTMLDOMNode *get_node_obj(HTMLDocument*,IUnknown*);
38 const IHTMLDOMChildrenCollectionVtbl *lpIHTMLDOMChildrenCollectionVtbl;
42 /* FIXME: implement weak reference */
45 nsIDOMNodeList *nslist;
46 } HTMLDOMChildrenCollection;
48 #define HTMLCHILDCOL(x) ((IHTMLDOMChildrenCollection*) &(x)->lpIHTMLDOMChildrenCollectionVtbl)
50 #define HTMLCHILDCOL_THIS(iface) DEFINE_THIS(HTMLDOMChildrenCollection, IHTMLDOMChildrenCollection, iface)
52 static HRESULT WINAPI HTMLDOMChildrenCollection_QueryInterface(IHTMLDOMChildrenCollection *iface, REFIID riid, void **ppv)
54 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
58 if(IsEqualGUID(&IID_IUnknown, riid)) {
59 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
60 *ppv = HTMLCHILDCOL(This);
61 }else if(IsEqualGUID(&IID_IHTMLDOMChildrenCollection, riid)) {
62 TRACE("(%p)->(IID_IHTMLDOMChildrenCollection %p)\n", This, ppv);
63 *ppv = HTMLCHILDCOL(This);
64 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
65 return *ppv ? S_OK : E_NOINTERFACE;
69 IUnknown_AddRef((IUnknown*)*ppv);
73 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
77 static ULONG WINAPI HTMLDOMChildrenCollection_AddRef(IHTMLDOMChildrenCollection *iface)
79 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
80 LONG ref = InterlockedIncrement(&This->ref);
82 TRACE("(%p) ref=%d\n", This, ref);
87 static ULONG WINAPI HTMLDOMChildrenCollection_Release(IHTMLDOMChildrenCollection *iface)
89 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
90 LONG ref = InterlockedDecrement(&This->ref);
92 TRACE("(%p) ref=%d\n", This, ref);
95 nsIDOMNodeList_Release(This->nslist);
102 static HRESULT WINAPI HTMLDOMChildrenCollection_GetTypeInfoCount(IHTMLDOMChildrenCollection *iface, UINT *pctinfo)
104 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
105 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->dispex), pctinfo);
108 static HRESULT WINAPI HTMLDOMChildrenCollection_GetTypeInfo(IHTMLDOMChildrenCollection *iface, UINT iTInfo,
109 LCID lcid, ITypeInfo **ppTInfo)
111 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
112 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
115 static HRESULT WINAPI HTMLDOMChildrenCollection_GetIDsOfNames(IHTMLDOMChildrenCollection *iface, REFIID riid,
116 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
118 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
119 return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->dispex), riid, rgszNames, cNames, lcid, rgDispId);
122 static HRESULT WINAPI HTMLDOMChildrenCollection_Invoke(IHTMLDOMChildrenCollection *iface, DISPID dispIdMember,
123 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
124 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
126 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
127 return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid,
128 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
131 static HRESULT WINAPI HTMLDOMChildrenCollection_get_length(IHTMLDOMChildrenCollection *iface, long *p)
133 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
136 TRACE("(%p)->(%p)\n", This, p);
138 nsIDOMNodeList_GetLength(This->nslist, &length);
143 static HRESULT WINAPI HTMLDOMChildrenCollection__newEnum(IHTMLDOMChildrenCollection *iface, IUnknown **p)
145 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
146 FIXME("(%p)->(%p)\n", This, p);
150 static HRESULT WINAPI HTMLDOMChildrenCollection_item(IHTMLDOMChildrenCollection *iface, long index, IDispatch **ppItem)
152 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
153 nsIDOMNode *nsnode = NULL;
157 TRACE("(%p)->(%ld %p)\n", This, index, ppItem);
159 nsIDOMNodeList_GetLength(This->nslist, &length);
160 if(index < 0 || index >= length)
163 nsres = nsIDOMNodeList_Item(This->nslist, index, &nsnode);
164 if(NS_FAILED(nsres) || !nsnode) {
165 ERR("Item failed: %08x\n", nsres);
169 *ppItem = (IDispatch*)get_node(This->doc, nsnode, TRUE);
170 IDispatch_AddRef(*ppItem);
174 #define DISPID_CHILDCOL_0 MSHTML_DISPID_CUSTOM_MIN
176 static HRESULT HTMLDOMChildrenCollection_get_dispid(IUnknown *iface, BSTR name, DWORD flags, DISPID *dispid)
178 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
183 for(ptr = name; *ptr && isdigitW(*ptr); ptr++)
184 idx = idx*10 + (*ptr-'0');
186 return DISP_E_UNKNOWNNAME;
188 nsIDOMNodeList_GetLength(This->nslist, &len);
190 return DISP_E_UNKNOWNNAME;
192 *dispid = DISPID_CHILDCOL_0 + idx;
193 TRACE("ret %x\n", *dispid);
197 static HRESULT HTMLDOMChildrenCollection_invoke(IUnknown *iface, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
198 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
200 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
202 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
205 case INVOKE_PROPERTYGET: {
206 IDispatch *disp = NULL;
209 hres = IHTMLDOMChildrenCollection_item(HTMLCHILDCOL(This), id - DISPID_CHILDCOL_0, &disp);
213 V_VT(res) = VT_DISPATCH;
214 V_DISPATCH(res) = disp;
219 FIXME("unimplemented flags %x\n", flags);
226 #undef HTMLCHILDCOL_THIS
228 static const IHTMLDOMChildrenCollectionVtbl HTMLDOMChildrenCollectionVtbl = {
229 HTMLDOMChildrenCollection_QueryInterface,
230 HTMLDOMChildrenCollection_AddRef,
231 HTMLDOMChildrenCollection_Release,
232 HTMLDOMChildrenCollection_GetTypeInfoCount,
233 HTMLDOMChildrenCollection_GetTypeInfo,
234 HTMLDOMChildrenCollection_GetIDsOfNames,
235 HTMLDOMChildrenCollection_Invoke,
236 HTMLDOMChildrenCollection_get_length,
237 HTMLDOMChildrenCollection__newEnum,
238 HTMLDOMChildrenCollection_item
241 static const tid_t HTMLDOMChildrenCollection_iface_tids[] = {
242 IHTMLDOMChildrenCollection_tid,
246 static const dispex_static_data_vtbl_t HTMLDOMChildrenCollection_dispex_vtbl = {
247 HTMLDOMChildrenCollection_get_dispid,
248 HTMLDOMChildrenCollection_invoke
251 static dispex_static_data_t HTMLDOMChildrenCollection_dispex = {
252 &HTMLDOMChildrenCollection_dispex_vtbl,
253 DispDOMChildrenCollection_tid,
255 HTMLDOMChildrenCollection_iface_tids
258 static IHTMLDOMChildrenCollection *create_child_collection(HTMLDocument *doc, nsIDOMNodeList *nslist)
260 HTMLDOMChildrenCollection *ret;
262 ret = heap_alloc_zero(sizeof(*ret));
263 ret->lpIHTMLDOMChildrenCollectionVtbl = &HTMLDOMChildrenCollectionVtbl;
266 nsIDOMNodeList_AddRef(nslist);
267 ret->nslist = nslist;
270 init_dispex(&ret->dispex, (IUnknown*)HTMLCHILDCOL(ret), &HTMLDOMChildrenCollection_dispex);
272 return HTMLCHILDCOL(ret);
275 #define HTMLDOMNODE_THIS(iface) DEFINE_THIS(HTMLDOMNode, HTMLDOMNode, iface)
277 static HRESULT WINAPI HTMLDOMNode_QueryInterface(IHTMLDOMNode *iface,
278 REFIID riid, void **ppv)
280 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
282 return This->vtbl->qi(This, riid, ppv);
285 static ULONG WINAPI HTMLDOMNode_AddRef(IHTMLDOMNode *iface)
287 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
288 LONG ref = InterlockedIncrement(&This->ref);
290 TRACE("(%p) ref=%d\n", This, ref);
295 static ULONG WINAPI HTMLDOMNode_Release(IHTMLDOMNode *iface)
297 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
298 LONG ref = InterlockedDecrement(&This->ref);
300 TRACE("(%p) ref=%d\n", This, ref);
303 This->vtbl->destructor(This);
310 static HRESULT WINAPI HTMLDOMNode_GetTypeInfoCount(IHTMLDOMNode *iface, UINT *pctinfo)
312 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
313 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->dispex), pctinfo);
316 static HRESULT WINAPI HTMLDOMNode_GetTypeInfo(IHTMLDOMNode *iface, UINT iTInfo,
317 LCID lcid, ITypeInfo **ppTInfo)
319 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
320 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
323 static HRESULT WINAPI HTMLDOMNode_GetIDsOfNames(IHTMLDOMNode *iface, REFIID riid,
324 LPOLESTR *rgszNames, UINT cNames,
325 LCID lcid, DISPID *rgDispId)
327 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
328 return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->dispex), riid, rgszNames, cNames, lcid, rgDispId);
331 static HRESULT WINAPI HTMLDOMNode_Invoke(IHTMLDOMNode *iface, DISPID dispIdMember,
332 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
333 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
335 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
336 return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid,
337 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
340 static HRESULT WINAPI HTMLDOMNode_get_nodeType(IHTMLDOMNode *iface, long *p)
342 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
345 TRACE("(%p)->(%p)\n", This, p);
347 nsIDOMNode_GetNodeType(This->nsnode, &type);
365 * According to MSDN only ELEMENT_NODE and TEXT_NODE are supported.
366 * It needs more tests.
368 FIXME("type %u\n", type);
375 static HRESULT WINAPI HTMLDOMNode_get_parentNode(IHTMLDOMNode *iface, IHTMLDOMNode **p)
377 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
382 TRACE("(%p)->(%p)\n", This, p);
384 nsres = nsIDOMNode_GetParentNode(This->nsnode, &nsnode);
385 if(NS_FAILED(nsres)) {
386 ERR("GetParentNode failed: %08x\n", nsres);
395 node = get_node(This->doc, nsnode, TRUE);
396 *p = HTMLDOMNODE(node);
397 IHTMLDOMNode_AddRef(*p);
401 static HRESULT WINAPI HTMLDOMNode_hasChildNodes(IHTMLDOMNode *iface, VARIANT_BOOL *fChildren)
403 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
404 PRBool has_child = FALSE;
407 TRACE("(%p)->(%p)\n", This, fChildren);
409 nsres = nsIDOMNode_HasChildNodes(This->nsnode, &has_child);
411 ERR("HasChildNodes failed: %08x\n", nsres);
413 *fChildren = has_child ? VARIANT_TRUE : VARIANT_FALSE;
417 static HRESULT WINAPI HTMLDOMNode_get_childNodes(IHTMLDOMNode *iface, IDispatch **p)
419 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
420 nsIDOMNodeList *nslist;
423 TRACE("(%p)->(%p)\n", This, p);
425 nsres = nsIDOMNode_GetChildNodes(This->nsnode, &nslist);
426 if(NS_FAILED(nsres)) {
427 ERR("GetChildNodes failed: %08x\n", nsres);
431 *p = (IDispatch*)create_child_collection(This->doc, nslist);
432 nsIDOMNodeList_Release(nslist);
437 static HRESULT WINAPI HTMLDOMNode_get_attributes(IHTMLDOMNode *iface, IDispatch **p)
439 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
440 FIXME("(%p)->(%p)\n", This, p);
444 static HRESULT WINAPI HTMLDOMNode_insertBefore(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
445 VARIANT refChild, IHTMLDOMNode **node)
447 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
448 FIXME("(%p)->(%p v %p)\n", This, newChild, node);
452 static HRESULT WINAPI HTMLDOMNode_removeChild(IHTMLDOMNode *iface, IHTMLDOMNode *oldChild,
455 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
456 HTMLDOMNode *node_obj;
460 TRACE("(%p)->(%p %p)\n", This, oldChild, node);
462 node_obj = get_node_obj(This->doc, (IUnknown*)oldChild);
466 nsres = nsIDOMNode_RemoveChild(This->nsnode, node_obj->nsnode, &nsnode);
467 if(NS_FAILED(nsres)) {
468 ERR("RemoveChild failed: %08x\n", nsres);
472 /* FIXME: Make sure that node != newChild */
473 *node = HTMLDOMNODE(get_node(This->doc, nsnode, TRUE));
474 IHTMLDOMNode_AddRef(*node);
478 static HRESULT WINAPI HTMLDOMNode_replaceChild(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
479 IHTMLDOMNode *oldChild, IHTMLDOMNode **node)
481 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
482 FIXME("(%p)->(%p %p %p)\n", This, newChild, oldChild, node);
486 static HRESULT WINAPI HTMLDOMNode_cloneNode(IHTMLDOMNode *iface, VARIANT_BOOL fDeep,
487 IHTMLDOMNode **clonedNode)
489 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
490 FIXME("(%p)->(%x %p)\n", This, fDeep, clonedNode);
494 static HRESULT WINAPI HTMLDOMNode_removeNode(IHTMLDOMNode *iface, VARIANT_BOOL fDeep,
495 IHTMLDOMNode **removed)
497 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
498 FIXME("(%p)->(%x %p)\n", This, fDeep, removed);
502 static HRESULT WINAPI HTMLDOMNode_swapNode(IHTMLDOMNode *iface, IHTMLDOMNode *otherNode,
503 IHTMLDOMNode **swappedNode)
505 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
506 FIXME("(%p)->(%p %p)\n", This, otherNode, swappedNode);
510 static HRESULT WINAPI HTMLDOMNode_replaceNode(IHTMLDOMNode *iface, IHTMLDOMNode *replacement,
511 IHTMLDOMNode **replaced)
513 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
514 FIXME("(%p)->(%p %p)\n", This, replacement, replaced);
518 static HRESULT WINAPI HTMLDOMNode_appendChild(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
521 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
522 HTMLDOMNode *node_obj;
526 TRACE("(%p)->(%p %p)\n", This, newChild, node);
528 node_obj = get_node_obj(This->doc, (IUnknown*)newChild);
532 nsres = nsIDOMNode_AppendChild(This->nsnode, node_obj->nsnode, &nsnode);
533 if(NS_FAILED(nsres)) {
534 ERR("AppendChild failed: %08x\n", nsres);
538 /* FIXME: Make sure that node != newChild */
539 *node = HTMLDOMNODE(get_node(This->doc, nsnode, TRUE));
540 IHTMLDOMNode_AddRef(*node);
544 static HRESULT WINAPI HTMLDOMNode_get_nodeName(IHTMLDOMNode *iface, BSTR *p)
546 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
548 TRACE("(%p)->(%p)\n", This, p);
554 const PRUnichar *name;
557 nsAString_Init(&name_str, NULL);
558 nsres = nsIDOMNode_GetNodeName(This->nsnode, &name_str);
560 if(NS_SUCCEEDED(nsres)) {
561 nsAString_GetData(&name_str, &name);
562 *p = SysAllocString(name);
564 ERR("GetNodeName failed: %08x\n", nsres);
567 nsAString_Finish(&name_str);
573 static HRESULT WINAPI HTMLDOMNode_put_nodeValue(IHTMLDOMNode *iface, VARIANT v)
575 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
577 TRACE("(%p)->()\n", This);
583 TRACE("bstr %s\n", debugstr_w(V_BSTR(&v)));
585 nsAString_Init(&val_str, V_BSTR(&v));
586 nsIDOMNode_SetNodeValue(This->nsnode, &val_str);
587 nsAString_Finish(&val_str);
593 FIXME("unsupported vt %d\n", V_VT(&v));
599 static HRESULT WINAPI HTMLDOMNode_get_nodeValue(IHTMLDOMNode *iface, VARIANT *p)
601 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
602 const PRUnichar *val;
605 TRACE("(%p)->(%p)\n", This, p);
607 nsAString_Init(&val_str, NULL);
608 nsIDOMNode_GetNodeValue(This->nsnode, &val_str);
609 nsAString_GetData(&val_str, &val);
613 V_BSTR(p) = SysAllocString(val);
618 nsAString_Finish(&val_str);
623 static HRESULT WINAPI HTMLDOMNode_get_firstChild(IHTMLDOMNode *iface, IHTMLDOMNode **p)
625 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
626 nsIDOMNode *nschild = NULL;
628 TRACE("(%p)->(%p)\n", This, p);
630 nsIDOMNode_GetFirstChild(This->nsnode, &nschild);
632 *p = HTMLDOMNODE(get_node(This->doc, nschild, TRUE));
633 IHTMLDOMNode_AddRef(*p);
641 static HRESULT WINAPI HTMLDOMNode_get_lastChild(IHTMLDOMNode *iface, IHTMLDOMNode **p)
643 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
644 nsIDOMNode *nschild = NULL;
646 TRACE("(%p)->(%p)\n", This, p);
648 nsIDOMNode_GetLastChild(This->nsnode, &nschild);
650 *p = HTMLDOMNODE(get_node(This->doc, nschild, TRUE));
651 IHTMLDOMNode_AddRef(*p);
659 static HRESULT WINAPI HTMLDOMNode_get_previousSibling(IHTMLDOMNode *iface, IHTMLDOMNode **p)
661 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
662 FIXME("(%p)->(%p)\n", This, p);
666 static HRESULT WINAPI HTMLDOMNode_get_nextSibling(IHTMLDOMNode *iface, IHTMLDOMNode **p)
668 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
669 FIXME("(%p)->(%p)\n", This, p);
673 #undef HTMLDOMNODE_THIS
675 static const IHTMLDOMNodeVtbl HTMLDOMNodeVtbl = {
676 HTMLDOMNode_QueryInterface,
679 HTMLDOMNode_GetTypeInfoCount,
680 HTMLDOMNode_GetTypeInfo,
681 HTMLDOMNode_GetIDsOfNames,
683 HTMLDOMNode_get_nodeType,
684 HTMLDOMNode_get_parentNode,
685 HTMLDOMNode_hasChildNodes,
686 HTMLDOMNode_get_childNodes,
687 HTMLDOMNode_get_attributes,
688 HTMLDOMNode_insertBefore,
689 HTMLDOMNode_removeChild,
690 HTMLDOMNode_replaceChild,
691 HTMLDOMNode_cloneNode,
692 HTMLDOMNode_removeNode,
693 HTMLDOMNode_swapNode,
694 HTMLDOMNode_replaceNode,
695 HTMLDOMNode_appendChild,
696 HTMLDOMNode_get_nodeName,
697 HTMLDOMNode_put_nodeValue,
698 HTMLDOMNode_get_nodeValue,
699 HTMLDOMNode_get_firstChild,
700 HTMLDOMNode_get_lastChild,
701 HTMLDOMNode_get_previousSibling,
702 HTMLDOMNode_get_nextSibling
705 #define HTMLDOMNODE2_THIS(iface) DEFINE_THIS(HTMLDOMNode, HTMLDOMNode2, iface)
707 static HRESULT WINAPI HTMLDOMNode2_QueryInterface(IHTMLDOMNode2 *iface,
708 REFIID riid, void **ppv)
710 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
712 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(This), riid, ppv);
715 static ULONG WINAPI HTMLDOMNode2_AddRef(IHTMLDOMNode2 *iface)
717 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
719 return IHTMLDOMNode_AddRef(HTMLDOMNODE(This));
722 static ULONG WINAPI HTMLDOMNode2_Release(IHTMLDOMNode2 *iface)
724 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
726 return IHTMLDOMNode_Release(HTMLDOMNODE(This));
729 static HRESULT WINAPI HTMLDOMNode2_GetTypeInfoCount(IHTMLDOMNode2 *iface, UINT *pctinfo)
731 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
732 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->dispex), pctinfo);
735 static HRESULT WINAPI HTMLDOMNode2_GetTypeInfo(IHTMLDOMNode2 *iface, UINT iTInfo,
736 LCID lcid, ITypeInfo **ppTInfo)
738 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
739 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
742 static HRESULT WINAPI HTMLDOMNode2_GetIDsOfNames(IHTMLDOMNode2 *iface, REFIID riid,
743 LPOLESTR *rgszNames, UINT cNames,
744 LCID lcid, DISPID *rgDispId)
746 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
747 return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->dispex), riid, rgszNames, cNames, lcid, rgDispId);
750 static HRESULT WINAPI HTMLDOMNode2_Invoke(IHTMLDOMNode2 *iface, DISPID dispIdMember,
751 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
752 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
754 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
755 return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid,
756 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
759 static HRESULT WINAPI HTMLDOMNode2_get_ownerDocument(IHTMLDOMNode2 *iface, IDispatch **p)
761 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
762 FIXME("(%p)->(%p)\n", This, p);
766 #undef HTMLDOMNODE2_THIS
768 static const IHTMLDOMNode2Vtbl HTMLDOMNode2Vtbl = {
769 HTMLDOMNode2_QueryInterface,
771 HTMLDOMNode2_Release,
772 HTMLDOMNode2_GetTypeInfoCount,
773 HTMLDOMNode2_GetTypeInfo,
774 HTMLDOMNode2_GetIDsOfNames,
776 HTMLDOMNode2_get_ownerDocument
779 HRESULT HTMLDOMNode_QI(HTMLDOMNode *This, REFIID riid, void **ppv)
783 if(IsEqualGUID(&IID_IUnknown, riid)) {
784 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
785 *ppv = HTMLDOMNODE(This);
786 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
787 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
788 *ppv = HTMLDOMNODE(This);
789 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
790 if(This->dispex.data) {
791 TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
792 *ppv = DISPATCHEX(&This->dispex);
794 FIXME("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
795 return E_NOINTERFACE;
797 }else if(IsEqualGUID(&IID_IHTMLDOMNode, riid)) {
798 TRACE("(%p)->(IID_IHTMLDOMNode %p)\n", This, ppv);
799 *ppv = HTMLDOMNODE(This);
800 }else if(IsEqualGUID(&IID_IHTMLDOMNode2, riid)) {
801 TRACE("(%p)->(IID_IHTMLDOMNode2 %p)\n", This, ppv);
802 *ppv = HTMLDOMNODE2(This);
803 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
804 return *ppv ? S_OK : E_NOINTERFACE;
808 IUnknown_AddRef((IUnknown*)*ppv);
812 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
813 return E_NOINTERFACE;
816 void HTMLDOMNode_destructor(HTMLDOMNode *This)
819 nsIDOMNode_Release(This->nsnode);
820 if(This->event_target)
821 release_event_target(This->event_target);
824 static const NodeImplVtbl HTMLDOMNodeImplVtbl = {
826 HTMLDOMNode_destructor
829 void HTMLDOMNode_Init(HTMLDocument *doc, HTMLDOMNode *node, nsIDOMNode *nsnode)
831 node->lpHTMLDOMNodeVtbl = &HTMLDOMNodeVtbl;
832 node->lpHTMLDOMNode2Vtbl = &HTMLDOMNode2Vtbl;
836 nsIDOMNode_AddRef(nsnode);
837 node->nsnode = nsnode;
839 node->next = doc->nodes;
843 static HTMLDOMNode *create_node(HTMLDocument *doc, nsIDOMNode *nsnode)
848 nsIDOMNode_GetNodeType(nsnode, &node_type);
852 ret = &HTMLElement_Create(doc, nsnode, FALSE)->node;
855 ret = HTMLDOMTextNode_Create(doc, nsnode);
858 ret = &HTMLCommentElement_Create(doc, nsnode)->node;
861 ret = heap_alloc_zero(sizeof(HTMLDOMNode));
862 ret->vtbl = &HTMLDOMNodeImplVtbl;
863 HTMLDOMNode_Init(doc, ret, nsnode);
866 TRACE("type %d ret %p\n", node_type, ret);
873 * List looks really ugly here. We should use a better data structure or
874 * (better) find a way to store HTMLDOMelement pointer in nsIDOMNode.
877 HTMLDOMNode *get_node(HTMLDocument *This, nsIDOMNode *nsnode, BOOL create)
879 HTMLDOMNode *iter = This->nodes;
882 if(iter->nsnode == nsnode)
890 return create_node(This, nsnode);
895 * We should use better way for getting node object (like private interface)
896 * or avoid it at all.
898 static HTMLDOMNode *get_node_obj(HTMLDocument *This, IUnknown *iface)
900 HTMLDOMNode *iter = This->nodes;
903 IUnknown_QueryInterface(iface, &IID_IHTMLDOMNode, (void**)&node);
904 IHTMLDOMNode_Release(node);
907 if(HTMLDOMNODE(iter) == node)
912 FIXME("Not found %p\n", iface);
916 void release_nodes(HTMLDocument *This)
918 HTMLDOMNode *iter, *next;
923 for(iter = This->nodes; iter; iter = next) {
926 IHTMLDOMNode_Release(HTMLDOMNODE(iter));