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 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
);
701 TRACE("(%p)->(%p)\n", This
, p
);
707 const PRUnichar
*name
;
710 nsAString_Init(&name_str
, NULL
);
711 nsres
= nsIDOMNode_GetNodeName(This
->nsnode
, &name_str
);
713 if(NS_SUCCEEDED(nsres
)) {
714 nsAString_GetData(&name_str
, &name
);
715 *p
= SysAllocString(name
);
717 ERR("GetNodeName failed: %08x\n", nsres
);
720 nsAString_Finish(&name_str
);
726 static HRESULT WINAPI
HTMLDOMNode_put_nodeValue(IHTMLDOMNode
*iface
, VARIANT v
)
728 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
730 TRACE("(%p)->()\n", This
);
736 TRACE("bstr %s\n", debugstr_w(V_BSTR(&v
)));
738 nsAString_InitDepend(&val_str
, V_BSTR(&v
));
739 nsIDOMNode_SetNodeValue(This
->nsnode
, &val_str
);
740 nsAString_Finish(&val_str
);
746 FIXME("unsupported vt %d\n", V_VT(&v
));
752 static HRESULT WINAPI
HTMLDOMNode_get_nodeValue(IHTMLDOMNode
*iface
, VARIANT
*p
)
754 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
755 const PRUnichar
*val
;
758 TRACE("(%p)->(%p)\n", This
, p
);
760 nsAString_Init(&val_str
, NULL
);
761 nsIDOMNode_GetNodeValue(This
->nsnode
, &val_str
);
762 nsAString_GetData(&val_str
, &val
);
766 V_BSTR(p
) = SysAllocString(val
);
771 nsAString_Finish(&val_str
);
776 static HRESULT WINAPI
HTMLDOMNode_get_firstChild(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
778 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
779 nsIDOMNode
*nschild
= NULL
;
783 TRACE("(%p)->(%p)\n", This
, p
);
785 nsIDOMNode_GetFirstChild(This
->nsnode
, &nschild
);
791 hres
= get_node(This
->doc
, nschild
, TRUE
, &node
);
792 nsIDOMNode_Release(nschild
);
796 *p
= &node
->IHTMLDOMNode_iface
;
797 IHTMLDOMNode_AddRef(*p
);
801 static HRESULT WINAPI
HTMLDOMNode_get_lastChild(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
803 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
804 nsIDOMNode
*nschild
= NULL
;
808 TRACE("(%p)->(%p)\n", This
, p
);
810 nsIDOMNode_GetLastChild(This
->nsnode
, &nschild
);
816 hres
= get_node(This
->doc
, nschild
, TRUE
, &node
);
817 nsIDOMNode_Release(nschild
);
821 *p
= &node
->IHTMLDOMNode_iface
;
822 IHTMLDOMNode_AddRef(*p
);
826 static HRESULT WINAPI
HTMLDOMNode_get_previousSibling(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
828 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
829 nsIDOMNode
*nschild
= NULL
;
833 TRACE("(%p)->(%p)\n", This
, p
);
835 nsIDOMNode_GetPreviousSibling(This
->nsnode
, &nschild
);
841 hres
= get_node(This
->doc
, nschild
, TRUE
, &node
);
842 nsIDOMNode_Release(nschild
);
846 *p
= &node
->IHTMLDOMNode_iface
;
847 IHTMLDOMNode_AddRef(*p
);
851 static HRESULT WINAPI
HTMLDOMNode_get_nextSibling(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
853 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
854 nsIDOMNode
*nssibling
= NULL
;
858 TRACE("(%p)->(%p)\n", This
, p
);
860 nsIDOMNode_GetNextSibling(This
->nsnode
, &nssibling
);
866 hres
= get_node(This
->doc
, nssibling
, TRUE
, &node
);
867 nsIDOMNode_Release(nssibling
);
871 *p
= &node
->IHTMLDOMNode_iface
;
872 IHTMLDOMNode_AddRef(*p
);
876 static const IHTMLDOMNodeVtbl HTMLDOMNodeVtbl
= {
877 HTMLDOMNode_QueryInterface
,
880 HTMLDOMNode_GetTypeInfoCount
,
881 HTMLDOMNode_GetTypeInfo
,
882 HTMLDOMNode_GetIDsOfNames
,
884 HTMLDOMNode_get_nodeType
,
885 HTMLDOMNode_get_parentNode
,
886 HTMLDOMNode_hasChildNodes
,
887 HTMLDOMNode_get_childNodes
,
888 HTMLDOMNode_get_attributes
,
889 HTMLDOMNode_insertBefore
,
890 HTMLDOMNode_removeChild
,
891 HTMLDOMNode_replaceChild
,
892 HTMLDOMNode_cloneNode
,
893 HTMLDOMNode_removeNode
,
894 HTMLDOMNode_swapNode
,
895 HTMLDOMNode_replaceNode
,
896 HTMLDOMNode_appendChild
,
897 HTMLDOMNode_get_nodeName
,
898 HTMLDOMNode_put_nodeValue
,
899 HTMLDOMNode_get_nodeValue
,
900 HTMLDOMNode_get_firstChild
,
901 HTMLDOMNode_get_lastChild
,
902 HTMLDOMNode_get_previousSibling
,
903 HTMLDOMNode_get_nextSibling
906 static inline HTMLDOMNode
*impl_from_IHTMLDOMNode2(IHTMLDOMNode2
*iface
)
908 return CONTAINING_RECORD(iface
, HTMLDOMNode
, IHTMLDOMNode2_iface
);
911 static HRESULT WINAPI
HTMLDOMNode2_QueryInterface(IHTMLDOMNode2
*iface
,
912 REFIID riid
, void **ppv
)
914 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
916 return IHTMLDOMNode_QueryInterface(&This
->IHTMLDOMNode_iface
, riid
, ppv
);
919 static ULONG WINAPI
HTMLDOMNode2_AddRef(IHTMLDOMNode2
*iface
)
921 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
923 return IHTMLDOMNode_AddRef(&This
->IHTMLDOMNode_iface
);
926 static ULONG WINAPI
HTMLDOMNode2_Release(IHTMLDOMNode2
*iface
)
928 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
930 return IHTMLDOMNode_Release(&This
->IHTMLDOMNode_iface
);
933 static HRESULT WINAPI
HTMLDOMNode2_GetTypeInfoCount(IHTMLDOMNode2
*iface
, UINT
*pctinfo
)
935 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
936 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
939 static HRESULT WINAPI
HTMLDOMNode2_GetTypeInfo(IHTMLDOMNode2
*iface
, UINT iTInfo
,
940 LCID lcid
, ITypeInfo
**ppTInfo
)
942 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
943 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
946 static HRESULT WINAPI
HTMLDOMNode2_GetIDsOfNames(IHTMLDOMNode2
*iface
, REFIID riid
,
947 LPOLESTR
*rgszNames
, UINT cNames
,
948 LCID lcid
, DISPID
*rgDispId
)
950 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
951 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
955 static HRESULT WINAPI
HTMLDOMNode2_Invoke(IHTMLDOMNode2
*iface
, DISPID dispIdMember
,
956 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
957 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
959 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
960 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
961 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
964 static HRESULT WINAPI
HTMLDOMNode2_get_ownerDocument(IHTMLDOMNode2
*iface
, IDispatch
**p
)
966 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
968 TRACE("(%p)->(%p)\n", This
, p
);
970 /* FIXME: Better check for document node */
971 if(This
== &This
->doc
->node
) {
974 *p
= (IDispatch
*)&This
->doc
->basedoc
.IHTMLDocument2_iface
;
975 IDispatch_AddRef(*p
);
980 static const IHTMLDOMNode2Vtbl HTMLDOMNode2Vtbl
= {
981 HTMLDOMNode2_QueryInterface
,
983 HTMLDOMNode2_Release
,
984 HTMLDOMNode2_GetTypeInfoCount
,
985 HTMLDOMNode2_GetTypeInfo
,
986 HTMLDOMNode2_GetIDsOfNames
,
988 HTMLDOMNode2_get_ownerDocument
991 HRESULT
HTMLDOMNode_QI(HTMLDOMNode
*This
, REFIID riid
, void **ppv
)
995 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
996 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
997 *ppv
= &This
->IHTMLDOMNode_iface
;
998 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
999 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
1000 *ppv
= &This
->IHTMLDOMNode_iface
;
1001 }else if(IsEqualGUID(&IID_IDispatchEx
, riid
)) {
1002 if(This
->dispex
.data
) {
1003 TRACE("(%p)->(IID_IDispatchEx %p)\n", This
, ppv
);
1004 *ppv
= &This
->dispex
.IDispatchEx_iface
;
1006 FIXME("(%p)->(IID_IDispatchEx %p)\n", This
, ppv
);
1007 return E_NOINTERFACE
;
1009 }else if(IsEqualGUID(&IID_IHTMLDOMNode
, riid
)) {
1010 TRACE("(%p)->(IID_IHTMLDOMNode %p)\n", This
, ppv
);
1011 *ppv
= &This
->IHTMLDOMNode_iface
;
1012 }else if(IsEqualGUID(&IID_IHTMLDOMNode2
, riid
)) {
1013 TRACE("(%p)->(IID_IHTMLDOMNode2 %p)\n", This
, ppv
);
1014 *ppv
= &This
->IHTMLDOMNode2_iface
;
1015 }else if(dispex_query_interface(&This
->dispex
, riid
, ppv
)) {
1016 return *ppv
? S_OK
: E_NOINTERFACE
;
1020 IUnknown_AddRef((IUnknown
*)*ppv
);
1024 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
1025 return E_NOINTERFACE
;
1028 void HTMLDOMNode_destructor(HTMLDOMNode
*This
)
1031 nsIDOMNode_Release(This
->nsnode
);
1032 if(This
->event_target
)
1033 release_event_target(This
->event_target
);
1036 static HRESULT
HTMLDOMNode_clone(HTMLDOMNode
*This
, nsIDOMNode
*nsnode
, HTMLDOMNode
**ret
)
1040 hres
= create_node(This
->doc
, nsnode
, ret
);
1044 IHTMLDOMNode_AddRef(&(*ret
)->IHTMLDOMNode_iface
);
1048 static const NodeImplVtbl HTMLDOMNodeImplVtbl
= {
1050 HTMLDOMNode_destructor
,
1054 void HTMLDOMNode_Init(HTMLDocumentNode
*doc
, HTMLDOMNode
*node
, nsIDOMNode
*nsnode
)
1056 node
->IHTMLDOMNode_iface
.lpVtbl
= &HTMLDOMNodeVtbl
;
1057 node
->IHTMLDOMNode2_iface
.lpVtbl
= &HTMLDOMNode2Vtbl
;
1062 nsIDOMNode_AddRef(nsnode
);
1063 node
->nsnode
= nsnode
;
1065 node
->next
= doc
->nodes
;
1069 static HRESULT
create_node(HTMLDocumentNode
*doc
, nsIDOMNode
*nsnode
, HTMLDOMNode
**ret
)
1074 nsIDOMNode_GetNodeType(nsnode
, &node_type
);
1077 case ELEMENT_NODE
: {
1079 hres
= HTMLElement_Create(doc
, nsnode
, FALSE
, &elem
);
1086 hres
= HTMLDOMTextNode_Create(doc
, nsnode
, ret
);
1090 case COMMENT_NODE
: {
1091 HTMLElement
*comment
;
1092 hres
= HTMLCommentElement_Create(doc
, nsnode
, &comment
);
1095 *ret
= &comment
->node
;
1098 case ATTRIBUTE_NODE
:
1099 ERR("Called on attribute node\n");
1100 return E_UNEXPECTED
;
1104 node
= heap_alloc_zero(sizeof(HTMLDOMNode
));
1106 return E_OUTOFMEMORY
;
1108 node
->vtbl
= &HTMLDOMNodeImplVtbl
;
1109 HTMLDOMNode_Init(doc
, node
, nsnode
);
1114 TRACE("type %d ret %p\n", node_type
, *ret
);
1120 * List looks really ugly here. We should use a better data structure or
1121 * (better) find a way to store HTMLDOMelement pointer in nsIDOMNode.
1124 HRESULT
get_node(HTMLDocumentNode
*This
, nsIDOMNode
*nsnode
, BOOL create
, HTMLDOMNode
**ret
)
1126 HTMLDOMNode
*iter
= This
->nodes
;
1129 if(iter
->nsnode
== nsnode
)
1134 if(iter
|| !create
) {
1139 return create_node(This
, nsnode
, ret
);
1144 * We should use better way for getting node object (like private interface)
1145 * or avoid it at all.
1147 static HTMLDOMNode
*get_node_obj(HTMLDocumentNode
*This
, IUnknown
*iface
)
1149 HTMLDOMNode
*iter
= This
->nodes
;
1152 IUnknown_QueryInterface(iface
, &IID_IHTMLDOMNode
, (void**)&node
);
1153 IHTMLDOMNode_Release(node
);
1156 if(&iter
->IHTMLDOMNode_iface
== node
)
1161 FIXME("Not found %p\n", iface
);
1165 void release_nodes(HTMLDocumentNode
*This
)
1167 HTMLDOMNode
*iter
, *next
;
1172 for(iter
= This
->nodes
; iter
; iter
= next
) {
1175 if(&This
->node
!= iter
)
1176 IHTMLDOMNode_Release(&iter
->IHTMLDOMNode_iface
);