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
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
;
57 WARN("%s not supported\n", debugstr_mshtml_guid(riid
));
62 IUnknown_AddRef((IUnknown
*)*ppv
);
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
);
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
);
85 release_dispex(&This
->dispex
);
86 VariantClear(&This
->value
);
87 heap_free(This
->name
);
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
,
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
);
133 FIXME("No name available\n");
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};
152 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&v
));
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
);
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
);
184 TRACE("(%p)->(%p)\n", This
, p
);
186 if(!This
->elem
|| !This
->elem
->dom_element
) {
187 FIXME("NULL This->elem\n");
191 if(get_dispid_type(This
->dispid
) != DISPEXPROP_BUILTIN
) {
196 hres
= IDispatchEx_GetMemberName(&This
->elem
->node
.event_target
.dispex
.IDispatchEx_iface
, This
->dispid
, &name
);
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
);
208 /* If the Gecko attribute node can be found, we know that the attribute is specified.
209 There is no point in calling GetSpecified */
211 nsIDOMAttr_Release(nsattr
);
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
,
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
);
293 static HRESULT WINAPI
HTMLDOMAttribute2_put_value(IHTMLDOMAttribute2
*iface
, BSTR v
)
295 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute2(iface
);
298 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
300 V_VT(&var
) = VT_BSTR
;
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
);
311 TRACE("(%p)->(%p)\n", This
, p
);
313 V_VT(&val
) = VT_EMPTY
;
315 hres
= get_elem_attr_value_by_dispid(This
->elem
, This
->dispid
, &val
);
317 hres
= VariantCopy(&val
, &This
->value
);
319 hres
= attr_value_to_string(&val
);
323 assert(V_VT(&val
) == VT_BSTR
);
325 if(!*p
&& !(*p
= SysAllocStringLen(NULL
, 0)))
326 return E_OUTOFMEMORY
;
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
422 static HRESULT WINAPI
HTMLDOMAttribute2_removeChild(IHTMLDOMAttribute2
*iface
, IHTMLDOMNode
*oldChild
,
425 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute2(iface
);
426 FIXME("(%p)->(%p %p)\n", This
, oldChild
, node
);
430 static HRESULT WINAPI
HTMLDOMAttribute2_appendChild(IHTMLDOMAttribute2
*iface
, IHTMLDOMNode
*newChild
,
433 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute2(iface
);
434 FIXME("(%p)->(%p %p)\n", This
, newChild
, node
);
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
);
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
);
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
= {
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 HTMLAttributeCollection
*col
;
501 HTMLDOMAttribute
*ret
;
504 ret
= heap_alloc_zero(sizeof(*ret
));
506 return E_OUTOFMEMORY
;
508 ret
->IHTMLDOMAttribute_iface
.lpVtbl
= &HTMLDOMAttributeVtbl
;
509 ret
->IHTMLDOMAttribute2_iface
.lpVtbl
= &HTMLDOMAttribute2Vtbl
;
511 ret
->dispid
= dispid
;
514 init_dispex(&ret
->dispex
, (IUnknown
*)&ret
->IHTMLDOMAttribute_iface
,
515 &HTMLDOMAttribute_dispex
);
517 /* For attributes attached to an element, (elem,dispid) pair should be valid used for its operation. */
519 hres
= HTMLElement_get_attr_col(&elem
->node
, &col
);
521 IHTMLDOMAttribute_Release(&ret
->IHTMLDOMAttribute_iface
);
524 IHTMLAttributeCollection_Release(&col
->IHTMLAttributeCollection_iface
);
526 list_add_tail(&elem
->attrs
->attrs
, &ret
->entry
);
529 /* For detached attributes we may still do most operations if we have its name available. */
531 ret
->name
= heap_strdupW(name
);
533 IHTMLDOMAttribute_Release(&ret
->IHTMLDOMAttribute_iface
);
534 return E_OUTOFMEMORY
;