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
32 #include "wine/debug.h"
34 #include "mshtml_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
38 #define NSSUPPORTS(x) ((nsISupports*) &(x)->lpSupportsVtbl)
40 #define HTMLDOMNODE_THIS(iface) DEFINE_THIS(HTMLDOMNode, HTMLDOMNode, iface)
42 static HRESULT WINAPI
HTMLDOMNode_QueryInterface(IHTMLDOMNode
*iface
,
43 REFIID riid
, void **ppv
)
45 HTMLDOMNode
*This
= HTMLDOMNODE_THIS(iface
);
47 return This
->vtbl
->qi(This
, riid
, ppv
);
50 static ULONG WINAPI
HTMLDOMNode_AddRef(IHTMLDOMNode
*iface
)
52 HTMLDOMNode
*This
= HTMLDOMNODE_THIS(iface
);
53 LONG ref
= InterlockedIncrement(&This
->ref
);
55 TRACE("(%p) ref=%d\n", This
, ref
);
60 static ULONG WINAPI
HTMLDOMNode_Release(IHTMLDOMNode
*iface
)
62 HTMLDOMNode
*This
= HTMLDOMNODE_THIS(iface
);
63 LONG ref
= InterlockedDecrement(&This
->ref
);
65 TRACE("(%p) ref=%d\n", This
, ref
);
68 This
->vtbl
->destructor(This
);
75 static HRESULT WINAPI
HTMLDOMNode_GetTypeInfoCount(IHTMLDOMNode
*iface
, UINT
*pctinfo
)
77 HTMLDOMNode
*This
= HTMLDOMNODE_THIS(iface
);
78 FIXME("(%p)->(%p)\n", This
, pctinfo
);
82 static HRESULT WINAPI
HTMLDOMNode_GetTypeInfo(IHTMLDOMNode
*iface
, UINT iTInfo
,
83 LCID lcid
, ITypeInfo
**ppTInfo
)
85 HTMLDOMNode
*This
= HTMLDOMNODE_THIS(iface
);
86 FIXME("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
90 static HRESULT WINAPI
HTMLDOMNode_GetIDsOfNames(IHTMLDOMNode
*iface
, REFIID riid
,
91 LPOLESTR
*rgszNames
, UINT cNames
,
92 LCID lcid
, DISPID
*rgDispId
)
94 HTMLDOMNode
*This
= HTMLDOMNODE_THIS(iface
);
95 FIXME("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
100 static HRESULT WINAPI
HTMLDOMNode_Invoke(IHTMLDOMNode
*iface
, DISPID dispIdMember
,
101 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
102 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
104 HTMLDOMNode
*This
= HTMLDOMNODE_THIS(iface
);
105 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
106 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
110 static HRESULT WINAPI
HTMLDOMNode_get_nodeType(IHTMLDOMNode
*iface
, long *p
)
112 HTMLDOMNode
*This
= HTMLDOMNODE_THIS(iface
);
113 FIXME("(%p)->(%p)\n", This
, p
);
117 static HRESULT WINAPI
HTMLDOMNode_get_parentNode(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
119 HTMLDOMNode
*This
= HTMLDOMNODE_THIS(iface
);
120 FIXME("(%p)->(%p)\n", This
, p
);
124 static HRESULT WINAPI
HTMLDOMNode_hasChildNodes(IHTMLDOMNode
*iface
, VARIANT_BOOL
*fChildren
)
126 HTMLDOMNode
*This
= HTMLDOMNODE_THIS(iface
);
127 FIXME("(%p)->(%p)\n", This
, fChildren
);
131 static HRESULT WINAPI
HTMLDOMNode_get_childNodes(IHTMLDOMNode
*iface
, IDispatch
**p
)
133 HTMLDOMNode
*This
= HTMLDOMNODE_THIS(iface
);
134 FIXME("(%p)->(%p)\n", This
, p
);
138 static HRESULT WINAPI
HTMLDOMNode_get_attributes(IHTMLDOMNode
*iface
, IDispatch
**p
)
140 HTMLDOMNode
*This
= HTMLDOMNODE_THIS(iface
);
141 FIXME("(%p)->(%p)\n", This
, p
);
145 static HRESULT WINAPI
HTMLDOMNode_insertBefore(IHTMLDOMNode
*iface
, IHTMLDOMNode
*newChild
,
146 VARIANT refChild
, IHTMLDOMNode
**node
)
148 HTMLDOMNode
*This
= HTMLDOMNODE_THIS(iface
);
149 FIXME("(%p)->(%p v %p)\n", This
, newChild
, node
);
153 static HRESULT WINAPI
HTMLDOMNode_removeChild(IHTMLDOMNode
*iface
, IHTMLDOMNode
*newChild
,
156 HTMLDOMNode
*This
= HTMLDOMNODE_THIS(iface
);
157 FIXME("(%p)->(%p %p)\n", This
, newChild
, node
);
161 static HRESULT WINAPI
HTMLDOMNode_replaceChild(IHTMLDOMNode
*iface
, IHTMLDOMNode
*newChild
,
162 IHTMLDOMNode
*oldChild
, IHTMLDOMNode
**node
)
164 HTMLDOMNode
*This
= HTMLDOMNODE_THIS(iface
);
165 FIXME("(%p)->(%p %p %p)\n", This
, newChild
, oldChild
, node
);
169 static HRESULT WINAPI
HTMLDOMNode_cloneNode(IHTMLDOMNode
*iface
, VARIANT_BOOL fDeep
,
170 IHTMLDOMNode
**clonedNode
)
172 HTMLDOMNode
*This
= HTMLDOMNODE_THIS(iface
);
173 FIXME("(%p)->(%x %p)\n", This
, fDeep
, clonedNode
);
177 static HRESULT WINAPI
HTMLDOMNode_removeNode(IHTMLDOMNode
*iface
, VARIANT_BOOL fDeep
,
178 IHTMLDOMNode
**removed
)
180 HTMLDOMNode
*This
= HTMLDOMNODE_THIS(iface
);
181 FIXME("(%p)->(%x %p)\n", This
, fDeep
, removed
);
185 static HRESULT WINAPI
HTMLDOMNode_swapNode(IHTMLDOMNode
*iface
, IHTMLDOMNode
*otherNode
,
186 IHTMLDOMNode
**swappedNode
)
188 HTMLDOMNode
*This
= HTMLDOMNODE_THIS(iface
);
189 FIXME("(%p)->(%p %p)\n", This
, otherNode
, swappedNode
);
193 static HRESULT WINAPI
HTMLDOMNode_replaceNode(IHTMLDOMNode
*iface
, IHTMLDOMNode
*replacement
,
194 IHTMLDOMNode
**replaced
)
196 HTMLDOMNode
*This
= HTMLDOMNODE_THIS(iface
);
197 FIXME("(%p)->(%p %p)\n", This
, replacement
, replaced
);
201 static HRESULT WINAPI
HTMLDOMNode_appendChild(IHTMLDOMNode
*iface
, IHTMLDOMNode
*newChild
,
204 HTMLDOMNode
*This
= HTMLDOMNODE_THIS(iface
);
205 FIXME("(%p)->(%p %p)\n", This
, newChild
, node
);
209 static HRESULT WINAPI
HTMLDOMNode_get_nodeName(IHTMLDOMNode
*iface
, BSTR
*p
)
211 HTMLDOMNode
*This
= HTMLDOMNODE_THIS(iface
);
213 TRACE("(%p)->(%p)\n", This
, p
);
219 const PRUnichar
*name
;
222 nsAString_Init(&name_str
, NULL
);
223 nsres
= nsIDOMNode_GetNodeName(This
->nsnode
, &name_str
);
225 if(NS_SUCCEEDED(nsres
)) {
226 nsAString_GetData(&name_str
, &name
);
227 *p
= SysAllocString(name
);
229 ERR("GetNodeName failed: %08x\n", nsres
);
232 nsAString_Finish(&name_str
);
238 static HRESULT WINAPI
HTMLDOMNode_put_nodeValue(IHTMLDOMNode
*iface
, VARIANT v
)
240 HTMLDOMNode
*This
= HTMLDOMNODE_THIS(iface
);
241 FIXME("(%p)->()\n", This
);
245 static HRESULT WINAPI
HTMLDOMNode_get_nodeValue(IHTMLDOMNode
*iface
, VARIANT
*p
)
247 HTMLDOMNode
*This
= HTMLDOMNODE_THIS(iface
);
248 FIXME("(%p)->(%p)\n", This
, p
);
252 static HRESULT WINAPI
HTMLDOMNode_get_firstChild(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
254 HTMLDOMNode
*This
= HTMLDOMNODE_THIS(iface
);
255 FIXME("(%p)->(%p)\n", This
, p
);
259 static HRESULT WINAPI
HTMLDOMNode_get_lastChild(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
261 HTMLDOMNode
*This
= HTMLDOMNODE_THIS(iface
);
262 FIXME("(%p)->(%p)\n", This
, p
);
266 static HRESULT WINAPI
HTMLDOMNode_get_previousSibling(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
268 HTMLDOMNode
*This
= HTMLDOMNODE_THIS(iface
);
269 FIXME("(%p)->(%p)\n", This
, p
);
273 static HRESULT WINAPI
HTMLDOMNode_get_nextSibling(IHTMLDOMNode
*iface
, IHTMLDOMNode
**p
)
275 HTMLDOMNode
*This
= HTMLDOMNODE_THIS(iface
);
276 FIXME("(%p)->(%p)\n", This
, p
);
280 static const IHTMLDOMNodeVtbl HTMLDOMNodeVtbl
= {
281 HTMLDOMNode_QueryInterface
,
284 HTMLDOMNode_GetTypeInfoCount
,
285 HTMLDOMNode_GetTypeInfo
,
286 HTMLDOMNode_GetIDsOfNames
,
288 HTMLDOMNode_get_nodeType
,
289 HTMLDOMNode_get_parentNode
,
290 HTMLDOMNode_hasChildNodes
,
291 HTMLDOMNode_get_childNodes
,
292 HTMLDOMNode_get_attributes
,
293 HTMLDOMNode_insertBefore
,
294 HTMLDOMNode_removeChild
,
295 HTMLDOMNode_replaceChild
,
296 HTMLDOMNode_cloneNode
,
297 HTMLDOMNode_removeNode
,
298 HTMLDOMNode_swapNode
,
299 HTMLDOMNode_replaceNode
,
300 HTMLDOMNode_appendChild
,
301 HTMLDOMNode_get_nodeName
,
302 HTMLDOMNode_put_nodeValue
,
303 HTMLDOMNode_get_nodeValue
,
304 HTMLDOMNode_get_firstChild
,
305 HTMLDOMNode_get_lastChild
,
306 HTMLDOMNode_get_previousSibling
,
307 HTMLDOMNode_get_nextSibling
310 HRESULT
HTMLDOMNode_QI(HTMLDOMNode
*This
, REFIID riid
, void **ppv
)
314 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
315 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
316 *ppv
= HTMLDOMNODE(This
);
317 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
318 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
319 *ppv
= HTMLDOMNODE(This
);
320 }else if(IsEqualGUID(&IID_IHTMLDOMNode
, riid
)) {
321 TRACE("(%p)->(IID_IHTMLDOMNode %p)\n", This
, ppv
);
322 *ppv
= HTMLDOMNODE(This
);
326 IUnknown_AddRef((IUnknown
*)*ppv
);
330 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
331 return E_NOINTERFACE
;
334 void HTMLDOMNode_destructor(HTMLDOMNode
*This
)
337 nsIDOMNode_Release(This
->nsnode
);
340 static const NodeImplVtbl HTMLDOMNodeImplVtbl
= {
342 HTMLDOMNode_destructor
345 static HTMLDOMNode
*create_node(HTMLDocument
*doc
, nsIDOMNode
*nsnode
)
350 nsIDOMNode_GetNodeType(nsnode
, &node_type
);
354 ret
= &HTMLElement_Create(nsnode
)->node
;
357 ret
= heap_alloc(sizeof(HTMLDOMNode
));
358 ret
->vtbl
= &HTMLDOMNodeImplVtbl
;
361 ret
->lpHTMLDOMNodeVtbl
= &HTMLDOMNodeVtbl
;
365 nsIDOMNode_AddRef(nsnode
);
366 ret
->nsnode
= nsnode
;
373 * List looks really ugly here. We should use a better data structure or
374 * (better) find a way to store HTMLDOMelement poiner in nsIDOMNode.
377 HTMLDOMNode
*get_node(HTMLDocument
*This
, nsIDOMNode
*nsnode
)
379 HTMLDOMNode
*iter
= This
->nodes
, *ret
;
382 if(iter
->nsnode
== nsnode
)
390 ret
= create_node(This
, nsnode
);
392 ret
->next
= This
->nodes
;
398 void release_nodes(HTMLDocument
*This
)
400 HTMLDOMNode
*iter
, *next
;
405 for(iter
= This
->nodes
; iter
; iter
= next
) {
408 IHTMLDOMNode_Release(HTMLDOMNODE(iter
));