msctf: Correct handling if NULL for pdimFocus in ITfThreadMgr::SetFocus.
[wine/multimedia.git] / dlls / mshtml / htmlnode.c
blob30fdac871620d57322c73c51d9f6fd7ef2210a31
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 NULL,
254 HTMLDOMChildrenCollection_get_dispid,
255 HTMLDOMChildrenCollection_invoke
258 static dispex_static_data_t HTMLDOMChildrenCollection_dispex = {
259 &HTMLDOMChildrenCollection_dispex_vtbl,
260 DispDOMChildrenCollection_tid,
261 NULL,
262 HTMLDOMChildrenCollection_iface_tids
265 static IHTMLDOMChildrenCollection *create_child_collection(HTMLDocument *doc, nsIDOMNodeList *nslist)
267 HTMLDOMChildrenCollection *ret;
269 ret = heap_alloc_zero(sizeof(*ret));
270 ret->lpIHTMLDOMChildrenCollectionVtbl = &HTMLDOMChildrenCollectionVtbl;
271 ret->ref = 1;
273 nsIDOMNodeList_AddRef(nslist);
274 ret->nslist = nslist;
275 ret->doc = doc;
277 init_dispex(&ret->dispex, (IUnknown*)HTMLCHILDCOL(ret), &HTMLDOMChildrenCollection_dispex);
279 return HTMLCHILDCOL(ret);
282 #define HTMLDOMNODE_THIS(iface) DEFINE_THIS(HTMLDOMNode, HTMLDOMNode, iface)
284 static HRESULT WINAPI HTMLDOMNode_QueryInterface(IHTMLDOMNode *iface,
285 REFIID riid, void **ppv)
287 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
289 return This->vtbl->qi(This, riid, ppv);
292 static ULONG WINAPI HTMLDOMNode_AddRef(IHTMLDOMNode *iface)
294 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
295 LONG ref = InterlockedIncrement(&This->ref);
297 TRACE("(%p) ref=%d\n", This, ref);
299 return ref;
302 static ULONG WINAPI HTMLDOMNode_Release(IHTMLDOMNode *iface)
304 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
305 LONG ref = InterlockedDecrement(&This->ref);
307 TRACE("(%p) ref=%d\n", This, ref);
309 if(!ref) {
310 This->vtbl->destructor(This);
311 release_dispex(&This->dispex);
312 heap_free(This);
315 return ref;
318 static HRESULT WINAPI HTMLDOMNode_GetTypeInfoCount(IHTMLDOMNode *iface, UINT *pctinfo)
320 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
321 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->dispex), pctinfo);
324 static HRESULT WINAPI HTMLDOMNode_GetTypeInfo(IHTMLDOMNode *iface, UINT iTInfo,
325 LCID lcid, ITypeInfo **ppTInfo)
327 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
328 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
331 static HRESULT WINAPI HTMLDOMNode_GetIDsOfNames(IHTMLDOMNode *iface, REFIID riid,
332 LPOLESTR *rgszNames, UINT cNames,
333 LCID lcid, DISPID *rgDispId)
335 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
336 return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->dispex), riid, rgszNames, cNames, lcid, rgDispId);
339 static HRESULT WINAPI HTMLDOMNode_Invoke(IHTMLDOMNode *iface, DISPID dispIdMember,
340 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
341 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
343 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
344 return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid,
345 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
348 static HRESULT WINAPI HTMLDOMNode_get_nodeType(IHTMLDOMNode *iface, LONG *p)
350 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
351 PRUint16 type = -1;
353 TRACE("(%p)->(%p)\n", This, p);
355 nsIDOMNode_GetNodeType(This->nsnode, &type);
357 switch(type) {
358 case ELEMENT_NODE:
359 *p = 1;
360 break;
361 case TEXT_NODE:
362 *p = 3;
363 break;
364 case COMMENT_NODE:
365 *p = 8;
366 break;
367 case DOCUMENT_NODE:
368 *p = 9;
369 break;
370 default:
372 * FIXME:
373 * According to MSDN only ELEMENT_NODE and TEXT_NODE are supported.
374 * It needs more tests.
376 FIXME("type %u\n", type);
377 *p = 0;
380 return S_OK;
383 static HRESULT WINAPI HTMLDOMNode_get_parentNode(IHTMLDOMNode *iface, IHTMLDOMNode **p)
385 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
386 HTMLDOMNode *node;
387 nsIDOMNode *nsnode;
388 nsresult nsres;
390 TRACE("(%p)->(%p)\n", This, p);
392 nsres = nsIDOMNode_GetParentNode(This->nsnode, &nsnode);
393 if(NS_FAILED(nsres)) {
394 ERR("GetParentNode failed: %08x\n", nsres);
395 return E_FAIL;
398 if(!nsnode) {
399 *p = NULL;
400 return S_OK;
403 node = get_node(This->doc, nsnode, TRUE);
404 *p = HTMLDOMNODE(node);
405 IHTMLDOMNode_AddRef(*p);
406 return S_OK;
409 static HRESULT WINAPI HTMLDOMNode_hasChildNodes(IHTMLDOMNode *iface, VARIANT_BOOL *fChildren)
411 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
412 PRBool has_child = FALSE;
413 nsresult nsres;
415 TRACE("(%p)->(%p)\n", This, fChildren);
417 nsres = nsIDOMNode_HasChildNodes(This->nsnode, &has_child);
418 if(NS_FAILED(nsres))
419 ERR("HasChildNodes failed: %08x\n", nsres);
421 *fChildren = has_child ? VARIANT_TRUE : VARIANT_FALSE;
422 return S_OK;
425 static HRESULT WINAPI HTMLDOMNode_get_childNodes(IHTMLDOMNode *iface, IDispatch **p)
427 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
428 nsIDOMNodeList *nslist;
429 nsresult nsres;
431 TRACE("(%p)->(%p)\n", This, p);
433 nsres = nsIDOMNode_GetChildNodes(This->nsnode, &nslist);
434 if(NS_FAILED(nsres)) {
435 ERR("GetChildNodes failed: %08x\n", nsres);
436 return E_FAIL;
439 *p = (IDispatch*)create_child_collection(This->doc, nslist);
440 nsIDOMNodeList_Release(nslist);
442 return S_OK;
445 static HRESULT WINAPI HTMLDOMNode_get_attributes(IHTMLDOMNode *iface, IDispatch **p)
447 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
448 FIXME("(%p)->(%p)\n", This, p);
449 return E_NOTIMPL;
452 static HRESULT WINAPI HTMLDOMNode_insertBefore(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
453 VARIANT refChild, IHTMLDOMNode **node)
455 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
456 nsIDOMNode *nsnode, *nsref = NULL;
457 HTMLDOMNode *new_child;
458 nsresult nsres;
460 TRACE("(%p)->(%p %s %p)\n", This, newChild, debugstr_variant(&refChild), node);
462 new_child = get_node_obj(This->doc, (IUnknown*)newChild);
463 if(!new_child) {
464 ERR("invalid newChild\n");
465 return E_INVALIDARG;
468 switch(V_VT(&refChild)) {
469 case VT_NULL:
470 break;
471 case VT_DISPATCH: {
472 HTMLDOMNode *ref_node;
474 ref_node = get_node_obj(This->doc, (IUnknown*)V_DISPATCH(&refChild));
475 if(!ref_node) {
476 ERR("unvalid node\n");
477 return E_FAIL;
480 nsref = ref_node->nsnode;
481 break;
483 default:
484 FIXME("unimplemented vt %d\n", V_VT(&refChild));
485 return E_NOTIMPL;
488 nsres = nsIDOMNode_InsertBefore(This->nsnode, new_child->nsnode, nsref, &nsnode);
489 if(NS_FAILED(nsres)) {
490 ERR("InsertBefore failed: %08x\n", nsres);
491 return E_FAIL;
494 *node = HTMLDOMNODE(get_node(This->doc, nsnode, TRUE));
495 nsIDOMNode_Release(nsnode);
496 IHTMLDOMNode_AddRef(*node);
497 return S_OK;
500 static HRESULT WINAPI HTMLDOMNode_removeChild(IHTMLDOMNode *iface, IHTMLDOMNode *oldChild,
501 IHTMLDOMNode **node)
503 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
504 HTMLDOMNode *node_obj;
505 nsIDOMNode *nsnode;
506 nsresult nsres;
508 TRACE("(%p)->(%p %p)\n", This, oldChild, node);
510 node_obj = get_node_obj(This->doc, (IUnknown*)oldChild);
511 if(!node_obj)
512 return E_FAIL;
514 nsres = nsIDOMNode_RemoveChild(This->nsnode, node_obj->nsnode, &nsnode);
515 if(NS_FAILED(nsres)) {
516 ERR("RemoveChild failed: %08x\n", nsres);
517 return E_FAIL;
520 /* FIXME: Make sure that node != newChild */
521 *node = HTMLDOMNODE(get_node(This->doc, nsnode, TRUE));
522 nsIDOMNode_Release(nsnode);
523 IHTMLDOMNode_AddRef(*node);
524 return S_OK;
527 static HRESULT WINAPI HTMLDOMNode_replaceChild(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
528 IHTMLDOMNode *oldChild, IHTMLDOMNode **node)
530 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
531 FIXME("(%p)->(%p %p %p)\n", This, newChild, oldChild, node);
532 return E_NOTIMPL;
535 static HRESULT WINAPI HTMLDOMNode_cloneNode(IHTMLDOMNode *iface, VARIANT_BOOL fDeep,
536 IHTMLDOMNode **clonedNode)
538 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
539 FIXME("(%p)->(%x %p)\n", This, fDeep, clonedNode);
540 return E_NOTIMPL;
543 static HRESULT WINAPI HTMLDOMNode_removeNode(IHTMLDOMNode *iface, VARIANT_BOOL fDeep,
544 IHTMLDOMNode **removed)
546 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
547 FIXME("(%p)->(%x %p)\n", This, fDeep, removed);
548 return E_NOTIMPL;
551 static HRESULT WINAPI HTMLDOMNode_swapNode(IHTMLDOMNode *iface, IHTMLDOMNode *otherNode,
552 IHTMLDOMNode **swappedNode)
554 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
555 FIXME("(%p)->(%p %p)\n", This, otherNode, swappedNode);
556 return E_NOTIMPL;
559 static HRESULT WINAPI HTMLDOMNode_replaceNode(IHTMLDOMNode *iface, IHTMLDOMNode *replacement,
560 IHTMLDOMNode **replaced)
562 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
563 FIXME("(%p)->(%p %p)\n", This, replacement, replaced);
564 return E_NOTIMPL;
567 static HRESULT WINAPI HTMLDOMNode_appendChild(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
568 IHTMLDOMNode **node)
570 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
571 HTMLDOMNode *node_obj;
572 nsIDOMNode *nsnode;
573 nsresult nsres;
575 TRACE("(%p)->(%p %p)\n", This, newChild, node);
577 node_obj = get_node_obj(This->doc, (IUnknown*)newChild);
578 if(!node_obj)
579 return E_FAIL;
581 nsres = nsIDOMNode_AppendChild(This->nsnode, node_obj->nsnode, &nsnode);
582 if(NS_FAILED(nsres)) {
583 WARN("AppendChild failed: %08x\n", nsres);
584 nsnode = node_obj->nsnode;
587 /* FIXME: Make sure that node != newChild */
588 *node = HTMLDOMNODE(get_node(This->doc, nsnode, TRUE));
589 IHTMLDOMNode_AddRef(*node);
590 return S_OK;
593 static HRESULT WINAPI HTMLDOMNode_get_nodeName(IHTMLDOMNode *iface, BSTR *p)
595 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
597 TRACE("(%p)->(%p)\n", This, p);
599 *p = NULL;
601 if(This->nsnode) {
602 nsAString name_str;
603 const PRUnichar *name;
604 nsresult nsres;
606 nsAString_Init(&name_str, NULL);
607 nsres = nsIDOMNode_GetNodeName(This->nsnode, &name_str);
609 if(NS_SUCCEEDED(nsres)) {
610 nsAString_GetData(&name_str, &name);
611 *p = SysAllocString(name);
612 }else {
613 ERR("GetNodeName failed: %08x\n", nsres);
616 nsAString_Finish(&name_str);
619 return S_OK;
622 static HRESULT WINAPI HTMLDOMNode_put_nodeValue(IHTMLDOMNode *iface, VARIANT v)
624 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
626 TRACE("(%p)->()\n", This);
628 switch(V_VT(&v)) {
629 case VT_BSTR: {
630 nsAString val_str;
632 TRACE("bstr %s\n", debugstr_w(V_BSTR(&v)));
634 nsAString_Init(&val_str, V_BSTR(&v));
635 nsIDOMNode_SetNodeValue(This->nsnode, &val_str);
636 nsAString_Finish(&val_str);
638 return S_OK;
641 default:
642 FIXME("unsupported vt %d\n", V_VT(&v));
645 return E_NOTIMPL;
648 static HRESULT WINAPI HTMLDOMNode_get_nodeValue(IHTMLDOMNode *iface, VARIANT *p)
650 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
651 const PRUnichar *val;
652 nsAString val_str;
654 TRACE("(%p)->(%p)\n", This, p);
656 nsAString_Init(&val_str, NULL);
657 nsIDOMNode_GetNodeValue(This->nsnode, &val_str);
658 nsAString_GetData(&val_str, &val);
660 if(*val) {
661 V_VT(p) = VT_BSTR;
662 V_BSTR(p) = SysAllocString(val);
663 }else {
664 V_VT(p) = VT_NULL;
667 nsAString_Finish(&val_str);
669 return S_OK;
672 static HRESULT WINAPI HTMLDOMNode_get_firstChild(IHTMLDOMNode *iface, IHTMLDOMNode **p)
674 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
675 nsIDOMNode *nschild = NULL;
677 TRACE("(%p)->(%p)\n", This, p);
679 nsIDOMNode_GetFirstChild(This->nsnode, &nschild);
680 if(nschild) {
681 *p = HTMLDOMNODE(get_node(This->doc, nschild, TRUE));
682 IHTMLDOMNode_AddRef(*p);
683 }else {
684 *p = NULL;
687 return S_OK;
690 static HRESULT WINAPI HTMLDOMNode_get_lastChild(IHTMLDOMNode *iface, IHTMLDOMNode **p)
692 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
693 nsIDOMNode *nschild = NULL;
695 TRACE("(%p)->(%p)\n", This, p);
697 nsIDOMNode_GetLastChild(This->nsnode, &nschild);
698 if(nschild) {
699 *p = HTMLDOMNODE(get_node(This->doc, nschild, TRUE));
700 IHTMLDOMNode_AddRef(*p);
701 }else {
702 *p = NULL;
705 return S_OK;
708 static HRESULT WINAPI HTMLDOMNode_get_previousSibling(IHTMLDOMNode *iface, IHTMLDOMNode **p)
710 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
711 FIXME("(%p)->(%p)\n", This, p);
712 return E_NOTIMPL;
715 static HRESULT WINAPI HTMLDOMNode_get_nextSibling(IHTMLDOMNode *iface, IHTMLDOMNode **p)
717 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
718 FIXME("(%p)->(%p)\n", This, p);
719 return E_NOTIMPL;
722 #undef HTMLDOMNODE_THIS
724 static const IHTMLDOMNodeVtbl HTMLDOMNodeVtbl = {
725 HTMLDOMNode_QueryInterface,
726 HTMLDOMNode_AddRef,
727 HTMLDOMNode_Release,
728 HTMLDOMNode_GetTypeInfoCount,
729 HTMLDOMNode_GetTypeInfo,
730 HTMLDOMNode_GetIDsOfNames,
731 HTMLDOMNode_Invoke,
732 HTMLDOMNode_get_nodeType,
733 HTMLDOMNode_get_parentNode,
734 HTMLDOMNode_hasChildNodes,
735 HTMLDOMNode_get_childNodes,
736 HTMLDOMNode_get_attributes,
737 HTMLDOMNode_insertBefore,
738 HTMLDOMNode_removeChild,
739 HTMLDOMNode_replaceChild,
740 HTMLDOMNode_cloneNode,
741 HTMLDOMNode_removeNode,
742 HTMLDOMNode_swapNode,
743 HTMLDOMNode_replaceNode,
744 HTMLDOMNode_appendChild,
745 HTMLDOMNode_get_nodeName,
746 HTMLDOMNode_put_nodeValue,
747 HTMLDOMNode_get_nodeValue,
748 HTMLDOMNode_get_firstChild,
749 HTMLDOMNode_get_lastChild,
750 HTMLDOMNode_get_previousSibling,
751 HTMLDOMNode_get_nextSibling
754 #define HTMLDOMNODE2_THIS(iface) DEFINE_THIS(HTMLDOMNode, HTMLDOMNode2, iface)
756 static HRESULT WINAPI HTMLDOMNode2_QueryInterface(IHTMLDOMNode2 *iface,
757 REFIID riid, void **ppv)
759 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
761 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(This), riid, ppv);
764 static ULONG WINAPI HTMLDOMNode2_AddRef(IHTMLDOMNode2 *iface)
766 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
768 return IHTMLDOMNode_AddRef(HTMLDOMNODE(This));
771 static ULONG WINAPI HTMLDOMNode2_Release(IHTMLDOMNode2 *iface)
773 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
775 return IHTMLDOMNode_Release(HTMLDOMNODE(This));
778 static HRESULT WINAPI HTMLDOMNode2_GetTypeInfoCount(IHTMLDOMNode2 *iface, UINT *pctinfo)
780 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
781 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->dispex), pctinfo);
784 static HRESULT WINAPI HTMLDOMNode2_GetTypeInfo(IHTMLDOMNode2 *iface, UINT iTInfo,
785 LCID lcid, ITypeInfo **ppTInfo)
787 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
788 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
791 static HRESULT WINAPI HTMLDOMNode2_GetIDsOfNames(IHTMLDOMNode2 *iface, REFIID riid,
792 LPOLESTR *rgszNames, UINT cNames,
793 LCID lcid, DISPID *rgDispId)
795 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
796 return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->dispex), riid, rgszNames, cNames, lcid, rgDispId);
799 static HRESULT WINAPI HTMLDOMNode2_Invoke(IHTMLDOMNode2 *iface, DISPID dispIdMember,
800 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
801 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
803 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
804 return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid,
805 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
808 static HRESULT WINAPI HTMLDOMNode2_get_ownerDocument(IHTMLDOMNode2 *iface, IDispatch **p)
810 HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
811 FIXME("(%p)->(%p)\n", This, p);
812 return E_NOTIMPL;
815 #undef HTMLDOMNODE2_THIS
817 static const IHTMLDOMNode2Vtbl HTMLDOMNode2Vtbl = {
818 HTMLDOMNode2_QueryInterface,
819 HTMLDOMNode2_AddRef,
820 HTMLDOMNode2_Release,
821 HTMLDOMNode2_GetTypeInfoCount,
822 HTMLDOMNode2_GetTypeInfo,
823 HTMLDOMNode2_GetIDsOfNames,
824 HTMLDOMNode2_Invoke,
825 HTMLDOMNode2_get_ownerDocument
828 HRESULT HTMLDOMNode_QI(HTMLDOMNode *This, REFIID riid, void **ppv)
830 *ppv = NULL;
832 if(IsEqualGUID(&IID_IUnknown, riid)) {
833 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
834 *ppv = HTMLDOMNODE(This);
835 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
836 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
837 *ppv = HTMLDOMNODE(This);
838 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
839 if(This->dispex.data) {
840 TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
841 *ppv = DISPATCHEX(&This->dispex);
842 }else {
843 FIXME("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
844 return E_NOINTERFACE;
846 }else if(IsEqualGUID(&IID_IHTMLDOMNode, riid)) {
847 TRACE("(%p)->(IID_IHTMLDOMNode %p)\n", This, ppv);
848 *ppv = HTMLDOMNODE(This);
849 }else if(IsEqualGUID(&IID_IHTMLDOMNode2, riid)) {
850 TRACE("(%p)->(IID_IHTMLDOMNode2 %p)\n", This, ppv);
851 *ppv = HTMLDOMNODE2(This);
852 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
853 return *ppv ? S_OK : E_NOINTERFACE;
856 if(*ppv) {
857 IUnknown_AddRef((IUnknown*)*ppv);
858 return S_OK;
861 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
862 return E_NOINTERFACE;
865 void HTMLDOMNode_destructor(HTMLDOMNode *This)
867 if(This->nsnode)
868 nsIDOMNode_Release(This->nsnode);
869 if(This->event_target)
870 release_event_target(This->event_target);
873 static const NodeImplVtbl HTMLDOMNodeImplVtbl = {
874 HTMLDOMNode_QI,
875 HTMLDOMNode_destructor
878 void HTMLDOMNode_Init(HTMLDocument *doc, HTMLDOMNode *node, nsIDOMNode *nsnode)
880 node->lpHTMLDOMNodeVtbl = &HTMLDOMNodeVtbl;
881 node->lpHTMLDOMNode2Vtbl = &HTMLDOMNode2Vtbl;
882 node->ref = 1;
883 node->doc = doc;
885 nsIDOMNode_AddRef(nsnode);
886 node->nsnode = nsnode;
888 node->next = doc->nodes;
889 doc->nodes = node;
892 static HTMLDOMNode *create_node(HTMLDocument *doc, nsIDOMNode *nsnode)
894 HTMLDOMNode *ret;
895 PRUint16 node_type;
897 nsIDOMNode_GetNodeType(nsnode, &node_type);
899 switch(node_type) {
900 case ELEMENT_NODE:
901 ret = &HTMLElement_Create(doc, nsnode, FALSE)->node;
902 break;
903 case TEXT_NODE:
904 ret = HTMLDOMTextNode_Create(doc, nsnode);
905 break;
906 case COMMENT_NODE:
907 ret = &HTMLCommentElement_Create(doc, nsnode)->node;
908 break;
909 default:
910 ret = heap_alloc_zero(sizeof(HTMLDOMNode));
911 ret->vtbl = &HTMLDOMNodeImplVtbl;
912 HTMLDOMNode_Init(doc, ret, nsnode);
915 TRACE("type %d ret %p\n", node_type, ret);
917 return ret;
921 * FIXME
922 * List looks really ugly here. We should use a better data structure or
923 * (better) find a way to store HTMLDOMelement pointer in nsIDOMNode.
926 HTMLDOMNode *get_node(HTMLDocument *This, nsIDOMNode *nsnode, BOOL create)
928 HTMLDOMNode *iter = This->nodes;
930 while(iter) {
931 if(iter->nsnode == nsnode)
932 break;
933 iter = iter->next;
936 if(iter || !create)
937 return iter;
939 return create_node(This, nsnode);
943 * FIXME
944 * We should use better way for getting node object (like private interface)
945 * or avoid it at all.
947 static HTMLDOMNode *get_node_obj(HTMLDocument *This, IUnknown *iface)
949 HTMLDOMNode *iter = This->nodes;
950 IHTMLDOMNode *node;
952 IUnknown_QueryInterface(iface, &IID_IHTMLDOMNode, (void**)&node);
953 IHTMLDOMNode_Release(node);
955 while(iter) {
956 if(HTMLDOMNODE(iter) == node)
957 return iter;
958 iter = iter->next;
961 FIXME("Not found %p\n", iface);
962 return NULL;
965 void release_nodes(HTMLDocument *This)
967 HTMLDOMNode *iter, *next;
969 if(!This->nodes)
970 return;
972 for(iter = This->nodes; iter; iter = next) {
973 next = iter->next;
974 iter->doc = NULL;
975 IHTMLDOMNode_Release(HTMLDOMNODE(iter));