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 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
47 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
48 *ppv
= &This
->IHTMLDOMAttribute_iface
;
49 }else if(IsEqualGUID(&IID_IHTMLDOMAttribute
, riid
)) {
50 TRACE("(%p)->(IID_IHTMLDOMAttribute %p)\n", This
, ppv
);
51 *ppv
= &This
->IHTMLDOMAttribute_iface
;
52 }else if(dispex_query_interface(&This
->dispex
, riid
, ppv
)) {
53 return *ppv
? S_OK
: E_NOINTERFACE
;
55 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
60 IUnknown_AddRef((IUnknown
*)*ppv
);
64 static ULONG WINAPI
HTMLDOMAttribute_AddRef(IHTMLDOMAttribute
*iface
)
66 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute(iface
);
67 LONG ref
= InterlockedIncrement(&This
->ref
);
69 TRACE("(%p) ref=%d\n", This
, ref
);
74 static ULONG WINAPI
HTMLDOMAttribute_Release(IHTMLDOMAttribute
*iface
)
76 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute(iface
);
77 LONG ref
= InterlockedDecrement(&This
->ref
);
79 TRACE("(%p) ref=%d\n", This
, ref
);
83 release_dispex(&This
->dispex
);
84 heap_free(This
->name
);
91 static HRESULT WINAPI
HTMLDOMAttribute_GetTypeInfoCount(IHTMLDOMAttribute
*iface
, UINT
*pctinfo
)
93 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute(iface
);
94 return IDispatchEx_GetTypeInfoCount(&This
->dispex
.IDispatchEx_iface
, pctinfo
);
97 static HRESULT WINAPI
HTMLDOMAttribute_GetTypeInfo(IHTMLDOMAttribute
*iface
, UINT iTInfo
,
98 LCID lcid
, ITypeInfo
**ppTInfo
)
100 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute(iface
);
101 return IDispatchEx_GetTypeInfo(&This
->dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
104 static HRESULT WINAPI
HTMLDOMAttribute_GetIDsOfNames(IHTMLDOMAttribute
*iface
, REFIID riid
,
105 LPOLESTR
*rgszNames
, UINT cNames
,
106 LCID lcid
, DISPID
*rgDispId
)
108 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute(iface
);
109 return IDispatchEx_GetIDsOfNames(&This
->dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
113 static HRESULT WINAPI
HTMLDOMAttribute_Invoke(IHTMLDOMAttribute
*iface
, DISPID dispIdMember
,
114 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
115 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
117 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute(iface
);
118 return IDispatchEx_Invoke(&This
->dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
119 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
122 static HRESULT WINAPI
HTMLDOMAttribute_get_nodeName(IHTMLDOMAttribute
*iface
, BSTR
*p
)
124 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute(iface
);
126 TRACE("(%p)->(%p)\n", This
, p
);
130 FIXME("No name available\n");
134 *p
= SysAllocString(This
->name
);
135 return *p
? S_OK
: E_OUTOFMEMORY
;
138 return IDispatchEx_GetMemberName(&This
->elem
->node
.dispex
.IDispatchEx_iface
, This
->dispid
, p
);
141 static HRESULT WINAPI
HTMLDOMAttribute_put_nodeName(IHTMLDOMAttribute
*iface
, VARIANT v
)
143 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute(iface
);
144 FIXME("(%p)->(%s)\n", This
, debugstr_variant(&v
));
148 static HRESULT WINAPI
HTMLDOMAttribute_get_nodeValue(IHTMLDOMAttribute
*iface
, VARIANT
*p
)
150 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute(iface
);
151 DISPPARAMS dp
= {NULL
, NULL
, 0, 0};
154 TRACE("(%p)->(%p)\n", This
, p
);
157 FIXME("NULL This->elem\n");
161 memset(&ei
, 0, sizeof(ei
));
162 return IDispatchEx_InvokeEx(&This
->elem
->node
.dispex
.IDispatchEx_iface
, This
->dispid
, LOCALE_SYSTEM_DEFAULT
,
163 DISPATCH_PROPERTYGET
, &dp
, p
, &ei
, NULL
);
166 static HRESULT WINAPI
HTMLDOMAttribute_get_specified(IHTMLDOMAttribute
*iface
, VARIANT_BOOL
*p
)
168 HTMLDOMAttribute
*This
= impl_from_IHTMLDOMAttribute(iface
);
175 TRACE("(%p)->(%p)\n", This
, p
);
177 if(!This
->elem
|| !This
->elem
->nselem
) {
178 FIXME("NULL This->elem\n");
182 if(get_dispid_type(This
->dispid
) != DISPEXPROP_BUILTIN
) {
187 hres
= IDispatchEx_GetMemberName(&This
->elem
->node
.dispex
.IDispatchEx_iface
, This
->dispid
, &name
);
191 /* FIXME: This is not exactly right, we have some attributes that don't map directly to Gecko attributes. */
192 nsAString_InitDepend(&nsname
, name
);
193 nsres
= nsIDOMHTMLElement_GetAttributeNode(This
->elem
->nselem
, &nsname
, &nsattr
);
194 nsAString_Finish(&nsname
);
199 /* If the Gecko attribute node can be found, we know that the attribute is specified.
200 There is no point in calling GetSpecified */
202 nsIDOMAttr_Release(nsattr
);
210 static const IHTMLDOMAttributeVtbl HTMLDOMAttributeVtbl
= {
211 HTMLDOMAttribute_QueryInterface
,
212 HTMLDOMAttribute_AddRef
,
213 HTMLDOMAttribute_Release
,
214 HTMLDOMAttribute_GetTypeInfoCount
,
215 HTMLDOMAttribute_GetTypeInfo
,
216 HTMLDOMAttribute_GetIDsOfNames
,
217 HTMLDOMAttribute_Invoke
,
218 HTMLDOMAttribute_get_nodeName
,
219 HTMLDOMAttribute_put_nodeName
,
220 HTMLDOMAttribute_get_nodeValue
,
221 HTMLDOMAttribute_get_specified
224 static const tid_t HTMLDOMAttribute_iface_tids
[] = {
225 IHTMLDOMAttribute_tid
,
228 static dispex_static_data_t HTMLDOMAttribute_dispex
= {
230 DispHTMLDOMAttribute_tid
,
232 HTMLDOMAttribute_iface_tids
235 HRESULT
HTMLDOMAttribute_Create(const WCHAR
*name
, HTMLElement
*elem
, DISPID dispid
, HTMLDOMAttribute
**attr
)
237 HTMLAttributeCollection
*col
;
238 HTMLDOMAttribute
*ret
;
241 ret
= heap_alloc_zero(sizeof(*ret
));
243 return E_OUTOFMEMORY
;
245 ret
->IHTMLDOMAttribute_iface
.lpVtbl
= &HTMLDOMAttributeVtbl
;
247 ret
->dispid
= dispid
;
250 init_dispex(&ret
->dispex
, (IUnknown
*)&ret
->IHTMLDOMAttribute_iface
,
251 &HTMLDOMAttribute_dispex
);
253 /* For attributes attached to an element, (elem,dispid) pair should be valid used for its operation. */
255 hres
= HTMLElement_get_attr_col(&elem
->node
, &col
);
257 IHTMLDOMAttribute_Release(&ret
->IHTMLDOMAttribute_iface
);
260 IHTMLAttributeCollection_Release(&col
->IHTMLAttributeCollection_iface
);
262 list_add_tail(&elem
->attrs
->attrs
, &ret
->entry
);
265 /* For detached attributes we may still do most operations if we have its name available. */
267 ret
->name
= heap_strdupW(name
);
269 IHTMLDOMAttribute_Release(&ret
->IHTMLDOMAttribute_iface
);
270 return E_OUTOFMEMORY
;