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 heap_free(This
->name
);
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
,
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
);
132 FIXME("No name available\n");
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};
151 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&v
));
154 FIXME("NULL This->elem\n");
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
);
171 FIXME("NULL This->elem\n");
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
);
187 TRACE("(%p)->(%p)\n", This
, p
);
189 if(!This
->elem
|| !This
->elem
->nselem
) {
190 FIXME("NULL This->elem\n");
194 if(get_dispid_type(This
->dispid
) != DISPEXPROP_BUILTIN
) {
199 hres
= IDispatchEx_GetMemberName(&This
->elem
->node
.event_target
.dispex
.IDispatchEx_iface
, This
->dispid
, &name
);
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
);
211 /* If the Gecko attribute node can be found, we know that the attribute is specified.
212 There is no point in calling GetSpecified */
214 nsIDOMAttr_Release(nsattr
);
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
,
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
);
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
));
303 static HRESULT WINAPI
HTMLDOMAttribute2_get_value(IHTMLDOMAttribute2
*iface
, BSTR
*p
)
305 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute2(iface
);
309 TRACE("(%p)->(%p)\n", This
, p
);
312 FIXME("NULL This->elem\n");
316 hres
= get_elem_attr_value_by_dispid(This
->elem
, This
->dispid
, ATTRFLAG_ASSTRING
, &val
);
320 assert(V_VT(&val
) == VT_BSTR
);
322 if(!*p
&& !(*p
= SysAllocStringLen(NULL
, 0)))
323 return E_OUTOFMEMORY
;
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
;
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
416 static HRESULT WINAPI
HTMLDOMAttribute2_removeChild(IHTMLDOMAttribute2
*iface
, IHTMLDOMNode
*oldChild
,
419 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute2(iface
);
420 FIXME("(%p)->(%p %p)\n", This
, oldChild
, node
);
424 static HRESULT WINAPI
HTMLDOMAttribute2_appendChild(IHTMLDOMAttribute2
*iface
, IHTMLDOMNode
*newChild
,
427 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute2(iface
);
428 FIXME("(%p)->(%p %p)\n", This
, newChild
, node
);
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
);
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
);
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
= {
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
;
494 ret
= heap_alloc_zero(sizeof(*ret
));
496 return E_OUTOFMEMORY
;
498 ret
->IHTMLDOMAttribute_iface
.lpVtbl
= &HTMLDOMAttributeVtbl
;
499 ret
->IHTMLDOMAttribute2_iface
.lpVtbl
= &HTMLDOMAttribute2Vtbl
;
501 ret
->dispid
= dispid
;
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. */
509 hres
= HTMLElement_get_attr_col(&elem
->node
, &col
);
511 IHTMLDOMAttribute_Release(&ret
->IHTMLDOMAttribute_iface
);
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. */
521 ret
->name
= heap_strdupW(name
);
523 IHTMLDOMAttribute_Release(&ret
->IHTMLDOMAttribute_iface
);
524 return E_OUTOFMEMORY
;