windows.networking.hostname/tests: Add IHostNameFactory::CreateHostName() tests.
[wine.git] / dlls / mshtml / htmlstylesheet.c
blob59680d720e26d50ecad7d2a86bad7e3482f169f3
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 typedef struct {
54 IEnumVARIANT IEnumVARIANT_iface;
56 LONG ref;
58 ULONG iter;
59 HTMLStyleSheetsCollection *col;
60 } HTMLStyleSheetsCollectionEnum;
62 struct HTMLStyleSheetRulesCollection {
63 DispatchEx dispex;
64 IHTMLStyleSheetRulesCollection IHTMLStyleSheetRulesCollection_iface;
66 LONG ref;
68 nsIDOMCSSRuleList *nslist;
71 struct HTMLStyleSheetRule {
72 DispatchEx dispex;
73 IHTMLStyleSheetRule IHTMLStyleSheetRule_iface;
75 LONG ref;
77 nsIDOMCSSRule *nsstylesheetrule;
80 static inline HTMLStyleSheetRule *impl_from_IHTMLStyleSheetRule(IHTMLStyleSheetRule *iface)
82 return CONTAINING_RECORD(iface, HTMLStyleSheetRule, IHTMLStyleSheetRule_iface);
85 static HRESULT WINAPI HTMLStyleSheetRule_QueryInterface(IHTMLStyleSheetRule *iface,
86 REFIID riid, void **ppv)
88 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
90 TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
92 if (IsEqualGUID(&IID_IUnknown, riid))
93 *ppv = &This->IHTMLStyleSheetRule_iface;
94 else if (IsEqualGUID(&IID_IHTMLStyleSheetRule, riid))
95 *ppv = &This->IHTMLStyleSheetRule_iface;
96 else if (dispex_query_interface(&This->dispex, riid, ppv))
97 return *ppv ? S_OK : E_NOINTERFACE;
98 else
100 *ppv = NULL;
101 FIXME("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
102 return E_NOINTERFACE;
105 IUnknown_AddRef((IUnknown *)*ppv);
106 return S_OK;
109 static ULONG WINAPI HTMLStyleSheetRule_AddRef(IHTMLStyleSheetRule *iface)
111 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
112 LONG ref = InterlockedIncrement(&This->ref);
114 TRACE("(%p) ref=%ld\n", This, ref);
116 return ref;
119 static ULONG WINAPI HTMLStyleSheetRule_Release(IHTMLStyleSheetRule *iface)
121 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
122 LONG ref = InterlockedDecrement(&This->ref);
124 TRACE("(%p) ref=%ld\n", This, ref);
126 if(!ref) {
127 release_dispex(&This->dispex);
128 if(This->nsstylesheetrule)
129 nsIDOMCSSRule_Release(This->nsstylesheetrule);
130 free(This);
133 return ref;
136 static HRESULT WINAPI HTMLStyleSheetRule_GetTypeInfoCount(
137 IHTMLStyleSheetRule *iface, UINT *pctinfo)
139 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
140 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
143 static HRESULT WINAPI HTMLStyleSheetRule_GetTypeInfo(IHTMLStyleSheetRule *iface,
144 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
146 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
147 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
150 static HRESULT WINAPI HTMLStyleSheetRule_GetIDsOfNames(IHTMLStyleSheetRule *iface,
151 REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
153 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
154 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
155 lcid, rgDispId);
158 static HRESULT WINAPI HTMLStyleSheetRule_Invoke(IHTMLStyleSheetRule *iface,
159 DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
160 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
162 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
163 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
164 pDispParams, pVarResult, pExcepInfo, puArgErr);
167 static HRESULT WINAPI HTMLStyleSheetRule_put_selectorText(IHTMLStyleSheetRule *iface, BSTR v)
169 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
170 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
171 return E_NOTIMPL;
174 static HRESULT WINAPI HTMLStyleSheetRule_get_selectorText(IHTMLStyleSheetRule *iface, BSTR *p)
176 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
177 FIXME("(%p)->(%p)\n", This, p);
178 return E_NOTIMPL;
181 static HRESULT WINAPI HTMLStyleSheetRule_get_style(IHTMLStyleSheetRule *iface, IHTMLRuleStyle **p)
183 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
184 FIXME("(%p)->(%p)\n", This, p);
185 return E_NOTIMPL;
188 static HRESULT WINAPI HTMLStyleSheetRule_get_readOnly(IHTMLStyleSheetRule *iface, VARIANT_BOOL *p)
190 HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
191 FIXME("(%p)->(%p)\n", This, p);
192 return E_NOTIMPL;
195 static const IHTMLStyleSheetRuleVtbl HTMLStyleSheetRuleVtbl = {
196 HTMLStyleSheetRule_QueryInterface,
197 HTMLStyleSheetRule_AddRef,
198 HTMLStyleSheetRule_Release,
199 HTMLStyleSheetRule_GetTypeInfoCount,
200 HTMLStyleSheetRule_GetTypeInfo,
201 HTMLStyleSheetRule_GetIDsOfNames,
202 HTMLStyleSheetRule_Invoke,
203 HTMLStyleSheetRule_put_selectorText,
204 HTMLStyleSheetRule_get_selectorText,
205 HTMLStyleSheetRule_get_style,
206 HTMLStyleSheetRule_get_readOnly
209 static const tid_t HTMLStyleSheetRule_iface_tids[] = {
210 IHTMLStyleSheetRule_tid,
213 static dispex_static_data_t HTMLStyleSheetRule_dispex = {
214 L"CSSStyleRule",
215 NULL,
216 DispHTMLStyleSheetRule_tid,
217 HTMLStyleSheetRule_iface_tids
220 static HRESULT create_style_sheet_rule(nsIDOMCSSRule *nsstylesheetrule, compat_mode_t compat_mode,
221 IHTMLStyleSheetRule **ret)
223 HTMLStyleSheetRule *rule;
224 nsresult nsres;
226 if(!(rule = malloc(sizeof(*rule))))
227 return E_OUTOFMEMORY;
229 rule->IHTMLStyleSheetRule_iface.lpVtbl = &HTMLStyleSheetRuleVtbl;
230 rule->ref = 1;
231 rule->nsstylesheetrule = NULL;
233 init_dispatch(&rule->dispex, (IUnknown *)&rule->IHTMLStyleSheetRule_iface, &HTMLStyleSheetRule_dispex,
234 compat_mode);
236 if (nsstylesheetrule)
238 nsres = nsIDOMCSSRule_QueryInterface(nsstylesheetrule, &IID_nsIDOMCSSRule,
239 (void **)&rule->nsstylesheetrule);
240 if (NS_FAILED(nsres))
241 ERR("Could not get nsIDOMCSSRule interface: %08lx\n", nsres);
244 *ret = &rule->IHTMLStyleSheetRule_iface;
245 return S_OK;
248 static inline HTMLStyleSheetRulesCollection *impl_from_IHTMLStyleSheetRulesCollection(IHTMLStyleSheetRulesCollection *iface)
250 return CONTAINING_RECORD(iface, HTMLStyleSheetRulesCollection, IHTMLStyleSheetRulesCollection_iface);
253 static HRESULT WINAPI HTMLStyleSheetRulesCollection_QueryInterface(IHTMLStyleSheetRulesCollection *iface,
254 REFIID riid, void **ppv)
256 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
258 TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
260 if(IsEqualGUID(&IID_IUnknown, riid)) {
261 *ppv = &This->IHTMLStyleSheetRulesCollection_iface;
262 }else if(IsEqualGUID(&IID_IHTMLStyleSheetRulesCollection, riid)) {
263 *ppv = &This->IHTMLStyleSheetRulesCollection_iface;
264 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
265 return *ppv ? S_OK : E_NOINTERFACE;
266 }else {
267 *ppv = NULL;
268 FIXME("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
269 return E_NOINTERFACE;
272 IUnknown_AddRef((IUnknown*)*ppv);
273 return S_OK;
276 static ULONG WINAPI HTMLStyleSheetRulesCollection_AddRef(IHTMLStyleSheetRulesCollection *iface)
278 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
279 LONG ref = InterlockedIncrement(&This->ref);
281 TRACE("(%p) ref=%ld\n", This, ref);
283 return ref;
286 static ULONG WINAPI HTMLStyleSheetRulesCollection_Release(IHTMLStyleSheetRulesCollection *iface)
288 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
289 LONG ref = InterlockedDecrement(&This->ref);
291 TRACE("(%p) ref=%ld\n", This, ref);
293 if(!ref) {
294 release_dispex(&This->dispex);
295 if(This->nslist)
296 nsIDOMCSSRuleList_Release(This->nslist);
297 free(This);
300 return ref;
303 static HRESULT WINAPI HTMLStyleSheetRulesCollection_GetTypeInfoCount(
304 IHTMLStyleSheetRulesCollection *iface, UINT *pctinfo)
306 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
307 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
310 static HRESULT WINAPI HTMLStyleSheetRulesCollection_GetTypeInfo(IHTMLStyleSheetRulesCollection *iface,
311 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
313 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
314 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
317 static HRESULT WINAPI HTMLStyleSheetRulesCollection_GetIDsOfNames(IHTMLStyleSheetRulesCollection *iface,
318 REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
320 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
321 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
322 lcid, rgDispId);
325 static HRESULT WINAPI HTMLStyleSheetRulesCollection_Invoke(IHTMLStyleSheetRulesCollection *iface,
326 DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
327 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
329 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
330 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
331 pDispParams, pVarResult, pExcepInfo, puArgErr);
334 static HRESULT WINAPI HTMLStyleSheetRulesCollection_get_length(IHTMLStyleSheetRulesCollection *iface,
335 LONG *p)
337 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
338 UINT32 len = 0;
340 TRACE("(%p)->(%p)\n", This, p);
342 if(This->nslist) {
343 nsresult nsres;
345 nsres = nsIDOMCSSRuleList_GetLength(This->nslist, &len);
346 if(NS_FAILED(nsres))
347 ERR("GetLength failed: %08lx\n", nsres);
350 *p = len;
351 return S_OK;
354 static HRESULT WINAPI HTMLStyleSheetRulesCollection_item(IHTMLStyleSheetRulesCollection *iface,
355 LONG index, IHTMLStyleSheetRule **p)
357 HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
358 nsIDOMCSSRule *nsstylesheetrule;
359 nsresult nsres;
360 HRESULT hres;
362 TRACE("(%p)->(%ld %p)\n", This, index, p);
364 nsres = nsIDOMCSSRuleList_Item(This->nslist, index, &nsstylesheetrule);
365 if(NS_FAILED(nsres))
366 return map_nsresult(nsres);
367 if(!nsstylesheetrule)
368 return E_INVALIDARG;
370 hres = create_style_sheet_rule(nsstylesheetrule, dispex_compat_mode(&This->dispex), p);
371 nsIDOMCSSRule_Release(nsstylesheetrule);
372 return hres;
375 static const IHTMLStyleSheetRulesCollectionVtbl HTMLStyleSheetRulesCollectionVtbl = {
376 HTMLStyleSheetRulesCollection_QueryInterface,
377 HTMLStyleSheetRulesCollection_AddRef,
378 HTMLStyleSheetRulesCollection_Release,
379 HTMLStyleSheetRulesCollection_GetTypeInfoCount,
380 HTMLStyleSheetRulesCollection_GetTypeInfo,
381 HTMLStyleSheetRulesCollection_GetIDsOfNames,
382 HTMLStyleSheetRulesCollection_Invoke,
383 HTMLStyleSheetRulesCollection_get_length,
384 HTMLStyleSheetRulesCollection_item
387 static inline HTMLStyleSheetRulesCollection *HTMLStyleSheetRulesCollection_from_DispatchEx(DispatchEx *iface)
389 return CONTAINING_RECORD(iface, HTMLStyleSheetRulesCollection, dispex);
392 static HRESULT HTMLStyleSheetRulesCollection_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
394 HTMLStyleSheetRulesCollection *This = HTMLStyleSheetRulesCollection_from_DispatchEx(dispex);
395 UINT32 len = 0;
396 DWORD idx = 0;
397 WCHAR *ptr;
399 for(ptr = name; *ptr && is_digit(*ptr); ptr++)
400 idx = idx*10 + (*ptr-'0');
401 if(*ptr)
402 return DISP_E_UNKNOWNNAME;
404 nsIDOMCSSRuleList_GetLength(This->nslist, &len);
405 if(idx >= len)
406 return DISP_E_UNKNOWNNAME;
408 *dispid = MSHTML_DISPID_CUSTOM_MIN + idx;
409 TRACE("ret %lx\n", *dispid);
410 return S_OK;
413 static HRESULT HTMLStyleSheetRulesCollection_get_name(DispatchEx *dispex, DISPID id, BSTR *name)
415 HTMLStyleSheetRulesCollection *This = HTMLStyleSheetRulesCollection_from_DispatchEx(dispex);
416 DWORD idx = id - MSHTML_DISPID_CUSTOM_MIN;
417 UINT32 len = 0;
418 WCHAR buf[11];
420 nsIDOMCSSRuleList_GetLength(This->nslist, &len);
421 if(idx >= len)
422 return DISP_E_MEMBERNOTFOUND;
424 len = swprintf(buf, ARRAY_SIZE(buf), L"%u", idx);
425 return (*name = SysAllocStringLen(buf, len)) ? S_OK : E_OUTOFMEMORY;
428 static HRESULT HTMLStyleSheetRulesCollection_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
429 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
431 HTMLStyleSheetRulesCollection *This = HTMLStyleSheetRulesCollection_from_DispatchEx(dispex);
433 TRACE("(%p)->(%lx %lx %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
435 switch(flags) {
436 case DISPATCH_PROPERTYGET: {
437 IHTMLStyleSheetRule *stylesheetrule;
438 nsIDOMCSSRule *nsstylesheetrule;
439 nsresult nsres;
440 HRESULT hres;
442 nsres = nsIDOMCSSRuleList_Item(This->nslist, id - MSHTML_DISPID_CUSTOM_MIN, &nsstylesheetrule);
443 if(NS_FAILED(nsres))
444 return DISP_E_MEMBERNOTFOUND;
445 if(!nsstylesheetrule) {
446 V_VT(res) = VT_EMPTY;
447 return S_OK;
450 hres = create_style_sheet_rule(nsstylesheetrule, dispex_compat_mode(&This->dispex), &stylesheetrule);
451 nsIDOMCSSRule_Release(nsstylesheetrule);
452 if(FAILED(hres))
453 return hres;
455 V_VT(res) = VT_DISPATCH;
456 V_DISPATCH(res) = (IDispatch*)stylesheetrule;
457 break;
460 default:
461 FIXME("unimplemented flags %x\n", flags);
462 return E_NOTIMPL;
465 return S_OK;
468 static const dispex_static_data_vtbl_t HTMLStyleSheetRulesCollection_dispex_vtbl = {
469 NULL,
470 HTMLStyleSheetRulesCollection_get_dispid,
471 HTMLStyleSheetRulesCollection_get_name,
472 HTMLStyleSheetRulesCollection_invoke
474 static const tid_t HTMLStyleSheetRulesCollection_iface_tids[] = {
475 IHTMLStyleSheetRulesCollection_tid,
478 static dispex_static_data_t HTMLStyleSheetRulesCollection_dispex = {
479 L"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->ref = 1;
495 collection->nslist = nslist;
497 init_dispatch(&collection->dispex, (IUnknown*)&collection->IHTMLStyleSheetRulesCollection_iface,
498 &HTMLStyleSheetRulesCollection_dispex, compat_mode);
500 if(nslist)
501 nsIDOMCSSRuleList_AddRef(nslist);
503 *ret = &collection->IHTMLStyleSheetRulesCollection_iface;
504 return S_OK;
507 static inline HTMLStyleSheetsCollectionEnum *HTMLStyleSheetsCollectionEnum_from_IEnumVARIANT(IEnumVARIANT *iface)
509 return CONTAINING_RECORD(iface, HTMLStyleSheetsCollectionEnum, IEnumVARIANT_iface);
512 static HRESULT WINAPI HTMLStyleSheetsCollectionEnum_QueryInterface(IEnumVARIANT *iface, REFIID riid, void **ppv)
514 HTMLStyleSheetsCollectionEnum *This = HTMLStyleSheetsCollectionEnum_from_IEnumVARIANT(iface);
516 TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
518 if(IsEqualGUID(riid, &IID_IUnknown)) {
519 *ppv = &This->IEnumVARIANT_iface;
520 }else if(IsEqualGUID(riid, &IID_IEnumVARIANT)) {
521 *ppv = &This->IEnumVARIANT_iface;
522 }else {
523 FIXME("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
524 *ppv = NULL;
525 return E_NOINTERFACE;
528 IUnknown_AddRef((IUnknown*)*ppv);
529 return S_OK;
532 static ULONG WINAPI HTMLStyleSheetsCollectionEnum_AddRef(IEnumVARIANT *iface)
534 HTMLStyleSheetsCollectionEnum *This = HTMLStyleSheetsCollectionEnum_from_IEnumVARIANT(iface);
535 LONG ref = InterlockedIncrement(&This->ref);
537 TRACE("(%p) ref=%ld\n", This, ref);
539 return ref;
542 static ULONG WINAPI HTMLStyleSheetsCollectionEnum_Release(IEnumVARIANT *iface)
544 HTMLStyleSheetsCollectionEnum *This = HTMLStyleSheetsCollectionEnum_from_IEnumVARIANT(iface);
545 LONG ref = InterlockedDecrement(&This->ref);
547 TRACE("(%p) ref=%ld\n", This, ref);
549 if(!ref) {
550 IHTMLStyleSheetsCollection_Release(&This->col->IHTMLStyleSheetsCollection_iface);
551 free(This);
554 return ref;
557 static HRESULT WINAPI HTMLStyleSheetsCollectionEnum_Next(IEnumVARIANT *iface, ULONG celt, VARIANT *rgVar, ULONG *pCeltFetched)
559 HTMLStyleSheetsCollectionEnum *This = HTMLStyleSheetsCollectionEnum_from_IEnumVARIANT(iface);
560 VARIANT index;
561 HRESULT hres;
562 ULONG num, i;
563 UINT32 len;
565 TRACE("(%p)->(%lu %p %p)\n", This, celt, rgVar, pCeltFetched);
567 nsIDOMStyleSheetList_GetLength(This->col->nslist, &len);
568 num = min(len - This->iter, celt);
569 V_VT(&index) = VT_I4;
571 for(i = 0; i < num; i++) {
572 V_I4(&index) = This->iter + i;
573 hres = IHTMLStyleSheetsCollection_item(&This->col->IHTMLStyleSheetsCollection_iface, &index, &rgVar[i]);
574 if(FAILED(hres)) {
575 while(i--)
576 VariantClear(&rgVar[i]);
577 return hres;
581 This->iter += num;
582 if(pCeltFetched)
583 *pCeltFetched = num;
584 return num == celt ? S_OK : S_FALSE;
587 static HRESULT WINAPI HTMLStyleSheetsCollectionEnum_Skip(IEnumVARIANT *iface, ULONG celt)
589 HTMLStyleSheetsCollectionEnum *This = HTMLStyleSheetsCollectionEnum_from_IEnumVARIANT(iface);
590 UINT32 len;
592 TRACE("(%p)->(%lu)\n", This, celt);
594 nsIDOMStyleSheetList_GetLength(This->col->nslist, &len);
595 if(This->iter + celt > len) {
596 This->iter = len;
597 return S_FALSE;
600 This->iter += celt;
601 return S_OK;
604 static HRESULT WINAPI HTMLStyleSheetsCollectionEnum_Reset(IEnumVARIANT *iface)
606 HTMLStyleSheetsCollectionEnum *This = HTMLStyleSheetsCollectionEnum_from_IEnumVARIANT(iface);
608 TRACE("(%p)->()\n", This);
610 This->iter = 0;
611 return S_OK;
614 static HRESULT WINAPI HTMLStyleSheetsCollectionEnum_Clone(IEnumVARIANT *iface, IEnumVARIANT **ppEnum)
616 HTMLStyleSheetsCollectionEnum *This = HTMLStyleSheetsCollectionEnum_from_IEnumVARIANT(iface);
617 FIXME("(%p)->(%p)\n", This, ppEnum);
618 return E_NOTIMPL;
621 static const IEnumVARIANTVtbl HTMLStyleSheetsCollectionEnumVtbl = {
622 HTMLStyleSheetsCollectionEnum_QueryInterface,
623 HTMLStyleSheetsCollectionEnum_AddRef,
624 HTMLStyleSheetsCollectionEnum_Release,
625 HTMLStyleSheetsCollectionEnum_Next,
626 HTMLStyleSheetsCollectionEnum_Skip,
627 HTMLStyleSheetsCollectionEnum_Reset,
628 HTMLStyleSheetsCollectionEnum_Clone
631 static inline HTMLStyleSheetsCollection *impl_from_IHTMLStyleSheetsCollection(IHTMLStyleSheetsCollection *iface)
633 return CONTAINING_RECORD(iface, HTMLStyleSheetsCollection, IHTMLStyleSheetsCollection_iface);
636 static HRESULT WINAPI HTMLStyleSheetsCollection_QueryInterface(IHTMLStyleSheetsCollection *iface,
637 REFIID riid, void **ppv)
639 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
641 TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
643 if(IsEqualGUID(&IID_IUnknown, riid)) {
644 *ppv = &This->IHTMLStyleSheetsCollection_iface;
645 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
646 *ppv = &This->IHTMLStyleSheetsCollection_iface;
647 }else if(IsEqualGUID(&IID_IHTMLStyleSheetsCollection, riid)) {
648 *ppv = &This->IHTMLStyleSheetsCollection_iface;
649 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
650 return *ppv ? S_OK : E_NOINTERFACE;
651 }else {
652 *ppv = NULL;
653 WARN("unsupported %s\n", debugstr_mshtml_guid(riid));
654 return E_NOINTERFACE;
657 IUnknown_AddRef((IUnknown*)*ppv);
658 return S_OK;
661 static ULONG WINAPI HTMLStyleSheetsCollection_AddRef(IHTMLStyleSheetsCollection *iface)
663 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
664 LONG ref = InterlockedIncrement(&This->ref);
666 TRACE("(%p) ref=%ld\n", This, ref);
668 return ref;
671 static ULONG WINAPI HTMLStyleSheetsCollection_Release(IHTMLStyleSheetsCollection *iface)
673 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
674 LONG ref = InterlockedDecrement(&This->ref);
676 TRACE("(%p) ref=%ld\n", This, ref);
678 if(!ref) {
679 release_dispex(&This->dispex);
680 if(This->nslist)
681 nsIDOMStyleSheetList_Release(This->nslist);
682 free(This);
685 return ref;
688 static HRESULT WINAPI HTMLStyleSheetsCollection_GetTypeInfoCount(IHTMLStyleSheetsCollection *iface,
689 UINT *pctinfo)
691 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
692 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
695 static HRESULT WINAPI HTMLStyleSheetsCollection_GetTypeInfo(IHTMLStyleSheetsCollection *iface,
696 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
698 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
699 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
702 static HRESULT WINAPI HTMLStyleSheetsCollection_GetIDsOfNames(IHTMLStyleSheetsCollection *iface,
703 REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
705 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
706 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
707 lcid, rgDispId);
710 static HRESULT WINAPI HTMLStyleSheetsCollection_Invoke(IHTMLStyleSheetsCollection *iface,
711 DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
712 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
714 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
715 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
716 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
719 static HRESULT WINAPI HTMLStyleSheetsCollection_get_length(IHTMLStyleSheetsCollection *iface,
720 LONG *p)
722 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
723 UINT32 len = 0;
725 TRACE("(%p)->(%p)\n", This, p);
727 if(This->nslist)
728 nsIDOMStyleSheetList_GetLength(This->nslist, &len);
730 *p = len;
731 return S_OK;
734 static HRESULT WINAPI HTMLStyleSheetsCollection_get__newEnum(IHTMLStyleSheetsCollection *iface,
735 IUnknown **p)
737 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
738 HTMLStyleSheetsCollectionEnum *ret;
740 TRACE("(%p)->(%p)\n", This, p);
742 ret = malloc(sizeof(*ret));
743 if(!ret)
744 return E_OUTOFMEMORY;
746 ret->IEnumVARIANT_iface.lpVtbl = &HTMLStyleSheetsCollectionEnumVtbl;
747 ret->ref = 1;
748 ret->iter = 0;
750 HTMLStyleSheetsCollection_AddRef(&This->IHTMLStyleSheetsCollection_iface);
751 ret->col = This;
753 *p = (IUnknown*)&ret->IEnumVARIANT_iface;
754 return S_OK;
757 static HRESULT WINAPI HTMLStyleSheetsCollection_item(IHTMLStyleSheetsCollection *iface,
758 VARIANT *pvarIndex, VARIANT *pvarResult)
760 HTMLStyleSheetsCollection *This = impl_from_IHTMLStyleSheetsCollection(iface);
762 TRACE("(%p)->(%s %p)\n", This, debugstr_variant(pvarIndex), pvarResult);
764 switch(V_VT(pvarIndex)) {
765 case VT_I4: {
766 nsIDOMStyleSheet *nsstylesheet;
767 IHTMLStyleSheet *stylesheet;
768 nsresult nsres;
769 HRESULT hres;
771 TRACE("index=%ld\n", V_I4(pvarIndex));
773 nsres = nsIDOMStyleSheetList_Item(This->nslist, V_I4(pvarIndex), &nsstylesheet);
774 if(NS_FAILED(nsres) || !nsstylesheet) {
775 WARN("Item failed: %08lx\n", nsres);
776 V_VT(pvarResult) = VT_EMPTY;
777 return E_INVALIDARG;
780 hres = create_style_sheet(nsstylesheet, dispex_compat_mode(&This->dispex), &stylesheet);
781 nsIDOMStyleSheet_Release(nsstylesheet);
782 if(FAILED(hres))
783 return hres;
785 V_VT(pvarResult) = VT_DISPATCH;
786 V_DISPATCH(pvarResult) = (IDispatch*)stylesheet;
787 return S_OK;
790 case VT_BSTR:
791 FIXME("id=%s not implemented\n", debugstr_w(V_BSTR(pvarResult)));
792 return E_NOTIMPL;
794 default:
795 WARN("Invalid index %s\n", debugstr_variant(pvarIndex));
798 return E_INVALIDARG;
801 static const IHTMLStyleSheetsCollectionVtbl HTMLStyleSheetsCollectionVtbl = {
802 HTMLStyleSheetsCollection_QueryInterface,
803 HTMLStyleSheetsCollection_AddRef,
804 HTMLStyleSheetsCollection_Release,
805 HTMLStyleSheetsCollection_GetTypeInfoCount,
806 HTMLStyleSheetsCollection_GetTypeInfo,
807 HTMLStyleSheetsCollection_GetIDsOfNames,
808 HTMLStyleSheetsCollection_Invoke,
809 HTMLStyleSheetsCollection_get_length,
810 HTMLStyleSheetsCollection_get__newEnum,
811 HTMLStyleSheetsCollection_item
814 static inline HTMLStyleSheetsCollection *HTMLStyleSheetsCollection_from_DispatchEx(DispatchEx *iface)
816 return CONTAINING_RECORD(iface, HTMLStyleSheetsCollection, dispex);
819 static HRESULT HTMLStyleSheetsCollection_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
821 HTMLStyleSheetsCollection *This = HTMLStyleSheetsCollection_from_DispatchEx(dispex);
822 UINT32 len = 0;
823 DWORD idx = 0;
824 WCHAR *ptr;
826 for(ptr = name; *ptr && is_digit(*ptr); ptr++)
827 idx = idx*10 + (*ptr-'0');
828 if(*ptr)
829 return DISP_E_UNKNOWNNAME;
831 nsIDOMStyleSheetList_GetLength(This->nslist, &len);
832 if(idx >= len)
833 return DISP_E_UNKNOWNNAME;
835 *dispid = MSHTML_DISPID_CUSTOM_MIN + idx;
836 TRACE("ret %lx\n", *dispid);
837 return S_OK;
840 static HRESULT HTMLStyleSheetsCollection_get_name(DispatchEx *dispex, DISPID id, BSTR *name)
842 HTMLStyleSheetsCollection *This = HTMLStyleSheetsCollection_from_DispatchEx(dispex);
843 DWORD idx = id - MSHTML_DISPID_CUSTOM_MIN;
844 UINT32 len = 0;
845 WCHAR buf[11];
847 nsIDOMStyleSheetList_GetLength(This->nslist, &len);
848 if(idx >= len)
849 return DISP_E_MEMBERNOTFOUND;
851 len = swprintf(buf, ARRAY_SIZE(buf), L"%u", idx);
852 return (*name = SysAllocStringLen(buf, len)) ? S_OK : E_OUTOFMEMORY;
855 static HRESULT HTMLStyleSheetsCollection_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
856 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
858 HTMLStyleSheetsCollection *This = HTMLStyleSheetsCollection_from_DispatchEx(dispex);
860 TRACE("(%p)->(%lx %lx %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
862 switch(flags) {
863 case DISPATCH_PROPERTYGET: {
864 nsIDOMStyleSheet *nsstylesheet;
865 IHTMLStyleSheet *stylesheet;
866 nsresult nsres;
867 HRESULT hres;
869 nsres = nsIDOMStyleSheetList_Item(This->nslist, id - MSHTML_DISPID_CUSTOM_MIN, &nsstylesheet);
870 if(NS_FAILED(nsres))
871 return DISP_E_MEMBERNOTFOUND;
872 if(!nsstylesheet) {
873 V_VT(res) = VT_EMPTY;
874 return S_OK;
877 hres = create_style_sheet(nsstylesheet, dispex_compat_mode(&This->dispex), &stylesheet);
878 nsIDOMStyleSheet_Release(nsstylesheet);
879 if(FAILED(hres))
880 return hres;
882 V_VT(res) = VT_DISPATCH;
883 V_DISPATCH(res) = (IDispatch*)stylesheet;
884 break;
887 default:
888 FIXME("unimplemented flags %x\n", flags);
889 return E_NOTIMPL;
892 return S_OK;
895 static const dispex_static_data_vtbl_t HTMLStyleSheetsCollection_dispex_vtbl = {
896 NULL,
897 HTMLStyleSheetsCollection_get_dispid,
898 HTMLStyleSheetsCollection_get_name,
899 HTMLStyleSheetsCollection_invoke
901 static const tid_t HTMLStyleSheetsCollection_iface_tids[] = {
902 IHTMLStyleSheetsCollection_tid,
905 static dispex_static_data_t HTMLStyleSheetsCollection_dispex = {
906 L"StyleSheetList",
907 &HTMLStyleSheetsCollection_dispex_vtbl,
908 DispHTMLStyleSheetsCollection_tid,
909 HTMLStyleSheetsCollection_iface_tids
912 HRESULT create_style_sheet_collection(nsIDOMStyleSheetList *nslist, compat_mode_t compat_mode,
913 IHTMLStyleSheetsCollection **ret)
915 HTMLStyleSheetsCollection *collection;
917 if(!(collection = malloc(sizeof(HTMLStyleSheetsCollection))))
918 return E_OUTOFMEMORY;
920 collection->IHTMLStyleSheetsCollection_iface.lpVtbl = &HTMLStyleSheetsCollectionVtbl;
921 collection->ref = 1;
923 if(nslist)
924 nsIDOMStyleSheetList_AddRef(nslist);
925 collection->nslist = nslist;
927 init_dispatch(&collection->dispex, (IUnknown*)&collection->IHTMLStyleSheetsCollection_iface,
928 &HTMLStyleSheetsCollection_dispex, compat_mode);
930 *ret = &collection->IHTMLStyleSheetsCollection_iface;
931 return S_OK;
934 static inline HTMLStyleSheet *impl_from_IHTMLStyleSheet(IHTMLStyleSheet *iface)
936 return CONTAINING_RECORD(iface, HTMLStyleSheet, IHTMLStyleSheet_iface);
939 static HRESULT WINAPI HTMLStyleSheet_QueryInterface(IHTMLStyleSheet *iface, REFIID riid, void **ppv)
941 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
943 TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
945 if(IsEqualGUID(&IID_IUnknown, riid)) {
946 *ppv = &This->IHTMLStyleSheet_iface;
947 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
948 *ppv = &This->IHTMLStyleSheet_iface;
949 }else if(IsEqualGUID(&IID_IHTMLStyleSheet, riid)) {
950 *ppv = &This->IHTMLStyleSheet_iface;
951 }else if(IsEqualGUID(&IID_IHTMLStyleSheet4, riid)) {
952 *ppv = &This->IHTMLStyleSheet4_iface;
953 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
954 return *ppv ? S_OK : E_NOINTERFACE;
955 }else {
956 *ppv = NULL;
957 WARN("unsupported %s\n", debugstr_mshtml_guid(riid));
958 return E_NOINTERFACE;
961 IUnknown_AddRef((IUnknown*)*ppv);
962 return S_OK;
965 static ULONG WINAPI HTMLStyleSheet_AddRef(IHTMLStyleSheet *iface)
967 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
968 LONG ref = InterlockedIncrement(&This->ref);
970 TRACE("(%p) ref=%ld\n", This, ref);
972 return ref;
975 static ULONG WINAPI HTMLStyleSheet_Release(IHTMLStyleSheet *iface)
977 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
978 LONG ref = InterlockedDecrement(&This->ref);
980 TRACE("(%p) ref=%ld\n", This, ref);
982 if(!ref) {
983 release_dispex(&This->dispex);
984 if(This->nsstylesheet)
985 nsIDOMCSSStyleSheet_Release(This->nsstylesheet);
986 free(This);
989 return ref;
992 static HRESULT WINAPI HTMLStyleSheet_GetTypeInfoCount(IHTMLStyleSheet *iface, UINT *pctinfo)
994 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
995 TRACE("(%p)->(%p)\n", This, pctinfo);
996 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
999 static HRESULT WINAPI HTMLStyleSheet_GetTypeInfo(IHTMLStyleSheet *iface, UINT iTInfo,
1000 LCID lcid, ITypeInfo **ppTInfo)
1002 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1003 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1006 static HRESULT WINAPI HTMLStyleSheet_GetIDsOfNames(IHTMLStyleSheet *iface, REFIID riid,
1007 LPOLESTR *rgszNames, UINT cNames,
1008 LCID lcid, DISPID *rgDispId)
1010 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1011 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames, lcid, rgDispId);
1014 static HRESULT WINAPI HTMLStyleSheet_Invoke(IHTMLStyleSheet *iface, DISPID dispIdMember,
1015 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1016 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1018 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1019 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags, pDispParams,
1020 pVarResult, pExcepInfo, puArgErr);
1023 static HRESULT WINAPI HTMLStyleSheet_put_title(IHTMLStyleSheet *iface, BSTR v)
1025 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1026 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
1027 return E_NOTIMPL;
1030 static HRESULT WINAPI HTMLStyleSheet_get_title(IHTMLStyleSheet *iface, BSTR *p)
1032 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1033 FIXME("(%p)->(%p)\n", This, p);
1034 return E_NOTIMPL;
1037 static HRESULT WINAPI HTMLStyleSheet_get_parentStyleSheet(IHTMLStyleSheet *iface,
1038 IHTMLStyleSheet **p)
1040 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1041 FIXME("(%p)->(%p)\n", This, p);
1042 return E_NOTIMPL;
1045 static HRESULT WINAPI HTMLStyleSheet_get_owningElement(IHTMLStyleSheet *iface, IHTMLElement **p)
1047 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1048 FIXME("(%p)->(%p)\n", This, p);
1049 return E_NOTIMPL;
1052 static HRESULT WINAPI HTMLStyleSheet_put_disabled(IHTMLStyleSheet *iface, VARIANT_BOOL v)
1054 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1055 FIXME("(%p)->(%x)\n", This, v);
1056 return E_NOTIMPL;
1059 static HRESULT WINAPI HTMLStyleSheet_get_disabled(IHTMLStyleSheet *iface, VARIANT_BOOL *p)
1061 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1062 FIXME("(%p)->(%p)\n", This, p);
1063 return E_NOTIMPL;
1066 static HRESULT WINAPI HTMLStyleSheet_get_readOnly(IHTMLStyleSheet *iface, VARIANT_BOOL *p)
1068 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1069 FIXME("(%p)->(%p)\n", This, p);
1070 return E_NOTIMPL;
1073 static HRESULT WINAPI HTMLStyleSheet_get_imports(IHTMLStyleSheet *iface,
1074 IHTMLStyleSheetsCollection **p)
1076 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1077 FIXME("(%p)->(%p)\n", This, p);
1078 return E_NOTIMPL;
1081 static HRESULT WINAPI HTMLStyleSheet_put_href(IHTMLStyleSheet *iface, BSTR v)
1083 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1084 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
1085 return E_NOTIMPL;
1088 static HRESULT WINAPI HTMLStyleSheet_get_href(IHTMLStyleSheet *iface, BSTR *p)
1090 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1091 nsAString href_str;
1092 nsresult nsres;
1094 TRACE("(%p)->(%p)\n", This, p);
1096 nsAString_Init(&href_str, NULL);
1097 nsres = nsIDOMCSSStyleSheet_GetHref(This->nsstylesheet, &href_str);
1098 return return_nsstr(nsres, &href_str, p);
1101 static HRESULT WINAPI HTMLStyleSheet_get_type(IHTMLStyleSheet *iface, BSTR *p)
1103 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1104 FIXME("(%p)->(%p)\n", This, p);
1105 return E_NOTIMPL;
1108 static HRESULT WINAPI HTMLStyleSheet_get_id(IHTMLStyleSheet *iface, BSTR *p)
1110 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1111 FIXME("(%p)->(%p)\n", This, p);
1112 return E_NOTIMPL;
1115 static HRESULT WINAPI HTMLStyleSheet_addImport(IHTMLStyleSheet *iface, BSTR bstrURL,
1116 LONG lIndex, LONG *plIndex)
1118 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1119 FIXME("(%p)->(%s %ld %p)\n", This, debugstr_w(bstrURL), lIndex, plIndex);
1120 return E_NOTIMPL;
1123 static HRESULT WINAPI HTMLStyleSheet_addRule(IHTMLStyleSheet *iface, BSTR bstrSelector,
1124 BSTR bstrStyle, LONG lIndex, LONG *plIndex)
1126 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1127 const WCHAR format[] = L"%s {%s}";
1128 nsIDOMCSSRuleList *nslist = NULL;
1129 UINT32 length, new_index;
1130 nsAString nsstr;
1131 nsresult nsres;
1132 WCHAR *rule;
1133 size_t len;
1135 TRACE("(%p)->(%s %s %ld %p)\n", This, debugstr_w(bstrSelector), debugstr_w(bstrStyle),
1136 lIndex, plIndex);
1138 if(!bstrSelector || !bstrStyle || !bstrSelector[0] || !bstrStyle[0])
1139 return E_INVALIDARG;
1141 nsres = nsIDOMCSSStyleSheet_GetCssRules(This->nsstylesheet, &nslist);
1142 if(NS_FAILED(nsres))
1143 return E_FAIL;
1144 nsIDOMCSSRuleList_GetLength(nslist, &length);
1146 if(lIndex > length)
1147 lIndex = length;
1149 len = ARRAY_SIZE(format) - 4 /* %s twice */ + wcslen(bstrSelector) + wcslen(bstrStyle);
1150 if(!(rule = malloc(len * sizeof(WCHAR))))
1151 return E_OUTOFMEMORY;
1152 swprintf(rule, len, format, bstrSelector, bstrStyle);
1154 nsAString_InitDepend(&nsstr, rule);
1155 nsres = nsIDOMCSSStyleSheet_InsertRule(This->nsstylesheet, &nsstr, lIndex, &new_index);
1156 if(NS_FAILED(nsres)) WARN("failed: %08lx\n", nsres);
1157 nsAString_Finish(&nsstr);
1158 free(rule);
1160 *plIndex = new_index;
1161 return map_nsresult(nsres);
1164 static HRESULT WINAPI HTMLStyleSheet_removeImport(IHTMLStyleSheet *iface, LONG lIndex)
1166 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1167 FIXME("(%p)->(%ld)\n", This, lIndex);
1168 return E_NOTIMPL;
1171 static HRESULT WINAPI HTMLStyleSheet_removeRule(IHTMLStyleSheet *iface, LONG lIndex)
1173 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1174 FIXME("(%p)->(%ld)\n", This, lIndex);
1175 return E_NOTIMPL;
1178 static HRESULT WINAPI HTMLStyleSheet_put_media(IHTMLStyleSheet *iface, BSTR v)
1180 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1181 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
1182 return E_NOTIMPL;
1185 static HRESULT WINAPI HTMLStyleSheet_get_media(IHTMLStyleSheet *iface, BSTR *p)
1187 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1188 FIXME("(%p)->(%p)\n", This, p);
1189 return E_NOTIMPL;
1192 static HRESULT WINAPI HTMLStyleSheet_put_cssText(IHTMLStyleSheet *iface, BSTR v)
1194 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1195 nsresult nsres;
1197 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1199 do {
1200 nsres = nsIDOMCSSStyleSheet_DeleteRule(This->nsstylesheet, 0);
1201 }while(NS_SUCCEEDED(nsres));
1203 if(v && *v) {
1204 nsAString nsstr;
1205 UINT32 idx;
1207 /* FIXME: This won't work for multiple rules in the string. */
1208 nsAString_InitDepend(&nsstr, v);
1209 nsres = nsIDOMCSSStyleSheet_InsertRule(This->nsstylesheet, &nsstr, 0, &idx);
1210 nsAString_Finish(&nsstr);
1211 if(NS_FAILED(nsres)) {
1212 FIXME("InsertRule failed for string %s. Probably multiple rules passed.\n", debugstr_w(v));
1213 return E_FAIL;
1217 return S_OK;
1220 static HRESULT WINAPI HTMLStyleSheet_get_cssText(IHTMLStyleSheet *iface, BSTR *p)
1222 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1223 nsIDOMCSSRuleList *nslist = NULL;
1224 nsIDOMCSSRule *nsrule;
1225 nsAString nsstr;
1226 UINT32 len;
1227 nsresult nsres;
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 nsres = nsIDOMCSSRuleList_GetLength(nslist, &len);
1238 assert(nsres == NS_OK);
1240 if(len) {
1241 nsres = nsIDOMCSSRuleList_Item(nslist, 0, &nsrule);
1242 if(NS_FAILED(nsres))
1243 ERR("Item failed: %08lx\n", nsres);
1246 nsIDOMCSSRuleList_Release(nslist);
1247 if(NS_FAILED(nsres))
1248 return E_FAIL;
1250 if(!len) {
1251 *p = NULL;
1252 return S_OK;
1255 nsAString_Init(&nsstr, NULL);
1256 nsres = nsIDOMCSSRule_GetCssText(nsrule, &nsstr);
1257 nsIDOMCSSRule_Release(nsrule);
1258 return return_nsstr(nsres, &nsstr, p);
1261 static HRESULT WINAPI HTMLStyleSheet_get_rules(IHTMLStyleSheet *iface,
1262 IHTMLStyleSheetRulesCollection **p)
1264 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
1265 nsIDOMCSSRuleList *nslist = NULL;
1266 nsresult nsres;
1267 HRESULT hres;
1269 TRACE("(%p)->(%p)\n", This, p);
1271 nsres = nsIDOMCSSStyleSheet_GetCssRules(This->nsstylesheet, &nslist);
1272 if(NS_FAILED(nsres)) {
1273 ERR("GetCssRules failed: %08lx\n", nsres);
1274 return E_FAIL;
1277 hres = create_style_sheet_rules_collection(nslist, dispex_compat_mode(&This->dispex), p);
1278 nsIDOMCSSRuleList_Release(nslist);
1279 return hres;
1282 static const IHTMLStyleSheetVtbl HTMLStyleSheetVtbl = {
1283 HTMLStyleSheet_QueryInterface,
1284 HTMLStyleSheet_AddRef,
1285 HTMLStyleSheet_Release,
1286 HTMLStyleSheet_GetTypeInfoCount,
1287 HTMLStyleSheet_GetTypeInfo,
1288 HTMLStyleSheet_GetIDsOfNames,
1289 HTMLStyleSheet_Invoke,
1290 HTMLStyleSheet_put_title,
1291 HTMLStyleSheet_get_title,
1292 HTMLStyleSheet_get_parentStyleSheet,
1293 HTMLStyleSheet_get_owningElement,
1294 HTMLStyleSheet_put_disabled,
1295 HTMLStyleSheet_get_disabled,
1296 HTMLStyleSheet_get_readOnly,
1297 HTMLStyleSheet_get_imports,
1298 HTMLStyleSheet_put_href,
1299 HTMLStyleSheet_get_href,
1300 HTMLStyleSheet_get_type,
1301 HTMLStyleSheet_get_id,
1302 HTMLStyleSheet_addImport,
1303 HTMLStyleSheet_addRule,
1304 HTMLStyleSheet_removeImport,
1305 HTMLStyleSheet_removeRule,
1306 HTMLStyleSheet_put_media,
1307 HTMLStyleSheet_get_media,
1308 HTMLStyleSheet_put_cssText,
1309 HTMLStyleSheet_get_cssText,
1310 HTMLStyleSheet_get_rules
1313 static inline HTMLStyleSheet *impl_from_IHTMLStyleSheet4(IHTMLStyleSheet4 *iface)
1315 return CONTAINING_RECORD(iface, HTMLStyleSheet, IHTMLStyleSheet4_iface);
1318 static HRESULT WINAPI HTMLStyleSheet4_QueryInterface(IHTMLStyleSheet4 *iface, REFIID riid, void **ppv)
1320 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1321 return IHTMLStyleSheet_QueryInterface(&This->IHTMLStyleSheet_iface, riid, ppv);
1324 static ULONG WINAPI HTMLStyleSheet4_AddRef(IHTMLStyleSheet4 *iface)
1326 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1327 return IHTMLStyleSheet_AddRef(&This->IHTMLStyleSheet_iface);
1330 static ULONG WINAPI HTMLStyleSheet4_Release(IHTMLStyleSheet4 *iface)
1332 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1333 return IHTMLStyleSheet_Release(&This->IHTMLStyleSheet_iface);
1336 static HRESULT WINAPI HTMLStyleSheet4_GetTypeInfoCount(IHTMLStyleSheet4 *iface, UINT *pctinfo)
1338 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1339 TRACE("(%p)->(%p)\n", This, pctinfo);
1340 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
1343 static HRESULT WINAPI HTMLStyleSheet4_GetTypeInfo(IHTMLStyleSheet4 *iface, UINT iTInfo,
1344 LCID lcid, ITypeInfo **ppTInfo)
1346 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1347 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1350 static HRESULT WINAPI HTMLStyleSheet4_GetIDsOfNames(IHTMLStyleSheet4 *iface, REFIID riid,
1351 LPOLESTR *rgszNames, UINT cNames,
1352 LCID lcid, DISPID *rgDispId)
1354 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1355 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames, lcid, rgDispId);
1358 static HRESULT WINAPI HTMLStyleSheet4_Invoke(IHTMLStyleSheet4 *iface, DISPID dispIdMember,
1359 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1360 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1362 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1363 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags, pDispParams,
1364 pVarResult, pExcepInfo, puArgErr);
1367 static HRESULT WINAPI HTMLStyleSheet4_get_type(IHTMLStyleSheet4 *iface, BSTR *p)
1369 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1370 TRACE("(%p)->(%p)\n", This, p);
1371 return IHTMLStyleSheet_get_type(&This->IHTMLStyleSheet_iface, p);
1374 static HRESULT WINAPI HTMLStyleSheet4_get_href(IHTMLStyleSheet4 *iface, VARIANT *p)
1376 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1377 nsAString href_str;
1378 nsresult nsres;
1380 TRACE("(%p)->(%p)\n", This, p);
1382 nsAString_Init(&href_str, NULL);
1383 nsres = nsIDOMCSSStyleSheet_GetHref(This->nsstylesheet, &href_str);
1384 return return_nsstr_variant(nsres, &href_str, 0, p);
1387 static HRESULT WINAPI HTMLStyleSheet4_get_title(IHTMLStyleSheet4 *iface, BSTR *p)
1389 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1390 FIXME("(%p)->(%p)\n", This, p);
1391 return E_NOTIMPL;
1394 static HRESULT WINAPI HTMLStyleSheet4_get_ownerNode(IHTMLStyleSheet4 *iface, IHTMLElement **p)
1396 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1397 FIXME("(%p)->(%p)\n", This, p);
1398 return E_NOTIMPL;
1401 static HRESULT WINAPI HTMLStyleSheet4_get_ownerRule(IHTMLStyleSheet4 *iface, IHTMLCSSRule **p)
1403 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1404 FIXME("(%p)->(%p)\n", This, p);
1405 return E_NOTIMPL;
1408 static HRESULT WINAPI HTMLStyleSheet4_get_cssRules(IHTMLStyleSheet4 *iface, IHTMLStyleSheetRulesCollection **p)
1410 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1411 TRACE("(%p)->(%p)\n", This, p);
1412 return IHTMLStyleSheet_get_rules(&This->IHTMLStyleSheet_iface, p);
1415 static HRESULT WINAPI HTMLStyleSheet4_get_media(IHTMLStyleSheet4 *iface, VARIANT *p)
1417 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1418 FIXME("(%p)->(%p)\n", This, p);
1419 return E_NOTIMPL;
1422 static HRESULT WINAPI HTMLStyleSheet4_insertRule(IHTMLStyleSheet4 *iface, BSTR rule, LONG index, LONG *p)
1424 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1425 UINT32 new_index = 0;
1426 nsAString nsstr;
1427 nsresult nsres;
1429 TRACE("(%p)->(%s %ld %p)\n", This, debugstr_w(rule), index, p);
1431 nsAString_InitDepend(&nsstr, rule);
1432 nsres = nsIDOMCSSStyleSheet_InsertRule(This->nsstylesheet, &nsstr, index, &new_index);
1433 if(NS_FAILED(nsres)) WARN("failed: %08lx\n", nsres);
1434 nsAString_Finish(&nsstr);
1435 *p = new_index;
1436 return map_nsresult(nsres);
1439 static HRESULT WINAPI HTMLStyleSheet4_deleteRule(IHTMLStyleSheet4 *iface, LONG index)
1441 HTMLStyleSheet *This = impl_from_IHTMLStyleSheet4(iface);
1442 FIXME("(%p)->(%ld)\n", This, index);
1443 return E_NOTIMPL;
1446 static const IHTMLStyleSheet4Vtbl HTMLStyleSheet4Vtbl = {
1447 HTMLStyleSheet4_QueryInterface,
1448 HTMLStyleSheet4_AddRef,
1449 HTMLStyleSheet4_Release,
1450 HTMLStyleSheet4_GetTypeInfoCount,
1451 HTMLStyleSheet4_GetTypeInfo,
1452 HTMLStyleSheet4_GetIDsOfNames,
1453 HTMLStyleSheet4_Invoke,
1454 HTMLStyleSheet4_get_type,
1455 HTMLStyleSheet4_get_href,
1456 HTMLStyleSheet4_get_title,
1457 HTMLStyleSheet4_get_ownerNode,
1458 HTMLStyleSheet4_get_ownerRule,
1459 HTMLStyleSheet4_get_cssRules,
1460 HTMLStyleSheet4_get_media,
1461 HTMLStyleSheet4_insertRule,
1462 HTMLStyleSheet4_deleteRule,
1465 static void HTMLStyleSheet_init_dispex_info(dispex_data_t *info, compat_mode_t mode)
1467 if(mode >= COMPAT_MODE_IE9)
1468 dispex_info_add_interface(info, IHTMLStyleSheet4_tid, NULL);
1471 static const tid_t HTMLStyleSheet_iface_tids[] = {
1472 IHTMLStyleSheet_tid,
1475 static dispex_static_data_t HTMLStyleSheet_dispex = {
1476 L"CSSStyleSheet",
1477 NULL,
1478 DispHTMLStyleSheet_tid,
1479 HTMLStyleSheet_iface_tids,
1480 HTMLStyleSheet_init_dispex_info
1483 HRESULT create_style_sheet(nsIDOMStyleSheet *nsstylesheet, compat_mode_t compat_mode, IHTMLStyleSheet **ret)
1485 HTMLStyleSheet *style_sheet;
1486 nsresult nsres;
1488 if(!(style_sheet = malloc(sizeof(HTMLStyleSheet))))
1489 return E_OUTOFMEMORY;
1491 style_sheet->IHTMLStyleSheet_iface.lpVtbl = &HTMLStyleSheetVtbl;
1492 style_sheet->IHTMLStyleSheet4_iface.lpVtbl = &HTMLStyleSheet4Vtbl;
1493 style_sheet->ref = 1;
1494 style_sheet->nsstylesheet = NULL;
1496 init_dispatch(&style_sheet->dispex, (IUnknown*)&style_sheet->IHTMLStyleSheet_iface,
1497 &HTMLStyleSheet_dispex, compat_mode);
1499 if(nsstylesheet) {
1500 nsres = nsIDOMStyleSheet_QueryInterface(nsstylesheet, &IID_nsIDOMCSSStyleSheet,
1501 (void**)&style_sheet->nsstylesheet);
1502 if(NS_FAILED(nsres))
1503 ERR("Could not get nsICSSStyleSheet interface: %08lx\n", nsres);
1506 *ret = &style_sheet->IHTMLStyleSheet_iface;
1507 return S_OK;