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
29 #include "wine/debug.h"
31 #include "mshtml_private.h"
32 #include "htmlevent.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
36 static HTMLDOMNode
*get_node_obj(IHTMLDOMNode
*);
37 static HRESULT
create_node(HTMLDocumentNode
*,nsIDOMNode
*,HTMLDOMNode
**);
39 static ExternalCycleCollectionParticipant node_ccp
;
43 IHTMLDOMChildrenCollection IHTMLDOMChildrenCollection_iface
;
47 nsIDOMNodeList
*nslist
;
48 } HTMLDOMChildrenCollection
;
51 IEnumVARIANT IEnumVARIANT_iface
;
56 HTMLDOMChildrenCollection
*col
;
57 } HTMLDOMChildrenCollectionEnum
;
59 static inline HTMLDOMChildrenCollectionEnum
*impl_from_IEnumVARIANT(IEnumVARIANT
*iface
)
61 return CONTAINING_RECORD(iface
, HTMLDOMChildrenCollectionEnum
, IEnumVARIANT_iface
);
64 static HRESULT WINAPI
HTMLDOMChildrenCollectionEnum_QueryInterface(IEnumVARIANT
*iface
, REFIID riid
, void **ppv
)
66 HTMLDOMChildrenCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
68 TRACE("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
70 if(IsEqualGUID(riid
, &IID_IUnknown
)) {
71 *ppv
= &This
->IEnumVARIANT_iface
;
72 }else if(IsEqualGUID(riid
, &IID_IEnumVARIANT
)) {
73 *ppv
= &This
->IEnumVARIANT_iface
;
75 FIXME("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
80 IUnknown_AddRef((IUnknown
*)*ppv
);
84 static ULONG WINAPI
HTMLDOMChildrenCollectionEnum_AddRef(IEnumVARIANT
*iface
)
86 HTMLDOMChildrenCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
87 LONG ref
= InterlockedIncrement(&This
->ref
);
89 TRACE("(%p) ref=%d\n", This
, ref
);
94 static ULONG WINAPI
HTMLDOMChildrenCollectionEnum_Release(IEnumVARIANT
*iface
)
96 HTMLDOMChildrenCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
97 LONG ref
= InterlockedDecrement(&This
->ref
);
99 TRACE("(%p) ref=%d\n", This
, ref
);
102 IHTMLDOMChildrenCollection_Release(&This
->col
->IHTMLDOMChildrenCollection_iface
);
109 static ULONG
get_enum_len(HTMLDOMChildrenCollectionEnum
*This
)
114 nsres
= nsIDOMNodeList_GetLength(This
->col
->nslist
, &len
);
115 assert(nsres
== NS_OK
);
119 static HRESULT WINAPI
HTMLDOMChildrenCollectionEnum_Next(IEnumVARIANT
*iface
, ULONG celt
, VARIANT
*rgVar
, ULONG
*pCeltFetched
)
121 HTMLDOMChildrenCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
122 ULONG fetched
= 0, len
;
128 TRACE("(%p)->(%d %p %p)\n", This
, celt
, rgVar
, pCeltFetched
);
130 len
= get_enum_len(This
);
132 while(This
->iter
+fetched
< len
&& fetched
< celt
) {
133 nsres
= nsIDOMNodeList_Item(This
->col
->nslist
, This
->iter
+fetched
, &nsnode
);
134 assert(nsres
== NS_OK
);
136 hres
= get_node(nsnode
, TRUE
, &node
);
137 nsIDOMNode_Release(nsnode
);
139 ERR("get_node failed: %08x\n", hres
);
143 V_VT(rgVar
+fetched
) = VT_DISPATCH
;
144 IHTMLDOMNode_AddRef(&node
->IHTMLDOMNode_iface
);
145 V_DISPATCH(rgVar
+fetched
) = (IDispatch
*)&node
->IHTMLDOMNode_iface
;
149 This
->iter
+= fetched
;
151 *pCeltFetched
= fetched
;
152 return fetched
== celt
? S_OK
: S_FALSE
;
155 static HRESULT WINAPI
HTMLDOMChildrenCollectionEnum_Skip(IEnumVARIANT
*iface
, ULONG celt
)
157 HTMLDOMChildrenCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
160 TRACE("(%p)->(%d)\n", This
, celt
);
162 len
= get_enum_len(This
);
163 if(This
->iter
+ celt
> len
) {
172 static HRESULT WINAPI
HTMLDOMChildrenCollectionEnum_Reset(IEnumVARIANT
*iface
)
174 HTMLDOMChildrenCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
176 TRACE("(%p)->()\n", This
);
182 static HRESULT WINAPI
HTMLDOMChildrenCollectionEnum_Clone(IEnumVARIANT
*iface
, IEnumVARIANT
**ppEnum
)
184 HTMLDOMChildrenCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
185 FIXME("(%p)->(%p)\n", This
, ppEnum
);
189 static const IEnumVARIANTVtbl HTMLDOMChildrenCollectionEnumVtbl
= {
190 HTMLDOMChildrenCollectionEnum_QueryInterface
,
191 HTMLDOMChildrenCollectionEnum_AddRef
,
192 HTMLDOMChildrenCollectionEnum_Release
,
193 HTMLDOMChildrenCollectionEnum_Next
,
194 HTMLDOMChildrenCollectionEnum_Skip
,
195 HTMLDOMChildrenCollectionEnum_Reset
,
196 HTMLDOMChildrenCollectionEnum_Clone
199 static inline HTMLDOMChildrenCollection
*impl_from_IHTMLDOMChildrenCollection(IHTMLDOMChildrenCollection
*iface
)
201 return CONTAINING_RECORD(iface
, HTMLDOMChildrenCollection
, IHTMLDOMChildrenCollection_iface
);
204 static HRESULT WINAPI
HTMLDOMChildrenCollection_QueryInterface(IHTMLDOMChildrenCollection
*iface
, REFIID riid
, void **ppv
)
206 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
208 TRACE("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
210 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
211 *ppv
= &This
->IHTMLDOMChildrenCollection_iface
;
212 }else if(IsEqualGUID(&IID_IHTMLDOMChildrenCollection
, riid
)) {
213 *ppv
= &This
->IHTMLDOMChildrenCollection_iface
;
214 }else if(dispex_query_interface(&This
->dispex
, riid
, ppv
)) {
215 return *ppv
? S_OK
: E_NOINTERFACE
;
218 WARN("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
219 return E_NOINTERFACE
;
222 IUnknown_AddRef((IUnknown
*)*ppv
);
226 static ULONG WINAPI
HTMLDOMChildrenCollection_AddRef(IHTMLDOMChildrenCollection
*iface
)
228 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
229 LONG ref
= InterlockedIncrement(&This
->ref
);
231 TRACE("(%p) ref=%d\n", This
, ref
);
236 static ULONG WINAPI
HTMLDOMChildrenCollection_Release(IHTMLDOMChildrenCollection
*iface
)
238 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
239 LONG ref
= InterlockedDecrement(&This
->ref
);
241 TRACE("(%p) ref=%d\n", This
, ref
);
244 nsIDOMNodeList_Release(This
->nslist
);
251 static HRESULT WINAPI
HTMLDOMChildrenCollection_GetTypeInfoCount(IHTMLDOMChildrenCollection
*iface
, UINT
*pctinfo
)
253 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
254 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
257 static HRESULT WINAPI
HTMLDOMChildrenCollection_GetTypeInfo(IHTMLDOMChildrenCollection
*iface
, UINT iTInfo
,
258 LCID lcid
, ITypeInfo
**ppTInfo
)
260 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
261 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
264 static HRESULT WINAPI
HTMLDOMChildrenCollection_GetIDsOfNames(IHTMLDOMChildrenCollection
*iface
, REFIID riid
,
265 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
267 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
268 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
272 static HRESULT WINAPI
HTMLDOMChildrenCollection_Invoke(IHTMLDOMChildrenCollection
*iface
, DISPID dispIdMember
,
273 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
274 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
276 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
277 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
278 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
281 static HRESULT WINAPI
HTMLDOMChildrenCollection_get_length(IHTMLDOMChildrenCollection
*iface
, LONG
*p
)
283 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
286 TRACE("(%p)->(%p)\n", This
, p
);
288 nsIDOMNodeList_GetLength(This
->nslist
, &length
);
293 static HRESULT WINAPI
HTMLDOMChildrenCollection_get__newEnum(IHTMLDOMChildrenCollection
*iface
, IUnknown
**p
)
295 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
296 HTMLDOMChildrenCollectionEnum
*ret
;
298 TRACE("(%p)->(%p)\n", This
, p
);
300 ret
= heap_alloc(sizeof(*ret
));
302 return E_OUTOFMEMORY
;
304 ret
->IEnumVARIANT_iface
.lpVtbl
= &HTMLDOMChildrenCollectionEnumVtbl
;
308 IHTMLDOMChildrenCollection_AddRef(&This
->IHTMLDOMChildrenCollection_iface
);
311 *p
= (IUnknown
*)&ret
->IEnumVARIANT_iface
;
315 static HRESULT WINAPI
HTMLDOMChildrenCollection_item(IHTMLDOMChildrenCollection
*iface
, LONG index
, IDispatch
**ppItem
)
317 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
318 nsIDOMNode
*nsnode
= NULL
;
324 TRACE("(%p)->(%d %p)\n", This
, index
, ppItem
);
331 nsIDOMNodeList_GetLength(This
->nslist
, &length
);
332 if(index
< 0 || index
>= length
)
335 nsres
= nsIDOMNodeList_Item(This
->nslist
, index
, &nsnode
);
336 if(NS_FAILED(nsres
) || !nsnode
) {
337 ERR("Item failed: %08x\n", nsres
);
341 hres
= get_node(nsnode
, TRUE
, &node
);
345 *ppItem
= (IDispatch
*)&node
->IHTMLDOMNode_iface
;
349 static const IHTMLDOMChildrenCollectionVtbl HTMLDOMChildrenCollectionVtbl
= {
350 HTMLDOMChildrenCollection_QueryInterface
,
351 HTMLDOMChildrenCollection_AddRef
,
352 HTMLDOMChildrenCollection_Release
,
353 HTMLDOMChildrenCollection_GetTypeInfoCount
,
354 HTMLDOMChildrenCollection_GetTypeInfo
,
355 HTMLDOMChildrenCollection_GetIDsOfNames
,
356 HTMLDOMChildrenCollection_Invoke
,
357 HTMLDOMChildrenCollection_get_length
,
358 HTMLDOMChildrenCollection_get__newEnum
,
359 HTMLDOMChildrenCollection_item
362 static inline HTMLDOMChildrenCollection
*impl_from_DispatchEx(DispatchEx
*iface
)
364 return CONTAINING_RECORD(iface
, HTMLDOMChildrenCollection
, dispex
);
367 #define DISPID_CHILDCOL_0 MSHTML_DISPID_CUSTOM_MIN
369 static HRESULT
HTMLDOMChildrenCollection_get_dispid(DispatchEx
*dispex
, BSTR name
, DWORD flags
, DISPID
*dispid
)
371 HTMLDOMChildrenCollection
*This
= impl_from_DispatchEx(dispex
);
376 for(ptr
= name
; *ptr
&& is_digit(*ptr
); ptr
++)
377 idx
= idx
*10 + (*ptr
-'0');
379 return DISP_E_UNKNOWNNAME
;
381 nsIDOMNodeList_GetLength(This
->nslist
, &len
);
383 return DISP_E_UNKNOWNNAME
;
385 *dispid
= DISPID_CHILDCOL_0
+ idx
;
386 TRACE("ret %x\n", *dispid
);
390 static HRESULT
HTMLDOMChildrenCollection_invoke(DispatchEx
*dispex
, DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
391 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
393 HTMLDOMChildrenCollection
*This
= impl_from_DispatchEx(dispex
);
395 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, flags
, params
, res
, ei
, caller
);
398 case DISPATCH_PROPERTYGET
: {
399 IDispatch
*disp
= NULL
;
402 hres
= IHTMLDOMChildrenCollection_item(&This
->IHTMLDOMChildrenCollection_iface
,
403 id
- DISPID_CHILDCOL_0
, &disp
);
407 V_VT(res
) = VT_DISPATCH
;
408 V_DISPATCH(res
) = disp
;
413 FIXME("unimplemented flags %x\n", flags
);
420 static const dispex_static_data_vtbl_t HTMLDOMChildrenCollection_dispex_vtbl
= {
422 HTMLDOMChildrenCollection_get_dispid
,
423 HTMLDOMChildrenCollection_invoke
,
427 static const tid_t HTMLDOMChildrenCollection_iface_tids
[] = {
428 IHTMLDOMChildrenCollection_tid
,
432 static dispex_static_data_t HTMLDOMChildrenCollection_dispex
= {
433 &HTMLDOMChildrenCollection_dispex_vtbl
,
434 DispDOMChildrenCollection_tid
,
435 HTMLDOMChildrenCollection_iface_tids
,
436 HTMLDOMNode_init_dispex_info
439 IHTMLDOMChildrenCollection
*create_child_collection(nsIDOMNodeList
*nslist
)
441 HTMLDOMChildrenCollection
*ret
;
443 ret
= heap_alloc_zero(sizeof(*ret
));
447 ret
->IHTMLDOMChildrenCollection_iface
.lpVtbl
= &HTMLDOMChildrenCollectionVtbl
;
450 nsIDOMNodeList_AddRef(nslist
);
451 ret
->nslist
= nslist
;
453 init_dispex(&ret
->dispex
, (IUnknown
*)&ret
->IHTMLDOMChildrenCollection_iface
,
454 &HTMLDOMChildrenCollection_dispex
);
456 return &ret
->IHTMLDOMChildrenCollection_iface
;
459 static inline HTMLDOMNode
*impl_from_IHTMLDOMNode(IHTMLDOMNode
*iface
)
461 return CONTAINING_RECORD(iface
, HTMLDOMNode
, IHTMLDOMNode_iface
);
464 static HRESULT WINAPI
HTMLDOMNode_QueryInterface(IHTMLDOMNode
*iface
,
465 REFIID riid
, void **ppv
)
467 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
469 return This
->vtbl
->qi(This
, riid
, ppv
);
472 static ULONG WINAPI
HTMLDOMNode_AddRef(IHTMLDOMNode
*iface
)
474 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
477 ref
= ccref_incr(&This
->ccref
, (nsISupports
*)&This
->IHTMLDOMNode_iface
);
479 TRACE("(%p) ref=%d\n", This
, ref
);
484 static ULONG WINAPI
HTMLDOMNode_Release(IHTMLDOMNode
*iface
)
486 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
487 LONG ref
= ccref_decr(&This
->ccref
, (nsISupports
*)&This
->IHTMLDOMNode_iface
, /*&node_ccp*/ NULL
);
489 TRACE("(%p) ref=%d\n", This
, ref
);
494 static HRESULT WINAPI
HTMLDOMNode_GetTypeInfoCount(IHTMLDOMNode
*iface
, UINT
*pctinfo
)
496 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
497 return IDispatchEx_GetTypeInfoCount(&This
->event_target
.dispex
.IDispatchEx_iface
, pctinfo
);
500 static HRESULT WINAPI
HTMLDOMNode_GetTypeInfo(IHTMLDOMNode
*iface
, UINT iTInfo
,
501 LCID lcid
, ITypeInfo
**ppTInfo
)
503 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
504 return IDispatchEx_GetTypeInfo(&This
->event_target
.dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
507 static HRESULT WINAPI
HTMLDOMNode_GetIDsOfNames(IHTMLDOMNode
*iface
, REFIID riid
,
508 LPOLESTR
*rgszNames
, UINT cNames
,
509 LCID lcid
, DISPID
*rgDispId
)
511 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
512 return IDispatchEx_GetIDsOfNames(&This
->event_target
.dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
516 static HRESULT WINAPI
HTMLDOMNode_Invoke(IHTMLDOMNode
*iface
, DISPID dispIdMember
,
517 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
518 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
520 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
521 return IDispatchEx_Invoke(&This
->event_target
.dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
522 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
525 static HRESULT WINAPI
HTMLDOMNode_get_nodeType(IHTMLDOMNode
*iface
, LONG
*p
)
527 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
530 TRACE("(%p)->(%p)\n", This
, p
);
532 nsIDOMNode_GetNodeType(This
->nsnode
, &type
);
542 case DOCUMENT_TYPE_NODE
:
548 case DOCUMENT_FRAGMENT_NODE
:
554 * According to MSDN only ELEMENT_NODE and TEXT_NODE are supported.
555 * It needs more tests.
557 FIXME("type %u\n", type
);
564 static HRESULT WINAPI
HTMLDOMNode_get_parentNode(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
566 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
572 TRACE("(%p)->(%p)\n", This
, p
);
574 nsres
= nsIDOMNode_GetParentNode(This
->nsnode
, &nsnode
);
575 if(NS_FAILED(nsres
)) {
576 ERR("GetParentNode failed: %08x\n", nsres
);
585 hres
= get_node(nsnode
, TRUE
, &node
);
586 nsIDOMNode_Release(nsnode
);
590 *p
= &node
->IHTMLDOMNode_iface
;
594 static HRESULT WINAPI
HTMLDOMNode_hasChildNodes(IHTMLDOMNode
*iface
, VARIANT_BOOL
*fChildren
)
596 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
597 cpp_bool has_child
= FALSE
;
600 TRACE("(%p)->(%p)\n", This
, fChildren
);
602 nsres
= nsIDOMNode_HasChildNodes(This
->nsnode
, &has_child
);
604 ERR("HasChildNodes failed: %08x\n", nsres
);
606 *fChildren
= variant_bool(has_child
);
610 static HRESULT WINAPI
HTMLDOMNode_get_childNodes(IHTMLDOMNode
*iface
, IDispatch
**p
)
612 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
613 nsIDOMNodeList
*nslist
;
616 TRACE("(%p)->(%p)\n", This
, p
);
618 nsres
= nsIDOMNode_GetChildNodes(This
->nsnode
, &nslist
);
619 if(NS_FAILED(nsres
)) {
620 ERR("GetChildNodes failed: %08x\n", nsres
);
624 *p
= (IDispatch
*)create_child_collection(nslist
);
625 nsIDOMNodeList_Release(nslist
);
627 return *p
? S_OK
: E_OUTOFMEMORY
;
630 static HRESULT WINAPI
HTMLDOMNode_get_attributes(IHTMLDOMNode
*iface
, IDispatch
**p
)
632 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
633 HTMLAttributeCollection
*col
;
636 TRACE("(%p)->(%p)\n", This
, p
);
638 if(This
->vtbl
->get_attr_col
) {
639 hres
= This
->vtbl
->get_attr_col(This
, &col
);
643 *p
= (IDispatch
*)&col
->IHTMLAttributeCollection_iface
;
651 static HRESULT WINAPI
HTMLDOMNode_insertBefore(IHTMLDOMNode
*iface
, IHTMLDOMNode
*newChild
,
652 VARIANT refChild
, IHTMLDOMNode
**node
)
654 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
655 HTMLDOMNode
*new_child
, *node_obj
, *ref_node
= NULL
;
660 TRACE("(%p)->(%p %s %p)\n", This
, newChild
, debugstr_variant(&refChild
), node
);
662 new_child
= get_node_obj(newChild
);
664 ERR("invalid newChild\n");
668 switch(V_VT(&refChild
)) {
672 IHTMLDOMNode
*ref_iface
;
674 if(!V_DISPATCH(&refChild
))
677 hres
= IDispatch_QueryInterface(V_DISPATCH(&refChild
), &IID_IHTMLDOMNode
, (void**)&ref_iface
);
681 ref_node
= get_node_obj(ref_iface
);
682 IHTMLDOMNode_Release(ref_iface
);
684 ERR("unvalid node\n");
691 FIXME("unimplemented refChild %s\n", debugstr_variant(&refChild
));
695 if(SUCCEEDED(hres
)) {
696 nsres
= nsIDOMNode_InsertBefore(This
->nsnode
, new_child
->nsnode
, ref_node
? ref_node
->nsnode
: NULL
, &nsnode
);
697 if(NS_FAILED(nsres
)) {
698 ERR("InsertBefore failed: %08x\n", nsres
);
702 node_release(new_child
);
704 node_release(ref_node
);
708 hres
= get_node(nsnode
, TRUE
, &node_obj
);
709 nsIDOMNode_Release(nsnode
);
713 *node
= &node_obj
->IHTMLDOMNode_iface
;
717 static HRESULT WINAPI
HTMLDOMNode_removeChild(IHTMLDOMNode
*iface
, IHTMLDOMNode
*oldChild
,
720 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
721 HTMLDOMNode
*node_obj
;
726 TRACE("(%p)->(%p %p)\n", This
, oldChild
, node
);
728 node_obj
= get_node_obj(oldChild
);
732 nsres
= nsIDOMNode_RemoveChild(This
->nsnode
, node_obj
->nsnode
, &nsnode
);
733 node_release(node_obj
);
734 if(NS_FAILED(nsres
)) {
735 ERR("RemoveChild failed: %08x\n", nsres
);
739 hres
= get_node(nsnode
, TRUE
, &node_obj
);
740 nsIDOMNode_Release(nsnode
);
744 /* FIXME: Make sure that node != newChild */
745 *node
= &node_obj
->IHTMLDOMNode_iface
;
749 static HRESULT WINAPI
HTMLDOMNode_replaceChild(IHTMLDOMNode
*iface
, IHTMLDOMNode
*newChild
,
750 IHTMLDOMNode
*oldChild
, IHTMLDOMNode
**node
)
752 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
753 HTMLDOMNode
*node_new
, *node_old
, *ret_node
;
758 TRACE("(%p)->(%p %p %p)\n", This
, newChild
, oldChild
, node
);
760 node_new
= get_node_obj(newChild
);
764 node_old
= get_node_obj(oldChild
);
766 node_release(node_new
);
770 nsres
= nsIDOMNode_ReplaceChild(This
->nsnode
, node_new
->nsnode
, node_old
->nsnode
, &nsnode
);
771 node_release(node_new
);
772 node_release(node_old
);
776 hres
= get_node(nsnode
, TRUE
, &ret_node
);
777 nsIDOMNode_Release(nsnode
);
781 *node
= &ret_node
->IHTMLDOMNode_iface
;
785 static HRESULT WINAPI
HTMLDOMNode_cloneNode(IHTMLDOMNode
*iface
, VARIANT_BOOL fDeep
,
786 IHTMLDOMNode
**clonedNode
)
788 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
789 HTMLDOMNode
*new_node
;
794 TRACE("(%p)->(%x %p)\n", This
, fDeep
, clonedNode
);
796 nsres
= nsIDOMNode_CloneNode(This
->nsnode
, fDeep
!= VARIANT_FALSE
, 1, &nsnode
);
797 if(NS_FAILED(nsres
) || !nsnode
) {
798 ERR("CloneNode failed: %08x\n", nsres
);
802 hres
= This
->vtbl
->clone(This
, nsnode
, &new_node
);
806 *clonedNode
= &new_node
->IHTMLDOMNode_iface
;
810 static HRESULT WINAPI
HTMLDOMNode_removeNode(IHTMLDOMNode
*iface
, VARIANT_BOOL fDeep
,
811 IHTMLDOMNode
**removed
)
813 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
814 FIXME("(%p)->(%x %p)\n", This
, fDeep
, removed
);
818 static HRESULT WINAPI
HTMLDOMNode_swapNode(IHTMLDOMNode
*iface
, IHTMLDOMNode
*otherNode
,
819 IHTMLDOMNode
**swappedNode
)
821 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
822 FIXME("(%p)->(%p %p)\n", This
, otherNode
, swappedNode
);
826 static HRESULT WINAPI
HTMLDOMNode_replaceNode(IHTMLDOMNode
*iface
, IHTMLDOMNode
*replacement
,
827 IHTMLDOMNode
**replaced
)
829 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
830 FIXME("(%p)->(%p %p)\n", This
, replacement
, replaced
);
834 static HRESULT WINAPI
HTMLDOMNode_appendChild(IHTMLDOMNode
*iface
, IHTMLDOMNode
*newChild
,
837 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
838 HTMLDOMNode
*node_obj
;
843 TRACE("(%p)->(%p %p)\n", This
, newChild
, node
);
845 node_obj
= get_node_obj(newChild
);
849 nsres
= nsIDOMNode_AppendChild(This
->nsnode
, node_obj
->nsnode
, &nsnode
);
850 node_release(node_obj
);
851 if(NS_FAILED(nsres
)) {
852 ERR("AppendChild failed: %08x\n", nsres
);
856 hres
= get_node(nsnode
, TRUE
, &node_obj
);
857 nsIDOMNode_Release(nsnode
);
861 /* FIXME: Make sure that node != newChild */
862 *node
= &node_obj
->IHTMLDOMNode_iface
;
866 static HRESULT WINAPI
HTMLDOMNode_get_nodeName(IHTMLDOMNode
*iface
, BSTR
*p
)
868 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
872 TRACE("(%p)->(%p)\n", This
, p
);
874 nsAString_Init(&name
, NULL
);
875 nsres
= nsIDOMNode_GetNodeName(This
->nsnode
, &name
);
876 return return_nsstr(nsres
, &name
, p
);
879 static HRESULT WINAPI
HTMLDOMNode_put_nodeValue(IHTMLDOMNode
*iface
, VARIANT v
)
881 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
883 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&v
));
889 nsAString_InitDepend(&val_str
, V_BSTR(&v
));
890 nsIDOMNode_SetNodeValue(This
->nsnode
, &val_str
);
891 nsAString_Finish(&val_str
);
897 FIXME("unsupported value %s\n", debugstr_variant(&v
));
903 static HRESULT WINAPI
HTMLDOMNode_get_nodeValue(IHTMLDOMNode
*iface
, VARIANT
*p
)
905 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
906 const PRUnichar
*val
;
909 TRACE("(%p)->(%p)\n", This
, p
);
911 nsAString_Init(&val_str
, NULL
);
912 nsIDOMNode_GetNodeValue(This
->nsnode
, &val_str
);
913 nsAString_GetData(&val_str
, &val
);
917 V_BSTR(p
) = SysAllocString(val
);
922 nsAString_Finish(&val_str
);
927 static HRESULT WINAPI
HTMLDOMNode_get_firstChild(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
929 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
930 nsIDOMNode
*nschild
= NULL
;
934 TRACE("(%p)->(%p)\n", This
, p
);
936 nsIDOMNode_GetFirstChild(This
->nsnode
, &nschild
);
942 hres
= get_node(nschild
, TRUE
, &node
);
943 nsIDOMNode_Release(nschild
);
947 *p
= &node
->IHTMLDOMNode_iface
;
951 static HRESULT WINAPI
HTMLDOMNode_get_lastChild(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
953 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
954 nsIDOMNode
*nschild
= NULL
;
958 TRACE("(%p)->(%p)\n", This
, p
);
960 nsIDOMNode_GetLastChild(This
->nsnode
, &nschild
);
966 hres
= get_node(nschild
, TRUE
, &node
);
967 nsIDOMNode_Release(nschild
);
971 *p
= &node
->IHTMLDOMNode_iface
;
975 static HRESULT WINAPI
HTMLDOMNode_get_previousSibling(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
977 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
978 nsIDOMNode
*nschild
= NULL
;
982 TRACE("(%p)->(%p)\n", This
, p
);
984 nsIDOMNode_GetPreviousSibling(This
->nsnode
, &nschild
);
990 hres
= get_node(nschild
, TRUE
, &node
);
991 nsIDOMNode_Release(nschild
);
995 *p
= &node
->IHTMLDOMNode_iface
;
999 static HRESULT WINAPI
HTMLDOMNode_get_nextSibling(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
1001 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
1002 nsIDOMNode
*nssibling
= NULL
;
1006 TRACE("(%p)->(%p)\n", This
, p
);
1008 nsIDOMNode_GetNextSibling(This
->nsnode
, &nssibling
);
1014 hres
= get_node(nssibling
, TRUE
, &node
);
1015 nsIDOMNode_Release(nssibling
);
1019 *p
= &node
->IHTMLDOMNode_iface
;
1023 static const IHTMLDOMNodeVtbl HTMLDOMNodeVtbl
= {
1024 HTMLDOMNode_QueryInterface
,
1026 HTMLDOMNode_Release
,
1027 HTMLDOMNode_GetTypeInfoCount
,
1028 HTMLDOMNode_GetTypeInfo
,
1029 HTMLDOMNode_GetIDsOfNames
,
1031 HTMLDOMNode_get_nodeType
,
1032 HTMLDOMNode_get_parentNode
,
1033 HTMLDOMNode_hasChildNodes
,
1034 HTMLDOMNode_get_childNodes
,
1035 HTMLDOMNode_get_attributes
,
1036 HTMLDOMNode_insertBefore
,
1037 HTMLDOMNode_removeChild
,
1038 HTMLDOMNode_replaceChild
,
1039 HTMLDOMNode_cloneNode
,
1040 HTMLDOMNode_removeNode
,
1041 HTMLDOMNode_swapNode
,
1042 HTMLDOMNode_replaceNode
,
1043 HTMLDOMNode_appendChild
,
1044 HTMLDOMNode_get_nodeName
,
1045 HTMLDOMNode_put_nodeValue
,
1046 HTMLDOMNode_get_nodeValue
,
1047 HTMLDOMNode_get_firstChild
,
1048 HTMLDOMNode_get_lastChild
,
1049 HTMLDOMNode_get_previousSibling
,
1050 HTMLDOMNode_get_nextSibling
1053 static HTMLDOMNode
*get_node_obj(IHTMLDOMNode
*iface
)
1057 if(iface
->lpVtbl
!= &HTMLDOMNodeVtbl
)
1060 ret
= impl_from_IHTMLDOMNode(iface
);
1065 static inline HTMLDOMNode
*impl_from_IHTMLDOMNode2(IHTMLDOMNode2
*iface
)
1067 return CONTAINING_RECORD(iface
, HTMLDOMNode
, IHTMLDOMNode2_iface
);
1070 static HRESULT WINAPI
HTMLDOMNode2_QueryInterface(IHTMLDOMNode2
*iface
,
1071 REFIID riid
, void **ppv
)
1073 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
1075 return IHTMLDOMNode_QueryInterface(&This
->IHTMLDOMNode_iface
, riid
, ppv
);
1078 static ULONG WINAPI
HTMLDOMNode2_AddRef(IHTMLDOMNode2
*iface
)
1080 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
1082 return IHTMLDOMNode_AddRef(&This
->IHTMLDOMNode_iface
);
1085 static ULONG WINAPI
HTMLDOMNode2_Release(IHTMLDOMNode2
*iface
)
1087 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
1089 return IHTMLDOMNode_Release(&This
->IHTMLDOMNode_iface
);
1092 static HRESULT WINAPI
HTMLDOMNode2_GetTypeInfoCount(IHTMLDOMNode2
*iface
, UINT
*pctinfo
)
1094 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
1095 return IDispatchEx_GetTypeInfoCount(&This
->event_target
.dispex
.IDispatchEx_iface
, pctinfo
);
1098 static HRESULT WINAPI
HTMLDOMNode2_GetTypeInfo(IHTMLDOMNode2
*iface
, UINT iTInfo
,
1099 LCID lcid
, ITypeInfo
**ppTInfo
)
1101 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
1102 return IDispatchEx_GetTypeInfo(&This
->event_target
.dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
1105 static HRESULT WINAPI
HTMLDOMNode2_GetIDsOfNames(IHTMLDOMNode2
*iface
, REFIID riid
,
1106 LPOLESTR
*rgszNames
, UINT cNames
,
1107 LCID lcid
, DISPID
*rgDispId
)
1109 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
1110 return IDispatchEx_GetIDsOfNames(&This
->event_target
.dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
1114 static HRESULT WINAPI
HTMLDOMNode2_Invoke(IHTMLDOMNode2
*iface
, DISPID dispIdMember
,
1115 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
1116 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1118 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
1119 return IDispatchEx_Invoke(&This
->event_target
.dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
1120 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1123 static HRESULT WINAPI
HTMLDOMNode2_get_ownerDocument(IHTMLDOMNode2
*iface
, IDispatch
**p
)
1125 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
1127 TRACE("(%p)->(%p)\n", This
, p
);
1129 /* FIXME: Better check for document node */
1130 if(This
== &This
->doc
->node
) {
1133 *p
= (IDispatch
*)&This
->doc
->basedoc
.IHTMLDocument2_iface
;
1134 IDispatch_AddRef(*p
);
1139 static const IHTMLDOMNode2Vtbl HTMLDOMNode2Vtbl
= {
1140 HTMLDOMNode2_QueryInterface
,
1141 HTMLDOMNode2_AddRef
,
1142 HTMLDOMNode2_Release
,
1143 HTMLDOMNode2_GetTypeInfoCount
,
1144 HTMLDOMNode2_GetTypeInfo
,
1145 HTMLDOMNode2_GetIDsOfNames
,
1146 HTMLDOMNode2_Invoke
,
1147 HTMLDOMNode2_get_ownerDocument
1150 static inline HTMLDOMNode
*impl_from_IHTMLDOMNode3(IHTMLDOMNode3
*iface
)
1152 return CONTAINING_RECORD(iface
, HTMLDOMNode
, IHTMLDOMNode3_iface
);
1155 static HRESULT WINAPI
HTMLDOMNode3_QueryInterface(IHTMLDOMNode3
*iface
, REFIID riid
, void **ppv
)
1157 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1158 return IHTMLDOMNode_QueryInterface(&This
->IHTMLDOMNode_iface
, riid
, ppv
);
1161 static ULONG WINAPI
HTMLDOMNode3_AddRef(IHTMLDOMNode3
*iface
)
1163 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1165 return IHTMLDOMNode_AddRef(&This
->IHTMLDOMNode_iface
);
1168 static ULONG WINAPI
HTMLDOMNode3_Release(IHTMLDOMNode3
*iface
)
1170 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1172 return IHTMLDOMNode_Release(&This
->IHTMLDOMNode_iface
);
1175 static HRESULT WINAPI
HTMLDOMNode3_GetTypeInfoCount(IHTMLDOMNode3
*iface
, UINT
*pctinfo
)
1177 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1178 return IDispatchEx_GetTypeInfoCount(&This
->event_target
.dispex
.IDispatchEx_iface
, pctinfo
);
1181 static HRESULT WINAPI
HTMLDOMNode3_GetTypeInfo(IHTMLDOMNode3
*iface
, UINT iTInfo
,
1182 LCID lcid
, ITypeInfo
**ppTInfo
)
1184 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1185 return IDispatchEx_GetTypeInfo(&This
->event_target
.dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
1188 static HRESULT WINAPI
HTMLDOMNode3_GetIDsOfNames(IHTMLDOMNode3
*iface
, REFIID riid
,
1189 LPOLESTR
*rgszNames
, UINT cNames
,
1190 LCID lcid
, DISPID
*rgDispId
)
1192 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1193 return IDispatchEx_GetIDsOfNames(&This
->event_target
.dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
1197 static HRESULT WINAPI
HTMLDOMNode3_Invoke(IHTMLDOMNode3
*iface
, DISPID dispIdMember
,
1198 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
1199 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1201 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1202 return IDispatchEx_Invoke(&This
->event_target
.dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
1203 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1206 static HRESULT WINAPI
HTMLDOMNode3_put_prefix(IHTMLDOMNode3
*iface
, VARIANT v
)
1208 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1209 FIXME("(%p)->(%s)\n", This
, debugstr_variant(&v
));
1213 static HRESULT WINAPI
HTMLDOMNode3_get_prefix(IHTMLDOMNode3
*iface
, VARIANT
*p
)
1215 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1216 FIXME("(%p)->(%p)\n", This
, p
);
1220 static HRESULT WINAPI
HTMLDOMNode3_get_localName(IHTMLDOMNode3
*iface
, VARIANT
*p
)
1222 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1223 FIXME("(%p)->(%p)\n", This
, p
);
1227 static HRESULT WINAPI
HTMLDOMNode3_get_namespaceURI(IHTMLDOMNode3
*iface
, VARIANT
*p
)
1229 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1233 TRACE("(%p)->(%p)\n", This
, p
);
1235 nsAString_InitDepend(&nsstr
, NULL
);
1236 nsres
= nsIDOMNode_GetNamespaceURI(This
->nsnode
, &nsstr
);
1237 return return_nsstr_variant(nsres
, &nsstr
, 0, p
);
1240 static HRESULT WINAPI
HTMLDOMNode3_put_textContent(IHTMLDOMNode3
*iface
, VARIANT v
)
1242 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1246 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&v
));
1248 variant_to_nsstr(&v
, FALSE
, &nsstr
);
1249 nsres
= nsIDOMNode_SetTextContent(This
->nsnode
, &nsstr
);
1250 nsAString_Finish(&nsstr
);
1251 if(NS_FAILED(nsres
)) {
1252 ERR("SetTextContent failed: %08x\n", nsres
);
1259 static HRESULT WINAPI
HTMLDOMNode3_get_textContent(IHTMLDOMNode3
*iface
, VARIANT
*p
)
1261 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1265 TRACE("(%p)->(%p)\n", This
, p
);
1267 nsAString_Init(&nsstr
, NULL
);
1268 nsres
= nsIDOMNode_GetTextContent(This
->nsnode
, &nsstr
);
1269 return return_nsstr_variant(nsres
, &nsstr
, 0, p
);
1272 static HRESULT WINAPI
HTMLDOMNode3_isEqualNode(IHTMLDOMNode3
*iface
, IHTMLDOMNode3
*otherNode
, VARIANT_BOOL
*isEqual
)
1274 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1275 FIXME("(%p)->()\n", This
);
1279 static HRESULT WINAPI
HTMLDOMNode3_lookupNamespaceURI(IHTMLDOMNode3
*iface
, VARIANT
*prefix
, VARIANT
*namespaceURI
)
1281 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1282 FIXME("(%p)->(%s %p)\n", This
, debugstr_variant(prefix
), namespaceURI
);
1286 static HRESULT WINAPI
HTMLDOMNode3_lookupPrefix(IHTMLDOMNode3
*iface
, VARIANT
*namespaceURI
, VARIANT
*prefix
)
1288 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1289 FIXME("(%p)->(%s %p)\n", This
, debugstr_variant(namespaceURI
), prefix
);
1293 static HRESULT WINAPI
HTMLDOMNode3_isDefaultNamespace(IHTMLDOMNode3
*iface
, VARIANT
*namespace, VARIANT_BOOL
*pfDefaultNamespace
)
1295 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1296 FIXME("(%p)->()\n", This
);
1300 static HRESULT WINAPI
HTMLDOMNode3_appendChild(IHTMLDOMNode3
*iface
, IHTMLDOMNode
*newChild
, IHTMLDOMNode
**node
)
1302 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1303 TRACE("(%p)->()\n", This
);
1304 return IHTMLDOMNode_appendChild(&This
->IHTMLDOMNode_iface
, newChild
, node
);
1307 static HRESULT WINAPI
HTMLDOMNode3_insertBefore(IHTMLDOMNode3
*iface
, IHTMLDOMNode
*newChild
, VARIANT refChild
, IHTMLDOMNode
**node
)
1309 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1310 TRACE("(%p)->(%p %s %p)\n", This
, newChild
, debugstr_variant(&refChild
), node
);
1311 return IHTMLDOMNode_insertBefore(&This
->IHTMLDOMNode_iface
, newChild
, refChild
, node
);
1314 static HRESULT WINAPI
HTMLDOMNode3_removeChild(IHTMLDOMNode3
*iface
, IHTMLDOMNode
*oldChild
, IHTMLDOMNode
**node
)
1316 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1317 TRACE("(%p)->(%p %p)\n", This
, oldChild
, node
);
1318 return IHTMLDOMNode_removeChild(&This
->IHTMLDOMNode_iface
, oldChild
, node
);
1321 static HRESULT WINAPI
HTMLDOMNode3_replaceChild(IHTMLDOMNode3
*iface
, IHTMLDOMNode
*newChild
, IHTMLDOMNode
*oldChild
, IHTMLDOMNode
**node
)
1323 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1324 TRACE("(%p)->(%p %p %p)\n", This
, newChild
, oldChild
, node
);
1325 return IHTMLDOMNode_replaceChild(&This
->IHTMLDOMNode_iface
, newChild
, oldChild
, node
);
1328 static HRESULT WINAPI
HTMLDOMNode3_isSameNode(IHTMLDOMNode3
*iface
, IHTMLDOMNode3
*otherNode
, VARIANT_BOOL
*isSame
)
1330 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1331 FIXME("(%p)->()\n", This
);
1335 static HRESULT WINAPI
HTMLDOMNode3_compareDocumentPosition(IHTMLDOMNode3
*iface
, IHTMLDOMNode
*otherNode
, USHORT
*flags
)
1337 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1342 TRACE("(%p)->()\n", This
);
1344 other
= get_node_obj(otherNode
);
1346 return E_INVALIDARG
;
1348 nsres
= nsIDOMNode_CompareDocumentPosition(This
->nsnode
, other
->nsnode
, &position
);
1349 IHTMLDOMNode_Release(&other
->IHTMLDOMNode_iface
);
1350 if(NS_FAILED(nsres
)) {
1351 ERR("failed: %08x\n", nsres
);
1359 static HRESULT WINAPI
HTMLDOMNode3_isSupported(IHTMLDOMNode3
*iface
, BSTR feature
, VARIANT version
, VARIANT_BOOL
*pfisSupported
)
1361 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1362 FIXME("(%p)->(%s %s %p)\n", This
, debugstr_w(feature
), debugstr_variant(&version
), pfisSupported
);
1366 static const IHTMLDOMNode3Vtbl HTMLDOMNode3Vtbl
= {
1367 HTMLDOMNode3_QueryInterface
,
1368 HTMLDOMNode3_AddRef
,
1369 HTMLDOMNode3_Release
,
1370 HTMLDOMNode3_GetTypeInfoCount
,
1371 HTMLDOMNode3_GetTypeInfo
,
1372 HTMLDOMNode3_GetIDsOfNames
,
1373 HTMLDOMNode3_Invoke
,
1374 HTMLDOMNode3_put_prefix
,
1375 HTMLDOMNode3_get_prefix
,
1376 HTMLDOMNode3_get_localName
,
1377 HTMLDOMNode3_get_namespaceURI
,
1378 HTMLDOMNode3_put_textContent
,
1379 HTMLDOMNode3_get_textContent
,
1380 HTMLDOMNode3_isEqualNode
,
1381 HTMLDOMNode3_lookupNamespaceURI
,
1382 HTMLDOMNode3_lookupPrefix
,
1383 HTMLDOMNode3_isDefaultNamespace
,
1384 HTMLDOMNode3_appendChild
,
1385 HTMLDOMNode3_insertBefore
,
1386 HTMLDOMNode3_removeChild
,
1387 HTMLDOMNode3_replaceChild
,
1388 HTMLDOMNode3_isSameNode
,
1389 HTMLDOMNode3_compareDocumentPosition
,
1390 HTMLDOMNode3_isSupported
1393 HRESULT
HTMLDOMNode_QI(HTMLDOMNode
*This
, REFIID riid
, void **ppv
)
1395 TRACE("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
1397 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
1398 *ppv
= &This
->IHTMLDOMNode_iface
;
1399 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
1400 *ppv
= &This
->IHTMLDOMNode_iface
;
1401 }else if(IsEqualGUID(&IID_IHTMLDOMNode
, riid
)) {
1402 *ppv
= &This
->IHTMLDOMNode_iface
;
1403 }else if(IsEqualGUID(&IID_IHTMLDOMNode2
, riid
)) {
1404 *ppv
= &This
->IHTMLDOMNode2_iface
;
1405 }else if(IsEqualGUID(&IID_IHTMLDOMNode3
, riid
)) {
1406 *ppv
= &This
->IHTMLDOMNode3_iface
;
1407 }else if(IsEqualGUID(&IID_nsXPCOMCycleCollectionParticipant
, riid
)) {
1410 }else if(IsEqualGUID(&IID_nsCycleCollectionISupports
, riid
)) {
1411 *ppv
= &This
->IHTMLDOMNode_iface
;
1414 return EventTarget_QI(&This
->event_target
, riid
, ppv
);
1417 IUnknown_AddRef((IUnknown
*)*ppv
);
1421 void HTMLDOMNode_destructor(HTMLDOMNode
*This
)
1423 release_event_target(&This
->event_target
);
1425 nsIDOMNode_Release(This
->nsnode
);
1426 if(This
->doc
&& &This
->doc
->node
!= This
)
1427 htmldoc_release(&This
->doc
->basedoc
);
1430 static HRESULT
HTMLDOMNode_clone(HTMLDOMNode
*This
, nsIDOMNode
*nsnode
, HTMLDOMNode
**ret
)
1432 return create_node(This
->doc
, nsnode
, ret
);
1435 void HTMLDOMNode_init_dispex_info(dispex_data_t
*info
, compat_mode_t mode
)
1437 if(mode
>= COMPAT_MODE_IE9
)
1438 dispex_info_add_interface(info
, IHTMLDOMNode3_tid
, NULL
);
1440 EventTarget_init_dispex_info(info
, mode
);
1443 static const cpc_entry_t HTMLDOMNode_cpc
[] = {{NULL
}};
1445 static const NodeImplVtbl HTMLDOMNodeImplVtbl
= {
1448 HTMLDOMNode_destructor
,
1453 void HTMLDOMNode_Init(HTMLDocumentNode
*doc
, HTMLDOMNode
*node
, nsIDOMNode
*nsnode
, dispex_static_data_t
*dispex_data
)
1457 node
->IHTMLDOMNode_iface
.lpVtbl
= &HTMLDOMNodeVtbl
;
1458 node
->IHTMLDOMNode2_iface
.lpVtbl
= &HTMLDOMNode2Vtbl
;
1459 node
->IHTMLDOMNode3_iface
.lpVtbl
= &HTMLDOMNode3Vtbl
;
1461 ccref_init(&node
->ccref
, 1);
1462 EventTarget_Init(&node
->event_target
, (IUnknown
*)&node
->IHTMLDOMNode_iface
, dispex_data
, doc
->document_mode
);
1464 if(&doc
->node
!= node
)
1465 htmldoc_addref(&doc
->basedoc
);
1468 nsIDOMNode_AddRef(nsnode
);
1469 node
->nsnode
= nsnode
;
1471 nsres
= nsIDOMNode_SetMshtmlNode(nsnode
, (nsISupports
*)&node
->IHTMLDOMNode_iface
);
1472 assert(nsres
== NS_OK
);
1475 static const tid_t HTMLDOMNode_iface_tids
[] = {
1479 static dispex_static_data_t HTMLDOMNode_dispex
= {
1482 HTMLDOMNode_iface_tids
,
1483 HTMLDOMNode_init_dispex_info
1486 static HRESULT
create_node(HTMLDocumentNode
*doc
, nsIDOMNode
*nsnode
, HTMLDOMNode
**ret
)
1491 nsIDOMNode_GetNodeType(nsnode
, &node_type
);
1494 case ELEMENT_NODE
: {
1496 hres
= HTMLElement_Create(doc
, nsnode
, FALSE
, &elem
);
1503 hres
= HTMLDOMTextNode_Create(doc
, nsnode
, ret
);
1507 /* doctype nodes are represented as comment nodes (at least in quirks mode) */
1508 case DOCUMENT_TYPE_NODE
:
1509 case COMMENT_NODE
: {
1510 HTMLElement
*comment
;
1511 hres
= HTMLCommentElement_Create(doc
, nsnode
, &comment
);
1514 *ret
= &comment
->node
;
1517 case ATTRIBUTE_NODE
:
1518 ERR("Called on attribute node\n");
1519 return E_UNEXPECTED
;
1523 FIXME("unimplemented node type %u\n", node_type
);
1525 node
= heap_alloc_zero(sizeof(HTMLDOMNode
));
1527 return E_OUTOFMEMORY
;
1529 node
->vtbl
= &HTMLDOMNodeImplVtbl
;
1530 HTMLDOMNode_Init(doc
, node
, nsnode
, &HTMLDOMNode_dispex
);
1535 TRACE("type %d ret %p\n", node_type
, *ret
);
1539 static nsresult NSAPI
HTMLDOMNode_traverse(void *ccp
, void *p
, nsCycleCollectionTraversalCallback
*cb
)
1541 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(p
);
1543 TRACE("%p\n", This
);
1545 describe_cc_node(&This
->ccref
, "HTMLDOMNode", cb
);
1548 note_cc_edge((nsISupports
*)This
->nsnode
, "This->nsnode", cb
);
1549 if(This
->doc
&& &This
->doc
->node
!= This
)
1550 note_cc_edge((nsISupports
*)&This
->doc
->node
.IHTMLDOMNode_iface
, "This->doc", cb
);
1551 dispex_traverse(&This
->event_target
.dispex
, cb
);
1553 if(This
->vtbl
->traverse
)
1554 This
->vtbl
->traverse(This
, cb
);
1559 static nsresult NSAPI
HTMLDOMNode_unlink(void *p
)
1561 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(p
);
1563 TRACE("%p\n", This
);
1565 if(This
->vtbl
->unlink
)
1566 This
->vtbl
->unlink(This
);
1568 dispex_unlink(&This
->event_target
.dispex
);
1571 nsIDOMNode
*nsnode
= This
->nsnode
;
1572 This
->nsnode
= NULL
;
1573 nsIDOMNode_Release(nsnode
);
1576 if(This
->doc
&& &This
->doc
->node
!= This
) {
1577 HTMLDocumentNode
*doc
= This
->doc
;
1579 htmldoc_release(&doc
->basedoc
);
1587 static void NSAPI
HTMLDOMNode_delete_cycle_collectable(void *p
)
1589 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(p
);
1591 TRACE("(%p)\n", This
);
1593 if(This
->vtbl
->unlink
)
1594 This
->vtbl
->unlink(This
);
1595 This
->vtbl
->destructor(This
);
1596 release_dispex(&This
->event_target
.dispex
);
1600 void init_node_cc(void)
1602 static const CCObjCallback node_ccp_callback
= {
1603 HTMLDOMNode_traverse
,
1605 HTMLDOMNode_delete_cycle_collectable
1608 ccp_init(&node_ccp
, &node_ccp_callback
);
1611 HRESULT
get_node(nsIDOMNode
*nsnode
, BOOL create
, HTMLDOMNode
**ret
)
1613 nsIDOMDocument
*dom_document
;
1614 HTMLDocumentNode
*document
;
1615 nsISupports
*unk
= NULL
;
1619 nsres
= nsIDOMNode_GetMshtmlNode(nsnode
, &unk
);
1620 assert(nsres
== NS_OK
);
1623 *ret
= get_node_obj((IHTMLDOMNode
*)unk
);
1624 nsISupports_Release(unk
);
1633 nsres
= nsIDOMNode_GetOwnerDocument(nsnode
, &dom_document
);
1634 if(NS_FAILED(nsres
) || !dom_document
) {
1635 ERR("GetOwnerDocument failed: %08x\n", nsres
);
1639 hres
= get_document_node(dom_document
, &document
);
1640 nsIDOMDocument_Release(dom_document
);
1644 hres
= create_node(document
, nsnode
, ret
);
1645 htmldoc_release(&document
->basedoc
);