comctl32: Fix a typo in comment.
[wine.git] / dlls / mshtml / htmlnode.c
blob0aad4912b0da46e54e548c0b15d3352953ba94ee
1 /*
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
19 #include <stdarg.h>
20 #include <assert.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "ole2.h"
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;
41 typedef struct {
42 DispatchEx dispex;
43 IHTMLDOMChildrenCollection IHTMLDOMChildrenCollection_iface;
45 LONG ref;
47 /* FIXME: implement weak reference */
48 HTMLDocumentNode *doc;
50 nsIDOMNodeList *nslist;
51 } HTMLDOMChildrenCollection;
53 typedef struct {
54 IEnumVARIANT IEnumVARIANT_iface;
56 LONG ref;
58 ULONG iter;
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;
77 }else {
78 FIXME("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
79 *ppv = NULL;
80 return E_NOINTERFACE;
83 IUnknown_AddRef((IUnknown*)*ppv);
84 return S_OK;
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);
94 return 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);
104 if(!ref) {
105 IHTMLDOMChildrenCollection_Release(&This->col->IHTMLDOMChildrenCollection_iface);
106 heap_free(This);
109 return ref;
112 static ULONG get_enum_len(HTMLDOMChildrenCollectionEnum *This)
114 ULONG len;
115 nsresult nsres;
117 nsres = nsIDOMNodeList_GetLength(This->col->nslist, &len);
118 assert(nsres == NS_OK);
119 return len;
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;
126 nsIDOMNode *nsnode;
127 HTMLDOMNode *node;
128 nsresult nsres;
129 HRESULT hres;
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);
141 if(FAILED(hres)) {
142 ERR("get_node failed: %08x\n", hres);
143 break;
146 V_VT(rgVar+fetched) = VT_DISPATCH;
147 IHTMLDOMNode_AddRef(&node->IHTMLDOMNode_iface);
148 V_DISPATCH(rgVar+fetched) = (IDispatch*)&node->IHTMLDOMNode_iface;
149 fetched++;
152 This->iter += fetched;
153 if(pCeltFetched)
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);
161 ULONG len;
163 TRACE("(%p)->(%d)\n", This, celt);
165 len = get_enum_len(This);
166 if(This->iter + celt > len) {
167 This->iter = len;
168 return S_FALSE;
171 This->iter += celt;
172 return S_OK;
175 static HRESULT WINAPI HTMLDOMChildrenCollectionEnum_Reset(IEnumVARIANT *iface)
177 HTMLDOMChildrenCollectionEnum *This = impl_from_IEnumVARIANT(iface);
179 TRACE("(%p)->()\n", This);
181 This->iter = 0;
182 return S_OK;
185 static HRESULT WINAPI HTMLDOMChildrenCollectionEnum_Clone(IEnumVARIANT *iface, IEnumVARIANT **ppEnum)
187 HTMLDOMChildrenCollectionEnum *This = impl_from_IEnumVARIANT(iface);
188 FIXME("(%p)->(%p)\n", This, ppEnum);
189 return E_NOTIMPL;
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;
219 }else {
220 *ppv = NULL;
221 WARN("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
222 return E_NOINTERFACE;
225 IUnknown_AddRef((IUnknown*)*ppv);
226 return S_OK;
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);
236 return 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);
246 if(!ref) {
247 htmldoc_release(&This->doc->basedoc);
248 nsIDOMNodeList_Release(This->nslist);
249 heap_free(This);
252 return ref;
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,
273 lcid, rgDispId);
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);
288 UINT32 length=0;
290 TRACE("(%p)->(%p)\n", This, p);
292 nsIDOMNodeList_GetLength(This->nslist, &length);
293 *p = length;
294 return S_OK;
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));
305 if(!ret)
306 return E_OUTOFMEMORY;
308 ret->IEnumVARIANT_iface.lpVtbl = &HTMLDOMChildrenCollectionEnumVtbl;
309 ret->ref = 1;
310 ret->iter = 0;
312 IHTMLDOMChildrenCollection_AddRef(&This->IHTMLDOMChildrenCollection_iface);
313 ret->col = This;
315 *p = (IUnknown*)&ret->IEnumVARIANT_iface;
316 return S_OK;
319 static HRESULT WINAPI HTMLDOMChildrenCollection_item(IHTMLDOMChildrenCollection *iface, LONG index, IDispatch **ppItem)
321 HTMLDOMChildrenCollection *This = impl_from_IHTMLDOMChildrenCollection(iface);
322 nsIDOMNode *nsnode = NULL;
323 HTMLDOMNode *node;
324 UINT32 length=0;
325 nsresult nsres;
326 HRESULT hres;
328 TRACE("(%p)->(%d %p)\n", This, index, ppItem);
330 if (ppItem)
331 *ppItem = NULL;
332 else
333 return E_POINTER;
335 nsIDOMNodeList_GetLength(This->nslist, &length);
336 if(index < 0 || index >= length)
337 return E_INVALIDARG;
339 nsres = nsIDOMNodeList_Item(This->nslist, index, &nsnode);
340 if(NS_FAILED(nsres) || !nsnode) {
341 ERR("Item failed: %08x\n", nsres);
342 return E_FAIL;
345 hres = get_node(This->doc, nsnode, TRUE, &node);
346 if(FAILED(hres))
347 return hres;
349 *ppItem = (IDispatch*)&node->IHTMLDOMNode_iface;
350 return S_OK;
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);
376 WCHAR *ptr;
377 DWORD idx=0;
378 UINT32 len = 0;
380 for(ptr = name; *ptr && isdigitW(*ptr); ptr++)
381 idx = idx*10 + (*ptr-'0');
382 if(*ptr)
383 return DISP_E_UNKNOWNNAME;
385 nsIDOMNodeList_GetLength(This->nslist, &len);
386 if(idx >= len)
387 return DISP_E_UNKNOWNNAME;
389 *dispid = DISPID_CHILDCOL_0 + idx;
390 TRACE("ret %x\n", *dispid);
391 return S_OK;
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);
401 switch(flags) {
402 case DISPATCH_PROPERTYGET: {
403 IDispatch *disp = NULL;
404 HRESULT hres;
406 hres = IHTMLDOMChildrenCollection_item(&This->IHTMLDOMChildrenCollection_iface,
407 id - DISPID_CHILDCOL_0, &disp);
408 if(FAILED(hres))
409 return hres;
411 V_VT(res) = VT_DISPATCH;
412 V_DISPATCH(res) = disp;
413 break;
416 default:
417 FIXME("unimplemented flags %x\n", flags);
418 return E_NOTIMPL;
421 return S_OK;
424 static const dispex_static_data_vtbl_t HTMLDOMChildrenCollection_dispex_vtbl = {
425 NULL,
426 HTMLDOMChildrenCollection_get_dispid,
427 HTMLDOMChildrenCollection_invoke,
428 NULL
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));
448 if(!ret)
449 return NULL;
451 ret->IHTMLDOMChildrenCollection_iface.lpVtbl = &HTMLDOMChildrenCollectionVtbl;
452 ret->ref = 1;
454 nsIDOMNodeList_AddRef(nslist);
455 ret->nslist = nslist;
457 htmldoc_addref(&doc->basedoc);
458 ret->doc = doc;
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);
482 LONG ref;
484 ref = ccref_incr(&This->ccref, (nsISupports*)&This->IHTMLDOMNode_iface);
486 TRACE("(%p) ref=%d\n", This, ref);
488 return 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);
498 return 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,
520 lcid, rgDispId);
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);
535 UINT16 type = -1;
537 TRACE("(%p)->(%p)\n", This, p);
539 nsIDOMNode_GetNodeType(This->nsnode, &type);
541 switch(type) {
542 case ELEMENT_NODE:
543 *p = 1;
544 break;
545 case TEXT_NODE:
546 *p = 3;
547 break;
548 case COMMENT_NODE:
549 case DOCUMENT_TYPE_NODE:
550 *p = 8;
551 break;
552 case DOCUMENT_NODE:
553 *p = 9;
554 break;
555 case DOCUMENT_FRAGMENT_NODE:
556 *p = 11;
557 break;
558 default:
560 * FIXME:
561 * According to MSDN only ELEMENT_NODE and TEXT_NODE are supported.
562 * It needs more tests.
564 FIXME("type %u\n", type);
565 *p = 0;
568 return S_OK;
571 static HRESULT WINAPI HTMLDOMNode_get_parentNode(IHTMLDOMNode *iface, IHTMLDOMNode **p)
573 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
574 HTMLDOMNode *node;
575 nsIDOMNode *nsnode;
576 nsresult nsres;
577 HRESULT hres;
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);
584 return E_FAIL;
587 if(!nsnode) {
588 *p = NULL;
589 return S_OK;
592 hres = get_node(This->doc, nsnode, TRUE, &node);
593 nsIDOMNode_Release(nsnode);
594 if(FAILED(hres))
595 return hres;
597 *p = &node->IHTMLDOMNode_iface;
598 return S_OK;
601 static HRESULT WINAPI HTMLDOMNode_hasChildNodes(IHTMLDOMNode *iface, VARIANT_BOOL *fChildren)
603 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
604 cpp_bool has_child = FALSE;
605 nsresult nsres;
607 TRACE("(%p)->(%p)\n", This, fChildren);
609 nsres = nsIDOMNode_HasChildNodes(This->nsnode, &has_child);
610 if(NS_FAILED(nsres))
611 ERR("HasChildNodes failed: %08x\n", nsres);
613 *fChildren = variant_bool(has_child);
614 return S_OK;
617 static HRESULT WINAPI HTMLDOMNode_get_childNodes(IHTMLDOMNode *iface, IDispatch **p)
619 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
620 nsIDOMNodeList *nslist;
621 nsresult nsres;
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);
628 return E_FAIL;
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;
641 HRESULT hres;
643 TRACE("(%p)->(%p)\n", This, p);
645 if(This->vtbl->get_attr_col) {
646 hres = This->vtbl->get_attr_col(This, &col);
647 if(FAILED(hres))
648 return hres;
650 *p = (IDispatch*)&col->IHTMLAttributeCollection_iface;
651 return S_OK;
654 *p = NULL;
655 return S_OK;
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;
663 nsIDOMNode *nsnode;
664 nsresult nsres;
665 HRESULT hres = S_OK;
667 TRACE("(%p)->(%p %s %p)\n", This, newChild, debugstr_variant(&refChild), node);
669 new_child = get_node_obj(newChild);
670 if(!new_child) {
671 ERR("invalid newChild\n");
672 return E_INVALIDARG;
675 switch(V_VT(&refChild)) {
676 case VT_NULL:
677 break;
678 case VT_DISPATCH: {
679 IHTMLDOMNode *ref_iface;
681 if(!V_DISPATCH(&refChild))
682 break;
684 hres = IDispatch_QueryInterface(V_DISPATCH(&refChild), &IID_IHTMLDOMNode, (void**)&ref_iface);
685 if(FAILED(hres))
686 break;
688 ref_node = get_node_obj(ref_iface);
689 IHTMLDOMNode_Release(ref_iface);
690 if(!ref_node) {
691 ERR("unvalid node\n");
692 hres = E_FAIL;
693 break;
695 break;
697 default:
698 FIXME("unimplemented refChild %s\n", debugstr_variant(&refChild));
699 hres = E_NOTIMPL;
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);
706 hres = E_FAIL;
709 node_release(new_child);
710 if(ref_node)
711 node_release(ref_node);
712 if(FAILED(hres))
713 return hres;
715 hres = get_node(This->doc, nsnode, TRUE, &node_obj);
716 nsIDOMNode_Release(nsnode);
717 if(FAILED(hres))
718 return hres;
720 *node = &node_obj->IHTMLDOMNode_iface;
721 return S_OK;
724 static HRESULT WINAPI HTMLDOMNode_removeChild(IHTMLDOMNode *iface, IHTMLDOMNode *oldChild,
725 IHTMLDOMNode **node)
727 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
728 HTMLDOMNode *node_obj;
729 nsIDOMNode *nsnode;
730 nsresult nsres;
731 HRESULT hres;
733 TRACE("(%p)->(%p %p)\n", This, oldChild, node);
735 node_obj = get_node_obj(oldChild);
736 if(!node_obj)
737 return E_FAIL;
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);
743 return E_FAIL;
746 hres = get_node(This->doc, nsnode, TRUE, &node_obj);
747 nsIDOMNode_Release(nsnode);
748 if(FAILED(hres))
749 return hres;
751 /* FIXME: Make sure that node != newChild */
752 *node = &node_obj->IHTMLDOMNode_iface;
753 return S_OK;
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;
761 nsIDOMNode *nsnode;
762 nsresult nsres;
763 HRESULT hres;
765 TRACE("(%p)->(%p %p %p)\n", This, newChild, oldChild, node);
767 node_new = get_node_obj(newChild);
768 if(!node_new)
769 return E_FAIL;
771 node_old = get_node_obj(oldChild);
772 if(!node_old) {
773 node_release(node_new);
774 return E_FAIL;
777 nsres = nsIDOMNode_ReplaceChild(This->nsnode, node_new->nsnode, node_old->nsnode, &nsnode);
778 node_release(node_new);
779 node_release(node_old);
780 if(NS_FAILED(nsres))
781 return E_FAIL;
783 hres = get_node(This->doc, nsnode, TRUE, &ret_node);
784 nsIDOMNode_Release(nsnode);
785 if(FAILED(hres))
786 return hres;
788 *node = &ret_node->IHTMLDOMNode_iface;
789 return S_OK;
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;
797 nsIDOMNode *nsnode;
798 nsresult nsres;
799 HRESULT hres;
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);
806 return E_FAIL;
809 hres = This->vtbl->clone(This, nsnode, &new_node);
810 if(FAILED(hres))
811 return hres;
813 *clonedNode = &new_node->IHTMLDOMNode_iface;
814 return S_OK;
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);
822 return E_NOTIMPL;
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);
830 return E_NOTIMPL;
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);
838 return E_NOTIMPL;
841 static HRESULT WINAPI HTMLDOMNode_appendChild(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
842 IHTMLDOMNode **node)
844 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
845 HTMLDOMNode *node_obj;
846 nsIDOMNode *nsnode;
847 nsresult nsres;
848 HRESULT hres;
850 TRACE("(%p)->(%p %p)\n", This, newChild, node);
852 node_obj = get_node_obj(newChild);
853 if(!node_obj)
854 return E_FAIL;
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);
860 return E_FAIL;
863 hres = get_node(This->doc, nsnode, TRUE, &node_obj);
864 nsIDOMNode_Release(nsnode);
865 if(FAILED(hres))
866 return hres;
868 /* FIXME: Make sure that node != newChild */
869 *node = &node_obj->IHTMLDOMNode_iface;
870 return S_OK;
873 static HRESULT WINAPI HTMLDOMNode_get_nodeName(IHTMLDOMNode *iface, BSTR *p)
875 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
876 nsAString name;
877 nsresult nsres;
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));
892 switch(V_VT(&v)) {
893 case VT_BSTR: {
894 nsAString val_str;
896 nsAString_InitDepend(&val_str, V_BSTR(&v));
897 nsIDOMNode_SetNodeValue(This->nsnode, &val_str);
898 nsAString_Finish(&val_str);
900 return S_OK;
903 default:
904 FIXME("unsupported value %s\n", debugstr_variant(&v));
907 return E_NOTIMPL;
910 static HRESULT WINAPI HTMLDOMNode_get_nodeValue(IHTMLDOMNode *iface, VARIANT *p)
912 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
913 const PRUnichar *val;
914 nsAString val_str;
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);
922 if(*val) {
923 V_VT(p) = VT_BSTR;
924 V_BSTR(p) = SysAllocString(val);
925 }else {
926 V_VT(p) = VT_NULL;
929 nsAString_Finish(&val_str);
931 return S_OK;
934 static HRESULT WINAPI HTMLDOMNode_get_firstChild(IHTMLDOMNode *iface, IHTMLDOMNode **p)
936 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
937 nsIDOMNode *nschild = NULL;
938 HTMLDOMNode *node;
939 HRESULT hres;
941 TRACE("(%p)->(%p)\n", This, p);
943 nsIDOMNode_GetFirstChild(This->nsnode, &nschild);
944 if(!nschild) {
945 *p = NULL;
946 return S_OK;
949 hres = get_node(This->doc, nschild, TRUE, &node);
950 nsIDOMNode_Release(nschild);
951 if(FAILED(hres))
952 return hres;
954 *p = &node->IHTMLDOMNode_iface;
955 return S_OK;
958 static HRESULT WINAPI HTMLDOMNode_get_lastChild(IHTMLDOMNode *iface, IHTMLDOMNode **p)
960 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
961 nsIDOMNode *nschild = NULL;
962 HTMLDOMNode *node;
963 HRESULT hres;
965 TRACE("(%p)->(%p)\n", This, p);
967 nsIDOMNode_GetLastChild(This->nsnode, &nschild);
968 if(!nschild) {
969 *p = NULL;
970 return S_OK;
973 hres = get_node(This->doc, nschild, TRUE, &node);
974 nsIDOMNode_Release(nschild);
975 if(FAILED(hres))
976 return hres;
978 *p = &node->IHTMLDOMNode_iface;
979 return S_OK;
982 static HRESULT WINAPI HTMLDOMNode_get_previousSibling(IHTMLDOMNode *iface, IHTMLDOMNode **p)
984 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
985 nsIDOMNode *nschild = NULL;
986 HTMLDOMNode *node;
987 HRESULT hres;
989 TRACE("(%p)->(%p)\n", This, p);
991 nsIDOMNode_GetPreviousSibling(This->nsnode, &nschild);
992 if(!nschild) {
993 *p = NULL;
994 return S_OK;
997 hres = get_node(This->doc, nschild, TRUE, &node);
998 nsIDOMNode_Release(nschild);
999 if(FAILED(hres))
1000 return hres;
1002 *p = &node->IHTMLDOMNode_iface;
1003 return S_OK;
1006 static HRESULT WINAPI HTMLDOMNode_get_nextSibling(IHTMLDOMNode *iface, IHTMLDOMNode **p)
1008 HTMLDOMNode *This = impl_from_IHTMLDOMNode(iface);
1009 nsIDOMNode *nssibling = NULL;
1010 HTMLDOMNode *node;
1011 HRESULT hres;
1013 TRACE("(%p)->(%p)\n", This, p);
1015 nsIDOMNode_GetNextSibling(This->nsnode, &nssibling);
1016 if(!nssibling) {
1017 *p = NULL;
1018 return S_OK;
1021 hres = get_node(This->doc, nssibling, TRUE, &node);
1022 nsIDOMNode_Release(nssibling);
1023 if(FAILED(hres))
1024 return hres;
1026 *p = &node->IHTMLDOMNode_iface;
1027 return S_OK;
1030 static const IHTMLDOMNodeVtbl HTMLDOMNodeVtbl = {
1031 HTMLDOMNode_QueryInterface,
1032 HTMLDOMNode_AddRef,
1033 HTMLDOMNode_Release,
1034 HTMLDOMNode_GetTypeInfoCount,
1035 HTMLDOMNode_GetTypeInfo,
1036 HTMLDOMNode_GetIDsOfNames,
1037 HTMLDOMNode_Invoke,
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)
1062 HTMLDOMNode *ret;
1064 if(iface->lpVtbl != &HTMLDOMNodeVtbl)
1065 return NULL;
1067 ret = impl_from_IHTMLDOMNode(iface);
1068 node_addref(ret);
1069 return ret;
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,
1118 lcid, rgDispId);
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) {
1138 *p = NULL;
1139 }else {
1140 *p = (IDispatch*)&This->doc->basedoc.IHTMLDocument2_iface;
1141 IDispatch_AddRef(*p);
1143 return S_OK;
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,
1201 lcid, rgDispId);
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));
1217 return E_NOTIMPL;
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);
1224 return E_NOTIMPL;
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);
1231 return E_NOTIMPL;
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);
1238 return E_NOTIMPL;
1241 static HRESULT WINAPI HTMLDOMNode3_put_textContent(IHTMLDOMNode3 *iface, VARIANT v)
1243 HTMLDOMNode *This = impl_from_IHTMLDOMNode3(iface);
1244 nsAString nsstr;
1245 nsresult nsres;
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));
1251 return E_NOTIMPL;
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);
1259 return E_FAIL;
1262 return S_OK;
1265 static HRESULT WINAPI HTMLDOMNode3_get_textContent(IHTMLDOMNode3 *iface, VARIANT *p)
1267 HTMLDOMNode *This = impl_from_IHTMLDOMNode3(iface);
1268 nsAString nsstr;
1269 nsresult nsres;
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);
1282 return E_NOTIMPL;
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);
1289 return E_NOTIMPL;
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);
1296 return E_NOTIMPL;
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);
1303 return E_NOTIMPL;
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);
1338 return E_NOTIMPL;
1341 static HRESULT WINAPI HTMLDOMNode3_compareDocumentPosition(IHTMLDOMNode3 *iface, IHTMLDOMNode *otherNode, USHORT *flags)
1343 HTMLDOMNode *This = impl_from_IHTMLDOMNode3(iface);
1344 HTMLDOMNode *other;
1345 UINT16 position;
1346 nsresult nsres;
1348 TRACE("(%p)->()\n", This);
1350 other = get_node_obj(otherNode);
1351 if(!other)
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);
1358 return E_FAIL;
1361 *flags = position;
1362 return S_OK;
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);
1369 return E_NOTIMPL;
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)) {
1414 *ppv = &node_ccp;
1415 return S_OK;
1416 }else if(IsEqualGUID(&IID_nsCycleCollectionISupports, riid)) {
1417 *ppv = &This->IHTMLDOMNode_iface;
1418 return S_OK;
1419 }else {
1420 return EventTarget_QI(&This->event_target, riid, ppv);
1423 IUnknown_AddRef((IUnknown*)*ppv);
1424 return S_OK;
1427 void HTMLDOMNode_destructor(HTMLDOMNode *This)
1429 release_event_target(&This->event_target);
1430 if(This->nsnode)
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 = {
1452 NULL,
1453 HTMLDOMNode_QI,
1454 HTMLDOMNode_destructor,
1455 HTMLDOMNode_cpc,
1456 HTMLDOMNode_clone
1459 void HTMLDOMNode_Init(HTMLDocumentNode *doc, HTMLDOMNode *node, nsIDOMNode *nsnode, dispex_static_data_t *dispex_data)
1461 nsresult nsres;
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);
1472 node->doc = doc;
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[] = {
1482 IHTMLDOMNode_tid,
1485 static dispex_static_data_t HTMLDOMNode_dispex = {
1486 NULL,
1487 IHTMLDOMNode_tid,
1488 HTMLDOMNode_iface_tids,
1489 HTMLDOMNode_init_dispex_info
1492 static HRESULT create_node(HTMLDocumentNode *doc, nsIDOMNode *nsnode, HTMLDOMNode **ret)
1494 UINT16 node_type;
1495 HRESULT hres;
1497 nsIDOMNode_GetNodeType(nsnode, &node_type);
1499 switch(node_type) {
1500 case ELEMENT_NODE: {
1501 HTMLElement *elem;
1502 hres = HTMLElement_Create(doc, nsnode, FALSE, &elem);
1503 if(FAILED(hres))
1504 return hres;
1505 *ret = &elem->node;
1506 break;
1508 case TEXT_NODE:
1509 hres = HTMLDOMTextNode_Create(doc, nsnode, ret);
1510 if(FAILED(hres))
1511 return hres;
1512 break;
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);
1518 if(FAILED(hres))
1519 return hres;
1520 *ret = &comment->node;
1521 break;
1523 case ATTRIBUTE_NODE:
1524 ERR("Called on attribute node\n");
1525 return E_UNEXPECTED;
1526 default: {
1527 HTMLDOMNode *node;
1529 FIXME("unimplemented node type %u\n", node_type);
1531 node = heap_alloc_zero(sizeof(HTMLDOMNode));
1532 if(!node)
1533 return E_OUTOFMEMORY;
1535 node->vtbl = &HTMLDOMNodeImplVtbl;
1536 HTMLDOMNode_Init(doc, node, nsnode, &HTMLDOMNode_dispex);
1537 *ret = node;
1541 TRACE("type %d ret %p\n", node_type, *ret);
1542 return S_OK;
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);
1553 if(This->nsnode)
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);
1562 return NS_OK;
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);
1576 if(This->nsnode) {
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;
1584 This->doc = NULL;
1585 htmldoc_release(doc);
1586 }else {
1587 This->doc = NULL;
1590 return NS_OK;
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);
1603 heap_free(This);
1606 void init_node_cc(void)
1608 static const CCObjCallback node_ccp_callback = {
1609 HTMLDOMNode_traverse,
1610 HTMLDOMNode_unlink,
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;
1620 nsresult nsres;
1622 nsres = nsIDOMNode_GetMshtmlNode(nsnode, &unk);
1623 assert(nsres == NS_OK);
1625 if(unk) {
1626 *ret = get_node_obj((IHTMLDOMNode*)unk);
1627 nsISupports_Release(unk);
1628 return NS_OK;
1631 if(!create) {
1632 *ret = NULL;
1633 return S_OK;
1636 return create_node(This, nsnode, ret);