2 * Copyright 2012 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
28 #include "wine/debug.h"
30 #include "mshtml_private.h"
31 #include "htmlevent.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
35 struct HTMLLinkElement
{
37 IHTMLLinkElement IHTMLLinkElement_iface
;
39 nsIDOMHTMLLinkElement
*nslink
;
42 static inline HTMLLinkElement
*impl_from_IHTMLLinkElement(IHTMLLinkElement
*iface
)
44 return CONTAINING_RECORD(iface
, HTMLLinkElement
, IHTMLLinkElement_iface
);
47 static HRESULT WINAPI
HTMLLinkElement_QueryInterface(IHTMLLinkElement
*iface
,
48 REFIID riid
, void **ppv
)
50 HTMLLinkElement
*This
= impl_from_IHTMLLinkElement(iface
);
52 return IHTMLDOMNode_QueryInterface(&This
->element
.node
.IHTMLDOMNode_iface
, riid
, ppv
);
55 static ULONG WINAPI
HTMLLinkElement_AddRef(IHTMLLinkElement
*iface
)
57 HTMLLinkElement
*This
= impl_from_IHTMLLinkElement(iface
);
59 return IHTMLDOMNode_AddRef(&This
->element
.node
.IHTMLDOMNode_iface
);
62 static ULONG WINAPI
HTMLLinkElement_Release(IHTMLLinkElement
*iface
)
64 HTMLLinkElement
*This
= impl_from_IHTMLLinkElement(iface
);
66 return IHTMLDOMNode_Release(&This
->element
.node
.IHTMLDOMNode_iface
);
69 static HRESULT WINAPI
HTMLLinkElement_GetTypeInfoCount(IHTMLLinkElement
*iface
, UINT
*pctinfo
)
71 HTMLLinkElement
*This
= impl_from_IHTMLLinkElement(iface
);
73 return IDispatchEx_GetTypeInfoCount(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, pctinfo
);
76 static HRESULT WINAPI
HTMLLinkElement_GetTypeInfo(IHTMLLinkElement
*iface
, UINT iTInfo
,
77 LCID lcid
, ITypeInfo
**ppTInfo
)
79 HTMLLinkElement
*This
= impl_from_IHTMLLinkElement(iface
);
81 return IDispatchEx_GetTypeInfo(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, iTInfo
, lcid
,
85 static HRESULT WINAPI
HTMLLinkElement_GetIDsOfNames(IHTMLLinkElement
*iface
, REFIID riid
,
86 LPOLESTR
*rgszNames
, UINT cNames
,
87 LCID lcid
, DISPID
*rgDispId
)
89 HTMLLinkElement
*This
= impl_from_IHTMLLinkElement(iface
);
91 return IDispatchEx_GetIDsOfNames(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, riid
, rgszNames
,
92 cNames
, lcid
, rgDispId
);
95 static HRESULT WINAPI
HTMLLinkElement_Invoke(IHTMLLinkElement
*iface
, DISPID dispIdMember
,
96 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
97 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
99 HTMLLinkElement
*This
= impl_from_IHTMLLinkElement(iface
);
101 return IDispatchEx_Invoke(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, dispIdMember
, riid
,
102 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
105 static HRESULT WINAPI
HTMLLinkElement_put_href(IHTMLLinkElement
*iface
, BSTR v
)
107 HTMLLinkElement
*This
= impl_from_IHTMLLinkElement(iface
);
111 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
113 nsAString_InitDepend(&href_str
, v
);
114 nsres
= nsIDOMHTMLLinkElement_SetHref(This
->nslink
, &href_str
);
115 nsAString_Finish(&href_str
);
117 return NS_SUCCEEDED(nsres
) ? S_OK
: E_FAIL
;
120 static HRESULT WINAPI
HTMLLinkElement_get_href(IHTMLLinkElement
*iface
, BSTR
*p
)
122 HTMLLinkElement
*This
= impl_from_IHTMLLinkElement(iface
);
126 TRACE("(%p)->(%p)\n", This
, p
);
128 nsAString_Init(&href_str
, NULL
);
129 nsres
= nsIDOMHTMLLinkElement_GetHref(This
->nslink
, &href_str
);
130 return return_nsstr(nsres
, &href_str
, p
);
133 static HRESULT WINAPI
HTMLLinkElement_put_rel(IHTMLLinkElement
*iface
, BSTR v
)
135 HTMLLinkElement
*This
= impl_from_IHTMLLinkElement(iface
);
139 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
141 nsAString_InitDepend(&rel_str
, v
);
142 nsres
= nsIDOMHTMLLinkElement_SetRel(This
->nslink
, &rel_str
);
143 nsAString_Finish(&rel_str
);
145 return NS_SUCCEEDED(nsres
) ? S_OK
: E_FAIL
;
148 static HRESULT WINAPI
HTMLLinkElement_get_rel(IHTMLLinkElement
*iface
, BSTR
*p
)
150 HTMLLinkElement
*This
= impl_from_IHTMLLinkElement(iface
);
154 TRACE("(%p)->(%p)\n", This
, p
);
156 nsAString_Init(&rel_str
, NULL
);
157 nsres
= nsIDOMHTMLLinkElement_GetRel(This
->nslink
, &rel_str
);
158 return return_nsstr(nsres
, &rel_str
, p
);
161 static HRESULT WINAPI
HTMLLinkElement_put_rev(IHTMLLinkElement
*iface
, BSTR v
)
163 HTMLLinkElement
*This
= impl_from_IHTMLLinkElement(iface
);
167 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
169 nsAString_InitDepend(&nsstr
, v
);
170 nsres
= nsIDOMHTMLLinkElement_SetRev(This
->nslink
, &nsstr
);
171 nsAString_Finish(&nsstr
);
172 if(NS_FAILED(nsres
)) {
173 ERR("SetRev failed: %08lx\n", nsres
);
180 static HRESULT WINAPI
HTMLLinkElement_get_rev(IHTMLLinkElement
*iface
, BSTR
*p
)
182 HTMLLinkElement
*This
= impl_from_IHTMLLinkElement(iface
);
186 TRACE("(%p)->(%p)\n", This
, p
);
188 nsAString_Init(&nsstr
, NULL
);
189 nsres
= nsIDOMHTMLLinkElement_GetRev(This
->nslink
, &nsstr
);
190 return return_nsstr(nsres
, &nsstr
, p
);
193 static HRESULT WINAPI
HTMLLinkElement_put_type(IHTMLLinkElement
*iface
, BSTR v
)
195 HTMLLinkElement
*This
= impl_from_IHTMLLinkElement(iface
);
199 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
201 nsAString_InitDepend(&type_str
, v
);
202 nsres
= nsIDOMHTMLLinkElement_SetType(This
->nslink
, &type_str
);
203 nsAString_Finish(&type_str
);
205 return NS_SUCCEEDED(nsres
) ? S_OK
: E_FAIL
;
208 static HRESULT WINAPI
HTMLLinkElement_get_type(IHTMLLinkElement
*iface
, BSTR
*p
)
210 HTMLLinkElement
*This
= impl_from_IHTMLLinkElement(iface
);
214 TRACE("(%p)->(%p)\n", This
, p
);
216 nsAString_Init(&type_str
, NULL
);
217 nsres
= nsIDOMHTMLLinkElement_GetType(This
->nslink
, &type_str
);
218 return return_nsstr(nsres
, &type_str
, p
);
221 static HRESULT WINAPI
HTMLLinkElement_get_readyState(IHTMLLinkElement
*iface
, BSTR
*p
)
223 HTMLLinkElement
*This
= impl_from_IHTMLLinkElement(iface
);
224 FIXME("(%p)->(%p)\n", This
, p
);
228 static HRESULT WINAPI
HTMLLinkElement_put_onreadystatechange(IHTMLLinkElement
*iface
, VARIANT v
)
230 HTMLLinkElement
*This
= impl_from_IHTMLLinkElement(iface
);
231 FIXME("(%p)->(%s)\n", This
, debugstr_variant(&v
));
235 static HRESULT WINAPI
HTMLLinkElement_get_onreadystatechange(IHTMLLinkElement
*iface
, VARIANT
*p
)
237 HTMLLinkElement
*This
= impl_from_IHTMLLinkElement(iface
);
238 FIXME("(%p)->(%p)\n", This
, p
);
242 static HRESULT WINAPI
HTMLLinkElement_put_onload(IHTMLLinkElement
*iface
, VARIANT v
)
244 HTMLLinkElement
*This
= impl_from_IHTMLLinkElement(iface
);
246 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&v
));
248 return set_node_event(&This
->element
.node
, EVENTID_LOAD
, &v
);
251 static HRESULT WINAPI
HTMLLinkElement_get_onload(IHTMLLinkElement
*iface
, VARIANT
*p
)
253 HTMLLinkElement
*This
= impl_from_IHTMLLinkElement(iface
);
255 TRACE("(%p)->(%p)\n", This
, p
);
257 return get_node_event(&This
->element
.node
, EVENTID_LOAD
, p
);
260 static HRESULT WINAPI
HTMLLinkElement_put_onerror(IHTMLLinkElement
*iface
, VARIANT v
)
262 HTMLLinkElement
*This
= impl_from_IHTMLLinkElement(iface
);
263 FIXME("(%p)->(%s)\n", This
, debugstr_variant(&v
));
267 static HRESULT WINAPI
HTMLLinkElement_get_onerror(IHTMLLinkElement
*iface
, VARIANT
*p
)
269 HTMLLinkElement
*This
= impl_from_IHTMLLinkElement(iface
);
270 FIXME("(%p)->(%p)\n", This
, p
);
274 static HRESULT WINAPI
HTMLLinkElement_get_styleSheet(IHTMLLinkElement
*iface
, IHTMLStyleSheet
**p
)
276 HTMLLinkElement
*This
= impl_from_IHTMLLinkElement(iface
);
277 FIXME("(%p)->(%p)\n", This
, p
);
281 static HRESULT WINAPI
HTMLLinkElement_put_disabled(IHTMLLinkElement
*iface
, VARIANT_BOOL v
)
283 HTMLLinkElement
*This
= impl_from_IHTMLLinkElement(iface
);
286 TRACE("(%p)->(%x)\n", This
, v
);
288 nsres
= nsIDOMHTMLLinkElement_SetDisabled(This
->nslink
, !!v
);
289 return SUCCEEDED(nsres
) ? S_OK
: E_FAIL
;
292 static HRESULT WINAPI
HTMLLinkElement_get_disabled(IHTMLLinkElement
*iface
, VARIANT_BOOL
*p
)
294 HTMLLinkElement
*This
= impl_from_IHTMLLinkElement(iface
);
298 TRACE("(%p)->(%p)\n", This
, p
);
300 nsres
= nsIDOMHTMLLinkElement_GetDisabled(This
->nslink
, &ret
);
304 *p
= variant_bool(ret
);
308 static HRESULT WINAPI
HTMLLinkElement_put_media(IHTMLLinkElement
*iface
, BSTR v
)
310 HTMLLinkElement
*This
= impl_from_IHTMLLinkElement(iface
);
314 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
316 nsAString_InitDepend(&str
, v
);
318 nsres
= nsIDOMHTMLLinkElement_SetMedia(This
->nslink
, &str
);
319 nsAString_Finish(&str
);
321 if(NS_FAILED(nsres
)) {
322 ERR("Set Media(%s) failed: %08lx\n", debugstr_w(v
), nsres
);
328 static HRESULT WINAPI
HTMLLinkElement_get_media(IHTMLLinkElement
*iface
, BSTR
*p
)
330 HTMLLinkElement
*This
= impl_from_IHTMLLinkElement(iface
);
334 TRACE("(%p)->(%p)\n", This
, p
);
336 nsAString_Init(&str
, NULL
);
337 nsres
= nsIDOMHTMLLinkElement_GetMedia(This
->nslink
, &str
);
339 return return_nsstr(nsres
, &str
, p
);
342 static const IHTMLLinkElementVtbl HTMLLinkElementVtbl
= {
343 HTMLLinkElement_QueryInterface
,
344 HTMLLinkElement_AddRef
,
345 HTMLLinkElement_Release
,
346 HTMLLinkElement_GetTypeInfoCount
,
347 HTMLLinkElement_GetTypeInfo
,
348 HTMLLinkElement_GetIDsOfNames
,
349 HTMLLinkElement_Invoke
,
350 HTMLLinkElement_put_href
,
351 HTMLLinkElement_get_href
,
352 HTMLLinkElement_put_rel
,
353 HTMLLinkElement_get_rel
,
354 HTMLLinkElement_put_rev
,
355 HTMLLinkElement_get_rev
,
356 HTMLLinkElement_put_type
,
357 HTMLLinkElement_get_type
,
358 HTMLLinkElement_get_readyState
,
359 HTMLLinkElement_put_onreadystatechange
,
360 HTMLLinkElement_get_onreadystatechange
,
361 HTMLLinkElement_put_onload
,
362 HTMLLinkElement_get_onload
,
363 HTMLLinkElement_put_onerror
,
364 HTMLLinkElement_get_onerror
,
365 HTMLLinkElement_get_styleSheet
,
366 HTMLLinkElement_put_disabled
,
367 HTMLLinkElement_get_disabled
,
368 HTMLLinkElement_put_media
,
369 HTMLLinkElement_get_media
372 static inline HTMLLinkElement
*impl_from_HTMLDOMNode(HTMLDOMNode
*iface
)
374 return CONTAINING_RECORD(iface
, HTMLLinkElement
, element
.node
);
377 static HRESULT
HTMLLinkElement_QI(HTMLDOMNode
*iface
, REFIID riid
, void **ppv
)
379 HTMLLinkElement
*This
= impl_from_HTMLDOMNode(iface
);
381 if(IsEqualGUID(&IID_IHTMLLinkElement
, riid
)) {
382 TRACE("(%p)->(IID_IHTMLLinkElement %p)\n", This
, ppv
);
383 *ppv
= &This
->IHTMLLinkElement_iface
;
385 return HTMLElement_QI(&This
->element
.node
, riid
, ppv
);
388 IUnknown_AddRef((IUnknown
*)*ppv
);
392 static HRESULT
HTMLLinkElementImpl_put_disabled(HTMLDOMNode
*iface
, VARIANT_BOOL v
)
394 HTMLLinkElement
*This
= impl_from_HTMLDOMNode(iface
);
395 return IHTMLLinkElement_put_disabled(&This
->IHTMLLinkElement_iface
, v
);
398 static HRESULT
HTMLLinkElementImpl_get_disabled(HTMLDOMNode
*iface
, VARIANT_BOOL
*p
)
400 HTMLLinkElement
*This
= impl_from_HTMLDOMNode(iface
);
401 return IHTMLLinkElement_get_disabled(&This
->IHTMLLinkElement_iface
, p
);
404 static void HTMLLinkElement_traverse(HTMLDOMNode
*iface
, nsCycleCollectionTraversalCallback
*cb
)
406 HTMLLinkElement
*This
= impl_from_HTMLDOMNode(iface
);
409 note_cc_edge((nsISupports
*)This
->nslink
, "This->nslink", cb
);
412 static void HTMLLinkElement_unlink(HTMLDOMNode
*iface
)
414 HTMLLinkElement
*This
= impl_from_HTMLDOMNode(iface
);
417 nsIDOMHTMLLinkElement
*nslink
= This
->nslink
;
420 nsIDOMHTMLLinkElement_Release(nslink
);
423 static const NodeImplVtbl HTMLLinkElementImplVtbl
= {
424 &CLSID_HTMLLinkElement
,
426 HTMLElement_destructor
,
429 HTMLElement_handle_event
,
430 HTMLElement_get_attr_col
,
432 HTMLLinkElementImpl_put_disabled
,
433 HTMLLinkElementImpl_get_disabled
,
439 HTMLLinkElement_traverse
,
440 HTMLLinkElement_unlink
443 static const tid_t HTMLLinkElement_iface_tids
[] = {
445 IHTMLLinkElement_tid
,
448 static dispex_static_data_t HTMLLinkElement_dispex
= {
451 DispHTMLLinkElement_tid
,
452 HTMLLinkElement_iface_tids
,
453 HTMLElement_init_dispex_info
456 HRESULT
HTMLLinkElement_Create(HTMLDocumentNode
*doc
, nsIDOMElement
*nselem
, HTMLElement
**elem
)
458 HTMLLinkElement
*ret
;
461 ret
= heap_alloc_zero(sizeof(*ret
));
463 return E_OUTOFMEMORY
;
465 ret
->IHTMLLinkElement_iface
.lpVtbl
= &HTMLLinkElementVtbl
;
466 ret
->element
.node
.vtbl
= &HTMLLinkElementImplVtbl
;
468 HTMLElement_Init(&ret
->element
, doc
, nselem
, &HTMLLinkElement_dispex
);
470 nsres
= nsIDOMElement_QueryInterface(nselem
, &IID_nsIDOMHTMLLinkElement
, (void**)&ret
->nslink
);
471 assert(nsres
== NS_OK
);
473 *elem
= &ret
->element
;