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 htmldoc_release(&This
->doc
->basedoc
);
99 nsIDOMNodeList_Release(This
->nslist
);
106 static HRESULT WINAPI
HTMLDOMChildrenCollection_GetTypeInfoCount(IHTMLDOMChildrenCollection
*iface
, UINT
*pctinfo
)
108 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
109 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
112 static HRESULT WINAPI
HTMLDOMChildrenCollection_GetTypeInfo(IHTMLDOMChildrenCollection
*iface
, UINT iTInfo
,
113 LCID lcid
, ITypeInfo
**ppTInfo
)
115 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
116 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
119 static HRESULT WINAPI
HTMLDOMChildrenCollection_GetIDsOfNames(IHTMLDOMChildrenCollection
*iface
, REFIID riid
,
120 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
122 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
123 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
127 static HRESULT WINAPI
HTMLDOMChildrenCollection_Invoke(IHTMLDOMChildrenCollection
*iface
, DISPID dispIdMember
,
128 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
129 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
131 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
132 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
133 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
136 static HRESULT WINAPI
HTMLDOMChildrenCollection_get_length(IHTMLDOMChildrenCollection
*iface
, LONG
*p
)
138 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
141 TRACE("(%p)->(%p)\n", This
, p
);
143 nsIDOMNodeList_GetLength(This
->nslist
, &length
);
148 static HRESULT WINAPI
HTMLDOMChildrenCollection__newEnum(IHTMLDOMChildrenCollection
*iface
, IUnknown
**p
)
150 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
151 FIXME("(%p)->(%p)\n", This
, p
);
155 static HRESULT WINAPI
HTMLDOMChildrenCollection_item(IHTMLDOMChildrenCollection
*iface
, LONG index
, IDispatch
**ppItem
)
157 HTMLDOMChildrenCollection
*This
= impl_from_IHTMLDOMChildrenCollection(iface
);
158 nsIDOMNode
*nsnode
= NULL
;
164 TRACE("(%p)->(%d %p)\n", This
, index
, ppItem
);
171 nsIDOMNodeList_GetLength(This
->nslist
, &length
);
172 if(index
< 0 || index
>= length
)
175 nsres
= nsIDOMNodeList_Item(This
->nslist
, index
, &nsnode
);
176 if(NS_FAILED(nsres
) || !nsnode
) {
177 ERR("Item failed: %08x\n", nsres
);
181 hres
= get_node(This
->doc
, nsnode
, TRUE
, &node
);
185 *ppItem
= (IDispatch
*)&node
->IHTMLDOMNode_iface
;
189 static const IHTMLDOMChildrenCollectionVtbl HTMLDOMChildrenCollectionVtbl
= {
190 HTMLDOMChildrenCollection_QueryInterface
,
191 HTMLDOMChildrenCollection_AddRef
,
192 HTMLDOMChildrenCollection_Release
,
193 HTMLDOMChildrenCollection_GetTypeInfoCount
,
194 HTMLDOMChildrenCollection_GetTypeInfo
,
195 HTMLDOMChildrenCollection_GetIDsOfNames
,
196 HTMLDOMChildrenCollection_Invoke
,
197 HTMLDOMChildrenCollection_get_length
,
198 HTMLDOMChildrenCollection__newEnum
,
199 HTMLDOMChildrenCollection_item
202 static inline HTMLDOMChildrenCollection
*impl_from_DispatchEx(DispatchEx
*iface
)
204 return CONTAINING_RECORD(iface
, HTMLDOMChildrenCollection
, dispex
);
207 #define DISPID_CHILDCOL_0 MSHTML_DISPID_CUSTOM_MIN
209 static HRESULT
HTMLDOMChildrenCollection_get_dispid(DispatchEx
*dispex
, BSTR name
, DWORD flags
, DISPID
*dispid
)
211 HTMLDOMChildrenCollection
*This
= impl_from_DispatchEx(dispex
);
216 for(ptr
= name
; *ptr
&& isdigitW(*ptr
); ptr
++)
217 idx
= idx
*10 + (*ptr
-'0');
219 return DISP_E_UNKNOWNNAME
;
221 nsIDOMNodeList_GetLength(This
->nslist
, &len
);
223 return DISP_E_UNKNOWNNAME
;
225 *dispid
= DISPID_CHILDCOL_0
+ idx
;
226 TRACE("ret %x\n", *dispid
);
230 static HRESULT
HTMLDOMChildrenCollection_invoke(DispatchEx
*dispex
, DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
231 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
233 HTMLDOMChildrenCollection
*This
= impl_from_DispatchEx(dispex
);
235 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, flags
, params
, res
, ei
, caller
);
238 case DISPATCH_PROPERTYGET
: {
239 IDispatch
*disp
= NULL
;
242 hres
= IHTMLDOMChildrenCollection_item(&This
->IHTMLDOMChildrenCollection_iface
,
243 id
- DISPID_CHILDCOL_0
, &disp
);
247 V_VT(res
) = VT_DISPATCH
;
248 V_DISPATCH(res
) = disp
;
253 FIXME("unimplemented flags %x\n", flags
);
260 static const dispex_static_data_vtbl_t HTMLDOMChildrenCollection_dispex_vtbl
= {
262 HTMLDOMChildrenCollection_get_dispid
,
263 HTMLDOMChildrenCollection_invoke
,
267 static const tid_t HTMLDOMChildrenCollection_iface_tids
[] = {
268 IHTMLDOMChildrenCollection_tid
,
272 static dispex_static_data_t HTMLDOMChildrenCollection_dispex
= {
273 &HTMLDOMChildrenCollection_dispex_vtbl
,
274 DispDOMChildrenCollection_tid
,
276 HTMLDOMChildrenCollection_iface_tids
279 static IHTMLDOMChildrenCollection
*create_child_collection(HTMLDocumentNode
*doc
, nsIDOMNodeList
*nslist
)
281 HTMLDOMChildrenCollection
*ret
;
283 ret
= heap_alloc_zero(sizeof(*ret
));
284 ret
->IHTMLDOMChildrenCollection_iface
.lpVtbl
= &HTMLDOMChildrenCollectionVtbl
;
287 nsIDOMNodeList_AddRef(nslist
);
288 ret
->nslist
= nslist
;
290 htmldoc_addref(&doc
->basedoc
);
293 init_dispex(&ret
->dispex
, (IUnknown
*)&ret
->IHTMLDOMChildrenCollection_iface
,
294 &HTMLDOMChildrenCollection_dispex
);
296 return &ret
->IHTMLDOMChildrenCollection_iface
;
299 static inline HTMLDOMNode
*impl_from_IHTMLDOMNode(IHTMLDOMNode
*iface
)
301 return CONTAINING_RECORD(iface
, HTMLDOMNode
, IHTMLDOMNode_iface
);
304 static HRESULT WINAPI
HTMLDOMNode_QueryInterface(IHTMLDOMNode
*iface
,
305 REFIID riid
, void **ppv
)
307 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
309 return This
->vtbl
->qi(This
, riid
, ppv
);
312 static ULONG WINAPI
HTMLDOMNode_AddRef(IHTMLDOMNode
*iface
)
314 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
315 LONG ref
= InterlockedIncrement(&This
->ref
);
317 TRACE("(%p) ref=%d\n", This
, ref
);
322 static ULONG WINAPI
HTMLDOMNode_Release(IHTMLDOMNode
*iface
)
324 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
325 LONG ref
= InterlockedDecrement(&This
->ref
);
327 TRACE("(%p) ref=%d\n", This
, ref
);
330 This
->vtbl
->destructor(This
);
331 release_dispex(&This
->dispex
);
338 static HRESULT WINAPI
HTMLDOMNode_GetTypeInfoCount(IHTMLDOMNode
*iface
, UINT
*pctinfo
)
340 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
341 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
344 static HRESULT WINAPI
HTMLDOMNode_GetTypeInfo(IHTMLDOMNode
*iface
, UINT iTInfo
,
345 LCID lcid
, ITypeInfo
**ppTInfo
)
347 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
348 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
351 static HRESULT WINAPI
HTMLDOMNode_GetIDsOfNames(IHTMLDOMNode
*iface
, REFIID riid
,
352 LPOLESTR
*rgszNames
, UINT cNames
,
353 LCID lcid
, DISPID
*rgDispId
)
355 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
356 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
360 static HRESULT WINAPI
HTMLDOMNode_Invoke(IHTMLDOMNode
*iface
, DISPID dispIdMember
,
361 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
362 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
364 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
365 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
366 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
369 static HRESULT WINAPI
HTMLDOMNode_get_nodeType(IHTMLDOMNode
*iface
, LONG
*p
)
371 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
374 TRACE("(%p)->(%p)\n", This
, p
);
376 nsIDOMNode_GetNodeType(This
->nsnode
, &type
);
391 case DOCUMENT_FRAGMENT_NODE
:
397 * According to MSDN only ELEMENT_NODE and TEXT_NODE are supported.
398 * It needs more tests.
400 FIXME("type %u\n", type
);
407 static HRESULT WINAPI
HTMLDOMNode_get_parentNode(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
409 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
415 TRACE("(%p)->(%p)\n", This
, p
);
417 nsres
= nsIDOMNode_GetParentNode(This
->nsnode
, &nsnode
);
418 if(NS_FAILED(nsres
)) {
419 ERR("GetParentNode failed: %08x\n", nsres
);
428 hres
= get_node(This
->doc
, nsnode
, TRUE
, &node
);
429 nsIDOMNode_Release(nsnode
);
433 *p
= &node
->IHTMLDOMNode_iface
;
437 static HRESULT WINAPI
HTMLDOMNode_hasChildNodes(IHTMLDOMNode
*iface
, VARIANT_BOOL
*fChildren
)
439 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
440 cpp_bool has_child
= FALSE
;
443 TRACE("(%p)->(%p)\n", This
, fChildren
);
445 nsres
= nsIDOMNode_HasChildNodes(This
->nsnode
, &has_child
);
447 ERR("HasChildNodes failed: %08x\n", nsres
);
449 *fChildren
= has_child
? VARIANT_TRUE
: VARIANT_FALSE
;
453 static HRESULT WINAPI
HTMLDOMNode_get_childNodes(IHTMLDOMNode
*iface
, IDispatch
**p
)
455 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
456 nsIDOMNodeList
*nslist
;
459 TRACE("(%p)->(%p)\n", This
, p
);
461 nsres
= nsIDOMNode_GetChildNodes(This
->nsnode
, &nslist
);
462 if(NS_FAILED(nsres
)) {
463 ERR("GetChildNodes failed: %08x\n", nsres
);
467 *p
= (IDispatch
*)create_child_collection(This
->doc
, nslist
);
468 nsIDOMNodeList_Release(nslist
);
473 static HRESULT WINAPI
HTMLDOMNode_get_attributes(IHTMLDOMNode
*iface
, IDispatch
**p
)
475 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
476 HTMLAttributeCollection
*col
;
479 TRACE("(%p)->(%p)\n", This
, p
);
481 if(This
->vtbl
->get_attr_col
) {
482 hres
= This
->vtbl
->get_attr_col(This
, &col
);
486 *p
= (IDispatch
*)&col
->IHTMLAttributeCollection_iface
;
494 static HRESULT WINAPI
HTMLDOMNode_insertBefore(IHTMLDOMNode
*iface
, IHTMLDOMNode
*newChild
,
495 VARIANT refChild
, IHTMLDOMNode
**node
)
497 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
498 HTMLDOMNode
*new_child
, *node_obj
, *ref_node
= NULL
;
503 TRACE("(%p)->(%p %s %p)\n", This
, newChild
, debugstr_variant(&refChild
), node
);
505 new_child
= get_node_obj(This
->doc
, (IUnknown
*)newChild
);
507 ERR("invalid newChild\n");
511 switch(V_VT(&refChild
)) {
515 ref_node
= get_node_obj(This
->doc
, (IUnknown
*)V_DISPATCH(&refChild
));
517 ERR("unvalid node\n");
524 FIXME("unimplemented refChild %s\n", debugstr_variant(&refChild
));
528 if(SUCCEEDED(hres
)) {
529 nsres
= nsIDOMNode_InsertBefore(This
->nsnode
, new_child
->nsnode
, ref_node
? ref_node
->nsnode
: NULL
, &nsnode
);
530 if(NS_FAILED(nsres
)) {
531 ERR("InsertBefore failed: %08x\n", nsres
);
535 node_release(new_child
);
537 node_release(ref_node
);
541 hres
= get_node(This
->doc
, nsnode
, TRUE
, &node_obj
);
542 nsIDOMNode_Release(nsnode
);
546 *node
= &node_obj
->IHTMLDOMNode_iface
;
550 static HRESULT WINAPI
HTMLDOMNode_removeChild(IHTMLDOMNode
*iface
, IHTMLDOMNode
*oldChild
,
553 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
554 HTMLDOMNode
*node_obj
;
559 TRACE("(%p)->(%p %p)\n", This
, oldChild
, node
);
561 node_obj
= get_node_obj(This
->doc
, (IUnknown
*)oldChild
);
565 nsres
= nsIDOMNode_RemoveChild(This
->nsnode
, node_obj
->nsnode
, &nsnode
);
566 node_release(node_obj
);
567 if(NS_FAILED(nsres
)) {
568 ERR("RemoveChild failed: %08x\n", nsres
);
572 hres
= get_node(This
->doc
, nsnode
, TRUE
, &node_obj
);
573 nsIDOMNode_Release(nsnode
);
577 /* FIXME: Make sure that node != newChild */
578 *node
= &node_obj
->IHTMLDOMNode_iface
;
582 static HRESULT WINAPI
HTMLDOMNode_replaceChild(IHTMLDOMNode
*iface
, IHTMLDOMNode
*newChild
,
583 IHTMLDOMNode
*oldChild
, IHTMLDOMNode
**node
)
585 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
586 HTMLDOMNode
*node_new
, *node_old
, *ret_node
;
591 TRACE("(%p)->(%p %p %p)\n", This
, newChild
, oldChild
, node
);
593 node_new
= get_node_obj(This
->doc
, (IUnknown
*)newChild
);
597 node_old
= get_node_obj(This
->doc
, (IUnknown
*)oldChild
);
599 node_release(node_new
);
603 nsres
= nsIDOMNode_ReplaceChild(This
->nsnode
, node_new
->nsnode
, node_old
->nsnode
, &nsnode
);
604 node_release(node_new
);
605 node_release(node_old
);
609 hres
= get_node(This
->doc
, nsnode
, TRUE
, &ret_node
);
610 nsIDOMNode_Release(nsnode
);
614 *node
= &ret_node
->IHTMLDOMNode_iface
;
618 static HRESULT WINAPI
HTMLDOMNode_cloneNode(IHTMLDOMNode
*iface
, VARIANT_BOOL fDeep
,
619 IHTMLDOMNode
**clonedNode
)
621 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
622 HTMLDOMNode
*new_node
;
627 TRACE("(%p)->(%x %p)\n", This
, fDeep
, clonedNode
);
629 nsres
= nsIDOMNode_CloneNode(This
->nsnode
, fDeep
!= VARIANT_FALSE
, 1, &nsnode
);
630 if(NS_FAILED(nsres
) || !nsnode
) {
631 ERR("CloneNode failed: %08x\n", nsres
);
635 hres
= This
->vtbl
->clone(This
, nsnode
, &new_node
);
639 *clonedNode
= &new_node
->IHTMLDOMNode_iface
;
643 static HRESULT WINAPI
HTMLDOMNode_removeNode(IHTMLDOMNode
*iface
, VARIANT_BOOL fDeep
,
644 IHTMLDOMNode
**removed
)
646 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
647 FIXME("(%p)->(%x %p)\n", This
, fDeep
, removed
);
651 static HRESULT WINAPI
HTMLDOMNode_swapNode(IHTMLDOMNode
*iface
, IHTMLDOMNode
*otherNode
,
652 IHTMLDOMNode
**swappedNode
)
654 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
655 FIXME("(%p)->(%p %p)\n", This
, otherNode
, swappedNode
);
659 static HRESULT WINAPI
HTMLDOMNode_replaceNode(IHTMLDOMNode
*iface
, IHTMLDOMNode
*replacement
,
660 IHTMLDOMNode
**replaced
)
662 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
663 FIXME("(%p)->(%p %p)\n", This
, replacement
, replaced
);
667 static HRESULT WINAPI
HTMLDOMNode_appendChild(IHTMLDOMNode
*iface
, IHTMLDOMNode
*newChild
,
670 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
671 HTMLDOMNode
*node_obj
;
676 TRACE("(%p)->(%p %p)\n", This
, newChild
, node
);
678 node_obj
= get_node_obj(This
->doc
, (IUnknown
*)newChild
);
682 nsres
= nsIDOMNode_AppendChild(This
->nsnode
, node_obj
->nsnode
, &nsnode
);
683 node_release(node_obj
);
684 if(NS_FAILED(nsres
)) {
685 ERR("AppendChild failed: %08x\n", nsres
);
689 hres
= get_node(This
->doc
, nsnode
, TRUE
, &node_obj
);
690 nsIDOMNode_Release(nsnode
);
694 /* FIXME: Make sure that node != newChild */
695 *node
= &node_obj
->IHTMLDOMNode_iface
;
699 static HRESULT WINAPI
HTMLDOMNode_get_nodeName(IHTMLDOMNode
*iface
, BSTR
*p
)
701 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
705 TRACE("(%p)->(%p)\n", This
, p
);
707 nsAString_Init(&name
, NULL
);
708 nsres
= nsIDOMNode_GetNodeName(This
->nsnode
, &name
);
709 return return_nsstr(nsres
, &name
, p
);
712 static HRESULT WINAPI
HTMLDOMNode_put_nodeValue(IHTMLDOMNode
*iface
, VARIANT v
)
714 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
716 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&v
));
722 nsAString_InitDepend(&val_str
, V_BSTR(&v
));
723 nsIDOMNode_SetNodeValue(This
->nsnode
, &val_str
);
724 nsAString_Finish(&val_str
);
730 FIXME("unsupported value %s\n", debugstr_variant(&v
));
736 static HRESULT WINAPI
HTMLDOMNode_get_nodeValue(IHTMLDOMNode
*iface
, VARIANT
*p
)
738 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
739 const PRUnichar
*val
;
742 TRACE("(%p)->(%p)\n", This
, p
);
744 nsAString_Init(&val_str
, NULL
);
745 nsIDOMNode_GetNodeValue(This
->nsnode
, &val_str
);
746 nsAString_GetData(&val_str
, &val
);
750 V_BSTR(p
) = SysAllocString(val
);
755 nsAString_Finish(&val_str
);
760 static HRESULT WINAPI
HTMLDOMNode_get_firstChild(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
762 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
763 nsIDOMNode
*nschild
= NULL
;
767 TRACE("(%p)->(%p)\n", This
, p
);
769 nsIDOMNode_GetFirstChild(This
->nsnode
, &nschild
);
775 hres
= get_node(This
->doc
, nschild
, TRUE
, &node
);
776 nsIDOMNode_Release(nschild
);
780 *p
= &node
->IHTMLDOMNode_iface
;
784 static HRESULT WINAPI
HTMLDOMNode_get_lastChild(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
786 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
787 nsIDOMNode
*nschild
= NULL
;
791 TRACE("(%p)->(%p)\n", This
, p
);
793 nsIDOMNode_GetLastChild(This
->nsnode
, &nschild
);
799 hres
= get_node(This
->doc
, nschild
, TRUE
, &node
);
800 nsIDOMNode_Release(nschild
);
804 *p
= &node
->IHTMLDOMNode_iface
;
808 static HRESULT WINAPI
HTMLDOMNode_get_previousSibling(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
810 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
811 nsIDOMNode
*nschild
= NULL
;
815 TRACE("(%p)->(%p)\n", This
, p
);
817 nsIDOMNode_GetPreviousSibling(This
->nsnode
, &nschild
);
823 hres
= get_node(This
->doc
, nschild
, TRUE
, &node
);
824 nsIDOMNode_Release(nschild
);
828 *p
= &node
->IHTMLDOMNode_iface
;
832 static HRESULT WINAPI
HTMLDOMNode_get_nextSibling(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
834 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode(iface
);
835 nsIDOMNode
*nssibling
= NULL
;
839 TRACE("(%p)->(%p)\n", This
, p
);
841 nsIDOMNode_GetNextSibling(This
->nsnode
, &nssibling
);
847 hres
= get_node(This
->doc
, nssibling
, TRUE
, &node
);
848 nsIDOMNode_Release(nssibling
);
852 *p
= &node
->IHTMLDOMNode_iface
;
856 static const IHTMLDOMNodeVtbl HTMLDOMNodeVtbl
= {
857 HTMLDOMNode_QueryInterface
,
860 HTMLDOMNode_GetTypeInfoCount
,
861 HTMLDOMNode_GetTypeInfo
,
862 HTMLDOMNode_GetIDsOfNames
,
864 HTMLDOMNode_get_nodeType
,
865 HTMLDOMNode_get_parentNode
,
866 HTMLDOMNode_hasChildNodes
,
867 HTMLDOMNode_get_childNodes
,
868 HTMLDOMNode_get_attributes
,
869 HTMLDOMNode_insertBefore
,
870 HTMLDOMNode_removeChild
,
871 HTMLDOMNode_replaceChild
,
872 HTMLDOMNode_cloneNode
,
873 HTMLDOMNode_removeNode
,
874 HTMLDOMNode_swapNode
,
875 HTMLDOMNode_replaceNode
,
876 HTMLDOMNode_appendChild
,
877 HTMLDOMNode_get_nodeName
,
878 HTMLDOMNode_put_nodeValue
,
879 HTMLDOMNode_get_nodeValue
,
880 HTMLDOMNode_get_firstChild
,
881 HTMLDOMNode_get_lastChild
,
882 HTMLDOMNode_get_previousSibling
,
883 HTMLDOMNode_get_nextSibling
886 static HTMLDOMNode
*get_node_obj(HTMLDocumentNode
*This
, IUnknown
*iface
)
891 hres
= IUnknown_QueryInterface(iface
, &IID_IHTMLDOMNode
, (void**)&node
);
892 return hres
== S_OK
&& node
->lpVtbl
== &HTMLDOMNodeVtbl
? impl_from_IHTMLDOMNode(node
) : NULL
;
895 static inline HTMLDOMNode
*impl_from_IHTMLDOMNode2(IHTMLDOMNode2
*iface
)
897 return CONTAINING_RECORD(iface
, HTMLDOMNode
, IHTMLDOMNode2_iface
);
900 static HRESULT WINAPI
HTMLDOMNode2_QueryInterface(IHTMLDOMNode2
*iface
,
901 REFIID riid
, void **ppv
)
903 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
905 return IHTMLDOMNode_QueryInterface(&This
->IHTMLDOMNode_iface
, riid
, ppv
);
908 static ULONG WINAPI
HTMLDOMNode2_AddRef(IHTMLDOMNode2
*iface
)
910 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
912 return IHTMLDOMNode_AddRef(&This
->IHTMLDOMNode_iface
);
915 static ULONG WINAPI
HTMLDOMNode2_Release(IHTMLDOMNode2
*iface
)
917 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
919 return IHTMLDOMNode_Release(&This
->IHTMLDOMNode_iface
);
922 static HRESULT WINAPI
HTMLDOMNode2_GetTypeInfoCount(IHTMLDOMNode2
*iface
, UINT
*pctinfo
)
924 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
925 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
928 static HRESULT WINAPI
HTMLDOMNode2_GetTypeInfo(IHTMLDOMNode2
*iface
, UINT iTInfo
,
929 LCID lcid
, ITypeInfo
**ppTInfo
)
931 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
932 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
935 static HRESULT WINAPI
HTMLDOMNode2_GetIDsOfNames(IHTMLDOMNode2
*iface
, REFIID riid
,
936 LPOLESTR
*rgszNames
, UINT cNames
,
937 LCID lcid
, DISPID
*rgDispId
)
939 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
940 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
944 static HRESULT WINAPI
HTMLDOMNode2_Invoke(IHTMLDOMNode2
*iface
, DISPID dispIdMember
,
945 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
946 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
948 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
949 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
950 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
953 static HRESULT WINAPI
HTMLDOMNode2_get_ownerDocument(IHTMLDOMNode2
*iface
, IDispatch
**p
)
955 HTMLDOMNode
*This
= impl_from_IHTMLDOMNode2(iface
);
957 TRACE("(%p)->(%p)\n", This
, p
);
959 /* FIXME: Better check for document node */
960 if(This
== &This
->doc
->node
) {
963 *p
= (IDispatch
*)&This
->doc
->basedoc
.IHTMLDocument2_iface
;
964 IDispatch_AddRef(*p
);
969 static const IHTMLDOMNode2Vtbl HTMLDOMNode2Vtbl
= {
970 HTMLDOMNode2_QueryInterface
,
972 HTMLDOMNode2_Release
,
973 HTMLDOMNode2_GetTypeInfoCount
,
974 HTMLDOMNode2_GetTypeInfo
,
975 HTMLDOMNode2_GetIDsOfNames
,
977 HTMLDOMNode2_get_ownerDocument
980 HRESULT
HTMLDOMNode_QI(HTMLDOMNode
*This
, REFIID riid
, void **ppv
)
984 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
985 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
986 *ppv
= &This
->IHTMLDOMNode_iface
;
987 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
988 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
989 *ppv
= &This
->IHTMLDOMNode_iface
;
990 }else if(IsEqualGUID(&IID_IDispatchEx
, riid
)) {
991 if(This
->dispex
.data
) {
992 TRACE("(%p)->(IID_IDispatchEx %p)\n", This
, ppv
);
993 *ppv
= &This
->dispex
.IDispatchEx_iface
;
995 FIXME("(%p)->(IID_IDispatchEx %p)\n", This
, ppv
);
996 return E_NOINTERFACE
;
998 }else if(IsEqualGUID(&IID_IHTMLDOMNode
, riid
)) {
999 TRACE("(%p)->(IID_IHTMLDOMNode %p)\n", This
, ppv
);
1000 *ppv
= &This
->IHTMLDOMNode_iface
;
1001 }else if(IsEqualGUID(&IID_IHTMLDOMNode2
, riid
)) {
1002 TRACE("(%p)->(IID_IHTMLDOMNode2 %p)\n", This
, ppv
);
1003 *ppv
= &This
->IHTMLDOMNode2_iface
;
1004 }else if(dispex_query_interface(&This
->dispex
, riid
, ppv
)) {
1005 return *ppv
? S_OK
: E_NOINTERFACE
;
1009 IUnknown_AddRef((IUnknown
*)*ppv
);
1013 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
1014 return E_NOINTERFACE
;
1017 void HTMLDOMNode_destructor(HTMLDOMNode
*This
)
1020 nsIDOMNode_Release(This
->nsnode
);
1021 if(This
->event_target
)
1022 release_event_target(This
->event_target
);
1025 static HRESULT
HTMLDOMNode_clone(HTMLDOMNode
*This
, nsIDOMNode
*nsnode
, HTMLDOMNode
**ret
)
1027 return create_node(This
->doc
, nsnode
, ret
);
1030 static const NodeImplVtbl HTMLDOMNodeImplVtbl
= {
1032 HTMLDOMNode_destructor
,
1036 void HTMLDOMNode_Init(HTMLDocumentNode
*doc
, HTMLDOMNode
*node
, nsIDOMNode
*nsnode
)
1038 node
->IHTMLDOMNode_iface
.lpVtbl
= &HTMLDOMNodeVtbl
;
1039 node
->IHTMLDOMNode2_iface
.lpVtbl
= &HTMLDOMNode2Vtbl
;
1043 if(&doc
->node
!= node
)
1044 node
->ref
++; /* one extra for list entry reference */
1047 nsIDOMNode_AddRef(nsnode
);
1048 node
->nsnode
= nsnode
;
1050 node
->next
= doc
->nodes
;
1054 static HRESULT
create_node(HTMLDocumentNode
*doc
, nsIDOMNode
*nsnode
, HTMLDOMNode
**ret
)
1059 nsIDOMNode_GetNodeType(nsnode
, &node_type
);
1062 case ELEMENT_NODE
: {
1064 hres
= HTMLElement_Create(doc
, nsnode
, FALSE
, &elem
);
1071 hres
= HTMLDOMTextNode_Create(doc
, nsnode
, ret
);
1075 case COMMENT_NODE
: {
1076 HTMLElement
*comment
;
1077 hres
= HTMLCommentElement_Create(doc
, nsnode
, &comment
);
1080 *ret
= &comment
->node
;
1083 case ATTRIBUTE_NODE
:
1084 ERR("Called on attribute node\n");
1085 return E_UNEXPECTED
;
1089 node
= heap_alloc_zero(sizeof(HTMLDOMNode
));
1091 return E_OUTOFMEMORY
;
1093 node
->vtbl
= &HTMLDOMNodeImplVtbl
;
1094 HTMLDOMNode_Init(doc
, node
, nsnode
);
1099 TRACE("type %d ret %p\n", node_type
, *ret
);
1105 * List looks really ugly here. We should use a better data structure or
1106 * (better) find a way to store HTMLDOMelement pointer in nsIDOMNode.
1109 HRESULT
get_node(HTMLDocumentNode
*This
, nsIDOMNode
*nsnode
, BOOL create
, HTMLDOMNode
**ret
)
1111 HTMLDOMNode
*iter
= This
->nodes
;
1114 if(iter
->nsnode
== nsnode
)
1119 if(iter
|| !create
) {
1121 IHTMLDOMNode_AddRef(&iter
->IHTMLDOMNode_iface
);
1126 return create_node(This
, nsnode
, ret
);
1129 void release_nodes(HTMLDocumentNode
*This
)
1131 HTMLDOMNode
*iter
, *next
;
1136 for(iter
= This
->nodes
; iter
; iter
= next
) {
1139 if(&This
->node
!= iter
)
1140 IHTMLDOMNode_Release(&iter
->IHTMLDOMNode_iface
);