hal: Add appropriate stdcall decorations to assembly functions.
[wine.git] / dlls / mshtml / htmlnode.c
blob720bbfef4be1a648075780ad0d13edb6075ea666
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>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "ole2.h"
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(HTMLDocument*,IUnknown*);
37 typedef struct {
38 DispatchEx dispex;
39 const IHTMLDOMChildrenCollectionVtbl *lpIHTMLDOMChildrenCollectionVtbl;
41 LONG ref;
43 /* FIXME: implement weak reference */
44 HTMLDocument *doc;
46 nsIDOMNodeList *nslist;
47 } HTMLDOMChildrenCollection;
49 #define HTMLCHILDCOL(x) ((IHTMLDOMChildrenCollection*) &(x)->lpIHTMLDOMChildrenCollectionVtbl)
51 #define HTMLCHILDCOL_THIS(iface) DEFINE_THIS(HTMLDOMChildrenCollection, IHTMLDOMChildrenCollection, iface)
53 static HRESULT WINAPI HTMLDOMChildrenCollection_QueryInterface(IHTMLDOMChildrenCollection *iface, REFIID riid, void **ppv)
55 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
57 *ppv = NULL;
59 if(IsEqualGUID(&IID_IUnknown, riid)) {
60 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
61 *ppv = HTMLCHILDCOL(This);
62 }else if(IsEqualGUID(&IID_IHTMLDOMChildrenCollection, riid)) {
63 TRACE("(%p)->(IID_IHTMLDOMChildrenCollection %p)\n", This, ppv);
64 *ppv = HTMLCHILDCOL(This);
65 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
66 return *ppv ? S_OK : E_NOINTERFACE;
69 if(*ppv) {
70 IUnknown_AddRef((IUnknown*)*ppv);
71 return S_OK;
74 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
75 return E_NOINTERFACE;
78 static ULONG WINAPI HTMLDOMChildrenCollection_AddRef(IHTMLDOMChildrenCollection *iface)
80 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
81 LONG ref = InterlockedIncrement(&This->ref);
83 TRACE("(%p) ref=%d\n", This, ref);
85 return ref;
88 static ULONG WINAPI HTMLDOMChildrenCollection_Release(IHTMLDOMChildrenCollection *iface)
90 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
91 LONG ref = InterlockedDecrement(&This->ref);
93 TRACE("(%p) ref=%d\n", This, ref);
95 if(!ref) {
96 nsIDOMNodeList_Release(This->nslist);
97 heap_free(This);
100 return ref;
103 static HRESULT WINAPI HTMLDOMChildrenCollection_GetTypeInfoCount(IHTMLDOMChildrenCollection *iface, UINT *pctinfo)
105 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
106 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->dispex), pctinfo);
109 static HRESULT WINAPI HTMLDOMChildrenCollection_GetTypeInfo(IHTMLDOMChildrenCollection *iface, UINT iTInfo,
110 LCID lcid, ITypeInfo **ppTInfo)
112 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
113 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
116 static HRESULT WINAPI HTMLDOMChildrenCollection_GetIDsOfNames(IHTMLDOMChildrenCollection *iface, REFIID riid,
117 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
119 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
120 return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->dispex), riid, rgszNames, cNames, lcid, rgDispId);
123 static HRESULT WINAPI HTMLDOMChildrenCollection_Invoke(IHTMLDOMChildrenCollection *iface, DISPID dispIdMember,
124 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
125 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
127 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
128 return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid,
129 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
132 static HRESULT WINAPI HTMLDOMChildrenCollection_get_length(IHTMLDOMChildrenCollection *iface, LONG *p)
134 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
135 PRUint32 length=0;
137 TRACE("(%p)->(%p)\n", This, p);
139 nsIDOMNodeList_GetLength(This->nslist, &length);
140 *p = length;
141 return S_OK;
144 static HRESULT WINAPI HTMLDOMChildrenCollection__newEnum(IHTMLDOMChildrenCollection *iface, IUnknown **p)
146 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
147 FIXME("(%p)->(%p)\n", This, p);
148 return E_NOTIMPL;
151 static HRESULT WINAPI HTMLDOMChildrenCollection_item(IHTMLDOMChildrenCollection *iface, LONG index, IDispatch **ppItem)
153 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
154 nsIDOMNode *nsnode = NULL;
155 PRUint32 length=0;
156 nsresult nsres;
158 TRACE("(%p)->(%d %p)\n", This, index, ppItem);
160 if (ppItem)
161 *ppItem = NULL;
162 else
163 return E_POINTER;
165 nsIDOMNodeList_GetLength(This->nslist, &length);
166 if(index < 0 || index >= length)
167 return E_INVALIDARG;
169 nsres = nsIDOMNodeList_Item(This->nslist, index, &nsnode);
170 if(NS_FAILED(nsres) || !nsnode) {
171 ERR("Item failed: %08x\n", nsres);
172 return E_FAIL;
175 *ppItem = (IDispatch*)get_node(This->doc, nsnode, TRUE);
176 IDispatch_AddRef(*ppItem);
177 return S_OK;
180 #define DISPID_CHILDCOL_0 MSHTML_DISPID_CUSTOM_MIN
182 static HRESULT HTMLDOMChildrenCollection_get_dispid(IUnknown *iface, BSTR name, DWORD flags, DISPID *dispid)
184 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
185 WCHAR *ptr;
186 DWORD idx=0;
187 PRUint32 len = 0;
189 for(ptr = name; *ptr && isdigitW(*ptr); ptr++)
190 idx = idx*10 + (*ptr-'0');
191 if(*ptr)
192 return DISP_E_UNKNOWNNAME;
194 nsIDOMNodeList_GetLength(This->nslist, &len);
195 if(idx >= len)
196 return DISP_E_UNKNOWNNAME;
198 *dispid = DISPID_CHILDCOL_0 + idx;
199 TRACE("ret %x\n", *dispid);
200 return S_OK;
203 static HRESULT HTMLDOMChildrenCollection_invoke(IUnknown *iface, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
204 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
206 HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
208 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
210 switch(flags) {
211 case INVOKE_PROPERTYGET: {
212 IDispatch *disp = NULL;
213 HRESULT hres;
215 hres = IHTMLDOMChildrenCollection_item(HTMLCHILDCOL(This), id - DISPID_CHILDCOL_0, &disp);
216 if(0&&FAILED(hres))
217 return hres;
219 V_VT(res) = VT_DISPATCH;
220 V_DISPATCH(res) = disp;
221 break;
224 default:
225 FIXME("unimplemented flags %x\n", flags);
226 return E_NOTIMPL;
229 return S_OK;
232 #undef HTMLCHILDCOL_THIS
234 static const IHTMLDOMChildrenCollectionVtbl HTMLDOMChildrenCollectionVtbl = {
235 HTMLDOMChildrenCollection_QueryInterface,
236 HTMLDOMChildrenCollection_AddRef,
237 HTMLDOMChildrenCollection_Release,
238 HTMLDOMChildrenCollection_GetTypeInfoCount,
239 HTMLDOMChildrenCollection_GetTypeInfo,
240 HTMLDOMChildrenCollection_GetIDsOfNames,
241 HTMLDOMChildrenCollection_Invoke,
242 HTMLDOMChildrenCollection_get_length,
243 HTMLDOMChildrenCollection__newEnum,
244 HTMLDOMChildrenCollection_item
247 static const tid_t HTMLDOMChildrenCollection_iface_tids[] = {
248 IHTMLDOMChildrenCollection_tid,
252 static const dispex_static_data_vtbl_t HTMLDOMChildrenCollection_dispex_vtbl = {
253 HTMLDOMChildrenCollection_get_dispid,
254 HTMLDOMChildrenCollection_invoke
257 static dispex_static_data_t HTMLDOMChildrenCollection_dispex = {
258 &HTMLDOMChildrenCollection_dispex_vtbl,
259 DispDOMChildrenCollection_tid,
260 NULL,
261 HTMLDOMChildrenCollection_iface_tids
264 static IHTMLDOMChildrenCollection *create_child_collection(HTMLDocument *doc, nsIDOMNodeList *nslist)
266 HTMLDOMChildrenCollection *ret;
268 ret = heap_alloc_zero(sizeof(*ret));
269 ret->lpIHTMLDOMChildrenCollectionVtbl = &HTMLDOMChildrenCollectionVtbl;
270 ret->ref = 1;
272 nsIDOMNodeList_AddRef(nslist);
273 ret->nslist = nslist;
274 ret->doc = doc;
276 init_dispex(&ret->dispex, (IUnknown*)HTMLCHILDCOL(ret), &HTMLDOMChildrenCollection_dispex);
278 return HTMLCHILDCOL(ret);
281 #define HTMLDOMNODE_THIS(iface) DEFINE_THIS(HTMLDOMNode, HTMLDOMNode, iface)
283 static HRESULT WINAPI HTMLDOMNode_QueryInterface(IHTMLDOMNode *iface,
284 REFIID riid, void **ppv)
286 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
288 return This->vtbl->qi(This, riid, ppv);
291 static ULONG WINAPI HTMLDOMNode_AddRef(IHTMLDOMNode *iface)
293 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
294 LONG ref = InterlockedIncrement(&This->ref);
296 TRACE("(%p) ref=%d\n", This, ref);
298 return ref;
301 static ULONG WINAPI HTMLDOMNode_Release(IHTMLDOMNode *iface)
303 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
304 LONG ref = InterlockedDecrement(&This->ref);
306 TRACE("(%p) ref=%d\n", This, ref);
308 if(!ref) {
309 This->vtbl->destructor(This);
310 heap_free(This);
313 return ref;
316 static HRESULT WINAPI HTMLDOMNode_GetTypeInfoCount(IHTMLDOMNode *iface, UINT *pctinfo)
318 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
319 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->dispex), pctinfo);
322 static HRESULT WINAPI HTMLDOMNode_GetTypeInfo(IHTMLDOMNode *iface, UINT iTInfo,
323 LCID lcid, ITypeInfo **ppTInfo)
325 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
326 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
329 static HRESULT WINAPI HTMLDOMNode_GetIDsOfNames(IHTMLDOMNode *iface, REFIID riid,
330 LPOLESTR *rgszNames, UINT cNames,
331 LCID lcid, DISPID *rgDispId)
333 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
334 return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->dispex), riid, rgszNames, cNames, lcid, rgDispId);
337 static HRESULT WINAPI HTMLDOMNode_Invoke(IHTMLDOMNode *iface, DISPID dispIdMember,
338 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
339 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
341 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
342 return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid,
343 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
346 static HRESULT WINAPI HTMLDOMNode_get_nodeType(IHTMLDOMNode *iface, LONG *p)
348 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
349 PRUint16 type = -1;
351 TRACE("(%p)->(%p)\n", This, p);
353 nsIDOMNode_GetNodeType(This->nsnode, &type);
355 switch(type) {
356 case ELEMENT_NODE:
357 *p = 1;
358 break;
359 case TEXT_NODE:
360 *p = 3;
361 break;
362 case COMMENT_NODE:
363 *p = 8;
364 break;
365 case DOCUMENT_NODE:
366 *p = 9;
367 break;
368 default:
370 * FIXME:
371 * According to MSDN only ELEMENT_NODE and TEXT_NODE are supported.
372 * It needs more tests.
374 FIXME("type %u\n", type);
375 *p = 0;
378 return S_OK;
381 static HRESULT WINAPI HTMLDOMNode_get_parentNode(IHTMLDOMNode *iface, IHTMLDOMNode **p)
383 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
384 HTMLDOMNode *node;
385 nsIDOMNode *nsnode;
386 nsresult nsres;
388 TRACE("(%p)->(%p)\n", This, p);
390 nsres = nsIDOMNode_GetParentNode(This->nsnode, &nsnode);
391 if(NS_FAILED(nsres)) {
392 ERR("GetParentNode failed: %08x\n", nsres);
393 return E_FAIL;
396 if(!nsnode) {
397 *p = NULL;
398 return S_OK;
401 node = get_node(This->doc, nsnode, TRUE);
402 *p = HTMLDOMNODE(node);
403 IHTMLDOMNode_AddRef(*p);
404 return S_OK;
407 static HRESULT WINAPI HTMLDOMNode_hasChildNodes(IHTMLDOMNode *iface, VARIANT_BOOL *fChildren)
409 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
410 PRBool has_child = FALSE;
411 nsresult nsres;
413 TRACE("(%p)->(%p)\n", This, fChildren);
415 nsres = nsIDOMNode_HasChildNodes(This->nsnode, &has_child);
416 if(NS_FAILED(nsres))
417 ERR("HasChildNodes failed: %08x\n", nsres);
419 *fChildren = has_child ? VARIANT_TRUE : VARIANT_FALSE;
420 return S_OK;
423 static HRESULT WINAPI HTMLDOMNode_get_childNodes(IHTMLDOMNode *iface, IDispatch **p)
425 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
426 nsIDOMNodeList *nslist;
427 nsresult nsres;
429 TRACE("(%p)->(%p)\n", This, p);
431 nsres = nsIDOMNode_GetChildNodes(This->nsnode, &nslist);
432 if(NS_FAILED(nsres)) {
433 ERR("GetChildNodes failed: %08x\n", nsres);
434 return E_FAIL;
437 *p = (IDispatch*)create_child_collection(This->doc, nslist);
438 nsIDOMNodeList_Release(nslist);
440 return S_OK;
443 static HRESULT WINAPI HTMLDOMNode_get_attributes(IHTMLDOMNode *iface, IDispatch **p)
445 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
446 FIXME("(%p)->(%p)\n", This, p);
447 return E_NOTIMPL;
450 static HRESULT WINAPI HTMLDOMNode_insertBefore(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
451 VARIANT refChild, IHTMLDOMNode **node)
453 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
454 nsIDOMNode *nsnode, *nsref = NULL;
455 HTMLDOMNode *new_child;
456 nsresult nsres;
458 TRACE("(%p)->(%p %s %p)\n", This, newChild, debugstr_variant(&refChild), node);
460 new_child = get_node_obj(This->doc, (IUnknown*)newChild);
461 if(!new_child) {
462 ERR("invalid newChild\n");
463 return E_INVALIDARG;
466 switch(V_VT(&refChild)) {
467 case VT_NULL:
468 break;
469 case VT_DISPATCH: {
470 HTMLDOMNode *ref_node;
472 ref_node = get_node_obj(This->doc, (IUnknown*)V_DISPATCH(&refChild));
473 if(!ref_node) {
474 ERR("unvalid node\n");
475 return E_FAIL;
478 nsref = ref_node->nsnode;
479 break;
481 default:
482 FIXME("unimplemented vt %d\n", V_VT(&refChild));
483 return E_NOTIMPL;
486 nsres = nsIDOMNode_InsertBefore(This->nsnode, new_child->nsnode, nsref, &nsnode);
487 if(NS_FAILED(nsres)) {
488 ERR("InsertBefore failed: %08x\n", nsres);
489 return E_FAIL;
492 *node = HTMLDOMNODE(get_node(This->doc, nsnode, TRUE));
493 nsIDOMNode_Release(nsnode);
494 IHTMLDOMNode_AddRef(*node);
495 return S_OK;
498 static HRESULT WINAPI HTMLDOMNode_removeChild(IHTMLDOMNode *iface, IHTMLDOMNode *oldChild,
499 IHTMLDOMNode **node)
501 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
502 HTMLDOMNode *node_obj;
503 nsIDOMNode *nsnode;
504 nsresult nsres;
506 TRACE("(%p)->(%p %p)\n", This, oldChild, node);
508 node_obj = get_node_obj(This->doc, (IUnknown*)oldChild);
509 if(!node_obj)
510 return E_FAIL;
512 nsres = nsIDOMNode_RemoveChild(This->nsnode, node_obj->nsnode, &nsnode);
513 if(NS_FAILED(nsres)) {
514 ERR("RemoveChild failed: %08x\n", nsres);
515 return E_FAIL;
518 /* FIXME: Make sure that node != newChild */
519 *node = HTMLDOMNODE(get_node(This->doc, nsnode, TRUE));
520 nsIDOMNode_Release(nsnode);
521 IHTMLDOMNode_AddRef(*node);
522 return S_OK;
525 static HRESULT WINAPI HTMLDOMNode_replaceChild(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
526 IHTMLDOMNode *oldChild, IHTMLDOMNode **node)
528 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
529 FIXME("(%p)->(%p %p %p)\n", This, newChild, oldChild, node);
530 return E_NOTIMPL;
533 static HRESULT WINAPI HTMLDOMNode_cloneNode(IHTMLDOMNode *iface, VARIANT_BOOL fDeep,
534 IHTMLDOMNode **clonedNode)
536 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
537 FIXME("(%p)->(%x %p)\n", This, fDeep, clonedNode);
538 return E_NOTIMPL;
541 static HRESULT WINAPI HTMLDOMNode_removeNode(IHTMLDOMNode *iface, VARIANT_BOOL fDeep,
542 IHTMLDOMNode **removed)
544 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
545 FIXME("(%p)->(%x %p)\n", This, fDeep, removed);
546 return E_NOTIMPL;
549 static HRESULT WINAPI HTMLDOMNode_swapNode(IHTMLDOMNode *iface, IHTMLDOMNode *otherNode,
550 IHTMLDOMNode **swappedNode)
552 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
553 FIXME("(%p)->(%p %p)\n", This, otherNode, swappedNode);
554 return E_NOTIMPL;
557 static HRESULT WINAPI HTMLDOMNode_replaceNode(IHTMLDOMNode *iface, IHTMLDOMNode *replacement,
558 IHTMLDOMNode **replaced)
560 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
561 FIXME("(%p)->(%p %p)\n", This, replacement, replaced);
562 return E_NOTIMPL;
565 static HRESULT WINAPI HTMLDOMNode_appendChild(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
566 IHTMLDOMNode **node)
568 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
569 HTMLDOMNode *node_obj;
570 nsIDOMNode *nsnode;
571 nsresult nsres;
573 TRACE("(%p)->(%p %p)\n", This, newChild, node);
575 node_obj = get_node_obj(This->doc, (IUnknown*)newChild);
576 if(!node_obj)
577 return E_FAIL;
579 nsres = nsIDOMNode_AppendChild(This->nsnode, node_obj->nsnode, &nsnode);
580 if(NS_FAILED(nsres)) {
581 WARN("AppendChild failed: %08x\n", nsres);
582 nsnode = node_obj->nsnode;
585 /* FIXME: Make sure that node != newChild */
586 *node = HTMLDOMNODE(get_node(This->doc, nsnode, TRUE));
587 IHTMLDOMNode_AddRef(*node);
588 return S_OK;
591 static HRESULT WINAPI HTMLDOMNode_get_nodeName(IHTMLDOMNode *iface, BSTR *p)
593 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
595 TRACE("(%p)->(%p)\n", This, p);
597 *p = NULL;
599 if(This->nsnode) {
600 nsAString name_str;
601 const PRUnichar *name;
602 nsresult nsres;
604 nsAString_Init(&name_str, NULL);
605 nsres = nsIDOMNode_GetNodeName(This->nsnode, &name_str);
607 if(NS_SUCCEEDED(nsres)) {
608 nsAString_GetData(&name_str, &name);
609 *p = SysAllocString(name);
610 }else {
611 ERR("GetNodeName failed: %08x\n", nsres);
614 nsAString_Finish(&name_str);
617 return S_OK;
620 static HRESULT WINAPI HTMLDOMNode_put_nodeValue(IHTMLDOMNode *iface, VARIANT v)
622 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
624 TRACE("(%p)->()\n", This);
626 switch(V_VT(&v)) {
627 case VT_BSTR: {
628 nsAString val_str;
630 TRACE("bstr %s\n", debugstr_w(V_BSTR(&v)));
632 nsAString_Init(&val_str, V_BSTR(&v));
633 nsIDOMNode_SetNodeValue(This->nsnode, &val_str);
634 nsAString_Finish(&val_str);
636 return S_OK;
639 default:
640 FIXME("unsupported vt %d\n", V_VT(&v));
643 return E_NOTIMPL;
646 static HRESULT WINAPI HTMLDOMNode_get_nodeValue(IHTMLDOMNode *iface, VARIANT *p)
648 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
649 const PRUnichar *val;
650 nsAString val_str;
652 TRACE("(%p)->(%p)\n", This, p);
654 nsAString_Init(&val_str, NULL);
655 nsIDOMNode_GetNodeValue(This->nsnode, &val_str);
656 nsAString_GetData(&val_str, &val);
658 if(*val) {
659 V_VT(p) = VT_BSTR;
660 V_BSTR(p) = SysAllocString(val);
661 }else {
662 V_VT(p) = VT_NULL;
665 nsAString_Finish(&val_str);
667 return S_OK;
670 static HRESULT WINAPI HTMLDOMNode_get_firstChild(IHTMLDOMNode *iface, IHTMLDOMNode **p)
672 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
673 nsIDOMNode *nschild = NULL;
675 TRACE("(%p)->(%p)\n", This, p);
677 nsIDOMNode_GetFirstChild(This->nsnode, &nschild);
678 if(nschild) {
679 *p = HTMLDOMNODE(get_node(This->doc, nschild, TRUE));
680 IHTMLDOMNode_AddRef(*p);
681 }else {
682 *p = NULL;
685 return S_OK;
688 static HRESULT WINAPI HTMLDOMNode_get_lastChild(IHTMLDOMNode *iface, IHTMLDOMNode **p)
690 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
691 nsIDOMNode *nschild = NULL;
693 TRACE("(%p)->(%p)\n", This, p);
695 nsIDOMNode_GetLastChild(This->nsnode, &nschild);
696 if(nschild) {
697 *p = HTMLDOMNODE(get_node(This->doc, nschild, TRUE));
698 IHTMLDOMNode_AddRef(*p);
699 }else {
700 *p = NULL;
703 return S_OK;
706 static HRESULT WINAPI HTMLDOMNode_get_previousSibling(IHTMLDOMNode *iface, IHTMLDOMNode **p)
708 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
709 FIXME("(%p)->(%p)\n", This, p);
710 return E_NOTIMPL;
713 static HRESULT WINAPI HTMLDOMNode_get_nextSibling(IHTMLDOMNode *iface, IHTMLDOMNode **p)
715 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
716 FIXME("(%p)->(%p)\n", This, p);
717 return E_NOTIMPL;
720 #undef HTMLDOMNODE_THIS
722 static const IHTMLDOMNodeVtbl HTMLDOMNodeVtbl = {
723 HTMLDOMNode_QueryInterface,
724 HTMLDOMNode_AddRef,
725 HTMLDOMNode_Release,
726 HTMLDOMNode_GetTypeInfoCount,
727 HTMLDOMNode_GetTypeInfo,
728 HTMLDOMNode_GetIDsOfNames,
729 HTMLDOMNode_Invoke,
730 HTMLDOMNode_get_nodeType,
731 HTMLDOMNode_get_parentNode,
732 HTMLDOMNode_hasChildNodes,
733 HTMLDOMNode_get_childNodes,
734 HTMLDOMNode_get_attributes,
735 HTMLDOMNode_insertBefore,
736 HTMLDOMNode_removeChild,
737 HTMLDOMNode_replaceChild,
738 HTMLDOMNode_cloneNode,
739 HTMLDOMNode_removeNode,
740 HTMLDOMNode_swapNode,
741 HTMLDOMNode_replaceNode,
742 HTMLDOMNode_appendChild,
743 HTMLDOMNode_get_nodeName,
744 HTMLDOMNode_put_nodeValue,
745 HTMLDOMNode_get_nodeValue,
746 HTMLDOMNode_get_firstChild,
747 HTMLDOMNode_get_lastChild,
748 HTMLDOMNode_get_previousSibling,
749 HTMLDOMNode_get_nextSibling
752 #define HTMLDOMNODE2_THIS(iface) DEFINE_THIS(HTMLDOMNode, HTMLDOMNode2, iface)
754 static HRESULT WINAPI HTMLDOMNode2_QueryInterface(IHTMLDOMNode2 *iface,
755 REFIID riid, void **ppv)
757 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
759 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(This), riid, ppv);
762 static ULONG WINAPI HTMLDOMNode2_AddRef(IHTMLDOMNode2 *iface)
764 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
766 return IHTMLDOMNode_AddRef(HTMLDOMNODE(This));
769 static ULONG WINAPI HTMLDOMNode2_Release(IHTMLDOMNode2 *iface)
771 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
773 return IHTMLDOMNode_Release(HTMLDOMNODE(This));
776 static HRESULT WINAPI HTMLDOMNode2_GetTypeInfoCount(IHTMLDOMNode2 *iface, UINT *pctinfo)
778 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
779 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->dispex), pctinfo);
782 static HRESULT WINAPI HTMLDOMNode2_GetTypeInfo(IHTMLDOMNode2 *iface, UINT iTInfo,
783 LCID lcid, ITypeInfo **ppTInfo)
785 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
786 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
789 static HRESULT WINAPI HTMLDOMNode2_GetIDsOfNames(IHTMLDOMNode2 *iface, REFIID riid,
790 LPOLESTR *rgszNames, UINT cNames,
791 LCID lcid, DISPID *rgDispId)
793 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
794 return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->dispex), riid, rgszNames, cNames, lcid, rgDispId);
797 static HRESULT WINAPI HTMLDOMNode2_Invoke(IHTMLDOMNode2 *iface, DISPID dispIdMember,
798 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
799 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
801 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
802 return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid,
803 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
806 static HRESULT WINAPI HTMLDOMNode2_get_ownerDocument(IHTMLDOMNode2 *iface, IDispatch **p)
808 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
809 FIXME("(%p)->(%p)\n", This, p);
810 return E_NOTIMPL;
813 #undef HTMLDOMNODE2_THIS
815 static const IHTMLDOMNode2Vtbl HTMLDOMNode2Vtbl = {
816 HTMLDOMNode2_QueryInterface,
817 HTMLDOMNode2_AddRef,
818 HTMLDOMNode2_Release,
819 HTMLDOMNode2_GetTypeInfoCount,
820 HTMLDOMNode2_GetTypeInfo,
821 HTMLDOMNode2_GetIDsOfNames,
822 HTMLDOMNode2_Invoke,
823 HTMLDOMNode2_get_ownerDocument
826 HRESULT HTMLDOMNode_QI(HTMLDOMNode *This, REFIID riid, void **ppv)
828 *ppv = NULL;
830 if(IsEqualGUID(&IID_IUnknown, riid)) {
831 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
832 *ppv = HTMLDOMNODE(This);
833 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
834 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
835 *ppv = HTMLDOMNODE(This);
836 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
837 if(This->dispex.data) {
838 TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
839 *ppv = DISPATCHEX(&This->dispex);
840 }else {
841 FIXME("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
842 return E_NOINTERFACE;
844 }else if(IsEqualGUID(&IID_IHTMLDOMNode, riid)) {
845 TRACE("(%p)->(IID_IHTMLDOMNode %p)\n", This, ppv);
846 *ppv = HTMLDOMNODE(This);
847 }else if(IsEqualGUID(&IID_IHTMLDOMNode2, riid)) {
848 TRACE("(%p)->(IID_IHTMLDOMNode2 %p)\n", This, ppv);
849 *ppv = HTMLDOMNODE2(This);
850 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
851 return *ppv ? S_OK : E_NOINTERFACE;
854 if(*ppv) {
855 IUnknown_AddRef((IUnknown*)*ppv);
856 return S_OK;
859 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
860 return E_NOINTERFACE;
863 void HTMLDOMNode_destructor(HTMLDOMNode *This)
865 if(This->nsnode)
866 nsIDOMNode_Release(This->nsnode);
867 if(This->event_target)
868 release_event_target(This->event_target);
871 static const NodeImplVtbl HTMLDOMNodeImplVtbl = {
872 HTMLDOMNode_QI,
873 HTMLDOMNode_destructor
876 void HTMLDOMNode_Init(HTMLDocument *doc, HTMLDOMNode *node, nsIDOMNode *nsnode)
878 node->lpHTMLDOMNodeVtbl = &HTMLDOMNodeVtbl;
879 node->lpHTMLDOMNode2Vtbl = &HTMLDOMNode2Vtbl;
880 node->ref = 1;
881 node->doc = doc;
883 nsIDOMNode_AddRef(nsnode);
884 node->nsnode = nsnode;
886 node->next = doc->nodes;
887 doc->nodes = node;
890 static HTMLDOMNode *create_node(HTMLDocument *doc, nsIDOMNode *nsnode)
892 HTMLDOMNode *ret;
893 PRUint16 node_type;
895 nsIDOMNode_GetNodeType(nsnode, &node_type);
897 switch(node_type) {
898 case ELEMENT_NODE:
899 ret = &HTMLElement_Create(doc, nsnode, FALSE)->node;
900 break;
901 case TEXT_NODE:
902 ret = HTMLDOMTextNode_Create(doc, nsnode);
903 break;
904 case COMMENT_NODE:
905 ret = &HTMLCommentElement_Create(doc, nsnode)->node;
906 break;
907 default:
908 ret = heap_alloc_zero(sizeof(HTMLDOMNode));
909 ret->vtbl = &HTMLDOMNodeImplVtbl;
910 HTMLDOMNode_Init(doc, ret, nsnode);
913 TRACE("type %d ret %p\n", node_type, ret);
915 return ret;
919 * FIXME
920 * List looks really ugly here. We should use a better data structure or
921 * (better) find a way to store HTMLDOMelement pointer in nsIDOMNode.
924 HTMLDOMNode *get_node(HTMLDocument *This, nsIDOMNode *nsnode, BOOL create)
926 HTMLDOMNode *iter = This->nodes;
928 while(iter) {
929 if(iter->nsnode == nsnode)
930 break;
931 iter = iter->next;
934 if(iter || !create)
935 return iter;
937 return create_node(This, nsnode);
941 * FIXME
942 * We should use better way for getting node object (like private interface)
943 * or avoid it at all.
945 static HTMLDOMNode *get_node_obj(HTMLDocument *This, IUnknown *iface)
947 HTMLDOMNode *iter = This->nodes;
948 IHTMLDOMNode *node;
950 IUnknown_QueryInterface(iface, &IID_IHTMLDOMNode, (void**)&node);
951 IHTMLDOMNode_Release(node);
953 while(iter) {
954 if(HTMLDOMNODE(iter) == node)
955 return iter;
956 iter = iter->next;
959 FIXME("Not found %p\n", iface);
960 return NULL;
963 void release_nodes(HTMLDocument *This)
965 HTMLDOMNode *iter, *next;
967 if(!This->nodes)
968 return;
970 for(iter = This->nodes; iter; iter = next) {
971 next = iter->next;
972 iter->doc = NULL;
973 IHTMLDOMNode_Release(HTMLDOMNODE(iter));