wimgapi: Add new stub dll.
[wine.git] / dlls / mshtml / htmlattr.c
blob0302ee9a56b8dfc161710026a2cd066a43f496de
1 /*
2 * Copyright 2011 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
20 #include <stdarg.h>
21 #include <assert.h>
23 #define COBJMACROS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "ole2.h"
30 #include "mshtml_private.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
36 static inline HTMLDOMAttribute *impl_from_IHTMLDOMAttribute(IHTMLDOMAttribute *iface)
38 return CONTAINING_RECORD(iface, HTMLDOMAttribute, IHTMLDOMAttribute_iface);
41 static HRESULT WINAPI HTMLDOMAttribute_QueryInterface(IHTMLDOMAttribute *iface,
42 REFIID riid, void **ppv)
44 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface);
46 TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
48 if(IsEqualGUID(&IID_IUnknown, riid)) {
49 *ppv = &This->IHTMLDOMAttribute_iface;
50 }else if(IsEqualGUID(&IID_IHTMLDOMAttribute, riid)) {
51 *ppv = &This->IHTMLDOMAttribute_iface;
52 }else if(IsEqualGUID(&IID_IHTMLDOMAttribute2, riid)) {
53 *ppv = &This->IHTMLDOMAttribute2_iface;
54 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
55 return *ppv ? S_OK : E_NOINTERFACE;
56 }else {
57 WARN("%s not supported\n", debugstr_mshtml_guid(riid));
58 *ppv = NULL;
59 return E_NOINTERFACE;
62 IUnknown_AddRef((IUnknown*)*ppv);
63 return S_OK;
66 static ULONG WINAPI HTMLDOMAttribute_AddRef(IHTMLDOMAttribute *iface)
68 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface);
69 LONG ref = InterlockedIncrement(&This->ref);
71 TRACE("(%p) ref=%d\n", This, ref);
73 return ref;
76 static ULONG WINAPI HTMLDOMAttribute_Release(IHTMLDOMAttribute *iface)
78 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface);
79 LONG ref = InterlockedDecrement(&This->ref);
81 TRACE("(%p) ref=%d\n", This, ref);
83 if(!ref) {
84 assert(!This->elem);
85 release_dispex(&This->dispex);
86 heap_free(This->name);
87 heap_free(This);
90 return ref;
93 static HRESULT WINAPI HTMLDOMAttribute_GetTypeInfoCount(IHTMLDOMAttribute *iface, UINT *pctinfo)
95 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface);
96 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
99 static HRESULT WINAPI HTMLDOMAttribute_GetTypeInfo(IHTMLDOMAttribute *iface, UINT iTInfo,
100 LCID lcid, ITypeInfo **ppTInfo)
102 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface);
103 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
106 static HRESULT WINAPI HTMLDOMAttribute_GetIDsOfNames(IHTMLDOMAttribute *iface, REFIID riid,
107 LPOLESTR *rgszNames, UINT cNames,
108 LCID lcid, DISPID *rgDispId)
110 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface);
111 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
112 lcid, rgDispId);
115 static HRESULT WINAPI HTMLDOMAttribute_Invoke(IHTMLDOMAttribute *iface, DISPID dispIdMember,
116 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
117 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
119 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface);
120 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
121 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
124 static HRESULT WINAPI HTMLDOMAttribute_get_nodeName(IHTMLDOMAttribute *iface, BSTR *p)
126 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface);
128 TRACE("(%p)->(%p)\n", This, p);
130 if(!This->elem) {
131 if(!This->name) {
132 FIXME("No name available\n");
133 return E_FAIL;
136 *p = SysAllocString(This->name);
137 return *p ? S_OK : E_OUTOFMEMORY;
140 return IDispatchEx_GetMemberName(&This->elem->node.event_target.dispex.IDispatchEx_iface, This->dispid, p);
143 static HRESULT WINAPI HTMLDOMAttribute_put_nodeValue(IHTMLDOMAttribute *iface, VARIANT v)
145 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface);
146 DISPID dispidNamed = DISPID_PROPERTYPUT;
147 DISPPARAMS dp = {&v, &dispidNamed, 1, 1};
148 EXCEPINFO ei;
149 VARIANT ret;
151 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
153 if(!This->elem) {
154 FIXME("NULL This->elem\n");
155 return E_UNEXPECTED;
158 memset(&ei, 0, sizeof(ei));
160 return IDispatchEx_InvokeEx(&This->elem->node.event_target.dispex.IDispatchEx_iface, This->dispid, LOCALE_SYSTEM_DEFAULT,
161 DISPATCH_PROPERTYPUT, &dp, &ret, &ei, NULL);
164 static HRESULT WINAPI HTMLDOMAttribute_get_nodeValue(IHTMLDOMAttribute *iface, VARIANT *p)
166 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface);
168 TRACE("(%p)->(%p)\n", This, p);
170 if(!This->elem) {
171 FIXME("NULL This->elem\n");
172 return E_UNEXPECTED;
175 return get_elem_attr_value_by_dispid(This->elem, This->dispid, 0, p);
178 static HRESULT WINAPI HTMLDOMAttribute_get_specified(IHTMLDOMAttribute *iface, VARIANT_BOOL *p)
180 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface);
181 nsIDOMAttr *nsattr;
182 nsAString nsname;
183 BSTR name;
184 nsresult nsres;
185 HRESULT hres;
187 TRACE("(%p)->(%p)\n", This, p);
189 if(!This->elem || !This->elem->nselem) {
190 FIXME("NULL This->elem\n");
191 return E_UNEXPECTED;
194 if(get_dispid_type(This->dispid) != DISPEXPROP_BUILTIN) {
195 *p = VARIANT_TRUE;
196 return S_OK;
199 hres = IDispatchEx_GetMemberName(&This->elem->node.event_target.dispex.IDispatchEx_iface, This->dispid, &name);
200 if(FAILED(hres))
201 return hres;
203 /* FIXME: This is not exactly right, we have some attributes that don't map directly to Gecko attributes. */
204 nsAString_InitDepend(&nsname, name);
205 nsres = nsIDOMHTMLElement_GetAttributeNode(This->elem->nselem, &nsname, &nsattr);
206 nsAString_Finish(&nsname);
207 SysFreeString(name);
208 if(NS_FAILED(nsres))
209 return E_FAIL;
211 /* If the Gecko attribute node can be found, we know that the attribute is specified.
212 There is no point in calling GetSpecified */
213 if(nsattr) {
214 nsIDOMAttr_Release(nsattr);
215 *p = VARIANT_TRUE;
216 }else {
217 *p = VARIANT_FALSE;
219 return S_OK;
222 static const IHTMLDOMAttributeVtbl HTMLDOMAttributeVtbl = {
223 HTMLDOMAttribute_QueryInterface,
224 HTMLDOMAttribute_AddRef,
225 HTMLDOMAttribute_Release,
226 HTMLDOMAttribute_GetTypeInfoCount,
227 HTMLDOMAttribute_GetTypeInfo,
228 HTMLDOMAttribute_GetIDsOfNames,
229 HTMLDOMAttribute_Invoke,
230 HTMLDOMAttribute_get_nodeName,
231 HTMLDOMAttribute_put_nodeValue,
232 HTMLDOMAttribute_get_nodeValue,
233 HTMLDOMAttribute_get_specified
236 static inline HTMLDOMAttribute *impl_from_IHTMLDOMAttribute2(IHTMLDOMAttribute2 *iface)
238 return CONTAINING_RECORD(iface, HTMLDOMAttribute, IHTMLDOMAttribute2_iface);
241 static HRESULT WINAPI HTMLDOMAttribute2_QueryInterface(IHTMLDOMAttribute2 *iface, REFIID riid, void **ppv)
243 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
244 return IHTMLDOMAttribute_QueryInterface(&This->IHTMLDOMAttribute_iface, riid, ppv);
247 static ULONG WINAPI HTMLDOMAttribute2_AddRef(IHTMLDOMAttribute2 *iface)
249 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
250 return IHTMLDOMAttribute_AddRef(&This->IHTMLDOMAttribute_iface);
253 static ULONG WINAPI HTMLDOMAttribute2_Release(IHTMLDOMAttribute2 *iface)
255 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
256 return IHTMLDOMAttribute_Release(&This->IHTMLDOMAttribute_iface);
259 static HRESULT WINAPI HTMLDOMAttribute2_GetTypeInfoCount(IHTMLDOMAttribute2 *iface, UINT *pctinfo)
261 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
262 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
265 static HRESULT WINAPI HTMLDOMAttribute2_GetTypeInfo(IHTMLDOMAttribute2 *iface, UINT iTInfo,
266 LCID lcid, ITypeInfo **ppTInfo)
268 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
269 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
272 static HRESULT WINAPI HTMLDOMAttribute2_GetIDsOfNames(IHTMLDOMAttribute2 *iface, REFIID riid,
273 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
275 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
276 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
277 lcid, rgDispId);
280 static HRESULT WINAPI HTMLDOMAttribute2_Invoke(IHTMLDOMAttribute2 *iface, DISPID dispIdMember,
281 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
282 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
284 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
285 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
286 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
289 static HRESULT WINAPI HTMLDOMAttribute2_get_name(IHTMLDOMAttribute2 *iface, BSTR *p)
291 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
292 FIXME("(%p)->(%p)\n", This, p);
293 return E_NOTIMPL;
296 static HRESULT WINAPI HTMLDOMAttribute2_put_value(IHTMLDOMAttribute2 *iface, BSTR v)
298 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
299 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
300 return E_NOTIMPL;
303 static HRESULT WINAPI HTMLDOMAttribute2_get_value(IHTMLDOMAttribute2 *iface, BSTR *p)
305 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
306 VARIANT val;
307 HRESULT hres;
309 TRACE("(%p)->(%p)\n", This, p);
311 if(!This->elem) {
312 FIXME("NULL This->elem\n");
313 return E_UNEXPECTED;
316 hres = get_elem_attr_value_by_dispid(This->elem, This->dispid, ATTRFLAG_ASSTRING, &val);
317 if(FAILED(hres))
318 return hres;
320 assert(V_VT(&val) == VT_BSTR);
321 *p = V_BSTR(&val);
322 if(!*p && !(*p = SysAllocStringLen(NULL, 0)))
323 return E_OUTOFMEMORY;
324 return S_OK;
327 static HRESULT WINAPI HTMLDOMAttribute2_get_expando(IHTMLDOMAttribute2 *iface, VARIANT_BOOL *p)
329 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
331 TRACE("(%p)->(%p)\n", This, p);
333 *p = get_dispid_type(This->dispid) == DISPEXPROP_BUILTIN ? VARIANT_FALSE : VARIANT_TRUE;
334 return S_OK;
337 static HRESULT WINAPI HTMLDOMAttribute2_get_nodeType(IHTMLDOMAttribute2 *iface, LONG *p)
339 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
340 FIXME("(%p)->(%p)\n", This, p);
341 return E_NOTIMPL;
344 static HRESULT WINAPI HTMLDOMAttribute2_get_parentNode(IHTMLDOMAttribute2 *iface, IHTMLDOMNode **p)
346 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
347 FIXME("(%p)->(%p)\n", This, p);
348 return E_NOTIMPL;
351 static HRESULT WINAPI HTMLDOMAttribute2_get_childNodes(IHTMLDOMAttribute2 *iface, IDispatch **p)
353 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
354 FIXME("(%p)->(%p)\n", This, p);
355 return E_NOTIMPL;
358 static HRESULT WINAPI HTMLDOMAttribute2_get_firstChild(IHTMLDOMAttribute2 *iface, IHTMLDOMNode **p)
360 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
361 FIXME("(%p)->(%p)\n", This, p);
362 return E_NOTIMPL;
365 static HRESULT WINAPI HTMLDOMAttribute2_get_lastChild(IHTMLDOMAttribute2 *iface, IHTMLDOMNode **p)
367 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
368 FIXME("(%p)->(%p)\n", This, p);
369 return E_NOTIMPL;
372 static HRESULT WINAPI HTMLDOMAttribute2_get_previousSibling(IHTMLDOMAttribute2 *iface, IHTMLDOMNode **p)
374 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
375 FIXME("(%p)->(%p)\n", This, p);
376 return E_NOTIMPL;
379 static HRESULT WINAPI HTMLDOMAttribute2_get_nextSibling(IHTMLDOMAttribute2 *iface, IHTMLDOMNode **p)
381 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
382 FIXME("(%p)->(%p)\n", This, p);
383 return E_NOTIMPL;
386 static HRESULT WINAPI HTMLDOMAttribute2_get_attributes(IHTMLDOMAttribute2 *iface, IDispatch **p)
388 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
389 FIXME("(%p)->(%p)\n", This, p);
390 return E_NOTIMPL;
393 static HRESULT WINAPI HTMLDOMAttribute2_get_ownerDocument(IHTMLDOMAttribute2 *iface, IDispatch **p)
395 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
396 FIXME("(%p)->(%p)\n", This, p);
397 return E_NOTIMPL;
400 static HRESULT WINAPI HTMLDOMAttribute2_insertBefore(IHTMLDOMAttribute2 *iface, IHTMLDOMNode *newChild,
401 VARIANT refChild, IHTMLDOMNode **node)
403 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
404 FIXME("(%p)->(%p %s %p)\n", This, newChild, debugstr_variant(&refChild), node);
405 return E_NOTIMPL;
408 static HRESULT WINAPI HTMLDOMAttribute2_replaceChild(IHTMLDOMAttribute2 *iface, IHTMLDOMNode *newChild,
409 IHTMLDOMNode *oldChild, IHTMLDOMNode **node)
411 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
412 FIXME("(%p)->(%p %p %p)\n", This, newChild, oldChild, node);
413 return E_NOTIMPL;
416 static HRESULT WINAPI HTMLDOMAttribute2_removeChild(IHTMLDOMAttribute2 *iface, IHTMLDOMNode *oldChild,
417 IHTMLDOMNode **node)
419 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
420 FIXME("(%p)->(%p %p)\n", This, oldChild, node);
421 return E_NOTIMPL;
424 static HRESULT WINAPI HTMLDOMAttribute2_appendChild(IHTMLDOMAttribute2 *iface, IHTMLDOMNode *newChild,
425 IHTMLDOMNode **node)
427 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
428 FIXME("(%p)->(%p %p)\n", This, newChild, node);
429 return E_NOTIMPL;
432 static HRESULT WINAPI HTMLDOMAttribute2_hasChildNodes(IHTMLDOMAttribute2 *iface, VARIANT_BOOL *fChildren)
434 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
435 FIXME("(%p)->(%p)\n", This, fChildren);
436 return E_NOTIMPL;
439 static HRESULT WINAPI HTMLDOMAttribute2_cloneNode(IHTMLDOMAttribute2 *iface, VARIANT_BOOL fDeep,
440 IHTMLDOMAttribute **clonedNode)
442 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
443 FIXME("(%p)->(%x %p)\n", This, fDeep, clonedNode);
444 return E_NOTIMPL;
447 static const IHTMLDOMAttribute2Vtbl HTMLDOMAttribute2Vtbl = {
448 HTMLDOMAttribute2_QueryInterface,
449 HTMLDOMAttribute2_AddRef,
450 HTMLDOMAttribute2_Release,
451 HTMLDOMAttribute2_GetTypeInfoCount,
452 HTMLDOMAttribute2_GetTypeInfo,
453 HTMLDOMAttribute2_GetIDsOfNames,
454 HTMLDOMAttribute2_Invoke,
455 HTMLDOMAttribute2_get_name,
456 HTMLDOMAttribute2_put_value,
457 HTMLDOMAttribute2_get_value,
458 HTMLDOMAttribute2_get_expando,
459 HTMLDOMAttribute2_get_nodeType,
460 HTMLDOMAttribute2_get_parentNode,
461 HTMLDOMAttribute2_get_childNodes,
462 HTMLDOMAttribute2_get_firstChild,
463 HTMLDOMAttribute2_get_lastChild,
464 HTMLDOMAttribute2_get_previousSibling,
465 HTMLDOMAttribute2_get_nextSibling,
466 HTMLDOMAttribute2_get_attributes,
467 HTMLDOMAttribute2_get_ownerDocument,
468 HTMLDOMAttribute2_insertBefore,
469 HTMLDOMAttribute2_replaceChild,
470 HTMLDOMAttribute2_removeChild,
471 HTMLDOMAttribute2_appendChild,
472 HTMLDOMAttribute2_hasChildNodes,
473 HTMLDOMAttribute2_cloneNode
476 static const tid_t HTMLDOMAttribute_iface_tids[] = {
477 IHTMLDOMAttribute_tid,
478 IHTMLDOMAttribute2_tid,
481 static dispex_static_data_t HTMLDOMAttribute_dispex = {
482 NULL,
483 DispHTMLDOMAttribute_tid,
485 HTMLDOMAttribute_iface_tids
488 HRESULT HTMLDOMAttribute_Create(const WCHAR *name, HTMLElement *elem, DISPID dispid, HTMLDOMAttribute **attr)
490 HTMLAttributeCollection *col;
491 HTMLDOMAttribute *ret;
492 HRESULT hres;
494 ret = heap_alloc_zero(sizeof(*ret));
495 if(!ret)
496 return E_OUTOFMEMORY;
498 ret->IHTMLDOMAttribute_iface.lpVtbl = &HTMLDOMAttributeVtbl;
499 ret->IHTMLDOMAttribute2_iface.lpVtbl = &HTMLDOMAttribute2Vtbl;
500 ret->ref = 1;
501 ret->dispid = dispid;
502 ret->elem = elem;
504 init_dispex(&ret->dispex, (IUnknown*)&ret->IHTMLDOMAttribute_iface,
505 &HTMLDOMAttribute_dispex);
507 /* For attributes attached to an element, (elem,dispid) pair should be valid used for its operation. */
508 if(elem) {
509 hres = HTMLElement_get_attr_col(&elem->node, &col);
510 if(FAILED(hres)) {
511 IHTMLDOMAttribute_Release(&ret->IHTMLDOMAttribute_iface);
512 return hres;
514 IHTMLAttributeCollection_Release(&col->IHTMLAttributeCollection_iface);
516 list_add_tail(&elem->attrs->attrs, &ret->entry);
519 /* For detached attributes we may still do most operations if we have its name available. */
520 if(name) {
521 ret->name = heap_strdupW(name);
522 if(!ret->name) {
523 IHTMLDOMAttribute_Release(&ret->IHTMLDOMAttribute_iface);
524 return E_OUTOFMEMORY;
528 *attr = ret;
529 return S_OK;