mshtml: Correctly set NULL event.
[wine] / dlls / mshtml / htmlstylesheet.c
1 /*
2  * Copyright 2006 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
21 #define COBJMACROS
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "ole2.h"
27
28 #include "wine/debug.h"
29 #include "wine/unicode.h"
30
31 #include "mshtml_private.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
34
35 struct HTMLStyleSheet {
36     IHTMLStyleSheet IHTMLStyleSheet_iface;
37
38     LONG ref;
39
40     nsIDOMCSSStyleSheet *nsstylesheet;
41 };
42
43 struct HTMLStyleSheetsCollection {
44     DispatchEx dispex;
45     IHTMLStyleSheetsCollection IHTMLStyleSheetsCollection_iface;
46
47     LONG ref;
48
49     nsIDOMStyleSheetList *nslist;
50 };
51
52 struct HTMLStyleSheetRulesCollection {
53     IHTMLStyleSheetRulesCollection IHTMLStyleSheetRulesCollection_iface;
54
55     LONG ref;
56
57     nsIDOMCSSRuleList *nslist;
58 };
59
60 static inline HTMLStyleSheetRulesCollection *impl_from_IHTMLStyleSheetRulesCollection(IHTMLStyleSheetRulesCollection *iface)
61 {
62     return CONTAINING_RECORD(iface, HTMLStyleSheetRulesCollection, IHTMLStyleSheetRulesCollection_iface);
63 }
64
65 static HRESULT WINAPI HTMLStyleSheetRulesCollection_QueryInterface(IHTMLStyleSheetRulesCollection *iface,
66         REFIID riid, void **ppv)
67 {
68     HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
69
70     if(IsEqualGUID(&IID_IUnknown, riid)) {
71         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
72         *ppv = &This->IHTMLStyleSheetRulesCollection_iface;
73     }else if(IsEqualGUID(&IID_IHTMLStyleSheetRulesCollection, riid)) {
74         TRACE("(%p)->(IID_IHTMLStyleSheetRulesCollection %p)\n", This, ppv);
75         *ppv = &This->IHTMLStyleSheetRulesCollection_iface;
76     }
77
78     if(*ppv) {
79         IUnknown_AddRef((IUnknown*)*ppv);
80         return S_OK;
81     }
82
83     FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
84     return E_NOINTERFACE;
85 }
86
87 static ULONG WINAPI HTMLStyleSheetRulesCollection_AddRef(IHTMLStyleSheetRulesCollection *iface)
88 {
89     HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
90     LONG ref = InterlockedIncrement(&This->ref);
91
92     TRACE("(%p) ref=%d\n", This, ref);
93
94     return ref;
95 }
96
97 static ULONG WINAPI HTMLStyleSheetRulesCollection_Release(IHTMLStyleSheetRulesCollection *iface)
98 {
99     HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
100     LONG ref = InterlockedDecrement(&This->ref);
101
102     TRACE("(%p) ref=%d\n", This, ref);
103
104     if(!ref) {
105         if(This->nslist)
106             nsIDOMCSSRuleList_Release(This->nslist);
107         heap_free(This);
108     }
109
110     return ref;
111 }
112
113 static HRESULT WINAPI HTMLStyleSheetRulesCollection_GetTypeInfoCount(
114         IHTMLStyleSheetRulesCollection *iface, UINT *pctinfo)
115 {
116     HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
117     FIXME("(%p)->(%p)\n", This, pctinfo);
118     return E_NOTIMPL;
119 }
120
121 static HRESULT WINAPI HTMLStyleSheetRulesCollection_GetTypeInfo(IHTMLStyleSheetRulesCollection *iface,
122         UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
123 {
124     HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
125     FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
126     return E_NOTIMPL;
127 }
128
129 static HRESULT WINAPI HTMLStyleSheetRulesCollection_GetIDsOfNames(IHTMLStyleSheetRulesCollection *iface,
130         REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
131 {
132     HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
133     FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
134           lcid, rgDispId);
135     return E_NOTIMPL;
136 }
137
138 static HRESULT WINAPI HTMLStyleSheetRulesCollection_Invoke(IHTMLStyleSheetRulesCollection *iface,
139         DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
140         VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
141 {
142     HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
143     FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
144           lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
145     return E_NOTIMPL;
146 }
147
148 static HRESULT WINAPI HTMLStyleSheetRulesCollection_get_length(IHTMLStyleSheetRulesCollection *iface,
149         LONG *p)
150 {
151     HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
152     PRUint32 len = 0;
153
154     TRACE("(%p)->(%p)\n", This, p);
155
156     if(This->nslist) {
157         nsresult nsres;
158
159         nsres = nsIDOMCSSRuleList_GetLength(This->nslist, &len);
160         if(NS_FAILED(nsres))
161             ERR("GetLength failed: %08x\n", nsres);
162     }
163
164     *p = len;
165     return S_OK;
166 }
167
168 static HRESULT WINAPI HTMLStyleSheetRulesCollection_item(IHTMLStyleSheetRulesCollection *iface,
169         LONG index, IHTMLStyleSheetRule **ppHTMLStyleSheetRule)
170 {
171     HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
172     FIXME("(%p)->(%d %p)\n", This, index, ppHTMLStyleSheetRule);
173     return E_NOTIMPL;
174 }
175
176 static const IHTMLStyleSheetRulesCollectionVtbl HTMLStyleSheetRulesCollectionVtbl = {
177     HTMLStyleSheetRulesCollection_QueryInterface,
178     HTMLStyleSheetRulesCollection_AddRef,
179     HTMLStyleSheetRulesCollection_Release,
180     HTMLStyleSheetRulesCollection_GetTypeInfoCount,
181     HTMLStyleSheetRulesCollection_GetTypeInfo,
182     HTMLStyleSheetRulesCollection_GetIDsOfNames,
183     HTMLStyleSheetRulesCollection_Invoke,
184     HTMLStyleSheetRulesCollection_get_length,
185     HTMLStyleSheetRulesCollection_item
186 };
187
188 static IHTMLStyleSheetRulesCollection *HTMLStyleSheetRulesCollection_Create(nsIDOMCSSRuleList *nslist)
189 {
190     HTMLStyleSheetRulesCollection *ret;
191
192     ret = heap_alloc(sizeof(*ret));
193     ret->IHTMLStyleSheetRulesCollection_iface.lpVtbl = &HTMLStyleSheetRulesCollectionVtbl;
194     ret->ref = 1;
195     ret->nslist = nslist;
196
197     if(nslist)
198         nsIDOMCSSRuleList_AddRef(nslist);
199
200     return &ret->IHTMLStyleSheetRulesCollection_iface;
201 }
202
203 static inline HTMLStyleSheetsCollection *impl_from_IHTMLStyleSheetsCollection(IHTMLStyleSheetsCollection *iface)
204 {
205     return CONTAINING_RECORD(iface, HTMLStyleSheetsCollection, IHTMLStyleSheetsCollection_iface);
206 }
207
208 static HRESULT WINAPI HTMLStyleSheetsCollection_QueryInterface(IHTMLStyleSheetsCollection *iface,
209          REFIID riid, void **ppv)
210 {
211     HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
212
213     *ppv = NULL;
214
215     if(IsEqualGUID(&IID_IUnknown, riid)) {
216         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
217         *ppv = &This->IHTMLStyleSheetsCollection_iface;
218     }else if(IsEqualGUID(&IID_IDispatch, riid)) {
219         TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
220         *ppv = &This->IHTMLStyleSheetsCollection_iface;
221     }else if(IsEqualGUID(&IID_IHTMLStyleSheetsCollection, riid)) {
222         TRACE("(%p)->(IID_IHTMLStyleSheetsCollection %p)\n", This, ppv);
223         *ppv = &This->IHTMLStyleSheetsCollection_iface;
224     }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
225         return *ppv ? S_OK : E_NOINTERFACE;
226     }
227
228     if(*ppv) {
229         IUnknown_AddRef((IUnknown*)*ppv);
230         return S_OK;
231     }
232
233     WARN("unsupported %s\n", debugstr_guid(riid));
234     return E_NOINTERFACE;
235 }
236
237 static ULONG WINAPI HTMLStyleSheetsCollection_AddRef(IHTMLStyleSheetsCollection *iface)
238 {
239     HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
240     LONG ref = InterlockedIncrement(&This->ref);
241
242     TRACE("(%p) ref=%d\n", This, ref);
243
244     return ref;
245 }
246
247 static ULONG WINAPI HTMLStyleSheetsCollection_Release(IHTMLStyleSheetsCollection *iface)
248 {
249     HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
250     LONG ref = InterlockedDecrement(&This->ref);
251
252     TRACE("(%p) ref=%d\n", This, ref);
253
254     if(!ref) {
255         if(This->nslist)
256             nsIDOMStyleSheetList_Release(This->nslist);
257         heap_free(This);
258     }
259
260     return ref;
261 }
262
263 static HRESULT WINAPI HTMLStyleSheetsCollection_GetTypeInfoCount(IHTMLStyleSheetsCollection *iface,
264         UINT *pctinfo)
265 {
266     HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
267     return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
268 }
269
270 static HRESULT WINAPI HTMLStyleSheetsCollection_GetTypeInfo(IHTMLStyleSheetsCollection *iface,
271         UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
272 {
273     HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
274     return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
275 }
276
277 static HRESULT WINAPI HTMLStyleSheetsCollection_GetIDsOfNames(IHTMLStyleSheetsCollection *iface,
278         REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
279 {
280     HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
281     return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
282             lcid, rgDispId);
283 }
284
285 static HRESULT WINAPI HTMLStyleSheetsCollection_Invoke(IHTMLStyleSheetsCollection *iface,
286         DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
287         VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
288 {
289     HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
290     return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
291             wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
292 }
293
294 static HRESULT WINAPI HTMLStyleSheetsCollection_get_length(IHTMLStyleSheetsCollection *iface,
295         LONG *p)
296 {
297     HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
298     PRUint32 len = 0;
299
300     TRACE("(%p)->(%p)\n", This, p);
301
302     if(This->nslist)
303         nsIDOMStyleSheetList_GetLength(This->nslist, &len);
304
305     *p = len;
306     return S_OK;
307 }
308
309 static HRESULT WINAPI HTMLStyleSheetsCollection_get__newEnum(IHTMLStyleSheetsCollection *iface,
310         IUnknown **p)
311 {
312     HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
313     FIXME("(%p)->(%p)\n", This, p);
314     return E_NOTIMPL;
315 }
316
317 static HRESULT WINAPI HTMLStyleSheetsCollection_item(IHTMLStyleSheetsCollection *iface,
318         VARIANT *pvarIndex, VARIANT *pvarResult)
319 {
320     HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
321
322     TRACE("(%p)->(%p %p)\n", This, pvarIndex, pvarResult);
323
324     switch(V_VT(pvarIndex)) {
325     case VT_I4: {
326         nsIDOMStyleSheet *nsstylesheet;
327         nsresult nsres;
328
329         TRACE("index=%d\n", V_I4(pvarIndex));
330
331         nsres = nsIDOMStyleSheetList_Item(This->nslist, V_I4(pvarIndex), &nsstylesheet);
332         if(NS_FAILED(nsres) || !nsstylesheet) {
333             WARN("Item failed: %08x\n", nsres);
334             V_VT(pvarResult) = VT_EMPTY;
335             return E_INVALIDARG;
336         }
337
338         V_VT(pvarResult) = VT_DISPATCH;
339         V_DISPATCH(pvarResult) = (IDispatch*)HTMLStyleSheet_Create(nsstylesheet);
340
341         return S_OK;
342     }
343
344     case VT_BSTR:
345         FIXME("id=%s not implemented\n", debugstr_w(V_BSTR(pvarResult)));
346         return E_NOTIMPL;
347
348     default:
349         WARN("Invalid vt=%d\n", V_VT(pvarIndex));
350     }
351
352     return E_INVALIDARG;
353 }
354
355 static const IHTMLStyleSheetsCollectionVtbl HTMLStyleSheetsCollectionVtbl = {
356     HTMLStyleSheetsCollection_QueryInterface,
357     HTMLStyleSheetsCollection_AddRef,
358     HTMLStyleSheetsCollection_Release,
359     HTMLStyleSheetsCollection_GetTypeInfoCount,
360     HTMLStyleSheetsCollection_GetTypeInfo,
361     HTMLStyleSheetsCollection_GetIDsOfNames,
362     HTMLStyleSheetsCollection_Invoke,
363     HTMLStyleSheetsCollection_get_length,
364     HTMLStyleSheetsCollection_get__newEnum,
365     HTMLStyleSheetsCollection_item
366 };
367
368 static const tid_t HTMLStyleSheetsCollection_iface_tids[] = {
369     IHTMLStyleSheetsCollection_tid,
370     0
371 };
372 static dispex_static_data_t HTMLStyleSheetsCollection_dispex = {
373     NULL,
374     DispHTMLStyleSheetsCollection_tid,
375     NULL,
376     HTMLStyleSheetsCollection_iface_tids
377 };
378
379 IHTMLStyleSheetsCollection *HTMLStyleSheetsCollection_Create(nsIDOMStyleSheetList *nslist)
380 {
381     HTMLStyleSheetsCollection *ret = heap_alloc(sizeof(HTMLStyleSheetsCollection));
382
383     ret->IHTMLStyleSheetsCollection_iface.lpVtbl = &HTMLStyleSheetsCollectionVtbl;
384     ret->ref = 1;
385
386     if(nslist)
387         nsIDOMStyleSheetList_AddRef(nslist);
388     ret->nslist = nslist;
389
390     init_dispex(&ret->dispex, (IUnknown*)&ret->IHTMLStyleSheetsCollection_iface,
391             &HTMLStyleSheetsCollection_dispex);
392
393     return &ret->IHTMLStyleSheetsCollection_iface;
394 }
395
396 static inline HTMLStyleSheet *impl_from_IHTMLStyleSheet(IHTMLStyleSheet *iface)
397 {
398     return CONTAINING_RECORD(iface, HTMLStyleSheet, IHTMLStyleSheet_iface);
399 }
400
401 static HRESULT WINAPI HTMLStyleSheet_QueryInterface(IHTMLStyleSheet *iface, REFIID riid, void **ppv)
402 {
403     HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
404
405     *ppv = NULL;
406
407     if(IsEqualGUID(&IID_IUnknown, riid)) {
408         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
409         *ppv = &This->IHTMLStyleSheet_iface;
410     }else if(IsEqualGUID(&IID_IDispatch, riid)) {
411         TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
412         *ppv = &This->IHTMLStyleSheet_iface;
413     }else if(IsEqualGUID(&IID_IHTMLStyleSheet, riid)) {
414         TRACE("(%p)->(IID_IHTMLStyleSheet %p)\n", This, ppv);
415         *ppv = &This->IHTMLStyleSheet_iface;
416     }
417
418     if(*ppv) {
419         IUnknown_AddRef((IUnknown*)*ppv);
420         return S_OK;
421     }
422
423     WARN("unsupported %s\n", debugstr_guid(riid));
424     return E_NOINTERFACE;
425 }
426
427 static ULONG WINAPI HTMLStyleSheet_AddRef(IHTMLStyleSheet *iface)
428 {
429     HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
430     LONG ref = InterlockedIncrement(&This->ref);
431
432     TRACE("(%p) ref=%d\n", This, ref);
433
434     return ref;
435 }
436
437 static ULONG WINAPI HTMLStyleSheet_Release(IHTMLStyleSheet *iface)
438 {
439     HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
440     LONG ref = InterlockedDecrement(&This->ref);
441
442     TRACE("(%p) ref=%d\n", This, ref);
443
444     if(!ref)
445         heap_free(This);
446
447     return ref;
448 }
449
450 static HRESULT WINAPI HTMLStyleSheet_GetTypeInfoCount(IHTMLStyleSheet *iface, UINT *pctinfo)
451 {
452     HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
453     FIXME("(%p)->(%p)\n", This, pctinfo);
454     return E_NOTIMPL;
455 }
456
457 static HRESULT WINAPI HTMLStyleSheet_GetTypeInfo(IHTMLStyleSheet *iface, UINT iTInfo,
458                                               LCID lcid, ITypeInfo **ppTInfo)
459 {
460     HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
461     FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
462     return E_NOTIMPL;
463 }
464
465 static HRESULT WINAPI HTMLStyleSheet_GetIDsOfNames(IHTMLStyleSheet *iface, REFIID riid,
466                                                 LPOLESTR *rgszNames, UINT cNames,
467                                                 LCID lcid, DISPID *rgDispId)
468 {
469     HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
470     FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
471           lcid, rgDispId);
472     return E_NOTIMPL;
473 }
474
475 static HRESULT WINAPI HTMLStyleSheet_Invoke(IHTMLStyleSheet *iface, DISPID dispIdMember,
476                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
477                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
478 {
479     HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
480     FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
481           lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
482     return E_NOTIMPL;
483 }
484
485 static HRESULT WINAPI HTMLStyleSheet_put_title(IHTMLStyleSheet *iface, BSTR v)
486 {
487     HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
488     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
489     return E_NOTIMPL;
490 }
491
492 static HRESULT WINAPI HTMLStyleSheet_get_title(IHTMLStyleSheet *iface, BSTR *p)
493 {
494     HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
495     FIXME("(%p)->(%p)\n", This, p);
496     return E_NOTIMPL;
497 }
498
499 static HRESULT WINAPI HTMLStyleSheet_get_parentStyleSheet(IHTMLStyleSheet *iface,
500                                                           IHTMLStyleSheet **p)
501 {
502     HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
503     FIXME("(%p)->(%p)\n", This, p);
504     return E_NOTIMPL;
505 }
506
507 static HRESULT WINAPI HTMLStyleSheet_get_owningElement(IHTMLStyleSheet *iface, IHTMLElement **p)
508 {
509     HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
510     FIXME("(%p)->(%p)\n", This, p);
511     return E_NOTIMPL;
512 }
513
514 static HRESULT WINAPI HTMLStyleSheet_put_disabled(IHTMLStyleSheet *iface, VARIANT_BOOL v)
515 {
516     HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
517     FIXME("(%p)->(%x)\n", This, v);
518     return E_NOTIMPL;
519 }
520
521 static HRESULT WINAPI HTMLStyleSheet_get_disabled(IHTMLStyleSheet *iface, VARIANT_BOOL *p)
522 {
523     HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
524     FIXME("(%p)->(%p)\n", This, p);
525     return E_NOTIMPL;
526 }
527
528 static HRESULT WINAPI HTMLStyleSheet_get_readOnly(IHTMLStyleSheet *iface, VARIANT_BOOL *p)
529 {
530     HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
531     FIXME("(%p)->(%p)\n", This, p);
532     return E_NOTIMPL;
533 }
534
535 static HRESULT WINAPI HTMLStyleSheet_get_imports(IHTMLStyleSheet *iface,
536                                                  IHTMLStyleSheetsCollection **p)
537 {
538     HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
539     FIXME("(%p)->(%p)\n", This, p);
540     return E_NOTIMPL;
541 }
542
543 static HRESULT WINAPI HTMLStyleSheet_put_href(IHTMLStyleSheet *iface, BSTR v)
544 {
545     HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
546     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
547     return E_NOTIMPL;
548 }
549
550 static HRESULT WINAPI HTMLStyleSheet_get_href(IHTMLStyleSheet *iface, BSTR *p)
551 {
552     HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
553     FIXME("(%p)->(%p)\n", This, p);
554     return E_NOTIMPL;
555 }
556
557 static HRESULT WINAPI HTMLStyleSheet_get_type(IHTMLStyleSheet *iface, BSTR *p)
558 {
559     HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
560     FIXME("(%p)->(%p)\n", This, p);
561     return E_NOTIMPL;
562 }
563
564 static HRESULT WINAPI HTMLStyleSheet_get_id(IHTMLStyleSheet *iface, BSTR *p)
565 {
566     HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
567     FIXME("(%p)->(%p)\n", This, p);
568     return E_NOTIMPL;
569 }
570
571 static HRESULT WINAPI HTMLStyleSheet_addImport(IHTMLStyleSheet *iface, BSTR bstrURL,
572                                                LONG lIndex, LONG *plIndex)
573 {
574     HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
575     FIXME("(%p)->(%s %d %p)\n", This, debugstr_w(bstrURL), lIndex, plIndex);
576     return E_NOTIMPL;
577 }
578
579 static HRESULT WINAPI HTMLStyleSheet_addRule(IHTMLStyleSheet *iface, BSTR bstrSelector,
580                                              BSTR bstrStyle, LONG lIndex, LONG *plIndex)
581 {
582     HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
583     FIXME("(%p)->(%s %s %d %p)\n", This, debugstr_w(bstrSelector), debugstr_w(bstrStyle),
584           lIndex, plIndex);
585     return E_NOTIMPL;
586 }
587
588 static HRESULT WINAPI HTMLStyleSheet_removeImport(IHTMLStyleSheet *iface, LONG lIndex)
589 {
590     HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
591     FIXME("(%p)->(%d)\n", This, lIndex);
592     return E_NOTIMPL;
593 }
594
595 static HRESULT WINAPI HTMLStyleSheet_removeRule(IHTMLStyleSheet *iface, LONG lIndex)
596 {
597     HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
598     FIXME("(%p)->(%d)\n", This, lIndex);
599     return E_NOTIMPL;
600 }
601
602 static HRESULT WINAPI HTMLStyleSheet_put_media(IHTMLStyleSheet *iface, BSTR v)
603 {
604     HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
605     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
606     return E_NOTIMPL;
607 }
608
609 static HRESULT WINAPI HTMLStyleSheet_get_media(IHTMLStyleSheet *iface, BSTR *p)
610 {
611     HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
612     FIXME("(%p)->(%p)\n", This, p);
613     return E_NOTIMPL;
614 }
615
616 static HRESULT WINAPI HTMLStyleSheet_put_cssText(IHTMLStyleSheet *iface, BSTR v)
617 {
618     HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
619     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
620     return E_NOTIMPL;
621 }
622
623 static HRESULT WINAPI HTMLStyleSheet_get_cssText(IHTMLStyleSheet *iface, BSTR *p)
624 {
625     HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
626     FIXME("(%p)->(%p)\n", This, p);
627     return E_NOTIMPL;
628 }
629
630 static HRESULT WINAPI HTMLStyleSheet_get_rules(IHTMLStyleSheet *iface,
631                                                IHTMLStyleSheetRulesCollection **p)
632 {
633     HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
634     nsIDOMCSSRuleList *nslist = NULL;
635     nsresult nsres;
636
637     TRACE("(%p)->(%p)\n", This, p);
638
639     /* Gecko has buggy security checks and GetCssRules will fail. We have a correct
640      * implementation and it will work when the bug will be fixed in Gecko. */
641     nsres = nsIDOMCSSStyleSheet_GetCssRules(This->nsstylesheet, &nslist);
642     if(NS_FAILED(nsres))
643         WARN("GetCssRules failed: %08x\n", nsres);
644
645     *p = HTMLStyleSheetRulesCollection_Create(nslist);
646     return S_OK;
647 }
648
649 static const IHTMLStyleSheetVtbl HTMLStyleSheetVtbl = {
650     HTMLStyleSheet_QueryInterface,
651     HTMLStyleSheet_AddRef,
652     HTMLStyleSheet_Release,
653     HTMLStyleSheet_GetTypeInfoCount,
654     HTMLStyleSheet_GetTypeInfo,
655     HTMLStyleSheet_GetIDsOfNames,
656     HTMLStyleSheet_Invoke,
657     HTMLStyleSheet_put_title,
658     HTMLStyleSheet_get_title,
659     HTMLStyleSheet_get_parentStyleSheet,
660     HTMLStyleSheet_get_owningElement,
661     HTMLStyleSheet_put_disabled,
662     HTMLStyleSheet_get_disabled,
663     HTMLStyleSheet_get_readOnly,
664     HTMLStyleSheet_get_imports,
665     HTMLStyleSheet_put_href,
666     HTMLStyleSheet_get_href,
667     HTMLStyleSheet_get_type,
668     HTMLStyleSheet_get_id,
669     HTMLStyleSheet_addImport,
670     HTMLStyleSheet_addRule,
671     HTMLStyleSheet_removeImport,
672     HTMLStyleSheet_removeRule,
673     HTMLStyleSheet_put_media,
674     HTMLStyleSheet_get_media,
675     HTMLStyleSheet_put_cssText,
676     HTMLStyleSheet_get_cssText,
677     HTMLStyleSheet_get_rules
678 };
679
680 IHTMLStyleSheet *HTMLStyleSheet_Create(nsIDOMStyleSheet *nsstylesheet)
681 {
682     HTMLStyleSheet *ret = heap_alloc(sizeof(HTMLStyleSheet));
683     nsresult nsres;
684
685     ret->IHTMLStyleSheet_iface.lpVtbl = &HTMLStyleSheetVtbl;
686     ret->ref = 1;
687     ret->nsstylesheet = NULL;
688
689     if(nsstylesheet) {
690         nsres = nsIDOMStyleSheet_QueryInterface(nsstylesheet, &IID_nsIDOMCSSStyleSheet,
691                 (void**)&ret->nsstylesheet);
692         if(NS_FAILED(nsres))
693             ERR("Could not get nsICSSStyleSheet interface: %08x\n", nsres);
694     }
695
696     return &ret->IHTMLStyleSheet_iface;
697 }