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 /* FIXME: implement weak reference */
48 HTMLDocumentNode
*doc
;
50 nsIDOMNodeList
*nslist
;
51 } HTMLDOMChildrenCollection
;
54 IEnumVARIANT IEnumVARIANT_iface
;
59 HTMLDOMChildrenCollection
*col
;
60 } HTMLDOMChildrenCollectionEnum
;
62 static inline HTMLDOMChildrenCollectionEnum
*impl_from_IEnumVARIANT(IEnumVARIANT
*iface
)
64 return CONTAINING_RECORD(iface
, HTMLDOMChildrenCollectionEnum
, IEnumVARIANT_iface
);
67 static HRESULT WINAPI
HTMLDOMChildrenCollectionEnum_QueryInterface(IEnumVARIANT
*iface
, REFIID riid
, void **ppv
)
69 HTMLDOMChildrenCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
71 TRACE("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
73 if(IsEqualGUID(riid
, &IID_IUnknown
)) {
74 *ppv
= &This
->IEnumVARIANT_iface
;
75 }else if(IsEqualGUID(riid
, &IID_IEnumVARIANT
)) {
76 *ppv
= &This
->IEnumVARIANT_iface
;
78 FIXME("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
83 IUnknown_AddRef((IUnknown
*)*ppv
);
87 static ULONG WINAPI
HTMLDOMChildrenCollectionEnum_AddRef(IEnumVARIANT
*iface
)
89 HTMLDOMChildrenCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
90 LONG ref
= InterlockedIncrement(&This
->ref
);
92 TRACE("(%p) ref=%d\n", This
, ref
);
97 static ULONG WINAPI
HTMLDOMChildrenCollectionEnum_Release(IEnumVARIANT
*iface
)
99 HTMLDOMChildrenCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
100 LONG ref
= InterlockedDecrement(&This
->ref
);
102 TRACE("(%p) ref=%d\n", This
, ref
);
105 IHTMLDOMChildrenCollection_Release(&This
->col
->IHTMLDOMChildrenCollection_iface
);
112 static ULONG
get_enum_len(HTMLDOMChildrenCollectionEnum
*This
)
117 nsres
= nsIDOMNodeList_GetLength(This
->col
->nslist
, &len
);
118 assert(nsres
== NS_OK
);
122 static HRESULT WINAPI
HTMLDOMChildrenCollectionEnum_Next(IEnumVARIANT
*iface
, ULONG celt
, VARIANT
*rgVar
, ULONG
*pCeltFetched
)
124 HTMLDOMChildrenCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
125 ULONG fetched
= 0, len
;
131 TRACE("(%p)->(%d %p %p)\n", This
, celt
, rgVar
, pCeltFetched
);
133 len
= get_enum_len(This
);
135 while(This
->iter
+fetched
< len
&& fetched
< celt
) {
136 nsres
= nsIDOMNodeList_Item(This
->col
->nslist
, This
->iter
+fetched
, &nsnode
);
137 assert(nsres
== NS_OK
);
139 hres
= get_node(This
->col
->doc
, nsnode
, TRUE
, &node
);
140 nsIDOMNode_Release(nsnode
);
142 ERR("get_node failed: %08x\n", hres
);
146 V_VT(rgVar
+fetched
) = VT_DISPATCH
;
147 IHTMLDOMNode_AddRef(&node
->IHTMLDOMNode_iface
);
148 V_DISPATCH(rgVar
+fetched
) = (IDispatch
*)&node
->IHTMLDOMNode_iface
;
152 This
->iter
+= fetched
;
154 *pCeltFetched
= fetched
;
155 return fetched
== celt
? S_OK
: S_FALSE
;
158 static HRESULT WINAPI
HTMLDOMChildrenCollectionEnum_Skip(IEnumVARIANT
*iface
, ULONG celt
)
160 HTMLDOMChildrenCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
163 TRACE("(%p)->(%d)\n", This
, celt
);
165 len
= get_enum_len(This
);
166 if(This
->iter
+ celt
> len
) {
175 static HRESULT WINAPI
HTMLDOMChildrenCollectionEnum_Reset(IEnumVARIANT
*iface
)
177 HTMLDOMChildrenCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
179 TRACE("(%p)->()\n", This
);
185 static HRESULT WINAPI
HTMLDOMChildrenCollectionEnum_Clone(IEnumVARIANT
*iface
, IEnumVARIANT
**ppEnum
)
187 HTMLDOMChildrenCollectionEnum
*This
= impl_from_IEnumVARIANT(iface
);
188 FIXME("(%p)->(%p)\n", This
, ppEnum
);
192 static const IEnumVARIANTVtbl HTMLDOMChildrenCollectionEnumVtbl
= {
193 HTMLDOMChildrenCollectionEnum_QueryInterface
,
194 HTMLDOMChildrenCollectionEnum_AddRef
,
195 HTMLDOMChildrenCollectionEnum_Release
,
196 HTMLDOMChildrenCollectionEnum_Next
,
197 HTMLDOMChildrenCollectionEnum_Skip
,
198 HTMLDOMChildrenCollectionEnum_Reset
,
199 HTMLDOMChildrenCollectionEnum_Clone
202 static inline HTMLDOMChildrenCollection
*impl_from_IHTMLDOMChildrenCollection(IHTMLDOMChildrenCollection
*iface
)
204 return CONTAINING_RECORD(iface
, HTMLDOMChildrenCollection
, IHTMLDOMChildrenCollection_iface
);
207 static HRESULT WINAPI
HTMLDOMChildrenCollection_QueryInterface(IHTMLDOMChildrenCollection
*iface
, REFIID riid
, void **ppv
)
209 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
211 TRACE("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
213 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
214 *ppv
= &This
->IHTMLDOMChildrenCollection_iface
;
215 }else if(IsEqualGUID(&IID_IHTMLDOMChildrenCollection
, riid
)) {
216 *ppv
= &This
->IHTMLDOMChildrenCollection_iface
;
217 }else if(dispex_query_interface(&This
->dispex
, riid
, ppv
)) {
218 return *ppv
? S_OK
: E_NOINTERFACE
;
221 WARN("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
222 return E_NOINTERFACE
;
225 IUnknown_AddRef((IUnknown
*)*ppv
);
229 static ULONG WINAPI
HTMLDOMChildrenCollection_AddRef(IHTMLDOMChildrenCollection
*iface
)
231 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
232 LONG ref
= InterlockedIncrement(&This
->ref
);
234 TRACE("(%p) ref=%d\n", This
, ref
);
239 static ULONG WINAPI
HTMLDOMChildrenCollection_Release(IHTMLDOMChildrenCollection
*iface
)
241 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
242 LONG ref
= InterlockedDecrement(&This
->ref
);
244 TRACE("(%p) ref=%d\n", This
, ref
);
247 htmldoc_release(&This
->doc
->basedoc
);
248 nsIDOMNodeList_Release(This
->nslist
);
255 static HRESULT WINAPI
HTMLDOMChildrenCollection_GetTypeInfoCount(IHTMLDOMChildrenCollection
*iface
, UINT
*pctinfo
)
257 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
258 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
261 static HRESULT WINAPI
HTMLDOMChildrenCollection_GetTypeInfo(IHTMLDOMChildrenCollection
*iface
, UINT iTInfo
,
262 LCID lcid
, ITypeInfo
**ppTInfo
)
264 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
265 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
268 static HRESULT WINAPI
HTMLDOMChildrenCollection_GetIDsOfNames(IHTMLDOMChildrenCollection
*iface
, REFIID riid
,
269 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
271 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
272 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
276 static HRESULT WINAPI
HTMLDOMChildrenCollection_Invoke(IHTMLDOMChildrenCollection
*iface
, DISPID dispIdMember
,
277 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
278 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
280 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
281 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
282 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
285 static HRESULT WINAPI
HTMLDOMChildrenCollection_get_length(IHTMLDOMChildrenCollection
*iface
, LONG
*p
)
287 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
290 TRACE("(%p)->(%p)\n", This
, p
);
292 nsIDOMNodeList_GetLength(This
->nslist
, &length
);
297 static HRESULT WINAPI
HTMLDOMChildrenCollection_get__newEnum(IHTMLDOMChildrenCollection
*iface
, IUnknown
**p
)
299 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
300 HTMLDOMChildrenCollectionEnum
*ret
;
302 TRACE("(%p)->(%p)\n", This
, p
);
304 ret
= heap_alloc(sizeof(*ret
));
306 return E_OUTOFMEMORY
;
308 ret
->IEnumVARIANT_iface
.lpVtbl
= &HTMLDOMChildrenCollectionEnumVtbl
;
312 IHTMLDOMChildrenCollection_AddRef(&This
->IHTMLDOMChildrenCollection_iface
);
315 *p
= (IUnknown
*)&ret
->IEnumVARIANT_iface
;
319 static HRESULT WINAPI
HTMLDOMChildrenCollection_item(IHTMLDOMChildrenCollection
*iface
, LONG index
, IDispatch
**ppItem
)
321 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
322 nsIDOMNode
*nsnode
= NULL
;
328 TRACE("(%p)->(%d %p)\n", This
, index
, ppItem
);
335 nsIDOMNodeList_GetLength(This
->nslist
, &length
);
336 if(index
< 0 || index
>= length
)
339 nsres
= nsIDOMNodeList_Item(This
->nslist
, index
, &nsnode
);
340 if(NS_FAILED(nsres
) || !nsnode
) {
341 ERR("Item failed: %08x\n", nsres
);
345 hres
= get_node(This
->doc
, nsnode
, TRUE
, &node
);
349 *ppItem
= (IDispatch
*)&node
->IHTMLDOMNode_iface
;
353 static const IHTMLDOMChildrenCollectionVtbl HTMLDOMChildrenCollectionVtbl
= {
354 HTMLDOMChildrenCollection_QueryInterface
,
355 HTMLDOMChildrenCollection_AddRef
,
356 HTMLDOMChildrenCollection_Release
,
357 HTMLDOMChildrenCollection_GetTypeInfoCount
,
358 HTMLDOMChildrenCollection_GetTypeInfo
,
359 HTMLDOMChildrenCollection_GetIDsOfNames
,
360 HTMLDOMChildrenCollection_Invoke
,
361 HTMLDOMChildrenCollection_get_length
,
362 HTMLDOMChildrenCollection_get__newEnum
,
363 HTMLDOMChildrenCollection_item
366 static inline HTMLDOMChildrenCollection
*impl_from_DispatchEx(DispatchEx
*iface
)
368 return CONTAINING_RECORD(iface
, HTMLDOMChildrenCollection
, dispex
);
371 #define DISPID_CHILDCOL_0 MSHTML_DISPID_CUSTOM_MIN
373 static HRESULT
HTMLDOMChildrenCollection_get_dispid(DispatchEx
*dispex
, BSTR name
, DWORD flags
, DISPID
*dispid
)
375 HTMLDOMChildrenCollection
*This
= impl_from_DispatchEx(dispex
);
380 for(ptr
= name
; *ptr
&& isdigitW(*ptr
); ptr
++)
381 idx
= idx
*10 + (*ptr
-'0');
383 return DISP_E_UNKNOWNNAME
;
385 nsIDOMNodeList_GetLength(This
->nslist
, &len
);
387 return DISP_E_UNKNOWNNAME
;
389 *dispid
= DISPID_CHILDCOL_0
+ idx
;
390 TRACE("ret %x\n", *dispid
);
394 static HRESULT
HTMLDOMChildrenCollection_invoke(DispatchEx
*dispex
, DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
395 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
397 HTMLDOMChildrenCollection
*This
= impl_from_DispatchEx(dispex
);
399 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, flags
, params
, res
, ei
, caller
);
402 case DISPATCH_PROPERTYGET
: {
403 IDispatch
*disp
= NULL
;
406 hres
= IHTMLDOMChildrenCollection_item(&This
->IHTMLDOMChildrenCollection_iface
,
407 id
- DISPID_CHILDCOL_0
, &disp
);
411 V_VT(res
) = VT_DISPATCH
;
412 V_DISPATCH(res
) = disp
;
417 FIXME("unimplemented flags %x\n", flags
);
424 static const dispex_static_data_vtbl_t HTMLDOMChildrenCollection_dispex_vtbl
= {
426 HTMLDOMChildrenCollection_get_dispid
,
427 HTMLDOMChildrenCollection_invoke
,
431 static const tid_t HTMLDOMChildrenCollection_iface_tids
[] = {
432 IHTMLDOMChildrenCollection_tid
,
436 static dispex_static_data_t HTMLDOMChildrenCollection_dispex
= {
437 &HTMLDOMChildrenCollection_dispex_vtbl
,
438 DispDOMChildrenCollection_tid
,
439 HTMLDOMChildrenCollection_iface_tids
,
440 HTMLDOMNode_init_dispex_info
443 IHTMLDOMChildrenCollection
*create_child_collection(HTMLDocumentNode
*doc
, nsIDOMNodeList
*nslist
)
445 HTMLDOMChildrenCollection
*ret
;
447 ret
= heap_alloc_zero(sizeof(*ret
));
451 ret
->IHTMLDOMChildrenCollection_iface
.lpVtbl
= &HTMLDOMChildrenCollectionVtbl
;
454 nsIDOMNodeList_AddRef(nslist
);
455 ret
->nslist
= nslist
;
457 htmldoc_addref(&doc
->basedoc
);
460 init_dispex(&ret
->dispex
, (IUnknown
*)&ret
->IHTMLDOMChildrenCollection_iface
,
461 &HTMLDOMChildrenCollection_dispex
);
463 return &ret
->IHTMLDOMChildrenCollection_iface
;
466 static inline HTMLDOMNode
*impl_from_IHTMLDOMNode(IHTMLDOMNode
*iface
)
468 return CONTAINING_RECORD(iface
, HTMLDOMNode
, IHTMLDOMNode_iface
);
471 static HRESULT WINAPI
HTMLDOMNode_QueryInterface(IHTMLDOMNode
*iface
,
472 REFIID riid
, void **ppv
)
474 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
476 return This
->vtbl
->qi(This
, riid
, ppv
);
479 static ULONG WINAPI
HTMLDOMNode_AddRef(IHTMLDOMNode
*iface
)
481 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
484 ref
= ccref_incr(&This
->ccref
, (nsISupports
*)&This
->IHTMLDOMNode_iface
);
486 TRACE("(%p) ref=%d\n", This
, ref
);
491 static ULONG WINAPI
HTMLDOMNode_Release(IHTMLDOMNode
*iface
)
493 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
494 LONG ref
= ccref_decr(&This
->ccref
, (nsISupports
*)&This
->IHTMLDOMNode_iface
, /*&node_ccp*/ NULL
);
496 TRACE("(%p) ref=%d\n", This
, ref
);
501 static HRESULT WINAPI
HTMLDOMNode_GetTypeInfoCount(IHTMLDOMNode
*iface
, UINT
*pctinfo
)
503 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
504 return IDispatchEx_GetTypeInfoCount(&This
->event_target
.dispex
.IDispatchEx_iface
, pctinfo
);
507 static HRESULT WINAPI
HTMLDOMNode_GetTypeInfo(IHTMLDOMNode
*iface
, UINT iTInfo
,
508 LCID lcid
, ITypeInfo
**ppTInfo
)
510 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
511 return IDispatchEx_GetTypeInfo(&This
->event_target
.dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
514 static HRESULT WINAPI
HTMLDOMNode_GetIDsOfNames(IHTMLDOMNode
*iface
, REFIID riid
,
515 LPOLESTR
*rgszNames
, UINT cNames
,
516 LCID lcid
, DISPID
*rgDispId
)
518 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
519 return IDispatchEx_GetIDsOfNames(&This
->event_target
.dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
523 static HRESULT WINAPI
HTMLDOMNode_Invoke(IHTMLDOMNode
*iface
, DISPID dispIdMember
,
524 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
525 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
527 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
528 return IDispatchEx_Invoke(&This
->event_target
.dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
529 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
532 static HRESULT WINAPI
HTMLDOMNode_get_nodeType(IHTMLDOMNode
*iface
, LONG
*p
)
534 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
537 TRACE("(%p)->(%p)\n", This
, p
);
539 nsIDOMNode_GetNodeType(This
->nsnode
, &type
);
549 case DOCUMENT_TYPE_NODE
:
555 case DOCUMENT_FRAGMENT_NODE
:
561 * According to MSDN only ELEMENT_NODE and TEXT_NODE are supported.
562 * It needs more tests.
564 FIXME("type %u\n", type
);
571 static HRESULT WINAPI
HTMLDOMNode_get_parentNode(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
573 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
579 TRACE("(%p)->(%p)\n", This
, p
);
581 nsres
= nsIDOMNode_GetParentNode(This
->nsnode
, &nsnode
);
582 if(NS_FAILED(nsres
)) {
583 ERR("GetParentNode failed: %08x\n", nsres
);
592 hres
= get_node(This
->doc
, nsnode
, TRUE
, &node
);
593 nsIDOMNode_Release(nsnode
);
597 *p
= &node
->IHTMLDOMNode_iface
;
601 static HRESULT WINAPI
HTMLDOMNode_hasChildNodes(IHTMLDOMNode
*iface
, VARIANT_BOOL
*fChildren
)
603 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
604 cpp_bool has_child
= FALSE
;
607 TRACE("(%p)->(%p)\n", This
, fChildren
);
609 nsres
= nsIDOMNode_HasChildNodes(This
->nsnode
, &has_child
);
611 ERR("HasChildNodes failed: %08x\n", nsres
);
613 *fChildren
= variant_bool(has_child
);
617 static HRESULT WINAPI
HTMLDOMNode_get_childNodes(IHTMLDOMNode
*iface
, IDispatch
**p
)
619 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
620 nsIDOMNodeList
*nslist
;
623 TRACE("(%p)->(%p)\n", This
, p
);
625 nsres
= nsIDOMNode_GetChildNodes(This
->nsnode
, &nslist
);
626 if(NS_FAILED(nsres
)) {
627 ERR("GetChildNodes failed: %08x\n", nsres
);
631 *p
= (IDispatch
*)create_child_collection(This
->doc
, nslist
);
632 nsIDOMNodeList_Release(nslist
);
634 return *p
? S_OK
: E_OUTOFMEMORY
;
637 static HRESULT WINAPI
HTMLDOMNode_get_attributes(IHTMLDOMNode
*iface
, IDispatch
**p
)
639 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
640 HTMLAttributeCollection
*col
;
643 TRACE("(%p)->(%p)\n", This
, p
);
645 if(This
->vtbl
->get_attr_col
) {
646 hres
= This
->vtbl
->get_attr_col(This
, &col
);
650 *p
= (IDispatch
*)&col
->IHTMLAttributeCollection_iface
;
658 static HRESULT WINAPI
HTMLDOMNode_insertBefore(IHTMLDOMNode
*iface
, IHTMLDOMNode
*newChild
,
659 VARIANT refChild
, IHTMLDOMNode
**node
)
661 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
662 HTMLDOMNode
*new_child
, *node_obj
, *ref_node
= NULL
;
667 TRACE("(%p)->(%p %s %p)\n", This
, newChild
, debugstr_variant(&refChild
), node
);
669 new_child
= get_node_obj(newChild
);
671 ERR("invalid newChild\n");
675 switch(V_VT(&refChild
)) {
679 IHTMLDOMNode
*ref_iface
;
681 if(!V_DISPATCH(&refChild
))
684 hres
= IDispatch_QueryInterface(V_DISPATCH(&refChild
), &IID_IHTMLDOMNode
, (void**)&ref_iface
);
688 ref_node
= get_node_obj(ref_iface
);
689 IHTMLDOMNode_Release(ref_iface
);
691 ERR("unvalid node\n");
698 FIXME("unimplemented refChild %s\n", debugstr_variant(&refChild
));
702 if(SUCCEEDED(hres
)) {
703 nsres
= nsIDOMNode_InsertBefore(This
->nsnode
, new_child
->nsnode
, ref_node
? ref_node
->nsnode
: NULL
, &nsnode
);
704 if(NS_FAILED(nsres
)) {
705 ERR("InsertBefore failed: %08x\n", nsres
);
709 node_release(new_child
);
711 node_release(ref_node
);
715 hres
= get_node(This
->doc
, nsnode
, TRUE
, &node_obj
);
716 nsIDOMNode_Release(nsnode
);
720 *node
= &node_obj
->IHTMLDOMNode_iface
;
724 static HRESULT WINAPI
HTMLDOMNode_removeChild(IHTMLDOMNode
*iface
, IHTMLDOMNode
*oldChild
,
727 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
728 HTMLDOMNode
*node_obj
;
733 TRACE("(%p)->(%p %p)\n", This
, oldChild
, node
);
735 node_obj
= get_node_obj(oldChild
);
739 nsres
= nsIDOMNode_RemoveChild(This
->nsnode
, node_obj
->nsnode
, &nsnode
);
740 node_release(node_obj
);
741 if(NS_FAILED(nsres
)) {
742 ERR("RemoveChild failed: %08x\n", nsres
);
746 hres
= get_node(This
->doc
, nsnode
, TRUE
, &node_obj
);
747 nsIDOMNode_Release(nsnode
);
751 /* FIXME: Make sure that node != newChild */
752 *node
= &node_obj
->IHTMLDOMNode_iface
;
756 static HRESULT WINAPI
HTMLDOMNode_replaceChild(IHTMLDOMNode
*iface
, IHTMLDOMNode
*newChild
,
757 IHTMLDOMNode
*oldChild
, IHTMLDOMNode
**node
)
759 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
760 HTMLDOMNode
*node_new
, *node_old
, *ret_node
;
765 TRACE("(%p)->(%p %p %p)\n", This
, newChild
, oldChild
, node
);
767 node_new
= get_node_obj(newChild
);
771 node_old
= get_node_obj(oldChild
);
773 node_release(node_new
);
777 nsres
= nsIDOMNode_ReplaceChild(This
->nsnode
, node_new
->nsnode
, node_old
->nsnode
, &nsnode
);
778 node_release(node_new
);
779 node_release(node_old
);
783 hres
= get_node(This
->doc
, nsnode
, TRUE
, &ret_node
);
784 nsIDOMNode_Release(nsnode
);
788 *node
= &ret_node
->IHTMLDOMNode_iface
;
792 static HRESULT WINAPI
HTMLDOMNode_cloneNode(IHTMLDOMNode
*iface
, VARIANT_BOOL fDeep
,
793 IHTMLDOMNode
**clonedNode
)
795 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
796 HTMLDOMNode
*new_node
;
801 TRACE("(%p)->(%x %p)\n", This
, fDeep
, clonedNode
);
803 nsres
= nsIDOMNode_CloneNode(This
->nsnode
, fDeep
!= VARIANT_FALSE
, 1, &nsnode
);
804 if(NS_FAILED(nsres
) || !nsnode
) {
805 ERR("CloneNode failed: %08x\n", nsres
);
809 hres
= This
->vtbl
->clone(This
, nsnode
, &new_node
);
813 *clonedNode
= &new_node
->IHTMLDOMNode_iface
;
817 static HRESULT WINAPI
HTMLDOMNode_removeNode(IHTMLDOMNode
*iface
, VARIANT_BOOL fDeep
,
818 IHTMLDOMNode
**removed
)
820 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
821 FIXME("(%p)->(%x %p)\n", This
, fDeep
, removed
);
825 static HRESULT WINAPI
HTMLDOMNode_swapNode(IHTMLDOMNode
*iface
, IHTMLDOMNode
*otherNode
,
826 IHTMLDOMNode
**swappedNode
)
828 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
829 FIXME("(%p)->(%p %p)\n", This
, otherNode
, swappedNode
);
833 static HRESULT WINAPI
HTMLDOMNode_replaceNode(IHTMLDOMNode
*iface
, IHTMLDOMNode
*replacement
,
834 IHTMLDOMNode
**replaced
)
836 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
837 FIXME("(%p)->(%p %p)\n", This
, replacement
, replaced
);
841 static HRESULT WINAPI
HTMLDOMNode_appendChild(IHTMLDOMNode
*iface
, IHTMLDOMNode
*newChild
,
844 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
845 HTMLDOMNode
*node_obj
;
850 TRACE("(%p)->(%p %p)\n", This
, newChild
, node
);
852 node_obj
= get_node_obj(newChild
);
856 nsres
= nsIDOMNode_AppendChild(This
->nsnode
, node_obj
->nsnode
, &nsnode
);
857 node_release(node_obj
);
858 if(NS_FAILED(nsres
)) {
859 ERR("AppendChild failed: %08x\n", nsres
);
863 hres
= get_node(This
->doc
, nsnode
, TRUE
, &node_obj
);
864 nsIDOMNode_Release(nsnode
);
868 /* FIXME: Make sure that node != newChild */
869 *node
= &node_obj
->IHTMLDOMNode_iface
;
873 static HRESULT WINAPI
HTMLDOMNode_get_nodeName(IHTMLDOMNode
*iface
, BSTR
*p
)
875 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
879 TRACE("(%p)->(%p)\n", This
, p
);
881 nsAString_Init(&name
, NULL
);
882 nsres
= nsIDOMNode_GetNodeName(This
->nsnode
, &name
);
883 return return_nsstr(nsres
, &name
, p
);
886 static HRESULT WINAPI
HTMLDOMNode_put_nodeValue(IHTMLDOMNode
*iface
, VARIANT v
)
888 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
890 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&v
));
896 nsAString_InitDepend(&val_str
, V_BSTR(&v
));
897 nsIDOMNode_SetNodeValue(This
->nsnode
, &val_str
);
898 nsAString_Finish(&val_str
);
904 FIXME("unsupported value %s\n", debugstr_variant(&v
));
910 static HRESULT WINAPI
HTMLDOMNode_get_nodeValue(IHTMLDOMNode
*iface
, VARIANT
*p
)
912 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
913 const PRUnichar
*val
;
916 TRACE("(%p)->(%p)\n", This
, p
);
918 nsAString_Init(&val_str
, NULL
);
919 nsIDOMNode_GetNodeValue(This
->nsnode
, &val_str
);
920 nsAString_GetData(&val_str
, &val
);
924 V_BSTR(p
) = SysAllocString(val
);
929 nsAString_Finish(&val_str
);
934 static HRESULT WINAPI
HTMLDOMNode_get_firstChild(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
936 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
937 nsIDOMNode
*nschild
= NULL
;
941 TRACE("(%p)->(%p)\n", This
, p
);
943 nsIDOMNode_GetFirstChild(This
->nsnode
, &nschild
);
949 hres
= get_node(This
->doc
, nschild
, TRUE
, &node
);
950 nsIDOMNode_Release(nschild
);
954 *p
= &node
->IHTMLDOMNode_iface
;
958 static HRESULT WINAPI
HTMLDOMNode_get_lastChild(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
960 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
961 nsIDOMNode
*nschild
= NULL
;
965 TRACE("(%p)->(%p)\n", This
, p
);
967 nsIDOMNode_GetLastChild(This
->nsnode
, &nschild
);
973 hres
= get_node(This
->doc
, nschild
, TRUE
, &node
);
974 nsIDOMNode_Release(nschild
);
978 *p
= &node
->IHTMLDOMNode_iface
;
982 static HRESULT WINAPI
HTMLDOMNode_get_previousSibling(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
984 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
985 nsIDOMNode
*nschild
= NULL
;
989 TRACE("(%p)->(%p)\n", This
, p
);
991 nsIDOMNode_GetPreviousSibling(This
->nsnode
, &nschild
);
997 hres
= get_node(This
->doc
, nschild
, TRUE
, &node
);
998 nsIDOMNode_Release(nschild
);
1002 *p
= &node
->IHTMLDOMNode_iface
;
1006 static HRESULT WINAPI
HTMLDOMNode_get_nextSibling(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
1008 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
1009 nsIDOMNode
*nssibling
= NULL
;
1013 TRACE("(%p)->(%p)\n", This
, p
);
1015 nsIDOMNode_GetNextSibling(This
->nsnode
, &nssibling
);
1021 hres
= get_node(This
->doc
, nssibling
, TRUE
, &node
);
1022 nsIDOMNode_Release(nssibling
);
1026 *p
= &node
->IHTMLDOMNode_iface
;
1030 static const IHTMLDOMNodeVtbl HTMLDOMNodeVtbl
= {
1031 HTMLDOMNode_QueryInterface
,
1033 HTMLDOMNode_Release
,
1034 HTMLDOMNode_GetTypeInfoCount
,
1035 HTMLDOMNode_GetTypeInfo
,
1036 HTMLDOMNode_GetIDsOfNames
,
1038 HTMLDOMNode_get_nodeType
,
1039 HTMLDOMNode_get_parentNode
,
1040 HTMLDOMNode_hasChildNodes
,
1041 HTMLDOMNode_get_childNodes
,
1042 HTMLDOMNode_get_attributes
,
1043 HTMLDOMNode_insertBefore
,
1044 HTMLDOMNode_removeChild
,
1045 HTMLDOMNode_replaceChild
,
1046 HTMLDOMNode_cloneNode
,
1047 HTMLDOMNode_removeNode
,
1048 HTMLDOMNode_swapNode
,
1049 HTMLDOMNode_replaceNode
,
1050 HTMLDOMNode_appendChild
,
1051 HTMLDOMNode_get_nodeName
,
1052 HTMLDOMNode_put_nodeValue
,
1053 HTMLDOMNode_get_nodeValue
,
1054 HTMLDOMNode_get_firstChild
,
1055 HTMLDOMNode_get_lastChild
,
1056 HTMLDOMNode_get_previousSibling
,
1057 HTMLDOMNode_get_nextSibling
1060 static HTMLDOMNode
*get_node_obj(IHTMLDOMNode
*iface
)
1064 if(iface
->lpVtbl
!= &HTMLDOMNodeVtbl
)
1067 ret
= impl_from_IHTMLDOMNode(iface
);
1072 static inline HTMLDOMNode
*impl_from_IHTMLDOMNode2(IHTMLDOMNode2
*iface
)
1074 return CONTAINING_RECORD(iface
, HTMLDOMNode
, IHTMLDOMNode2_iface
);
1077 static HRESULT WINAPI
HTMLDOMNode2_QueryInterface(IHTMLDOMNode2
*iface
,
1078 REFIID riid
, void **ppv
)
1080 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
1082 return IHTMLDOMNode_QueryInterface(&This
->IHTMLDOMNode_iface
, riid
, ppv
);
1085 static ULONG WINAPI
HTMLDOMNode2_AddRef(IHTMLDOMNode2
*iface
)
1087 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
1089 return IHTMLDOMNode_AddRef(&This
->IHTMLDOMNode_iface
);
1092 static ULONG WINAPI
HTMLDOMNode2_Release(IHTMLDOMNode2
*iface
)
1094 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
1096 return IHTMLDOMNode_Release(&This
->IHTMLDOMNode_iface
);
1099 static HRESULT WINAPI
HTMLDOMNode2_GetTypeInfoCount(IHTMLDOMNode2
*iface
, UINT
*pctinfo
)
1101 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
1102 return IDispatchEx_GetTypeInfoCount(&This
->event_target
.dispex
.IDispatchEx_iface
, pctinfo
);
1105 static HRESULT WINAPI
HTMLDOMNode2_GetTypeInfo(IHTMLDOMNode2
*iface
, UINT iTInfo
,
1106 LCID lcid
, ITypeInfo
**ppTInfo
)
1108 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
1109 return IDispatchEx_GetTypeInfo(&This
->event_target
.dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
1112 static HRESULT WINAPI
HTMLDOMNode2_GetIDsOfNames(IHTMLDOMNode2
*iface
, REFIID riid
,
1113 LPOLESTR
*rgszNames
, UINT cNames
,
1114 LCID lcid
, DISPID
*rgDispId
)
1116 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
1117 return IDispatchEx_GetIDsOfNames(&This
->event_target
.dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
1121 static HRESULT WINAPI
HTMLDOMNode2_Invoke(IHTMLDOMNode2
*iface
, DISPID dispIdMember
,
1122 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
1123 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1125 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
1126 return IDispatchEx_Invoke(&This
->event_target
.dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
1127 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1130 static HRESULT WINAPI
HTMLDOMNode2_get_ownerDocument(IHTMLDOMNode2
*iface
, IDispatch
**p
)
1132 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
1134 TRACE("(%p)->(%p)\n", This
, p
);
1136 /* FIXME: Better check for document node */
1137 if(This
== &This
->doc
->node
) {
1140 *p
= (IDispatch
*)&This
->doc
->basedoc
.IHTMLDocument2_iface
;
1141 IDispatch_AddRef(*p
);
1146 static const IHTMLDOMNode2Vtbl HTMLDOMNode2Vtbl
= {
1147 HTMLDOMNode2_QueryInterface
,
1148 HTMLDOMNode2_AddRef
,
1149 HTMLDOMNode2_Release
,
1150 HTMLDOMNode2_GetTypeInfoCount
,
1151 HTMLDOMNode2_GetTypeInfo
,
1152 HTMLDOMNode2_GetIDsOfNames
,
1153 HTMLDOMNode2_Invoke
,
1154 HTMLDOMNode2_get_ownerDocument
1157 static inline HTMLDOMNode
*impl_from_IHTMLDOMNode3(IHTMLDOMNode3
*iface
)
1159 return CONTAINING_RECORD(iface
, HTMLDOMNode
, IHTMLDOMNode3_iface
);
1162 static HRESULT WINAPI
HTMLDOMNode3_QueryInterface(IHTMLDOMNode3
*iface
, REFIID riid
, void **ppv
)
1164 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1165 return IHTMLDOMNode_QueryInterface(&This
->IHTMLDOMNode_iface
, riid
, ppv
);
1168 static ULONG WINAPI
HTMLDOMNode3_AddRef(IHTMLDOMNode3
*iface
)
1170 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1172 return IHTMLDOMNode_AddRef(&This
->IHTMLDOMNode_iface
);
1175 static ULONG WINAPI
HTMLDOMNode3_Release(IHTMLDOMNode3
*iface
)
1177 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1179 return IHTMLDOMNode_Release(&This
->IHTMLDOMNode_iface
);
1182 static HRESULT WINAPI
HTMLDOMNode3_GetTypeInfoCount(IHTMLDOMNode3
*iface
, UINT
*pctinfo
)
1184 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1185 return IDispatchEx_GetTypeInfoCount(&This
->event_target
.dispex
.IDispatchEx_iface
, pctinfo
);
1188 static HRESULT WINAPI
HTMLDOMNode3_GetTypeInfo(IHTMLDOMNode3
*iface
, UINT iTInfo
,
1189 LCID lcid
, ITypeInfo
**ppTInfo
)
1191 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1192 return IDispatchEx_GetTypeInfo(&This
->event_target
.dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
1195 static HRESULT WINAPI
HTMLDOMNode3_GetIDsOfNames(IHTMLDOMNode3
*iface
, REFIID riid
,
1196 LPOLESTR
*rgszNames
, UINT cNames
,
1197 LCID lcid
, DISPID
*rgDispId
)
1199 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1200 return IDispatchEx_GetIDsOfNames(&This
->event_target
.dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
1204 static HRESULT WINAPI
HTMLDOMNode3_Invoke(IHTMLDOMNode3
*iface
, DISPID dispIdMember
,
1205 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
1206 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1208 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1209 return IDispatchEx_Invoke(&This
->event_target
.dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
1210 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1213 static HRESULT WINAPI
HTMLDOMNode3_put_prefix(IHTMLDOMNode3
*iface
, VARIANT v
)
1215 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1216 FIXME("(%p)->(%s)\n", This
, debugstr_variant(&v
));
1220 static HRESULT WINAPI
HTMLDOMNode3_get_prefix(IHTMLDOMNode3
*iface
, VARIANT
*p
)
1222 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1223 FIXME("(%p)->(%p)\n", This
, p
);
1227 static HRESULT WINAPI
HTMLDOMNode3_get_localName(IHTMLDOMNode3
*iface
, VARIANT
*p
)
1229 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1230 FIXME("(%p)->(%p)\n", This
, p
);
1234 static HRESULT WINAPI
HTMLDOMNode3_get_namespaceURI(IHTMLDOMNode3
*iface
, VARIANT
*p
)
1236 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1237 FIXME("(%p)->(%p)\n", This
, p
);
1241 static HRESULT WINAPI
HTMLDOMNode3_put_textContent(IHTMLDOMNode3
*iface
, VARIANT v
)
1243 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1247 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&v
));
1249 if(V_VT(&v
) != VT_BSTR
) {
1250 FIXME("unsupported argument %s\n", debugstr_variant(&v
));
1254 nsAString_Init(&nsstr
, V_BSTR(&v
));
1255 nsres
= nsIDOMNode_SetTextContent(This
->nsnode
, &nsstr
);
1256 nsAString_Finish(&nsstr
);
1257 if(NS_FAILED(nsres
)) {
1258 ERR("SetTextContent failed: %08x\n", nsres
);
1265 static HRESULT WINAPI
HTMLDOMNode3_get_textContent(IHTMLDOMNode3
*iface
, VARIANT
*p
)
1267 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1271 TRACE("(%p)->(%p)\n", This
, p
);
1273 nsAString_Init(&nsstr
, NULL
);
1274 nsres
= nsIDOMNode_GetTextContent(This
->nsnode
, &nsstr
);
1275 return return_nsstr_variant(nsres
, &nsstr
, p
);
1278 static HRESULT WINAPI
HTMLDOMNode3_isEqualNode(IHTMLDOMNode3
*iface
, IHTMLDOMNode3
*otherNode
, VARIANT_BOOL
*isEqual
)
1280 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1281 FIXME("(%p)->()\n", This
);
1285 static HRESULT WINAPI
HTMLDOMNode3_lookupNamespaceURI(IHTMLDOMNode3
*iface
, VARIANT
*prefix
, VARIANT
*namespaceURI
)
1287 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1288 FIXME("(%p)->(%s %p)\n", This
, debugstr_variant(prefix
), namespaceURI
);
1292 static HRESULT WINAPI
HTMLDOMNode3_lookupPrefix(IHTMLDOMNode3
*iface
, VARIANT
*namespaceURI
, VARIANT
*prefix
)
1294 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1295 FIXME("(%p)->(%s %p)\n", This
, debugstr_variant(namespaceURI
), prefix
);
1299 static HRESULT WINAPI
HTMLDOMNode3_isDefaultNamespace(IHTMLDOMNode3
*iface
, VARIANT
*namespace, VARIANT_BOOL
*pfDefaultNamespace
)
1301 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1302 FIXME("(%p)->()\n", This
);
1306 static HRESULT WINAPI
HTMLDOMNode3_appendChild(IHTMLDOMNode3
*iface
, IHTMLDOMNode
*newChild
, IHTMLDOMNode
**node
)
1308 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1309 TRACE("(%p)->()\n", This
);
1310 return IHTMLDOMNode_appendChild(&This
->IHTMLDOMNode_iface
, newChild
, node
);
1313 static HRESULT WINAPI
HTMLDOMNode3_insertBefore(IHTMLDOMNode3
*iface
, IHTMLDOMNode
*newChild
, VARIANT refChild
, IHTMLDOMNode
**node
)
1315 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1316 TRACE("(%p)->(%p %s %p)\n", This
, newChild
, debugstr_variant(&refChild
), node
);
1317 return IHTMLDOMNode_insertBefore(&This
->IHTMLDOMNode_iface
, newChild
, refChild
, node
);
1320 static HRESULT WINAPI
HTMLDOMNode3_removeChild(IHTMLDOMNode3
*iface
, IHTMLDOMNode
*oldChild
, IHTMLDOMNode
**node
)
1322 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1323 TRACE("(%p)->(%p %p)\n", This
, oldChild
, node
);
1324 return IHTMLDOMNode_removeChild(&This
->IHTMLDOMNode_iface
, oldChild
, node
);
1327 static HRESULT WINAPI
HTMLDOMNode3_replaceChild(IHTMLDOMNode3
*iface
, IHTMLDOMNode
*newChild
, IHTMLDOMNode
*oldChild
, IHTMLDOMNode
**node
)
1329 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1330 TRACE("(%p)->(%p %p %p)\n", This
, newChild
, oldChild
, node
);
1331 return IHTMLDOMNode_replaceChild(&This
->IHTMLDOMNode_iface
, newChild
, oldChild
, node
);
1334 static HRESULT WINAPI
HTMLDOMNode3_isSameNode(IHTMLDOMNode3
*iface
, IHTMLDOMNode3
*otherNode
, VARIANT_BOOL
*isSame
)
1336 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1337 FIXME("(%p)->()\n", This
);
1341 static HRESULT WINAPI
HTMLDOMNode3_compareDocumentPosition(IHTMLDOMNode3
*iface
, IHTMLDOMNode
*otherNode
, USHORT
*flags
)
1343 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1348 TRACE("(%p)->()\n", This
);
1350 other
= get_node_obj(otherNode
);
1352 return E_INVALIDARG
;
1354 nsres
= nsIDOMNode_CompareDocumentPosition(This
->nsnode
, other
->nsnode
, &position
);
1355 IHTMLDOMNode_Release(&other
->IHTMLDOMNode_iface
);
1356 if(NS_FAILED(nsres
)) {
1357 ERR("failed: %08x\n", nsres
);
1365 static HRESULT WINAPI
HTMLDOMNode3_isSupported(IHTMLDOMNode3
*iface
, BSTR feature
, VARIANT version
, VARIANT_BOOL
*pfisSupported
)
1367 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode3(iface
);
1368 FIXME("(%p)->(%s %s %p)\n", This
, debugstr_w(feature
), debugstr_variant(&version
), pfisSupported
);
1372 static const IHTMLDOMNode3Vtbl HTMLDOMNode3Vtbl
= {
1373 HTMLDOMNode3_QueryInterface
,
1374 HTMLDOMNode3_AddRef
,
1375 HTMLDOMNode3_Release
,
1376 HTMLDOMNode3_GetTypeInfoCount
,
1377 HTMLDOMNode3_GetTypeInfo
,
1378 HTMLDOMNode3_GetIDsOfNames
,
1379 HTMLDOMNode3_Invoke
,
1380 HTMLDOMNode3_put_prefix
,
1381 HTMLDOMNode3_get_prefix
,
1382 HTMLDOMNode3_get_localName
,
1383 HTMLDOMNode3_get_namespaceURI
,
1384 HTMLDOMNode3_put_textContent
,
1385 HTMLDOMNode3_get_textContent
,
1386 HTMLDOMNode3_isEqualNode
,
1387 HTMLDOMNode3_lookupNamespaceURI
,
1388 HTMLDOMNode3_lookupPrefix
,
1389 HTMLDOMNode3_isDefaultNamespace
,
1390 HTMLDOMNode3_appendChild
,
1391 HTMLDOMNode3_insertBefore
,
1392 HTMLDOMNode3_removeChild
,
1393 HTMLDOMNode3_replaceChild
,
1394 HTMLDOMNode3_isSameNode
,
1395 HTMLDOMNode3_compareDocumentPosition
,
1396 HTMLDOMNode3_isSupported
1399 HRESULT
HTMLDOMNode_QI(HTMLDOMNode
*This
, REFIID riid
, void **ppv
)
1401 TRACE("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
1403 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
1404 *ppv
= &This
->IHTMLDOMNode_iface
;
1405 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
1406 *ppv
= &This
->IHTMLDOMNode_iface
;
1407 }else if(IsEqualGUID(&IID_IHTMLDOMNode
, riid
)) {
1408 *ppv
= &This
->IHTMLDOMNode_iface
;
1409 }else if(IsEqualGUID(&IID_IHTMLDOMNode2
, riid
)) {
1410 *ppv
= &This
->IHTMLDOMNode2_iface
;
1411 }else if(IsEqualGUID(&IID_IHTMLDOMNode3
, riid
)) {
1412 *ppv
= &This
->IHTMLDOMNode3_iface
;
1413 }else if(IsEqualGUID(&IID_nsXPCOMCycleCollectionParticipant
, riid
)) {
1416 }else if(IsEqualGUID(&IID_nsCycleCollectionISupports
, riid
)) {
1417 *ppv
= &This
->IHTMLDOMNode_iface
;
1420 return EventTarget_QI(&This
->event_target
, riid
, ppv
);
1423 IUnknown_AddRef((IUnknown
*)*ppv
);
1427 void HTMLDOMNode_destructor(HTMLDOMNode
*This
)
1429 release_event_target(&This
->event_target
);
1431 nsIDOMNode_Release(This
->nsnode
);
1432 if(This
->doc
&& &This
->doc
->node
!= This
)
1433 htmldoc_release(&This
->doc
->basedoc
);
1436 static HRESULT
HTMLDOMNode_clone(HTMLDOMNode
*This
, nsIDOMNode
*nsnode
, HTMLDOMNode
**ret
)
1438 return create_node(This
->doc
, nsnode
, ret
);
1441 void HTMLDOMNode_init_dispex_info(dispex_data_t
*info
, compat_mode_t mode
)
1443 if(mode
>= COMPAT_MODE_IE9
)
1444 dispex_info_add_interface(info
, IHTMLDOMNode3_tid
, NULL
);
1446 EventTarget_init_dispex_info(info
, mode
);
1449 static const cpc_entry_t HTMLDOMNode_cpc
[] = {{NULL
}};
1451 static const NodeImplVtbl HTMLDOMNodeImplVtbl
= {
1454 HTMLDOMNode_destructor
,
1459 void HTMLDOMNode_Init(HTMLDocumentNode
*doc
, HTMLDOMNode
*node
, nsIDOMNode
*nsnode
, dispex_static_data_t
*dispex_data
)
1463 node
->IHTMLDOMNode_iface
.lpVtbl
= &HTMLDOMNodeVtbl
;
1464 node
->IHTMLDOMNode2_iface
.lpVtbl
= &HTMLDOMNode2Vtbl
;
1465 node
->IHTMLDOMNode3_iface
.lpVtbl
= &HTMLDOMNode3Vtbl
;
1467 ccref_init(&node
->ccref
, 1);
1468 EventTarget_Init(&node
->event_target
, (IUnknown
*)&node
->IHTMLDOMNode_iface
, dispex_data
, doc
->document_mode
);
1470 if(&doc
->node
!= node
)
1471 htmldoc_addref(&doc
->basedoc
);
1474 nsIDOMNode_AddRef(nsnode
);
1475 node
->nsnode
= nsnode
;
1477 nsres
= nsIDOMNode_SetMshtmlNode(nsnode
, (nsISupports
*)&node
->IHTMLDOMNode_iface
);
1478 assert(nsres
== NS_OK
);
1481 static const tid_t HTMLDOMNode_iface_tids
[] = {
1485 static dispex_static_data_t HTMLDOMNode_dispex
= {
1488 HTMLDOMNode_iface_tids
,
1489 HTMLDOMNode_init_dispex_info
1492 static HRESULT
create_node(HTMLDocumentNode
*doc
, nsIDOMNode
*nsnode
, HTMLDOMNode
**ret
)
1497 nsIDOMNode_GetNodeType(nsnode
, &node_type
);
1500 case ELEMENT_NODE
: {
1502 hres
= HTMLElement_Create(doc
, nsnode
, FALSE
, &elem
);
1509 hres
= HTMLDOMTextNode_Create(doc
, nsnode
, ret
);
1513 /* doctype nodes are represented as comment nodes (at least in quirks mode) */
1514 case DOCUMENT_TYPE_NODE
:
1515 case COMMENT_NODE
: {
1516 HTMLElement
*comment
;
1517 hres
= HTMLCommentElement_Create(doc
, nsnode
, &comment
);
1520 *ret
= &comment
->node
;
1523 case ATTRIBUTE_NODE
:
1524 ERR("Called on attribute node\n");
1525 return E_UNEXPECTED
;
1529 FIXME("unimplemented node type %u\n", node_type
);
1531 node
= heap_alloc_zero(sizeof(HTMLDOMNode
));
1533 return E_OUTOFMEMORY
;
1535 node
->vtbl
= &HTMLDOMNodeImplVtbl
;
1536 HTMLDOMNode_Init(doc
, node
, nsnode
, &HTMLDOMNode_dispex
);
1541 TRACE("type %d ret %p\n", node_type
, *ret
);
1545 static nsresult NSAPI
HTMLDOMNode_traverse(void *ccp
, void *p
, nsCycleCollectionTraversalCallback
*cb
)
1547 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(p
);
1549 TRACE("%p\n", This
);
1551 describe_cc_node(&This
->ccref
, "HTMLDOMNode", cb
);
1554 note_cc_edge((nsISupports
*)This
->nsnode
, "This->nsnode", cb
);
1555 if(This
->doc
&& &This
->doc
->node
!= This
)
1556 note_cc_edge((nsISupports
*)&This
->doc
->node
.IHTMLDOMNode_iface
, "This->doc", cb
);
1557 dispex_traverse(&This
->event_target
.dispex
, cb
);
1559 if(This
->vtbl
->traverse
)
1560 This
->vtbl
->traverse(This
, cb
);
1565 static nsresult NSAPI
HTMLDOMNode_unlink(void *p
)
1567 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(p
);
1569 TRACE("%p\n", This
);
1571 if(This
->vtbl
->unlink
)
1572 This
->vtbl
->unlink(This
);
1574 dispex_unlink(&This
->event_target
.dispex
);
1577 nsIDOMNode
*nsnode
= This
->nsnode
;
1578 This
->nsnode
= NULL
;
1579 nsIDOMNode_Release(nsnode
);
1582 if(This
->doc
&& &This
->doc
->node
!= This
) {
1583 HTMLDocument
*doc
= &This
->doc
->basedoc
;
1585 htmldoc_release(doc
);
1593 static void NSAPI
HTMLDOMNode_delete_cycle_collectable(void *p
)
1595 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(p
);
1597 TRACE("(%p)\n", This
);
1599 if(This
->vtbl
->unlink
)
1600 This
->vtbl
->unlink(This
);
1601 This
->vtbl
->destructor(This
);
1602 release_dispex(&This
->event_target
.dispex
);
1606 void init_node_cc(void)
1608 static const CCObjCallback node_ccp_callback
= {
1609 HTMLDOMNode_traverse
,
1611 HTMLDOMNode_delete_cycle_collectable
1614 ccp_init(&node_ccp
, &node_ccp_callback
);
1617 HRESULT
get_node(HTMLDocumentNode
*This
, nsIDOMNode
*nsnode
, BOOL create
, HTMLDOMNode
**ret
)
1619 nsISupports
*unk
= NULL
;
1622 nsres
= nsIDOMNode_GetMshtmlNode(nsnode
, &unk
);
1623 assert(nsres
== NS_OK
);
1626 *ret
= get_node_obj((IHTMLDOMNode
*)unk
);
1627 nsISupports_Release(unk
);
1636 return create_node(This
, nsnode
, ret
);