winex11: Create a global vulkan instance for xrandr.
[wine.git] / dlls / mshtml / htmlstylesheet.c
blob1c8b52ddfba27f52ce6682b4222a41b66729de8f
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 DISPEX_IDISPATCH_IMPL(HTMLStyleSheetRule, IHTMLStyleSheetRule,
78 impl_from_IHTMLStyleSheetRule(iface)->dispex)
80 static HRESULT WINAPI HTMLStyleSheetRule_put_selectorText(IHTMLStyleSheetRule *iface, BSTR v)
82 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
83 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
84 return E_NOTIMPL;
87 static HRESULT WINAPI HTMLStyleSheetRule_get_selectorText(IHTMLStyleSheetRule *iface, BSTR *p)
89 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
90 FIXME("(%p)->(%p)\n", This, p);
91 return E_NOTIMPL;
94 static HRESULT WINAPI HTMLStyleSheetRule_get_style(IHTMLStyleSheetRule *iface, IHTMLRuleStyle **p)
96 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
97 FIXME("(%p)->(%p)\n", This, p);
98 return E_NOTIMPL;
101 static HRESULT WINAPI HTMLStyleSheetRule_get_readOnly(IHTMLStyleSheetRule *iface, VARIANT_BOOL *p)
103 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
104 FIXME("(%p)->(%p)\n", This, p);
105 return E_NOTIMPL;
108 static const IHTMLStyleSheetRuleVtbl HTMLStyleSheetRuleVtbl = {
109 HTMLStyleSheetRule_QueryInterface,
110 HTMLStyleSheetRule_AddRef,
111 HTMLStyleSheetRule_Release,
112 HTMLStyleSheetRule_GetTypeInfoCount,
113 HTMLStyleSheetRule_GetTypeInfo,
114 HTMLStyleSheetRule_GetIDsOfNames,
115 HTMLStyleSheetRule_Invoke,
116 HTMLStyleSheetRule_put_selectorText,
117 HTMLStyleSheetRule_get_selectorText,
118 HTMLStyleSheetRule_get_style,
119 HTMLStyleSheetRule_get_readOnly
122 static inline HTMLStyleSheetRule *HTMLStyleSheetRule_from_DispatchEx(DispatchEx *iface)
124 return CONTAINING_RECORD(iface, HTMLStyleSheetRule, dispex);
127 static void *HTMLStyleSheetRule_query_interface(DispatchEx *dispex, REFIID riid)
129 HTMLStyleSheetRule *This = HTMLStyleSheetRule_from_DispatchEx(dispex);
131 if(IsEqualGUID(&IID_IHTMLStyleSheetRule, riid))
132 return &This->IHTMLStyleSheetRule_iface;
134 return NULL;
137 static void HTMLStyleSheetRule_traverse(DispatchEx *dispex, nsCycleCollectionTraversalCallback *cb)
139 HTMLStyleSheetRule *This = HTMLStyleSheetRule_from_DispatchEx(dispex);
140 if(This->nsstylesheetrule)
141 note_cc_edge((nsISupports*)This->nsstylesheetrule, "nsstylesheetrule", cb);
144 static void HTMLStyleSheetRule_unlink(DispatchEx *dispex)
146 HTMLStyleSheetRule *This = HTMLStyleSheetRule_from_DispatchEx(dispex);
147 unlink_ref(&This->nsstylesheetrule);
150 static void HTMLStyleSheetRule_destructor(DispatchEx *dispex)
152 HTMLStyleSheetRule *This = HTMLStyleSheetRule_from_DispatchEx(dispex);
153 free(This);
156 static const dispex_static_data_vtbl_t HTMLStyleSheetRule_dispex_vtbl = {
157 .query_interface = HTMLStyleSheetRule_query_interface,
158 .destructor = HTMLStyleSheetRule_destructor,
159 .traverse = HTMLStyleSheetRule_traverse,
160 .unlink = HTMLStyleSheetRule_unlink
163 static const tid_t HTMLStyleSheetRule_iface_tids[] = {
164 IHTMLStyleSheetRule_tid,
167 static dispex_static_data_t HTMLStyleSheetRule_dispex = {
168 "CSSStyleRule",
169 &HTMLStyleSheetRule_dispex_vtbl,
170 DispHTMLStyleSheetRule_tid,
171 HTMLStyleSheetRule_iface_tids
174 static HRESULT create_style_sheet_rule(nsIDOMCSSRule *nsstylesheetrule, compat_mode_t compat_mode,
175 IHTMLStyleSheetRule **ret)
177 HTMLStyleSheetRule *rule;
178 nsresult nsres;
180 if(!(rule = malloc(sizeof(*rule))))
181 return E_OUTOFMEMORY;
183 rule->IHTMLStyleSheetRule_iface.lpVtbl = &HTMLStyleSheetRuleVtbl;
184 rule->nsstylesheetrule = NULL;
186 init_dispatch(&rule->dispex, &HTMLStyleSheetRule_dispex, compat_mode);
188 if (nsstylesheetrule)
190 nsres = nsIDOMCSSRule_QueryInterface(nsstylesheetrule, &IID_nsIDOMCSSRule,
191 (void **)&rule->nsstylesheetrule);
192 if (NS_FAILED(nsres))
193 ERR("Could not get nsIDOMCSSRule interface: %08lx\n", nsres);
196 *ret = &rule->IHTMLStyleSheetRule_iface;
197 return S_OK;
200 static inline HTMLStyleSheetRulesCollection *impl_from_IHTMLStyleSheetRulesCollection(IHTMLStyleSheetRulesCollection *iface)
202 return CONTAINING_RECORD(iface, HTMLStyleSheetRulesCollection, IHTMLStyleSheetRulesCollection_iface);
205 DISPEX_IDISPATCH_IMPL(HTMLStyleSheetRulesCollection, IHTMLStyleSheetRulesCollection,
206 impl_from_IHTMLStyleSheetRulesCollection(iface)->dispex)
208 static HRESULT WINAPI HTMLStyleSheetRulesCollection_get_length(IHTMLStyleSheetRulesCollection *iface,
209 LONG *p)
211 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
212 UINT32 len = 0;
214 TRACE("(%p)->(%p)\n", This, p);
216 if(This->nslist) {
217 nsresult nsres;
219 nsres = nsIDOMCSSRuleList_GetLength(This->nslist, &len);
220 if(NS_FAILED(nsres))
221 ERR("GetLength failed: %08lx\n", nsres);
224 *p = len;
225 return S_OK;
228 static HRESULT WINAPI HTMLStyleSheetRulesCollection_item(IHTMLStyleSheetRulesCollection *iface,
229 LONG index, IHTMLStyleSheetRule **p)
231 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
232 nsIDOMCSSRule *nsstylesheetrule;
233 nsresult nsres;
234 HRESULT hres;
236 TRACE("(%p)->(%ld %p)\n", This, index, p);
238 nsres = nsIDOMCSSRuleList_Item(This->nslist, index, &nsstylesheetrule);
239 if(NS_FAILED(nsres))
240 return map_nsresult(nsres);
241 if(!nsstylesheetrule)
242 return E_INVALIDARG;
244 hres = create_style_sheet_rule(nsstylesheetrule, dispex_compat_mode(&This->dispex), p);
245 nsIDOMCSSRule_Release(nsstylesheetrule);
246 return hres;
249 static const IHTMLStyleSheetRulesCollectionVtbl HTMLStyleSheetRulesCollectionVtbl = {
250 HTMLStyleSheetRulesCollection_QueryInterface,
251 HTMLStyleSheetRulesCollection_AddRef,
252 HTMLStyleSheetRulesCollection_Release,
253 HTMLStyleSheetRulesCollection_GetTypeInfoCount,
254 HTMLStyleSheetRulesCollection_GetTypeInfo,
255 HTMLStyleSheetRulesCollection_GetIDsOfNames,
256 HTMLStyleSheetRulesCollection_Invoke,
257 HTMLStyleSheetRulesCollection_get_length,
258 HTMLStyleSheetRulesCollection_item
261 static inline HTMLStyleSheetRulesCollection *HTMLStyleSheetRulesCollection_from_DispatchEx(DispatchEx *iface)
263 return CONTAINING_RECORD(iface, HTMLStyleSheetRulesCollection, dispex);
266 static void *HTMLStyleSheetRulesCollection_query_interface(DispatchEx *dispex, REFIID riid)
268 HTMLStyleSheetRulesCollection *This = HTMLStyleSheetRulesCollection_from_DispatchEx(dispex);
270 if(IsEqualGUID(&IID_IHTMLStyleSheetRulesCollection, riid))
271 return &This->IHTMLStyleSheetRulesCollection_iface;
273 return NULL;
276 static void HTMLStyleSheetRulesCollection_traverse(DispatchEx *dispex, nsCycleCollectionTraversalCallback *cb)
278 HTMLStyleSheetRulesCollection *This = HTMLStyleSheetRulesCollection_from_DispatchEx(dispex);
279 if(This->nslist)
280 note_cc_edge((nsISupports*)This->nslist, "nslist", cb);
283 static void HTMLStyleSheetRulesCollection_unlink(DispatchEx *dispex)
285 HTMLStyleSheetRulesCollection *This = HTMLStyleSheetRulesCollection_from_DispatchEx(dispex);
286 unlink_ref(&This->nslist);
289 static void HTMLStyleSheetRulesCollection_destructor(DispatchEx *dispex)
291 HTMLStyleSheetRulesCollection *This = HTMLStyleSheetRulesCollection_from_DispatchEx(dispex);
292 free(This);
295 static HRESULT HTMLStyleSheetRulesCollection_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
297 HTMLStyleSheetRulesCollection *This = HTMLStyleSheetRulesCollection_from_DispatchEx(dispex);
298 UINT32 len = 0;
299 DWORD idx = 0;
300 WCHAR *ptr;
302 for(ptr = name; *ptr && is_digit(*ptr); ptr++)
303 idx = idx*10 + (*ptr-'0');
304 if(*ptr)
305 return DISP_E_UNKNOWNNAME;
307 nsIDOMCSSRuleList_GetLength(This->nslist, &len);
308 if(idx >= len)
309 return DISP_E_UNKNOWNNAME;
311 *dispid = MSHTML_DISPID_CUSTOM_MIN + idx;
312 TRACE("ret %lx\n", *dispid);
313 return S_OK;
316 static HRESULT HTMLStyleSheetRulesCollection_get_name(DispatchEx *dispex, DISPID id, BSTR *name)
318 HTMLStyleSheetRulesCollection *This = HTMLStyleSheetRulesCollection_from_DispatchEx(dispex);
319 DWORD idx = id - MSHTML_DISPID_CUSTOM_MIN;
320 UINT32 len = 0;
321 WCHAR buf[11];
323 nsIDOMCSSRuleList_GetLength(This->nslist, &len);
324 if(idx >= len)
325 return DISP_E_MEMBERNOTFOUND;
327 len = swprintf(buf, ARRAY_SIZE(buf), L"%u", idx);
328 return (*name = SysAllocStringLen(buf, len)) ? S_OK : E_OUTOFMEMORY;
331 static HRESULT HTMLStyleSheetRulesCollection_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
332 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
334 HTMLStyleSheetRulesCollection *This = HTMLStyleSheetRulesCollection_from_DispatchEx(dispex);
336 TRACE("(%p)->(%lx %lx %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
338 switch(flags) {
339 case DISPATCH_PROPERTYGET: {
340 IHTMLStyleSheetRule *stylesheetrule;
341 nsIDOMCSSRule *nsstylesheetrule;
342 nsresult nsres;
343 HRESULT hres;
345 nsres = nsIDOMCSSRuleList_Item(This->nslist, id - MSHTML_DISPID_CUSTOM_MIN, &nsstylesheetrule);
346 if(NS_FAILED(nsres))
347 return DISP_E_MEMBERNOTFOUND;
348 if(!nsstylesheetrule) {
349 V_VT(res) = VT_EMPTY;
350 return S_OK;
353 hres = create_style_sheet_rule(nsstylesheetrule, dispex_compat_mode(&This->dispex), &stylesheetrule);
354 nsIDOMCSSRule_Release(nsstylesheetrule);
355 if(FAILED(hres))
356 return hres;
358 V_VT(res) = VT_DISPATCH;
359 V_DISPATCH(res) = (IDispatch*)stylesheetrule;
360 break;
363 default:
364 FIXME("unimplemented flags %x\n", flags);
365 return E_NOTIMPL;
368 return S_OK;
371 static const dispex_static_data_vtbl_t HTMLStyleSheetRulesCollection_dispex_vtbl = {
372 .query_interface = HTMLStyleSheetRulesCollection_query_interface,
373 .destructor = HTMLStyleSheetRulesCollection_destructor,
374 .traverse = HTMLStyleSheetRulesCollection_traverse,
375 .unlink = HTMLStyleSheetRulesCollection_unlink,
376 .get_dispid = HTMLStyleSheetRulesCollection_get_dispid,
377 .get_name = HTMLStyleSheetRulesCollection_get_name,
378 .invoke = HTMLStyleSheetRulesCollection_invoke
380 static const tid_t HTMLStyleSheetRulesCollection_iface_tids[] = {
381 IHTMLStyleSheetRulesCollection_tid,
384 static dispex_static_data_t HTMLStyleSheetRulesCollection_dispex = {
385 "MSCSSRuleList",
386 &HTMLStyleSheetRulesCollection_dispex_vtbl,
387 DispHTMLStyleSheetRulesCollection_tid,
388 HTMLStyleSheetRulesCollection_iface_tids
391 static HRESULT create_style_sheet_rules_collection(nsIDOMCSSRuleList *nslist, compat_mode_t compat_mode,
392 IHTMLStyleSheetRulesCollection **ret)
394 HTMLStyleSheetRulesCollection *collection;
396 if(!(collection = malloc(sizeof(*collection))))
397 return E_OUTOFMEMORY;
399 collection->IHTMLStyleSheetRulesCollection_iface.lpVtbl = &HTMLStyleSheetRulesCollectionVtbl;
400 collection->nslist = nslist;
402 init_dispatch(&collection->dispex, &HTMLStyleSheetRulesCollection_dispex, compat_mode);
404 if(nslist)
405 nsIDOMCSSRuleList_AddRef(nslist);
407 *ret = &collection->IHTMLStyleSheetRulesCollection_iface;
408 return S_OK;
411 static inline HTMLStyleSheetsCollectionEnum *HTMLStyleSheetsCollectionEnum_from_IEnumVARIANT(IEnumVARIANT *iface)
413 return CONTAINING_RECORD(iface, HTMLStyleSheetsCollectionEnum, IEnumVARIANT_iface);
416 static HRESULT WINAPI HTMLStyleSheetsCollectionEnum_QueryInterface(IEnumVARIANT *iface, REFIID riid, void **ppv)
418 HTMLStyleSheetsCollectionEnum *This = HTMLStyleSheetsCollectionEnum_from_IEnumVARIANT(iface);
420 TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
422 if(IsEqualGUID(riid, &IID_IUnknown)) {
423 *ppv = &This->IEnumVARIANT_iface;
424 }else if(IsEqualGUID(riid, &IID_IEnumVARIANT)) {
425 *ppv = &This->IEnumVARIANT_iface;
426 }else {
427 FIXME("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
428 *ppv = NULL;
429 return E_NOINTERFACE;
432 IUnknown_AddRef((IUnknown*)*ppv);
433 return S_OK;
436 static ULONG WINAPI HTMLStyleSheetsCollectionEnum_AddRef(IEnumVARIANT *iface)
438 HTMLStyleSheetsCollectionEnum *This = HTMLStyleSheetsCollectionEnum_from_IEnumVARIANT(iface);
439 LONG ref = InterlockedIncrement(&This->ref);
441 TRACE("(%p) ref=%ld\n", This, ref);
443 return ref;
446 static ULONG WINAPI HTMLStyleSheetsCollectionEnum_Release(IEnumVARIANT *iface)
448 HTMLStyleSheetsCollectionEnum *This = HTMLStyleSheetsCollectionEnum_from_IEnumVARIANT(iface);
449 LONG ref = InterlockedDecrement(&This->ref);
451 TRACE("(%p) ref=%ld\n", This, ref);
453 if(!ref) {
454 IHTMLStyleSheetsCollection_Release(&This->col->IHTMLStyleSheetsCollection_iface);
455 free(This);
458 return ref;
461 static HRESULT WINAPI HTMLStyleSheetsCollectionEnum_Next(IEnumVARIANT *iface, ULONG celt, VARIANT *rgVar, ULONG *pCeltFetched)
463 HTMLStyleSheetsCollectionEnum *This = HTMLStyleSheetsCollectionEnum_from_IEnumVARIANT(iface);
464 VARIANT index;
465 HRESULT hres;
466 ULONG num, i;
467 UINT32 len;
469 TRACE("(%p)->(%lu %p %p)\n", This, celt, rgVar, pCeltFetched);
471 nsIDOMStyleSheetList_GetLength(This->col->nslist, &len);
472 num = min(len - This->iter, celt);
473 V_VT(&index) = VT_I4;
475 for(i = 0; i < num; i++) {
476 V_I4(&index) = This->iter + i;
477 hres = IHTMLStyleSheetsCollection_item(&This->col->IHTMLStyleSheetsCollection_iface, &index, &rgVar[i]);
478 if(FAILED(hres)) {
479 while(i--)
480 VariantClear(&rgVar[i]);
481 return hres;
485 This->iter += num;
486 if(pCeltFetched)
487 *pCeltFetched = num;
488 return num == celt ? S_OK : S_FALSE;
491 static HRESULT WINAPI HTMLStyleSheetsCollectionEnum_Skip(IEnumVARIANT *iface, ULONG celt)
493 HTMLStyleSheetsCollectionEnum *This = HTMLStyleSheetsCollectionEnum_from_IEnumVARIANT(iface);
494 UINT32 len;
496 TRACE("(%p)->(%lu)\n", This, celt);
498 nsIDOMStyleSheetList_GetLength(This->col->nslist, &len);
499 if(This->iter + celt > len) {
500 This->iter = len;
501 return S_FALSE;
504 This->iter += celt;
505 return S_OK;
508 static HRESULT WINAPI HTMLStyleSheetsCollectionEnum_Reset(IEnumVARIANT *iface)
510 HTMLStyleSheetsCollectionEnum *This = HTMLStyleSheetsCollectionEnum_from_IEnumVARIANT(iface);
512 TRACE("(%p)->()\n", This);
514 This->iter = 0;
515 return S_OK;
518 static HRESULT WINAPI HTMLStyleSheetsCollectionEnum_Clone(IEnumVARIANT *iface, IEnumVARIANT **ppEnum)
520 HTMLStyleSheetsCollectionEnum *This = HTMLStyleSheetsCollectionEnum_from_IEnumVARIANT(iface);
521 FIXME("(%p)->(%p)\n", This, ppEnum);
522 return E_NOTIMPL;
525 static const IEnumVARIANTVtbl HTMLStyleSheetsCollectionEnumVtbl = {
526 HTMLStyleSheetsCollectionEnum_QueryInterface,
527 HTMLStyleSheetsCollectionEnum_AddRef,
528 HTMLStyleSheetsCollectionEnum_Release,
529 HTMLStyleSheetsCollectionEnum_Next,
530 HTMLStyleSheetsCollectionEnum_Skip,
531 HTMLStyleSheetsCollectionEnum_Reset,
532 HTMLStyleSheetsCollectionEnum_Clone
535 static inline HTMLStyleSheetsCollection *impl_from_IHTMLStyleSheetsCollection(IHTMLStyleSheetsCollection *iface)
537 return CONTAINING_RECORD(iface, HTMLStyleSheetsCollection, IHTMLStyleSheetsCollection_iface);
540 DISPEX_IDISPATCH_IMPL(HTMLStyleSheetsCollection, IHTMLStyleSheetsCollection,
541 impl_from_IHTMLStyleSheetsCollection(iface)->dispex)
543 static HRESULT WINAPI HTMLStyleSheetsCollection_get_length(IHTMLStyleSheetsCollection *iface,
544 LONG *p)
546 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
547 UINT32 len = 0;
549 TRACE("(%p)->(%p)\n", This, p);
551 if(This->nslist)
552 nsIDOMStyleSheetList_GetLength(This->nslist, &len);
554 *p = len;
555 return S_OK;
558 static HRESULT WINAPI HTMLStyleSheetsCollection_get__newEnum(IHTMLStyleSheetsCollection *iface,
559 IUnknown **p)
561 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
562 HTMLStyleSheetsCollectionEnum *ret;
564 TRACE("(%p)->(%p)\n", This, p);
566 ret = malloc(sizeof(*ret));
567 if(!ret)
568 return E_OUTOFMEMORY;
570 ret->IEnumVARIANT_iface.lpVtbl = &HTMLStyleSheetsCollectionEnumVtbl;
571 ret->ref = 1;
572 ret->iter = 0;
574 HTMLStyleSheetsCollection_AddRef(&This->IHTMLStyleSheetsCollection_iface);
575 ret->col = This;
577 *p = (IUnknown*)&ret->IEnumVARIANT_iface;
578 return S_OK;
581 static HRESULT WINAPI HTMLStyleSheetsCollection_item(IHTMLStyleSheetsCollection *iface,
582 VARIANT *pvarIndex, VARIANT *pvarResult)
584 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
586 TRACE("(%p)->(%s %p)\n", This, debugstr_variant(pvarIndex), pvarResult);
588 switch(V_VT(pvarIndex)) {
589 case VT_I4: {
590 nsIDOMStyleSheet *nsstylesheet;
591 IHTMLStyleSheet *stylesheet;
592 nsresult nsres;
593 HRESULT hres;
595 TRACE("index=%ld\n", V_I4(pvarIndex));
597 nsres = nsIDOMStyleSheetList_Item(This->nslist, V_I4(pvarIndex), &nsstylesheet);
598 if(NS_FAILED(nsres) || !nsstylesheet) {
599 WARN("Item failed: %08lx\n", nsres);
600 V_VT(pvarResult) = VT_EMPTY;
601 return E_INVALIDARG;
604 hres = create_style_sheet(nsstylesheet, dispex_compat_mode(&This->dispex), &stylesheet);
605 nsIDOMStyleSheet_Release(nsstylesheet);
606 if(FAILED(hres))
607 return hres;
609 V_VT(pvarResult) = VT_DISPATCH;
610 V_DISPATCH(pvarResult) = (IDispatch*)stylesheet;
611 return S_OK;
614 case VT_BSTR:
615 FIXME("id=%s not implemented\n", debugstr_w(V_BSTR(pvarResult)));
616 return E_NOTIMPL;
618 default:
619 WARN("Invalid index %s\n", debugstr_variant(pvarIndex));
622 return E_INVALIDARG;
625 static const IHTMLStyleSheetsCollectionVtbl HTMLStyleSheetsCollectionVtbl = {
626 HTMLStyleSheetsCollection_QueryInterface,
627 HTMLStyleSheetsCollection_AddRef,
628 HTMLStyleSheetsCollection_Release,
629 HTMLStyleSheetsCollection_GetTypeInfoCount,
630 HTMLStyleSheetsCollection_GetTypeInfo,
631 HTMLStyleSheetsCollection_GetIDsOfNames,
632 HTMLStyleSheetsCollection_Invoke,
633 HTMLStyleSheetsCollection_get_length,
634 HTMLStyleSheetsCollection_get__newEnum,
635 HTMLStyleSheetsCollection_item
638 static inline HTMLStyleSheetsCollection *HTMLStyleSheetsCollection_from_DispatchEx(DispatchEx *iface)
640 return CONTAINING_RECORD(iface, HTMLStyleSheetsCollection, dispex);
643 static void *HTMLStyleSheetsCollection_query_interface(DispatchEx *dispex, REFIID riid)
645 HTMLStyleSheetsCollection *This = HTMLStyleSheetsCollection_from_DispatchEx(dispex);
647 if(IsEqualGUID(&IID_IHTMLStyleSheetsCollection, riid))
648 return &This->IHTMLStyleSheetsCollection_iface;
650 return NULL;
653 static void HTMLStyleSheetsCollection_traverse(DispatchEx *dispex, nsCycleCollectionTraversalCallback *cb)
655 HTMLStyleSheetsCollection *This = HTMLStyleSheetsCollection_from_DispatchEx(dispex);
656 if(This->nslist)
657 note_cc_edge((nsISupports*)This->nslist, "nslist", cb);
660 static void HTMLStyleSheetsCollection_unlink(DispatchEx *dispex)
662 HTMLStyleSheetsCollection *This = HTMLStyleSheetsCollection_from_DispatchEx(dispex);
663 unlink_ref(&This->nslist);
666 static void HTMLStyleSheetsCollection_destructor(DispatchEx *dispex)
668 HTMLStyleSheetsCollection *This = HTMLStyleSheetsCollection_from_DispatchEx(dispex);
669 free(This);
672 static HRESULT HTMLStyleSheetsCollection_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
674 HTMLStyleSheetsCollection *This = HTMLStyleSheetsCollection_from_DispatchEx(dispex);
675 UINT32 len = 0;
676 DWORD idx = 0;
677 WCHAR *ptr;
679 for(ptr = name; *ptr && is_digit(*ptr); ptr++)
680 idx = idx*10 + (*ptr-'0');
681 if(*ptr)
682 return DISP_E_UNKNOWNNAME;
684 nsIDOMStyleSheetList_GetLength(This->nslist, &len);
685 if(idx >= len)
686 return DISP_E_UNKNOWNNAME;
688 *dispid = MSHTML_DISPID_CUSTOM_MIN + idx;
689 TRACE("ret %lx\n", *dispid);
690 return S_OK;
693 static HRESULT HTMLStyleSheetsCollection_get_name(DispatchEx *dispex, DISPID id, BSTR *name)
695 HTMLStyleSheetsCollection *This = HTMLStyleSheetsCollection_from_DispatchEx(dispex);
696 DWORD idx = id - MSHTML_DISPID_CUSTOM_MIN;
697 UINT32 len = 0;
698 WCHAR buf[11];
700 nsIDOMStyleSheetList_GetLength(This->nslist, &len);
701 if(idx >= len)
702 return DISP_E_MEMBERNOTFOUND;
704 len = swprintf(buf, ARRAY_SIZE(buf), L"%u", idx);
705 return (*name = SysAllocStringLen(buf, len)) ? S_OK : E_OUTOFMEMORY;
708 static HRESULT HTMLStyleSheetsCollection_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
709 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
711 HTMLStyleSheetsCollection *This = HTMLStyleSheetsCollection_from_DispatchEx(dispex);
713 TRACE("(%p)->(%lx %lx %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
715 switch(flags) {
716 case DISPATCH_PROPERTYGET: {
717 nsIDOMStyleSheet *nsstylesheet;
718 IHTMLStyleSheet *stylesheet;
719 nsresult nsres;
720 HRESULT hres;
722 nsres = nsIDOMStyleSheetList_Item(This->nslist, id - MSHTML_DISPID_CUSTOM_MIN, &nsstylesheet);
723 if(NS_FAILED(nsres))
724 return DISP_E_MEMBERNOTFOUND;
725 if(!nsstylesheet) {
726 V_VT(res) = VT_EMPTY;
727 return S_OK;
730 hres = create_style_sheet(nsstylesheet, dispex_compat_mode(&This->dispex), &stylesheet);
731 nsIDOMStyleSheet_Release(nsstylesheet);
732 if(FAILED(hres))
733 return hres;
735 V_VT(res) = VT_DISPATCH;
736 V_DISPATCH(res) = (IDispatch*)stylesheet;
737 break;
740 default:
741 FIXME("unimplemented flags %x\n", flags);
742 return E_NOTIMPL;
745 return S_OK;
748 static const dispex_static_data_vtbl_t HTMLStyleSheetsCollection_dispex_vtbl = {
749 .query_interface = HTMLStyleSheetsCollection_query_interface,
750 .destructor = HTMLStyleSheetsCollection_destructor,
751 .traverse = HTMLStyleSheetsCollection_traverse,
752 .unlink = HTMLStyleSheetsCollection_unlink,
753 .get_dispid = HTMLStyleSheetsCollection_get_dispid,
754 .get_name = HTMLStyleSheetsCollection_get_name,
755 .invoke = HTMLStyleSheetsCollection_invoke
757 static const tid_t HTMLStyleSheetsCollection_iface_tids[] = {
758 IHTMLStyleSheetsCollection_tid,
761 static dispex_static_data_t HTMLStyleSheetsCollection_dispex = {
762 "StyleSheetList",
763 &HTMLStyleSheetsCollection_dispex_vtbl,
764 DispHTMLStyleSheetsCollection_tid,
765 HTMLStyleSheetsCollection_iface_tids
768 HRESULT create_style_sheet_collection(nsIDOMStyleSheetList *nslist, compat_mode_t compat_mode,
769 IHTMLStyleSheetsCollection **ret)
771 HTMLStyleSheetsCollection *collection;
773 if(!(collection = malloc(sizeof(HTMLStyleSheetsCollection))))
774 return E_OUTOFMEMORY;
776 collection->IHTMLStyleSheetsCollection_iface.lpVtbl = &HTMLStyleSheetsCollectionVtbl;
778 if(nslist)
779 nsIDOMStyleSheetList_AddRef(nslist);
780 collection->nslist = nslist;
782 init_dispatch(&collection->dispex, &HTMLStyleSheetsCollection_dispex, compat_mode);
784 *ret = &collection->IHTMLStyleSheetsCollection_iface;
785 return S_OK;
788 static inline HTMLStyleSheet *impl_from_IHTMLStyleSheet(IHTMLStyleSheet *iface)
790 return CONTAINING_RECORD(iface, HTMLStyleSheet, IHTMLStyleSheet_iface);
793 DISPEX_IDISPATCH_IMPL(HTMLStyleSheet, IHTMLStyleSheet, impl_from_IHTMLStyleSheet(iface)->dispex)
795 static HRESULT WINAPI HTMLStyleSheet_put_title(IHTMLStyleSheet *iface, BSTR v)
797 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
798 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
799 return E_NOTIMPL;
802 static HRESULT WINAPI HTMLStyleSheet_get_title(IHTMLStyleSheet *iface, BSTR *p)
804 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
805 FIXME("(%p)->(%p)\n", This, p);
806 return E_NOTIMPL;
809 static HRESULT WINAPI HTMLStyleSheet_get_parentStyleSheet(IHTMLStyleSheet *iface,
810 IHTMLStyleSheet **p)
812 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
813 FIXME("(%p)->(%p)\n", This, p);
814 return E_NOTIMPL;
817 static HRESULT WINAPI HTMLStyleSheet_get_owningElement(IHTMLStyleSheet *iface, IHTMLElement **p)
819 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
820 FIXME("(%p)->(%p)\n", This, p);
821 return E_NOTIMPL;
824 static HRESULT WINAPI HTMLStyleSheet_put_disabled(IHTMLStyleSheet *iface, VARIANT_BOOL v)
826 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
827 FIXME("(%p)->(%x)\n", This, v);
828 return E_NOTIMPL;
831 static HRESULT WINAPI HTMLStyleSheet_get_disabled(IHTMLStyleSheet *iface, VARIANT_BOOL *p)
833 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
834 FIXME("(%p)->(%p)\n", This, p);
835 return E_NOTIMPL;
838 static HRESULT WINAPI HTMLStyleSheet_get_readOnly(IHTMLStyleSheet *iface, VARIANT_BOOL *p)
840 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
841 FIXME("(%p)->(%p)\n", This, p);
842 return E_NOTIMPL;
845 static HRESULT WINAPI HTMLStyleSheet_get_imports(IHTMLStyleSheet *iface,
846 IHTMLStyleSheetsCollection **p)
848 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
849 FIXME("(%p)->(%p)\n", This, p);
850 return E_NOTIMPL;
853 static HRESULT WINAPI HTMLStyleSheet_put_href(IHTMLStyleSheet *iface, BSTR v)
855 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
856 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
857 return E_NOTIMPL;
860 static HRESULT WINAPI HTMLStyleSheet_get_href(IHTMLStyleSheet *iface, BSTR *p)
862 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
863 nsAString href_str;
864 nsresult nsres;
866 TRACE("(%p)->(%p)\n", This, p);
868 nsAString_Init(&href_str, NULL);
869 nsres = nsIDOMCSSStyleSheet_GetHref(This->nsstylesheet, &href_str);
870 return return_nsstr(nsres, &href_str, p);
873 static HRESULT WINAPI HTMLStyleSheet_get_type(IHTMLStyleSheet *iface, BSTR *p)
875 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
876 FIXME("(%p)->(%p)\n", This, p);
877 return E_NOTIMPL;
880 static HRESULT WINAPI HTMLStyleSheet_get_id(IHTMLStyleSheet *iface, BSTR *p)
882 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
883 FIXME("(%p)->(%p)\n", This, p);
884 return E_NOTIMPL;
887 static HRESULT WINAPI HTMLStyleSheet_addImport(IHTMLStyleSheet *iface, BSTR bstrURL,
888 LONG lIndex, LONG *plIndex)
890 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
891 FIXME("(%p)->(%s %ld %p)\n", This, debugstr_w(bstrURL), lIndex, plIndex);
892 return E_NOTIMPL;
895 static HRESULT WINAPI HTMLStyleSheet_addRule(IHTMLStyleSheet *iface, BSTR bstrSelector,
896 BSTR bstrStyle, LONG lIndex, LONG *plIndex)
898 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
899 const WCHAR format[] = L"%s {%s}";
900 nsIDOMCSSRuleList *nslist = NULL;
901 UINT32 length, new_index;
902 nsAString nsstr;
903 nsresult nsres;
904 WCHAR *rule;
905 size_t len;
907 TRACE("(%p)->(%s %s %ld %p)\n", This, debugstr_w(bstrSelector), debugstr_w(bstrStyle),
908 lIndex, plIndex);
910 if(!bstrSelector || !bstrStyle || !bstrSelector[0] || !bstrStyle[0])
911 return E_INVALIDARG;
913 nsres = nsIDOMCSSStyleSheet_GetCssRules(This->nsstylesheet, &nslist);
914 if(NS_FAILED(nsres))
915 return E_FAIL;
916 nsIDOMCSSRuleList_GetLength(nslist, &length);
918 if(lIndex > length)
919 lIndex = length;
921 len = ARRAY_SIZE(format) - 4 /* %s twice */ + wcslen(bstrSelector) + wcslen(bstrStyle);
922 if(!(rule = malloc(len * sizeof(WCHAR))))
923 return E_OUTOFMEMORY;
924 swprintf(rule, len, format, bstrSelector, bstrStyle);
926 nsAString_InitDepend(&nsstr, rule);
927 nsres = nsIDOMCSSStyleSheet_InsertRule(This->nsstylesheet, &nsstr, lIndex, &new_index);
928 if(NS_FAILED(nsres)) WARN("failed: %08lx\n", nsres);
929 nsAString_Finish(&nsstr);
930 free(rule);
932 *plIndex = new_index;
933 return map_nsresult(nsres);
936 static HRESULT WINAPI HTMLStyleSheet_removeImport(IHTMLStyleSheet *iface, LONG lIndex)
938 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
939 FIXME("(%p)->(%ld)\n", This, lIndex);
940 return E_NOTIMPL;
943 static HRESULT WINAPI HTMLStyleSheet_removeRule(IHTMLStyleSheet *iface, LONG lIndex)
945 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
946 FIXME("(%p)->(%ld)\n", This, lIndex);
947 return E_NOTIMPL;
950 static HRESULT WINAPI HTMLStyleSheet_put_media(IHTMLStyleSheet *iface, BSTR v)
952 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
953 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
954 return E_NOTIMPL;
957 static HRESULT WINAPI HTMLStyleSheet_get_media(IHTMLStyleSheet *iface, BSTR *p)
959 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
960 FIXME("(%p)->(%p)\n", This, p);
961 return E_NOTIMPL;
964 static HRESULT WINAPI HTMLStyleSheet_put_cssText(IHTMLStyleSheet *iface, BSTR v)
966 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
967 nsresult nsres;
969 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
971 do {
972 nsres = nsIDOMCSSStyleSheet_DeleteRule(This->nsstylesheet, 0);
973 }while(NS_SUCCEEDED(nsres));
975 if(v && *v) {
976 nsAString nsstr;
977 UINT32 idx;
979 /* FIXME: This won't work for multiple rules in the string. */
980 nsAString_InitDepend(&nsstr, v);
981 nsres = nsIDOMCSSStyleSheet_InsertRule(This->nsstylesheet, &nsstr, 0, &idx);
982 nsAString_Finish(&nsstr);
983 if(NS_FAILED(nsres)) {
984 FIXME("InsertRule failed for string %s. Probably multiple rules passed.\n", debugstr_w(v));
985 return E_FAIL;
989 return S_OK;
992 static HRESULT WINAPI HTMLStyleSheet_get_cssText(IHTMLStyleSheet *iface, BSTR *p)
994 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
995 nsIDOMCSSRuleList *nslist = NULL;
996 nsIDOMCSSRule *nsrule;
997 nsAString nsstr;
998 UINT32 len;
999 nsresult nsres;
1001 TRACE("(%p)->(%p)\n", This, p);
1003 nsres = nsIDOMCSSStyleSheet_GetCssRules(This->nsstylesheet, &nslist);
1004 if(NS_FAILED(nsres)) {
1005 ERR("GetCssRules failed: %08lx\n", nsres);
1006 return E_FAIL;
1009 nsres = nsIDOMCSSRuleList_GetLength(nslist, &len);
1010 assert(nsres == NS_OK);
1012 if(len) {
1013 nsres = nsIDOMCSSRuleList_Item(nslist, 0, &nsrule);
1014 if(NS_FAILED(nsres))
1015 ERR("Item failed: %08lx\n", nsres);
1018 nsIDOMCSSRuleList_Release(nslist);
1019 if(NS_FAILED(nsres))
1020 return E_FAIL;
1022 if(!len) {
1023 *p = NULL;
1024 return S_OK;
1027 nsAString_Init(&nsstr, NULL);
1028 nsres = nsIDOMCSSRule_GetCssText(nsrule, &nsstr);
1029 nsIDOMCSSRule_Release(nsrule);
1030 return return_nsstr(nsres, &nsstr, p);
1033 static HRESULT WINAPI HTMLStyleSheet_get_rules(IHTMLStyleSheet *iface,
1034 IHTMLStyleSheetRulesCollection **p)
1036 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1037 nsIDOMCSSRuleList *nslist = NULL;
1038 nsresult nsres;
1039 HRESULT hres;
1041 TRACE("(%p)->(%p)\n", This, p);
1043 nsres = nsIDOMCSSStyleSheet_GetCssRules(This->nsstylesheet, &nslist);
1044 if(NS_FAILED(nsres)) {
1045 ERR("GetCssRules failed: %08lx\n", nsres);
1046 return E_FAIL;
1049 hres = create_style_sheet_rules_collection(nslist, dispex_compat_mode(&This->dispex), p);
1050 nsIDOMCSSRuleList_Release(nslist);
1051 return hres;
1054 static const IHTMLStyleSheetVtbl HTMLStyleSheetVtbl = {
1055 HTMLStyleSheet_QueryInterface,
1056 HTMLStyleSheet_AddRef,
1057 HTMLStyleSheet_Release,
1058 HTMLStyleSheet_GetTypeInfoCount,
1059 HTMLStyleSheet_GetTypeInfo,
1060 HTMLStyleSheet_GetIDsOfNames,
1061 HTMLStyleSheet_Invoke,
1062 HTMLStyleSheet_put_title,
1063 HTMLStyleSheet_get_title,
1064 HTMLStyleSheet_get_parentStyleSheet,
1065 HTMLStyleSheet_get_owningElement,
1066 HTMLStyleSheet_put_disabled,
1067 HTMLStyleSheet_get_disabled,
1068 HTMLStyleSheet_get_readOnly,
1069 HTMLStyleSheet_get_imports,
1070 HTMLStyleSheet_put_href,
1071 HTMLStyleSheet_get_href,
1072 HTMLStyleSheet_get_type,
1073 HTMLStyleSheet_get_id,
1074 HTMLStyleSheet_addImport,
1075 HTMLStyleSheet_addRule,
1076 HTMLStyleSheet_removeImport,
1077 HTMLStyleSheet_removeRule,
1078 HTMLStyleSheet_put_media,
1079 HTMLStyleSheet_get_media,
1080 HTMLStyleSheet_put_cssText,
1081 HTMLStyleSheet_get_cssText,
1082 HTMLStyleSheet_get_rules
1085 static inline HTMLStyleSheet *impl_from_IHTMLStyleSheet4(IHTMLStyleSheet4 *iface)
1087 return CONTAINING_RECORD(iface, HTMLStyleSheet, IHTMLStyleSheet4_iface);
1090 DISPEX_IDISPATCH_IMPL(HTMLStyleSheet4, IHTMLStyleSheet4, impl_from_IHTMLStyleSheet4(iface)->dispex)
1092 static HRESULT WINAPI HTMLStyleSheet4_get_type(IHTMLStyleSheet4 *iface, BSTR *p)
1094 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1095 TRACE("(%p)->(%p)\n", This, p);
1096 return IHTMLStyleSheet_get_type(&This->IHTMLStyleSheet_iface, p);
1099 static HRESULT WINAPI HTMLStyleSheet4_get_href(IHTMLStyleSheet4 *iface, VARIANT *p)
1101 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1102 nsAString href_str;
1103 nsresult nsres;
1105 TRACE("(%p)->(%p)\n", This, p);
1107 nsAString_Init(&href_str, NULL);
1108 nsres = nsIDOMCSSStyleSheet_GetHref(This->nsstylesheet, &href_str);
1109 return return_nsstr_variant(nsres, &href_str, 0, p);
1112 static HRESULT WINAPI HTMLStyleSheet4_get_title(IHTMLStyleSheet4 *iface, BSTR *p)
1114 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1115 FIXME("(%p)->(%p)\n", This, p);
1116 return E_NOTIMPL;
1119 static HRESULT WINAPI HTMLStyleSheet4_get_ownerNode(IHTMLStyleSheet4 *iface, IHTMLElement **p)
1121 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1122 FIXME("(%p)->(%p)\n", This, p);
1123 return E_NOTIMPL;
1126 static HRESULT WINAPI HTMLStyleSheet4_get_ownerRule(IHTMLStyleSheet4 *iface, IHTMLCSSRule **p)
1128 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1129 FIXME("(%p)->(%p)\n", This, p);
1130 return E_NOTIMPL;
1133 static HRESULT WINAPI HTMLStyleSheet4_get_cssRules(IHTMLStyleSheet4 *iface, IHTMLStyleSheetRulesCollection **p)
1135 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1136 TRACE("(%p)->(%p)\n", This, p);
1137 return IHTMLStyleSheet_get_rules(&This->IHTMLStyleSheet_iface, p);
1140 static HRESULT WINAPI HTMLStyleSheet4_get_media(IHTMLStyleSheet4 *iface, VARIANT *p)
1142 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1143 FIXME("(%p)->(%p)\n", This, p);
1144 return E_NOTIMPL;
1147 static HRESULT WINAPI HTMLStyleSheet4_insertRule(IHTMLStyleSheet4 *iface, BSTR rule, LONG index, LONG *p)
1149 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1150 UINT32 new_index = 0;
1151 nsAString nsstr;
1152 nsresult nsres;
1154 TRACE("(%p)->(%s %ld %p)\n", This, debugstr_w(rule), index, p);
1156 nsAString_InitDepend(&nsstr, rule);
1157 nsres = nsIDOMCSSStyleSheet_InsertRule(This->nsstylesheet, &nsstr, index, &new_index);
1158 if(NS_FAILED(nsres)) WARN("failed: %08lx\n", nsres);
1159 nsAString_Finish(&nsstr);
1160 *p = new_index;
1161 return map_nsresult(nsres);
1164 static HRESULT WINAPI HTMLStyleSheet4_deleteRule(IHTMLStyleSheet4 *iface, LONG index)
1166 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1167 FIXME("(%p)->(%ld)\n", This, index);
1168 return E_NOTIMPL;
1171 static const IHTMLStyleSheet4Vtbl HTMLStyleSheet4Vtbl = {
1172 HTMLStyleSheet4_QueryInterface,
1173 HTMLStyleSheet4_AddRef,
1174 HTMLStyleSheet4_Release,
1175 HTMLStyleSheet4_GetTypeInfoCount,
1176 HTMLStyleSheet4_GetTypeInfo,
1177 HTMLStyleSheet4_GetIDsOfNames,
1178 HTMLStyleSheet4_Invoke,
1179 HTMLStyleSheet4_get_type,
1180 HTMLStyleSheet4_get_href,
1181 HTMLStyleSheet4_get_title,
1182 HTMLStyleSheet4_get_ownerNode,
1183 HTMLStyleSheet4_get_ownerRule,
1184 HTMLStyleSheet4_get_cssRules,
1185 HTMLStyleSheet4_get_media,
1186 HTMLStyleSheet4_insertRule,
1187 HTMLStyleSheet4_deleteRule,
1190 static inline HTMLStyleSheet *HTMLStyleSheet_from_DispatchEx(DispatchEx *iface)
1192 return CONTAINING_RECORD(iface, HTMLStyleSheet, dispex);
1195 static void *HTMLStyleSheet_query_interface(DispatchEx *dispex, REFIID riid)
1197 HTMLStyleSheet *This = HTMLStyleSheet_from_DispatchEx(dispex);
1199 if(IsEqualGUID(&IID_IHTMLStyleSheet, riid))
1200 return &This->IHTMLStyleSheet_iface;
1201 if(IsEqualGUID(&IID_IHTMLStyleSheet4, riid))
1202 return &This->IHTMLStyleSheet4_iface;
1204 return NULL;
1207 static void HTMLStyleSheet_traverse(DispatchEx *dispex, nsCycleCollectionTraversalCallback *cb)
1209 HTMLStyleSheet *This = HTMLStyleSheet_from_DispatchEx(dispex);
1210 if(This->nsstylesheet)
1211 note_cc_edge((nsISupports*)This->nsstylesheet, "nsstylesheet", cb);
1214 static void HTMLStyleSheet_unlink(DispatchEx *dispex)
1216 HTMLStyleSheet *This = HTMLStyleSheet_from_DispatchEx(dispex);
1217 unlink_ref(&This->nsstylesheet);
1220 static void HTMLStyleSheet_destructor(DispatchEx *dispex)
1222 HTMLStyleSheet *This = HTMLStyleSheet_from_DispatchEx(dispex);
1223 free(This);
1226 static void HTMLStyleSheet_init_dispex_info(dispex_data_t *info, compat_mode_t mode)
1228 if(mode >= COMPAT_MODE_IE9)
1229 dispex_info_add_interface(info, IHTMLStyleSheet4_tid, NULL);
1232 static const dispex_static_data_vtbl_t HTMLStyleSheet_dispex_vtbl = {
1233 .query_interface = HTMLStyleSheet_query_interface,
1234 .destructor = HTMLStyleSheet_destructor,
1235 .traverse = HTMLStyleSheet_traverse,
1236 .unlink = HTMLStyleSheet_unlink
1239 static const tid_t HTMLStyleSheet_iface_tids[] = {
1240 IHTMLStyleSheet_tid,
1243 static dispex_static_data_t HTMLStyleSheet_dispex = {
1244 "CSSStyleSheet",
1245 &HTMLStyleSheet_dispex_vtbl,
1246 DispHTMLStyleSheet_tid,
1247 HTMLStyleSheet_iface_tids,
1248 HTMLStyleSheet_init_dispex_info
1251 HRESULT create_style_sheet(nsIDOMStyleSheet *nsstylesheet, compat_mode_t compat_mode, IHTMLStyleSheet **ret)
1253 HTMLStyleSheet *style_sheet;
1254 nsresult nsres;
1256 if(!(style_sheet = malloc(sizeof(HTMLStyleSheet))))
1257 return E_OUTOFMEMORY;
1259 style_sheet->IHTMLStyleSheet_iface.lpVtbl = &HTMLStyleSheetVtbl;
1260 style_sheet->IHTMLStyleSheet4_iface.lpVtbl = &HTMLStyleSheet4Vtbl;
1261 style_sheet->nsstylesheet = NULL;
1263 init_dispatch(&style_sheet->dispex, &HTMLStyleSheet_dispex, compat_mode);
1265 if(nsstylesheet) {
1266 nsres = nsIDOMStyleSheet_QueryInterface(nsstylesheet, &IID_nsIDOMCSSStyleSheet,
1267 (void**)&style_sheet->nsstylesheet);
1268 if(NS_FAILED(nsres))
1269 ERR("Could not get nsICSSStyleSheet interface: %08lx\n", nsres);
1272 *ret = &style_sheet->IHTMLStyleSheet_iface;
1273 return S_OK;