urlmon: Improve ObtainUserAgentString conformance to native.
[wine.git] / dlls / mshtml / htmlnode.c
blobc226db3942076deade94a97790121763cea4c2f7
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 "config.h"
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "winnls.h"
30 #include "ole2.h"
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);
46 HRESULT hres;
48 if(This->impl.unk)
49 return IUnknown_QueryInterface(This->impl.unk, riid, ppv);
51 hres = HTMLDOMNode_QI(This, riid, ppv);
52 if(FAILED(hres))
53 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
55 return hres;
58 static ULONG WINAPI HTMLDOMNode_AddRef(IHTMLDOMNode *iface)
60 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
62 if(This->impl.unk)
63 return IUnknown_AddRef(This->impl.unk);
65 TRACE("(%p)\n", This);
66 return IHTMLDocument2_AddRef(HTMLDOC(This->doc));
69 static ULONG WINAPI HTMLDOMNode_Release(IHTMLDOMNode *iface)
71 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
73 if(This->impl.unk)
74 return IUnknown_Release(This->impl.unk);
76 TRACE("(%p)\n", This);
77 return IHTMLDocument2_Release(HTMLDOC(This->doc));
80 static HRESULT WINAPI HTMLDOMNode_GetTypeInfoCount(IHTMLDOMNode *iface, UINT *pctinfo)
82 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
83 FIXME("(%p)->(%p)\n", This, pctinfo);
84 return E_NOTIMPL;
87 static HRESULT WINAPI HTMLDOMNode_GetTypeInfo(IHTMLDOMNode *iface, UINT iTInfo,
88 LCID lcid, ITypeInfo **ppTInfo)
90 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
91 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
92 return E_NOTIMPL;
95 static HRESULT WINAPI HTMLDOMNode_GetIDsOfNames(IHTMLDOMNode *iface, REFIID riid,
96 LPOLESTR *rgszNames, UINT cNames,
97 LCID lcid, DISPID *rgDispId)
99 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
100 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
101 lcid, rgDispId);
102 return E_NOTIMPL;
105 static HRESULT WINAPI HTMLDOMNode_Invoke(IHTMLDOMNode *iface, DISPID dispIdMember,
106 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
107 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
109 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
110 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
111 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
112 return E_NOTIMPL;
115 static HRESULT WINAPI HTMLDOMNode_get_nodeType(IHTMLDOMNode *iface, long *p)
117 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
118 FIXME("(%p)->(%p)\n", This, p);
119 return E_NOTIMPL;
122 static HRESULT WINAPI HTMLDOMNode_get_parentNode(IHTMLDOMNode *iface, IHTMLDOMNode **p)
124 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
125 FIXME("(%p)->(%p)\n", This, p);
126 return E_NOTIMPL;
129 static HRESULT WINAPI HTMLDOMNode_hasChildNodes(IHTMLDOMNode *iface, VARIANT_BOOL *fChildren)
131 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
132 FIXME("(%p)->(%p)\n", This, fChildren);
133 return E_NOTIMPL;
136 static HRESULT WINAPI HTMLDOMNode_get_childNodes(IHTMLDOMNode *iface, IDispatch **p)
138 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
139 FIXME("(%p)->(%p)\n", This, p);
140 return E_NOTIMPL;
143 static HRESULT WINAPI HTMLDOMNode_get_attributes(IHTMLDOMNode *iface, IDispatch **p)
145 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
146 FIXME("(%p)->(%p)\n", This, p);
147 return E_NOTIMPL;
150 static HRESULT WINAPI HTMLDOMNode_insertBefore(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
151 VARIANT refChild, IHTMLDOMNode **node)
153 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
154 FIXME("(%p)->(%p v %p)\n", This, newChild, node);
155 return E_NOTIMPL;
158 static HRESULT WINAPI HTMLDOMNode_removeChild(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
159 IHTMLDOMNode **node)
161 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
162 FIXME("(%p)->(%p %p)\n", This, newChild, node);
163 return E_NOTIMPL;
166 static HRESULT WINAPI HTMLDOMNode_replaceChild(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
167 IHTMLDOMNode *oldChild, IHTMLDOMNode **node)
169 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
170 FIXME("(%p)->(%p %p %p)\n", This, newChild, oldChild, node);
171 return E_NOTIMPL;
174 static HRESULT WINAPI HTMLDOMNode_cloneNode(IHTMLDOMNode *iface, VARIANT_BOOL fDeep,
175 IHTMLDOMNode **clonedNode)
177 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
178 FIXME("(%p)->(%x %p)\n", This, fDeep, clonedNode);
179 return E_NOTIMPL;
182 static HRESULT WINAPI HTMLDOMNode_removeNode(IHTMLDOMNode *iface, VARIANT_BOOL fDeep,
183 IHTMLDOMNode **removed)
185 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
186 FIXME("(%p)->(%x %p)\n", This, fDeep, removed);
187 return E_NOTIMPL;
190 static HRESULT WINAPI HTMLDOMNode_swapNode(IHTMLDOMNode *iface, IHTMLDOMNode *otherNode,
191 IHTMLDOMNode **swappedNode)
193 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
194 FIXME("(%p)->(%p %p)\n", This, otherNode, swappedNode);
195 return E_NOTIMPL;
198 static HRESULT WINAPI HTMLDOMNode_replaceNode(IHTMLDOMNode *iface, IHTMLDOMNode *replacement,
199 IHTMLDOMNode **replaced)
201 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
202 FIXME("(%p)->(%p %p)\n", This, replacement, replaced);
203 return E_NOTIMPL;
206 static HRESULT WINAPI HTMLDOMNode_appendChild(IHTMLDOMNode *iface, IHTMLDOMNode *newChild,
207 IHTMLDOMNode **node)
209 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
210 FIXME("(%p)->(%p %p)\n", This, newChild, node);
211 return E_NOTIMPL;
214 static HRESULT WINAPI HTMLDOMNode_get_nodeName(IHTMLDOMNode *iface, BSTR *p)
216 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
218 TRACE("(%p)->(%p)\n", This, p);
220 *p = NULL;
222 if(This->nsnode) {
223 nsAString name_str;
224 const PRUnichar *name;
225 nsresult nsres;
227 nsAString_Init(&name_str, NULL);
228 nsres = nsIDOMNode_GetNodeName(This->nsnode, &name_str);
230 if(NS_SUCCEEDED(nsres)) {
231 nsAString_GetData(&name_str, &name, NULL);
232 *p = SysAllocString(name);
233 }else {
234 ERR("GetNodeName failed: %08x\n", nsres);
237 nsAString_Finish(&name_str);
240 return S_OK;
243 static HRESULT WINAPI HTMLDOMNode_put_nodeValue(IHTMLDOMNode *iface, VARIANT v)
245 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
246 FIXME("(%p)->()\n", This);
247 return E_NOTIMPL;
250 static HRESULT WINAPI HTMLDOMNode_get_nodeValue(IHTMLDOMNode *iface, VARIANT *p)
252 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
253 FIXME("(%p)->(%p)\n", This, p);
254 return E_NOTIMPL;
257 static HRESULT WINAPI HTMLDOMNode_get_firstChild(IHTMLDOMNode *iface, IHTMLDOMNode **p)
259 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
260 FIXME("(%p)->(%p)\n", This, p);
261 return E_NOTIMPL;
264 static HRESULT WINAPI HTMLDOMNode_get_lastChild(IHTMLDOMNode *iface, IHTMLDOMNode **p)
266 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
267 FIXME("(%p)->(%p)\n", This, p);
268 return E_NOTIMPL;
271 static HRESULT WINAPI HTMLDOMNode_get_previousSibling(IHTMLDOMNode *iface, IHTMLDOMNode **p)
273 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
274 FIXME("(%p)->(%p)\n", This, p);
275 return E_NOTIMPL;
278 static HRESULT WINAPI HTMLDOMNode_get_nextSibling(IHTMLDOMNode *iface, IHTMLDOMNode **p)
280 HTMLDOMNode *This = HTMLDOMNODE_THIS(iface);
281 FIXME("(%p)->(%p)\n", This, p);
282 return E_NOTIMPL;
285 static const IHTMLDOMNodeVtbl HTMLDOMNodeVtbl = {
286 HTMLDOMNode_QueryInterface,
287 HTMLDOMNode_AddRef,
288 HTMLDOMNode_Release,
289 HTMLDOMNode_GetTypeInfoCount,
290 HTMLDOMNode_GetTypeInfo,
291 HTMLDOMNode_GetIDsOfNames,
292 HTMLDOMNode_Invoke,
293 HTMLDOMNode_get_nodeType,
294 HTMLDOMNode_get_parentNode,
295 HTMLDOMNode_hasChildNodes,
296 HTMLDOMNode_get_childNodes,
297 HTMLDOMNode_get_attributes,
298 HTMLDOMNode_insertBefore,
299 HTMLDOMNode_removeChild,
300 HTMLDOMNode_replaceChild,
301 HTMLDOMNode_cloneNode,
302 HTMLDOMNode_removeNode,
303 HTMLDOMNode_swapNode,
304 HTMLDOMNode_replaceNode,
305 HTMLDOMNode_appendChild,
306 HTMLDOMNode_get_nodeName,
307 HTMLDOMNode_put_nodeValue,
308 HTMLDOMNode_get_nodeValue,
309 HTMLDOMNode_get_firstChild,
310 HTMLDOMNode_get_lastChild,
311 HTMLDOMNode_get_previousSibling,
312 HTMLDOMNode_get_nextSibling
315 HRESULT HTMLDOMNode_QI(HTMLDOMNode *This, REFIID riid, void **ppv)
317 *ppv = NULL;
319 if(IsEqualGUID(&IID_IUnknown, riid)) {
320 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
321 *ppv = HTMLDOMNODE(This);
322 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
323 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
324 *ppv = HTMLDOMNODE(This);
325 }else if(IsEqualGUID(&IID_IHTMLDOMNode, riid)) {
326 TRACE("(%p)->(IID_IHTMLDOMNode %p)\n", This, ppv);
327 *ppv = HTMLDOMNODE(This);
330 if(*ppv) {
331 IUnknown_AddRef((IUnknown*)*ppv);
332 return S_OK;
335 return E_NOINTERFACE;
339 * FIXME
340 * List looks really ugly here. We should use a better data structure or
341 * (better) find a way to store HTMLDOMelement poiner in nsIDOMNode.
344 HTMLDOMNode *get_node(HTMLDocument *This, nsIDOMNode *nsnode)
346 HTMLDOMNode *iter = This->nodes, *ret;
347 PRUint16 node_type;
349 while(iter) {
350 if(iter->nsnode == nsnode)
351 break;
352 iter = iter->next;
355 if(iter)
356 return iter;
358 ret = mshtml_alloc(sizeof(HTMLDOMNode));
359 ret->lpHTMLDOMNodeVtbl = &HTMLDOMNodeVtbl;
360 ret->node_type = NT_UNKNOWN;
361 ret->impl.unk = NULL;
362 ret->destructor = NULL;
363 ret->doc = This;
365 nsIDOMNode_AddRef(nsnode);
366 ret->nsnode = nsnode;
368 ret->next = This->nodes;
369 This->nodes = ret;
371 nsIDOMNode_GetNodeType(nsnode, &node_type);
373 if(node_type == NS_ELEMENT_NODE
374 || node_type == NS_DOCUMENT_NODE)
375 HTMLElement_Create(ret);
377 return ret;
380 void release_nodes(HTMLDocument *This)
382 HTMLDOMNode *iter, *next;
384 if(!This->nodes)
385 return;
387 for(iter = This->nodes; iter; iter = next) {
388 next = iter->next;
389 if(iter->destructor)
390 iter->destructor(iter->impl.unk);
391 nsIDOMNode_Release(iter->nsnode);
392 mshtml_free(iter);