mshtml: Added noscript tag handling tests.
[wine] / dlls / mshtml / htmlstyleelem.c
1 /*
2  * Copyright 2010 Jacek Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include <stdarg.h>
20 #include <assert.h>
21
22 #define COBJMACROS
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "winreg.h"
28 #include "ole2.h"
29
30 #include "wine/debug.h"
31
32 #include "mshtml_private.h"
33
34 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
35
36 typedef struct {
37     HTMLElement element;
38
39     IHTMLStyleElement IHTMLStyleElement_iface;
40
41     nsIDOMHTMLStyleElement *nsstyle;
42 } HTMLStyleElement;
43
44 static inline HTMLStyleElement *impl_from_IHTMLStyleElement(IHTMLStyleElement *iface)
45 {
46     return CONTAINING_RECORD(iface, HTMLStyleElement, IHTMLStyleElement_iface);
47 }
48
49 static HRESULT WINAPI HTMLStyleElement_QueryInterface(IHTMLStyleElement *iface,
50         REFIID riid, void **ppv)
51 {
52     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
53
54     return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
55 }
56
57 static ULONG WINAPI HTMLStyleElement_AddRef(IHTMLStyleElement *iface)
58 {
59     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
60
61     return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
62 }
63
64 static ULONG WINAPI HTMLStyleElement_Release(IHTMLStyleElement *iface)
65 {
66     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
67
68     return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
69 }
70
71 static HRESULT WINAPI HTMLStyleElement_GetTypeInfoCount(IHTMLStyleElement *iface, UINT *pctinfo)
72 {
73     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
74     return IDispatchEx_GetTypeInfoCount(&This->element.node.dispex.IDispatchEx_iface, pctinfo);
75 }
76
77 static HRESULT WINAPI HTMLStyleElement_GetTypeInfo(IHTMLStyleElement *iface, UINT iTInfo,
78         LCID lcid, ITypeInfo **ppTInfo)
79 {
80     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
81     return IDispatchEx_GetTypeInfo(&This->element.node.dispex.IDispatchEx_iface, iTInfo, lcid,
82             ppTInfo);
83 }
84
85 static HRESULT WINAPI HTMLStyleElement_GetIDsOfNames(IHTMLStyleElement *iface, REFIID riid,
86         LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
87 {
88     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
89     return IDispatchEx_GetIDsOfNames(&This->element.node.dispex.IDispatchEx_iface, riid, rgszNames,
90             cNames, lcid, rgDispId);
91 }
92
93 static HRESULT WINAPI HTMLStyleElement_Invoke(IHTMLStyleElement *iface, DISPID dispIdMember,
94         REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
95         VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
96 {
97     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
98     return IDispatchEx_Invoke(&This->element.node.dispex.IDispatchEx_iface, dispIdMember, riid,
99             lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
100 }
101
102 static HRESULT WINAPI HTMLStyleElement_put_type(IHTMLStyleElement *iface, BSTR v)
103 {
104     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
105     nsAString type_str;
106     nsresult nsres;
107
108     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
109
110     nsAString_InitDepend(&type_str, v);
111     nsres = nsIDOMHTMLStyleElement_SetType(This->nsstyle, &type_str);
112     nsAString_Finish(&type_str);
113     if(NS_FAILED(nsres)) {
114         ERR("SetType failed: %08x\n", nsres);
115         return E_FAIL;
116     }
117
118     return S_OK;
119 }
120
121 static HRESULT WINAPI HTMLStyleElement_get_type(IHTMLStyleElement *iface, BSTR *p)
122 {
123     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
124     nsAString nsstr;
125     nsresult nsres;
126
127     TRACE("(%p)->(%p)\n", This, p);
128
129     nsAString_Init(&nsstr, NULL);
130     nsres = nsIDOMHTMLStyleElement_GetType(This->nsstyle, &nsstr);
131     return return_nsstr(nsres, &nsstr, p);
132 }
133
134 static HRESULT WINAPI HTMLStyleElement_get_readyState(IHTMLStyleElement *iface, BSTR *p)
135 {
136     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
137     FIXME("(%p)->(%p)\n", This, p);
138     return E_NOTIMPL;
139 }
140
141 static HRESULT WINAPI HTMLStyleElement_put_onreadystatechange(IHTMLStyleElement *iface, VARIANT v)
142 {
143     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
144     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
145     return E_NOTIMPL;
146 }
147
148 static HRESULT WINAPI HTMLStyleElement_get_onreadystatechange(IHTMLStyleElement *iface, VARIANT *p)
149 {
150     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
151     FIXME("(%p)->(%p)\n", This, p);
152     return E_NOTIMPL;
153 }
154
155 static HRESULT WINAPI HTMLStyleElement_put_onload(IHTMLStyleElement *iface, VARIANT v)
156 {
157     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
158     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
159     return E_NOTIMPL;
160 }
161
162 static HRESULT WINAPI HTMLStyleElement_get_onload(IHTMLStyleElement *iface, VARIANT *p)
163 {
164     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
165     FIXME("(%p)->(%p)\n", This, p);
166     return E_NOTIMPL;
167 }
168
169 static HRESULT WINAPI HTMLStyleElement_put_onerror(IHTMLStyleElement *iface, VARIANT v)
170 {
171     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
172     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
173     return E_NOTIMPL;
174 }
175
176 static HRESULT WINAPI HTMLStyleElement_get_onerror(IHTMLStyleElement *iface, VARIANT *p)
177 {
178     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
179     FIXME("(%p)->(%p)\n", This, p);
180     return E_NOTIMPL;
181 }
182
183 static HRESULT WINAPI HTMLStyleElement_get_styleSheet(IHTMLStyleElement *iface, IHTMLStyleSheet **p)
184 {
185     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
186     FIXME("(%p)->(%p)\n", This, p);
187     return E_NOTIMPL;
188 }
189
190 static HRESULT WINAPI HTMLStyleElement_put_disabled(IHTMLStyleElement *iface, VARIANT_BOOL v)
191 {
192     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
193     FIXME("(%p)->(%x)\n", This, v);
194     return E_NOTIMPL;
195 }
196
197 static HRESULT WINAPI HTMLStyleElement_get_disabled(IHTMLStyleElement *iface, VARIANT_BOOL *p)
198 {
199     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
200     FIXME("(%p)->(%p)\n", This, p);
201     return E_NOTIMPL;
202 }
203
204 static HRESULT WINAPI HTMLStyleElement_put_media(IHTMLStyleElement *iface, BSTR v)
205 {
206     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
207     nsAString media_str;
208     nsresult nsres;
209
210     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
211
212     nsAString_InitDepend(&media_str, v);
213     nsres = nsIDOMHTMLStyleElement_SetMedia(This->nsstyle, &media_str);
214     nsAString_Finish(&media_str);
215     if(NS_FAILED(nsres)) {
216         ERR("SetMedia failed: %08x\n", nsres);
217         return E_FAIL;
218     }
219
220     return S_OK;
221 }
222
223 static HRESULT WINAPI HTMLStyleElement_get_media(IHTMLStyleElement *iface, BSTR *p)
224 {
225     HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
226     nsAString nsstr;
227     nsresult nsres;
228
229     TRACE("(%p)->(%p)\n", This, p);
230
231     nsAString_Init(&nsstr, NULL);
232     nsres = nsIDOMHTMLStyleElement_GetMedia(This->nsstyle, &nsstr);
233     return return_nsstr(nsres, &nsstr, p);
234 }
235
236 static const IHTMLStyleElementVtbl HTMLStyleElementVtbl = {
237     HTMLStyleElement_QueryInterface,
238     HTMLStyleElement_AddRef,
239     HTMLStyleElement_Release,
240     HTMLStyleElement_GetTypeInfoCount,
241     HTMLStyleElement_GetTypeInfo,
242     HTMLStyleElement_GetIDsOfNames,
243     HTMLStyleElement_Invoke,
244     HTMLStyleElement_put_type,
245     HTMLStyleElement_get_type,
246     HTMLStyleElement_get_readyState,
247     HTMLStyleElement_put_onreadystatechange,
248     HTMLStyleElement_get_onreadystatechange,
249     HTMLStyleElement_put_onload,
250     HTMLStyleElement_get_onload,
251     HTMLStyleElement_put_onerror,
252     HTMLStyleElement_get_onerror,
253     HTMLStyleElement_get_styleSheet,
254     HTMLStyleElement_put_disabled,
255     HTMLStyleElement_get_disabled,
256     HTMLStyleElement_put_media,
257     HTMLStyleElement_get_media
258 };
259
260 static inline HTMLStyleElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
261 {
262     return CONTAINING_RECORD(iface, HTMLStyleElement, element.node);
263 }
264
265 static HRESULT HTMLStyleElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
266 {
267     HTMLStyleElement *This = impl_from_HTMLDOMNode(iface);
268
269     if(IsEqualGUID(&IID_IUnknown, riid)) {
270         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
271         *ppv = &This->IHTMLStyleElement_iface;
272     }else if(IsEqualGUID(&IID_IDispatch, riid)) {
273         TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
274         *ppv = &This->IHTMLStyleElement_iface;
275     }else if(IsEqualGUID(&IID_IHTMLStyleElement, riid)) {
276         TRACE("(%p)->(IID_IHTMLStyleElement %p)\n", This, ppv);
277         *ppv = &This->IHTMLStyleElement_iface;
278     }else {
279         return HTMLElement_QI(&This->element.node, riid, ppv);
280     }
281
282     IUnknown_AddRef((IUnknown*)*ppv);
283     return S_OK;
284 }
285
286 static const NodeImplVtbl HTMLStyleElementImplVtbl = {
287     HTMLStyleElement_QI,
288     HTMLElement_destructor,
289     HTMLElement_clone,
290     HTMLElement_handle_event,
291     HTMLElement_get_attr_col
292 };
293
294 static const tid_t HTMLStyleElement_iface_tids[] = {
295     HTMLELEMENT_TIDS,
296     IHTMLStyleElement_tid,
297     0
298 };
299 static dispex_static_data_t HTMLStyleElement_dispex = {
300     NULL,
301     DispHTMLStyleElement_tid,
302     NULL,
303     HTMLStyleElement_iface_tids
304 };
305
306 HRESULT HTMLStyleElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
307 {
308     HTMLStyleElement *ret;
309     nsresult nsres;
310
311     ret = heap_alloc_zero(sizeof(*ret));
312     if(!ret)
313         return E_OUTOFMEMORY;
314
315     ret->IHTMLStyleElement_iface.lpVtbl = &HTMLStyleElementVtbl;
316     ret->element.node.vtbl = &HTMLStyleElementImplVtbl;
317
318     HTMLElement_Init(&ret->element, doc, nselem, &HTMLStyleElement_dispex);
319
320     nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLStyleElement, (void**)&ret->nsstyle);
321
322     /* Share nsstyle reference with nsnode */
323     assert(nsres == NS_OK && (nsIDOMNode*)ret->nsstyle == ret->element.node.nsnode);
324     nsIDOMNode_Release(ret->element.node.nsnode);
325
326     *elem = &ret->element;
327     return S_OK;
328 }