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"
34 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
36 struct HTMLStyleElement
{
39 IHTMLStyleElement IHTMLStyleElement_iface
;
41 nsIDOMHTMLStyleElement
*nsstyle
;
42 IHTMLStyleSheet
*style_sheet
;
45 static inline HTMLStyleElement
*impl_from_IHTMLStyleElement(IHTMLStyleElement
*iface
)
47 return CONTAINING_RECORD(iface
, HTMLStyleElement
, IHTMLStyleElement_iface
);
50 static HRESULT WINAPI
HTMLStyleElement_QueryInterface(IHTMLStyleElement
*iface
,
51 REFIID riid
, void **ppv
)
53 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
55 return IHTMLDOMNode_QueryInterface(&This
->element
.node
.IHTMLDOMNode_iface
, riid
, ppv
);
58 static ULONG WINAPI
HTMLStyleElement_AddRef(IHTMLStyleElement
*iface
)
60 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
62 return IHTMLDOMNode_AddRef(&This
->element
.node
.IHTMLDOMNode_iface
);
65 static ULONG WINAPI
HTMLStyleElement_Release(IHTMLStyleElement
*iface
)
67 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
69 return IHTMLDOMNode_Release(&This
->element
.node
.IHTMLDOMNode_iface
);
72 static HRESULT WINAPI
HTMLStyleElement_GetTypeInfoCount(IHTMLStyleElement
*iface
, UINT
*pctinfo
)
74 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
75 return IDispatchEx_GetTypeInfoCount(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, pctinfo
);
78 static HRESULT WINAPI
HTMLStyleElement_GetTypeInfo(IHTMLStyleElement
*iface
, UINT iTInfo
,
79 LCID lcid
, ITypeInfo
**ppTInfo
)
81 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
82 return IDispatchEx_GetTypeInfo(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, iTInfo
, lcid
,
86 static HRESULT WINAPI
HTMLStyleElement_GetIDsOfNames(IHTMLStyleElement
*iface
, REFIID riid
,
87 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
89 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
90 return IDispatchEx_GetIDsOfNames(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, riid
, rgszNames
,
91 cNames
, lcid
, rgDispId
);
94 static HRESULT WINAPI
HTMLStyleElement_Invoke(IHTMLStyleElement
*iface
, DISPID dispIdMember
,
95 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
96 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
98 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
99 return IDispatchEx_Invoke(&This
->element
.node
.event_target
.dispex
.IDispatchEx_iface
, dispIdMember
, riid
,
100 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
103 static HRESULT WINAPI
HTMLStyleElement_put_type(IHTMLStyleElement
*iface
, BSTR v
)
105 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
109 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
111 nsAString_InitDepend(&type_str
, v
);
112 nsres
= nsIDOMHTMLStyleElement_SetType(This
->nsstyle
, &type_str
);
113 nsAString_Finish(&type_str
);
114 if(NS_FAILED(nsres
)) {
115 ERR("SetType failed: %08x\n", nsres
);
122 static HRESULT WINAPI
HTMLStyleElement_get_type(IHTMLStyleElement
*iface
, BSTR
*p
)
124 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
128 TRACE("(%p)->(%p)\n", This
, p
);
130 nsAString_Init(&nsstr
, NULL
);
131 nsres
= nsIDOMHTMLStyleElement_GetType(This
->nsstyle
, &nsstr
);
132 return return_nsstr(nsres
, &nsstr
, p
);
135 static HRESULT WINAPI
HTMLStyleElement_get_readyState(IHTMLStyleElement
*iface
, BSTR
*p
)
137 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
138 FIXME("(%p)->(%p)\n", This
, p
);
142 static HRESULT WINAPI
HTMLStyleElement_put_onreadystatechange(IHTMLStyleElement
*iface
, VARIANT v
)
144 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
145 FIXME("(%p)->(%s)\n", This
, debugstr_variant(&v
));
149 static HRESULT WINAPI
HTMLStyleElement_get_onreadystatechange(IHTMLStyleElement
*iface
, VARIANT
*p
)
151 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
152 FIXME("(%p)->(%p)\n", This
, p
);
156 static HRESULT WINAPI
HTMLStyleElement_put_onload(IHTMLStyleElement
*iface
, VARIANT v
)
158 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
159 FIXME("(%p)->(%s)\n", This
, debugstr_variant(&v
));
163 static HRESULT WINAPI
HTMLStyleElement_get_onload(IHTMLStyleElement
*iface
, VARIANT
*p
)
165 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
166 FIXME("(%p)->(%p)\n", This
, p
);
170 static HRESULT WINAPI
HTMLStyleElement_put_onerror(IHTMLStyleElement
*iface
, VARIANT v
)
172 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
173 FIXME("(%p)->(%s)\n", This
, debugstr_variant(&v
));
177 static HRESULT WINAPI
HTMLStyleElement_get_onerror(IHTMLStyleElement
*iface
, VARIANT
*p
)
179 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
180 FIXME("(%p)->(%p)\n", This
, p
);
184 static HRESULT WINAPI
HTMLStyleElement_get_styleSheet(IHTMLStyleElement
*iface
, IHTMLStyleSheet
**p
)
186 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
188 TRACE("(%p)->(%p)\n", This
, p
);
193 if(!This
->style_sheet
) {
194 nsIDOMStyleSheet
*ss
;
197 nsres
= nsIDOMHTMLStyleElement_GetDOMStyleSheet(This
->nsstyle
, &ss
);
198 assert(nsres
== NS_OK
);
201 This
->style_sheet
= HTMLStyleSheet_Create(ss
);
202 nsIDOMStyleSheet_Release(ss
);
203 if(!This
->style_sheet
)
204 return E_OUTOFMEMORY
;
208 if(This
->style_sheet
)
209 IHTMLStyleSheet_AddRef(This
->style_sheet
);
210 *p
= This
->style_sheet
;
214 static HRESULT WINAPI
HTMLStyleElement_put_disabled(IHTMLStyleElement
*iface
, VARIANT_BOOL v
)
216 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
217 FIXME("(%p)->(%x)\n", This
, v
);
221 static HRESULT WINAPI
HTMLStyleElement_get_disabled(IHTMLStyleElement
*iface
, VARIANT_BOOL
*p
)
223 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
224 FIXME("(%p)->(%p)\n", This
, p
);
228 static HRESULT WINAPI
HTMLStyleElement_put_media(IHTMLStyleElement
*iface
, BSTR v
)
230 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
234 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
236 nsAString_InitDepend(&media_str
, v
);
237 nsres
= nsIDOMHTMLStyleElement_SetMedia(This
->nsstyle
, &media_str
);
238 nsAString_Finish(&media_str
);
239 if(NS_FAILED(nsres
)) {
240 ERR("SetMedia failed: %08x\n", nsres
);
247 static HRESULT WINAPI
HTMLStyleElement_get_media(IHTMLStyleElement
*iface
, BSTR
*p
)
249 HTMLStyleElement
*This
= impl_from_IHTMLStyleElement(iface
);
253 TRACE("(%p)->(%p)\n", This
, p
);
255 nsAString_Init(&nsstr
, NULL
);
256 nsres
= nsIDOMHTMLStyleElement_GetMedia(This
->nsstyle
, &nsstr
);
257 return return_nsstr(nsres
, &nsstr
, p
);
260 static const IHTMLStyleElementVtbl HTMLStyleElementVtbl
= {
261 HTMLStyleElement_QueryInterface
,
262 HTMLStyleElement_AddRef
,
263 HTMLStyleElement_Release
,
264 HTMLStyleElement_GetTypeInfoCount
,
265 HTMLStyleElement_GetTypeInfo
,
266 HTMLStyleElement_GetIDsOfNames
,
267 HTMLStyleElement_Invoke
,
268 HTMLStyleElement_put_type
,
269 HTMLStyleElement_get_type
,
270 HTMLStyleElement_get_readyState
,
271 HTMLStyleElement_put_onreadystatechange
,
272 HTMLStyleElement_get_onreadystatechange
,
273 HTMLStyleElement_put_onload
,
274 HTMLStyleElement_get_onload
,
275 HTMLStyleElement_put_onerror
,
276 HTMLStyleElement_get_onerror
,
277 HTMLStyleElement_get_styleSheet
,
278 HTMLStyleElement_put_disabled
,
279 HTMLStyleElement_get_disabled
,
280 HTMLStyleElement_put_media
,
281 HTMLStyleElement_get_media
284 static inline HTMLStyleElement
*impl_from_HTMLDOMNode(HTMLDOMNode
*iface
)
286 return CONTAINING_RECORD(iface
, HTMLStyleElement
, element
.node
);
289 static HRESULT
HTMLStyleElement_QI(HTMLDOMNode
*iface
, REFIID riid
, void **ppv
)
291 HTMLStyleElement
*This
= impl_from_HTMLDOMNode(iface
);
293 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
294 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
295 *ppv
= &This
->IHTMLStyleElement_iface
;
296 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
297 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
298 *ppv
= &This
->IHTMLStyleElement_iface
;
299 }else if(IsEqualGUID(&IID_IHTMLStyleElement
, riid
)) {
300 TRACE("(%p)->(IID_IHTMLStyleElement %p)\n", This
, ppv
);
301 *ppv
= &This
->IHTMLStyleElement_iface
;
303 return HTMLElement_QI(&This
->element
.node
, riid
, ppv
);
306 IUnknown_AddRef((IUnknown
*)*ppv
);
310 static void HTMLStyleElement_destructor(HTMLDOMNode
*iface
)
312 HTMLStyleElement
*This
= impl_from_HTMLDOMNode(iface
);
314 if(This
->style_sheet
) {
315 IHTMLStyleSheet_Release(This
->style_sheet
);
316 This
->style_sheet
= NULL
;
319 HTMLElement_destructor(iface
);
322 static void HTMLStyleElement_traverse(HTMLDOMNode
*iface
, nsCycleCollectionTraversalCallback
*cb
)
324 HTMLStyleElement
*This
= impl_from_HTMLDOMNode(iface
);
327 note_cc_edge((nsISupports
*)This
->nsstyle
, "This->nsstyle", cb
);
330 static void HTMLStyleElement_unlink(HTMLDOMNode
*iface
)
332 HTMLStyleElement
*This
= impl_from_HTMLDOMNode(iface
);
335 nsIDOMHTMLStyleElement
*nsstyle
= This
->nsstyle
;
337 This
->nsstyle
= NULL
;
338 nsIDOMHTMLStyleElement_Release(nsstyle
);
342 static const NodeImplVtbl HTMLStyleElementImplVtbl
= {
343 &CLSID_HTMLStyleElement
,
345 HTMLStyleElement_destructor
,
348 HTMLElement_handle_event
,
349 HTMLElement_get_attr_col
,
358 HTMLStyleElement_traverse
,
359 HTMLStyleElement_unlink
362 static const tid_t HTMLStyleElement_iface_tids
[] = {
364 IHTMLStyleElement_tid
,
367 static dispex_static_data_t HTMLStyleElement_dispex
= {
369 DispHTMLStyleElement_tid
,
370 HTMLStyleElement_iface_tids
,
371 HTMLElement_init_dispex_info
374 HRESULT
HTMLStyleElement_Create(HTMLDocumentNode
*doc
, nsIDOMElement
*nselem
, HTMLElement
**elem
)
376 HTMLStyleElement
*ret
;
379 ret
= heap_alloc_zero(sizeof(*ret
));
381 return E_OUTOFMEMORY
;
383 ret
->IHTMLStyleElement_iface
.lpVtbl
= &HTMLStyleElementVtbl
;
384 ret
->element
.node
.vtbl
= &HTMLStyleElementImplVtbl
;
386 HTMLElement_Init(&ret
->element
, doc
, nselem
, &HTMLStyleElement_dispex
);
388 nsres
= nsIDOMElement_QueryInterface(nselem
, &IID_nsIDOMHTMLStyleElement
, (void**)&ret
->nsstyle
);
389 assert(nsres
== NS_OK
);
391 *elem
= &ret
->element
;