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(IHTMLDOMNode
*);
36 static HRESULT
create_node(HTMLDocumentNode
*,nsIDOMNode
*,HTMLDOMNode
**);
38 static ExternalCycleCollectionParticipant node_ccp
;
42 IHTMLDOMChildrenCollection IHTMLDOMChildrenCollection_iface
;
46 nsIDOMNodeList
*nslist
;
47 } HTMLDOMChildrenCollection
;
50 IEnumVARIANT IEnumVARIANT_iface
;
55 HTMLDOMChildrenCollection
*col
;
56 } HTMLDOMChildrenCollectionEnum
;
58 static inline HTMLDOMChildrenCollectionEnum
*impl_from_IEnumVARIANT(IEnumVARIANT
*iface
)
60 return CONTAINING_RECORD(iface
, HTMLDOMChildrenCollectionEnum
, IEnumVARIANT_iface
);
63 static HRESULT WINAPI
HTMLDOMChildrenCollectionEnum_QueryInterface(IEnumVARIANT
*iface
, REFIID riid
, void **ppv
)
65 HTMLDOMChildrenCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
67 TRACE("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
69 if(IsEqualGUID(riid
, &IID_IUnknown
)) {
70 *ppv
= &This
->IEnumVARIANT_iface
;
71 }else if(IsEqualGUID(riid
, &IID_IEnumVARIANT
)) {
72 *ppv
= &This
->IEnumVARIANT_iface
;
74 FIXME("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
79 IUnknown_AddRef((IUnknown
*)*ppv
);
83 static ULONG WINAPI
HTMLDOMChildrenCollectionEnum_AddRef(IEnumVARIANT
*iface
)
85 HTMLDOMChildrenCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
86 LONG ref
= InterlockedIncrement(&This
->ref
);
88 TRACE("(%p) ref=%ld\n", This
, ref
);
93 static ULONG WINAPI
HTMLDOMChildrenCollectionEnum_Release(IEnumVARIANT
*iface
)
95 HTMLDOMChildrenCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
96 LONG ref
= InterlockedDecrement(&This
->ref
);
98 TRACE("(%p) ref=%ld\n", This
, ref
);
101 IHTMLDOMChildrenCollection_Release(&This
->col
->IHTMLDOMChildrenCollection_iface
);
108 static ULONG
get_enum_len(HTMLDOMChildrenCollectionEnum
*This
)
113 nsres
= nsIDOMNodeList_GetLength(This
->col
->nslist
, &len
);
114 assert(nsres
== NS_OK
);
118 static HRESULT WINAPI
HTMLDOMChildrenCollectionEnum_Next(IEnumVARIANT
*iface
, ULONG celt
, VARIANT
*rgVar
, ULONG
*pCeltFetched
)
120 HTMLDOMChildrenCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
121 ULONG fetched
= 0, len
;
127 TRACE("(%p)->(%ld %p %p)\n", This
, celt
, rgVar
, pCeltFetched
);
129 len
= get_enum_len(This
);
131 while(This
->iter
+fetched
< len
&& fetched
< celt
) {
132 nsres
= nsIDOMNodeList_Item(This
->col
->nslist
, This
->iter
+fetched
, &nsnode
);
133 assert(nsres
== NS_OK
);
135 hres
= get_node(nsnode
, TRUE
, &node
);
136 nsIDOMNode_Release(nsnode
);
139 VariantClear(rgVar
+fetched
);
143 V_VT(rgVar
+fetched
) = VT_DISPATCH
;
144 V_DISPATCH(rgVar
+fetched
) = (IDispatch
*)&node
->IHTMLDOMNode_iface
;
148 This
->iter
+= fetched
;
150 *pCeltFetched
= fetched
;
151 return fetched
== celt
? S_OK
: S_FALSE
;
154 static HRESULT WINAPI
HTMLDOMChildrenCollectionEnum_Skip(IEnumVARIANT
*iface
, ULONG celt
)
156 HTMLDOMChildrenCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
159 TRACE("(%p)->(%ld)\n", This
, celt
);
161 len
= get_enum_len(This
);
162 if(This
->iter
+ celt
> len
) {
171 static HRESULT WINAPI
HTMLDOMChildrenCollectionEnum_Reset(IEnumVARIANT
*iface
)
173 HTMLDOMChildrenCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
175 TRACE("(%p)->()\n", This
);
181 static HRESULT WINAPI
HTMLDOMChildrenCollectionEnum_Clone(IEnumVARIANT
*iface
, IEnumVARIANT
**ppEnum
)
183 HTMLDOMChildrenCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
184 FIXME("(%p)->(%p)\n", This
, ppEnum
);
188 static const IEnumVARIANTVtbl HTMLDOMChildrenCollectionEnumVtbl
= {
189 HTMLDOMChildrenCollectionEnum_QueryInterface
,
190 HTMLDOMChildrenCollectionEnum_AddRef
,
191 HTMLDOMChildrenCollectionEnum_Release
,
192 HTMLDOMChildrenCollectionEnum_Next
,
193 HTMLDOMChildrenCollectionEnum_Skip
,
194 HTMLDOMChildrenCollectionEnum_Reset
,
195 HTMLDOMChildrenCollectionEnum_Clone
198 static inline HTMLDOMChildrenCollection
*impl_from_IHTMLDOMChildrenCollection(IHTMLDOMChildrenCollection
*iface
)
200 return CONTAINING_RECORD(iface
, HTMLDOMChildrenCollection
, IHTMLDOMChildrenCollection_iface
);
203 static HRESULT WINAPI
HTMLDOMChildrenCollection_QueryInterface(IHTMLDOMChildrenCollection
*iface
, REFIID riid
, void **ppv
)
205 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
207 TRACE("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
209 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
210 *ppv
= &This
->IHTMLDOMChildrenCollection_iface
;
211 }else if(IsEqualGUID(&IID_IHTMLDOMChildrenCollection
, riid
)) {
212 *ppv
= &This
->IHTMLDOMChildrenCollection_iface
;
213 }else if(dispex_query_interface(&This
->dispex
, riid
, ppv
)) {
214 return *ppv
? S_OK
: E_NOINTERFACE
;
217 WARN("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
218 return E_NOINTERFACE
;
221 IUnknown_AddRef((IUnknown
*)*ppv
);
225 static ULONG WINAPI
HTMLDOMChildrenCollection_AddRef(IHTMLDOMChildrenCollection
*iface
)
227 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
228 LONG ref
= InterlockedIncrement(&This
->ref
);
230 TRACE("(%p) ref=%ld\n", This
, ref
);
235 static ULONG WINAPI
HTMLDOMChildrenCollection_Release(IHTMLDOMChildrenCollection
*iface
)
237 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
238 LONG ref
= InterlockedDecrement(&This
->ref
);
240 TRACE("(%p) ref=%ld\n", This
, ref
);
243 release_dispex(&This
->dispex
);
248 static HRESULT WINAPI
HTMLDOMChildrenCollection_GetTypeInfoCount(IHTMLDOMChildrenCollection
*iface
, UINT
*pctinfo
)
250 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
251 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
254 static HRESULT WINAPI
HTMLDOMChildrenCollection_GetTypeInfo(IHTMLDOMChildrenCollection
*iface
, UINT iTInfo
,
255 LCID lcid
, ITypeInfo
**ppTInfo
)
257 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
258 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
261 static HRESULT WINAPI
HTMLDOMChildrenCollection_GetIDsOfNames(IHTMLDOMChildrenCollection
*iface
, REFIID riid
,
262 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
264 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
265 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
269 static HRESULT WINAPI
HTMLDOMChildrenCollection_Invoke(IHTMLDOMChildrenCollection
*iface
, DISPID dispIdMember
,
270 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
271 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
273 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
274 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
275 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
278 static HRESULT WINAPI
HTMLDOMChildrenCollection_get_length(IHTMLDOMChildrenCollection
*iface
, LONG
*p
)
280 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
283 TRACE("(%p)->(%p)\n", This
, p
);
285 nsIDOMNodeList_GetLength(This
->nslist
, &length
);
290 static HRESULT WINAPI
HTMLDOMChildrenCollection_get__newEnum(IHTMLDOMChildrenCollection
*iface
, IUnknown
**p
)
292 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
293 HTMLDOMChildrenCollectionEnum
*ret
;
295 TRACE("(%p)->(%p)\n", This
, p
);
297 ret
= malloc(sizeof(*ret
));
299 return E_OUTOFMEMORY
;
301 ret
->IEnumVARIANT_iface
.lpVtbl
= &HTMLDOMChildrenCollectionEnumVtbl
;
305 IHTMLDOMChildrenCollection_AddRef(&This
->IHTMLDOMChildrenCollection_iface
);
308 *p
= (IUnknown
*)&ret
->IEnumVARIANT_iface
;
312 static HRESULT WINAPI
HTMLDOMChildrenCollection_item(IHTMLDOMChildrenCollection
*iface
, LONG index
, IDispatch
**ppItem
)
314 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
315 nsIDOMNode
*nsnode
= NULL
;
321 TRACE("(%p)->(%ld %p)\n", This
, index
, ppItem
);
328 nsIDOMNodeList_GetLength(This
->nslist
, &length
);
329 if(index
< 0 || index
>= length
)
332 nsres
= nsIDOMNodeList_Item(This
->nslist
, index
, &nsnode
);
333 if(NS_FAILED(nsres
) || !nsnode
) {
334 ERR("Item failed: %08lx\n", nsres
);
338 hres
= get_node(nsnode
, TRUE
, &node
);
339 nsIDOMNode_Release(nsnode
);
343 *ppItem
= (IDispatch
*)&node
->IHTMLDOMNode_iface
;
347 static const IHTMLDOMChildrenCollectionVtbl HTMLDOMChildrenCollectionVtbl
= {
348 HTMLDOMChildrenCollection_QueryInterface
,
349 HTMLDOMChildrenCollection_AddRef
,
350 HTMLDOMChildrenCollection_Release
,
351 HTMLDOMChildrenCollection_GetTypeInfoCount
,
352 HTMLDOMChildrenCollection_GetTypeInfo
,
353 HTMLDOMChildrenCollection_GetIDsOfNames
,
354 HTMLDOMChildrenCollection_Invoke
,
355 HTMLDOMChildrenCollection_get_length
,
356 HTMLDOMChildrenCollection_get__newEnum
,
357 HTMLDOMChildrenCollection_item
360 static inline HTMLDOMChildrenCollection
*impl_from_DispatchEx(DispatchEx
*iface
)
362 return CONTAINING_RECORD(iface
, HTMLDOMChildrenCollection
, dispex
);
365 static void HTMLDOMChildrenCollection_unlink(DispatchEx
*dispex
)
367 HTMLDOMChildrenCollection
*This
= impl_from_DispatchEx(dispex
);
368 unlink_ref(&This
->nslist
);
371 static void HTMLDOMChildrenCollection_destructor(DispatchEx
*dispex
)
373 HTMLDOMChildrenCollection
*This
= impl_from_DispatchEx(dispex
);
377 #define DISPID_CHILDCOL_0 MSHTML_DISPID_CUSTOM_MIN
379 static HRESULT
HTMLDOMChildrenCollection_get_dispid(DispatchEx
*dispex
, BSTR name
, DWORD flags
, DISPID
*dispid
)
381 HTMLDOMChildrenCollection
*This
= impl_from_DispatchEx(dispex
);
386 for(ptr
= name
; *ptr
&& is_digit(*ptr
); ptr
++)
387 idx
= idx
*10 + (*ptr
-'0');
389 return DISP_E_UNKNOWNNAME
;
391 nsIDOMNodeList_GetLength(This
->nslist
, &len
);
393 return DISP_E_UNKNOWNNAME
;
395 *dispid
= DISPID_CHILDCOL_0
+ idx
;
396 TRACE("ret %lx\n", *dispid
);
400 static HRESULT
HTMLDOMChildrenCollection_get_name(DispatchEx
*dispex
, DISPID id
, BSTR
*name
)
402 HTMLDOMChildrenCollection
*This
= impl_from_DispatchEx(dispex
);
403 DWORD idx
= id
- DISPID_CHILDCOL_0
;
407 nsIDOMNodeList_GetLength(This
->nslist
, &len
);
409 return DISP_E_MEMBERNOTFOUND
;
411 len
= swprintf(buf
, ARRAY_SIZE(buf
), L
"%u", idx
);
412 return (*name
= SysAllocStringLen(buf
, len
)) ? S_OK
: E_OUTOFMEMORY
;
415 static HRESULT
HTMLDOMChildrenCollection_invoke(DispatchEx
*dispex
, DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
416 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
418 HTMLDOMChildrenCollection
*This
= impl_from_DispatchEx(dispex
);
420 TRACE("(%p)->(%lx %lx %x %p %p %p %p)\n", This
, id
, lcid
, flags
, params
, res
, ei
, caller
);
423 case DISPATCH_PROPERTYGET
: {
424 IDispatch
*disp
= NULL
;
427 hres
= IHTMLDOMChildrenCollection_item(&This
->IHTMLDOMChildrenCollection_iface
,
428 id
- DISPID_CHILDCOL_0
, &disp
);
432 V_VT(res
) = VT_DISPATCH
;
433 V_DISPATCH(res
) = disp
;
438 FIXME("unimplemented flags %x\n", flags
);
445 static const dispex_static_data_vtbl_t HTMLDOMChildrenCollection_dispex_vtbl
= {
446 .destructor
= HTMLDOMChildrenCollection_destructor
,
447 .unlink
= HTMLDOMChildrenCollection_unlink
,
448 .get_dispid
= HTMLDOMChildrenCollection_get_dispid
,
449 .get_name
= HTMLDOMChildrenCollection_get_name
,
450 .invoke
= HTMLDOMChildrenCollection_invoke
,
453 static const tid_t HTMLDOMChildrenCollection_iface_tids
[] = {
454 IHTMLDOMChildrenCollection_tid
,
458 static dispex_static_data_t HTMLDOMChildrenCollection_dispex
= {
460 &HTMLDOMChildrenCollection_dispex_vtbl
,
461 DispDOMChildrenCollection_tid
,
462 HTMLDOMChildrenCollection_iface_tids
,
463 HTMLDOMNode_init_dispex_info
466 HRESULT
create_child_collection(nsIDOMNodeList
*nslist
, compat_mode_t compat_mode
, IHTMLDOMChildrenCollection
**ret
)
468 HTMLDOMChildrenCollection
*collection
;
470 if(!(collection
= calloc(1, sizeof(*collection
))))
471 return E_OUTOFMEMORY
;
473 collection
->IHTMLDOMChildrenCollection_iface
.lpVtbl
= &HTMLDOMChildrenCollectionVtbl
;
476 nsIDOMNodeList_AddRef(nslist
);
477 collection
->nslist
= nslist
;
479 init_dispatch(&collection
->dispex
, (IUnknown
*)&collection
->IHTMLDOMChildrenCollection_iface
,
480 &HTMLDOMChildrenCollection_dispex
, compat_mode
);
482 *ret
= &collection
->IHTMLDOMChildrenCollection_iface
;
486 static inline HTMLDOMNode
*impl_from_IHTMLDOMNode(IHTMLDOMNode
*iface
)
488 return CONTAINING_RECORD(iface
, HTMLDOMNode
, IHTMLDOMNode_iface
);
491 static HRESULT WINAPI
HTMLDOMNode_QueryInterface(IHTMLDOMNode
*iface
,
492 REFIID riid
, void **ppv
)
494 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
496 return This
->vtbl
->qi(This
, riid
, ppv
);
499 static ULONG WINAPI
HTMLDOMNode_AddRef(IHTMLDOMNode
*iface
)
501 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
504 ref
= ccref_incr(&This
->ccref
, (nsISupports
*)&This
->IHTMLDOMNode_iface
);
506 TRACE("(%p) ref=%ld\n", This
, ref
);
511 static ULONG WINAPI
HTMLDOMNode_Release(IHTMLDOMNode
*iface
)
513 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
514 LONG ref
= ccref_decr(&This
->ccref
, (nsISupports
*)&This
->IHTMLDOMNode_iface
, &node_ccp
);
516 TRACE("(%p) ref=%ld\n", This
, ref
);
521 static HRESULT WINAPI
HTMLDOMNode_GetTypeInfoCount(IHTMLDOMNode
*iface
, UINT
*pctinfo
)
523 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
524 return IDispatchEx_GetTypeInfoCount(&This
->event_target
.dispex
.IDispatchEx_iface
, pctinfo
);
527 static HRESULT WINAPI
HTMLDOMNode_GetTypeInfo(IHTMLDOMNode
*iface
, UINT iTInfo
,
528 LCID lcid
, ITypeInfo
**ppTInfo
)
530 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
531 return IDispatchEx_GetTypeInfo(&This
->event_target
.dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
534 static HRESULT WINAPI
HTMLDOMNode_GetIDsOfNames(IHTMLDOMNode
*iface
, REFIID riid
,
535 LPOLESTR
*rgszNames
, UINT cNames
,
536 LCID lcid
, DISPID
*rgDispId
)
538 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
539 return IDispatchEx_GetIDsOfNames(&This
->event_target
.dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
543 static HRESULT WINAPI
HTMLDOMNode_Invoke(IHTMLDOMNode
*iface
, DISPID dispIdMember
,
544 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
545 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
547 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
548 return IDispatchEx_Invoke(&This
->event_target
.dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
549 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
552 static HRESULT WINAPI
HTMLDOMNode_get_nodeType(IHTMLDOMNode
*iface
, LONG
*p
)
554 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
557 TRACE("(%p)->(%p)\n", This
, p
);
559 nsIDOMNode_GetNodeType(This
->nsnode
, &type
);
569 case DOCUMENT_TYPE_NODE
:
575 case DOCUMENT_FRAGMENT_NODE
:
581 * According to MSDN only ELEMENT_NODE and TEXT_NODE are supported.
582 * It needs more tests.
584 FIXME("type %u\n", type
);
591 static HRESULT WINAPI
HTMLDOMNode_get_parentNode(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
593 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
599 TRACE("(%p)->(%p)\n", This
, p
);
601 nsres
= nsIDOMNode_GetParentNode(This
->nsnode
, &nsnode
);
602 if(NS_FAILED(nsres
)) {
603 ERR("GetParentNode failed: %08lx\n", nsres
);
612 hres
= get_node(nsnode
, TRUE
, &node
);
613 nsIDOMNode_Release(nsnode
);
617 *p
= &node
->IHTMLDOMNode_iface
;
621 static HRESULT WINAPI
HTMLDOMNode_hasChildNodes(IHTMLDOMNode
*iface
, VARIANT_BOOL
*fChildren
)
623 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
624 cpp_bool has_child
= FALSE
;
627 TRACE("(%p)->(%p)\n", This
, fChildren
);
629 nsres
= nsIDOMNode_HasChildNodes(This
->nsnode
, &has_child
);
631 ERR("HasChildNodes failed: %08lx\n", nsres
);
633 *fChildren
= variant_bool(has_child
);
637 static HRESULT WINAPI
HTMLDOMNode_get_childNodes(IHTMLDOMNode
*iface
, IDispatch
**p
)
639 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
640 nsIDOMNodeList
*nslist
;
643 TRACE("(%p)->(%p)\n", This
, p
);
645 hres
= map_nsresult(nsIDOMNode_GetChildNodes(This
->nsnode
, &nslist
));
647 ERR("GetChildNodes failed: %08lx\n", hres
);
651 hres
= create_child_collection(nslist
, dispex_compat_mode(&This
->event_target
.dispex
),
652 (IHTMLDOMChildrenCollection
**)p
);
653 nsIDOMNodeList_Release(nslist
);
657 static HRESULT WINAPI
HTMLDOMNode_get_attributes(IHTMLDOMNode
*iface
, IDispatch
**p
)
659 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
660 HTMLAttributeCollection
*col
;
663 TRACE("(%p)->(%p)\n", This
, p
);
665 if(This
->vtbl
->get_attr_col
) {
666 hres
= This
->vtbl
->get_attr_col(This
, &col
);
670 *p
= (IDispatch
*)&col
->IHTMLAttributeCollection_iface
;
678 static HRESULT WINAPI
HTMLDOMNode_insertBefore(IHTMLDOMNode
*iface
, IHTMLDOMNode
*newChild
,
679 VARIANT refChild
, IHTMLDOMNode
**node
)
681 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
682 HTMLDOMNode
*new_child
, *node_obj
, *ref_node
= NULL
;
687 TRACE("(%p)->(%p %s %p)\n", This
, newChild
, debugstr_variant(&refChild
), node
);
689 new_child
= get_node_obj(newChild
);
691 ERR("invalid newChild\n");
695 switch(V_VT(&refChild
)) {
699 IHTMLDOMNode
*ref_iface
;
701 if(!V_DISPATCH(&refChild
))
704 hres
= IDispatch_QueryInterface(V_DISPATCH(&refChild
), &IID_IHTMLDOMNode
, (void**)&ref_iface
);
708 ref_node
= get_node_obj(ref_iface
);
709 IHTMLDOMNode_Release(ref_iface
);
711 ERR("unvalid node\n");
718 FIXME("unimplemented refChild %s\n", debugstr_variant(&refChild
));
722 if(SUCCEEDED(hres
)) {
723 nsres
= nsIDOMNode_InsertBefore(This
->nsnode
, new_child
->nsnode
, ref_node
? ref_node
->nsnode
: NULL
, &nsnode
);
724 if(NS_FAILED(nsres
)) {
725 ERR("InsertBefore failed: %08lx\n", nsres
);
729 node_release(new_child
);
731 node_release(ref_node
);
735 hres
= get_node(nsnode
, TRUE
, &node_obj
);
736 nsIDOMNode_Release(nsnode
);
740 *node
= &node_obj
->IHTMLDOMNode_iface
;
744 static HRESULT WINAPI
HTMLDOMNode_removeChild(IHTMLDOMNode
*iface
, IHTMLDOMNode
*oldChild
,
747 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
748 HTMLDOMNode
*node_obj
;
753 TRACE("(%p)->(%p %p)\n", This
, oldChild
, node
);
755 node_obj
= get_node_obj(oldChild
);
759 nsres
= nsIDOMNode_RemoveChild(This
->nsnode
, node_obj
->nsnode
, &nsnode
);
760 node_release(node_obj
);
761 if(NS_FAILED(nsres
)) {
762 ERR("RemoveChild failed: %08lx\n", nsres
);
766 hres
= get_node(nsnode
, TRUE
, &node_obj
);
767 nsIDOMNode_Release(nsnode
);
771 /* FIXME: Make sure that node != newChild */
772 *node
= &node_obj
->IHTMLDOMNode_iface
;
776 static HRESULT WINAPI
HTMLDOMNode_replaceChild(IHTMLDOMNode
*iface
, IHTMLDOMNode
*newChild
,
777 IHTMLDOMNode
*oldChild
, IHTMLDOMNode
**node
)
779 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
780 HTMLDOMNode
*node_new
, *node_old
, *ret_node
;
785 TRACE("(%p)->(%p %p %p)\n", This
, newChild
, oldChild
, node
);
787 node_new
= get_node_obj(newChild
);
791 node_old
= get_node_obj(oldChild
);
793 node_release(node_new
);
797 nsres
= nsIDOMNode_ReplaceChild(This
->nsnode
, node_new
->nsnode
, node_old
->nsnode
, &nsnode
);
798 node_release(node_new
);
799 node_release(node_old
);
803 hres
= get_node(nsnode
, TRUE
, &ret_node
);
804 nsIDOMNode_Release(nsnode
);
808 *node
= &ret_node
->IHTMLDOMNode_iface
;
812 static HRESULT WINAPI
HTMLDOMNode_cloneNode(IHTMLDOMNode
*iface
, VARIANT_BOOL fDeep
,
813 IHTMLDOMNode
**clonedNode
)
815 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
816 HTMLDOMNode
*new_node
;
821 TRACE("(%p)->(%x %p)\n", This
, fDeep
, clonedNode
);
823 nsres
= nsIDOMNode_CloneNode(This
->nsnode
, fDeep
!= VARIANT_FALSE
, 1, &nsnode
);
824 if(NS_FAILED(nsres
) || !nsnode
) {
825 ERR("CloneNode failed: %08lx\n", nsres
);
829 hres
= This
->vtbl
->clone(This
, nsnode
, &new_node
);
830 nsIDOMNode_Release(nsnode
);
834 *clonedNode
= &new_node
->IHTMLDOMNode_iface
;
838 static HRESULT WINAPI
HTMLDOMNode_removeNode(IHTMLDOMNode
*iface
, VARIANT_BOOL fDeep
,
839 IHTMLDOMNode
**removed
)
841 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
842 FIXME("(%p)->(%x %p)\n", This
, fDeep
, removed
);
846 static HRESULT WINAPI
HTMLDOMNode_swapNode(IHTMLDOMNode
*iface
, IHTMLDOMNode
*otherNode
,
847 IHTMLDOMNode
**swappedNode
)
849 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
850 FIXME("(%p)->(%p %p)\n", This
, otherNode
, swappedNode
);
854 static HRESULT WINAPI
HTMLDOMNode_replaceNode(IHTMLDOMNode
*iface
, IHTMLDOMNode
*replacement
,
855 IHTMLDOMNode
**replaced
)
857 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
858 FIXME("(%p)->(%p %p)\n", This
, replacement
, replaced
);
862 static HRESULT WINAPI
HTMLDOMNode_appendChild(IHTMLDOMNode
*iface
, IHTMLDOMNode
*newChild
,
865 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
866 HTMLDOMNode
*node_obj
;
871 TRACE("(%p)->(%p %p)\n", This
, newChild
, node
);
873 node_obj
= get_node_obj(newChild
);
877 nsres
= nsIDOMNode_AppendChild(This
->nsnode
, node_obj
->nsnode
, &nsnode
);
878 node_release(node_obj
);
879 if(NS_FAILED(nsres
)) {
880 ERR("AppendChild failed: %08lx\n", nsres
);
884 hres
= get_node(nsnode
, TRUE
, &node_obj
);
885 nsIDOMNode_Release(nsnode
);
889 /* FIXME: Make sure that node != newChild */
890 *node
= &node_obj
->IHTMLDOMNode_iface
;
894 static HRESULT WINAPI
HTMLDOMNode_get_nodeName(IHTMLDOMNode
*iface
, BSTR
*p
)
896 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
900 TRACE("(%p)->(%p)\n", This
, p
);
902 nsAString_Init(&name
, NULL
);
903 nsres
= nsIDOMNode_GetNodeName(This
->nsnode
, &name
);
904 return return_nsstr(nsres
, &name
, p
);
907 static HRESULT WINAPI
HTMLDOMNode_put_nodeValue(IHTMLDOMNode
*iface
, VARIANT v
)
909 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
911 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&v
));
917 nsAString_InitDepend(&val_str
, V_BSTR(&v
));
918 nsIDOMNode_SetNodeValue(This
->nsnode
, &val_str
);
919 nsAString_Finish(&val_str
);
925 FIXME("unsupported value %s\n", debugstr_variant(&v
));
931 static HRESULT WINAPI
HTMLDOMNode_get_nodeValue(IHTMLDOMNode
*iface
, VARIANT
*p
)
933 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
934 const PRUnichar
*val
;
937 TRACE("(%p)->(%p)\n", This
, p
);
939 nsAString_Init(&val_str
, NULL
);
940 nsIDOMNode_GetNodeValue(This
->nsnode
, &val_str
);
941 nsAString_GetData(&val_str
, &val
);
945 V_BSTR(p
) = SysAllocString(val
);
950 nsAString_Finish(&val_str
);
955 static HRESULT WINAPI
HTMLDOMNode_get_firstChild(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
957 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
958 nsIDOMNode
*nschild
= NULL
;
962 TRACE("(%p)->(%p)\n", This
, p
);
964 nsIDOMNode_GetFirstChild(This
->nsnode
, &nschild
);
970 hres
= get_node(nschild
, TRUE
, &node
);
971 nsIDOMNode_Release(nschild
);
975 *p
= &node
->IHTMLDOMNode_iface
;
979 static HRESULT WINAPI
HTMLDOMNode_get_lastChild(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
981 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
982 nsIDOMNode
*nschild
= NULL
;
986 TRACE("(%p)->(%p)\n", This
, p
);
988 nsIDOMNode_GetLastChild(This
->nsnode
, &nschild
);
994 hres
= get_node(nschild
, TRUE
, &node
);
995 nsIDOMNode_Release(nschild
);
999 *p
= &node
->IHTMLDOMNode_iface
;
1003 static HRESULT WINAPI
HTMLDOMNode_get_previousSibling(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
1005 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
1006 nsIDOMNode
*nschild
= NULL
;
1010 TRACE("(%p)->(%p)\n", This
, p
);
1012 nsIDOMNode_GetPreviousSibling(This
->nsnode
, &nschild
);
1018 hres
= get_node(nschild
, TRUE
, &node
);
1019 nsIDOMNode_Release(nschild
);
1023 *p
= &node
->IHTMLDOMNode_iface
;
1027 static HRESULT WINAPI
HTMLDOMNode_get_nextSibling(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
1029 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
1030 nsIDOMNode
*nssibling
= NULL
;
1034 TRACE("(%p)->(%p)\n", This
, p
);
1036 nsIDOMNode_GetNextSibling(This
->nsnode
, &nssibling
);
1042 hres
= get_node(nssibling
, TRUE
, &node
);
1043 nsIDOMNode_Release(nssibling
);
1047 *p
= &node
->IHTMLDOMNode_iface
;
1051 static const IHTMLDOMNodeVtbl HTMLDOMNodeVtbl
= {
1052 HTMLDOMNode_QueryInterface
,
1054 HTMLDOMNode_Release
,
1055 HTMLDOMNode_GetTypeInfoCount
,
1056 HTMLDOMNode_GetTypeInfo
,
1057 HTMLDOMNode_GetIDsOfNames
,
1059 HTMLDOMNode_get_nodeType
,
1060 HTMLDOMNode_get_parentNode
,
1061 HTMLDOMNode_hasChildNodes
,
1062 HTMLDOMNode_get_childNodes
,
1063 HTMLDOMNode_get_attributes
,
1064 HTMLDOMNode_insertBefore
,
1065 HTMLDOMNode_removeChild
,
1066 HTMLDOMNode_replaceChild
,
1067 HTMLDOMNode_cloneNode
,
1068 HTMLDOMNode_removeNode
,
1069 HTMLDOMNode_swapNode
,
1070 HTMLDOMNode_replaceNode
,
1071 HTMLDOMNode_appendChild
,
1072 HTMLDOMNode_get_nodeName
,
1073 HTMLDOMNode_put_nodeValue
,
1074 HTMLDOMNode_get_nodeValue
,
1075 HTMLDOMNode_get_firstChild
,
1076 HTMLDOMNode_get_lastChild
,
1077 HTMLDOMNode_get_previousSibling
,
1078 HTMLDOMNode_get_nextSibling
1081 HTMLDOMNode
*unsafe_impl_from_IHTMLDOMNode(IHTMLDOMNode
*iface
)
1083 return iface
->lpVtbl
== &HTMLDOMNodeVtbl
? impl_from_IHTMLDOMNode(iface
) : NULL
;
1086 static HTMLDOMNode
*get_node_obj(IHTMLDOMNode
*iface
)
1090 if(iface
->lpVtbl
!= &HTMLDOMNodeVtbl
)
1093 ret
= impl_from_IHTMLDOMNode(iface
);
1098 static inline HTMLDOMNode
*impl_from_IHTMLDOMNode2(IHTMLDOMNode2
*iface
)
1100 return CONTAINING_RECORD(iface
, HTMLDOMNode
, IHTMLDOMNode2_iface
);
1103 static HRESULT WINAPI
HTMLDOMNode2_QueryInterface(IHTMLDOMNode2
*iface
,
1104 REFIID riid
, void **ppv
)
1106 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
1108 return IHTMLDOMNode_QueryInterface(&This
->IHTMLDOMNode_iface
, riid
, ppv
);
1111 static ULONG WINAPI
HTMLDOMNode2_AddRef(IHTMLDOMNode2
*iface
)
1113 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
1115 return IHTMLDOMNode_AddRef(&This
->IHTMLDOMNode_iface
);
1118 static ULONG WINAPI
HTMLDOMNode2_Release(IHTMLDOMNode2
*iface
)
1120 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
1122 return IHTMLDOMNode_Release(&This
->IHTMLDOMNode_iface
);
1125 static HRESULT WINAPI
HTMLDOMNode2_GetTypeInfoCount(IHTMLDOMNode2
*iface
, UINT
*pctinfo
)
1127 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
1128 return IDispatchEx_GetTypeInfoCount(&This
->event_target
.dispex
.IDispatchEx_iface
, pctinfo
);
1131 static HRESULT WINAPI
HTMLDOMNode2_GetTypeInfo(IHTMLDOMNode2
*iface
, UINT iTInfo
,
1132 LCID lcid
, ITypeInfo
**ppTInfo
)
1134 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
1135 return IDispatchEx_GetTypeInfo(&This
->event_target
.dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
1138 static HRESULT WINAPI
HTMLDOMNode2_GetIDsOfNames(IHTMLDOMNode2
*iface
, REFIID riid
,
1139 LPOLESTR
*rgszNames
, UINT cNames
,
1140 LCID lcid
, DISPID
*rgDispId
)
1142 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
1143 return IDispatchEx_GetIDsOfNames(&This
->event_target
.dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
1147 static HRESULT WINAPI
HTMLDOMNode2_Invoke(IHTMLDOMNode2
*iface
, DISPID dispIdMember
,
1148 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
1149 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1151 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
1152 return IDispatchEx_Invoke(&This
->event_target
.dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
1153 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1156 static HRESULT WINAPI
HTMLDOMNode2_get_ownerDocument(IHTMLDOMNode2
*iface
, IDispatch
**p
)
1158 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
1160 TRACE("(%p)->(%p)\n", This
, p
);
1162 /* FIXME: Better check for document node */
1163 if(This
== &This
->doc
->node
) {
1166 *p
= (IDispatch
*)&This
->doc
->IHTMLDocument2_iface
;
1167 IDispatch_AddRef(*p
);
1172 static const IHTMLDOMNode2Vtbl HTMLDOMNode2Vtbl
= {
1173 HTMLDOMNode2_QueryInterface
,
1174 HTMLDOMNode2_AddRef
,
1175 HTMLDOMNode2_Release
,
1176 HTMLDOMNode2_GetTypeInfoCount
,
1177 HTMLDOMNode2_GetTypeInfo
,
1178 HTMLDOMNode2_GetIDsOfNames
,
1179 HTMLDOMNode2_Invoke
,
1180 HTMLDOMNode2_get_ownerDocument
1183 static inline HTMLDOMNode
*impl_from_IHTMLDOMNode3(IHTMLDOMNode3
*iface
)
1185 return CONTAINING_RECORD(iface
, HTMLDOMNode
, IHTMLDOMNode3_iface
);
1188 static HRESULT WINAPI
HTMLDOMNode3_QueryInterface(IHTMLDOMNode3
*iface
, REFIID riid
, void **ppv
)
1190 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1191 return IHTMLDOMNode_QueryInterface(&This
->IHTMLDOMNode_iface
, riid
, ppv
);
1194 static ULONG WINAPI
HTMLDOMNode3_AddRef(IHTMLDOMNode3
*iface
)
1196 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1198 return IHTMLDOMNode_AddRef(&This
->IHTMLDOMNode_iface
);
1201 static ULONG WINAPI
HTMLDOMNode3_Release(IHTMLDOMNode3
*iface
)
1203 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1205 return IHTMLDOMNode_Release(&This
->IHTMLDOMNode_iface
);
1208 static HRESULT WINAPI
HTMLDOMNode3_GetTypeInfoCount(IHTMLDOMNode3
*iface
, UINT
*pctinfo
)
1210 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1211 return IDispatchEx_GetTypeInfoCount(&This
->event_target
.dispex
.IDispatchEx_iface
, pctinfo
);
1214 static HRESULT WINAPI
HTMLDOMNode3_GetTypeInfo(IHTMLDOMNode3
*iface
, UINT iTInfo
,
1215 LCID lcid
, ITypeInfo
**ppTInfo
)
1217 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1218 return IDispatchEx_GetTypeInfo(&This
->event_target
.dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
1221 static HRESULT WINAPI
HTMLDOMNode3_GetIDsOfNames(IHTMLDOMNode3
*iface
, REFIID riid
,
1222 LPOLESTR
*rgszNames
, UINT cNames
,
1223 LCID lcid
, DISPID
*rgDispId
)
1225 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1226 return IDispatchEx_GetIDsOfNames(&This
->event_target
.dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
1230 static HRESULT WINAPI
HTMLDOMNode3_Invoke(IHTMLDOMNode3
*iface
, DISPID dispIdMember
,
1231 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
1232 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1234 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1235 return IDispatchEx_Invoke(&This
->event_target
.dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
1236 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1239 static HRESULT WINAPI
HTMLDOMNode3_put_prefix(IHTMLDOMNode3
*iface
, VARIANT v
)
1241 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1242 FIXME("(%p)->(%s)\n", This
, debugstr_variant(&v
));
1246 static HRESULT WINAPI
HTMLDOMNode3_get_prefix(IHTMLDOMNode3
*iface
, VARIANT
*p
)
1248 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1249 FIXME("(%p)->(%p)\n", This
, p
);
1253 static HRESULT WINAPI
HTMLDOMNode3_get_localName(IHTMLDOMNode3
*iface
, VARIANT
*p
)
1255 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1256 FIXME("(%p)->(%p)\n", This
, p
);
1260 static HRESULT WINAPI
HTMLDOMNode3_get_namespaceURI(IHTMLDOMNode3
*iface
, VARIANT
*p
)
1262 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1266 TRACE("(%p)->(%p)\n", This
, p
);
1268 nsAString_InitDepend(&nsstr
, NULL
);
1269 nsres
= nsIDOMNode_GetNamespaceURI(This
->nsnode
, &nsstr
);
1270 return return_nsstr_variant(nsres
, &nsstr
, 0, p
);
1273 static HRESULT WINAPI
HTMLDOMNode3_put_textContent(IHTMLDOMNode3
*iface
, VARIANT v
)
1275 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1279 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&v
));
1281 variant_to_nsstr(&v
, FALSE
, &nsstr
);
1282 nsres
= nsIDOMNode_SetTextContent(This
->nsnode
, &nsstr
);
1283 nsAString_Finish(&nsstr
);
1284 if(NS_FAILED(nsres
)) {
1285 ERR("SetTextContent failed: %08lx\n", nsres
);
1292 static HRESULT WINAPI
HTMLDOMNode3_get_textContent(IHTMLDOMNode3
*iface
, VARIANT
*p
)
1294 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1298 TRACE("(%p)->(%p)\n", This
, p
);
1300 nsAString_Init(&nsstr
, NULL
);
1301 nsres
= nsIDOMNode_GetTextContent(This
->nsnode
, &nsstr
);
1302 return return_nsstr_variant(nsres
, &nsstr
, 0, p
);
1305 static HRESULT WINAPI
HTMLDOMNode3_isEqualNode(IHTMLDOMNode3
*iface
, IHTMLDOMNode3
*otherNode
, VARIANT_BOOL
*isEqual
)
1307 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1308 FIXME("(%p)->()\n", This
);
1312 static HRESULT WINAPI
HTMLDOMNode3_lookupNamespaceURI(IHTMLDOMNode3
*iface
, VARIANT
*prefix
, VARIANT
*namespaceURI
)
1314 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1315 FIXME("(%p)->(%s %p)\n", This
, debugstr_variant(prefix
), namespaceURI
);
1319 static HRESULT WINAPI
HTMLDOMNode3_lookupPrefix(IHTMLDOMNode3
*iface
, VARIANT
*namespaceURI
, VARIANT
*prefix
)
1321 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1322 FIXME("(%p)->(%s %p)\n", This
, debugstr_variant(namespaceURI
), prefix
);
1326 static HRESULT WINAPI
HTMLDOMNode3_isDefaultNamespace(IHTMLDOMNode3
*iface
, VARIANT
*namespace, VARIANT_BOOL
*pfDefaultNamespace
)
1328 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1329 FIXME("(%p)->()\n", This
);
1333 static HRESULT WINAPI
HTMLDOMNode3_appendChild(IHTMLDOMNode3
*iface
, IHTMLDOMNode
*newChild
, IHTMLDOMNode
**node
)
1335 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1336 TRACE("(%p)->()\n", This
);
1337 return IHTMLDOMNode_appendChild(&This
->IHTMLDOMNode_iface
, newChild
, node
);
1340 static HRESULT WINAPI
HTMLDOMNode3_insertBefore(IHTMLDOMNode3
*iface
, IHTMLDOMNode
*newChild
, VARIANT refChild
, IHTMLDOMNode
**node
)
1342 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1343 TRACE("(%p)->(%p %s %p)\n", This
, newChild
, debugstr_variant(&refChild
), node
);
1344 return IHTMLDOMNode_insertBefore(&This
->IHTMLDOMNode_iface
, newChild
, refChild
, node
);
1347 static HRESULT WINAPI
HTMLDOMNode3_removeChild(IHTMLDOMNode3
*iface
, IHTMLDOMNode
*oldChild
, IHTMLDOMNode
**node
)
1349 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1350 TRACE("(%p)->(%p %p)\n", This
, oldChild
, node
);
1351 return IHTMLDOMNode_removeChild(&This
->IHTMLDOMNode_iface
, oldChild
, node
);
1354 static HRESULT WINAPI
HTMLDOMNode3_replaceChild(IHTMLDOMNode3
*iface
, IHTMLDOMNode
*newChild
, IHTMLDOMNode
*oldChild
, IHTMLDOMNode
**node
)
1356 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1357 TRACE("(%p)->(%p %p %p)\n", This
, newChild
, oldChild
, node
);
1358 return IHTMLDOMNode_replaceChild(&This
->IHTMLDOMNode_iface
, newChild
, oldChild
, node
);
1361 static HRESULT WINAPI
HTMLDOMNode3_isSameNode(IHTMLDOMNode3
*iface
, IHTMLDOMNode3
*otherNode
, VARIANT_BOOL
*isSame
)
1363 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1364 FIXME("(%p)->()\n", This
);
1368 static HRESULT WINAPI
HTMLDOMNode3_compareDocumentPosition(IHTMLDOMNode3
*iface
, IHTMLDOMNode
*otherNode
, USHORT
*flags
)
1370 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1375 TRACE("(%p)->()\n", This
);
1377 other
= get_node_obj(otherNode
);
1379 return E_INVALIDARG
;
1381 nsres
= nsIDOMNode_CompareDocumentPosition(This
->nsnode
, other
->nsnode
, &position
);
1382 IHTMLDOMNode_Release(&other
->IHTMLDOMNode_iface
);
1383 if(NS_FAILED(nsres
)) {
1384 ERR("failed: %08lx\n", nsres
);
1392 static HRESULT WINAPI
HTMLDOMNode3_isSupported(IHTMLDOMNode3
*iface
, BSTR feature
, VARIANT version
, VARIANT_BOOL
*pfisSupported
)
1394 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1395 FIXME("(%p)->(%s %s %p)\n", This
, debugstr_w(feature
), debugstr_variant(&version
), pfisSupported
);
1399 static const IHTMLDOMNode3Vtbl HTMLDOMNode3Vtbl
= {
1400 HTMLDOMNode3_QueryInterface
,
1401 HTMLDOMNode3_AddRef
,
1402 HTMLDOMNode3_Release
,
1403 HTMLDOMNode3_GetTypeInfoCount
,
1404 HTMLDOMNode3_GetTypeInfo
,
1405 HTMLDOMNode3_GetIDsOfNames
,
1406 HTMLDOMNode3_Invoke
,
1407 HTMLDOMNode3_put_prefix
,
1408 HTMLDOMNode3_get_prefix
,
1409 HTMLDOMNode3_get_localName
,
1410 HTMLDOMNode3_get_namespaceURI
,
1411 HTMLDOMNode3_put_textContent
,
1412 HTMLDOMNode3_get_textContent
,
1413 HTMLDOMNode3_isEqualNode
,
1414 HTMLDOMNode3_lookupNamespaceURI
,
1415 HTMLDOMNode3_lookupPrefix
,
1416 HTMLDOMNode3_isDefaultNamespace
,
1417 HTMLDOMNode3_appendChild
,
1418 HTMLDOMNode3_insertBefore
,
1419 HTMLDOMNode3_removeChild
,
1420 HTMLDOMNode3_replaceChild
,
1421 HTMLDOMNode3_isSameNode
,
1422 HTMLDOMNode3_compareDocumentPosition
,
1423 HTMLDOMNode3_isSupported
1426 HRESULT
HTMLDOMNode_QI(HTMLDOMNode
*This
, REFIID riid
, void **ppv
)
1428 TRACE("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
1430 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
1431 *ppv
= &This
->IHTMLDOMNode_iface
;
1432 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
1433 *ppv
= &This
->IHTMLDOMNode_iface
;
1434 }else if(IsEqualGUID(&IID_IHTMLDOMNode
, riid
)) {
1435 *ppv
= &This
->IHTMLDOMNode_iface
;
1436 }else if(IsEqualGUID(&IID_IHTMLDOMNode2
, riid
)) {
1437 *ppv
= &This
->IHTMLDOMNode2_iface
;
1438 }else if(IsEqualGUID(&IID_IHTMLDOMNode3
, riid
)) {
1439 *ppv
= &This
->IHTMLDOMNode3_iface
;
1440 }else if(IsEqualGUID(&IID_nsXPCOMCycleCollectionParticipant
, riid
)) {
1443 }else if(IsEqualGUID(&IID_nsCycleCollectionISupports
, riid
)) {
1444 *ppv
= &This
->IHTMLDOMNode_iface
;
1447 return EventTarget_QI(&This
->event_target
, riid
, ppv
);
1450 IUnknown_AddRef((IUnknown
*)*ppv
);
1454 void HTMLDOMNode_destructor(HTMLDOMNode
*This
)
1456 release_event_target(&This
->event_target
);
1458 nsIDOMNode_Release(This
->nsnode
);
1459 if(This
->doc
&& &This
->doc
->node
!= This
)
1460 IHTMLDOMNode_Release(&This
->doc
->node
.IHTMLDOMNode_iface
);
1463 static HRESULT
HTMLDOMNode_clone(HTMLDOMNode
*This
, nsIDOMNode
*nsnode
, HTMLDOMNode
**ret
)
1465 return create_node(This
->doc
, nsnode
, ret
);
1468 void HTMLDOMNode_init_dispex_info(dispex_data_t
*info
, compat_mode_t mode
)
1470 if(mode
>= COMPAT_MODE_IE9
)
1471 dispex_info_add_interface(info
, IHTMLDOMNode3_tid
, NULL
);
1473 EventTarget_init_dispex_info(info
, mode
);
1476 static const cpc_entry_t HTMLDOMNode_cpc
[] = {{NULL
}};
1478 static const NodeImplVtbl HTMLDOMNodeImplVtbl
= {
1479 .qi
= HTMLDOMNode_QI
,
1480 .destructor
= HTMLDOMNode_destructor
,
1481 .cpc_entries
= HTMLDOMNode_cpc
,
1482 .clone
= HTMLDOMNode_clone
1485 void HTMLDOMNode_Init(HTMLDocumentNode
*doc
, HTMLDOMNode
*node
, nsIDOMNode
*nsnode
, dispex_static_data_t
*dispex_data
)
1489 node
->IHTMLDOMNode_iface
.lpVtbl
= &HTMLDOMNodeVtbl
;
1490 node
->IHTMLDOMNode2_iface
.lpVtbl
= &HTMLDOMNode2Vtbl
;
1491 node
->IHTMLDOMNode3_iface
.lpVtbl
= &HTMLDOMNode3Vtbl
;
1493 ccref_init(&node
->ccref
, 1);
1494 EventTarget_Init(&node
->event_target
, (IUnknown
*)&node
->IHTMLDOMNode_iface
, dispex_data
, doc
->document_mode
);
1496 if(&doc
->node
!= node
)
1497 IHTMLDOMNode_AddRef(&doc
->node
.IHTMLDOMNode_iface
);
1500 nsIDOMNode_AddRef(nsnode
);
1501 node
->nsnode
= nsnode
;
1503 nsres
= nsIDOMNode_SetMshtmlNode(nsnode
, (nsISupports
*)&node
->IHTMLDOMNode_iface
);
1504 assert(nsres
== NS_OK
);
1507 static const tid_t HTMLDOMNode_iface_tids
[] = {
1511 static dispex_static_data_t HTMLDOMNode_dispex
= {
1515 HTMLDOMNode_iface_tids
,
1516 HTMLDOMNode_init_dispex_info
1519 static HRESULT
create_node(HTMLDocumentNode
*doc
, nsIDOMNode
*nsnode
, HTMLDOMNode
**ret
)
1524 nsIDOMNode_GetNodeType(nsnode
, &node_type
);
1527 case ELEMENT_NODE
: {
1529 hres
= HTMLElement_Create(doc
, nsnode
, FALSE
, &elem
);
1536 hres
= HTMLDOMTextNode_Create(doc
, nsnode
, ret
);
1540 case DOCUMENT_TYPE_NODE
:
1541 if(dispex_compat_mode(&doc
->node
.event_target
.dispex
) >= COMPAT_MODE_IE9
) {
1542 hres
= create_doctype_node(doc
, nsnode
, ret
);
1547 /* doctype nodes are represented as comment nodes in quirks mode */
1549 case COMMENT_NODE
: {
1550 HTMLElement
*comment
;
1551 hres
= HTMLCommentElement_Create(doc
, nsnode
, &comment
);
1554 *ret
= &comment
->node
;
1557 case ATTRIBUTE_NODE
:
1558 ERR("Called on attribute node\n");
1559 return E_UNEXPECTED
;
1563 FIXME("unimplemented node type %u\n", node_type
);
1565 node
= calloc(1, sizeof(HTMLDOMNode
));
1567 return E_OUTOFMEMORY
;
1569 node
->vtbl
= &HTMLDOMNodeImplVtbl
;
1570 HTMLDOMNode_Init(doc
, node
, nsnode
, &HTMLDOMNode_dispex
);
1575 TRACE("type %d ret %p\n", node_type
, *ret
);
1579 static nsresult NSAPI
HTMLDOMNode_traverse(void *ccp
, void *p
, nsCycleCollectionTraversalCallback
*cb
)
1581 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(p
);
1583 TRACE("%p\n", This
);
1585 describe_cc_node(&This
->ccref
, "HTMLDOMNode", cb
);
1588 note_cc_edge((nsISupports
*)This
->nsnode
, "This->nsnode", cb
);
1589 if(This
->doc
&& &This
->doc
->node
!= This
)
1590 note_cc_edge((nsISupports
*)&This
->doc
->node
.IHTMLDOMNode_iface
, "This->doc", cb
);
1591 dispex_traverse(&This
->event_target
.dispex
, cb
);
1593 if(This
->vtbl
->traverse
)
1594 This
->vtbl
->traverse(This
, cb
);
1599 static nsresult NSAPI
HTMLDOMNode_unlink(void *p
)
1601 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(p
);
1603 TRACE("%p\n", This
);
1605 if(This
->vtbl
->unlink
)
1606 This
->vtbl
->unlink(This
);
1608 dispex_unlink(&This
->event_target
.dispex
);
1609 unlink_ref(&This
->nsnode
);
1611 if(This
->doc
&& &This
->doc
->node
!= This
) {
1612 HTMLDocumentNode
*doc
= This
->doc
;
1614 IHTMLDOMNode_Release(&doc
->node
.IHTMLDOMNode_iface
);
1622 static void NSAPI
HTMLDOMNode_delete_cycle_collectable(void *p
)
1624 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(p
);
1626 TRACE("(%p)\n", This
);
1628 if(This
->vtbl
->unlink
)
1629 This
->vtbl
->unlink(This
);
1630 This
->vtbl
->destructor(This
);
1631 release_dispex(&This
->event_target
.dispex
);
1635 void init_node_cc(void)
1637 static const CCObjCallback node_ccp_callback
= {
1638 HTMLDOMNode_traverse
,
1640 HTMLDOMNode_delete_cycle_collectable
1643 ccp_init(&node_ccp
, &node_ccp_callback
);
1646 HRESULT
get_node(nsIDOMNode
*nsnode
, BOOL create
, HTMLDOMNode
**ret
)
1648 nsIDOMDocument
*dom_document
;
1649 HTMLDocumentNode
*document
;
1650 nsISupports
*unk
= NULL
;
1654 nsres
= nsIDOMNode_GetMshtmlNode(nsnode
, &unk
);
1655 assert(nsres
== NS_OK
);
1658 *ret
= get_node_obj((IHTMLDOMNode
*)unk
);
1659 nsISupports_Release(unk
);
1668 nsres
= nsIDOMNode_GetOwnerDocument(nsnode
, &dom_document
);
1669 if(NS_FAILED(nsres
) || !dom_document
) {
1670 ERR("GetOwnerDocument failed: %08lx\n", nsres
);
1674 hres
= get_document_node(dom_document
, &document
);
1675 nsIDOMDocument_Release(dom_document
);
1679 hres
= create_node(document
, nsnode
, ret
);
1680 IHTMLDOMNode_Release(&document
->node
.IHTMLDOMNode_iface
);