~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/mshtml/htmlnode.c

Version: ~ [ wine-1.5.30 ] ~ [ wine-1.5.29 ] ~ [ wine-1.5.28 ] ~ [ wine-1.5.27 ] ~ [ wine-1.5.26 ] ~ [ wine-1.5.25 ] ~ [ wine-1.5.24 ] ~ [ wine-1.5.23 ] ~ [ wine-1.5.22 ] ~ [ wine-1.5.21 ] ~ [ wine-1.5.20 ] ~ [ wine-1.5.19 ] ~ [ wine-1.5.18 ] ~ [ wine-1.5.17 ] ~ [ wine-1.5.16 ] ~ [ wine-1.5.15 ] ~ [ wine-1.5.14 ] ~ [ wine-1.5.13 ] ~ [ wine-1.5.12 ] ~ [ wine-1.5.11 ] ~ [ wine-1.5.10 ] ~ [ wine-1.5.9 ] ~ [ wine-1.5.8 ] ~ [ wine-1.5.7 ] ~ [ wine-1.4.1 ] ~ [ wine-1.5.6 ] ~ [ wine-1.5.5 ] ~ [ wine-1.5.4 ] ~ [ wine-1.5.3 ] ~ [ wine-1.5.2 ] ~ [ wine-1.5.1 ] ~ [ wine-1.5.0 ] ~ [ wine-1.4 ] ~ [ wine-1.4-rc6 ] ~ [ wine-1.4-rc5 ] ~ [ wine-1.4-rc4 ] ~ [ wine-1.4-rc3 ] ~ [ wine-1.4-rc2 ] ~ [ wine-1.4-rc1 ] ~ [ wine-1.3.37 ] ~ [ wine-1.3.36 ] ~ [ wine-1.3.35 ] ~ [ wine-1.3.34 ] ~ [ wine-1.3.33 ] ~ [ wine-1.3.32 ] ~ [ wine-1.3.31 ] ~ [ wine-1.3.30 ] ~ [ wine-1.3.29 ] ~ [ wine-1.3.28 ] ~ [ wine-1.3.27 ] ~ [ wine-1.3.26 ] ~ [ wine-1.3.25 ] ~ [ wine-1.3.24 ] ~ [ wine-1.3.23 ] ~ [ wine-1.3.22 ] ~ [ wine-1.3.21 ] ~ [ wine-1.3.20 ] ~ [ wine-1.3.19 ] ~ [ wine-1.3.18 ] ~ [ wine-1.2.3 ] ~ [ wine-1.3.17 ] ~ [ wine-1.3.16 ] ~ [ wine-1.3.15 ] ~ [ wine-1.3.14 ] ~ [ wine-1.3.13 ] ~ [ wine-1.3.12 ] ~ [ wine-1.3.11 ] ~ [ wine-1.3.10 ] ~ [ wine-1.3.9 ] ~ [ wine-1.2.2 ] ~ [ wine-1.3.8 ] ~ [ wine-1.3.7 ] ~ [ wine-1.3.6 ] ~ [ wine-1.3.5 ] ~ [ wine-1.2.1 ] ~ [ wine-1.3.4 ] ~ [ wine-1.3.3 ] ~ [ wine-1.3.2 ] ~ [ wine-1.3.1 ] ~ [ wine-1.3.0 ] ~ [ wine-1.2 ] ~ [ wine-1.2-rc7 ] ~ [ wine-1.2-rc6 ] ~ [ wine-1.2-rc5 ] ~ [ wine-1.2-rc4 ] ~ [ wine-1.2-rc3 ] ~ [ wine-1.2-rc2 ] ~ [ wine-1.2-rc1 ] ~ [ wine-1.1.44 ] ~ [ wine-1.1.43 ] ~ [ wine-1.1.42 ] ~ [ wine-1.1.41 ] ~ [ wine-1.1.40 ] ~ [ wine-1.1.39 ] ~ [ wine-1.1.38 ] ~ [ wine-1.1.37 ] ~ [ wine-1.1.36 ] ~ [ wine-1.1.35 ] ~ [ wine-1.1.34 ] ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  1 /*
  2  * Copyright 2006 Jacek Caban for CodeWeavers
  3  *
  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.
  8  *
  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.
 13  *
 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
 17  */
 18 
 19 #include <stdarg.h>
 20 
 21 #define COBJMACROS
 22 
 23 #include "windef.h"
 24 #include "winbase.h"
 25 #include "winuser.h"
 26 #include "ole2.h"
 27 
 28 #include "wine/debug.h"
 29 
 30 #include "mshtml_private.h"
 31 #include "htmlevent.h"
 32 
 33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
 34 
 35 static HTMLDOMNode *get_node_obj(HTMLDocumentNode*,IUnknown*);
 36 
 37 typedef struct {
 38     DispatchEx dispex;
 39     const IHTMLDOMChildrenCollectionVtbl  *lpIHTMLDOMChildrenCollectionVtbl;
 40 
 41     LONG ref;
 42 
 43     /* FIXME: implement weak reference */
 44     HTMLDocumentNode *doc;
 45 
 46     nsIDOMNodeList *nslist;
 47 } HTMLDOMChildrenCollection;
 48 
 49 #define HTMLCHILDCOL(x)  ((IHTMLDOMChildrenCollection*)  &(x)->lpIHTMLDOMChildrenCollectionVtbl)
 50 
 51 #define HTMLCHILDCOL_THIS(iface) DEFINE_THIS(HTMLDOMChildrenCollection, IHTMLDOMChildrenCollection, iface)
 52 
 53 static HRESULT WINAPI HTMLDOMChildrenCollection_QueryInterface(IHTMLDOMChildrenCollection *iface, REFIID riid, void **ppv)
 54 {
 55     HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
 56 
 57     *ppv = NULL;
 58 
 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;
 67     }
 68 
 69     if(*ppv) {
 70         IUnknown_AddRef((IUnknown*)*ppv);
 71         return S_OK;
 72     }
 73 
 74     WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
 75     return E_NOINTERFACE;
 76 }
 77 
 78 static ULONG WINAPI HTMLDOMChildrenCollection_AddRef(IHTMLDOMChildrenCollection *iface)
 79 {
 80     HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
 81     LONG ref = InterlockedIncrement(&This->ref);
 82 
 83     TRACE("(%p) ref=%d\n", This, ref);
 84 
 85     return ref;
 86 }
 87 
 88 static ULONG WINAPI HTMLDOMChildrenCollection_Release(IHTMLDOMChildrenCollection *iface)
 89 {
 90     HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
 91     LONG ref = InterlockedDecrement(&This->ref);
 92 
 93     TRACE("(%p) ref=%d\n", This, ref);
 94 
 95     if(!ref) {
 96         nsIDOMNodeList_Release(This->nslist);
 97         heap_free(This);
 98     }
 99 
100     return ref;
101 }
102 
103 static HRESULT WINAPI HTMLDOMChildrenCollection_GetTypeInfoCount(IHTMLDOMChildrenCollection *iface, UINT *pctinfo)
104 {
105     HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
106     return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->dispex), pctinfo);
107 }
108 
109 static HRESULT WINAPI HTMLDOMChildrenCollection_GetTypeInfo(IHTMLDOMChildrenCollection *iface, UINT iTInfo,
110         LCID lcid, ITypeInfo **ppTInfo)
111 {
112     HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
113     return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
114 }
115 
116 static HRESULT WINAPI HTMLDOMChildrenCollection_GetIDsOfNames(IHTMLDOMChildrenCollection *iface, REFIID riid,
117         LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
118 {
119     HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
120     return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->dispex), riid, rgszNames, cNames, lcid, rgDispId);
121 }
122 
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)
126 {
127     HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
128     return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid,
129             wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
130 }
131 
132 static HRESULT WINAPI HTMLDOMChildrenCollection_get_length(IHTMLDOMChildrenCollection *iface, LONG *p)
133 {
134     HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
135     PRUint32 length=0;
136 
137     TRACE("(%p)->(%p)\n", This, p);
138 
139     nsIDOMNodeList_GetLength(This->nslist, &length);
140     *p = length;
141     return S_OK;
142 }
143 
144 static HRESULT WINAPI HTMLDOMChildrenCollection__newEnum(IHTMLDOMChildrenCollection *iface, IUnknown **p)
145 {
146     HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
147     FIXME("(%p)->(%p)\n", This, p);
148     return E_NOTIMPL;
149 }
150 
151 static HRESULT WINAPI HTMLDOMChildrenCollection_item(IHTMLDOMChildrenCollection *iface, LONG index, IDispatch **ppItem)
152 {
153     HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
154     nsIDOMNode *nsnode = NULL;
155     PRUint32 length=0;
156     nsresult nsres;
157 
158     TRACE("(%p)->(%d %p)\n", This, index, ppItem);
159 
160     if (ppItem)
161         *ppItem = NULL;
162     else
163         return E_POINTER;
164 
165     nsIDOMNodeList_GetLength(This->nslist, &length);
166     if(index < 0 || index >= length)
167         return E_INVALIDARG;
168 
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;
173     }
174 
175     *ppItem = (IDispatch*)get_node(This->doc, nsnode, TRUE);
176     IDispatch_AddRef(*ppItem);
177     return S_OK;
178 }
179 
180 #define DISPID_CHILDCOL_0 MSHTML_DISPID_CUSTOM_MIN
181 
182 static HRESULT HTMLDOMChildrenCollection_get_dispid(IUnknown *iface, BSTR name, DWORD flags, DISPID *dispid)
183 {
184     HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
185     WCHAR *ptr;
186     DWORD idx=0;
187     PRUint32 len = 0;
188 
189     for(ptr = name; *ptr && isdigitW(*ptr); ptr++)
190         idx = idx*10 + (*ptr-'');
191     if(*ptr)
192         return DISP_E_UNKNOWNNAME;
193 
194     nsIDOMNodeList_GetLength(This->nslist, &len);
195     if(idx >= len)
196         return DISP_E_UNKNOWNNAME;
197 
198     *dispid = DISPID_CHILDCOL_0 + idx;
199     TRACE("ret %x\n", *dispid);
200     return S_OK;
201 }
202 
203 static HRESULT HTMLDOMChildrenCollection_invoke(IUnknown *iface, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
204         VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
205 {
206     HTMLDOMChildrenCollection *This = HTMLCHILDCOL_THIS(iface);
207 
208     TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
209 
210     switch(flags) {
211     case DISPATCH_PROPERTYGET: {
212         IDispatch *disp = NULL;
213         HRESULT hres;
214 
215         hres = IHTMLDOMChildrenCollection_item(HTMLCHILDCOL(This), id - DISPID_CHILDCOL_0, &disp);
216         if(0&&FAILED(hres))
217             return hres;
218 
219         V_VT(res) = VT_DISPATCH;
220         V_DISPATCH(res) = disp;
221         break;
222     }
223 
224     default:
225         FIXME("unimplemented flags %x\n", flags);
226         return E_NOTIMPL;
227     }
228 
229     return S_OK;
230 }
231 
232 #undef HTMLCHILDCOL_THIS
233 
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
245 };
246 
247 static const tid_t HTMLDOMChildrenCollection_iface_tids[] = {
248     IHTMLDOMChildrenCollection_tid,
249     0
250 };
251 
252 static const dispex_static_data_vtbl_t HTMLDOMChildrenCollection_dispex_vtbl = {
253     NULL,
254     HTMLDOMChildrenCollection_get_dispid,
255     HTMLDOMChildrenCollection_invoke
256 };
257 
258 static dispex_static_data_t HTMLDOMChildrenCollection_dispex = {
259     &HTMLDOMChildrenCollection_dispex_vtbl,
260     DispDOMChildrenCollection_tid,
261     NULL,
262     HTMLDOMChildrenCollection_iface_tids
263 };
264 
265 static IHTMLDOMChildrenCollection *create_child_collection(HTMLDocumentNode *doc, nsIDOMNodeList *nslist)
266 {
267     HTMLDOMChildrenCollection *ret;
268 
269     ret = heap_alloc_zero(sizeof(*ret));
270     ret->lpIHTMLDOMChildrenCollectionVtbl = &HTMLDOMChildrenCollectionVtbl;
271     ret->ref = 1;
272 
273     nsIDOMNodeList_AddRef(nslist);
274     ret->nslist = nslist;
275     ret->doc = doc;
276 
277     init_dispex(&ret->dispex, (IUnknown*)HTMLCHILDCOL(ret), &HTMLDOMChildrenCollection_dispex);
278 
279     return HTMLCHILDCOL(ret);
280 }
281 
282 #define HTMLDOMNODE_THIS(iface) DEFINE_THIS(HTMLDOMNode, HTMLDOMNode, iface)
283 
284 static HRESULT WINAPI HTMLDOMNode_QueryInterface(IHTMLDOMNode *iface,
285                                                  REFIID riid, void **ppv)
286 {
287     HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
288 
289     return This->vtbl->qi(This, riid, ppv);
290 }
291 
292 static ULONG WINAPI HTMLDOMNode_AddRef(IHTMLDOMNode *iface)
293 {
294     HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
295     LONG ref = InterlockedIncrement(&This->ref);
296 
297     TRACE("(%p) ref=%d\n", This, ref);
298 
299     return ref;
300 }
301 
302 static ULONG WINAPI HTMLDOMNode_Release(IHTMLDOMNode *iface)
303 {
304     HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
305     LONG ref = InterlockedDecrement(&This->ref);
306 
307     TRACE("(%p) ref=%d\n", This, ref);
308 
309     if(!ref) {
310         This->vtbl->destructor(This);
311         release_dispex(&This->dispex);
312         heap_free(This);
313     }
314 
315     return ref;
316 }
317 
318 static HRESULT WINAPI HTMLDOMNode_GetTypeInfoCount(IHTMLDOMNode *iface, UINT *pctinfo)
319 {
320     HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
321     return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->dispex), pctinfo);
322 }
323 
324 static HRESULT WINAPI HTMLDOMNode_GetTypeInfo(IHTMLDOMNode *iface, UINT iTInfo,
325                                               LCID lcid, ITypeInfo **ppTInfo)
326 {
327     HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
328     return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
329 }
330 
331 static HRESULT WINAPI HTMLDOMNode_GetIDsOfNames(IHTMLDOMNode *iface, REFIID riid,
332                                                 LPOLESTR *rgszNames, UINT cNames,
333                                                 LCID lcid, DISPID *rgDispId)
334 {
335     HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
336     return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->dispex), riid, rgszNames, cNames, lcid, rgDispId);
337 }
338 
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)
342 {
343     HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
344     return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid,
345             wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
346 }
347 
348 static HRESULT WINAPI HTMLDOMNode_get_nodeType(IHTMLDOMNode *iface, LONG *p)
349 {
350     HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
351     PRUint16 type = -1;
352 
353     TRACE("(%p)->(%p)\n", This, p);
354 
355     nsIDOMNode_GetNodeType(This->nsnode, &type);
356 
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:
371         /*
372          * FIXME:
373          * According to MSDN only ELEMENT_NODE and TEXT_NODE are supported.
374          * It needs more tests.
375          */
376         FIXME("type %u\n", type);
377         *p = 0;
378     }
379 
380     return S_OK;
381 }
382 
383 static HRESULT WINAPI HTMLDOMNode_get_parentNode(IHTMLDOMNode *iface, IHTMLDOMNode **p)
384 {
385     HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
386     HTMLDOMNode *node;
387     nsIDOMNode *nsnode;
388     nsresult nsres;
389 
390     TRACE("(%p)->(%p)\n", This, p);
391 
392     nsres = nsIDOMNode_GetParentNode(This->nsnode, &nsnode);
393     if(NS_FAILED(nsres)) {
394         ERR("GetParentNode failed: %08x\n", nsres);
395         return E_FAIL;
396     }
397 
398     if(!nsnode) {
399         *p = NULL;
400         return S_OK;
401     }
402 
403     node = get_node(This->doc, nsnode, TRUE);
404     *p = HTMLDOMNODE(node);
405     IHTMLDOMNode_AddRef(*p);
406     return S_OK;
407 }
408 
409 static HRESULT WINAPI HTMLDOMNode_hasChildNodes(IHTMLDOMNode *iface, VARIANT_BOOL *fChildren)
410 {
411     HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
412     PRBool has_child = FALSE;
413     nsresult nsres;
414 
415     TRACE("(%p)->(%p)\n", This, fChildren);
416 
417     nsres = nsIDOMNode_HasChildNodes(This->nsnode, &has_child);
418     if(NS_FAILED(nsres))
419         ERR("HasChildNodes failed: %08x\n", nsres);
420 
421     *fChildren = has_child ? VARIANT_TRUE : VARIANT_FALSE;
422     return S_OK;
423 }
424 
425 static HRESULT WINAPI HTMLDOMNode_get_childNodes(IHTMLDOMNode *iface, IDispatch **p)
426 {
427     HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
428     nsIDOMNodeList *nslist;
429     nsresult nsres;
430 
431     TRACE("(%p)->(%p)\n", This, p);
432 
433     nsres = nsIDOMNode_GetChildNodes(This->nsnode, &nslist);
434     if(NS_FAILED(nsres)) {
435         ERR("GetChildNodes failed: %08x\n", nsres);
436         return E_FAIL;
437     }
438 
439     *p = (IDispatch*)create_child_collection(This->doc, nslist);
440     nsIDOMNodeList_Release(nslist);
441 
442     return S_OK;
443 }
444 
445 static HRESULT WINAPI HTMLDOMNode_get_attributes(IHTMLDOMNode *iface, IDispatch **p)
446 {
447     HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
448     FIXME("(%p)->(%p)\n", This, p);
449     return E_NOTIMPL;
450 }
451 
452 static HRESULT WINAPI HTMLDOMNode_insertBefore(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
453                                                VARIANT refChild, IHTMLDOMNode **node)
454 {
455     HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
456     nsIDOMNode *nsnode, *nsref = NULL;
457     HTMLDOMNode *new_child;
458     nsresult nsres;
459 
460     TRACE("(%p)->(%p %s %p)\n", This, newChild, debugstr_variant(&refChild), node);
461 
462     new_child = get_node_obj(This->doc, (IUnknown*)newChild);
463     if(!new_child) {
464         ERR("invalid newChild\n");
465         return E_INVALIDARG;
466     }
467 
468     switch(V_VT(&refChild)) {
469     case VT_NULL:
470         break;
471     case VT_DISPATCH: {
472         HTMLDOMNode *ref_node;
473 
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;
478         }
479 
480         nsref = ref_node->nsnode;
481         break;
482     }
483     default:
484         FIXME("unimplemented vt %d\n", V_VT(&refChild));
485         return E_NOTIMPL;
486     }
487 
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;
492     }
493 
494     *node = HTMLDOMNODE(get_node(This->doc, nsnode, TRUE));
495     nsIDOMNode_Release(nsnode);
496     IHTMLDOMNode_AddRef(*node);
497     return S_OK;
498 }
499 
500 static HRESULT WINAPI HTMLDOMNode_removeChild(IHTMLDOMNode *iface, IHTMLDOMNode *oldChild,
501                                               IHTMLDOMNode **node)
502 {
503     HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
504     HTMLDOMNode *node_obj;
505     nsIDOMNode *nsnode;
506     nsresult nsres;
507 
508     TRACE("(%p)->(%p %p)\n", This, oldChild, node);
509 
510     node_obj = get_node_obj(This->doc, (IUnknown*)oldChild);
511     if(!node_obj)
512         return E_FAIL;
513 
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;
518     }
519 
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;
525 }
526 
527 static HRESULT WINAPI HTMLDOMNode_replaceChild(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
528                                                IHTMLDOMNode *oldChild, IHTMLDOMNode **node)
529 {
530     HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
531     FIXME("(%p)->(%p %p %p)\n", This, newChild, oldChild, node);
532     return E_NOTIMPL;
533 }
534 
535 static HRESULT WINAPI HTMLDOMNode_cloneNode(IHTMLDOMNode *iface, VARIANT_BOOL fDeep,
536                                             IHTMLDOMNode **clonedNode)
537 {
538     HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
539     nsIDOMNode *nsnode;
540     HTMLDOMNode *node;
541     nsresult nsres;
542 
543     TRACE("(%p)->(%x %p)\n", This, fDeep, clonedNode);
544 
545     nsres = nsIDOMNode_CloneNode(This->nsnode, fDeep != VARIANT_FALSE, &nsnode);
546     if(NS_FAILED(nsres) || !nsnode) {
547         ERR("CloneNode failed: %08x\n", nsres);
548         return E_FAIL;
549     }
550 
551     node = get_node(This->doc, nsnode, TRUE);
552     IHTMLDOMNode_AddRef(HTMLDOMNODE(node));
553     *clonedNode = HTMLDOMNODE(node);
554     return S_OK;
555 }
556 
557 static HRESULT WINAPI HTMLDOMNode_removeNode(IHTMLDOMNode *iface, VARIANT_BOOL fDeep,
558                                              IHTMLDOMNode **removed)
559 {
560     HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
561     FIXME("(%p)->(%x %p)\n", This, fDeep, removed);
562     return E_NOTIMPL;
563 }
564 
565 static HRESULT WINAPI HTMLDOMNode_swapNode(IHTMLDOMNode *iface, IHTMLDOMNode *otherNode,
566                                            IHTMLDOMNode **swappedNode)
567 {
568     HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
569     FIXME("(%p)->(%p %p)\n", This, otherNode, swappedNode);
570     return E_NOTIMPL;
571 }
572 
573 static HRESULT WINAPI HTMLDOMNode_replaceNode(IHTMLDOMNode *iface, IHTMLDOMNode *replacement,
574                                               IHTMLDOMNode **replaced)
575 {
576     HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
577     FIXME("(%p)->(%p %p)\n", This, replacement, replaced);
578     return E_NOTIMPL;
579 }
580 
581 static HRESULT WINAPI HTMLDOMNode_appendChild(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
582                                               IHTMLDOMNode **node)
583 {
584     HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
585     HTMLDOMNode *node_obj;
586     nsIDOMNode *nsnode;
587     nsresult nsres;
588 
589     TRACE("(%p)->(%p %p)\n", This, newChild, node);
590 
591     node_obj = get_node_obj(This->doc, (IUnknown*)newChild);
592     if(!node_obj)
593         return E_FAIL;
594 
595     nsres = nsIDOMNode_AppendChild(This->nsnode, node_obj->nsnode, &nsnode);
596     if(NS_FAILED(nsres)) {
597         WARN("AppendChild failed: %08x\n", nsres);
598         nsnode = node_obj->nsnode;
599     }
600 
601     /* FIXME: Make sure that node != newChild */
602     *node = HTMLDOMNODE(get_node(This->doc, nsnode, TRUE));
603     IHTMLDOMNode_AddRef(*node);
604     return S_OK;
605 }
606 
607 static HRESULT WINAPI HTMLDOMNode_get_nodeName(IHTMLDOMNode *iface, BSTR *p)
608 {
609     HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
610 
611     TRACE("(%p)->(%p)\n", This, p);
612 
613     *p = NULL;
614 
615     if(This->nsnode) {
616         nsAString name_str;
617         const PRUnichar *name;
618         nsresult nsres;
619 
620         nsAString_Init(&name_str, NULL);
621         nsres = nsIDOMNode_GetNodeName(This->nsnode, &name_str);
622 
623         if(NS_SUCCEEDED(nsres)) {
624             nsAString_GetData(&name_str, &name);
625             *p = SysAllocString(name);
626         }else {
627             ERR("GetNodeName failed: %08x\n", nsres);
628         }
629 
630         nsAString_Finish(&name_str);
631     }
632 
633     return S_OK;
634 }
635 
636 static HRESULT WINAPI HTMLDOMNode_put_nodeValue(IHTMLDOMNode *iface, VARIANT v)
637 {
638     HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
639 
640     TRACE("(%p)->()\n", This);
641 
642     switch(V_VT(&v)) {
643     case VT_BSTR: {
644         nsAString val_str;
645 
646         TRACE("bstr %s\n", debugstr_w(V_BSTR(&v)));
647 
648         nsAString_Init(&val_str, V_BSTR(&v));
649         nsIDOMNode_SetNodeValue(This->nsnode, &val_str);
650         nsAString_Finish(&val_str);
651 
652         return S_OK;
653     }
654 
655     default:
656         FIXME("unsupported vt %d\n", V_VT(&v));
657     }
658 
659     return E_NOTIMPL;
660 }
661 
662 static HRESULT WINAPI HTMLDOMNode_get_nodeValue(IHTMLDOMNode *iface, VARIANT *p)
663 {
664     HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
665     const PRUnichar *val;
666     nsAString val_str;
667 
668     TRACE("(%p)->(%p)\n", This, p);
669 
670     nsAString_Init(&val_str, NULL);
671     nsIDOMNode_GetNodeValue(This->nsnode, &val_str);
672     nsAString_GetData(&val_str, &val);
673 
674     if(*val) {
675         V_VT(p) = VT_BSTR;
676         V_BSTR(p) = SysAllocString(val);
677     }else {
678         V_VT(p) = VT_NULL;
679     }
680 
681     nsAString_Finish(&val_str);
682 
683     return S_OK;
684 }
685 
686 static HRESULT WINAPI HTMLDOMNode_get_firstChild(IHTMLDOMNode *iface, IHTMLDOMNode **p)
687 {
688     HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
689     nsIDOMNode *nschild = NULL;
690 
691     TRACE("(%p)->(%p)\n", This, p);
692 
693     nsIDOMNode_GetFirstChild(This->nsnode, &nschild);
694     if(nschild) {
695         *p = HTMLDOMNODE(get_node(This->doc, nschild, TRUE));
696         IHTMLDOMNode_AddRef(*p);
697     }else {
698         *p = NULL;
699     }
700 
701     return S_OK;
702 }
703 
704 static HRESULT WINAPI HTMLDOMNode_get_lastChild(IHTMLDOMNode *iface, IHTMLDOMNode **p)
705 {
706     HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
707     nsIDOMNode *nschild = NULL;
708 
709     TRACE("(%p)->(%p)\n", This, p);
710 
711     nsIDOMNode_GetLastChild(This->nsnode, &nschild);
712     if(nschild) {
713         *p = HTMLDOMNODE(get_node(This->doc, nschild, TRUE));
714         IHTMLDOMNode_AddRef(*p);
715     }else {
716         *p = NULL;
717     }
718 
719     return S_OK;
720 }
721 
722 static HRESULT WINAPI HTMLDOMNode_get_previousSibling(IHTMLDOMNode *iface, IHTMLDOMNode **p)
723 {
724     HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
725     FIXME("(%p)->(%p)\n", This, p);
726     return E_NOTIMPL;
727 }
728 
729 static HRESULT WINAPI HTMLDOMNode_get_nextSibling(IHTMLDOMNode *iface, IHTMLDOMNode **p)
730 {
731     HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
732     FIXME("(%p)->(%p)\n", This, p);
733     return E_NOTIMPL;
734 }
735 
736 #undef HTMLDOMNODE_THIS
737 
738 static const IHTMLDOMNodeVtbl HTMLDOMNodeVtbl = {
739     HTMLDOMNode_QueryInterface,
740     HTMLDOMNode_AddRef,
741     HTMLDOMNode_Release,
742     HTMLDOMNode_GetTypeInfoCount,
743     HTMLDOMNode_GetTypeInfo,
744     HTMLDOMNode_GetIDsOfNames,
745     HTMLDOMNode_Invoke,
746     HTMLDOMNode_get_nodeType,
747     HTMLDOMNode_get_parentNode,
748     HTMLDOMNode_hasChildNodes,
749     HTMLDOMNode_get_childNodes,
750     HTMLDOMNode_get_attributes,
751     HTMLDOMNode_insertBefore,
752     HTMLDOMNode_removeChild,
753     HTMLDOMNode_replaceChild,
754     HTMLDOMNode_cloneNode,
755     HTMLDOMNode_removeNode,
756     HTMLDOMNode_swapNode,
757     HTMLDOMNode_replaceNode,
758     HTMLDOMNode_appendChild,
759     HTMLDOMNode_get_nodeName,
760     HTMLDOMNode_put_nodeValue,
761     HTMLDOMNode_get_nodeValue,
762     HTMLDOMNode_get_firstChild,
763     HTMLDOMNode_get_lastChild,
764     HTMLDOMNode_get_previousSibling,
765     HTMLDOMNode_get_nextSibling
766 };
767 
768 #define HTMLDOMNODE2_THIS(iface) DEFINE_THIS(HTMLDOMNode, HTMLDOMNode2, iface)
769 
770 static HRESULT WINAPI HTMLDOMNode2_QueryInterface(IHTMLDOMNode2 *iface,
771         REFIID riid, void **ppv)
772 {
773     HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
774 
775     return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(This), riid, ppv);
776 }
777 
778 static ULONG WINAPI HTMLDOMNode2_AddRef(IHTMLDOMNode2 *iface)
779 {
780     HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
781 
782     return IHTMLDOMNode_AddRef(HTMLDOMNODE(This));
783 }
784 
785 static ULONG WINAPI HTMLDOMNode2_Release(IHTMLDOMNode2 *iface)
786 {
787     HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
788 
789     return IHTMLDOMNode_Release(HTMLDOMNODE(This));
790 }
791 
792 static HRESULT WINAPI HTMLDOMNode2_GetTypeInfoCount(IHTMLDOMNode2 *iface, UINT *pctinfo)
793 {
794     HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
795     return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->dispex), pctinfo);
796 }
797 
798 static HRESULT WINAPI HTMLDOMNode2_GetTypeInfo(IHTMLDOMNode2 *iface, UINT iTInfo,
799         LCID lcid, ITypeInfo **ppTInfo)
800 {
801     HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
802     return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
803 }
804 
805 static HRESULT WINAPI HTMLDOMNode2_GetIDsOfNames(IHTMLDOMNode2 *iface, REFIID riid,
806                                                 LPOLESTR *rgszNames, UINT cNames,
807                                                 LCID lcid, DISPID *rgDispId)
808 {
809     HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
810     return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->dispex), riid, rgszNames, cNames, lcid, rgDispId);
811 }
812 
813 static HRESULT WINAPI HTMLDOMNode2_Invoke(IHTMLDOMNode2 *iface, DISPID dispIdMember,
814         REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
815         VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
816 {
817     HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
818     return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid,
819             wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
820 }
821 
822 static HRESULT WINAPI HTMLDOMNode2_get_ownerDocument(IHTMLDOMNode2 *iface, IDispatch **p)
823 {
824     HTMLDOMNode *This = HTMLDOMNODE2_THIS(iface);
825 
826     TRACE("(%p)->(%p)\n", This, p);
827 
828     *p = (IDispatch*)HTMLDOC(&This->doc->basedoc);
829     IDispatch_AddRef(*p);
830     return S_OK;
831 }
832 
833 #undef HTMLDOMNODE2_THIS
834 
835 static const IHTMLDOMNode2Vtbl HTMLDOMNode2Vtbl = {
836     HTMLDOMNode2_QueryInterface,
837     HTMLDOMNode2_AddRef,
838     HTMLDOMNode2_Release,
839     HTMLDOMNode2_GetTypeInfoCount,
840     HTMLDOMNode2_GetTypeInfo,
841     HTMLDOMNode2_GetIDsOfNames,
842     HTMLDOMNode2_Invoke,
843     HTMLDOMNode2_get_ownerDocument
844 };
845 
846 HRESULT HTMLDOMNode_QI(HTMLDOMNode *This, REFIID riid, void **ppv)
847 {
848     *ppv = NULL;
849 
850     if(IsEqualGUID(&IID_IUnknown, riid)) {
851         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
852         *ppv = HTMLDOMNODE(This);
853     }else if(IsEqualGUID(&IID_IDispatch, riid)) {
854         TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
855         *ppv = HTMLDOMNODE(This);
856     }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
857         if(This->dispex.data) {
858             TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
859             *ppv = DISPATCHEX(&This->dispex);
860         }else {
861             FIXME("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
862             return E_NOINTERFACE;
863         }
864     }else if(IsEqualGUID(&IID_IHTMLDOMNode, riid)) {
865         TRACE("(%p)->(IID_IHTMLDOMNode %p)\n", This, ppv);
866         *ppv = HTMLDOMNODE(This);
867     }else if(IsEqualGUID(&IID_IHTMLDOMNode2, riid)) {
868         TRACE("(%p)->(IID_IHTMLDOMNode2 %p)\n", This, ppv);
869         *ppv = HTMLDOMNODE2(This);
870     }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
871         return *ppv ? S_OK : E_NOINTERFACE;
872     }
873 
874     if(*ppv) {
875         IUnknown_AddRef((IUnknown*)*ppv);
876         return S_OK;
877     }
878 
879     WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
880     return E_NOINTERFACE;
881 }
882 
883 void HTMLDOMNode_destructor(HTMLDOMNode *This)
884 {
885     if(This->nsnode)
886         nsIDOMNode_Release(This->nsnode);
887     if(This->event_target)
888         release_event_target(This->event_target);
889 }
890 
891 static const NodeImplVtbl HTMLDOMNodeImplVtbl = {
892     HTMLDOMNode_QI,
893     HTMLDOMNode_destructor
894 };
895 
896 void HTMLDOMNode_Init(HTMLDocumentNode *doc, HTMLDOMNode *node, nsIDOMNode *nsnode)
897 {
898     node->lpHTMLDOMNodeVtbl = &HTMLDOMNodeVtbl;
899     node->lpHTMLDOMNode2Vtbl = &HTMLDOMNode2Vtbl;
900     node->ref = 1;
901     node->doc = doc;
902 
903     nsIDOMNode_AddRef(nsnode);
904     node->nsnode = nsnode;
905 
906     node->next = doc->nodes;
907     doc->nodes = node;
908 }
909 
910 static HTMLDOMNode *create_node(HTMLDocumentNode *doc, nsIDOMNode *nsnode)
911 {
912     HTMLDOMNode *ret;
913     PRUint16 node_type;
914 
915     nsIDOMNode_GetNodeType(nsnode, &node_type);
916 
917     switch(node_type) {
918     case ELEMENT_NODE:
919         ret = &HTMLElement_Create(doc, nsnode, FALSE)->node;
920         break;
921     case TEXT_NODE:
922         ret = HTMLDOMTextNode_Create(doc, nsnode);
923         break;
924     case COMMENT_NODE:
925         ret = &HTMLCommentElement_Create(doc, nsnode)->node;
926         break;
927     default:
928         ret = heap_alloc_zero(sizeof(HTMLDOMNode));
929         ret->vtbl = &HTMLDOMNodeImplVtbl;
930         HTMLDOMNode_Init(doc, ret, nsnode);
931     }
932 
933     TRACE("type %d ret %p\n", node_type, ret);
934 
935     return ret;
936 }
937 
938 /*
939  * FIXME
940  * List looks really ugly here. We should use a better data structure or
941  * (better) find a way to store HTMLDOMelement pointer in nsIDOMNode.
942  */
943 
944 HTMLDOMNode *get_node(HTMLDocumentNode *This, nsIDOMNode *nsnode, BOOL create)
945 {
946     HTMLDOMNode *iter = This->nodes;
947 
948     while(iter) {
949         if(iter->nsnode == nsnode)
950             break;
951         iter = iter->next;
952     }
953 
954     if(iter || !create)
955         return iter;
956 
957     return create_node(This, nsnode);
958 }
959 
960 /*
961  * FIXME
962  * We should use better way for getting node object (like private interface)
963  * or avoid it at all.
964  */
965 static HTMLDOMNode *get_node_obj(HTMLDocumentNode *This, IUnknown *iface)
966 {
967     HTMLDOMNode *iter = This->nodes;
968     IHTMLDOMNode *node;
969 
970     IUnknown_QueryInterface(iface, &IID_IHTMLDOMNode, (void**)&node);
971     IHTMLDOMNode_Release(node);
972 
973     while(iter) {
974         if(HTMLDOMNODE(iter) == node)
975             return iter;
976         iter = iter->next;
977     }
978 
979     FIXME("Not found %p\n", iface);
980     return NULL;
981 }
982 
983 void release_nodes(HTMLDocumentNode *This)
984 {
985     HTMLDOMNode *iter, *next;
986 
987     if(!This->nodes)
988         return;
989 
990     for(iter = This->nodes; iter; iter = next) {
991         next = iter->next;
992         iter->doc = NULL;
993         if(&This->node != iter)
994             IHTMLDOMNode_Release(HTMLDOMNODE(iter));
995     }
996 }
997 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.