user32: Remove _wassert workaround.
[wine.git] / dlls / mshtml / htmlstylesheet.c
blob3d9b7bb8683ce774a5878e5aa5f0fe12efc4b02f
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 LONG ref;
41 nsIDOMCSSStyleSheet *nsstylesheet;
44 struct HTMLStyleSheetsCollection {
45 DispatchEx dispex;
46 IHTMLStyleSheetsCollection IHTMLStyleSheetsCollection_iface;
48 LONG ref;
50 nsIDOMStyleSheetList *nslist;
53 struct HTMLStyleSheetRulesCollection {
54 DispatchEx dispex;
55 IHTMLStyleSheetRulesCollection IHTMLStyleSheetRulesCollection_iface;
57 LONG ref;
59 nsIDOMCSSRuleList *nslist;
62 struct HTMLStyleSheetRule {
63 DispatchEx dispex;
64 IHTMLStyleSheetRule IHTMLStyleSheetRule_iface;
66 LONG ref;
68 nsIDOMCSSRule *nsstylesheetrule;
71 static inline HTMLStyleSheetRule *impl_from_IHTMLStyleSheetRule(IHTMLStyleSheetRule *iface)
73 return CONTAINING_RECORD(iface, HTMLStyleSheetRule, IHTMLStyleSheetRule_iface);
76 static HRESULT WINAPI HTMLStyleSheetRule_QueryInterface(IHTMLStyleSheetRule *iface,
77 REFIID riid, void **ppv)
79 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
81 TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
83 if (IsEqualGUID(&IID_IUnknown, riid))
84 *ppv = &This->IHTMLStyleSheetRule_iface;
85 else if (IsEqualGUID(&IID_IHTMLStyleSheetRule, riid))
86 *ppv = &This->IHTMLStyleSheetRule_iface;
87 else if (dispex_query_interface(&This->dispex, riid, ppv))
88 return *ppv ? S_OK : E_NOINTERFACE;
89 else
91 *ppv = NULL;
92 FIXME("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
93 return E_NOINTERFACE;
96 IUnknown_AddRef((IUnknown *)*ppv);
97 return S_OK;
100 static ULONG WINAPI HTMLStyleSheetRule_AddRef(IHTMLStyleSheetRule *iface)
102 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
103 LONG ref = InterlockedIncrement(&This->ref);
105 TRACE("(%p) ref=%d\n", This, ref);
107 return ref;
110 static ULONG WINAPI HTMLStyleSheetRule_Release(IHTMLStyleSheetRule *iface)
112 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
113 LONG ref = InterlockedDecrement(&This->ref);
115 TRACE("(%p) ref=%d\n", This, ref);
117 if(!ref) {
118 release_dispex(&This->dispex);
119 if(This->nsstylesheetrule)
120 nsIDOMCSSRule_Release(This->nsstylesheetrule);
121 heap_free(This);
124 return ref;
127 static HRESULT WINAPI HTMLStyleSheetRule_GetTypeInfoCount(
128 IHTMLStyleSheetRule *iface, UINT *pctinfo)
130 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
131 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
134 static HRESULT WINAPI HTMLStyleSheetRule_GetTypeInfo(IHTMLStyleSheetRule *iface,
135 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
137 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
138 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
141 static HRESULT WINAPI HTMLStyleSheetRule_GetIDsOfNames(IHTMLStyleSheetRule *iface,
142 REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
144 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
145 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
146 lcid, rgDispId);
149 static HRESULT WINAPI HTMLStyleSheetRule_Invoke(IHTMLStyleSheetRule *iface,
150 DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
151 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
153 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
154 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
155 pDispParams, pVarResult, pExcepInfo, puArgErr);
158 static HRESULT WINAPI HTMLStyleSheetRule_put_selectorText(IHTMLStyleSheetRule *iface, BSTR v)
160 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
161 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
162 return E_NOTIMPL;
165 static HRESULT WINAPI HTMLStyleSheetRule_get_selectorText(IHTMLStyleSheetRule *iface, BSTR *p)
167 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
168 FIXME("(%p)->(%p)\n", This, p);
169 return E_NOTIMPL;
172 static HRESULT WINAPI HTMLStyleSheetRule_get_style(IHTMLStyleSheetRule *iface, IHTMLRuleStyle **p)
174 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
175 FIXME("(%p)->(%p)\n", This, p);
176 return E_NOTIMPL;
179 static HRESULT WINAPI HTMLStyleSheetRule_get_readOnly(IHTMLStyleSheetRule *iface, VARIANT_BOOL *p)
181 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
182 FIXME("(%p)->(%p)\n", This, p);
183 return E_NOTIMPL;
186 static const IHTMLStyleSheetRuleVtbl HTMLStyleSheetRuleVtbl = {
187 HTMLStyleSheetRule_QueryInterface,
188 HTMLStyleSheetRule_AddRef,
189 HTMLStyleSheetRule_Release,
190 HTMLStyleSheetRule_GetTypeInfoCount,
191 HTMLStyleSheetRule_GetTypeInfo,
192 HTMLStyleSheetRule_GetIDsOfNames,
193 HTMLStyleSheetRule_Invoke,
194 HTMLStyleSheetRule_put_selectorText,
195 HTMLStyleSheetRule_get_selectorText,
196 HTMLStyleSheetRule_get_style,
197 HTMLStyleSheetRule_get_readOnly
200 static const tid_t HTMLStyleSheetRule_iface_tids[] = {
201 IHTMLStyleSheetRule_tid,
204 static dispex_static_data_t HTMLStyleSheetRule_dispex = {
205 L"CSSStyleRule",
206 NULL,
207 DispHTMLStyleSheetRule_tid,
208 HTMLStyleSheetRule_iface_tids
211 static HRESULT create_style_sheet_rule(nsIDOMCSSRule *nsstylesheetrule, compat_mode_t compat_mode,
212 IHTMLStyleSheetRule **ret)
214 HTMLStyleSheetRule *rule;
215 nsresult nsres;
217 if(!(rule = heap_alloc(sizeof(*rule))))
218 return E_OUTOFMEMORY;
220 rule->IHTMLStyleSheetRule_iface.lpVtbl = &HTMLStyleSheetRuleVtbl;
221 rule->ref = 1;
222 rule->nsstylesheetrule = NULL;
224 init_dispatch(&rule->dispex, (IUnknown *)&rule->IHTMLStyleSheetRule_iface, &HTMLStyleSheetRule_dispex,
225 compat_mode);
227 if (nsstylesheetrule)
229 nsres = nsIDOMCSSRule_QueryInterface(nsstylesheetrule, &IID_nsIDOMCSSRule,
230 (void **)&rule->nsstylesheetrule);
231 if (NS_FAILED(nsres))
232 ERR("Could not get nsIDOMCSSRule interface: %08x\n", nsres);
235 *ret = &rule->IHTMLStyleSheetRule_iface;
236 return S_OK;
239 static inline HTMLStyleSheetRulesCollection *impl_from_IHTMLStyleSheetRulesCollection(IHTMLStyleSheetRulesCollection *iface)
241 return CONTAINING_RECORD(iface, HTMLStyleSheetRulesCollection, IHTMLStyleSheetRulesCollection_iface);
244 static HRESULT WINAPI HTMLStyleSheetRulesCollection_QueryInterface(IHTMLStyleSheetRulesCollection *iface,
245 REFIID riid, void **ppv)
247 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
249 TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
251 if(IsEqualGUID(&IID_IUnknown, riid)) {
252 *ppv = &This->IHTMLStyleSheetRulesCollection_iface;
253 }else if(IsEqualGUID(&IID_IHTMLStyleSheetRulesCollection, riid)) {
254 *ppv = &This->IHTMLStyleSheetRulesCollection_iface;
255 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
256 return *ppv ? S_OK : E_NOINTERFACE;
257 }else {
258 *ppv = NULL;
259 FIXME("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
260 return E_NOINTERFACE;
263 IUnknown_AddRef((IUnknown*)*ppv);
264 return S_OK;
267 static ULONG WINAPI HTMLStyleSheetRulesCollection_AddRef(IHTMLStyleSheetRulesCollection *iface)
269 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
270 LONG ref = InterlockedIncrement(&This->ref);
272 TRACE("(%p) ref=%d\n", This, ref);
274 return ref;
277 static ULONG WINAPI HTMLStyleSheetRulesCollection_Release(IHTMLStyleSheetRulesCollection *iface)
279 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
280 LONG ref = InterlockedDecrement(&This->ref);
282 TRACE("(%p) ref=%d\n", This, ref);
284 if(!ref) {
285 release_dispex(&This->dispex);
286 if(This->nslist)
287 nsIDOMCSSRuleList_Release(This->nslist);
288 heap_free(This);
291 return ref;
294 static HRESULT WINAPI HTMLStyleSheetRulesCollection_GetTypeInfoCount(
295 IHTMLStyleSheetRulesCollection *iface, UINT *pctinfo)
297 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
298 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
301 static HRESULT WINAPI HTMLStyleSheetRulesCollection_GetTypeInfo(IHTMLStyleSheetRulesCollection *iface,
302 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
304 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
305 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
308 static HRESULT WINAPI HTMLStyleSheetRulesCollection_GetIDsOfNames(IHTMLStyleSheetRulesCollection *iface,
309 REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
311 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
312 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
313 lcid, rgDispId);
316 static HRESULT WINAPI HTMLStyleSheetRulesCollection_Invoke(IHTMLStyleSheetRulesCollection *iface,
317 DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
318 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
320 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
321 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
322 pDispParams, pVarResult, pExcepInfo, puArgErr);
325 static HRESULT WINAPI HTMLStyleSheetRulesCollection_get_length(IHTMLStyleSheetRulesCollection *iface,
326 LONG *p)
328 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
329 UINT32 len = 0;
331 TRACE("(%p)->(%p)\n", This, p);
333 if(This->nslist) {
334 nsresult nsres;
336 nsres = nsIDOMCSSRuleList_GetLength(This->nslist, &len);
337 if(NS_FAILED(nsres))
338 ERR("GetLength failed: %08x\n", nsres);
341 *p = len;
342 return S_OK;
345 static HRESULT WINAPI HTMLStyleSheetRulesCollection_item(IHTMLStyleSheetRulesCollection *iface,
346 LONG index, IHTMLStyleSheetRule **p)
348 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
349 nsIDOMCSSRule *nsstylesheetrule;
350 nsresult nsres;
351 HRESULT hres;
353 TRACE("(%p)->(%d %p)\n", This, index, p);
355 nsres = nsIDOMCSSRuleList_Item(This->nslist, index, &nsstylesheetrule);
356 if(NS_FAILED(nsres))
357 return map_nsresult(nsres);
358 if(!nsstylesheetrule)
359 return E_INVALIDARG;
361 hres = create_style_sheet_rule(nsstylesheetrule, dispex_compat_mode(&This->dispex), p);
362 nsIDOMCSSRule_Release(nsstylesheetrule);
363 return hres;
366 static const IHTMLStyleSheetRulesCollectionVtbl HTMLStyleSheetRulesCollectionVtbl = {
367 HTMLStyleSheetRulesCollection_QueryInterface,
368 HTMLStyleSheetRulesCollection_AddRef,
369 HTMLStyleSheetRulesCollection_Release,
370 HTMLStyleSheetRulesCollection_GetTypeInfoCount,
371 HTMLStyleSheetRulesCollection_GetTypeInfo,
372 HTMLStyleSheetRulesCollection_GetIDsOfNames,
373 HTMLStyleSheetRulesCollection_Invoke,
374 HTMLStyleSheetRulesCollection_get_length,
375 HTMLStyleSheetRulesCollection_item
378 static inline HTMLStyleSheetRulesCollection *HTMLStyleSheetRulesCollection_from_DispatchEx(DispatchEx *iface)
380 return CONTAINING_RECORD(iface, HTMLStyleSheetRulesCollection, dispex);
383 static HRESULT HTMLStyleSheetRulesCollection_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
385 HTMLStyleSheetRulesCollection *This = HTMLStyleSheetRulesCollection_from_DispatchEx(dispex);
386 UINT32 len = 0;
387 DWORD idx = 0;
388 WCHAR *ptr;
390 for(ptr = name; *ptr && is_digit(*ptr); ptr++)
391 idx = idx*10 + (*ptr-'0');
392 if(*ptr)
393 return DISP_E_UNKNOWNNAME;
395 nsIDOMCSSRuleList_GetLength(This->nslist, &len);
396 if(idx >= len)
397 return DISP_E_UNKNOWNNAME;
399 *dispid = MSHTML_DISPID_CUSTOM_MIN + idx;
400 TRACE("ret %x\n", *dispid);
401 return S_OK;
404 static HRESULT HTMLStyleSheetRulesCollection_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
405 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
407 HTMLStyleSheetRulesCollection *This = HTMLStyleSheetRulesCollection_from_DispatchEx(dispex);
409 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
411 switch(flags) {
412 case DISPATCH_PROPERTYGET: {
413 IHTMLStyleSheetRule *stylesheetrule;
414 nsIDOMCSSRule *nsstylesheetrule;
415 nsresult nsres;
416 HRESULT hres;
418 nsres = nsIDOMCSSRuleList_Item(This->nslist, id - MSHTML_DISPID_CUSTOM_MIN, &nsstylesheetrule);
419 if(NS_FAILED(nsres))
420 return DISP_E_MEMBERNOTFOUND;
421 if(!nsstylesheetrule) {
422 V_VT(res) = VT_EMPTY;
423 return S_OK;
426 hres = create_style_sheet_rule(nsstylesheetrule, dispex_compat_mode(&This->dispex), &stylesheetrule);
427 nsIDOMCSSRule_Release(nsstylesheetrule);
428 if(FAILED(hres))
429 return hres;
431 V_VT(res) = VT_DISPATCH;
432 V_DISPATCH(res) = (IDispatch*)stylesheetrule;
433 break;
436 default:
437 FIXME("unimplemented flags %x\n", flags);
438 return E_NOTIMPL;
441 return S_OK;
444 static const dispex_static_data_vtbl_t HTMLStyleSheetRulesCollection_dispex_vtbl = {
445 NULL,
446 HTMLStyleSheetRulesCollection_get_dispid,
447 HTMLStyleSheetRulesCollection_invoke
449 static const tid_t HTMLStyleSheetRulesCollection_iface_tids[] = {
450 IHTMLStyleSheetRulesCollection_tid,
453 static dispex_static_data_t HTMLStyleSheetRulesCollection_dispex = {
454 L"MSCSSRuleList",
455 &HTMLStyleSheetRulesCollection_dispex_vtbl,
456 DispHTMLStyleSheetRulesCollection_tid,
457 HTMLStyleSheetRulesCollection_iface_tids
460 static HRESULT create_style_sheet_rules_collection(nsIDOMCSSRuleList *nslist, compat_mode_t compat_mode,
461 IHTMLStyleSheetRulesCollection **ret)
463 HTMLStyleSheetRulesCollection *collection;
465 if(!(collection = heap_alloc(sizeof(*collection))))
466 return E_OUTOFMEMORY;
468 collection->IHTMLStyleSheetRulesCollection_iface.lpVtbl = &HTMLStyleSheetRulesCollectionVtbl;
469 collection->ref = 1;
470 collection->nslist = nslist;
472 init_dispatch(&collection->dispex, (IUnknown*)&collection->IHTMLStyleSheetRulesCollection_iface,
473 &HTMLStyleSheetRulesCollection_dispex, compat_mode);
475 if(nslist)
476 nsIDOMCSSRuleList_AddRef(nslist);
478 *ret = &collection->IHTMLStyleSheetRulesCollection_iface;
479 return S_OK;
482 static inline HTMLStyleSheetsCollection *impl_from_IHTMLStyleSheetsCollection(IHTMLStyleSheetsCollection *iface)
484 return CONTAINING_RECORD(iface, HTMLStyleSheetsCollection, IHTMLStyleSheetsCollection_iface);
487 static HRESULT WINAPI HTMLStyleSheetsCollection_QueryInterface(IHTMLStyleSheetsCollection *iface,
488 REFIID riid, void **ppv)
490 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
492 TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
494 if(IsEqualGUID(&IID_IUnknown, riid)) {
495 *ppv = &This->IHTMLStyleSheetsCollection_iface;
496 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
497 *ppv = &This->IHTMLStyleSheetsCollection_iface;
498 }else if(IsEqualGUID(&IID_IHTMLStyleSheetsCollection, riid)) {
499 *ppv = &This->IHTMLStyleSheetsCollection_iface;
500 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
501 return *ppv ? S_OK : E_NOINTERFACE;
502 }else {
503 *ppv = NULL;
504 WARN("unsupported %s\n", debugstr_mshtml_guid(riid));
505 return E_NOINTERFACE;
508 IUnknown_AddRef((IUnknown*)*ppv);
509 return S_OK;
512 static ULONG WINAPI HTMLStyleSheetsCollection_AddRef(IHTMLStyleSheetsCollection *iface)
514 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
515 LONG ref = InterlockedIncrement(&This->ref);
517 TRACE("(%p) ref=%d\n", This, ref);
519 return ref;
522 static ULONG WINAPI HTMLStyleSheetsCollection_Release(IHTMLStyleSheetsCollection *iface)
524 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
525 LONG ref = InterlockedDecrement(&This->ref);
527 TRACE("(%p) ref=%d\n", This, ref);
529 if(!ref) {
530 release_dispex(&This->dispex);
531 if(This->nslist)
532 nsIDOMStyleSheetList_Release(This->nslist);
533 heap_free(This);
536 return ref;
539 static HRESULT WINAPI HTMLStyleSheetsCollection_GetTypeInfoCount(IHTMLStyleSheetsCollection *iface,
540 UINT *pctinfo)
542 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
543 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
546 static HRESULT WINAPI HTMLStyleSheetsCollection_GetTypeInfo(IHTMLStyleSheetsCollection *iface,
547 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
549 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
550 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
553 static HRESULT WINAPI HTMLStyleSheetsCollection_GetIDsOfNames(IHTMLStyleSheetsCollection *iface,
554 REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
556 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
557 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
558 lcid, rgDispId);
561 static HRESULT WINAPI HTMLStyleSheetsCollection_Invoke(IHTMLStyleSheetsCollection *iface,
562 DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
563 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
565 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
566 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
567 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
570 static HRESULT WINAPI HTMLStyleSheetsCollection_get_length(IHTMLStyleSheetsCollection *iface,
571 LONG *p)
573 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
574 UINT32 len = 0;
576 TRACE("(%p)->(%p)\n", This, p);
578 if(This->nslist)
579 nsIDOMStyleSheetList_GetLength(This->nslist, &len);
581 *p = len;
582 return S_OK;
585 static HRESULT WINAPI HTMLStyleSheetsCollection_get__newEnum(IHTMLStyleSheetsCollection *iface,
586 IUnknown **p)
588 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
589 FIXME("(%p)->(%p)\n", This, p);
590 return E_NOTIMPL;
593 static HRESULT WINAPI HTMLStyleSheetsCollection_item(IHTMLStyleSheetsCollection *iface,
594 VARIANT *pvarIndex, VARIANT *pvarResult)
596 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
598 TRACE("(%p)->(%s %p)\n", This, debugstr_variant(pvarIndex), pvarResult);
600 switch(V_VT(pvarIndex)) {
601 case VT_I4: {
602 nsIDOMStyleSheet *nsstylesheet;
603 IHTMLStyleSheet *stylesheet;
604 nsresult nsres;
605 HRESULT hres;
607 TRACE("index=%d\n", V_I4(pvarIndex));
609 nsres = nsIDOMStyleSheetList_Item(This->nslist, V_I4(pvarIndex), &nsstylesheet);
610 if(NS_FAILED(nsres) || !nsstylesheet) {
611 WARN("Item failed: %08x\n", nsres);
612 V_VT(pvarResult) = VT_EMPTY;
613 return E_INVALIDARG;
616 hres = create_style_sheet(nsstylesheet, dispex_compat_mode(&This->dispex), &stylesheet);
617 nsIDOMStyleSheet_Release(nsstylesheet);
618 if(FAILED(hres))
619 return hres;
621 V_VT(pvarResult) = VT_DISPATCH;
622 V_DISPATCH(pvarResult) = (IDispatch*)stylesheet;
623 return S_OK;
626 case VT_BSTR:
627 FIXME("id=%s not implemented\n", debugstr_w(V_BSTR(pvarResult)));
628 return E_NOTIMPL;
630 default:
631 WARN("Invalid index %s\n", debugstr_variant(pvarIndex));
634 return E_INVALIDARG;
637 static const IHTMLStyleSheetsCollectionVtbl HTMLStyleSheetsCollectionVtbl = {
638 HTMLStyleSheetsCollection_QueryInterface,
639 HTMLStyleSheetsCollection_AddRef,
640 HTMLStyleSheetsCollection_Release,
641 HTMLStyleSheetsCollection_GetTypeInfoCount,
642 HTMLStyleSheetsCollection_GetTypeInfo,
643 HTMLStyleSheetsCollection_GetIDsOfNames,
644 HTMLStyleSheetsCollection_Invoke,
645 HTMLStyleSheetsCollection_get_length,
646 HTMLStyleSheetsCollection_get__newEnum,
647 HTMLStyleSheetsCollection_item
650 static inline HTMLStyleSheetsCollection *HTMLStyleSheetsCollection_from_DispatchEx(DispatchEx *iface)
652 return CONTAINING_RECORD(iface, HTMLStyleSheetsCollection, dispex);
655 static HRESULT HTMLStyleSheetsCollection_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
657 HTMLStyleSheetsCollection *This = HTMLStyleSheetsCollection_from_DispatchEx(dispex);
658 UINT32 len = 0;
659 DWORD idx = 0;
660 WCHAR *ptr;
662 for(ptr = name; *ptr && is_digit(*ptr); ptr++)
663 idx = idx*10 + (*ptr-'0');
664 if(*ptr)
665 return DISP_E_UNKNOWNNAME;
667 nsIDOMStyleSheetList_GetLength(This->nslist, &len);
668 if(idx >= len)
669 return DISP_E_UNKNOWNNAME;
671 *dispid = MSHTML_DISPID_CUSTOM_MIN + idx;
672 TRACE("ret %x\n", *dispid);
673 return S_OK;
676 static HRESULT HTMLStyleSheetsCollection_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
677 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
679 HTMLStyleSheetsCollection *This = HTMLStyleSheetsCollection_from_DispatchEx(dispex);
681 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
683 switch(flags) {
684 case DISPATCH_PROPERTYGET: {
685 nsIDOMStyleSheet *nsstylesheet;
686 IHTMLStyleSheet *stylesheet;
687 nsresult nsres;
688 HRESULT hres;
690 nsres = nsIDOMStyleSheetList_Item(This->nslist, id - MSHTML_DISPID_CUSTOM_MIN, &nsstylesheet);
691 if(NS_FAILED(nsres))
692 return DISP_E_MEMBERNOTFOUND;
693 if(!nsstylesheet) {
694 V_VT(res) = VT_EMPTY;
695 return S_OK;
698 hres = create_style_sheet(nsstylesheet, dispex_compat_mode(&This->dispex), &stylesheet);
699 nsIDOMStyleSheet_Release(nsstylesheet);
700 if(FAILED(hres))
701 return hres;
703 V_VT(res) = VT_DISPATCH;
704 V_DISPATCH(res) = (IDispatch*)stylesheet;
705 break;
708 default:
709 FIXME("unimplemented flags %x\n", flags);
710 return E_NOTIMPL;
713 return S_OK;
716 static const dispex_static_data_vtbl_t HTMLStyleSheetsCollection_dispex_vtbl = {
717 NULL,
718 HTMLStyleSheetsCollection_get_dispid,
719 HTMLStyleSheetsCollection_invoke
721 static const tid_t HTMLStyleSheetsCollection_iface_tids[] = {
722 IHTMLStyleSheetsCollection_tid,
725 static dispex_static_data_t HTMLStyleSheetsCollection_dispex = {
726 L"StyleSheetList",
727 &HTMLStyleSheetsCollection_dispex_vtbl,
728 DispHTMLStyleSheetsCollection_tid,
729 HTMLStyleSheetsCollection_iface_tids
732 HRESULT create_style_sheet_collection(nsIDOMStyleSheetList *nslist, compat_mode_t compat_mode,
733 IHTMLStyleSheetsCollection **ret)
735 HTMLStyleSheetsCollection *collection;
737 if(!(collection = heap_alloc(sizeof(HTMLStyleSheetsCollection))))
738 return E_OUTOFMEMORY;
740 collection->IHTMLStyleSheetsCollection_iface.lpVtbl = &HTMLStyleSheetsCollectionVtbl;
741 collection->ref = 1;
743 if(nslist)
744 nsIDOMStyleSheetList_AddRef(nslist);
745 collection->nslist = nslist;
747 init_dispatch(&collection->dispex, (IUnknown*)&collection->IHTMLStyleSheetsCollection_iface,
748 &HTMLStyleSheetsCollection_dispex, compat_mode);
750 *ret = &collection->IHTMLStyleSheetsCollection_iface;
751 return S_OK;
754 static inline HTMLStyleSheet *impl_from_IHTMLStyleSheet(IHTMLStyleSheet *iface)
756 return CONTAINING_RECORD(iface, HTMLStyleSheet, IHTMLStyleSheet_iface);
759 static HRESULT WINAPI HTMLStyleSheet_QueryInterface(IHTMLStyleSheet *iface, REFIID riid, void **ppv)
761 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
763 TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
765 if(IsEqualGUID(&IID_IUnknown, riid)) {
766 *ppv = &This->IHTMLStyleSheet_iface;
767 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
768 *ppv = &This->IHTMLStyleSheet_iface;
769 }else if(IsEqualGUID(&IID_IHTMLStyleSheet, riid)) {
770 *ppv = &This->IHTMLStyleSheet_iface;
771 }else if(IsEqualGUID(&IID_IHTMLStyleSheet4, riid)) {
772 *ppv = &This->IHTMLStyleSheet4_iface;
773 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
774 return *ppv ? S_OK : E_NOINTERFACE;
775 }else {
776 *ppv = NULL;
777 WARN("unsupported %s\n", debugstr_mshtml_guid(riid));
778 return E_NOINTERFACE;
781 IUnknown_AddRef((IUnknown*)*ppv);
782 return S_OK;
785 static ULONG WINAPI HTMLStyleSheet_AddRef(IHTMLStyleSheet *iface)
787 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
788 LONG ref = InterlockedIncrement(&This->ref);
790 TRACE("(%p) ref=%d\n", This, ref);
792 return ref;
795 static ULONG WINAPI HTMLStyleSheet_Release(IHTMLStyleSheet *iface)
797 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
798 LONG ref = InterlockedDecrement(&This->ref);
800 TRACE("(%p) ref=%d\n", This, ref);
802 if(!ref) {
803 release_dispex(&This->dispex);
804 if(This->nsstylesheet)
805 nsIDOMCSSStyleSheet_Release(This->nsstylesheet);
806 heap_free(This);
809 return ref;
812 static HRESULT WINAPI HTMLStyleSheet_GetTypeInfoCount(IHTMLStyleSheet *iface, UINT *pctinfo)
814 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
815 TRACE("(%p)->(%p)\n", This, pctinfo);
816 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
819 static HRESULT WINAPI HTMLStyleSheet_GetTypeInfo(IHTMLStyleSheet *iface, UINT iTInfo,
820 LCID lcid, ITypeInfo **ppTInfo)
822 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
823 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
826 static HRESULT WINAPI HTMLStyleSheet_GetIDsOfNames(IHTMLStyleSheet *iface, REFIID riid,
827 LPOLESTR *rgszNames, UINT cNames,
828 LCID lcid, DISPID *rgDispId)
830 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
831 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames, lcid, rgDispId);
834 static HRESULT WINAPI HTMLStyleSheet_Invoke(IHTMLStyleSheet *iface, DISPID dispIdMember,
835 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
836 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
838 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
839 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags, pDispParams,
840 pVarResult, pExcepInfo, puArgErr);
843 static HRESULT WINAPI HTMLStyleSheet_put_title(IHTMLStyleSheet *iface, BSTR v)
845 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
846 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
847 return E_NOTIMPL;
850 static HRESULT WINAPI HTMLStyleSheet_get_title(IHTMLStyleSheet *iface, BSTR *p)
852 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
853 FIXME("(%p)->(%p)\n", This, p);
854 return E_NOTIMPL;
857 static HRESULT WINAPI HTMLStyleSheet_get_parentStyleSheet(IHTMLStyleSheet *iface,
858 IHTMLStyleSheet **p)
860 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
861 FIXME("(%p)->(%p)\n", This, p);
862 return E_NOTIMPL;
865 static HRESULT WINAPI HTMLStyleSheet_get_owningElement(IHTMLStyleSheet *iface, IHTMLElement **p)
867 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
868 FIXME("(%p)->(%p)\n", This, p);
869 return E_NOTIMPL;
872 static HRESULT WINAPI HTMLStyleSheet_put_disabled(IHTMLStyleSheet *iface, VARIANT_BOOL v)
874 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
875 FIXME("(%p)->(%x)\n", This, v);
876 return E_NOTIMPL;
879 static HRESULT WINAPI HTMLStyleSheet_get_disabled(IHTMLStyleSheet *iface, VARIANT_BOOL *p)
881 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
882 FIXME("(%p)->(%p)\n", This, p);
883 return E_NOTIMPL;
886 static HRESULT WINAPI HTMLStyleSheet_get_readOnly(IHTMLStyleSheet *iface, VARIANT_BOOL *p)
888 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
889 FIXME("(%p)->(%p)\n", This, p);
890 return E_NOTIMPL;
893 static HRESULT WINAPI HTMLStyleSheet_get_imports(IHTMLStyleSheet *iface,
894 IHTMLStyleSheetsCollection **p)
896 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
897 FIXME("(%p)->(%p)\n", This, p);
898 return E_NOTIMPL;
901 static HRESULT WINAPI HTMLStyleSheet_put_href(IHTMLStyleSheet *iface, BSTR v)
903 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
904 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
905 return E_NOTIMPL;
908 static HRESULT WINAPI HTMLStyleSheet_get_href(IHTMLStyleSheet *iface, BSTR *p)
910 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
911 nsAString href_str;
912 nsresult nsres;
914 TRACE("(%p)->(%p)\n", This, p);
916 nsAString_Init(&href_str, NULL);
917 nsres = nsIDOMCSSStyleSheet_GetHref(This->nsstylesheet, &href_str);
918 return return_nsstr(nsres, &href_str, p);
921 static HRESULT WINAPI HTMLStyleSheet_get_type(IHTMLStyleSheet *iface, BSTR *p)
923 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
924 FIXME("(%p)->(%p)\n", This, p);
925 return E_NOTIMPL;
928 static HRESULT WINAPI HTMLStyleSheet_get_id(IHTMLStyleSheet *iface, BSTR *p)
930 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
931 FIXME("(%p)->(%p)\n", This, p);
932 return E_NOTIMPL;
935 static HRESULT WINAPI HTMLStyleSheet_addImport(IHTMLStyleSheet *iface, BSTR bstrURL,
936 LONG lIndex, LONG *plIndex)
938 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
939 FIXME("(%p)->(%s %d %p)\n", This, debugstr_w(bstrURL), lIndex, plIndex);
940 return E_NOTIMPL;
943 static HRESULT WINAPI HTMLStyleSheet_addRule(IHTMLStyleSheet *iface, BSTR bstrSelector,
944 BSTR bstrStyle, LONG lIndex, LONG *plIndex)
946 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
947 const WCHAR format[] = L"%s {%s}";
948 nsIDOMCSSRuleList *nslist = NULL;
949 UINT32 length, new_index;
950 nsAString nsstr;
951 nsresult nsres;
952 WCHAR *rule;
953 size_t len;
955 TRACE("(%p)->(%s %s %d %p)\n", This, debugstr_w(bstrSelector), debugstr_w(bstrStyle),
956 lIndex, plIndex);
958 if(!bstrSelector || !bstrStyle || !bstrSelector[0] || !bstrStyle[0])
959 return E_INVALIDARG;
961 nsres = nsIDOMCSSStyleSheet_GetCssRules(This->nsstylesheet, &nslist);
962 if(NS_FAILED(nsres))
963 return E_FAIL;
964 nsIDOMCSSRuleList_GetLength(nslist, &length);
966 if(lIndex > length)
967 lIndex = length;
969 len = ARRAY_SIZE(format) - 4 /* %s twice */ + wcslen(bstrSelector) + wcslen(bstrStyle);
970 if(!(rule = heap_alloc(len * sizeof(WCHAR))))
971 return E_OUTOFMEMORY;
972 swprintf(rule, len, format, bstrSelector, bstrStyle);
974 nsAString_InitDepend(&nsstr, rule);
975 nsres = nsIDOMCSSStyleSheet_InsertRule(This->nsstylesheet, &nsstr, lIndex, &new_index);
976 if(NS_FAILED(nsres)) WARN("failed: %08x\n", nsres);
977 nsAString_Finish(&nsstr);
978 heap_free(rule);
980 *plIndex = new_index;
981 return map_nsresult(nsres);
984 static HRESULT WINAPI HTMLStyleSheet_removeImport(IHTMLStyleSheet *iface, LONG lIndex)
986 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
987 FIXME("(%p)->(%d)\n", This, lIndex);
988 return E_NOTIMPL;
991 static HRESULT WINAPI HTMLStyleSheet_removeRule(IHTMLStyleSheet *iface, LONG lIndex)
993 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
994 FIXME("(%p)->(%d)\n", This, lIndex);
995 return E_NOTIMPL;
998 static HRESULT WINAPI HTMLStyleSheet_put_media(IHTMLStyleSheet *iface, BSTR v)
1000 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1001 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
1002 return E_NOTIMPL;
1005 static HRESULT WINAPI HTMLStyleSheet_get_media(IHTMLStyleSheet *iface, BSTR *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_cssText(IHTMLStyleSheet *iface, BSTR v)
1014 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1015 nsresult nsres;
1017 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1019 do {
1020 nsres = nsIDOMCSSStyleSheet_DeleteRule(This->nsstylesheet, 0);
1021 }while(NS_SUCCEEDED(nsres));
1023 if(v && *v) {
1024 nsAString nsstr;
1025 UINT32 idx;
1027 /* FIXME: This won't work for multiple rules in the string. */
1028 nsAString_InitDepend(&nsstr, v);
1029 nsres = nsIDOMCSSStyleSheet_InsertRule(This->nsstylesheet, &nsstr, 0, &idx);
1030 nsAString_Finish(&nsstr);
1031 if(NS_FAILED(nsres)) {
1032 FIXME("InsertRule failed for string %s. Probably multiple rules passed.\n", debugstr_w(v));
1033 return E_FAIL;
1037 return S_OK;
1040 static HRESULT WINAPI HTMLStyleSheet_get_cssText(IHTMLStyleSheet *iface, BSTR *p)
1042 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1043 nsIDOMCSSRuleList *nslist = NULL;
1044 nsIDOMCSSRule *nsrule;
1045 nsAString nsstr;
1046 UINT32 len;
1047 nsresult nsres;
1049 TRACE("(%p)->(%p)\n", This, p);
1051 nsres = nsIDOMCSSStyleSheet_GetCssRules(This->nsstylesheet, &nslist);
1052 if(NS_FAILED(nsres)) {
1053 ERR("GetCssRules failed: %08x\n", nsres);
1054 return E_FAIL;
1057 nsres = nsIDOMCSSRuleList_GetLength(nslist, &len);
1058 assert(nsres == NS_OK);
1060 if(len) {
1061 nsres = nsIDOMCSSRuleList_Item(nslist, 0, &nsrule);
1062 if(NS_FAILED(nsres))
1063 ERR("Item failed: %08x\n", nsres);
1066 nsIDOMCSSRuleList_Release(nslist);
1067 if(NS_FAILED(nsres))
1068 return E_FAIL;
1070 if(!len) {
1071 *p = NULL;
1072 return S_OK;
1075 nsAString_Init(&nsstr, NULL);
1076 nsres = nsIDOMCSSRule_GetCssText(nsrule, &nsstr);
1077 nsIDOMCSSRule_Release(nsrule);
1078 return return_nsstr(nsres, &nsstr, p);
1081 static HRESULT WINAPI HTMLStyleSheet_get_rules(IHTMLStyleSheet *iface,
1082 IHTMLStyleSheetRulesCollection **p)
1084 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1085 nsIDOMCSSRuleList *nslist = NULL;
1086 nsresult nsres;
1087 HRESULT hres;
1089 TRACE("(%p)->(%p)\n", This, p);
1091 nsres = nsIDOMCSSStyleSheet_GetCssRules(This->nsstylesheet, &nslist);
1092 if(NS_FAILED(nsres)) {
1093 ERR("GetCssRules failed: %08x\n", nsres);
1094 return E_FAIL;
1097 hres = create_style_sheet_rules_collection(nslist, dispex_compat_mode(&This->dispex), p);
1098 nsIDOMCSSRuleList_Release(nslist);
1099 return hres;
1102 static const IHTMLStyleSheetVtbl HTMLStyleSheetVtbl = {
1103 HTMLStyleSheet_QueryInterface,
1104 HTMLStyleSheet_AddRef,
1105 HTMLStyleSheet_Release,
1106 HTMLStyleSheet_GetTypeInfoCount,
1107 HTMLStyleSheet_GetTypeInfo,
1108 HTMLStyleSheet_GetIDsOfNames,
1109 HTMLStyleSheet_Invoke,
1110 HTMLStyleSheet_put_title,
1111 HTMLStyleSheet_get_title,
1112 HTMLStyleSheet_get_parentStyleSheet,
1113 HTMLStyleSheet_get_owningElement,
1114 HTMLStyleSheet_put_disabled,
1115 HTMLStyleSheet_get_disabled,
1116 HTMLStyleSheet_get_readOnly,
1117 HTMLStyleSheet_get_imports,
1118 HTMLStyleSheet_put_href,
1119 HTMLStyleSheet_get_href,
1120 HTMLStyleSheet_get_type,
1121 HTMLStyleSheet_get_id,
1122 HTMLStyleSheet_addImport,
1123 HTMLStyleSheet_addRule,
1124 HTMLStyleSheet_removeImport,
1125 HTMLStyleSheet_removeRule,
1126 HTMLStyleSheet_put_media,
1127 HTMLStyleSheet_get_media,
1128 HTMLStyleSheet_put_cssText,
1129 HTMLStyleSheet_get_cssText,
1130 HTMLStyleSheet_get_rules
1133 static inline HTMLStyleSheet *impl_from_IHTMLStyleSheet4(IHTMLStyleSheet4 *iface)
1135 return CONTAINING_RECORD(iface, HTMLStyleSheet, IHTMLStyleSheet4_iface);
1138 static HRESULT WINAPI HTMLStyleSheet4_QueryInterface(IHTMLStyleSheet4 *iface, REFIID riid, void **ppv)
1140 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1141 return IHTMLStyleSheet_QueryInterface(&This->IHTMLStyleSheet_iface, riid, ppv);
1144 static ULONG WINAPI HTMLStyleSheet4_AddRef(IHTMLStyleSheet4 *iface)
1146 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1147 return IHTMLStyleSheet_AddRef(&This->IHTMLStyleSheet_iface);
1150 static ULONG WINAPI HTMLStyleSheet4_Release(IHTMLStyleSheet4 *iface)
1152 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1153 return IHTMLStyleSheet_Release(&This->IHTMLStyleSheet_iface);
1156 static HRESULT WINAPI HTMLStyleSheet4_GetTypeInfoCount(IHTMLStyleSheet4 *iface, UINT *pctinfo)
1158 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1159 TRACE("(%p)->(%p)\n", This, pctinfo);
1160 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
1163 static HRESULT WINAPI HTMLStyleSheet4_GetTypeInfo(IHTMLStyleSheet4 *iface, UINT iTInfo,
1164 LCID lcid, ITypeInfo **ppTInfo)
1166 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1167 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1170 static HRESULT WINAPI HTMLStyleSheet4_GetIDsOfNames(IHTMLStyleSheet4 *iface, REFIID riid,
1171 LPOLESTR *rgszNames, UINT cNames,
1172 LCID lcid, DISPID *rgDispId)
1174 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1175 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames, lcid, rgDispId);
1178 static HRESULT WINAPI HTMLStyleSheet4_Invoke(IHTMLStyleSheet4 *iface, DISPID dispIdMember,
1179 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1180 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1182 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1183 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags, pDispParams,
1184 pVarResult, pExcepInfo, puArgErr);
1187 static HRESULT WINAPI HTMLStyleSheet4_get_type(IHTMLStyleSheet4 *iface, BSTR *p)
1189 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1190 TRACE("(%p)->(%p)\n", This, p);
1191 return IHTMLStyleSheet_get_type(&This->IHTMLStyleSheet_iface, p);
1194 static HRESULT WINAPI HTMLStyleSheet4_get_href(IHTMLStyleSheet4 *iface, VARIANT *p)
1196 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1197 nsAString href_str;
1198 nsresult nsres;
1200 TRACE("(%p)->(%p)\n", This, p);
1202 nsAString_Init(&href_str, NULL);
1203 nsres = nsIDOMCSSStyleSheet_GetHref(This->nsstylesheet, &href_str);
1204 return return_nsstr_variant(nsres, &href_str, 0, p);
1207 static HRESULT WINAPI HTMLStyleSheet4_get_title(IHTMLStyleSheet4 *iface, BSTR *p)
1209 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1210 FIXME("(%p)->(%p)\n", This, p);
1211 return E_NOTIMPL;
1214 static HRESULT WINAPI HTMLStyleSheet4_get_ownerNode(IHTMLStyleSheet4 *iface, IHTMLElement **p)
1216 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1217 FIXME("(%p)->(%p)\n", This, p);
1218 return E_NOTIMPL;
1221 static HRESULT WINAPI HTMLStyleSheet4_get_ownerRule(IHTMLStyleSheet4 *iface, IHTMLCSSRule **p)
1223 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1224 FIXME("(%p)->(%p)\n", This, p);
1225 return E_NOTIMPL;
1228 static HRESULT WINAPI HTMLStyleSheet4_get_cssRules(IHTMLStyleSheet4 *iface, IHTMLStyleSheetRulesCollection **p)
1230 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1231 TRACE("(%p)->(%p)\n", This, p);
1232 return IHTMLStyleSheet_get_rules(&This->IHTMLStyleSheet_iface, p);
1235 static HRESULT WINAPI HTMLStyleSheet4_get_media(IHTMLStyleSheet4 *iface, VARIANT *p)
1237 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1238 FIXME("(%p)->(%p)\n", This, p);
1239 return E_NOTIMPL;
1242 static HRESULT WINAPI HTMLStyleSheet4_insertRule(IHTMLStyleSheet4 *iface, BSTR rule, LONG index, LONG *p)
1244 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1245 UINT32 new_index = 0;
1246 nsAString nsstr;
1247 nsresult nsres;
1249 TRACE("(%p)->(%s %d %p)\n", This, debugstr_w(rule), index, p);
1251 nsAString_InitDepend(&nsstr, rule);
1252 nsres = nsIDOMCSSStyleSheet_InsertRule(This->nsstylesheet, &nsstr, index, &new_index);
1253 if(NS_FAILED(nsres)) WARN("failed: %08x\n", nsres);
1254 nsAString_Finish(&nsstr);
1255 *p = new_index;
1256 return map_nsresult(nsres);
1259 static HRESULT WINAPI HTMLStyleSheet4_deleteRule(IHTMLStyleSheet4 *iface, LONG index)
1261 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1262 FIXME("(%p)->(%d)\n", This, index);
1263 return E_NOTIMPL;
1266 static const IHTMLStyleSheet4Vtbl HTMLStyleSheet4Vtbl = {
1267 HTMLStyleSheet4_QueryInterface,
1268 HTMLStyleSheet4_AddRef,
1269 HTMLStyleSheet4_Release,
1270 HTMLStyleSheet4_GetTypeInfoCount,
1271 HTMLStyleSheet4_GetTypeInfo,
1272 HTMLStyleSheet4_GetIDsOfNames,
1273 HTMLStyleSheet4_Invoke,
1274 HTMLStyleSheet4_get_type,
1275 HTMLStyleSheet4_get_href,
1276 HTMLStyleSheet4_get_title,
1277 HTMLStyleSheet4_get_ownerNode,
1278 HTMLStyleSheet4_get_ownerRule,
1279 HTMLStyleSheet4_get_cssRules,
1280 HTMLStyleSheet4_get_media,
1281 HTMLStyleSheet4_insertRule,
1282 HTMLStyleSheet4_deleteRule,
1285 static void HTMLStyleSheet_init_dispex_info(dispex_data_t *info, compat_mode_t mode)
1287 if(mode >= COMPAT_MODE_IE9)
1288 dispex_info_add_interface(info, IHTMLStyleSheet4_tid, NULL);
1291 static const tid_t HTMLStyleSheet_iface_tids[] = {
1292 IHTMLStyleSheet_tid,
1295 static dispex_static_data_t HTMLStyleSheet_dispex = {
1296 L"CSSStyleSheet",
1297 NULL,
1298 DispHTMLStyleSheet_tid,
1299 HTMLStyleSheet_iface_tids,
1300 HTMLStyleSheet_init_dispex_info
1303 HRESULT create_style_sheet(nsIDOMStyleSheet *nsstylesheet, compat_mode_t compat_mode, IHTMLStyleSheet **ret)
1305 HTMLStyleSheet *style_sheet;
1306 nsresult nsres;
1308 if(!(style_sheet = heap_alloc(sizeof(HTMLStyleSheet))))
1309 return E_OUTOFMEMORY;
1311 style_sheet->IHTMLStyleSheet_iface.lpVtbl = &HTMLStyleSheetVtbl;
1312 style_sheet->IHTMLStyleSheet4_iface.lpVtbl = &HTMLStyleSheet4Vtbl;
1313 style_sheet->ref = 1;
1314 style_sheet->nsstylesheet = NULL;
1316 init_dispatch(&style_sheet->dispex, (IUnknown*)&style_sheet->IHTMLStyleSheet_iface,
1317 &HTMLStyleSheet_dispex, compat_mode);
1319 if(nsstylesheet) {
1320 nsres = nsIDOMStyleSheet_QueryInterface(nsstylesheet, &IID_nsIDOMCSSStyleSheet,
1321 (void**)&style_sheet->nsstylesheet);
1322 if(NS_FAILED(nsres))
1323 ERR("Could not get nsICSSStyleSheet interface: %08x\n", nsres);
1326 *ret = &style_sheet->IHTMLStyleSheet_iface;
1327 return S_OK;