evr: Add a forward for MFGetStrideForBitmapInfoHeader().
[wine.git] / dlls / mshtml / htmlattr.c
blob14b79812eb0cc1a233944a36854220eb31a0cc5a
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 VariantClear(&This->value);
87 heap_free(This->name);
88 heap_free(This);
91 return ref;
94 static HRESULT WINAPI HTMLDOMAttribute_GetTypeInfoCount(IHTMLDOMAttribute *iface, UINT *pctinfo)
96 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface);
97 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
100 static HRESULT WINAPI HTMLDOMAttribute_GetTypeInfo(IHTMLDOMAttribute *iface, UINT iTInfo,
101 LCID lcid, ITypeInfo **ppTInfo)
103 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface);
104 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
107 static HRESULT WINAPI HTMLDOMAttribute_GetIDsOfNames(IHTMLDOMAttribute *iface, REFIID riid,
108 LPOLESTR *rgszNames, UINT cNames,
109 LCID lcid, DISPID *rgDispId)
111 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface);
112 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
113 lcid, rgDispId);
116 static HRESULT WINAPI HTMLDOMAttribute_Invoke(IHTMLDOMAttribute *iface, DISPID dispIdMember,
117 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
118 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
120 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface);
121 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
122 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
125 static HRESULT WINAPI HTMLDOMAttribute_get_nodeName(IHTMLDOMAttribute *iface, BSTR *p)
127 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface);
129 TRACE("(%p)->(%p)\n", This, p);
131 if(!This->elem) {
132 if(!This->name) {
133 FIXME("No name available\n");
134 return E_FAIL;
137 *p = SysAllocString(This->name);
138 return *p ? S_OK : E_OUTOFMEMORY;
141 return IDispatchEx_GetMemberName(&This->elem->node.event_target.dispex.IDispatchEx_iface, This->dispid, p);
144 static HRESULT WINAPI HTMLDOMAttribute_put_nodeValue(IHTMLDOMAttribute *iface, VARIANT v)
146 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface);
147 DISPID dispidNamed = DISPID_PROPERTYPUT;
148 DISPPARAMS dp = {&v, &dispidNamed, 1, 1};
149 EXCEPINFO ei;
150 VARIANT ret;
152 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
154 if(!This->elem)
155 return VariantCopy(&This->value, &v);
157 memset(&ei, 0, sizeof(ei));
159 return IDispatchEx_InvokeEx(&This->elem->node.event_target.dispex.IDispatchEx_iface, This->dispid, LOCALE_SYSTEM_DEFAULT,
160 DISPATCH_PROPERTYPUT, &dp, &ret, &ei, NULL);
163 static HRESULT WINAPI HTMLDOMAttribute_get_nodeValue(IHTMLDOMAttribute *iface, VARIANT *p)
165 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface);
167 TRACE("(%p)->(%p)\n", This, p);
169 if(!This->elem)
170 return VariantCopy(p, &This->value);
172 return get_elem_attr_value_by_dispid(This->elem, This->dispid, p);
175 static HRESULT WINAPI HTMLDOMAttribute_get_specified(IHTMLDOMAttribute *iface, VARIANT_BOOL *p)
177 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface);
178 nsIDOMAttr *nsattr;
179 nsAString nsname;
180 BSTR name;
181 nsresult nsres;
182 HRESULT hres;
184 TRACE("(%p)->(%p)\n", This, p);
186 if(!This->elem || !This->elem->dom_element) {
187 FIXME("NULL This->elem\n");
188 return E_UNEXPECTED;
191 if(get_dispid_type(This->dispid) != DISPEXPROP_BUILTIN) {
192 *p = VARIANT_TRUE;
193 return S_OK;
196 hres = IDispatchEx_GetMemberName(&This->elem->node.event_target.dispex.IDispatchEx_iface, This->dispid, &name);
197 if(FAILED(hres))
198 return hres;
200 /* FIXME: This is not exactly right, we have some attributes that don't map directly to Gecko attributes. */
201 nsAString_InitDepend(&nsname, name);
202 nsres = nsIDOMElement_GetAttributeNode(This->elem->dom_element, &nsname, &nsattr);
203 nsAString_Finish(&nsname);
204 SysFreeString(name);
205 if(NS_FAILED(nsres))
206 return E_FAIL;
208 /* If the Gecko attribute node can be found, we know that the attribute is specified.
209 There is no point in calling GetSpecified */
210 if(nsattr) {
211 nsIDOMAttr_Release(nsattr);
212 *p = VARIANT_TRUE;
213 }else {
214 *p = VARIANT_FALSE;
216 return S_OK;
219 static const IHTMLDOMAttributeVtbl HTMLDOMAttributeVtbl = {
220 HTMLDOMAttribute_QueryInterface,
221 HTMLDOMAttribute_AddRef,
222 HTMLDOMAttribute_Release,
223 HTMLDOMAttribute_GetTypeInfoCount,
224 HTMLDOMAttribute_GetTypeInfo,
225 HTMLDOMAttribute_GetIDsOfNames,
226 HTMLDOMAttribute_Invoke,
227 HTMLDOMAttribute_get_nodeName,
228 HTMLDOMAttribute_put_nodeValue,
229 HTMLDOMAttribute_get_nodeValue,
230 HTMLDOMAttribute_get_specified
233 static inline HTMLDOMAttribute *impl_from_IHTMLDOMAttribute2(IHTMLDOMAttribute2 *iface)
235 return CONTAINING_RECORD(iface, HTMLDOMAttribute, IHTMLDOMAttribute2_iface);
238 static HRESULT WINAPI HTMLDOMAttribute2_QueryInterface(IHTMLDOMAttribute2 *iface, REFIID riid, void **ppv)
240 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
241 return IHTMLDOMAttribute_QueryInterface(&This->IHTMLDOMAttribute_iface, riid, ppv);
244 static ULONG WINAPI HTMLDOMAttribute2_AddRef(IHTMLDOMAttribute2 *iface)
246 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
247 return IHTMLDOMAttribute_AddRef(&This->IHTMLDOMAttribute_iface);
250 static ULONG WINAPI HTMLDOMAttribute2_Release(IHTMLDOMAttribute2 *iface)
252 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
253 return IHTMLDOMAttribute_Release(&This->IHTMLDOMAttribute_iface);
256 static HRESULT WINAPI HTMLDOMAttribute2_GetTypeInfoCount(IHTMLDOMAttribute2 *iface, UINT *pctinfo)
258 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
259 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
262 static HRESULT WINAPI HTMLDOMAttribute2_GetTypeInfo(IHTMLDOMAttribute2 *iface, UINT iTInfo,
263 LCID lcid, ITypeInfo **ppTInfo)
265 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
266 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
269 static HRESULT WINAPI HTMLDOMAttribute2_GetIDsOfNames(IHTMLDOMAttribute2 *iface, REFIID riid,
270 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
272 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
273 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
274 lcid, rgDispId);
277 static HRESULT WINAPI HTMLDOMAttribute2_Invoke(IHTMLDOMAttribute2 *iface, DISPID dispIdMember,
278 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
279 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
281 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
282 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
283 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
286 static HRESULT WINAPI HTMLDOMAttribute2_get_name(IHTMLDOMAttribute2 *iface, BSTR *p)
288 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
289 FIXME("(%p)->(%p)\n", This, p);
290 return E_NOTIMPL;
293 static HRESULT WINAPI HTMLDOMAttribute2_put_value(IHTMLDOMAttribute2 *iface, BSTR v)
295 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
296 VARIANT var;
298 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
300 V_VT(&var) = VT_BSTR;
301 V_BSTR(&var) = v;
302 return IHTMLDOMAttribute_put_nodeValue(&This->IHTMLDOMAttribute_iface, var);
305 static HRESULT WINAPI HTMLDOMAttribute2_get_value(IHTMLDOMAttribute2 *iface, BSTR *p)
307 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
308 VARIANT val;
309 HRESULT hres;
311 TRACE("(%p)->(%p)\n", This, p);
313 V_VT(&val) = VT_EMPTY;
314 if(This->elem)
315 hres = get_elem_attr_value_by_dispid(This->elem, This->dispid, &val);
316 else
317 hres = VariantCopy(&val, &This->value);
318 if(SUCCEEDED(hres))
319 hres = attr_value_to_string(&val);
320 if(FAILED(hres))
321 return hres;
323 assert(V_VT(&val) == VT_BSTR);
324 *p = V_BSTR(&val);
325 if(!*p && !(*p = SysAllocStringLen(NULL, 0)))
326 return E_OUTOFMEMORY;
327 return S_OK;
330 static HRESULT WINAPI HTMLDOMAttribute2_get_expando(IHTMLDOMAttribute2 *iface, VARIANT_BOOL *p)
332 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
334 TRACE("(%p)->(%p)\n", This, p);
336 *p = variant_bool(This->elem && get_dispid_type(This->dispid) != DISPEXPROP_BUILTIN);
337 return S_OK;
340 static HRESULT WINAPI HTMLDOMAttribute2_get_nodeType(IHTMLDOMAttribute2 *iface, LONG *p)
342 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
343 FIXME("(%p)->(%p)\n", This, p);
344 return E_NOTIMPL;
347 static HRESULT WINAPI HTMLDOMAttribute2_get_parentNode(IHTMLDOMAttribute2 *iface, IHTMLDOMNode **p)
349 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
351 TRACE("(%p)->(%p)\n", This, p);
353 *p = NULL;
354 return S_OK;
357 static HRESULT WINAPI HTMLDOMAttribute2_get_childNodes(IHTMLDOMAttribute2 *iface, IDispatch **p)
359 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
360 FIXME("(%p)->(%p)\n", This, p);
361 return E_NOTIMPL;
364 static HRESULT WINAPI HTMLDOMAttribute2_get_firstChild(IHTMLDOMAttribute2 *iface, IHTMLDOMNode **p)
366 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
367 FIXME("(%p)->(%p)\n", This, p);
368 return E_NOTIMPL;
371 static HRESULT WINAPI HTMLDOMAttribute2_get_lastChild(IHTMLDOMAttribute2 *iface, IHTMLDOMNode **p)
373 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
374 FIXME("(%p)->(%p)\n", This, p);
375 return E_NOTIMPL;
378 static HRESULT WINAPI HTMLDOMAttribute2_get_previousSibling(IHTMLDOMAttribute2 *iface, IHTMLDOMNode **p)
380 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
381 FIXME("(%p)->(%p)\n", This, p);
382 return E_NOTIMPL;
385 static HRESULT WINAPI HTMLDOMAttribute2_get_nextSibling(IHTMLDOMAttribute2 *iface, IHTMLDOMNode **p)
387 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
388 FIXME("(%p)->(%p)\n", This, p);
389 return E_NOTIMPL;
392 static HRESULT WINAPI HTMLDOMAttribute2_get_attributes(IHTMLDOMAttribute2 *iface, IDispatch **p)
394 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
395 FIXME("(%p)->(%p)\n", This, p);
396 return E_NOTIMPL;
399 static HRESULT WINAPI HTMLDOMAttribute2_get_ownerDocument(IHTMLDOMAttribute2 *iface, IDispatch **p)
401 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
402 FIXME("(%p)->(%p)\n", This, p);
403 return E_NOTIMPL;
406 static HRESULT WINAPI HTMLDOMAttribute2_insertBefore(IHTMLDOMAttribute2 *iface, IHTMLDOMNode *newChild,
407 VARIANT refChild, IHTMLDOMNode **node)
409 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
410 FIXME("(%p)->(%p %s %p)\n", This, newChild, debugstr_variant(&refChild), node);
411 return E_NOTIMPL;
414 static HRESULT WINAPI HTMLDOMAttribute2_replaceChild(IHTMLDOMAttribute2 *iface, IHTMLDOMNode *newChild,
415 IHTMLDOMNode *oldChild, IHTMLDOMNode **node)
417 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
418 FIXME("(%p)->(%p %p %p)\n", This, newChild, oldChild, node);
419 return E_NOTIMPL;
422 static HRESULT WINAPI HTMLDOMAttribute2_removeChild(IHTMLDOMAttribute2 *iface, IHTMLDOMNode *oldChild,
423 IHTMLDOMNode **node)
425 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
426 FIXME("(%p)->(%p %p)\n", This, oldChild, node);
427 return E_NOTIMPL;
430 static HRESULT WINAPI HTMLDOMAttribute2_appendChild(IHTMLDOMAttribute2 *iface, IHTMLDOMNode *newChild,
431 IHTMLDOMNode **node)
433 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
434 FIXME("(%p)->(%p %p)\n", This, newChild, node);
435 return E_NOTIMPL;
438 static HRESULT WINAPI HTMLDOMAttribute2_hasChildNodes(IHTMLDOMAttribute2 *iface, VARIANT_BOOL *fChildren)
440 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
441 FIXME("(%p)->(%p)\n", This, fChildren);
442 return E_NOTIMPL;
445 static HRESULT WINAPI HTMLDOMAttribute2_cloneNode(IHTMLDOMAttribute2 *iface, VARIANT_BOOL fDeep,
446 IHTMLDOMAttribute **clonedNode)
448 HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute2(iface);
449 FIXME("(%p)->(%x %p)\n", This, fDeep, clonedNode);
450 return E_NOTIMPL;
453 static const IHTMLDOMAttribute2Vtbl HTMLDOMAttribute2Vtbl = {
454 HTMLDOMAttribute2_QueryInterface,
455 HTMLDOMAttribute2_AddRef,
456 HTMLDOMAttribute2_Release,
457 HTMLDOMAttribute2_GetTypeInfoCount,
458 HTMLDOMAttribute2_GetTypeInfo,
459 HTMLDOMAttribute2_GetIDsOfNames,
460 HTMLDOMAttribute2_Invoke,
461 HTMLDOMAttribute2_get_name,
462 HTMLDOMAttribute2_put_value,
463 HTMLDOMAttribute2_get_value,
464 HTMLDOMAttribute2_get_expando,
465 HTMLDOMAttribute2_get_nodeType,
466 HTMLDOMAttribute2_get_parentNode,
467 HTMLDOMAttribute2_get_childNodes,
468 HTMLDOMAttribute2_get_firstChild,
469 HTMLDOMAttribute2_get_lastChild,
470 HTMLDOMAttribute2_get_previousSibling,
471 HTMLDOMAttribute2_get_nextSibling,
472 HTMLDOMAttribute2_get_attributes,
473 HTMLDOMAttribute2_get_ownerDocument,
474 HTMLDOMAttribute2_insertBefore,
475 HTMLDOMAttribute2_replaceChild,
476 HTMLDOMAttribute2_removeChild,
477 HTMLDOMAttribute2_appendChild,
478 HTMLDOMAttribute2_hasChildNodes,
479 HTMLDOMAttribute2_cloneNode
482 static const tid_t HTMLDOMAttribute_iface_tids[] = {
483 IHTMLDOMAttribute_tid,
484 IHTMLDOMAttribute2_tid,
487 static dispex_static_data_t HTMLDOMAttribute_dispex = {
488 NULL,
489 DispHTMLDOMAttribute_tid,
490 HTMLDOMAttribute_iface_tids
493 HTMLDOMAttribute *unsafe_impl_from_IHTMLDOMAttribute(IHTMLDOMAttribute *iface)
495 return iface->lpVtbl == &HTMLDOMAttributeVtbl ? impl_from_IHTMLDOMAttribute(iface) : NULL;
498 HRESULT HTMLDOMAttribute_Create(const WCHAR *name, HTMLElement *elem, DISPID dispid, HTMLDOMAttribute **attr)
500 compat_mode_t compat_mode = elem ? dispex_compat_mode(&elem->node.event_target.dispex) : COMPAT_MODE_QUIRKS;
501 HTMLAttributeCollection *col;
502 HTMLDOMAttribute *ret;
503 HRESULT hres;
505 ret = heap_alloc_zero(sizeof(*ret));
506 if(!ret)
507 return E_OUTOFMEMORY;
509 ret->IHTMLDOMAttribute_iface.lpVtbl = &HTMLDOMAttributeVtbl;
510 ret->IHTMLDOMAttribute2_iface.lpVtbl = &HTMLDOMAttribute2Vtbl;
511 ret->ref = 1;
512 ret->dispid = dispid;
513 ret->elem = elem;
515 init_dispatch(&ret->dispex, (IUnknown*)&ret->IHTMLDOMAttribute_iface,
516 &HTMLDOMAttribute_dispex, compat_mode);
518 /* For attributes attached to an element, (elem,dispid) pair should be valid used for its operation. */
519 if(elem) {
520 hres = HTMLElement_get_attr_col(&elem->node, &col);
521 if(FAILED(hres)) {
522 IHTMLDOMAttribute_Release(&ret->IHTMLDOMAttribute_iface);
523 return hres;
525 IHTMLAttributeCollection_Release(&col->IHTMLAttributeCollection_iface);
527 list_add_tail(&elem->attrs->attrs, &ret->entry);
530 /* For detached attributes we may still do most operations if we have its name available. */
531 if(name) {
532 ret->name = heap_strdupW(name);
533 if(!ret->name) {
534 IHTMLDOMAttribute_Release(&ret->IHTMLDOMAttribute_iface);
535 return E_OUTOFMEMORY;
539 *attr = ret;
540 return S_OK;