htmlstyleelem.c 15.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
/*
 * Copyright 2010 Jacek Caban for CodeWeavers
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include <stdarg.h>

#define COBJMACROS

#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "winreg.h"
#include "ole2.h"

#include "wine/debug.h"

#include "mshtml_private.h"
32
#include "mshtmdid.h"
33 34 35

WINE_DEFAULT_DEBUG_CHANNEL(mshtml);

36
struct HTMLStyleElement {
37 38
    HTMLElement element;

39
    IHTMLStyleElement IHTMLStyleElement_iface;
40
    IHTMLStyleElement2 IHTMLStyleElement2_iface;
41 42

    nsIDOMHTMLStyleElement *nsstyle;
43
    IHTMLStyleSheet *style_sheet;
44
};
45

46 47 48 49
static inline HTMLStyleElement *impl_from_IHTMLStyleElement(IHTMLStyleElement *iface)
{
    return CONTAINING_RECORD(iface, HTMLStyleElement, IHTMLStyleElement_iface);
}
50 51 52 53

static HRESULT WINAPI HTMLStyleElement_QueryInterface(IHTMLStyleElement *iface,
        REFIID riid, void **ppv)
{
54
    HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
55

56
    return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
57 58 59 60
}

static ULONG WINAPI HTMLStyleElement_AddRef(IHTMLStyleElement *iface)
{
61
    HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
62

63
    return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
64 65 66 67
}

static ULONG WINAPI HTMLStyleElement_Release(IHTMLStyleElement *iface)
{
68
    HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
69

70
    return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
71 72 73 74
}

static HRESULT WINAPI HTMLStyleElement_GetTypeInfoCount(IHTMLStyleElement *iface, UINT *pctinfo)
{
75
    HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
76
    return IDispatchEx_GetTypeInfoCount(&This->element.node.event_target.dispex.IDispatchEx_iface, pctinfo);
77 78 79 80 81
}

static HRESULT WINAPI HTMLStyleElement_GetTypeInfo(IHTMLStyleElement *iface, UINT iTInfo,
        LCID lcid, ITypeInfo **ppTInfo)
{
82
    HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
83
    return IDispatchEx_GetTypeInfo(&This->element.node.event_target.dispex.IDispatchEx_iface, iTInfo, lcid,
84
            ppTInfo);
85 86 87 88 89
}

static HRESULT WINAPI HTMLStyleElement_GetIDsOfNames(IHTMLStyleElement *iface, REFIID riid,
        LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
{
90
    HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
91
    return IDispatchEx_GetIDsOfNames(&This->element.node.event_target.dispex.IDispatchEx_iface, riid, rgszNames,
92
            cNames, lcid, rgDispId);
93 94 95 96 97 98
}

static HRESULT WINAPI HTMLStyleElement_Invoke(IHTMLStyleElement *iface, DISPID dispIdMember,
        REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
        VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
99
    HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
100
    return IDispatchEx_Invoke(&This->element.node.event_target.dispex.IDispatchEx_iface, dispIdMember, riid,
101
            lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
102 103 104 105
}

static HRESULT WINAPI HTMLStyleElement_put_type(IHTMLStyleElement *iface, BSTR v)
{
106
    HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
107 108 109 110 111 112 113 114 115
    nsAString type_str;
    nsresult nsres;

    TRACE("(%p)->(%s)\n", This, debugstr_w(v));

    nsAString_InitDepend(&type_str, v);
    nsres = nsIDOMHTMLStyleElement_SetType(This->nsstyle, &type_str);
    nsAString_Finish(&type_str);
    if(NS_FAILED(nsres)) {
116
        ERR("SetType failed: %08lx\n", nsres);
117 118 119 120
        return E_FAIL;
    }

    return S_OK;
121 122 123 124
}

static HRESULT WINAPI HTMLStyleElement_get_type(IHTMLStyleElement *iface, BSTR *p)
{
125
    HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
126 127 128 129 130 131 132 133
    nsAString nsstr;
    nsresult nsres;

    TRACE("(%p)->(%p)\n", This, p);

    nsAString_Init(&nsstr, NULL);
    nsres = nsIDOMHTMLStyleElement_GetType(This->nsstyle, &nsstr);
    return return_nsstr(nsres, &nsstr, p);
134 135 136 137
}

static HRESULT WINAPI HTMLStyleElement_get_readyState(IHTMLStyleElement *iface, BSTR *p)
{
138
    HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
139 140 141 142 143 144
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLStyleElement_put_onreadystatechange(IHTMLStyleElement *iface, VARIANT v)
{
145
    HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
146 147 148 149 150 151
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLStyleElement_get_onreadystatechange(IHTMLStyleElement *iface, VARIANT *p)
{
152
    HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
153 154 155 156 157 158
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLStyleElement_put_onload(IHTMLStyleElement *iface, VARIANT v)
{
159
    HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
160 161
    TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
    return IHTMLElement6_put_onload(&This->element.IHTMLElement6_iface, v);
162 163 164 165
}

static HRESULT WINAPI HTMLStyleElement_get_onload(IHTMLStyleElement *iface, VARIANT *p)
{
166
    HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
167 168
    TRACE("(%p)->(%p)\n", This, p);
    return IHTMLElement6_get_onload(&This->element.IHTMLElement6_iface, p);
169 170 171 172
}

static HRESULT WINAPI HTMLStyleElement_put_onerror(IHTMLStyleElement *iface, VARIANT v)
{
173
    HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
174 175
    TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
    return IHTMLElement6_put_onerror(&This->element.IHTMLElement6_iface, v);
176 177 178 179
}

static HRESULT WINAPI HTMLStyleElement_get_onerror(IHTMLStyleElement *iface, VARIANT *p)
{
180
    HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
181 182
    TRACE("(%p)->(%p)\n", This, p);
    return IHTMLElement6_get_onerror(&This->element.IHTMLElement6_iface, p);
183 184 185 186
}

static HRESULT WINAPI HTMLStyleElement_get_styleSheet(IHTMLStyleElement *iface, IHTMLStyleSheet **p)
{
187
    HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
188 189 190 191 192 193 194 195 196 197 198 199 200 201

    TRACE("(%p)->(%p)\n", This, p);

    if(!This->nsstyle)
        return E_FAIL;

    if(!This->style_sheet) {
        nsIDOMStyleSheet *ss;
        nsresult nsres;

        nsres = nsIDOMHTMLStyleElement_GetDOMStyleSheet(This->nsstyle, &ss);
        assert(nsres == NS_OK);

        if(ss) {
202 203
            HRESULT hres = create_style_sheet(ss, dispex_compat_mode(&This->element.node.event_target.dispex),
                                              &This->style_sheet);
204
            nsIDOMStyleSheet_Release(ss);
205 206
            if(FAILED(hres))
                return hres;
207 208 209 210 211 212 213
        }
    }

    if(This->style_sheet)
        IHTMLStyleSheet_AddRef(This->style_sheet);
    *p = This->style_sheet;
    return S_OK;
214 215 216 217
}

static HRESULT WINAPI HTMLStyleElement_put_disabled(IHTMLStyleElement *iface, VARIANT_BOOL v)
{
218
    HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
219 220 221 222 223 224
    FIXME("(%p)->(%x)\n", This, v);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLStyleElement_get_disabled(IHTMLStyleElement *iface, VARIANT_BOOL *p)
{
225
    HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
226 227 228 229 230 231
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLStyleElement_put_media(IHTMLStyleElement *iface, BSTR v)
{
232
    HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
233 234 235 236 237 238 239 240 241
    nsAString media_str;
    nsresult nsres;

    TRACE("(%p)->(%s)\n", This, debugstr_w(v));

    nsAString_InitDepend(&media_str, v);
    nsres = nsIDOMHTMLStyleElement_SetMedia(This->nsstyle, &media_str);
    nsAString_Finish(&media_str);
    if(NS_FAILED(nsres)) {
242
        ERR("SetMedia failed: %08lx\n", nsres);
243 244 245 246
        return E_FAIL;
    }

    return S_OK;
247 248 249 250
}

static HRESULT WINAPI HTMLStyleElement_get_media(IHTMLStyleElement *iface, BSTR *p)
{
251
    HTMLStyleElement *This = impl_from_IHTMLStyleElement(iface);
252 253 254 255 256 257 258 259
    nsAString nsstr;
    nsresult nsres;

    TRACE("(%p)->(%p)\n", This, p);

    nsAString_Init(&nsstr, NULL);
    nsres = nsIDOMHTMLStyleElement_GetMedia(This->nsstyle, &nsstr);
    return return_nsstr(nsres, &nsstr, p);
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
}

static const IHTMLStyleElementVtbl HTMLStyleElementVtbl = {
    HTMLStyleElement_QueryInterface,
    HTMLStyleElement_AddRef,
    HTMLStyleElement_Release,
    HTMLStyleElement_GetTypeInfoCount,
    HTMLStyleElement_GetTypeInfo,
    HTMLStyleElement_GetIDsOfNames,
    HTMLStyleElement_Invoke,
    HTMLStyleElement_put_type,
    HTMLStyleElement_get_type,
    HTMLStyleElement_get_readyState,
    HTMLStyleElement_put_onreadystatechange,
    HTMLStyleElement_get_onreadystatechange,
    HTMLStyleElement_put_onload,
    HTMLStyleElement_get_onload,
    HTMLStyleElement_put_onerror,
    HTMLStyleElement_get_onerror,
    HTMLStyleElement_get_styleSheet,
    HTMLStyleElement_put_disabled,
    HTMLStyleElement_get_disabled,
    HTMLStyleElement_put_media,
    HTMLStyleElement_get_media
};

286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
static inline HTMLStyleElement *impl_from_IHTMLStyleElement2(IHTMLStyleElement2 *iface)
{
    return CONTAINING_RECORD(iface, HTMLStyleElement, IHTMLStyleElement2_iface);
}

static HRESULT WINAPI HTMLStyleElement2_QueryInterface(IHTMLStyleElement2 *iface,
                                                       REFIID riid, void **ppv)
{
    HTMLStyleElement *This = impl_from_IHTMLStyleElement2(iface);

    return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
}

static ULONG WINAPI HTMLStyleElement2_AddRef(IHTMLStyleElement2 *iface)
{
    HTMLStyleElement *This = impl_from_IHTMLStyleElement2(iface);

    return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
}

static ULONG WINAPI HTMLStyleElement2_Release(IHTMLStyleElement2 *iface)
{
    HTMLStyleElement *This = impl_from_IHTMLStyleElement2(iface);

    return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
}

static HRESULT WINAPI HTMLStyleElement2_GetTypeInfoCount(IHTMLStyleElement2 *iface, UINT *pctinfo)
{
    HTMLStyleElement *This = impl_from_IHTMLStyleElement2(iface);
    return IDispatchEx_GetTypeInfoCount(&This->element.node.event_target.dispex.IDispatchEx_iface, pctinfo);
}

static HRESULT WINAPI HTMLStyleElement2_GetTypeInfo(IHTMLStyleElement2 *iface, UINT iTInfo,
                                                    LCID lcid, ITypeInfo **ppTInfo)
{
    HTMLStyleElement *This = impl_from_IHTMLStyleElement2(iface);
    return IDispatchEx_GetTypeInfo(&This->element.node.event_target.dispex.IDispatchEx_iface, iTInfo, lcid,
                                   ppTInfo);
}

static HRESULT WINAPI HTMLStyleElement2_GetIDsOfNames(IHTMLStyleElement2 *iface, REFIID riid,
        LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
{
    HTMLStyleElement *This = impl_from_IHTMLStyleElement2(iface);
    return IDispatchEx_GetIDsOfNames(&This->element.node.event_target.dispex.IDispatchEx_iface, riid, rgszNames,
                                     cNames, lcid, rgDispId);
}

static HRESULT WINAPI HTMLStyleElement2_Invoke(IHTMLStyleElement2 *iface, DISPID dispIdMember,
        REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
        VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
    HTMLStyleElement *This = impl_from_IHTMLStyleElement2(iface);
    return IDispatchEx_Invoke(&This->element.node.event_target.dispex.IDispatchEx_iface, dispIdMember, riid,
                              lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
}

static HRESULT WINAPI HTMLStyleElement2_get_sheet(IHTMLStyleElement2 *iface, IHTMLStyleSheet **p)
{
    HTMLStyleElement *This = impl_from_IHTMLStyleElement2(iface);
    TRACE("(%p)->(%p)\n", This, p);
    return IHTMLStyleElement_get_styleSheet(&This->IHTMLStyleElement_iface, p);
}

static const IHTMLStyleElement2Vtbl HTMLStyleElement2Vtbl = {
    HTMLStyleElement2_QueryInterface,
    HTMLStyleElement2_AddRef,
    HTMLStyleElement2_Release,
    HTMLStyleElement2_GetTypeInfoCount,
    HTMLStyleElement2_GetTypeInfo,
    HTMLStyleElement2_GetIDsOfNames,
    HTMLStyleElement2_Invoke,
    HTMLStyleElement2_get_sheet
};

362 363 364 365
static inline HTMLStyleElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
{
    return CONTAINING_RECORD(iface, HTMLStyleElement, element.node);
}
366 367 368

static HRESULT HTMLStyleElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
{
369
    HTMLStyleElement *This = impl_from_HTMLDOMNode(iface);
370 371 372

    if(IsEqualGUID(&IID_IUnknown, riid)) {
        TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
373
        *ppv = &This->IHTMLStyleElement_iface;
374 375
    }else if(IsEqualGUID(&IID_IDispatch, riid)) {
        TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
376
        *ppv = &This->IHTMLStyleElement_iface;
377 378
    }else if(IsEqualGUID(&IID_IHTMLStyleElement, riid)) {
        TRACE("(%p)->(IID_IHTMLStyleElement %p)\n", This, ppv);
379
        *ppv = &This->IHTMLStyleElement_iface;
380 381 382
    }else if(IsEqualGUID(&IID_IHTMLStyleElement2, riid)) {
        TRACE("(%p)->(IID_IHTMLStyleElement2 %p)\n", This, ppv);
        *ppv = &This->IHTMLStyleElement2_iface;
383 384 385 386 387 388 389 390
    }else {
        return HTMLElement_QI(&This->element.node, riid, ppv);
    }

    IUnknown_AddRef((IUnknown*)*ppv);
    return S_OK;
}

391 392 393 394 395 396 397 398 399 400 401 402
static void HTMLStyleElement_destructor(HTMLDOMNode *iface)
{
    HTMLStyleElement *This = impl_from_HTMLDOMNode(iface);

    if(This->style_sheet) {
        IHTMLStyleSheet_Release(This->style_sheet);
        This->style_sheet = NULL;
    }

    HTMLElement_destructor(iface);
}

403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
static void HTMLStyleElement_traverse(HTMLDOMNode *iface, nsCycleCollectionTraversalCallback *cb)
{
    HTMLStyleElement *This = impl_from_HTMLDOMNode(iface);

    if(This->nsstyle)
        note_cc_edge((nsISupports*)This->nsstyle, "This->nsstyle", cb);
}

static void HTMLStyleElement_unlink(HTMLDOMNode *iface)
{
    HTMLStyleElement *This = impl_from_HTMLDOMNode(iface);

    if(This->nsstyle) {
        nsIDOMHTMLStyleElement *nsstyle = This->nsstyle;

        This->nsstyle = NULL;
        nsIDOMHTMLStyleElement_Release(nsstyle);
    }
}

423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
static void HTMLStyleElement_init_dispex_info(dispex_data_t *info, compat_mode_t mode)
{
    static const dispex_hook_t ie11_hooks[] = {
        {DISPID_IHTMLSTYLEELEMENT_READYSTATE, NULL},
        {DISPID_IHTMLSTYLEELEMENT_STYLESHEET, NULL},
        {DISPID_UNKNOWN}
    };

    HTMLElement_init_dispex_info(info, mode);

    dispex_info_add_interface(info, IHTMLStyleElement_tid,
                              mode >= COMPAT_MODE_IE11 ? ie11_hooks : NULL);

    if(mode >= COMPAT_MODE_IE9)
        dispex_info_add_interface(info, IHTMLStyleElement2_tid, NULL);
}

440
static const NodeImplVtbl HTMLStyleElementImplVtbl = {
441
    &CLSID_HTMLStyleElement,
442
    HTMLStyleElement_QI,
443
    HTMLStyleElement_destructor,
444
    HTMLElement_cpc,
445
    HTMLElement_clone,
446
    HTMLElement_handle_event,
447 448 449 450 451 452 453 454 455 456 457
    HTMLElement_get_attr_col,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    HTMLStyleElement_traverse,
    HTMLStyleElement_unlink
458 459 460 461 462 463 464
};

static const tid_t HTMLStyleElement_iface_tids[] = {
    HTMLELEMENT_TIDS,
    0
};
static dispex_static_data_t HTMLStyleElement_dispex = {
465
    L"HTMLStyleElement",
466 467
    NULL,
    DispHTMLStyleElement_tid,
468
    HTMLStyleElement_iface_tids,
469
    HTMLStyleElement_init_dispex_info
470 471
};

472
HRESULT HTMLStyleElement_Create(HTMLDocumentNode *doc, nsIDOMElement *nselem, HTMLElement **elem)
473
{
474
    HTMLStyleElement *ret;
475
    nsresult nsres;
476 477 478 479

    ret = heap_alloc_zero(sizeof(*ret));
    if(!ret)
        return E_OUTOFMEMORY;
480

481
    ret->IHTMLStyleElement_iface.lpVtbl = &HTMLStyleElementVtbl;
482
    ret->IHTMLStyleElement2_iface.lpVtbl = &HTMLStyleElement2Vtbl;
483 484
    ret->element.node.vtbl = &HTMLStyleElementImplVtbl;

485 486
    HTMLElement_Init(&ret->element, doc, nselem, &HTMLStyleElement_dispex);

487
    nsres = nsIDOMElement_QueryInterface(nselem, &IID_nsIDOMHTMLStyleElement, (void**)&ret->nsstyle);
488
    assert(nsres == NS_OK);
489

490 491
    *elem = &ret->element;
    return S_OK;
492
}