gdi32: Fix leak in GdiDeleteSpoolFileHandle.
[wine.git] / dlls / mshtml / htmlstylesheet.c
blob496eabb485aa441ab071e184bb5369a83455d844
1 /*
2 * Copyright 2006 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
19 #include <stdarg.h>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "ole2.h"
28 #include "wine/debug.h"
30 #include "mshtml_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
34 struct HTMLStyleSheet {
35 DispatchEx dispex;
36 IHTMLStyleSheet IHTMLStyleSheet_iface;
37 IHTMLStyleSheet4 IHTMLStyleSheet4_iface;
39 nsIDOMCSSStyleSheet *nsstylesheet;
42 struct HTMLStyleSheetsCollection {
43 DispatchEx dispex;
44 IHTMLStyleSheetsCollection IHTMLStyleSheetsCollection_iface;
46 nsIDOMStyleSheetList *nslist;
49 typedef struct {
50 IEnumVARIANT IEnumVARIANT_iface;
52 LONG ref;
54 ULONG iter;
55 HTMLStyleSheetsCollection *col;
56 } HTMLStyleSheetsCollectionEnum;
58 struct HTMLStyleSheetRulesCollection {
59 DispatchEx dispex;
60 IHTMLStyleSheetRulesCollection IHTMLStyleSheetRulesCollection_iface;
62 nsIDOMCSSRuleList *nslist;
65 struct HTMLStyleSheetRule {
66 DispatchEx dispex;
67 IHTMLStyleSheetRule IHTMLStyleSheetRule_iface;
69 nsIDOMCSSRule *nsstylesheetrule;
72 static inline HTMLStyleSheetRule *impl_from_IHTMLStyleSheetRule(IHTMLStyleSheetRule *iface)
74 return CONTAINING_RECORD(iface, HTMLStyleSheetRule, IHTMLStyleSheetRule_iface);
77 static HRESULT WINAPI HTMLStyleSheetRule_QueryInterface(IHTMLStyleSheetRule *iface,
78 REFIID riid, void **ppv)
80 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
81 return IDispatchEx_QueryInterface(&This->dispex.IDispatchEx_iface, riid, ppv);
84 static ULONG WINAPI HTMLStyleSheetRule_AddRef(IHTMLStyleSheetRule *iface)
86 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
87 return IDispatchEx_AddRef(&This->dispex.IDispatchEx_iface);
90 static ULONG WINAPI HTMLStyleSheetRule_Release(IHTMLStyleSheetRule *iface)
92 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
93 return IDispatchEx_Release(&This->dispex.IDispatchEx_iface);
96 static HRESULT WINAPI HTMLStyleSheetRule_GetTypeInfoCount(
97 IHTMLStyleSheetRule *iface, UINT *pctinfo)
99 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
100 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
103 static HRESULT WINAPI HTMLStyleSheetRule_GetTypeInfo(IHTMLStyleSheetRule *iface,
104 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
106 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
107 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
110 static HRESULT WINAPI HTMLStyleSheetRule_GetIDsOfNames(IHTMLStyleSheetRule *iface,
111 REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
113 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
114 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
115 lcid, rgDispId);
118 static HRESULT WINAPI HTMLStyleSheetRule_Invoke(IHTMLStyleSheetRule *iface,
119 DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
120 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
122 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
123 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
124 pDispParams, pVarResult, pExcepInfo, puArgErr);
127 static HRESULT WINAPI HTMLStyleSheetRule_put_selectorText(IHTMLStyleSheetRule *iface, BSTR v)
129 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
130 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
131 return E_NOTIMPL;
134 static HRESULT WINAPI HTMLStyleSheetRule_get_selectorText(IHTMLStyleSheetRule *iface, BSTR *p)
136 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
137 FIXME("(%p)->(%p)\n", This, p);
138 return E_NOTIMPL;
141 static HRESULT WINAPI HTMLStyleSheetRule_get_style(IHTMLStyleSheetRule *iface, IHTMLRuleStyle **p)
143 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
144 FIXME("(%p)->(%p)\n", This, p);
145 return E_NOTIMPL;
148 static HRESULT WINAPI HTMLStyleSheetRule_get_readOnly(IHTMLStyleSheetRule *iface, VARIANT_BOOL *p)
150 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
151 FIXME("(%p)->(%p)\n", This, p);
152 return E_NOTIMPL;
155 static const IHTMLStyleSheetRuleVtbl HTMLStyleSheetRuleVtbl = {
156 HTMLStyleSheetRule_QueryInterface,
157 HTMLStyleSheetRule_AddRef,
158 HTMLStyleSheetRule_Release,
159 HTMLStyleSheetRule_GetTypeInfoCount,
160 HTMLStyleSheetRule_GetTypeInfo,
161 HTMLStyleSheetRule_GetIDsOfNames,
162 HTMLStyleSheetRule_Invoke,
163 HTMLStyleSheetRule_put_selectorText,
164 HTMLStyleSheetRule_get_selectorText,
165 HTMLStyleSheetRule_get_style,
166 HTMLStyleSheetRule_get_readOnly
169 static inline HTMLStyleSheetRule *HTMLStyleSheetRule_from_DispatchEx(DispatchEx *iface)
171 return CONTAINING_RECORD(iface, HTMLStyleSheetRule, dispex);
174 static void *HTMLStyleSheetRule_query_interface(DispatchEx *dispex, REFIID riid)
176 HTMLStyleSheetRule *This = HTMLStyleSheetRule_from_DispatchEx(dispex);
178 if(IsEqualGUID(&IID_IHTMLStyleSheetRule, riid))
179 return &This->IHTMLStyleSheetRule_iface;
181 return NULL;
184 static void HTMLStyleSheetRule_traverse(DispatchEx *dispex, nsCycleCollectionTraversalCallback *cb)
186 HTMLStyleSheetRule *This = HTMLStyleSheetRule_from_DispatchEx(dispex);
187 if(This->nsstylesheetrule)
188 note_cc_edge((nsISupports*)This->nsstylesheetrule, "nsstylesheetrule", cb);
191 static void HTMLStyleSheetRule_unlink(DispatchEx *dispex)
193 HTMLStyleSheetRule *This = HTMLStyleSheetRule_from_DispatchEx(dispex);
194 unlink_ref(&This->nsstylesheetrule);
197 static void HTMLStyleSheetRule_destructor(DispatchEx *dispex)
199 HTMLStyleSheetRule *This = HTMLStyleSheetRule_from_DispatchEx(dispex);
200 free(This);
203 static const dispex_static_data_vtbl_t HTMLStyleSheetRule_dispex_vtbl = {
204 .query_interface = HTMLStyleSheetRule_query_interface,
205 .destructor = HTMLStyleSheetRule_destructor,
206 .traverse = HTMLStyleSheetRule_traverse,
207 .unlink = HTMLStyleSheetRule_unlink
210 static const tid_t HTMLStyleSheetRule_iface_tids[] = {
211 IHTMLStyleSheetRule_tid,
214 static dispex_static_data_t HTMLStyleSheetRule_dispex = {
215 "CSSStyleRule",
216 &HTMLStyleSheetRule_dispex_vtbl,
217 DispHTMLStyleSheetRule_tid,
218 HTMLStyleSheetRule_iface_tids
221 static HRESULT create_style_sheet_rule(nsIDOMCSSRule *nsstylesheetrule, compat_mode_t compat_mode,
222 IHTMLStyleSheetRule **ret)
224 HTMLStyleSheetRule *rule;
225 nsresult nsres;
227 if(!(rule = malloc(sizeof(*rule))))
228 return E_OUTOFMEMORY;
230 rule->IHTMLStyleSheetRule_iface.lpVtbl = &HTMLStyleSheetRuleVtbl;
231 rule->nsstylesheetrule = NULL;
233 init_dispatch(&rule->dispex, &HTMLStyleSheetRule_dispex, compat_mode);
235 if (nsstylesheetrule)
237 nsres = nsIDOMCSSRule_QueryInterface(nsstylesheetrule, &IID_nsIDOMCSSRule,
238 (void **)&rule->nsstylesheetrule);
239 if (NS_FAILED(nsres))
240 ERR("Could not get nsIDOMCSSRule interface: %08lx\n", nsres);
243 *ret = &rule->IHTMLStyleSheetRule_iface;
244 return S_OK;
247 static inline HTMLStyleSheetRulesCollection *impl_from_IHTMLStyleSheetRulesCollection(IHTMLStyleSheetRulesCollection *iface)
249 return CONTAINING_RECORD(iface, HTMLStyleSheetRulesCollection, IHTMLStyleSheetRulesCollection_iface);
252 static HRESULT WINAPI HTMLStyleSheetRulesCollection_QueryInterface(IHTMLStyleSheetRulesCollection *iface,
253 REFIID riid, void **ppv)
255 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
256 return IDispatchEx_QueryInterface(&This->dispex.IDispatchEx_iface, riid, ppv);
259 static ULONG WINAPI HTMLStyleSheetRulesCollection_AddRef(IHTMLStyleSheetRulesCollection *iface)
261 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
262 return IDispatchEx_AddRef(&This->dispex.IDispatchEx_iface);
265 static ULONG WINAPI HTMLStyleSheetRulesCollection_Release(IHTMLStyleSheetRulesCollection *iface)
267 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
268 return IDispatchEx_Release(&This->dispex.IDispatchEx_iface);
271 static HRESULT WINAPI HTMLStyleSheetRulesCollection_GetTypeInfoCount(
272 IHTMLStyleSheetRulesCollection *iface, UINT *pctinfo)
274 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
275 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
278 static HRESULT WINAPI HTMLStyleSheetRulesCollection_GetTypeInfo(IHTMLStyleSheetRulesCollection *iface,
279 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
281 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
282 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
285 static HRESULT WINAPI HTMLStyleSheetRulesCollection_GetIDsOfNames(IHTMLStyleSheetRulesCollection *iface,
286 REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
288 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
289 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
290 lcid, rgDispId);
293 static HRESULT WINAPI HTMLStyleSheetRulesCollection_Invoke(IHTMLStyleSheetRulesCollection *iface,
294 DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
295 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
297 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
298 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
299 pDispParams, pVarResult, pExcepInfo, puArgErr);
302 static HRESULT WINAPI HTMLStyleSheetRulesCollection_get_length(IHTMLStyleSheetRulesCollection *iface,
303 LONG *p)
305 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
306 UINT32 len = 0;
308 TRACE("(%p)->(%p)\n", This, p);
310 if(This->nslist) {
311 nsresult nsres;
313 nsres = nsIDOMCSSRuleList_GetLength(This->nslist, &len);
314 if(NS_FAILED(nsres))
315 ERR("GetLength failed: %08lx\n", nsres);
318 *p = len;
319 return S_OK;
322 static HRESULT WINAPI HTMLStyleSheetRulesCollection_item(IHTMLStyleSheetRulesCollection *iface,
323 LONG index, IHTMLStyleSheetRule **p)
325 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
326 nsIDOMCSSRule *nsstylesheetrule;
327 nsresult nsres;
328 HRESULT hres;
330 TRACE("(%p)->(%ld %p)\n", This, index, p);
332 nsres = nsIDOMCSSRuleList_Item(This->nslist, index, &nsstylesheetrule);
333 if(NS_FAILED(nsres))
334 return map_nsresult(nsres);
335 if(!nsstylesheetrule)
336 return E_INVALIDARG;
338 hres = create_style_sheet_rule(nsstylesheetrule, dispex_compat_mode(&This->dispex), p);
339 nsIDOMCSSRule_Release(nsstylesheetrule);
340 return hres;
343 static const IHTMLStyleSheetRulesCollectionVtbl HTMLStyleSheetRulesCollectionVtbl = {
344 HTMLStyleSheetRulesCollection_QueryInterface,
345 HTMLStyleSheetRulesCollection_AddRef,
346 HTMLStyleSheetRulesCollection_Release,
347 HTMLStyleSheetRulesCollection_GetTypeInfoCount,
348 HTMLStyleSheetRulesCollection_GetTypeInfo,
349 HTMLStyleSheetRulesCollection_GetIDsOfNames,
350 HTMLStyleSheetRulesCollection_Invoke,
351 HTMLStyleSheetRulesCollection_get_length,
352 HTMLStyleSheetRulesCollection_item
355 static inline HTMLStyleSheetRulesCollection *HTMLStyleSheetRulesCollection_from_DispatchEx(DispatchEx *iface)
357 return CONTAINING_RECORD(iface, HTMLStyleSheetRulesCollection, dispex);
360 static void *HTMLStyleSheetRulesCollection_query_interface(DispatchEx *dispex, REFIID riid)
362 HTMLStyleSheetRulesCollection *This = HTMLStyleSheetRulesCollection_from_DispatchEx(dispex);
364 if(IsEqualGUID(&IID_IHTMLStyleSheetRulesCollection, riid))
365 return &This->IHTMLStyleSheetRulesCollection_iface;
367 return NULL;
370 static void HTMLStyleSheetRulesCollection_traverse(DispatchEx *dispex, nsCycleCollectionTraversalCallback *cb)
372 HTMLStyleSheetRulesCollection *This = HTMLStyleSheetRulesCollection_from_DispatchEx(dispex);
373 if(This->nslist)
374 note_cc_edge((nsISupports*)This->nslist, "nslist", cb);
377 static void HTMLStyleSheetRulesCollection_unlink(DispatchEx *dispex)
379 HTMLStyleSheetRulesCollection *This = HTMLStyleSheetRulesCollection_from_DispatchEx(dispex);
380 unlink_ref(&This->nslist);
383 static void HTMLStyleSheetRulesCollection_destructor(DispatchEx *dispex)
385 HTMLStyleSheetRulesCollection *This = HTMLStyleSheetRulesCollection_from_DispatchEx(dispex);
386 free(This);
389 static HRESULT HTMLStyleSheetRulesCollection_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
391 HTMLStyleSheetRulesCollection *This = HTMLStyleSheetRulesCollection_from_DispatchEx(dispex);
392 UINT32 len = 0;
393 DWORD idx = 0;
394 WCHAR *ptr;
396 for(ptr = name; *ptr && is_digit(*ptr); ptr++)
397 idx = idx*10 + (*ptr-'0');
398 if(*ptr)
399 return DISP_E_UNKNOWNNAME;
401 nsIDOMCSSRuleList_GetLength(This->nslist, &len);
402 if(idx >= len)
403 return DISP_E_UNKNOWNNAME;
405 *dispid = MSHTML_DISPID_CUSTOM_MIN + idx;
406 TRACE("ret %lx\n", *dispid);
407 return S_OK;
410 static HRESULT HTMLStyleSheetRulesCollection_get_name(DispatchEx *dispex, DISPID id, BSTR *name)
412 HTMLStyleSheetRulesCollection *This = HTMLStyleSheetRulesCollection_from_DispatchEx(dispex);
413 DWORD idx = id - MSHTML_DISPID_CUSTOM_MIN;
414 UINT32 len = 0;
415 WCHAR buf[11];
417 nsIDOMCSSRuleList_GetLength(This->nslist, &len);
418 if(idx >= len)
419 return DISP_E_MEMBERNOTFOUND;
421 len = swprintf(buf, ARRAY_SIZE(buf), L"%u", idx);
422 return (*name = SysAllocStringLen(buf, len)) ? S_OK : E_OUTOFMEMORY;
425 static HRESULT HTMLStyleSheetRulesCollection_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
426 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
428 HTMLStyleSheetRulesCollection *This = HTMLStyleSheetRulesCollection_from_DispatchEx(dispex);
430 TRACE("(%p)->(%lx %lx %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
432 switch(flags) {
433 case DISPATCH_PROPERTYGET: {
434 IHTMLStyleSheetRule *stylesheetrule;
435 nsIDOMCSSRule *nsstylesheetrule;
436 nsresult nsres;
437 HRESULT hres;
439 nsres = nsIDOMCSSRuleList_Item(This->nslist, id - MSHTML_DISPID_CUSTOM_MIN, &nsstylesheetrule);
440 if(NS_FAILED(nsres))
441 return DISP_E_MEMBERNOTFOUND;
442 if(!nsstylesheetrule) {
443 V_VT(res) = VT_EMPTY;
444 return S_OK;
447 hres = create_style_sheet_rule(nsstylesheetrule, dispex_compat_mode(&This->dispex), &stylesheetrule);
448 nsIDOMCSSRule_Release(nsstylesheetrule);
449 if(FAILED(hres))
450 return hres;
452 V_VT(res) = VT_DISPATCH;
453 V_DISPATCH(res) = (IDispatch*)stylesheetrule;
454 break;
457 default:
458 FIXME("unimplemented flags %x\n", flags);
459 return E_NOTIMPL;
462 return S_OK;
465 static const dispex_static_data_vtbl_t HTMLStyleSheetRulesCollection_dispex_vtbl = {
466 .query_interface = HTMLStyleSheetRulesCollection_query_interface,
467 .destructor = HTMLStyleSheetRulesCollection_destructor,
468 .traverse = HTMLStyleSheetRulesCollection_traverse,
469 .unlink = HTMLStyleSheetRulesCollection_unlink,
470 .get_dispid = HTMLStyleSheetRulesCollection_get_dispid,
471 .get_name = HTMLStyleSheetRulesCollection_get_name,
472 .invoke = HTMLStyleSheetRulesCollection_invoke
474 static const tid_t HTMLStyleSheetRulesCollection_iface_tids[] = {
475 IHTMLStyleSheetRulesCollection_tid,
478 static dispex_static_data_t HTMLStyleSheetRulesCollection_dispex = {
479 "MSCSSRuleList",
480 &HTMLStyleSheetRulesCollection_dispex_vtbl,
481 DispHTMLStyleSheetRulesCollection_tid,
482 HTMLStyleSheetRulesCollection_iface_tids
485 static HRESULT create_style_sheet_rules_collection(nsIDOMCSSRuleList *nslist, compat_mode_t compat_mode,
486 IHTMLStyleSheetRulesCollection **ret)
488 HTMLStyleSheetRulesCollection *collection;
490 if(!(collection = malloc(sizeof(*collection))))
491 return E_OUTOFMEMORY;
493 collection->IHTMLStyleSheetRulesCollection_iface.lpVtbl = &HTMLStyleSheetRulesCollectionVtbl;
494 collection->nslist = nslist;
496 init_dispatch(&collection->dispex, &HTMLStyleSheetRulesCollection_dispex, compat_mode);
498 if(nslist)
499 nsIDOMCSSRuleList_AddRef(nslist);
501 *ret = &collection->IHTMLStyleSheetRulesCollection_iface;
502 return S_OK;
505 static inline HTMLStyleSheetsCollectionEnum *HTMLStyleSheetsCollectionEnum_from_IEnumVARIANT(IEnumVARIANT *iface)
507 return CONTAINING_RECORD(iface, HTMLStyleSheetsCollectionEnum, IEnumVARIANT_iface);
510 static HRESULT WINAPI HTMLStyleSheetsCollectionEnum_QueryInterface(IEnumVARIANT *iface, REFIID riid, void **ppv)
512 HTMLStyleSheetsCollectionEnum *This = HTMLStyleSheetsCollectionEnum_from_IEnumVARIANT(iface);
514 TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
516 if(IsEqualGUID(riid, &IID_IUnknown)) {
517 *ppv = &This->IEnumVARIANT_iface;
518 }else if(IsEqualGUID(riid, &IID_IEnumVARIANT)) {
519 *ppv = &This->IEnumVARIANT_iface;
520 }else {
521 FIXME("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
522 *ppv = NULL;
523 return E_NOINTERFACE;
526 IUnknown_AddRef((IUnknown*)*ppv);
527 return S_OK;
530 static ULONG WINAPI HTMLStyleSheetsCollectionEnum_AddRef(IEnumVARIANT *iface)
532 HTMLStyleSheetsCollectionEnum *This = HTMLStyleSheetsCollectionEnum_from_IEnumVARIANT(iface);
533 LONG ref = InterlockedIncrement(&This->ref);
535 TRACE("(%p) ref=%ld\n", This, ref);
537 return ref;
540 static ULONG WINAPI HTMLStyleSheetsCollectionEnum_Release(IEnumVARIANT *iface)
542 HTMLStyleSheetsCollectionEnum *This = HTMLStyleSheetsCollectionEnum_from_IEnumVARIANT(iface);
543 LONG ref = InterlockedDecrement(&This->ref);
545 TRACE("(%p) ref=%ld\n", This, ref);
547 if(!ref) {
548 IHTMLStyleSheetsCollection_Release(&This->col->IHTMLStyleSheetsCollection_iface);
549 free(This);
552 return ref;
555 static HRESULT WINAPI HTMLStyleSheetsCollectionEnum_Next(IEnumVARIANT *iface, ULONG celt, VARIANT *rgVar, ULONG *pCeltFetched)
557 HTMLStyleSheetsCollectionEnum *This = HTMLStyleSheetsCollectionEnum_from_IEnumVARIANT(iface);
558 VARIANT index;
559 HRESULT hres;
560 ULONG num, i;
561 UINT32 len;
563 TRACE("(%p)->(%lu %p %p)\n", This, celt, rgVar, pCeltFetched);
565 nsIDOMStyleSheetList_GetLength(This->col->nslist, &len);
566 num = min(len - This->iter, celt);
567 V_VT(&index) = VT_I4;
569 for(i = 0; i < num; i++) {
570 V_I4(&index) = This->iter + i;
571 hres = IHTMLStyleSheetsCollection_item(&This->col->IHTMLStyleSheetsCollection_iface, &index, &rgVar[i]);
572 if(FAILED(hres)) {
573 while(i--)
574 VariantClear(&rgVar[i]);
575 return hres;
579 This->iter += num;
580 if(pCeltFetched)
581 *pCeltFetched = num;
582 return num == celt ? S_OK : S_FALSE;
585 static HRESULT WINAPI HTMLStyleSheetsCollectionEnum_Skip(IEnumVARIANT *iface, ULONG celt)
587 HTMLStyleSheetsCollectionEnum *This = HTMLStyleSheetsCollectionEnum_from_IEnumVARIANT(iface);
588 UINT32 len;
590 TRACE("(%p)->(%lu)\n", This, celt);
592 nsIDOMStyleSheetList_GetLength(This->col->nslist, &len);
593 if(This->iter + celt > len) {
594 This->iter = len;
595 return S_FALSE;
598 This->iter += celt;
599 return S_OK;
602 static HRESULT WINAPI HTMLStyleSheetsCollectionEnum_Reset(IEnumVARIANT *iface)
604 HTMLStyleSheetsCollectionEnum *This = HTMLStyleSheetsCollectionEnum_from_IEnumVARIANT(iface);
606 TRACE("(%p)->()\n", This);
608 This->iter = 0;
609 return S_OK;
612 static HRESULT WINAPI HTMLStyleSheetsCollectionEnum_Clone(IEnumVARIANT *iface, IEnumVARIANT **ppEnum)
614 HTMLStyleSheetsCollectionEnum *This = HTMLStyleSheetsCollectionEnum_from_IEnumVARIANT(iface);
615 FIXME("(%p)->(%p)\n", This, ppEnum);
616 return E_NOTIMPL;
619 static const IEnumVARIANTVtbl HTMLStyleSheetsCollectionEnumVtbl = {
620 HTMLStyleSheetsCollectionEnum_QueryInterface,
621 HTMLStyleSheetsCollectionEnum_AddRef,
622 HTMLStyleSheetsCollectionEnum_Release,
623 HTMLStyleSheetsCollectionEnum_Next,
624 HTMLStyleSheetsCollectionEnum_Skip,
625 HTMLStyleSheetsCollectionEnum_Reset,
626 HTMLStyleSheetsCollectionEnum_Clone
629 static inline HTMLStyleSheetsCollection *impl_from_IHTMLStyleSheetsCollection(IHTMLStyleSheetsCollection *iface)
631 return CONTAINING_RECORD(iface, HTMLStyleSheetsCollection, IHTMLStyleSheetsCollection_iface);
634 static HRESULT WINAPI HTMLStyleSheetsCollection_QueryInterface(IHTMLStyleSheetsCollection *iface,
635 REFIID riid, void **ppv)
637 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
638 return IDispatchEx_QueryInterface(&This->dispex.IDispatchEx_iface, riid, ppv);
641 static ULONG WINAPI HTMLStyleSheetsCollection_AddRef(IHTMLStyleSheetsCollection *iface)
643 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
644 return IDispatchEx_AddRef(&This->dispex.IDispatchEx_iface);
647 static ULONG WINAPI HTMLStyleSheetsCollection_Release(IHTMLStyleSheetsCollection *iface)
649 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
650 return IDispatchEx_Release(&This->dispex.IDispatchEx_iface);
653 static HRESULT WINAPI HTMLStyleSheetsCollection_GetTypeInfoCount(IHTMLStyleSheetsCollection *iface,
654 UINT *pctinfo)
656 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
657 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
660 static HRESULT WINAPI HTMLStyleSheetsCollection_GetTypeInfo(IHTMLStyleSheetsCollection *iface,
661 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
663 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
664 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
667 static HRESULT WINAPI HTMLStyleSheetsCollection_GetIDsOfNames(IHTMLStyleSheetsCollection *iface,
668 REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
670 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
671 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
672 lcid, rgDispId);
675 static HRESULT WINAPI HTMLStyleSheetsCollection_Invoke(IHTMLStyleSheetsCollection *iface,
676 DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
677 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
679 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
680 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
681 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
684 static HRESULT WINAPI HTMLStyleSheetsCollection_get_length(IHTMLStyleSheetsCollection *iface,
685 LONG *p)
687 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
688 UINT32 len = 0;
690 TRACE("(%p)->(%p)\n", This, p);
692 if(This->nslist)
693 nsIDOMStyleSheetList_GetLength(This->nslist, &len);
695 *p = len;
696 return S_OK;
699 static HRESULT WINAPI HTMLStyleSheetsCollection_get__newEnum(IHTMLStyleSheetsCollection *iface,
700 IUnknown **p)
702 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
703 HTMLStyleSheetsCollectionEnum *ret;
705 TRACE("(%p)->(%p)\n", This, p);
707 ret = malloc(sizeof(*ret));
708 if(!ret)
709 return E_OUTOFMEMORY;
711 ret->IEnumVARIANT_iface.lpVtbl = &HTMLStyleSheetsCollectionEnumVtbl;
712 ret->ref = 1;
713 ret->iter = 0;
715 HTMLStyleSheetsCollection_AddRef(&This->IHTMLStyleSheetsCollection_iface);
716 ret->col = This;
718 *p = (IUnknown*)&ret->IEnumVARIANT_iface;
719 return S_OK;
722 static HRESULT WINAPI HTMLStyleSheetsCollection_item(IHTMLStyleSheetsCollection *iface,
723 VARIANT *pvarIndex, VARIANT *pvarResult)
725 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
727 TRACE("(%p)->(%s %p)\n", This, debugstr_variant(pvarIndex), pvarResult);
729 switch(V_VT(pvarIndex)) {
730 case VT_I4: {
731 nsIDOMStyleSheet *nsstylesheet;
732 IHTMLStyleSheet *stylesheet;
733 nsresult nsres;
734 HRESULT hres;
736 TRACE("index=%ld\n", V_I4(pvarIndex));
738 nsres = nsIDOMStyleSheetList_Item(This->nslist, V_I4(pvarIndex), &nsstylesheet);
739 if(NS_FAILED(nsres) || !nsstylesheet) {
740 WARN("Item failed: %08lx\n", nsres);
741 V_VT(pvarResult) = VT_EMPTY;
742 return E_INVALIDARG;
745 hres = create_style_sheet(nsstylesheet, dispex_compat_mode(&This->dispex), &stylesheet);
746 nsIDOMStyleSheet_Release(nsstylesheet);
747 if(FAILED(hres))
748 return hres;
750 V_VT(pvarResult) = VT_DISPATCH;
751 V_DISPATCH(pvarResult) = (IDispatch*)stylesheet;
752 return S_OK;
755 case VT_BSTR:
756 FIXME("id=%s not implemented\n", debugstr_w(V_BSTR(pvarResult)));
757 return E_NOTIMPL;
759 default:
760 WARN("Invalid index %s\n", debugstr_variant(pvarIndex));
763 return E_INVALIDARG;
766 static const IHTMLStyleSheetsCollectionVtbl HTMLStyleSheetsCollectionVtbl = {
767 HTMLStyleSheetsCollection_QueryInterface,
768 HTMLStyleSheetsCollection_AddRef,
769 HTMLStyleSheetsCollection_Release,
770 HTMLStyleSheetsCollection_GetTypeInfoCount,
771 HTMLStyleSheetsCollection_GetTypeInfo,
772 HTMLStyleSheetsCollection_GetIDsOfNames,
773 HTMLStyleSheetsCollection_Invoke,
774 HTMLStyleSheetsCollection_get_length,
775 HTMLStyleSheetsCollection_get__newEnum,
776 HTMLStyleSheetsCollection_item
779 static inline HTMLStyleSheetsCollection *HTMLStyleSheetsCollection_from_DispatchEx(DispatchEx *iface)
781 return CONTAINING_RECORD(iface, HTMLStyleSheetsCollection, dispex);
784 static void *HTMLStyleSheetsCollection_query_interface(DispatchEx *dispex, REFIID riid)
786 HTMLStyleSheetsCollection *This = HTMLStyleSheetsCollection_from_DispatchEx(dispex);
788 if(IsEqualGUID(&IID_IHTMLStyleSheetsCollection, riid))
789 return &This->IHTMLStyleSheetsCollection_iface;
791 return NULL;
794 static void HTMLStyleSheetsCollection_traverse(DispatchEx *dispex, nsCycleCollectionTraversalCallback *cb)
796 HTMLStyleSheetsCollection *This = HTMLStyleSheetsCollection_from_DispatchEx(dispex);
797 if(This->nslist)
798 note_cc_edge((nsISupports*)This->nslist, "nslist", cb);
801 static void HTMLStyleSheetsCollection_unlink(DispatchEx *dispex)
803 HTMLStyleSheetsCollection *This = HTMLStyleSheetsCollection_from_DispatchEx(dispex);
804 unlink_ref(&This->nslist);
807 static void HTMLStyleSheetsCollection_destructor(DispatchEx *dispex)
809 HTMLStyleSheetsCollection *This = HTMLStyleSheetsCollection_from_DispatchEx(dispex);
810 free(This);
813 static HRESULT HTMLStyleSheetsCollection_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
815 HTMLStyleSheetsCollection *This = HTMLStyleSheetsCollection_from_DispatchEx(dispex);
816 UINT32 len = 0;
817 DWORD idx = 0;
818 WCHAR *ptr;
820 for(ptr = name; *ptr && is_digit(*ptr); ptr++)
821 idx = idx*10 + (*ptr-'0');
822 if(*ptr)
823 return DISP_E_UNKNOWNNAME;
825 nsIDOMStyleSheetList_GetLength(This->nslist, &len);
826 if(idx >= len)
827 return DISP_E_UNKNOWNNAME;
829 *dispid = MSHTML_DISPID_CUSTOM_MIN + idx;
830 TRACE("ret %lx\n", *dispid);
831 return S_OK;
834 static HRESULT HTMLStyleSheetsCollection_get_name(DispatchEx *dispex, DISPID id, BSTR *name)
836 HTMLStyleSheetsCollection *This = HTMLStyleSheetsCollection_from_DispatchEx(dispex);
837 DWORD idx = id - MSHTML_DISPID_CUSTOM_MIN;
838 UINT32 len = 0;
839 WCHAR buf[11];
841 nsIDOMStyleSheetList_GetLength(This->nslist, &len);
842 if(idx >= len)
843 return DISP_E_MEMBERNOTFOUND;
845 len = swprintf(buf, ARRAY_SIZE(buf), L"%u", idx);
846 return (*name = SysAllocStringLen(buf, len)) ? S_OK : E_OUTOFMEMORY;
849 static HRESULT HTMLStyleSheetsCollection_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
850 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
852 HTMLStyleSheetsCollection *This = HTMLStyleSheetsCollection_from_DispatchEx(dispex);
854 TRACE("(%p)->(%lx %lx %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
856 switch(flags) {
857 case DISPATCH_PROPERTYGET: {
858 nsIDOMStyleSheet *nsstylesheet;
859 IHTMLStyleSheet *stylesheet;
860 nsresult nsres;
861 HRESULT hres;
863 nsres = nsIDOMStyleSheetList_Item(This->nslist, id - MSHTML_DISPID_CUSTOM_MIN, &nsstylesheet);
864 if(NS_FAILED(nsres))
865 return DISP_E_MEMBERNOTFOUND;
866 if(!nsstylesheet) {
867 V_VT(res) = VT_EMPTY;
868 return S_OK;
871 hres = create_style_sheet(nsstylesheet, dispex_compat_mode(&This->dispex), &stylesheet);
872 nsIDOMStyleSheet_Release(nsstylesheet);
873 if(FAILED(hres))
874 return hres;
876 V_VT(res) = VT_DISPATCH;
877 V_DISPATCH(res) = (IDispatch*)stylesheet;
878 break;
881 default:
882 FIXME("unimplemented flags %x\n", flags);
883 return E_NOTIMPL;
886 return S_OK;
889 static const dispex_static_data_vtbl_t HTMLStyleSheetsCollection_dispex_vtbl = {
890 .query_interface = HTMLStyleSheetsCollection_query_interface,
891 .destructor = HTMLStyleSheetsCollection_destructor,
892 .traverse = HTMLStyleSheetsCollection_traverse,
893 .unlink = HTMLStyleSheetsCollection_unlink,
894 .get_dispid = HTMLStyleSheetsCollection_get_dispid,
895 .get_name = HTMLStyleSheetsCollection_get_name,
896 .invoke = HTMLStyleSheetsCollection_invoke
898 static const tid_t HTMLStyleSheetsCollection_iface_tids[] = {
899 IHTMLStyleSheetsCollection_tid,
902 static dispex_static_data_t HTMLStyleSheetsCollection_dispex = {
903 "StyleSheetList",
904 &HTMLStyleSheetsCollection_dispex_vtbl,
905 DispHTMLStyleSheetsCollection_tid,
906 HTMLStyleSheetsCollection_iface_tids
909 HRESULT create_style_sheet_collection(nsIDOMStyleSheetList *nslist, compat_mode_t compat_mode,
910 IHTMLStyleSheetsCollection **ret)
912 HTMLStyleSheetsCollection *collection;
914 if(!(collection = malloc(sizeof(HTMLStyleSheetsCollection))))
915 return E_OUTOFMEMORY;
917 collection->IHTMLStyleSheetsCollection_iface.lpVtbl = &HTMLStyleSheetsCollectionVtbl;
919 if(nslist)
920 nsIDOMStyleSheetList_AddRef(nslist);
921 collection->nslist = nslist;
923 init_dispatch(&collection->dispex, &HTMLStyleSheetsCollection_dispex, compat_mode);
925 *ret = &collection->IHTMLStyleSheetsCollection_iface;
926 return S_OK;
929 static inline HTMLStyleSheet *impl_from_IHTMLStyleSheet(IHTMLStyleSheet *iface)
931 return CONTAINING_RECORD(iface, HTMLStyleSheet, IHTMLStyleSheet_iface);
934 static HRESULT WINAPI HTMLStyleSheet_QueryInterface(IHTMLStyleSheet *iface, REFIID riid, void **ppv)
936 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
937 return IDispatchEx_QueryInterface(&This->dispex.IDispatchEx_iface, riid, ppv);
940 static ULONG WINAPI HTMLStyleSheet_AddRef(IHTMLStyleSheet *iface)
942 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
943 return IDispatchEx_AddRef(&This->dispex.IDispatchEx_iface);
946 static ULONG WINAPI HTMLStyleSheet_Release(IHTMLStyleSheet *iface)
948 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
949 return IDispatchEx_Release(&This->dispex.IDispatchEx_iface);
952 static HRESULT WINAPI HTMLStyleSheet_GetTypeInfoCount(IHTMLStyleSheet *iface, UINT *pctinfo)
954 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
955 TRACE("(%p)->(%p)\n", This, pctinfo);
956 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
959 static HRESULT WINAPI HTMLStyleSheet_GetTypeInfo(IHTMLStyleSheet *iface, UINT iTInfo,
960 LCID lcid, ITypeInfo **ppTInfo)
962 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
963 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
966 static HRESULT WINAPI HTMLStyleSheet_GetIDsOfNames(IHTMLStyleSheet *iface, REFIID riid,
967 LPOLESTR *rgszNames, UINT cNames,
968 LCID lcid, DISPID *rgDispId)
970 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
971 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames, lcid, rgDispId);
974 static HRESULT WINAPI HTMLStyleSheet_Invoke(IHTMLStyleSheet *iface, DISPID dispIdMember,
975 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
976 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
978 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
979 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags, pDispParams,
980 pVarResult, pExcepInfo, puArgErr);
983 static HRESULT WINAPI HTMLStyleSheet_put_title(IHTMLStyleSheet *iface, BSTR v)
985 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
986 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
987 return E_NOTIMPL;
990 static HRESULT WINAPI HTMLStyleSheet_get_title(IHTMLStyleSheet *iface, BSTR *p)
992 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
993 FIXME("(%p)->(%p)\n", This, p);
994 return E_NOTIMPL;
997 static HRESULT WINAPI HTMLStyleSheet_get_parentStyleSheet(IHTMLStyleSheet *iface,
998 IHTMLStyleSheet **p)
1000 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1001 FIXME("(%p)->(%p)\n", This, p);
1002 return E_NOTIMPL;
1005 static HRESULT WINAPI HTMLStyleSheet_get_owningElement(IHTMLStyleSheet *iface, IHTMLElement **p)
1007 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1008 FIXME("(%p)->(%p)\n", This, p);
1009 return E_NOTIMPL;
1012 static HRESULT WINAPI HTMLStyleSheet_put_disabled(IHTMLStyleSheet *iface, VARIANT_BOOL v)
1014 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1015 FIXME("(%p)->(%x)\n", This, v);
1016 return E_NOTIMPL;
1019 static HRESULT WINAPI HTMLStyleSheet_get_disabled(IHTMLStyleSheet *iface, VARIANT_BOOL *p)
1021 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1022 FIXME("(%p)->(%p)\n", This, p);
1023 return E_NOTIMPL;
1026 static HRESULT WINAPI HTMLStyleSheet_get_readOnly(IHTMLStyleSheet *iface, VARIANT_BOOL *p)
1028 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1029 FIXME("(%p)->(%p)\n", This, p);
1030 return E_NOTIMPL;
1033 static HRESULT WINAPI HTMLStyleSheet_get_imports(IHTMLStyleSheet *iface,
1034 IHTMLStyleSheetsCollection **p)
1036 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1037 FIXME("(%p)->(%p)\n", This, p);
1038 return E_NOTIMPL;
1041 static HRESULT WINAPI HTMLStyleSheet_put_href(IHTMLStyleSheet *iface, BSTR v)
1043 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1044 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
1045 return E_NOTIMPL;
1048 static HRESULT WINAPI HTMLStyleSheet_get_href(IHTMLStyleSheet *iface, BSTR *p)
1050 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1051 nsAString href_str;
1052 nsresult nsres;
1054 TRACE("(%p)->(%p)\n", This, p);
1056 nsAString_Init(&href_str, NULL);
1057 nsres = nsIDOMCSSStyleSheet_GetHref(This->nsstylesheet, &href_str);
1058 return return_nsstr(nsres, &href_str, p);
1061 static HRESULT WINAPI HTMLStyleSheet_get_type(IHTMLStyleSheet *iface, BSTR *p)
1063 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1064 FIXME("(%p)->(%p)\n", This, p);
1065 return E_NOTIMPL;
1068 static HRESULT WINAPI HTMLStyleSheet_get_id(IHTMLStyleSheet *iface, BSTR *p)
1070 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1071 FIXME("(%p)->(%p)\n", This, p);
1072 return E_NOTIMPL;
1075 static HRESULT WINAPI HTMLStyleSheet_addImport(IHTMLStyleSheet *iface, BSTR bstrURL,
1076 LONG lIndex, LONG *plIndex)
1078 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1079 FIXME("(%p)->(%s %ld %p)\n", This, debugstr_w(bstrURL), lIndex, plIndex);
1080 return E_NOTIMPL;
1083 static HRESULT WINAPI HTMLStyleSheet_addRule(IHTMLStyleSheet *iface, BSTR bstrSelector,
1084 BSTR bstrStyle, LONG lIndex, LONG *plIndex)
1086 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1087 const WCHAR format[] = L"%s {%s}";
1088 nsIDOMCSSRuleList *nslist = NULL;
1089 UINT32 length, new_index;
1090 nsAString nsstr;
1091 nsresult nsres;
1092 WCHAR *rule;
1093 size_t len;
1095 TRACE("(%p)->(%s %s %ld %p)\n", This, debugstr_w(bstrSelector), debugstr_w(bstrStyle),
1096 lIndex, plIndex);
1098 if(!bstrSelector || !bstrStyle || !bstrSelector[0] || !bstrStyle[0])
1099 return E_INVALIDARG;
1101 nsres = nsIDOMCSSStyleSheet_GetCssRules(This->nsstylesheet, &nslist);
1102 if(NS_FAILED(nsres))
1103 return E_FAIL;
1104 nsIDOMCSSRuleList_GetLength(nslist, &length);
1106 if(lIndex > length)
1107 lIndex = length;
1109 len = ARRAY_SIZE(format) - 4 /* %s twice */ + wcslen(bstrSelector) + wcslen(bstrStyle);
1110 if(!(rule = malloc(len * sizeof(WCHAR))))
1111 return E_OUTOFMEMORY;
1112 swprintf(rule, len, format, bstrSelector, bstrStyle);
1114 nsAString_InitDepend(&nsstr, rule);
1115 nsres = nsIDOMCSSStyleSheet_InsertRule(This->nsstylesheet, &nsstr, lIndex, &new_index);
1116 if(NS_FAILED(nsres)) WARN("failed: %08lx\n", nsres);
1117 nsAString_Finish(&nsstr);
1118 free(rule);
1120 *plIndex = new_index;
1121 return map_nsresult(nsres);
1124 static HRESULT WINAPI HTMLStyleSheet_removeImport(IHTMLStyleSheet *iface, LONG lIndex)
1126 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1127 FIXME("(%p)->(%ld)\n", This, lIndex);
1128 return E_NOTIMPL;
1131 static HRESULT WINAPI HTMLStyleSheet_removeRule(IHTMLStyleSheet *iface, LONG lIndex)
1133 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1134 FIXME("(%p)->(%ld)\n", This, lIndex);
1135 return E_NOTIMPL;
1138 static HRESULT WINAPI HTMLStyleSheet_put_media(IHTMLStyleSheet *iface, BSTR v)
1140 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1141 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
1142 return E_NOTIMPL;
1145 static HRESULT WINAPI HTMLStyleSheet_get_media(IHTMLStyleSheet *iface, BSTR *p)
1147 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1148 FIXME("(%p)->(%p)\n", This, p);
1149 return E_NOTIMPL;
1152 static HRESULT WINAPI HTMLStyleSheet_put_cssText(IHTMLStyleSheet *iface, BSTR v)
1154 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1155 nsresult nsres;
1157 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1159 do {
1160 nsres = nsIDOMCSSStyleSheet_DeleteRule(This->nsstylesheet, 0);
1161 }while(NS_SUCCEEDED(nsres));
1163 if(v && *v) {
1164 nsAString nsstr;
1165 UINT32 idx;
1167 /* FIXME: This won't work for multiple rules in the string. */
1168 nsAString_InitDepend(&nsstr, v);
1169 nsres = nsIDOMCSSStyleSheet_InsertRule(This->nsstylesheet, &nsstr, 0, &idx);
1170 nsAString_Finish(&nsstr);
1171 if(NS_FAILED(nsres)) {
1172 FIXME("InsertRule failed for string %s. Probably multiple rules passed.\n", debugstr_w(v));
1173 return E_FAIL;
1177 return S_OK;
1180 static HRESULT WINAPI HTMLStyleSheet_get_cssText(IHTMLStyleSheet *iface, BSTR *p)
1182 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1183 nsIDOMCSSRuleList *nslist = NULL;
1184 nsIDOMCSSRule *nsrule;
1185 nsAString nsstr;
1186 UINT32 len;
1187 nsresult nsres;
1189 TRACE("(%p)->(%p)\n", This, p);
1191 nsres = nsIDOMCSSStyleSheet_GetCssRules(This->nsstylesheet, &nslist);
1192 if(NS_FAILED(nsres)) {
1193 ERR("GetCssRules failed: %08lx\n", nsres);
1194 return E_FAIL;
1197 nsres = nsIDOMCSSRuleList_GetLength(nslist, &len);
1198 assert(nsres == NS_OK);
1200 if(len) {
1201 nsres = nsIDOMCSSRuleList_Item(nslist, 0, &nsrule);
1202 if(NS_FAILED(nsres))
1203 ERR("Item failed: %08lx\n", nsres);
1206 nsIDOMCSSRuleList_Release(nslist);
1207 if(NS_FAILED(nsres))
1208 return E_FAIL;
1210 if(!len) {
1211 *p = NULL;
1212 return S_OK;
1215 nsAString_Init(&nsstr, NULL);
1216 nsres = nsIDOMCSSRule_GetCssText(nsrule, &nsstr);
1217 nsIDOMCSSRule_Release(nsrule);
1218 return return_nsstr(nsres, &nsstr, p);
1221 static HRESULT WINAPI HTMLStyleSheet_get_rules(IHTMLStyleSheet *iface,
1222 IHTMLStyleSheetRulesCollection **p)
1224 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1225 nsIDOMCSSRuleList *nslist = NULL;
1226 nsresult nsres;
1227 HRESULT hres;
1229 TRACE("(%p)->(%p)\n", This, p);
1231 nsres = nsIDOMCSSStyleSheet_GetCssRules(This->nsstylesheet, &nslist);
1232 if(NS_FAILED(nsres)) {
1233 ERR("GetCssRules failed: %08lx\n", nsres);
1234 return E_FAIL;
1237 hres = create_style_sheet_rules_collection(nslist, dispex_compat_mode(&This->dispex), p);
1238 nsIDOMCSSRuleList_Release(nslist);
1239 return hres;
1242 static const IHTMLStyleSheetVtbl HTMLStyleSheetVtbl = {
1243 HTMLStyleSheet_QueryInterface,
1244 HTMLStyleSheet_AddRef,
1245 HTMLStyleSheet_Release,
1246 HTMLStyleSheet_GetTypeInfoCount,
1247 HTMLStyleSheet_GetTypeInfo,
1248 HTMLStyleSheet_GetIDsOfNames,
1249 HTMLStyleSheet_Invoke,
1250 HTMLStyleSheet_put_title,
1251 HTMLStyleSheet_get_title,
1252 HTMLStyleSheet_get_parentStyleSheet,
1253 HTMLStyleSheet_get_owningElement,
1254 HTMLStyleSheet_put_disabled,
1255 HTMLStyleSheet_get_disabled,
1256 HTMLStyleSheet_get_readOnly,
1257 HTMLStyleSheet_get_imports,
1258 HTMLStyleSheet_put_href,
1259 HTMLStyleSheet_get_href,
1260 HTMLStyleSheet_get_type,
1261 HTMLStyleSheet_get_id,
1262 HTMLStyleSheet_addImport,
1263 HTMLStyleSheet_addRule,
1264 HTMLStyleSheet_removeImport,
1265 HTMLStyleSheet_removeRule,
1266 HTMLStyleSheet_put_media,
1267 HTMLStyleSheet_get_media,
1268 HTMLStyleSheet_put_cssText,
1269 HTMLStyleSheet_get_cssText,
1270 HTMLStyleSheet_get_rules
1273 static inline HTMLStyleSheet *impl_from_IHTMLStyleSheet4(IHTMLStyleSheet4 *iface)
1275 return CONTAINING_RECORD(iface, HTMLStyleSheet, IHTMLStyleSheet4_iface);
1278 static HRESULT WINAPI HTMLStyleSheet4_QueryInterface(IHTMLStyleSheet4 *iface, REFIID riid, void **ppv)
1280 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1281 return IHTMLStyleSheet_QueryInterface(&This->IHTMLStyleSheet_iface, riid, ppv);
1284 static ULONG WINAPI HTMLStyleSheet4_AddRef(IHTMLStyleSheet4 *iface)
1286 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1287 return IHTMLStyleSheet_AddRef(&This->IHTMLStyleSheet_iface);
1290 static ULONG WINAPI HTMLStyleSheet4_Release(IHTMLStyleSheet4 *iface)
1292 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1293 return IHTMLStyleSheet_Release(&This->IHTMLStyleSheet_iface);
1296 static HRESULT WINAPI HTMLStyleSheet4_GetTypeInfoCount(IHTMLStyleSheet4 *iface, UINT *pctinfo)
1298 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1299 TRACE("(%p)->(%p)\n", This, pctinfo);
1300 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
1303 static HRESULT WINAPI HTMLStyleSheet4_GetTypeInfo(IHTMLStyleSheet4 *iface, UINT iTInfo,
1304 LCID lcid, ITypeInfo **ppTInfo)
1306 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1307 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1310 static HRESULT WINAPI HTMLStyleSheet4_GetIDsOfNames(IHTMLStyleSheet4 *iface, REFIID riid,
1311 LPOLESTR *rgszNames, UINT cNames,
1312 LCID lcid, DISPID *rgDispId)
1314 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1315 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames, lcid, rgDispId);
1318 static HRESULT WINAPI HTMLStyleSheet4_Invoke(IHTMLStyleSheet4 *iface, DISPID dispIdMember,
1319 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1320 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1322 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1323 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags, pDispParams,
1324 pVarResult, pExcepInfo, puArgErr);
1327 static HRESULT WINAPI HTMLStyleSheet4_get_type(IHTMLStyleSheet4 *iface, BSTR *p)
1329 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1330 TRACE("(%p)->(%p)\n", This, p);
1331 return IHTMLStyleSheet_get_type(&This->IHTMLStyleSheet_iface, p);
1334 static HRESULT WINAPI HTMLStyleSheet4_get_href(IHTMLStyleSheet4 *iface, VARIANT *p)
1336 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1337 nsAString href_str;
1338 nsresult nsres;
1340 TRACE("(%p)->(%p)\n", This, p);
1342 nsAString_Init(&href_str, NULL);
1343 nsres = nsIDOMCSSStyleSheet_GetHref(This->nsstylesheet, &href_str);
1344 return return_nsstr_variant(nsres, &href_str, 0, p);
1347 static HRESULT WINAPI HTMLStyleSheet4_get_title(IHTMLStyleSheet4 *iface, BSTR *p)
1349 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1350 FIXME("(%p)->(%p)\n", This, p);
1351 return E_NOTIMPL;
1354 static HRESULT WINAPI HTMLStyleSheet4_get_ownerNode(IHTMLStyleSheet4 *iface, IHTMLElement **p)
1356 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1357 FIXME("(%p)->(%p)\n", This, p);
1358 return E_NOTIMPL;
1361 static HRESULT WINAPI HTMLStyleSheet4_get_ownerRule(IHTMLStyleSheet4 *iface, IHTMLCSSRule **p)
1363 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1364 FIXME("(%p)->(%p)\n", This, p);
1365 return E_NOTIMPL;
1368 static HRESULT WINAPI HTMLStyleSheet4_get_cssRules(IHTMLStyleSheet4 *iface, IHTMLStyleSheetRulesCollection **p)
1370 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1371 TRACE("(%p)->(%p)\n", This, p);
1372 return IHTMLStyleSheet_get_rules(&This->IHTMLStyleSheet_iface, p);
1375 static HRESULT WINAPI HTMLStyleSheet4_get_media(IHTMLStyleSheet4 *iface, VARIANT *p)
1377 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1378 FIXME("(%p)->(%p)\n", This, p);
1379 return E_NOTIMPL;
1382 static HRESULT WINAPI HTMLStyleSheet4_insertRule(IHTMLStyleSheet4 *iface, BSTR rule, LONG index, LONG *p)
1384 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1385 UINT32 new_index = 0;
1386 nsAString nsstr;
1387 nsresult nsres;
1389 TRACE("(%p)->(%s %ld %p)\n", This, debugstr_w(rule), index, p);
1391 nsAString_InitDepend(&nsstr, rule);
1392 nsres = nsIDOMCSSStyleSheet_InsertRule(This->nsstylesheet, &nsstr, index, &new_index);
1393 if(NS_FAILED(nsres)) WARN("failed: %08lx\n", nsres);
1394 nsAString_Finish(&nsstr);
1395 *p = new_index;
1396 return map_nsresult(nsres);
1399 static HRESULT WINAPI HTMLStyleSheet4_deleteRule(IHTMLStyleSheet4 *iface, LONG index)
1401 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1402 FIXME("(%p)->(%ld)\n", This, index);
1403 return E_NOTIMPL;
1406 static const IHTMLStyleSheet4Vtbl HTMLStyleSheet4Vtbl = {
1407 HTMLStyleSheet4_QueryInterface,
1408 HTMLStyleSheet4_AddRef,
1409 HTMLStyleSheet4_Release,
1410 HTMLStyleSheet4_GetTypeInfoCount,
1411 HTMLStyleSheet4_GetTypeInfo,
1412 HTMLStyleSheet4_GetIDsOfNames,
1413 HTMLStyleSheet4_Invoke,
1414 HTMLStyleSheet4_get_type,
1415 HTMLStyleSheet4_get_href,
1416 HTMLStyleSheet4_get_title,
1417 HTMLStyleSheet4_get_ownerNode,
1418 HTMLStyleSheet4_get_ownerRule,
1419 HTMLStyleSheet4_get_cssRules,
1420 HTMLStyleSheet4_get_media,
1421 HTMLStyleSheet4_insertRule,
1422 HTMLStyleSheet4_deleteRule,
1425 static inline HTMLStyleSheet *HTMLStyleSheet_from_DispatchEx(DispatchEx *iface)
1427 return CONTAINING_RECORD(iface, HTMLStyleSheet, dispex);
1430 static void *HTMLStyleSheet_query_interface(DispatchEx *dispex, REFIID riid)
1432 HTMLStyleSheet *This = HTMLStyleSheet_from_DispatchEx(dispex);
1434 if(IsEqualGUID(&IID_IHTMLStyleSheet, riid))
1435 return &This->IHTMLStyleSheet_iface;
1436 if(IsEqualGUID(&IID_IHTMLStyleSheet4, riid))
1437 return &This->IHTMLStyleSheet4_iface;
1439 return NULL;
1442 static void HTMLStyleSheet_traverse(DispatchEx *dispex, nsCycleCollectionTraversalCallback *cb)
1444 HTMLStyleSheet *This = HTMLStyleSheet_from_DispatchEx(dispex);
1445 if(This->nsstylesheet)
1446 note_cc_edge((nsISupports*)This->nsstylesheet, "nsstylesheet", cb);
1449 static void HTMLStyleSheet_unlink(DispatchEx *dispex)
1451 HTMLStyleSheet *This = HTMLStyleSheet_from_DispatchEx(dispex);
1452 unlink_ref(&This->nsstylesheet);
1455 static void HTMLStyleSheet_destructor(DispatchEx *dispex)
1457 HTMLStyleSheet *This = HTMLStyleSheet_from_DispatchEx(dispex);
1458 free(This);
1461 static void HTMLStyleSheet_init_dispex_info(dispex_data_t *info, compat_mode_t mode)
1463 if(mode >= COMPAT_MODE_IE9)
1464 dispex_info_add_interface(info, IHTMLStyleSheet4_tid, NULL);
1467 static const dispex_static_data_vtbl_t HTMLStyleSheet_dispex_vtbl = {
1468 .query_interface = HTMLStyleSheet_query_interface,
1469 .destructor = HTMLStyleSheet_destructor,
1470 .traverse = HTMLStyleSheet_traverse,
1471 .unlink = HTMLStyleSheet_unlink
1474 static const tid_t HTMLStyleSheet_iface_tids[] = {
1475 IHTMLStyleSheet_tid,
1478 static dispex_static_data_t HTMLStyleSheet_dispex = {
1479 "CSSStyleSheet",
1480 &HTMLStyleSheet_dispex_vtbl,
1481 DispHTMLStyleSheet_tid,
1482 HTMLStyleSheet_iface_tids,
1483 HTMLStyleSheet_init_dispex_info
1486 HRESULT create_style_sheet(nsIDOMStyleSheet *nsstylesheet, compat_mode_t compat_mode, IHTMLStyleSheet **ret)
1488 HTMLStyleSheet *style_sheet;
1489 nsresult nsres;
1491 if(!(style_sheet = malloc(sizeof(HTMLStyleSheet))))
1492 return E_OUTOFMEMORY;
1494 style_sheet->IHTMLStyleSheet_iface.lpVtbl = &HTMLStyleSheetVtbl;
1495 style_sheet->IHTMLStyleSheet4_iface.lpVtbl = &HTMLStyleSheet4Vtbl;
1496 style_sheet->nsstylesheet = NULL;
1498 init_dispatch(&style_sheet->dispex, &HTMLStyleSheet_dispex, compat_mode);
1500 if(nsstylesheet) {
1501 nsres = nsIDOMStyleSheet_QueryInterface(nsstylesheet, &IID_nsIDOMCSSStyleSheet,
1502 (void**)&style_sheet->nsstylesheet);
1503 if(NS_FAILED(nsres))
1504 ERR("Could not get nsICSSStyleSheet interface: %08lx\n", nsres);
1507 *ret = &style_sheet->IHTMLStyleSheet_iface;
1508 return S_OK;