2 * Copyright 2010 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 "wine/debug.h"
32 #include "mshtml_private.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
37 struct HTMLStyleElement
{
40 IHTMLStyleElement IHTMLStyleElement_iface
;
41 IHTMLStyleElement2 IHTMLStyleElement2_iface
;
43 nsIDOMHTMLStyleElement
*nsstyle
;
44 IHTMLStyleSheet
*style_sheet
;
47 static inline HTMLStyleElement
*impl_from_IHTMLStyleElement(IHTMLStyleElement
*iface
)
49 return CONTAINING_RECORD(iface
, HTMLStyleElement
, IHTMLStyleElement_iface
);
52 static HRESULT WINAPI
HTMLStyleElement_QueryInterface(IHTMLStyleElement
*iface
,
53 REFIID riid
, void **ppv
)
55 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
57 return IHTMLDOMNode_QueryInterface(&This
->element
.node
.IHTMLDOMNode_iface
, riid
, ppv
);
60 static ULONG WINAPI
HTMLStyleElement_AddRef(IHTMLStyleElement
*iface
)
62 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
64 return IHTMLDOMNode_AddRef(&This
->element
.node
.IHTMLDOMNode_iface
);
67 static ULONG WINAPI
HTMLStyleElement_Release(IHTMLStyleElement
*iface
)
69 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
71 return IHTMLDOMNode_Release(&This
->element
.node
.IHTMLDOMNode_iface
);
74 static HRESULT WINAPI
HTMLStyleElement_GetTypeInfoCount(IHTMLStyleElement
*iface
, UINT
*pctinfo
)
76 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
77 return IDispatchEx_GetTypeInfoCount(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, pctinfo
);
80 static HRESULT WINAPI
HTMLStyleElement_GetTypeInfo(IHTMLStyleElement
*iface
, UINT iTInfo
,
81 LCID lcid
, ITypeInfo
**ppTInfo
)
83 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
84 return IDispatchEx_GetTypeInfo(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, iTInfo
, lcid
,
88 static HRESULT WINAPI
HTMLStyleElement_GetIDsOfNames(IHTMLStyleElement
*iface
, REFIID riid
,
89 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
91 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
92 return IDispatchEx_GetIDsOfNames(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, riid
, rgszNames
,
93 cNames
, lcid
, rgDispId
);
96 static HRESULT WINAPI
HTMLStyleElement_Invoke(IHTMLStyleElement
*iface
, DISPID dispIdMember
,
97 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
98 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
100 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(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
HTMLStyleElement_put_type(IHTMLStyleElement
*iface
, BSTR v
)
107 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
111 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
113 nsAString_InitDepend(&type_str
, v
);
114 nsres
= nsIDOMHTMLStyleElement_SetType(This
->nsstyle
, &type_str
);
115 nsAString_Finish(&type_str
);
116 if(NS_FAILED(nsres
)) {
117 ERR("SetType failed: %08x\n", nsres
);
124 static HRESULT WINAPI
HTMLStyleElement_get_type(IHTMLStyleElement
*iface
, BSTR
*p
)
126 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
130 TRACE("(%p)->(%p)\n", This
, p
);
132 nsAString_Init(&nsstr
, NULL
);
133 nsres
= nsIDOMHTMLStyleElement_GetType(This
->nsstyle
, &nsstr
);
134 return return_nsstr(nsres
, &nsstr
, p
);
137 static HRESULT WINAPI
HTMLStyleElement_get_readyState(IHTMLStyleElement
*iface
, BSTR
*p
)
139 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
140 FIXME("(%p)->(%p)\n", This
, p
);
144 static HRESULT WINAPI
HTMLStyleElement_put_onreadystatechange(IHTMLStyleElement
*iface
, VARIANT v
)
146 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
147 FIXME("(%p)->(%s)\n", This
, debugstr_variant(&v
));
151 static HRESULT WINAPI
HTMLStyleElement_get_onreadystatechange(IHTMLStyleElement
*iface
, VARIANT
*p
)
153 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
154 FIXME("(%p)->(%p)\n", This
, p
);
158 static HRESULT WINAPI
HTMLStyleElement_put_onload(IHTMLStyleElement
*iface
, VARIANT v
)
160 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
161 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&v
));
162 return IHTMLElement6_put_onload(&This
->element
.IHTMLElement6_iface
, v
);
165 static HRESULT WINAPI
HTMLStyleElement_get_onload(IHTMLStyleElement
*iface
, VARIANT
*p
)
167 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
168 TRACE("(%p)->(%p)\n", This
, p
);
169 return IHTMLElement6_get_onload(&This
->element
.IHTMLElement6_iface
, p
);
172 static HRESULT WINAPI
HTMLStyleElement_put_onerror(IHTMLStyleElement
*iface
, VARIANT v
)
174 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
175 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&v
));
176 return IHTMLElement6_put_onerror(&This
->element
.IHTMLElement6_iface
, v
);
179 static HRESULT WINAPI
HTMLStyleElement_get_onerror(IHTMLStyleElement
*iface
, VARIANT
*p
)
181 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
182 TRACE("(%p)->(%p)\n", This
, p
);
183 return IHTMLElement6_get_onerror(&This
->element
.IHTMLElement6_iface
, p
);
186 static HRESULT WINAPI
HTMLStyleElement_get_styleSheet(IHTMLStyleElement
*iface
, IHTMLStyleSheet
**p
)
188 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
190 TRACE("(%p)->(%p)\n", This
, p
);
195 if(!This
->style_sheet
) {
196 nsIDOMStyleSheet
*ss
;
199 nsres
= nsIDOMHTMLStyleElement_GetDOMStyleSheet(This
->nsstyle
, &ss
);
200 assert(nsres
== NS_OK
);
203 HRESULT hres
= create_style_sheet(ss
, dispex_compat_mode(&This
->element
.node
.event_target
.dispex
),
205 nsIDOMStyleSheet_Release(ss
);
211 if(This
->style_sheet
)
212 IHTMLStyleSheet_AddRef(This
->style_sheet
);
213 *p
= This
->style_sheet
;
217 static HRESULT WINAPI
HTMLStyleElement_put_disabled(IHTMLStyleElement
*iface
, VARIANT_BOOL v
)
219 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
220 FIXME("(%p)->(%x)\n", This
, v
);
224 static HRESULT WINAPI
HTMLStyleElement_get_disabled(IHTMLStyleElement
*iface
, VARIANT_BOOL
*p
)
226 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
227 FIXME("(%p)->(%p)\n", This
, p
);
231 static HRESULT WINAPI
HTMLStyleElement_put_media(IHTMLStyleElement
*iface
, BSTR v
)
233 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
237 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
239 nsAString_InitDepend(&media_str
, v
);
240 nsres
= nsIDOMHTMLStyleElement_SetMedia(This
->nsstyle
, &media_str
);
241 nsAString_Finish(&media_str
);
242 if(NS_FAILED(nsres
)) {
243 ERR("SetMedia failed: %08x\n", nsres
);
250 static HRESULT WINAPI
HTMLStyleElement_get_media(IHTMLStyleElement
*iface
, BSTR
*p
)
252 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
256 TRACE("(%p)->(%p)\n", This
, p
);
258 nsAString_Init(&nsstr
, NULL
);
259 nsres
= nsIDOMHTMLStyleElement_GetMedia(This
->nsstyle
, &nsstr
);
260 return return_nsstr(nsres
, &nsstr
, p
);
263 static const IHTMLStyleElementVtbl HTMLStyleElementVtbl
= {
264 HTMLStyleElement_QueryInterface
,
265 HTMLStyleElement_AddRef
,
266 HTMLStyleElement_Release
,
267 HTMLStyleElement_GetTypeInfoCount
,
268 HTMLStyleElement_GetTypeInfo
,
269 HTMLStyleElement_GetIDsOfNames
,
270 HTMLStyleElement_Invoke
,
271 HTMLStyleElement_put_type
,
272 HTMLStyleElement_get_type
,
273 HTMLStyleElement_get_readyState
,
274 HTMLStyleElement_put_onreadystatechange
,
275 HTMLStyleElement_get_onreadystatechange
,
276 HTMLStyleElement_put_onload
,
277 HTMLStyleElement_get_onload
,
278 HTMLStyleElement_put_onerror
,
279 HTMLStyleElement_get_onerror
,
280 HTMLStyleElement_get_styleSheet
,
281 HTMLStyleElement_put_disabled
,
282 HTMLStyleElement_get_disabled
,
283 HTMLStyleElement_put_media
,
284 HTMLStyleElement_get_media
287 static inline HTMLStyleElement
*impl_from_IHTMLStyleElement2(IHTMLStyleElement2
*iface
)
289 return CONTAINING_RECORD(iface
, HTMLStyleElement
, IHTMLStyleElement2_iface
);
292 static HRESULT WINAPI
HTMLStyleElement2_QueryInterface(IHTMLStyleElement2
*iface
,
293 REFIID riid
, void **ppv
)
295 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement2(iface
);
297 return IHTMLDOMNode_QueryInterface(&This
->element
.node
.IHTMLDOMNode_iface
, riid
, ppv
);
300 static ULONG WINAPI
HTMLStyleElement2_AddRef(IHTMLStyleElement2
*iface
)
302 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement2(iface
);
304 return IHTMLDOMNode_AddRef(&This
->element
.node
.IHTMLDOMNode_iface
);
307 static ULONG WINAPI
HTMLStyleElement2_Release(IHTMLStyleElement2
*iface
)
309 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement2(iface
);
311 return IHTMLDOMNode_Release(&This
->element
.node
.IHTMLDOMNode_iface
);
314 static HRESULT WINAPI
HTMLStyleElement2_GetTypeInfoCount(IHTMLStyleElement2
*iface
, UINT
*pctinfo
)
316 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement2(iface
);
317 return IDispatchEx_GetTypeInfoCount(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, pctinfo
);
320 static HRESULT WINAPI
HTMLStyleElement2_GetTypeInfo(IHTMLStyleElement2
*iface
, UINT iTInfo
,
321 LCID lcid
, ITypeInfo
**ppTInfo
)
323 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement2(iface
);
324 return IDispatchEx_GetTypeInfo(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, iTInfo
, lcid
,
328 static HRESULT WINAPI
HTMLStyleElement2_GetIDsOfNames(IHTMLStyleElement2
*iface
, REFIID riid
,
329 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
331 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement2(iface
);
332 return IDispatchEx_GetIDsOfNames(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, riid
, rgszNames
,
333 cNames
, lcid
, rgDispId
);
336 static HRESULT WINAPI
HTMLStyleElement2_Invoke(IHTMLStyleElement2
*iface
, DISPID dispIdMember
,
337 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
338 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
340 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement2(iface
);
341 return IDispatchEx_Invoke(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, dispIdMember
, riid
,
342 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
345 static HRESULT WINAPI
HTMLStyleElement2_get_sheet(IHTMLStyleElement2
*iface
, IHTMLStyleSheet
**p
)
347 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement2(iface
);
348 TRACE("(%p)->(%p)\n", This
, p
);
349 return IHTMLStyleElement_get_styleSheet(&This
->IHTMLStyleElement_iface
, p
);
352 static const IHTMLStyleElement2Vtbl HTMLStyleElement2Vtbl
= {
353 HTMLStyleElement2_QueryInterface
,
354 HTMLStyleElement2_AddRef
,
355 HTMLStyleElement2_Release
,
356 HTMLStyleElement2_GetTypeInfoCount
,
357 HTMLStyleElement2_GetTypeInfo
,
358 HTMLStyleElement2_GetIDsOfNames
,
359 HTMLStyleElement2_Invoke
,
360 HTMLStyleElement2_get_sheet
363 static inline HTMLStyleElement
*impl_from_HTMLDOMNode(HTMLDOMNode
*iface
)
365 return CONTAINING_RECORD(iface
, HTMLStyleElement
, element
.node
);
368 static HRESULT
HTMLStyleElement_QI(HTMLDOMNode
*iface
, REFIID riid
, void **ppv
)
370 HTMLStyleElement
*This
= impl_from_HTMLDOMNode(iface
);
372 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
373 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
374 *ppv
= &This
->IHTMLStyleElement_iface
;
375 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
376 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
377 *ppv
= &This
->IHTMLStyleElement_iface
;
378 }else if(IsEqualGUID(&IID_IHTMLStyleElement
, riid
)) {
379 TRACE("(%p)->(IID_IHTMLStyleElement %p)\n", This
, ppv
);
380 *ppv
= &This
->IHTMLStyleElement_iface
;
381 }else if(IsEqualGUID(&IID_IHTMLStyleElement2
, riid
)) {
382 TRACE("(%p)->(IID_IHTMLStyleElement2 %p)\n", This
, ppv
);
383 *ppv
= &This
->IHTMLStyleElement2_iface
;
385 return HTMLElement_QI(&This
->element
.node
, riid
, ppv
);
388 IUnknown_AddRef((IUnknown
*)*ppv
);
392 static void HTMLStyleElement_destructor(HTMLDOMNode
*iface
)
394 HTMLStyleElement
*This
= impl_from_HTMLDOMNode(iface
);
396 if(This
->style_sheet
) {
397 IHTMLStyleSheet_Release(This
->style_sheet
);
398 This
->style_sheet
= NULL
;
401 HTMLElement_destructor(iface
);
404 static void HTMLStyleElement_traverse(HTMLDOMNode
*iface
, nsCycleCollectionTraversalCallback
*cb
)
406 HTMLStyleElement
*This
= impl_from_HTMLDOMNode(iface
);
409 note_cc_edge((nsISupports
*)This
->nsstyle
, "This->nsstyle", cb
);
412 static void HTMLStyleElement_unlink(HTMLDOMNode
*iface
)
414 HTMLStyleElement
*This
= impl_from_HTMLDOMNode(iface
);
417 nsIDOMHTMLStyleElement
*nsstyle
= This
->nsstyle
;
419 This
->nsstyle
= NULL
;
420 nsIDOMHTMLStyleElement_Release(nsstyle
);
424 static void HTMLStyleElement_init_dispex_info(dispex_data_t
*info
, compat_mode_t mode
)
426 static const dispex_hook_t ie11_hooks
[] = {
427 {DISPID_IHTMLSTYLEELEMENT_READYSTATE
, NULL
},
428 {DISPID_IHTMLSTYLEELEMENT_STYLESHEET
, NULL
},
432 HTMLElement_init_dispex_info(info
, mode
);
434 dispex_info_add_interface(info
, IHTMLStyleElement_tid
,
435 mode
>= COMPAT_MODE_IE11
? ie11_hooks
: NULL
);
437 if(mode
>= COMPAT_MODE_IE9
)
438 dispex_info_add_interface(info
, IHTMLStyleElement2_tid
, NULL
);
441 static const NodeImplVtbl HTMLStyleElementImplVtbl
= {
442 &CLSID_HTMLStyleElement
,
444 HTMLStyleElement_destructor
,
447 HTMLElement_handle_event
,
448 HTMLElement_get_attr_col
,
457 HTMLStyleElement_traverse
,
458 HTMLStyleElement_unlink
461 static const tid_t HTMLStyleElement_iface_tids
[] = {
465 static dispex_static_data_t HTMLStyleElement_dispex
= {
467 DispHTMLStyleElement_tid
,
468 HTMLStyleElement_iface_tids
,
469 HTMLStyleElement_init_dispex_info
472 HRESULT
HTMLStyleElement_Create(HTMLDocumentNode
*doc
, nsIDOMElement
*nselem
, HTMLElement
**elem
)
474 HTMLStyleElement
*ret
;
477 ret
= heap_alloc_zero(sizeof(*ret
));
479 return E_OUTOFMEMORY
;
481 ret
->IHTMLStyleElement_iface
.lpVtbl
= &HTMLStyleElementVtbl
;
482 ret
->IHTMLStyleElement2_iface
.lpVtbl
= &HTMLStyleElement2Vtbl
;
483 ret
->element
.node
.vtbl
= &HTMLStyleElementImplVtbl
;
485 HTMLElement_Init(&ret
->element
, doc
, nselem
, &HTMLStyleElement_dispex
);
487 nsres
= nsIDOMElement_QueryInterface(nselem
, &IID_nsIDOMHTMLStyleElement
, (void**)&ret
->nsstyle
);
488 assert(nsres
== NS_OK
);
490 *elem
= &ret
->element
;