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