2 * Copyright 2006 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/debug.h"
30 #include "mshtml_private.h"
31 #include "htmlevent.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
35 static HTMLDOMNode
*get_node_obj(HTMLDocumentNode
*,IUnknown
*);
36 static HRESULT
create_node(HTMLDocumentNode
*,nsIDOMNode
*,HTMLDOMNode
**);
40 IHTMLDOMChildrenCollection IHTMLDOMChildrenCollection_iface
;
44 /* FIXME: implement weak reference */
45 HTMLDocumentNode
*doc
;
47 nsIDOMNodeList
*nslist
;
48 } HTMLDOMChildrenCollection
;
50 static inline HTMLDOMChildrenCollection
*impl_from_IHTMLDOMChildrenCollection(IHTMLDOMChildrenCollection
*iface
)
52 return CONTAINING_RECORD(iface
, HTMLDOMChildrenCollection
, IHTMLDOMChildrenCollection_iface
);
55 static HRESULT WINAPI
HTMLDOMChildrenCollection_QueryInterface(IHTMLDOMChildrenCollection
*iface
, REFIID riid
, void **ppv
)
57 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
61 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
62 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
63 *ppv
= &This
->IHTMLDOMChildrenCollection_iface
;
64 }else if(IsEqualGUID(&IID_IHTMLDOMChildrenCollection
, riid
)) {
65 TRACE("(%p)->(IID_IHTMLDOMChildrenCollection %p)\n", This
, ppv
);
66 *ppv
= &This
->IHTMLDOMChildrenCollection_iface
;
67 }else if(dispex_query_interface(&This
->dispex
, riid
, ppv
)) {
68 return *ppv
? S_OK
: E_NOINTERFACE
;
72 IUnknown_AddRef((IUnknown
*)*ppv
);
76 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
80 static ULONG WINAPI
HTMLDOMChildrenCollection_AddRef(IHTMLDOMChildrenCollection
*iface
)
82 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
83 LONG ref
= InterlockedIncrement(&This
->ref
);
85 TRACE("(%p) ref=%d\n", This
, ref
);
90 static ULONG WINAPI
HTMLDOMChildrenCollection_Release(IHTMLDOMChildrenCollection
*iface
)
92 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
93 LONG ref
= InterlockedDecrement(&This
->ref
);
95 TRACE("(%p) ref=%d\n", This
, ref
);
98 nsIDOMNodeList_Release(This
->nslist
);
105 static HRESULT WINAPI
HTMLDOMChildrenCollection_GetTypeInfoCount(IHTMLDOMChildrenCollection
*iface
, UINT
*pctinfo
)
107 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
108 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
111 static HRESULT WINAPI
HTMLDOMChildrenCollection_GetTypeInfo(IHTMLDOMChildrenCollection
*iface
, UINT iTInfo
,
112 LCID lcid
, ITypeInfo
**ppTInfo
)
114 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
115 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
118 static HRESULT WINAPI
HTMLDOMChildrenCollection_GetIDsOfNames(IHTMLDOMChildrenCollection
*iface
, REFIID riid
,
119 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
121 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
122 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
126 static HRESULT WINAPI
HTMLDOMChildrenCollection_Invoke(IHTMLDOMChildrenCollection
*iface
, DISPID dispIdMember
,
127 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
128 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
130 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
131 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
132 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
135 static HRESULT WINAPI
HTMLDOMChildrenCollection_get_length(IHTMLDOMChildrenCollection
*iface
, LONG
*p
)
137 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
140 TRACE("(%p)->(%p)\n", This
, p
);
142 nsIDOMNodeList_GetLength(This
->nslist
, &length
);
147 static HRESULT WINAPI
HTMLDOMChildrenCollection__newEnum(IHTMLDOMChildrenCollection
*iface
, IUnknown
**p
)
149 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
150 FIXME("(%p)->(%p)\n", This
, p
);
154 static HRESULT WINAPI
HTMLDOMChildrenCollection_item(IHTMLDOMChildrenCollection
*iface
, LONG index
, IDispatch
**ppItem
)
156 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
157 nsIDOMNode
*nsnode
= NULL
;
163 TRACE("(%p)->(%d %p)\n", This
, index
, ppItem
);
170 nsIDOMNodeList_GetLength(This
->nslist
, &length
);
171 if(index
< 0 || index
>= length
)
174 nsres
= nsIDOMNodeList_Item(This
->nslist
, index
, &nsnode
);
175 if(NS_FAILED(nsres
) || !nsnode
) {
176 ERR("Item failed: %08x\n", nsres
);
180 hres
= get_node(This
->doc
, nsnode
, TRUE
, &node
);
184 *ppItem
= (IDispatch
*)&node
->IHTMLDOMNode_iface
;
188 static const IHTMLDOMChildrenCollectionVtbl HTMLDOMChildrenCollectionVtbl
= {
189 HTMLDOMChildrenCollection_QueryInterface
,
190 HTMLDOMChildrenCollection_AddRef
,
191 HTMLDOMChildrenCollection_Release
,
192 HTMLDOMChildrenCollection_GetTypeInfoCount
,
193 HTMLDOMChildrenCollection_GetTypeInfo
,
194 HTMLDOMChildrenCollection_GetIDsOfNames
,
195 HTMLDOMChildrenCollection_Invoke
,
196 HTMLDOMChildrenCollection_get_length
,
197 HTMLDOMChildrenCollection__newEnum
,
198 HTMLDOMChildrenCollection_item
201 static inline HTMLDOMChildrenCollection
*impl_from_DispatchEx(DispatchEx
*iface
)
203 return CONTAINING_RECORD(iface
, HTMLDOMChildrenCollection
, dispex
);
206 #define DISPID_CHILDCOL_0 MSHTML_DISPID_CUSTOM_MIN
208 static HRESULT
HTMLDOMChildrenCollection_get_dispid(DispatchEx
*dispex
, BSTR name
, DWORD flags
, DISPID
*dispid
)
210 HTMLDOMChildrenCollection
*This
= impl_from_DispatchEx(dispex
);
215 for(ptr
= name
; *ptr
&& isdigitW(*ptr
); ptr
++)
216 idx
= idx
*10 + (*ptr
-'0');
218 return DISP_E_UNKNOWNNAME
;
220 nsIDOMNodeList_GetLength(This
->nslist
, &len
);
222 return DISP_E_UNKNOWNNAME
;
224 *dispid
= DISPID_CHILDCOL_0
+ idx
;
225 TRACE("ret %x\n", *dispid
);
229 static HRESULT
HTMLDOMChildrenCollection_invoke(DispatchEx
*dispex
, DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
230 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
232 HTMLDOMChildrenCollection
*This
= impl_from_DispatchEx(dispex
);
234 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, flags
, params
, res
, ei
, caller
);
237 case DISPATCH_PROPERTYGET
: {
238 IDispatch
*disp
= NULL
;
241 hres
= IHTMLDOMChildrenCollection_item(&This
->IHTMLDOMChildrenCollection_iface
,
242 id
- DISPID_CHILDCOL_0
, &disp
);
246 V_VT(res
) = VT_DISPATCH
;
247 V_DISPATCH(res
) = disp
;
252 FIXME("unimplemented flags %x\n", flags
);
259 static const dispex_static_data_vtbl_t HTMLDOMChildrenCollection_dispex_vtbl
= {
261 HTMLDOMChildrenCollection_get_dispid
,
262 HTMLDOMChildrenCollection_invoke
,
266 static const tid_t HTMLDOMChildrenCollection_iface_tids
[] = {
267 IHTMLDOMChildrenCollection_tid
,
271 static dispex_static_data_t HTMLDOMChildrenCollection_dispex
= {
272 &HTMLDOMChildrenCollection_dispex_vtbl
,
273 DispDOMChildrenCollection_tid
,
275 HTMLDOMChildrenCollection_iface_tids
278 static IHTMLDOMChildrenCollection
*create_child_collection(HTMLDocumentNode
*doc
, nsIDOMNodeList
*nslist
)
280 HTMLDOMChildrenCollection
*ret
;
282 ret
= heap_alloc_zero(sizeof(*ret
));
283 ret
->IHTMLDOMChildrenCollection_iface
.lpVtbl
= &HTMLDOMChildrenCollectionVtbl
;
286 nsIDOMNodeList_AddRef(nslist
);
287 ret
->nslist
= nslist
;
290 init_dispex(&ret
->dispex
, (IUnknown
*)&ret
->IHTMLDOMChildrenCollection_iface
,
291 &HTMLDOMChildrenCollection_dispex
);
293 return &ret
->IHTMLDOMChildrenCollection_iface
;
296 static inline HTMLDOMNode
*impl_from_IHTMLDOMNode(IHTMLDOMNode
*iface
)
298 return CONTAINING_RECORD(iface
, HTMLDOMNode
, IHTMLDOMNode_iface
);
301 static HRESULT WINAPI
HTMLDOMNode_QueryInterface(IHTMLDOMNode
*iface
,
302 REFIID riid
, void **ppv
)
304 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
306 return This
->vtbl
->qi(This
, riid
, ppv
);
309 static ULONG WINAPI
HTMLDOMNode_AddRef(IHTMLDOMNode
*iface
)
311 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
312 LONG ref
= InterlockedIncrement(&This
->ref
);
314 TRACE("(%p) ref=%d\n", This
, ref
);
319 static ULONG WINAPI
HTMLDOMNode_Release(IHTMLDOMNode
*iface
)
321 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
322 LONG ref
= InterlockedDecrement(&This
->ref
);
324 TRACE("(%p) ref=%d\n", This
, ref
);
327 This
->vtbl
->destructor(This
);
328 release_dispex(&This
->dispex
);
335 static HRESULT WINAPI
HTMLDOMNode_GetTypeInfoCount(IHTMLDOMNode
*iface
, UINT
*pctinfo
)
337 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
338 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
341 static HRESULT WINAPI
HTMLDOMNode_GetTypeInfo(IHTMLDOMNode
*iface
, UINT iTInfo
,
342 LCID lcid
, ITypeInfo
**ppTInfo
)
344 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
345 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
348 static HRESULT WINAPI
HTMLDOMNode_GetIDsOfNames(IHTMLDOMNode
*iface
, REFIID riid
,
349 LPOLESTR
*rgszNames
, UINT cNames
,
350 LCID lcid
, DISPID
*rgDispId
)
352 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
353 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
357 static HRESULT WINAPI
HTMLDOMNode_Invoke(IHTMLDOMNode
*iface
, DISPID dispIdMember
,
358 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
359 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
361 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
362 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
363 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
366 static HRESULT WINAPI
HTMLDOMNode_get_nodeType(IHTMLDOMNode
*iface
, LONG
*p
)
368 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
371 TRACE("(%p)->(%p)\n", This
, p
);
373 nsIDOMNode_GetNodeType(This
->nsnode
, &type
);
388 case DOCUMENT_FRAGMENT_NODE
:
394 * According to MSDN only ELEMENT_NODE and TEXT_NODE are supported.
395 * It needs more tests.
397 FIXME("type %u\n", type
);
404 static HRESULT WINAPI
HTMLDOMNode_get_parentNode(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
406 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
412 TRACE("(%p)->(%p)\n", This
, p
);
414 nsres
= nsIDOMNode_GetParentNode(This
->nsnode
, &nsnode
);
415 if(NS_FAILED(nsres
)) {
416 ERR("GetParentNode failed: %08x\n", nsres
);
425 hres
= get_node(This
->doc
, nsnode
, TRUE
, &node
);
426 nsIDOMNode_Release(nsnode
);
430 *p
= &node
->IHTMLDOMNode_iface
;
434 static HRESULT WINAPI
HTMLDOMNode_hasChildNodes(IHTMLDOMNode
*iface
, VARIANT_BOOL
*fChildren
)
436 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
437 cpp_bool has_child
= FALSE
;
440 TRACE("(%p)->(%p)\n", This
, fChildren
);
442 nsres
= nsIDOMNode_HasChildNodes(This
->nsnode
, &has_child
);
444 ERR("HasChildNodes failed: %08x\n", nsres
);
446 *fChildren
= has_child
? VARIANT_TRUE
: VARIANT_FALSE
;
450 static HRESULT WINAPI
HTMLDOMNode_get_childNodes(IHTMLDOMNode
*iface
, IDispatch
**p
)
452 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
453 nsIDOMNodeList
*nslist
;
456 TRACE("(%p)->(%p)\n", This
, p
);
458 nsres
= nsIDOMNode_GetChildNodes(This
->nsnode
, &nslist
);
459 if(NS_FAILED(nsres
)) {
460 ERR("GetChildNodes failed: %08x\n", nsres
);
464 *p
= (IDispatch
*)create_child_collection(This
->doc
, nslist
);
465 nsIDOMNodeList_Release(nslist
);
470 static HRESULT WINAPI
HTMLDOMNode_get_attributes(IHTMLDOMNode
*iface
, IDispatch
**p
)
472 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
473 HTMLAttributeCollection
*col
;
476 TRACE("(%p)->(%p)\n", This
, p
);
478 if(This
->vtbl
->get_attr_col
) {
479 hres
= This
->vtbl
->get_attr_col(This
, &col
);
483 *p
= (IDispatch
*)&col
->IHTMLAttributeCollection_iface
;
491 static HRESULT WINAPI
HTMLDOMNode_insertBefore(IHTMLDOMNode
*iface
, IHTMLDOMNode
*newChild
,
492 VARIANT refChild
, IHTMLDOMNode
**node
)
494 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
495 nsIDOMNode
*nsnode
, *nsref
= NULL
;
496 HTMLDOMNode
*new_child
;
497 HTMLDOMNode
*node_obj
;
501 TRACE("(%p)->(%p %s %p)\n", This
, newChild
, debugstr_variant(&refChild
), node
);
503 new_child
= get_node_obj(This
->doc
, (IUnknown
*)newChild
);
505 ERR("invalid newChild\n");
509 switch(V_VT(&refChild
)) {
513 HTMLDOMNode
*ref_node
;
515 ref_node
= get_node_obj(This
->doc
, (IUnknown
*)V_DISPATCH(&refChild
));
517 ERR("unvalid node\n");
521 nsref
= ref_node
->nsnode
;
525 FIXME("unimplemented refChild %s\n", debugstr_variant(&refChild
));
529 nsres
= nsIDOMNode_InsertBefore(This
->nsnode
, new_child
->nsnode
, nsref
, &nsnode
);
530 if(NS_FAILED(nsres
)) {
531 ERR("InsertBefore failed: %08x\n", nsres
);
535 hres
= get_node(This
->doc
, nsnode
, TRUE
, &node_obj
);
536 nsIDOMNode_Release(nsnode
);
540 *node
= &node_obj
->IHTMLDOMNode_iface
;
544 static HRESULT WINAPI
HTMLDOMNode_removeChild(IHTMLDOMNode
*iface
, IHTMLDOMNode
*oldChild
,
547 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
548 HTMLDOMNode
*node_obj
;
553 TRACE("(%p)->(%p %p)\n", This
, oldChild
, node
);
555 node_obj
= get_node_obj(This
->doc
, (IUnknown
*)oldChild
);
559 nsres
= nsIDOMNode_RemoveChild(This
->nsnode
, node_obj
->nsnode
, &nsnode
);
560 if(NS_FAILED(nsres
)) {
561 ERR("RemoveChild failed: %08x\n", nsres
);
565 hres
= get_node(This
->doc
, nsnode
, TRUE
, &node_obj
);
566 nsIDOMNode_Release(nsnode
);
570 /* FIXME: Make sure that node != newChild */
571 *node
= &node_obj
->IHTMLDOMNode_iface
;
575 static HRESULT WINAPI
HTMLDOMNode_replaceChild(IHTMLDOMNode
*iface
, IHTMLDOMNode
*newChild
,
576 IHTMLDOMNode
*oldChild
, IHTMLDOMNode
**node
)
578 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
579 HTMLDOMNode
*node_new
;
580 HTMLDOMNode
*node_old
;
585 TRACE("(%p)->(%p %p %p)\n", This
, newChild
, oldChild
, node
);
587 node_new
= get_node_obj(This
->doc
, (IUnknown
*)newChild
);
591 node_old
= get_node_obj(This
->doc
, (IUnknown
*)oldChild
);
595 nsres
= nsIDOMNode_ReplaceChild(This
->nsnode
, node_new
->nsnode
, node_old
->nsnode
, &nsnode
);
596 if(NS_FAILED(nsres
)) {
600 nsnode
= node_new
->nsnode
;
602 hres
= get_node(This
->doc
, nsnode
, TRUE
, &node_new
);
603 nsIDOMNode_Release(nsnode
);
607 *node
= &node_new
->IHTMLDOMNode_iface
;
611 static HRESULT WINAPI
HTMLDOMNode_cloneNode(IHTMLDOMNode
*iface
, VARIANT_BOOL fDeep
,
612 IHTMLDOMNode
**clonedNode
)
614 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
615 HTMLDOMNode
*new_node
;
620 TRACE("(%p)->(%x %p)\n", This
, fDeep
, clonedNode
);
622 nsres
= nsIDOMNode_CloneNode(This
->nsnode
, fDeep
!= VARIANT_FALSE
, 1, &nsnode
);
623 if(NS_FAILED(nsres
) || !nsnode
) {
624 ERR("CloneNode failed: %08x\n", nsres
);
628 hres
= This
->vtbl
->clone(This
, nsnode
, &new_node
);
632 *clonedNode
= &new_node
->IHTMLDOMNode_iface
;
636 static HRESULT WINAPI
HTMLDOMNode_removeNode(IHTMLDOMNode
*iface
, VARIANT_BOOL fDeep
,
637 IHTMLDOMNode
**removed
)
639 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
640 FIXME("(%p)->(%x %p)\n", This
, fDeep
, removed
);
644 static HRESULT WINAPI
HTMLDOMNode_swapNode(IHTMLDOMNode
*iface
, IHTMLDOMNode
*otherNode
,
645 IHTMLDOMNode
**swappedNode
)
647 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
648 FIXME("(%p)->(%p %p)\n", This
, otherNode
, swappedNode
);
652 static HRESULT WINAPI
HTMLDOMNode_replaceNode(IHTMLDOMNode
*iface
, IHTMLDOMNode
*replacement
,
653 IHTMLDOMNode
**replaced
)
655 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
656 FIXME("(%p)->(%p %p)\n", This
, replacement
, replaced
);
660 static HRESULT WINAPI
HTMLDOMNode_appendChild(IHTMLDOMNode
*iface
, IHTMLDOMNode
*newChild
,
663 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
664 HTMLDOMNode
*node_obj
;
669 TRACE("(%p)->(%p %p)\n", This
, newChild
, node
);
671 node_obj
= get_node_obj(This
->doc
, (IUnknown
*)newChild
);
675 nsres
= nsIDOMNode_AppendChild(This
->nsnode
, node_obj
->nsnode
, &nsnode
);
676 if(NS_FAILED(nsres
)) {
677 WARN("AppendChild failed: %08x\n", nsres
);
678 nsnode
= node_obj
->nsnode
;
681 hres
= get_node(This
->doc
, nsnode
, TRUE
, &node_obj
);
682 nsIDOMNode_Release(nsnode
);
686 /* FIXME: Make sure that node != newChild */
687 *node
= &node_obj
->IHTMLDOMNode_iface
;
691 static HRESULT WINAPI
HTMLDOMNode_get_nodeName(IHTMLDOMNode
*iface
, BSTR
*p
)
693 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
697 TRACE("(%p)->(%p)\n", This
, p
);
699 nsAString_Init(&name
, NULL
);
700 nsres
= nsIDOMNode_GetNodeName(This
->nsnode
, &name
);
701 return return_nsstr(nsres
, &name
, p
);
704 static HRESULT WINAPI
HTMLDOMNode_put_nodeValue(IHTMLDOMNode
*iface
, VARIANT v
)
706 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
708 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&v
));
714 nsAString_InitDepend(&val_str
, V_BSTR(&v
));
715 nsIDOMNode_SetNodeValue(This
->nsnode
, &val_str
);
716 nsAString_Finish(&val_str
);
722 FIXME("unsupported value %s\n", debugstr_variant(&v
));
728 static HRESULT WINAPI
HTMLDOMNode_get_nodeValue(IHTMLDOMNode
*iface
, VARIANT
*p
)
730 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
731 const PRUnichar
*val
;
734 TRACE("(%p)->(%p)\n", This
, p
);
736 nsAString_Init(&val_str
, NULL
);
737 nsIDOMNode_GetNodeValue(This
->nsnode
, &val_str
);
738 nsAString_GetData(&val_str
, &val
);
742 V_BSTR(p
) = SysAllocString(val
);
747 nsAString_Finish(&val_str
);
752 static HRESULT WINAPI
HTMLDOMNode_get_firstChild(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
754 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
755 nsIDOMNode
*nschild
= NULL
;
759 TRACE("(%p)->(%p)\n", This
, p
);
761 nsIDOMNode_GetFirstChild(This
->nsnode
, &nschild
);
767 hres
= get_node(This
->doc
, nschild
, TRUE
, &node
);
768 nsIDOMNode_Release(nschild
);
772 *p
= &node
->IHTMLDOMNode_iface
;
776 static HRESULT WINAPI
HTMLDOMNode_get_lastChild(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
778 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
779 nsIDOMNode
*nschild
= NULL
;
783 TRACE("(%p)->(%p)\n", This
, p
);
785 nsIDOMNode_GetLastChild(This
->nsnode
, &nschild
);
791 hres
= get_node(This
->doc
, nschild
, TRUE
, &node
);
792 nsIDOMNode_Release(nschild
);
796 *p
= &node
->IHTMLDOMNode_iface
;
800 static HRESULT WINAPI
HTMLDOMNode_get_previousSibling(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
802 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
803 nsIDOMNode
*nschild
= NULL
;
807 TRACE("(%p)->(%p)\n", This
, p
);
809 nsIDOMNode_GetPreviousSibling(This
->nsnode
, &nschild
);
815 hres
= get_node(This
->doc
, nschild
, TRUE
, &node
);
816 nsIDOMNode_Release(nschild
);
820 *p
= &node
->IHTMLDOMNode_iface
;
824 static HRESULT WINAPI
HTMLDOMNode_get_nextSibling(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
826 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
827 nsIDOMNode
*nssibling
= NULL
;
831 TRACE("(%p)->(%p)\n", This
, p
);
833 nsIDOMNode_GetNextSibling(This
->nsnode
, &nssibling
);
839 hres
= get_node(This
->doc
, nssibling
, TRUE
, &node
);
840 nsIDOMNode_Release(nssibling
);
844 *p
= &node
->IHTMLDOMNode_iface
;
848 static const IHTMLDOMNodeVtbl HTMLDOMNodeVtbl
= {
849 HTMLDOMNode_QueryInterface
,
852 HTMLDOMNode_GetTypeInfoCount
,
853 HTMLDOMNode_GetTypeInfo
,
854 HTMLDOMNode_GetIDsOfNames
,
856 HTMLDOMNode_get_nodeType
,
857 HTMLDOMNode_get_parentNode
,
858 HTMLDOMNode_hasChildNodes
,
859 HTMLDOMNode_get_childNodes
,
860 HTMLDOMNode_get_attributes
,
861 HTMLDOMNode_insertBefore
,
862 HTMLDOMNode_removeChild
,
863 HTMLDOMNode_replaceChild
,
864 HTMLDOMNode_cloneNode
,
865 HTMLDOMNode_removeNode
,
866 HTMLDOMNode_swapNode
,
867 HTMLDOMNode_replaceNode
,
868 HTMLDOMNode_appendChild
,
869 HTMLDOMNode_get_nodeName
,
870 HTMLDOMNode_put_nodeValue
,
871 HTMLDOMNode_get_nodeValue
,
872 HTMLDOMNode_get_firstChild
,
873 HTMLDOMNode_get_lastChild
,
874 HTMLDOMNode_get_previousSibling
,
875 HTMLDOMNode_get_nextSibling
878 static inline HTMLDOMNode
*impl_from_IHTMLDOMNode2(IHTMLDOMNode2
*iface
)
880 return CONTAINING_RECORD(iface
, HTMLDOMNode
, IHTMLDOMNode2_iface
);
883 static HRESULT WINAPI
HTMLDOMNode2_QueryInterface(IHTMLDOMNode2
*iface
,
884 REFIID riid
, void **ppv
)
886 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
888 return IHTMLDOMNode_QueryInterface(&This
->IHTMLDOMNode_iface
, riid
, ppv
);
891 static ULONG WINAPI
HTMLDOMNode2_AddRef(IHTMLDOMNode2
*iface
)
893 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
895 return IHTMLDOMNode_AddRef(&This
->IHTMLDOMNode_iface
);
898 static ULONG WINAPI
HTMLDOMNode2_Release(IHTMLDOMNode2
*iface
)
900 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
902 return IHTMLDOMNode_Release(&This
->IHTMLDOMNode_iface
);
905 static HRESULT WINAPI
HTMLDOMNode2_GetTypeInfoCount(IHTMLDOMNode2
*iface
, UINT
*pctinfo
)
907 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
908 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
911 static HRESULT WINAPI
HTMLDOMNode2_GetTypeInfo(IHTMLDOMNode2
*iface
, UINT iTInfo
,
912 LCID lcid
, ITypeInfo
**ppTInfo
)
914 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
915 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
918 static HRESULT WINAPI
HTMLDOMNode2_GetIDsOfNames(IHTMLDOMNode2
*iface
, REFIID riid
,
919 LPOLESTR
*rgszNames
, UINT cNames
,
920 LCID lcid
, DISPID
*rgDispId
)
922 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
923 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
927 static HRESULT WINAPI
HTMLDOMNode2_Invoke(IHTMLDOMNode2
*iface
, DISPID dispIdMember
,
928 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
929 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
931 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
932 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
933 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
936 static HRESULT WINAPI
HTMLDOMNode2_get_ownerDocument(IHTMLDOMNode2
*iface
, IDispatch
**p
)
938 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
940 TRACE("(%p)->(%p)\n", This
, p
);
942 /* FIXME: Better check for document node */
943 if(This
== &This
->doc
->node
) {
946 *p
= (IDispatch
*)&This
->doc
->basedoc
.IHTMLDocument2_iface
;
947 IDispatch_AddRef(*p
);
952 static const IHTMLDOMNode2Vtbl HTMLDOMNode2Vtbl
= {
953 HTMLDOMNode2_QueryInterface
,
955 HTMLDOMNode2_Release
,
956 HTMLDOMNode2_GetTypeInfoCount
,
957 HTMLDOMNode2_GetTypeInfo
,
958 HTMLDOMNode2_GetIDsOfNames
,
960 HTMLDOMNode2_get_ownerDocument
963 HRESULT
HTMLDOMNode_QI(HTMLDOMNode
*This
, REFIID riid
, void **ppv
)
967 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
968 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
969 *ppv
= &This
->IHTMLDOMNode_iface
;
970 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
971 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
972 *ppv
= &This
->IHTMLDOMNode_iface
;
973 }else if(IsEqualGUID(&IID_IDispatchEx
, riid
)) {
974 if(This
->dispex
.data
) {
975 TRACE("(%p)->(IID_IDispatchEx %p)\n", This
, ppv
);
976 *ppv
= &This
->dispex
.IDispatchEx_iface
;
978 FIXME("(%p)->(IID_IDispatchEx %p)\n", This
, ppv
);
979 return E_NOINTERFACE
;
981 }else if(IsEqualGUID(&IID_IHTMLDOMNode
, riid
)) {
982 TRACE("(%p)->(IID_IHTMLDOMNode %p)\n", This
, ppv
);
983 *ppv
= &This
->IHTMLDOMNode_iface
;
984 }else if(IsEqualGUID(&IID_IHTMLDOMNode2
, riid
)) {
985 TRACE("(%p)->(IID_IHTMLDOMNode2 %p)\n", This
, ppv
);
986 *ppv
= &This
->IHTMLDOMNode2_iface
;
987 }else if(dispex_query_interface(&This
->dispex
, riid
, ppv
)) {
988 return *ppv
? S_OK
: E_NOINTERFACE
;
992 IUnknown_AddRef((IUnknown
*)*ppv
);
996 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
997 return E_NOINTERFACE
;
1000 void HTMLDOMNode_destructor(HTMLDOMNode
*This
)
1003 nsIDOMNode_Release(This
->nsnode
);
1004 if(This
->event_target
)
1005 release_event_target(This
->event_target
);
1008 static HRESULT
HTMLDOMNode_clone(HTMLDOMNode
*This
, nsIDOMNode
*nsnode
, HTMLDOMNode
**ret
)
1010 return create_node(This
->doc
, nsnode
, ret
);
1013 static const NodeImplVtbl HTMLDOMNodeImplVtbl
= {
1015 HTMLDOMNode_destructor
,
1019 void HTMLDOMNode_Init(HTMLDocumentNode
*doc
, HTMLDOMNode
*node
, nsIDOMNode
*nsnode
)
1021 node
->IHTMLDOMNode_iface
.lpVtbl
= &HTMLDOMNodeVtbl
;
1022 node
->IHTMLDOMNode2_iface
.lpVtbl
= &HTMLDOMNode2Vtbl
;
1026 if(&doc
->node
!= node
)
1027 node
->ref
++; /* one extra for list entry reference */
1030 nsIDOMNode_AddRef(nsnode
);
1031 node
->nsnode
= nsnode
;
1033 node
->next
= doc
->nodes
;
1037 static HRESULT
create_node(HTMLDocumentNode
*doc
, nsIDOMNode
*nsnode
, HTMLDOMNode
**ret
)
1042 nsIDOMNode_GetNodeType(nsnode
, &node_type
);
1045 case ELEMENT_NODE
: {
1047 hres
= HTMLElement_Create(doc
, nsnode
, FALSE
, &elem
);
1054 hres
= HTMLDOMTextNode_Create(doc
, nsnode
, ret
);
1058 case COMMENT_NODE
: {
1059 HTMLElement
*comment
;
1060 hres
= HTMLCommentElement_Create(doc
, nsnode
, &comment
);
1063 *ret
= &comment
->node
;
1066 case ATTRIBUTE_NODE
:
1067 ERR("Called on attribute node\n");
1068 return E_UNEXPECTED
;
1072 node
= heap_alloc_zero(sizeof(HTMLDOMNode
));
1074 return E_OUTOFMEMORY
;
1076 node
->vtbl
= &HTMLDOMNodeImplVtbl
;
1077 HTMLDOMNode_Init(doc
, node
, nsnode
);
1082 TRACE("type %d ret %p\n", node_type
, *ret
);
1088 * List looks really ugly here. We should use a better data structure or
1089 * (better) find a way to store HTMLDOMelement pointer in nsIDOMNode.
1092 HRESULT
get_node(HTMLDocumentNode
*This
, nsIDOMNode
*nsnode
, BOOL create
, HTMLDOMNode
**ret
)
1094 HTMLDOMNode
*iter
= This
->nodes
;
1097 if(iter
->nsnode
== nsnode
)
1102 if(iter
|| !create
) {
1104 IHTMLDOMNode_AddRef(&iter
->IHTMLDOMNode_iface
);
1109 return create_node(This
, nsnode
, ret
);
1114 * We should use better way for getting node object (like private interface)
1115 * or avoid it at all.
1117 static HTMLDOMNode
*get_node_obj(HTMLDocumentNode
*This
, IUnknown
*iface
)
1119 HTMLDOMNode
*iter
= This
->nodes
;
1122 IUnknown_QueryInterface(iface
, &IID_IHTMLDOMNode
, (void**)&node
);
1123 IHTMLDOMNode_Release(node
);
1126 if(&iter
->IHTMLDOMNode_iface
== node
)
1131 FIXME("Not found %p\n", iface
);
1135 void release_nodes(HTMLDocumentNode
*This
)
1137 HTMLDOMNode
*iter
, *next
;
1142 for(iter
= This
->nodes
; iter
; iter
= next
) {
1145 if(&This
->node
!= iter
)
1146 IHTMLDOMNode_Release(&iter
->IHTMLDOMNode_iface
);