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
19 #include "mshtml_private.h"
21 static inline HTMLDOMAttribute
*impl_from_IHTMLDOMAttribute(IHTMLDOMAttribute
*iface
)
23 return CONTAINING_RECORD(iface
, HTMLDOMAttribute
, IHTMLDOMAttribute_iface
);
26 static HRESULT WINAPI
HTMLDOMAttribute_QueryInterface(IHTMLDOMAttribute
*iface
,
27 REFIID riid
, void **ppv
)
29 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute(iface
);
31 TRACE("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
33 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
34 *ppv
= &This
->IHTMLDOMAttribute_iface
;
35 }else if(IsEqualGUID(&IID_IHTMLDOMAttribute
, riid
)) {
36 *ppv
= &This
->IHTMLDOMAttribute_iface
;
37 }else if(IsEqualGUID(&IID_IHTMLDOMAttribute2
, riid
)) {
38 *ppv
= &This
->IHTMLDOMAttribute2_iface
;
39 }else if(dispex_query_interface(&This
->dispex
, riid
, ppv
)) {
40 return *ppv
? S_OK
: E_NOINTERFACE
;
42 WARN("%s not supported\n", debugstr_mshtml_guid(riid
));
47 IUnknown_AddRef((IUnknown
*)*ppv
);
51 static ULONG WINAPI
HTMLDOMAttribute_AddRef(IHTMLDOMAttribute
*iface
)
53 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute(iface
);
54 LONG ref
= InterlockedIncrement(&This
->ref
);
56 TRACE("(%p) ref=%d\n", This
, ref
);
61 static ULONG WINAPI
HTMLDOMAttribute_Release(IHTMLDOMAttribute
*iface
)
63 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute(iface
);
64 LONG ref
= InterlockedDecrement(&This
->ref
);
66 TRACE("(%p) ref=%d\n", This
, ref
);
70 release_dispex(&This
->dispex
);
71 heap_free(This
->name
);
78 static HRESULT WINAPI
HTMLDOMAttribute_GetTypeInfoCount(IHTMLDOMAttribute
*iface
, UINT
*pctinfo
)
80 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute(iface
);
81 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
84 static HRESULT WINAPI
HTMLDOMAttribute_GetTypeInfo(IHTMLDOMAttribute
*iface
, UINT iTInfo
,
85 LCID lcid
, ITypeInfo
**ppTInfo
)
87 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute(iface
);
88 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
91 static HRESULT WINAPI
HTMLDOMAttribute_GetIDsOfNames(IHTMLDOMAttribute
*iface
, REFIID riid
,
92 LPOLESTR
*rgszNames
, UINT cNames
,
93 LCID lcid
, DISPID
*rgDispId
)
95 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute(iface
);
96 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
100 static HRESULT WINAPI
HTMLDOMAttribute_Invoke(IHTMLDOMAttribute
*iface
, DISPID dispIdMember
,
101 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
102 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
104 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute(iface
);
105 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
106 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
109 static HRESULT WINAPI
HTMLDOMAttribute_get_nodeName(IHTMLDOMAttribute
*iface
, BSTR
*p
)
111 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute(iface
);
113 TRACE("(%p)->(%p)\n", This
, p
);
117 FIXME("No name available\n");
121 *p
= SysAllocString(This
->name
);
122 return *p
? S_OK
: E_OUTOFMEMORY
;
125 return IDispatchEx_GetMemberName(&This
->elem
->node
.event_target
.dispex
.IDispatchEx_iface
, This
->dispid
, p
);
128 static HRESULT WINAPI
HTMLDOMAttribute_put_nodeValue(IHTMLDOMAttribute
*iface
, VARIANT v
)
130 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute(iface
);
131 DISPID dispidNamed
= DISPID_PROPERTYPUT
;
132 DISPPARAMS dp
= {&v
, &dispidNamed
, 1, 1};
136 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&v
));
139 FIXME("NULL This->elem\n");
143 memset(&ei
, 0, sizeof(ei
));
145 return IDispatchEx_InvokeEx(&This
->elem
->node
.event_target
.dispex
.IDispatchEx_iface
, This
->dispid
, LOCALE_SYSTEM_DEFAULT
,
146 DISPATCH_PROPERTYPUT
, &dp
, &ret
, &ei
, NULL
);
149 static HRESULT WINAPI
HTMLDOMAttribute_get_nodeValue(IHTMLDOMAttribute
*iface
, VARIANT
*p
)
151 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute(iface
);
153 TRACE("(%p)->(%p)\n", This
, p
);
156 FIXME("NULL This->elem\n");
160 return get_elem_attr_value_by_dispid(This
->elem
, This
->dispid
, 0, p
);
163 static HRESULT WINAPI
HTMLDOMAttribute_get_specified(IHTMLDOMAttribute
*iface
, VARIANT_BOOL
*p
)
165 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute(iface
);
172 TRACE("(%p)->(%p)\n", This
, p
);
174 if(!This
->elem
|| !This
->elem
->nselem
) {
175 FIXME("NULL This->elem\n");
179 if(get_dispid_type(This
->dispid
) != DISPEXPROP_BUILTIN
) {
184 hres
= IDispatchEx_GetMemberName(&This
->elem
->node
.event_target
.dispex
.IDispatchEx_iface
, This
->dispid
, &name
);
188 /* FIXME: This is not exactly right, we have some attributes that don't map directly to Gecko attributes. */
189 nsAString_InitDepend(&nsname
, name
);
190 nsres
= nsIDOMHTMLElement_GetAttributeNode(This
->elem
->nselem
, &nsname
, &nsattr
);
191 nsAString_Finish(&nsname
);
196 /* If the Gecko attribute node can be found, we know that the attribute is specified.
197 There is no point in calling GetSpecified */
199 nsIDOMAttr_Release(nsattr
);
207 static const IHTMLDOMAttributeVtbl HTMLDOMAttributeVtbl
= {
208 HTMLDOMAttribute_QueryInterface
,
209 HTMLDOMAttribute_AddRef
,
210 HTMLDOMAttribute_Release
,
211 HTMLDOMAttribute_GetTypeInfoCount
,
212 HTMLDOMAttribute_GetTypeInfo
,
213 HTMLDOMAttribute_GetIDsOfNames
,
214 HTMLDOMAttribute_Invoke
,
215 HTMLDOMAttribute_get_nodeName
,
216 HTMLDOMAttribute_put_nodeValue
,
217 HTMLDOMAttribute_get_nodeValue
,
218 HTMLDOMAttribute_get_specified
221 static inline HTMLDOMAttribute
*impl_from_IHTMLDOMAttribute2(IHTMLDOMAttribute2
*iface
)
223 return CONTAINING_RECORD(iface
, HTMLDOMAttribute
, IHTMLDOMAttribute2_iface
);
226 static HRESULT WINAPI
HTMLDOMAttribute2_QueryInterface(IHTMLDOMAttribute2
*iface
, REFIID riid
, void **ppv
)
228 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute2(iface
);
229 return IHTMLDOMAttribute_QueryInterface(&This
->IHTMLDOMAttribute_iface
, riid
, ppv
);
232 static ULONG WINAPI
HTMLDOMAttribute2_AddRef(IHTMLDOMAttribute2
*iface
)
234 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute2(iface
);
235 return IHTMLDOMAttribute_AddRef(&This
->IHTMLDOMAttribute_iface
);
238 static ULONG WINAPI
HTMLDOMAttribute2_Release(IHTMLDOMAttribute2
*iface
)
240 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute2(iface
);
241 return IHTMLDOMAttribute_Release(&This
->IHTMLDOMAttribute_iface
);
244 static HRESULT WINAPI
HTMLDOMAttribute2_GetTypeInfoCount(IHTMLDOMAttribute2
*iface
, UINT
*pctinfo
)
246 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute2(iface
);
247 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
250 static HRESULT WINAPI
HTMLDOMAttribute2_GetTypeInfo(IHTMLDOMAttribute2
*iface
, UINT iTInfo
,
251 LCID lcid
, ITypeInfo
**ppTInfo
)
253 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute2(iface
);
254 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
257 static HRESULT WINAPI
HTMLDOMAttribute2_GetIDsOfNames(IHTMLDOMAttribute2
*iface
, REFIID riid
,
258 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
260 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute2(iface
);
261 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
265 static HRESULT WINAPI
HTMLDOMAttribute2_Invoke(IHTMLDOMAttribute2
*iface
, DISPID dispIdMember
,
266 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
267 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
269 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute2(iface
);
270 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
271 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
274 static HRESULT WINAPI
HTMLDOMAttribute2_get_name(IHTMLDOMAttribute2
*iface
, BSTR
*p
)
276 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute2(iface
);
277 FIXME("(%p)->(%p)\n", This
, p
);
281 static HRESULT WINAPI
HTMLDOMAttribute2_put_value(IHTMLDOMAttribute2
*iface
, BSTR v
)
283 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute2(iface
);
284 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
288 static HRESULT WINAPI
HTMLDOMAttribute2_get_value(IHTMLDOMAttribute2
*iface
, BSTR
*p
)
290 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute2(iface
);
294 TRACE("(%p)->(%p)\n", This
, p
);
297 FIXME("NULL This->elem\n");
301 hres
= get_elem_attr_value_by_dispid(This
->elem
, This
->dispid
, ATTRFLAG_ASSTRING
, &val
);
305 assert(V_VT(&val
) == VT_BSTR
);
307 if(!*p
&& !(*p
= SysAllocStringLen(NULL
, 0)))
308 return E_OUTOFMEMORY
;
312 static HRESULT WINAPI
HTMLDOMAttribute2_get_expando(IHTMLDOMAttribute2
*iface
, VARIANT_BOOL
*p
)
314 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute2(iface
);
316 TRACE("(%p)->(%p)\n", This
, p
);
318 *p
= get_dispid_type(This
->dispid
) == DISPEXPROP_BUILTIN
? VARIANT_FALSE
: VARIANT_TRUE
;
322 static HRESULT WINAPI
HTMLDOMAttribute2_get_nodeType(IHTMLDOMAttribute2
*iface
, LONG
*p
)
324 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute2(iface
);
325 FIXME("(%p)->(%p)\n", This
, p
);
329 static HRESULT WINAPI
HTMLDOMAttribute2_get_parentNode(IHTMLDOMAttribute2
*iface
, IHTMLDOMNode
**p
)
331 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute2(iface
);
332 FIXME("(%p)->(%p)\n", This
, p
);
336 static HRESULT WINAPI
HTMLDOMAttribute2_get_childNodes(IHTMLDOMAttribute2
*iface
, IDispatch
**p
)
338 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute2(iface
);
339 FIXME("(%p)->(%p)\n", This
, p
);
343 static HRESULT WINAPI
HTMLDOMAttribute2_get_firstChild(IHTMLDOMAttribute2
*iface
, IHTMLDOMNode
**p
)
345 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute2(iface
);
346 FIXME("(%p)->(%p)\n", This
, p
);
350 static HRESULT WINAPI
HTMLDOMAttribute2_get_lastChild(IHTMLDOMAttribute2
*iface
, IHTMLDOMNode
**p
)
352 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute2(iface
);
353 FIXME("(%p)->(%p)\n", This
, p
);
357 static HRESULT WINAPI
HTMLDOMAttribute2_get_previousSibling(IHTMLDOMAttribute2
*iface
, IHTMLDOMNode
**p
)
359 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute2(iface
);
360 FIXME("(%p)->(%p)\n", This
, p
);
364 static HRESULT WINAPI
HTMLDOMAttribute2_get_nextSibling(IHTMLDOMAttribute2
*iface
, IHTMLDOMNode
**p
)
366 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute2(iface
);
367 FIXME("(%p)->(%p)\n", This
, p
);
371 static HRESULT WINAPI
HTMLDOMAttribute2_get_attributes(IHTMLDOMAttribute2
*iface
, IDispatch
**p
)
373 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute2(iface
);
374 FIXME("(%p)->(%p)\n", This
, p
);
378 static HRESULT WINAPI
HTMLDOMAttribute2_get_ownerDocument(IHTMLDOMAttribute2
*iface
, IDispatch
**p
)
380 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute2(iface
);
381 FIXME("(%p)->(%p)\n", This
, p
);
385 static HRESULT WINAPI
HTMLDOMAttribute2_insertBefore(IHTMLDOMAttribute2
*iface
, IHTMLDOMNode
*newChild
,
386 VARIANT refChild
, IHTMLDOMNode
**node
)
388 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute2(iface
);
389 FIXME("(%p)->(%p %s %p)\n", This
, newChild
, debugstr_variant(&refChild
), node
);
393 static HRESULT WINAPI
HTMLDOMAttribute2_replaceChild(IHTMLDOMAttribute2
*iface
, IHTMLDOMNode
*newChild
,
394 IHTMLDOMNode
*oldChild
, IHTMLDOMNode
**node
)
396 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute2(iface
);
397 FIXME("(%p)->(%p %p %p)\n", This
, newChild
, oldChild
, node
);
401 static HRESULT WINAPI
HTMLDOMAttribute2_removeChild(IHTMLDOMAttribute2
*iface
, IHTMLDOMNode
*oldChild
,
404 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute2(iface
);
405 FIXME("(%p)->(%p %p)\n", This
, oldChild
, node
);
409 static HRESULT WINAPI
HTMLDOMAttribute2_appendChild(IHTMLDOMAttribute2
*iface
, IHTMLDOMNode
*newChild
,
412 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute2(iface
);
413 FIXME("(%p)->(%p %p)\n", This
, newChild
, node
);
417 static HRESULT WINAPI
HTMLDOMAttribute2_hasChildNodes(IHTMLDOMAttribute2
*iface
, VARIANT_BOOL
*fChildren
)
419 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute2(iface
);
420 FIXME("(%p)->(%p)\n", This
, fChildren
);
424 static HRESULT WINAPI
HTMLDOMAttribute2_cloneNode(IHTMLDOMAttribute2
*iface
, VARIANT_BOOL fDeep
,
425 IHTMLDOMAttribute
**clonedNode
)
427 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute2(iface
);
428 FIXME("(%p)->(%x %p)\n", This
, fDeep
, clonedNode
);
432 static const IHTMLDOMAttribute2Vtbl HTMLDOMAttribute2Vtbl
= {
433 HTMLDOMAttribute2_QueryInterface
,
434 HTMLDOMAttribute2_AddRef
,
435 HTMLDOMAttribute2_Release
,
436 HTMLDOMAttribute2_GetTypeInfoCount
,
437 HTMLDOMAttribute2_GetTypeInfo
,
438 HTMLDOMAttribute2_GetIDsOfNames
,
439 HTMLDOMAttribute2_Invoke
,
440 HTMLDOMAttribute2_get_name
,
441 HTMLDOMAttribute2_put_value
,
442 HTMLDOMAttribute2_get_value
,
443 HTMLDOMAttribute2_get_expando
,
444 HTMLDOMAttribute2_get_nodeType
,
445 HTMLDOMAttribute2_get_parentNode
,
446 HTMLDOMAttribute2_get_childNodes
,
447 HTMLDOMAttribute2_get_firstChild
,
448 HTMLDOMAttribute2_get_lastChild
,
449 HTMLDOMAttribute2_get_previousSibling
,
450 HTMLDOMAttribute2_get_nextSibling
,
451 HTMLDOMAttribute2_get_attributes
,
452 HTMLDOMAttribute2_get_ownerDocument
,
453 HTMLDOMAttribute2_insertBefore
,
454 HTMLDOMAttribute2_replaceChild
,
455 HTMLDOMAttribute2_removeChild
,
456 HTMLDOMAttribute2_appendChild
,
457 HTMLDOMAttribute2_hasChildNodes
,
458 HTMLDOMAttribute2_cloneNode
461 static const tid_t HTMLDOMAttribute_iface_tids
[] = {
462 IHTMLDOMAttribute_tid
,
463 IHTMLDOMAttribute2_tid
,
466 static dispex_static_data_t HTMLDOMAttribute_dispex
= {
468 DispHTMLDOMAttribute_tid
,
470 HTMLDOMAttribute_iface_tids
473 HRESULT
HTMLDOMAttribute_Create(const WCHAR
*name
, HTMLElement
*elem
, DISPID dispid
, HTMLDOMAttribute
**attr
)
475 HTMLAttributeCollection
*col
;
476 HTMLDOMAttribute
*ret
;
479 ret
= heap_alloc_zero(sizeof(*ret
));
481 return E_OUTOFMEMORY
;
483 ret
->IHTMLDOMAttribute_iface
.lpVtbl
= &HTMLDOMAttributeVtbl
;
484 ret
->IHTMLDOMAttribute2_iface
.lpVtbl
= &HTMLDOMAttribute2Vtbl
;
486 ret
->dispid
= dispid
;
489 init_dispex(&ret
->dispex
, (IUnknown
*)&ret
->IHTMLDOMAttribute_iface
,
490 &HTMLDOMAttribute_dispex
);
492 /* For attributes attached to an element, (elem,dispid) pair should be valid used for its operation. */
494 hres
= HTMLElement_get_attr_col(&elem
->node
, &col
);
496 IHTMLDOMAttribute_Release(&ret
->IHTMLDOMAttribute_iface
);
499 IHTMLAttributeCollection_Release(&col
->IHTMLAttributeCollection_iface
);
501 list_add_tail(&elem
->attrs
->attrs
, &ret
->entry
);
504 /* For detached attributes we may still do most operations if we have its name available. */
506 ret
->name
= heap_strdupW(name
);
508 IHTMLDOMAttribute_Release(&ret
->IHTMLDOMAttribute_iface
);
509 return E_OUTOFMEMORY
;