htmlimg.c 28.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * Copyright 2008 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>
20
#include <assert.h>
21 22 23 24 25 26 27 28 29 30 31

#define COBJMACROS

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

#include "wine/debug.h"

#include "mshtml_private.h"
32
#include "htmlevent.h"
33 34 35 36 37 38

WINE_DEFAULT_DEBUG_CHANNEL(mshtml);

typedef struct {
    HTMLElement element;

39
    IHTMLImgElement IHTMLImgElement_iface;
40 41

    nsIDOMHTMLImageElement *nsimg;
42 43
} HTMLImgElement;

44 45 46 47
static inline HTMLImgElement *impl_from_IHTMLImgElement(IHTMLImgElement *iface)
{
    return CONTAINING_RECORD(iface, HTMLImgElement, IHTMLImgElement_iface);
}
48 49 50

static HRESULT WINAPI HTMLImgElement_QueryInterface(IHTMLImgElement *iface, REFIID riid, void **ppv)
{
51
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
52

53
    return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
54 55 56 57
}

static ULONG WINAPI HTMLImgElement_AddRef(IHTMLImgElement *iface)
{
58
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
59

60
    return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
61 62 63 64
}

static ULONG WINAPI HTMLImgElement_Release(IHTMLImgElement *iface)
{
65
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
66

67
    return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
68 69 70 71
}

static HRESULT WINAPI HTMLImgElement_GetTypeInfoCount(IHTMLImgElement *iface, UINT *pctinfo)
{
72
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
73
    return IDispatchEx_GetTypeInfoCount(&This->element.node.event_target.dispex.IDispatchEx_iface, pctinfo);
74 75 76 77 78
}

static HRESULT WINAPI HTMLImgElement_GetTypeInfo(IHTMLImgElement *iface, UINT iTInfo,
                                              LCID lcid, ITypeInfo **ppTInfo)
{
79
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
80
    return IDispatchEx_GetTypeInfo(&This->element.node.event_target.dispex.IDispatchEx_iface, iTInfo, lcid,
81
            ppTInfo);
82 83 84 85 86 87
}

static HRESULT WINAPI HTMLImgElement_GetIDsOfNames(IHTMLImgElement *iface, REFIID riid,
                                                LPOLESTR *rgszNames, UINT cNames,
                                                LCID lcid, DISPID *rgDispId)
{
88
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
89
    return IDispatchEx_GetIDsOfNames(&This->element.node.event_target.dispex.IDispatchEx_iface, riid, rgszNames,
90
            cNames, lcid, rgDispId);
91 92 93 94 95 96
}

static HRESULT WINAPI HTMLImgElement_Invoke(IHTMLImgElement *iface, DISPID dispIdMember,
                            REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
                            VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
97
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
98
    return IDispatchEx_Invoke(&This->element.node.event_target.dispex.IDispatchEx_iface, dispIdMember, riid,
99
            lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
100 101 102 103
}

static HRESULT WINAPI HTMLImgElement_put_isMap(IHTMLImgElement *iface, VARIANT_BOOL v)
{
104
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
105 106 107 108 109 110 111 112 113 114 115
    nsresult nsres;

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

    nsres = nsIDOMHTMLImageElement_SetIsMap(This->nsimg, v != VARIANT_FALSE);
    if (NS_FAILED(nsres)) {
        ERR("Set IsMap failed: %08x\n", nsres);
        return E_FAIL;
    }

    return S_OK;
116 117 118 119
}

static HRESULT WINAPI HTMLImgElement_get_isMap(IHTMLImgElement *iface, VARIANT_BOOL *p)
{
120
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
    cpp_bool b;
    nsresult nsres;

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

    if (p == NULL)
        return E_INVALIDARG;

    nsres = nsIDOMHTMLImageElement_GetIsMap(This->nsimg, &b);
    if (NS_FAILED(nsres)) {
        ERR("Get IsMap failed: %08x\n", nsres);
        return E_FAIL;
    }
    *p = b ? VARIANT_TRUE : VARIANT_FALSE;
    return S_OK;
136 137 138 139
}

static HRESULT WINAPI HTMLImgElement_put_useMap(IHTMLImgElement *iface, BSTR v)
{
140
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
141 142 143 144 145 146
    FIXME("(%p)->(%s)\n", This, debugstr_w(v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLImgElement_get_useMap(IHTMLImgElement *iface, BSTR *p)
{
147
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
148 149 150 151 152 153
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLImgElement_get_mimeType(IHTMLImgElement *iface, BSTR *p)
{
154
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
155 156 157 158 159 160
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLImgElement_get_fileSize(IHTMLImgElement *iface, BSTR *p)
{
161
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
162 163 164 165 166 167
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLImgElement_get_fileCreatedDate(IHTMLImgElement *iface, BSTR *p)
{
168
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
169 170 171 172 173 174
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLImgElement_get_fileModifiedDate(IHTMLImgElement *iface, BSTR *p)
{
175
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
176 177 178 179 180 181
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLImgElement_get_fileUpdatedDate(IHTMLImgElement *iface, BSTR *p)
{
182
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
183 184 185 186 187 188
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLImgElement_get_protocol(IHTMLImgElement *iface, BSTR *p)
{
189
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
190 191 192 193 194 195
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLImgElement_get_href(IHTMLImgElement *iface, BSTR *p)
{
196
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
197 198 199 200 201 202
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLImgElement_get_nameProp(IHTMLImgElement *iface, BSTR *p)
{
203
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
204 205 206 207 208 209
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLImgElement_put_border(IHTMLImgElement *iface, VARIANT v)
{
210
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
211 212 213 214 215 216
    FIXME("(%p)->()\n", This);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLImgElement_get_border(IHTMLImgElement *iface, VARIANT *p)
{
217
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
218 219 220 221
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

222
static HRESULT WINAPI HTMLImgElement_put_vspace(IHTMLImgElement *iface, LONG v)
223
{
224
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
225
    FIXME("(%p)->(%d)\n", This, v);
226 227 228
    return E_NOTIMPL;
}

229
static HRESULT WINAPI HTMLImgElement_get_vspace(IHTMLImgElement *iface, LONG *p)
230
{
231
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
232 233 234 235
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

236
static HRESULT WINAPI HTMLImgElement_put_hspace(IHTMLImgElement *iface, LONG v)
237
{
238
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
239
    FIXME("(%p)->(%d)\n", This, v);
240 241 242
    return E_NOTIMPL;
}

243
static HRESULT WINAPI HTMLImgElement_get_hspace(IHTMLImgElement *iface, LONG *p)
244
{
245
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
246 247 248 249 250 251
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLImgElement_put_alt(IHTMLImgElement *iface, BSTR v)
{
252
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
253 254 255 256 257
    nsAString alt_str;
    nsresult nsres;

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

258
    nsAString_InitDepend(&alt_str, v);
259 260 261 262 263 264
    nsres = nsIDOMHTMLImageElement_SetAlt(This->nsimg, &alt_str);
    nsAString_Finish(&alt_str);
    if(NS_FAILED(nsres))
        ERR("SetAlt failed: %08x\n", nsres);

    return S_OK;
265 266 267 268
}

static HRESULT WINAPI HTMLImgElement_get_alt(IHTMLImgElement *iface, BSTR *p)
{
269
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
270 271 272 273 274 275 276
    nsAString alt_str;
    nsresult nsres;

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

    nsAString_Init(&alt_str, NULL);
    nsres = nsIDOMHTMLImageElement_GetAlt(This->nsimg, &alt_str);
277
    return return_nsstr(nsres, &alt_str, p);
278 279 280 281
}

static HRESULT WINAPI HTMLImgElement_put_src(IHTMLImgElement *iface, BSTR v)
{
282
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
283 284 285 286 287
    nsAString src_str;
    nsresult nsres;

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

288
    nsAString_InitDepend(&src_str, v);
289 290 291 292 293
    nsres = nsIDOMHTMLImageElement_SetSrc(This->nsimg, &src_str);
    nsAString_Finish(&src_str);
    if(NS_FAILED(nsres))
        ERR("SetSrc failed: %08x\n", nsres);

294
    return S_OK;
295 296 297 298
}

static HRESULT WINAPI HTMLImgElement_get_src(IHTMLImgElement *iface, BSTR *p)
{
299
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
300 301 302
    const PRUnichar *src;
    nsAString src_str;
    nsresult nsres;
303 304 305
    HRESULT hres = S_OK;

    static const WCHAR blockedW[] = {'B','L','O','C','K','E','D',':',':',0};
306 307 308 309 310

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

    nsAString_Init(&src_str, NULL);
    nsres = nsIDOMHTMLImageElement_GetSrc(This->nsimg, &src_str);
311 312 313 314 315 316 317 318 319 320 321 322
    if(NS_SUCCEEDED(nsres)) {
        nsAString_GetData(&src_str, &src);

        if(!strncmpiW(src, blockedW, sizeof(blockedW)/sizeof(WCHAR)-1)) {
            TRACE("returning BLOCKED::\n");
            *p = SysAllocString(blockedW);
            if(!*p)
                hres = E_OUTOFMEMORY;
        }else {
            hres = nsuri_to_url(src, TRUE, p);
        }
    }else {
323
        ERR("GetSrc failed: %08x\n", nsres);
324
        hres = E_FAIL;
325 326 327 328
    }

    nsAString_Finish(&src_str);
    return hres;
329 330 331 332
}

static HRESULT WINAPI HTMLImgElement_put_lowsrc(IHTMLImgElement *iface, BSTR v)
{
333
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
334 335 336 337 338 339
    FIXME("(%p)->(%s)\n", This, debugstr_w(v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLImgElement_get_lowsrc(IHTMLImgElement *iface, BSTR *p)
{
340
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
341 342 343 344 345 346
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLImgElement_put_vrml(IHTMLImgElement *iface, BSTR v)
{
347
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
348 349 350 351 352 353
    FIXME("(%p)->(%s)\n", This, debugstr_w(v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLImgElement_get_vrml(IHTMLImgElement *iface, BSTR *p)
{
354
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
355 356 357 358 359 360
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLImgElement_put_dynsrc(IHTMLImgElement *iface, BSTR v)
{
361
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
362 363 364 365 366 367
    FIXME("(%p)->(%s)\n", This, debugstr_w(v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLImgElement_get_dynsrc(IHTMLImgElement *iface, BSTR *p)
{
368
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
369 370 371 372 373 374
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLImgElement_get_readyState(IHTMLImgElement *iface, BSTR *p)
{
375
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
376 377 378 379 380 381
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLImgElement_get_complete(IHTMLImgElement *iface, VARIANT_BOOL *p)
{
382
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
383 384 385 386 387 388 389 390 391 392 393 394 395
    cpp_bool complete;
    nsresult nsres;

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

    nsres = nsIDOMHTMLImageElement_GetComplete(This->nsimg, &complete);
    if(NS_FAILED(nsres)) {
        ERR("GetComplete failed: %08x\n", nsres);
        return E_FAIL;
    }

    *p = complete ? VARIANT_TRUE : VARIANT_FALSE;
    return S_OK;
396 397 398 399
}

static HRESULT WINAPI HTMLImgElement_put_loop(IHTMLImgElement *iface, VARIANT v)
{
400
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
401 402 403 404 405 406
    FIXME("(%p)->()\n", This);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLImgElement_get_loop(IHTMLImgElement *iface, VARIANT *p)
{
407
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
408 409 410 411 412 413
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLImgElement_put_align(IHTMLImgElement *iface, BSTR v)
{
414
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429
    nsAString str;
    nsresult nsres;

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

    nsAString_InitDepend(&str, v);

    nsres = nsIDOMHTMLImageElement_SetAlign(This->nsimg, &str);
    nsAString_Finish(&str);
    if (NS_FAILED(nsres)){
        ERR("Set Align(%s) failed: %08x\n", debugstr_w(v), nsres);
        return E_FAIL;
    }

    return S_OK;
430 431 432 433
}

static HRESULT WINAPI HTMLImgElement_get_align(IHTMLImgElement *iface, BSTR *p)
{
434
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
435 436 437 438 439 440 441 442 443
    nsAString str;
    nsresult nsres;

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

    nsAString_Init(&str, NULL);
    nsres = nsIDOMHTMLImageElement_GetAlign(This->nsimg, &str);

    return return_nsstr(nsres, &str, p);
444 445 446 447
}

static HRESULT WINAPI HTMLImgElement_put_onload(IHTMLImgElement *iface, VARIANT v)
{
448
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
449 450 451 452

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

    return set_node_event(&This->element.node, EVENTID_LOAD, &v);
453 454 455 456
}

static HRESULT WINAPI HTMLImgElement_get_onload(IHTMLImgElement *iface, VARIANT *p)
{
457
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
458 459 460 461

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

    return get_node_event(&This->element.node, EVENTID_LOAD, p);
462 463 464 465
}

static HRESULT WINAPI HTMLImgElement_put_onerror(IHTMLImgElement *iface, VARIANT v)
{
466
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
467 468 469 470

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

    return set_node_event(&This->element.node, EVENTID_ERROR, &v);
471 472 473 474
}

static HRESULT WINAPI HTMLImgElement_get_onerror(IHTMLImgElement *iface, VARIANT *p)
{
475
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
476 477 478 479

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

    return get_node_event(&This->element.node, EVENTID_ERROR, p);
480 481 482 483
}

static HRESULT WINAPI HTMLImgElement_put_onabort(IHTMLImgElement *iface, VARIANT v)
{
484
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
485 486 487 488

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

    return set_node_event(&This->element.node, EVENTID_ABORT, &v);
489 490 491 492
}

static HRESULT WINAPI HTMLImgElement_get_onabort(IHTMLImgElement *iface, VARIANT *p)
{
493
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
494 495 496 497

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

    return get_node_event(&This->element.node, EVENTID_ABORT, p);
498 499 500 501
}

static HRESULT WINAPI HTMLImgElement_put_name(IHTMLImgElement *iface, BSTR v)
{
502
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
503 504 505 506 507 508
    FIXME("(%p)->(%s)\n", This, debugstr_w(v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLImgElement_get_name(IHTMLImgElement *iface, BSTR *p)
{
509
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
510
    nsAString name;
511 512 513 514
    nsresult nsres;

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

515 516 517
    nsAString_Init(&name, NULL);
    nsres = nsIDOMHTMLImageElement_GetName(This->nsimg, &name);
    return return_nsstr(nsres, &name, p);
518 519
}

520
static HRESULT WINAPI HTMLImgElement_put_width(IHTMLImgElement *iface, LONG v)
521
{
522
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
523 524 525 526 527 528 529 530 531 532 533
    nsresult nsres;

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

    nsres = nsIDOMHTMLImageElement_SetWidth(This->nsimg, v);
    if(NS_FAILED(nsres)) {
        ERR("SetWidth failed: %08x\n", nsres);
        return E_FAIL;
    }

    return S_OK;
534 535
}

536
static HRESULT WINAPI HTMLImgElement_get_width(IHTMLImgElement *iface, LONG *p)
537
{
538
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
539
    UINT32 width;
540 541 542 543 544 545 546 547 548 549 550 551
    nsresult nsres;

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

    nsres = nsIDOMHTMLImageElement_GetWidth(This->nsimg, &width);
    if(NS_FAILED(nsres)) {
        ERR("GetWidth failed: %08x\n", nsres);
        return E_FAIL;
    }

    *p = width;
    return S_OK;
552 553
}

554
static HRESULT WINAPI HTMLImgElement_put_height(IHTMLImgElement *iface, LONG v)
555
{
556
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
557 558 559 560 561 562 563 564 565 566 567
    nsresult nsres;

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

    nsres = nsIDOMHTMLImageElement_SetHeight(This->nsimg, v);
    if(NS_FAILED(nsres)) {
        ERR("SetHeight failed: %08x\n", nsres);
        return E_FAIL;
    }

    return S_OK;
568 569
}

570
static HRESULT WINAPI HTMLImgElement_get_height(IHTMLImgElement *iface, LONG *p)
571
{
572
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
573
    UINT32 height;
574 575 576 577 578 579 580 581 582 583 584 585
    nsresult nsres;

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

    nsres = nsIDOMHTMLImageElement_GetHeight(This->nsimg, &height);
    if(NS_FAILED(nsres)) {
        ERR("GetHeight failed: %08x\n", nsres);
        return E_FAIL;
    }

    *p = height;
    return S_OK;
586 587 588 589
}

static HRESULT WINAPI HTMLImgElement_put_start(IHTMLImgElement *iface, BSTR v)
{
590
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
591 592 593 594 595 596
    FIXME("(%p)->()\n", This);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLImgElement_get_start(IHTMLImgElement *iface, BSTR *p)
{
597
    HTMLImgElement *This = impl_from_IHTMLImgElement(iface);
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static const IHTMLImgElementVtbl HTMLImgElementVtbl = {
    HTMLImgElement_QueryInterface,
    HTMLImgElement_AddRef,
    HTMLImgElement_Release,
    HTMLImgElement_GetTypeInfoCount,
    HTMLImgElement_GetTypeInfo,
    HTMLImgElement_GetIDsOfNames,
    HTMLImgElement_Invoke,
    HTMLImgElement_put_isMap,
    HTMLImgElement_get_isMap,
    HTMLImgElement_put_useMap,
    HTMLImgElement_get_useMap,
    HTMLImgElement_get_mimeType,
    HTMLImgElement_get_fileSize,
    HTMLImgElement_get_fileCreatedDate,
    HTMLImgElement_get_fileModifiedDate,
    HTMLImgElement_get_fileUpdatedDate,
    HTMLImgElement_get_protocol,
    HTMLImgElement_get_href,
    HTMLImgElement_get_nameProp,
    HTMLImgElement_put_border,
    HTMLImgElement_get_border,
    HTMLImgElement_put_vspace,
    HTMLImgElement_get_vspace,
    HTMLImgElement_put_hspace,
    HTMLImgElement_get_hspace,
    HTMLImgElement_put_alt,
    HTMLImgElement_get_alt,
    HTMLImgElement_put_src,
    HTMLImgElement_get_src,
    HTMLImgElement_put_lowsrc,
    HTMLImgElement_get_lowsrc,
    HTMLImgElement_put_vrml,
    HTMLImgElement_get_vrml,
    HTMLImgElement_put_dynsrc,
    HTMLImgElement_get_dynsrc,
    HTMLImgElement_get_readyState,
    HTMLImgElement_get_complete,
    HTMLImgElement_put_loop,
    HTMLImgElement_get_loop,
    HTMLImgElement_put_align,
    HTMLImgElement_get_align,
    HTMLImgElement_put_onload,
    HTMLImgElement_get_onload,
    HTMLImgElement_put_onerror,
    HTMLImgElement_get_onerror,
    HTMLImgElement_put_onabort,
    HTMLImgElement_get_onabort,
    HTMLImgElement_put_name,
    HTMLImgElement_get_name,
    HTMLImgElement_put_width,
    HTMLImgElement_get_width,
    HTMLImgElement_put_height,
    HTMLImgElement_get_height,
    HTMLImgElement_put_start,
    HTMLImgElement_get_start
};

660 661 662 663
static inline HTMLImgElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
{
    return CONTAINING_RECORD(iface, HTMLImgElement, element.node);
}
664 665 666

static HRESULT HTMLImgElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
{
667
    HTMLImgElement *This = impl_from_HTMLDOMNode(iface);
668 669 670 671 672

    *ppv = NULL;

    if(IsEqualGUID(&IID_IHTMLImgElement, riid)) {
        TRACE("(%p)->(IID_IHTMLImgElement %p)\n", This, ppv);
673
        *ppv = &This->IHTMLImgElement_iface;
674 675 676 677 678 679 680 681
    }else {
        return HTMLElement_QI(&This->element.node, riid, ppv);
    }

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

682 683
static HRESULT HTMLImgElement_get_readystate(HTMLDOMNode *iface, BSTR *p)
{
684
    HTMLImgElement *This = impl_from_HTMLDOMNode(iface);
685

686
    return IHTMLImgElement_get_readyState(&This->IHTMLImgElement_iface, p);
687 688
}

689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708
static void HTMLImgElement_traverse(HTMLDOMNode *iface, nsCycleCollectionTraversalCallback *cb)
{
    HTMLImgElement *This = impl_from_HTMLDOMNode(iface);

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

static void HTMLImgElement_unlink(HTMLDOMNode *iface)
{
    HTMLImgElement *This = impl_from_HTMLDOMNode(iface);

    if(This->nsimg) {
        nsIDOMHTMLImageElement *nsimg = This->nsimg;

        This->nsimg = NULL;
        nsIDOMHTMLImageElement_Release(nsimg);
    }
}

709 710
static const NodeImplVtbl HTMLImgElementImplVtbl = {
    HTMLImgElement_QI,
711
    HTMLElement_destructor,
712
    HTMLElement_cpc,
713
    HTMLElement_clone,
714
    HTMLElement_handle_event,
715
    HTMLElement_get_attr_col,
716 717 718 719 720
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
721 722 723 724 725 726
    HTMLImgElement_get_readystate,
    NULL,
    NULL,
    NULL,
    HTMLImgElement_traverse,
    HTMLImgElement_unlink
727 728
};

729
static const tid_t HTMLImgElement_iface_tids[] = {
730
    HTMLELEMENT_TIDS,
731 732 733
    IHTMLImgElement_tid,
    0
};
734 735 736
static dispex_static_data_t HTMLImgElement_dispex = {
    NULL,
    DispHTMLImg_tid,
737 738
    HTMLImgElement_iface_tids,
    HTMLElement_init_dispex_info
739 740
};

741
HRESULT HTMLImgElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
742
{
743
    HTMLImgElement *ret;
744
    nsresult nsres;
745

746 747 748 749
    ret = heap_alloc_zero(sizeof(HTMLImgElement));
    if(!ret)
        return E_OUTOFMEMORY;

750
    ret->IHTMLImgElement_iface.lpVtbl = &HTMLImgElementVtbl;
751 752
    ret->element.node.vtbl = &HTMLImgElementImplVtbl;

753 754
    HTMLElement_Init(&ret->element, doc, nselem, &HTMLImgElement_dispex);

755
    nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLImageElement, (void**)&ret->nsimg);
756
    assert(nsres == NS_OK);
757

758 759
    *elem = &ret->element;
    return S_OK;
760
}
761

762 763 764 765
static inline HTMLImageElementFactory *impl_from_IHTMLImageElementFactory(IHTMLImageElementFactory *iface)
{
    return CONTAINING_RECORD(iface, HTMLImageElementFactory, IHTMLImageElementFactory_iface);
}
766 767 768 769

static HRESULT WINAPI HTMLImageElementFactory_QueryInterface(IHTMLImageElementFactory *iface,
        REFIID riid, void **ppv)
{
770
    HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
771

772
    TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
773 774

    if(IsEqualGUID(&IID_IUnknown, riid)) {
775
        *ppv = &This->IHTMLImageElementFactory_iface;
776
    }else if(IsEqualGUID(&IID_IHTMLImageElementFactory, riid)) {
777
        *ppv = &This->IHTMLImageElementFactory_iface;
778
    }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
779
        return *ppv ? S_OK : E_NOINTERFACE;
780 781 782 783
    }else {
        *ppv = NULL;
        WARN("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
        return E_NOINTERFACE;
784 785
    }

786 787
    IUnknown_AddRef((IUnknown*)*ppv);
    return S_OK;
788 789 790 791
}

static ULONG WINAPI HTMLImageElementFactory_AddRef(IHTMLImageElementFactory *iface)
{
792
    HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
793 794 795 796 797 798 799 800 801
    LONG ref = InterlockedIncrement(&This->ref);

    TRACE("(%p) ref=%d\n", This, ref);

    return ref;
}

static ULONG WINAPI HTMLImageElementFactory_Release(IHTMLImageElementFactory *iface)
{
802
    HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
803 804 805 806 807 808 809 810 811 812 813 814 815
    LONG ref = InterlockedDecrement(&This->ref);

    TRACE("(%p) ref=%d\n", This, ref);

    if(!ref)
        heap_free(This);

    return ref;
}

static HRESULT WINAPI HTMLImageElementFactory_GetTypeInfoCount(IHTMLImageElementFactory *iface,
        UINT *pctinfo)
{
816
    HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
817
    return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
818 819 820 821 822
}

static HRESULT WINAPI HTMLImageElementFactory_GetTypeInfo(IHTMLImageElementFactory *iface,
        UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
{
823
    HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
824
    return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
825 826 827 828 829 830
}

static HRESULT WINAPI HTMLImageElementFactory_GetIDsOfNames(IHTMLImageElementFactory *iface,
        REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid,
        DISPID *rgDispId)
{
831
    HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
832
    return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames, lcid, rgDispId);
833 834 835 836 837 838 839
}

static HRESULT WINAPI HTMLImageElementFactory_Invoke(IHTMLImageElementFactory *iface,
        DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags,
        DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
        UINT *puArgErr)
{
840
    HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
841 842
    return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
            pDispParams, pVarResult, pExcepInfo, puArgErr);
843 844
}

845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868
static LONG var_to_size(const VARIANT *v)
{
    switch(V_VT(v)) {
    case VT_EMPTY:
        return 0;
    case VT_I4:
        return V_I4(v);
    case VT_BSTR: {
        LONG ret;
        HRESULT hres;

        hres = VarI4FromStr(V_BSTR(v), 0, 0, &ret);
        if(FAILED(hres)) {
            FIXME("VarI4FromStr failed: %08x\n", hres);
            return 0;
        }
        return ret;
    }
    default:
        FIXME("unsupported size %s\n", debugstr_variant(v));
    }
    return 0;
}

869
static HRESULT WINAPI HTMLImageElementFactory_create(IHTMLImageElementFactory *iface,
870
        VARIANT width, VARIANT height, IHTMLImgElement **img_elem)
871
{
872
    HTMLImageElementFactory *This = impl_from_IHTMLImageElementFactory(iface);
873
    HTMLDocumentNode *doc;
874
    IHTMLImgElement *img;
875 876
    HTMLElement *elem;
    nsIDOMHTMLElement *nselem;
877
    LONG l;
878 879 880 881 882 883 884
    HRESULT hres;

    static const PRUnichar imgW[] = {'I','M','G',0};

    TRACE("(%p)->(%s %s %p)\n", This, debugstr_variant(&width),
            debugstr_variant(&height), img_elem);

885
    if(!This->window || !This->window->doc) {
886 887 888 889
        WARN("NULL doc\n");
        return E_UNEXPECTED;
    }

890
    doc = This->window->doc;
891

892 893
    *img_elem = NULL;

894
    hres = create_nselem(doc, imgW, &nselem);
895 896 897
    if(FAILED(hres))
        return hres;

898
    hres = HTMLElement_Create(doc, (nsIDOMNode*)nselem, FALSE, &elem);
899 900
    nsIDOMHTMLElement_Release(nselem);
    if(FAILED(hres)) {
901
        ERR("HTMLElement_Create failed\n");
902
        return hres;
903 904
    }

905 906
    hres = IHTMLElement_QueryInterface(&elem->IHTMLElement_iface, &IID_IHTMLImgElement,
            (void**)&img);
907
    IHTMLElement_Release(&elem->IHTMLElement_iface);
908 909 910 911 912
    if(FAILED(hres)) {
        ERR("IHTMLElement_QueryInterface failed: 0x%08x\n", hres);
        return hres;
    }

913 914 915 916 917 918
    l = var_to_size(&width);
    if(l)
        IHTMLImgElement_put_width(img, l);
    l = var_to_size(&height);
    if(l)
        IHTMLImgElement_put_height(img, l);
919

920
    *img_elem = img;
921
    return S_OK;
922 923
}

924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940
static const IHTMLImageElementFactoryVtbl HTMLImageElementFactoryVtbl = {
    HTMLImageElementFactory_QueryInterface,
    HTMLImageElementFactory_AddRef,
    HTMLImageElementFactory_Release,
    HTMLImageElementFactory_GetTypeInfoCount,
    HTMLImageElementFactory_GetTypeInfo,
    HTMLImageElementFactory_GetIDsOfNames,
    HTMLImageElementFactory_Invoke,
    HTMLImageElementFactory_create
};

static inline HTMLImageElementFactory *impl_from_DispatchEx(DispatchEx *iface)
{
    return CONTAINING_RECORD(iface, HTMLImageElementFactory, dispex);
}

static HRESULT HTMLImageElementFactory_value(DispatchEx *dispex, LCID lcid,
941 942 943
        WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei,
        IServiceProvider *caller)
{
944
    HTMLImageElementFactory *This = impl_from_DispatchEx(dispex);
945 946 947 948 949 950 951 952 953 954 955 956
    IHTMLImgElement *img;
    VARIANT empty, *width, *height;
    HRESULT hres;
    int argc = params->cArgs - params->cNamedArgs;

    V_VT(res) = VT_NULL;

    V_VT(&empty) = VT_EMPTY;

    width = argc >= 1 ? params->rgvarg + (params->cArgs - 1) : &empty;
    height = argc >= 2 ? params->rgvarg + (params->cArgs - 2) : &empty;

957 958
    hres = IHTMLImageElementFactory_create(&This->IHTMLImageElementFactory_iface, *width, *height,
            &img);
959 960 961 962 963 964 965 966 967
    if(FAILED(hres))
        return hres;

    V_VT(res) = VT_DISPATCH;
    V_DISPATCH(res) = (IDispatch*)img;

    return S_OK;
}

968 969 970 971 972
static const tid_t HTMLImageElementFactory_iface_tids[] = {
    IHTMLImageElementFactory_tid,
    0
};

973 974
static const dispex_static_data_vtbl_t HTMLImageElementFactory_dispex_vtbl = {
    HTMLImageElementFactory_value,
975
    NULL,
976
    NULL,
977 978 979 980 981
    NULL
};

static dispex_static_data_t HTMLImageElementFactory_dispex = {
    &HTMLImageElementFactory_dispex_vtbl,
982 983 984 985
    IHTMLImageElementFactory_tid,
    HTMLImageElementFactory_iface_tids
};

986
HRESULT HTMLImageElementFactory_Create(HTMLInnerWindow *window, HTMLImageElementFactory **ret_val)
987 988 989 990
{
    HTMLImageElementFactory *ret;

    ret = heap_alloc(sizeof(HTMLImageElementFactory));
991 992
    if(!ret)
        return E_OUTOFMEMORY;
993

994
    ret->IHTMLImageElementFactory_iface.lpVtbl = &HTMLImageElementFactoryVtbl;
995 996 997
    ret->ref = 1;
    ret->window = window;

998 999
    init_dispex(&ret->dispex, (IUnknown*)&ret->IHTMLImageElementFactory_iface,
            &HTMLImageElementFactory_dispex);
1000

1001 1002
    *ret_val = ret;
    return S_OK;
1003
}