htmldoc.c 157 KB
Newer Older
1
/*
2
 * Copyright 2005-2009 Jacek Caban for CodeWeavers
3 4 5 6 7 8 9 10 11 12 13 14 15
 *
 * 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
16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 18 19 20 21 22
 */

#include "config.h"

#include <stdarg.h>
#include <stdio.h>
23
#include <assert.h>
24 25 26 27 28 29

#define COBJMACROS

#include "windef.h"
#include "winbase.h"
#include "winuser.h"
30
#include "wininet.h"
31
#include "ole2.h"
32
#include "perhist.h"
33
#include "mshtmdid.h"
34
#include "mshtmcid.h"
35 36 37 38

#include "wine/debug.h"

#include "mshtml_private.h"
39
#include "htmlevent.h"
40
#include "pluginhost.h"
41
#include "binding.h"
42 43 44

WINE_DEFAULT_DEBUG_CHANNEL(mshtml);

45 46
static HRESULT create_document_fragment(nsIDOMNode *nsnode, HTMLDocumentNode *doc_node, HTMLDocumentNode **ret);

47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
HRESULT get_doc_elem_by_id(HTMLDocumentNode *doc, const WCHAR *id, HTMLElement **ret)
{
    nsIDOMNodeList *nsnode_list;
    nsIDOMElement *nselem;
    nsIDOMNode *nsnode;
    nsAString id_str;
    nsresult nsres;
    HRESULT hres;

    if(!doc->nsdoc) {
        WARN("NULL nsdoc\n");
        return E_UNEXPECTED;
    }

    nsAString_InitDepend(&id_str, id);
    /* get element by id attribute */
    nsres = nsIDOMHTMLDocument_GetElementById(doc->nsdoc, &id_str, &nselem);
    if(FAILED(nsres)) {
        ERR("GetElementById failed: %08x\n", nsres);
        nsAString_Finish(&id_str);
        return E_FAIL;
    }

    /* get first element by name attribute */
    nsres = nsIDOMHTMLDocument_GetElementsByName(doc->nsdoc, &id_str, &nsnode_list);
    nsAString_Finish(&id_str);
    if(FAILED(nsres)) {
        ERR("getElementsByName failed: %08x\n", nsres);
        if(nselem)
            nsIDOMElement_Release(nselem);
        return E_FAIL;
    }

    nsres = nsIDOMNodeList_Item(nsnode_list, 0, &nsnode);
    nsIDOMNodeList_Release(nsnode_list);
    assert(nsres == NS_OK);

    if(nsnode && nselem) {
        UINT16 pos;

        nsres = nsIDOMNode_CompareDocumentPosition(nsnode, (nsIDOMNode*)nselem, &pos);
        if(NS_FAILED(nsres)) {
            FIXME("CompareDocumentPosition failed: 0x%08x\n", nsres);
            nsIDOMNode_Release(nsnode);
            nsIDOMElement_Release(nselem);
            return E_FAIL;
        }

        TRACE("CompareDocumentPosition gave: 0x%x\n", pos);
        if(!(pos & (DOCUMENT_POSITION_PRECEDING | DOCUMENT_POSITION_CONTAINS))) {
            nsIDOMElement_Release(nselem);
            nselem = NULL;
        }
    }

    if(nsnode) {
        if(!nselem) {
            nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMElement, (void**)&nselem);
            assert(nsres == NS_OK);
        }
        nsIDOMNode_Release(nsnode);
    }

    if(!nselem) {
        *ret = NULL;
        return S_OK;
    }

    hres = get_elem(doc, nselem, ret);
    nsIDOMElement_Release(nselem);
    return hres;
}

120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
UINT get_document_charset(HTMLDocumentNode *doc)
{
    nsAString charset_str;
    UINT ret = 0;
    nsresult nsres;

    if(doc->charset)
        return doc->charset;

    nsAString_Init(&charset_str, NULL);
    nsres = nsIDOMHTMLDocument_GetCharacterSet(doc->nsdoc, &charset_str);
    if(NS_SUCCEEDED(nsres)) {
        const PRUnichar *charset;

        nsAString_GetData(&charset_str, &charset);

        if(*charset) {
            BSTR str = SysAllocString(charset);
            ret = cp_from_charset_string(str);
            SysFreeString(str);
        }
    }else {
        ERR("GetCharset failed: %08x\n", nsres);
    }
    nsAString_Finish(&charset_str);

    if(!ret)
        return CP_UTF8;

    return doc->charset = ret;
}

152 153 154 155
static inline HTMLDocument *impl_from_IHTMLDocument2(IHTMLDocument2 *iface)
{
    return CONTAINING_RECORD(iface, HTMLDocument, IHTMLDocument2_iface);
}
156

157
static HRESULT WINAPI HTMLDocument_QueryInterface(IHTMLDocument2 *iface, REFIID riid, void **ppv)
158
{
159
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
160

161
    return htmldoc_query_interface(This, riid, ppv);
162 163 164 165
}

static ULONG WINAPI HTMLDocument_AddRef(IHTMLDocument2 *iface)
{
166
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
167 168

    return htmldoc_addref(This);
169 170 171 172
}

static ULONG WINAPI HTMLDocument_Release(IHTMLDocument2 *iface)
{
173
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
174

175
    return htmldoc_release(This);
176 177 178 179
}

static HRESULT WINAPI HTMLDocument_GetTypeInfoCount(IHTMLDocument2 *iface, UINT *pctinfo)
{
180
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
181

182
    return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
183 184 185 186 187
}

static HRESULT WINAPI HTMLDocument_GetTypeInfo(IHTMLDocument2 *iface, UINT iTInfo,
                                                LCID lcid, ITypeInfo **ppTInfo)
{
188
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
189

190
    return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
191 192 193 194 195 196
}

static HRESULT WINAPI HTMLDocument_GetIDsOfNames(IHTMLDocument2 *iface, REFIID riid,
                                                LPOLESTR *rgszNames, UINT cNames,
                                                LCID lcid, DISPID *rgDispId)
{
197
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
198

199 200
    return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
            rgDispId);
201 202 203 204 205 206
}

static HRESULT WINAPI HTMLDocument_Invoke(IHTMLDocument2 *iface, DISPID dispIdMember,
                            REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
                            VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
207
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
208

209 210
    return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
            pDispParams, pVarResult, pExcepInfo, puArgErr);
211 212 213 214
}

static HRESULT WINAPI HTMLDocument_get_Script(IHTMLDocument2 *iface, IDispatch **p)
{
215
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
216 217 218

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

219
    *p = (IDispatch*)&This->window->base.IHTMLWindow2_iface;
220 221
    IDispatch_AddRef(*p);
    return S_OK;
222 223 224 225
}

static HRESULT WINAPI HTMLDocument_get_all(IHTMLDocument2 *iface, IHTMLElementCollection **p)
{
226
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
227
    nsIDOMElement *nselem = NULL;
228
    HTMLDOMNode *node;
229
    nsresult nsres;
230
    HRESULT hres;
231 232 233

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

234
    if(!This->doc_node->nsdoc) {
235 236
        WARN("NULL nsdoc\n");
        return E_UNEXPECTED;
237 238
    }

239
    nsres = nsIDOMHTMLDocument_GetDocumentElement(This->doc_node->nsdoc, &nselem);
240 241 242
    if(NS_FAILED(nsres)) {
        ERR("GetDocumentElement failed: %08x\n", nsres);
        return E_FAIL;
243 244
    }

245
    if(!nselem) {
246
        *p = NULL;
247
        return S_OK;
248
    }
249

250 251
    hres = get_node(This->doc_node, (nsIDOMNode*)nselem, TRUE, &node);
    nsIDOMElement_Release(nselem);
252 253 254 255 256
    if(FAILED(hres))
        return hres;

    *p = create_all_collection(node, TRUE);
    node_release(node);
257
    return hres;
258 259 260 261
}

static HRESULT WINAPI HTMLDocument_get_body(IHTMLDocument2 *iface, IHTMLElement **p)
{
262
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
263 264
    nsIDOMHTMLElement *nsbody = NULL;
    HTMLDOMNode *node;
265
    HRESULT hres;
266 267 268

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

269 270
    if(This->doc_node->nsdoc) {
        nsresult nsres;
271

272 273 274 275 276
        nsres = nsIDOMHTMLDocument_GetBody(This->doc_node->nsdoc, &nsbody);
        if(NS_FAILED(nsres)) {
            TRACE("Could not get body: %08x\n", nsres);
            return E_UNEXPECTED;
        }
277 278
    }

279
    if(!nsbody) {
280
        *p = NULL;
281
        return S_OK;
282
    }
283

284 285 286 287 288
    hres = get_node(This->doc_node, (nsIDOMNode*)nsbody, TRUE, &node);
    nsIDOMHTMLElement_Release(nsbody);
    if(FAILED(hres))
        return hres;

289 290 291
    hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)p);
    node_release(node);
    return hres;
292 293 294 295
}

static HRESULT WINAPI HTMLDocument_get_activeElement(IHTMLDocument2 *iface, IHTMLElement **p)
{
296
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
    nsIDOMElement *nselem;
    HTMLElement *elem;
    nsresult nsres;
    HRESULT hres;

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

    if(!This->doc_node->nsdoc) {
        *p = NULL;
        return S_OK;
    }

    /*
     * NOTE: Gecko may return an active element even if the document is not visible.
     * IE returns NULL in this case.
     */
    nsres = nsIDOMHTMLDocument_GetActiveElement(This->doc_node->nsdoc, &nselem);
    if(NS_FAILED(nsres)) {
        ERR("GetActiveElement failed: %08x\n", nsres);
        return E_FAIL;
    }

319 320 321 322 323
    if(!nselem) {
        *p = NULL;
        return S_OK;
    }

324 325 326 327 328 329 330
    hres = get_elem(This->doc_node, nselem, &elem);
    nsIDOMElement_Release(nselem);
    if(FAILED(hres))
        return hres;

    *p = &elem->IHTMLElement_iface;
    return S_OK;
331 332 333 334
}

static HRESULT WINAPI HTMLDocument_get_images(IHTMLDocument2 *iface, IHTMLElementCollection **p)
{
335
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
336 337 338 339 340 341 342 343 344 345
    nsIDOMHTMLCollection *nscoll = NULL;
    nsresult nsres;

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

    if(!p)
        return E_INVALIDARG;

    *p = NULL;

346
    if(!This->doc_node->nsdoc) {
347 348 349 350
        WARN("NULL nsdoc\n");
        return E_UNEXPECTED;
    }

351
    nsres = nsIDOMHTMLDocument_GetImages(This->doc_node->nsdoc, &nscoll);
352 353 354 355 356 357
    if(NS_FAILED(nsres)) {
        ERR("GetImages failed: %08x\n", nsres);
        return E_FAIL;
    }

    if(nscoll) {
358
        *p = create_collection_from_htmlcol(This->doc_node, nscoll);
359
        nsIDOMHTMLCollection_Release(nscoll);
360 361 362
    }

    return S_OK;
363 364 365 366
}

static HRESULT WINAPI HTMLDocument_get_applets(IHTMLDocument2 *iface, IHTMLElementCollection **p)
{
367
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
368 369 370 371 372 373 374 375 376 377
    nsIDOMHTMLCollection *nscoll = NULL;
    nsresult nsres;

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

    if(!p)
        return E_INVALIDARG;

    *p = NULL;

378
    if(!This->doc_node->nsdoc) {
379 380 381 382
        WARN("NULL nsdoc\n");
        return E_UNEXPECTED;
    }

383
    nsres = nsIDOMHTMLDocument_GetApplets(This->doc_node->nsdoc, &nscoll);
384 385 386 387 388 389
    if(NS_FAILED(nsres)) {
        ERR("GetApplets failed: %08x\n", nsres);
        return E_FAIL;
    }

    if(nscoll) {
390
        *p = create_collection_from_htmlcol(This->doc_node, nscoll);
391
        nsIDOMHTMLCollection_Release(nscoll);
392 393 394
    }

    return S_OK;
395 396 397 398
}

static HRESULT WINAPI HTMLDocument_get_links(IHTMLDocument2 *iface, IHTMLElementCollection **p)
{
399
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
400 401 402 403 404 405 406 407 408 409
    nsIDOMHTMLCollection *nscoll = NULL;
    nsresult nsres;

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

    if(!p)
        return E_INVALIDARG;

    *p = NULL;

410
    if(!This->doc_node->nsdoc) {
411 412 413 414
        WARN("NULL nsdoc\n");
        return E_UNEXPECTED;
    }

415
    nsres = nsIDOMHTMLDocument_GetLinks(This->doc_node->nsdoc, &nscoll);
416 417 418 419 420 421
    if(NS_FAILED(nsres)) {
        ERR("GetLinks failed: %08x\n", nsres);
        return E_FAIL;
    }

    if(nscoll) {
422
        *p = create_collection_from_htmlcol(This->doc_node, nscoll);
423
        nsIDOMHTMLCollection_Release(nscoll);
424 425 426
    }

    return S_OK;
427 428 429 430
}

static HRESULT WINAPI HTMLDocument_get_forms(IHTMLDocument2 *iface, IHTMLElementCollection **p)
{
431
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
432 433 434 435 436 437 438 439 440 441
    nsIDOMHTMLCollection *nscoll = NULL;
    nsresult nsres;

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

    if(!p)
        return E_INVALIDARG;

    *p = NULL;

442
    if(!This->doc_node->nsdoc) {
443 444 445 446
        WARN("NULL nsdoc\n");
        return E_UNEXPECTED;
    }

447
    nsres = nsIDOMHTMLDocument_GetForms(This->doc_node->nsdoc, &nscoll);
448 449 450 451 452 453
    if(NS_FAILED(nsres)) {
        ERR("GetForms failed: %08x\n", nsres);
        return E_FAIL;
    }

    if(nscoll) {
454
        *p = create_collection_from_htmlcol(This->doc_node, nscoll);
455
        nsIDOMHTMLCollection_Release(nscoll);
456 457 458
    }

    return S_OK;
459 460 461 462
}

static HRESULT WINAPI HTMLDocument_get_anchors(IHTMLDocument2 *iface, IHTMLElementCollection **p)
{
463
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
464 465 466 467 468 469 470 471 472 473
    nsIDOMHTMLCollection *nscoll = NULL;
    nsresult nsres;

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

    if(!p)
        return E_INVALIDARG;

    *p = NULL;

474
    if(!This->doc_node->nsdoc) {
475 476 477 478
        WARN("NULL nsdoc\n");
        return E_UNEXPECTED;
    }

479
    nsres = nsIDOMHTMLDocument_GetAnchors(This->doc_node->nsdoc, &nscoll);
480 481 482 483 484 485
    if(NS_FAILED(nsres)) {
        ERR("GetAnchors failed: %08x\n", nsres);
        return E_FAIL;
    }

    if(nscoll) {
486
        *p = create_collection_from_htmlcol(This->doc_node, nscoll);
487
        nsIDOMHTMLCollection_Release(nscoll);
488 489 490
    }

    return S_OK;
491 492 493 494
}

static HRESULT WINAPI HTMLDocument_put_title(IHTMLDocument2 *iface, BSTR v)
{
495
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
496 497 498 499 500
    nsAString nsstr;
    nsresult nsres;

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

501
    if(!This->doc_node->nsdoc) {
502 503
        WARN("NULL nsdoc\n");
        return E_UNEXPECTED;
504 505
    }

506
    nsAString_InitDepend(&nsstr, v);
507
    nsres = nsIDOMHTMLDocument_SetTitle(This->doc_node->nsdoc, &nsstr);
508 509 510 511 512
    nsAString_Finish(&nsstr);
    if(NS_FAILED(nsres))
        ERR("SetTitle failed: %08x\n", nsres);

    return S_OK;
513 514 515 516
}

static HRESULT WINAPI HTMLDocument_get_title(IHTMLDocument2 *iface, BSTR *p)
{
517
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
518 519 520 521 522 523
    const PRUnichar *ret;
    nsAString nsstr;
    nsresult nsres;

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

524
    if(!This->doc_node->nsdoc) {
525 526
        WARN("NULL nsdoc\n");
        return E_UNEXPECTED;
527 528 529 530
    }


    nsAString_Init(&nsstr, NULL);
531
    nsres = nsIDOMHTMLDocument_GetTitle(This->doc_node->nsdoc, &nsstr);
532 533 534 535 536
    if (NS_SUCCEEDED(nsres)) {
        nsAString_GetData(&nsstr, &ret);
        *p = SysAllocString(ret);
    }
    nsAString_Finish(&nsstr);
537

538
    if(NS_FAILED(nsres)) {
539
        ERR("GetTitle failed: %08x\n", nsres);
540 541
        return E_FAIL;
    }
542 543

    return S_OK;
544 545 546 547
}

static HRESULT WINAPI HTMLDocument_get_scripts(IHTMLDocument2 *iface, IHTMLElementCollection **p)
{
548
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575
    nsIDOMHTMLCollection *nscoll = NULL;
    nsresult nsres;

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

    if(!p)
        return E_INVALIDARG;

    *p = NULL;

    if(!This->doc_node->nsdoc) {
        WARN("NULL nsdoc\n");
        return E_UNEXPECTED;
    }

    nsres = nsIDOMHTMLDocument_GetScripts(This->doc_node->nsdoc, &nscoll);
    if(NS_FAILED(nsres)) {
        ERR("GetImages failed: %08x\n", nsres);
        return E_FAIL;
    }

    if(nscoll) {
        *p = create_collection_from_htmlcol(This->doc_node, nscoll);
        nsIDOMHTMLCollection_Release(nscoll);
    }

    return S_OK;
576 577 578 579
}

static HRESULT WINAPI HTMLDocument_put_designMode(IHTMLDocument2 *iface, BSTR v)
{
580
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595
    HRESULT hres;

    static const WCHAR onW[] = {'o','n',0};

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

    if(strcmpiW(v, onW)) {
        FIXME("Unsupported arg %s\n", debugstr_w(v));
        return E_NOTIMPL;
    }

    hres = setup_edit_mode(This->doc_obj);
    if(FAILED(hres))
        return hres;

596
    call_property_onchanged(&This->cp_container, DISPID_IHTMLDOCUMENT2_DESIGNMODE);
597
    return S_OK;
598 599 600 601
}

static HRESULT WINAPI HTMLDocument_get_designMode(IHTMLDocument2 *iface, BSTR *p)
{
602
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
603
    static const WCHAR szOff[] = {'O','f','f',0};
604 605 606 607 608 609 610 611
    FIXME("(%p)->(%p) always returning Off\n", This, p);

    if(!p)
        return E_INVALIDARG;

    *p = SysAllocString(szOff);

    return S_OK;
612 613 614 615
}

static HRESULT WINAPI HTMLDocument_get_selection(IHTMLDocument2 *iface, IHTMLSelectionObject **p)
{
616
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
617 618
    nsISelection *nsselection;
    nsresult nsres;
619 620 621

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

622 623 624 625
    nsres = nsIDOMWindow_GetSelection(This->window->nswindow, &nsselection);
    if(NS_FAILED(nsres)) {
        ERR("GetSelection failed: %08x\n", nsres);
        return E_FAIL;
626 627
    }

628
    return HTMLSelectionObject_Create(This->doc_node, nsselection, p);
629 630 631 632
}

static HRESULT WINAPI HTMLDocument_get_readyState(IHTMLDocument2 *iface, BSTR *p)
{
633
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
634 635 636 637 638 639 640


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

    if(!p)
        return E_POINTER;

641
    return get_readystate_string(This->window->readystate, p);
642 643 644 645
}

static HRESULT WINAPI HTMLDocument_get_frames(IHTMLDocument2 *iface, IHTMLFramesCollection2 **p)
{
646
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
647 648 649

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

650
    return IHTMLWindow2_get_frames(&This->window->base.IHTMLWindow2_iface, p);
651 652 653 654
}

static HRESULT WINAPI HTMLDocument_get_embeds(IHTMLDocument2 *iface, IHTMLElementCollection **p)
{
655
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
656
    FIXME("(%p)->(%p)\n", This, p);
657 658 659 660 661
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_plugins(IHTMLDocument2 *iface, IHTMLElementCollection **p)
{
662
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
663
    FIXME("(%p)->(%p)\n", This, p);
664 665 666 667 668
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_alinkColor(IHTMLDocument2 *iface, VARIANT v)
{
669
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
670
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
671 672 673 674 675
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_alinkColor(IHTMLDocument2 *iface, VARIANT *p)
{
676
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
677
    FIXME("(%p)->(%p)\n", This, p);
678 679 680 681 682
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_bgColor(IHTMLDocument2 *iface, VARIANT v)
{
683
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
684
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
685 686 687 688 689
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_bgColor(IHTMLDocument2 *iface, VARIANT *p)
{
690
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
691
    FIXME("(%p)->(%p)\n", This, p);
692 693 694 695 696
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_fgColor(IHTMLDocument2 *iface, VARIANT v)
{
697
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
698
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
699 700 701 702 703
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_fgColor(IHTMLDocument2 *iface, VARIANT *p)
{
704
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
705
    FIXME("(%p)->(%p)\n", This, p);
706 707 708 709 710
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_linkColor(IHTMLDocument2 *iface, VARIANT v)
{
711
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
712
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
713 714 715 716 717
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_linkColor(IHTMLDocument2 *iface, VARIANT *p)
{
718
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
719
    FIXME("(%p)->(%p)\n", This, p);
720 721 722 723 724
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_vlinkColor(IHTMLDocument2 *iface, VARIANT v)
{
725
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
726
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
727 728 729 730 731
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_vlinkColor(IHTMLDocument2 *iface, VARIANT *p)
{
732
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
733
    FIXME("(%p)->(%p)\n", This, p);
734 735 736 737 738
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_referrer(IHTMLDocument2 *iface, BSTR *p)
{
739
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
740

741
    FIXME("(%p)->(%p)\n", This, p);
742 743 744 745

    *p = NULL;
    return S_OK;
 }
746 747 748

static HRESULT WINAPI HTMLDocument_get_location(IHTMLDocument2 *iface, IHTMLLocation **p)
{
749
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
750 751 752

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

753 754 755 756 757
    if(!This->doc_node->nsdoc) {
        WARN("NULL nsdoc\n");
        return E_UNEXPECTED;
    }

758
    return IHTMLWindow2_get_location(&This->window->base.IHTMLWindow2_iface, p);
759 760 761 762
}

static HRESULT WINAPI HTMLDocument_get_lastModified(IHTMLDocument2 *iface, BSTR *p)
{
763
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
764
    FIXME("(%p)->(%p)\n", This, p);
765 766 767 768 769
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_URL(IHTMLDocument2 *iface, BSTR v)
{
770
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
771 772 773 774 775 776 777 778

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

    if(!This->window) {
        FIXME("No window available\n");
        return E_FAIL;
    }

779
    return navigate_url(This->window, v, This->window->uri, BINDING_NAVIGATED);
780 781 782 783
}

static HRESULT WINAPI HTMLDocument_get_URL(IHTMLDocument2 *iface, BSTR *p)
{
784
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
785 786 787 788 789 790

    static const WCHAR about_blank_url[] =
        {'a','b','o','u','t',':','b','l','a','n','k',0};

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

791
    *p = SysAllocString(This->window->url ? This->window->url : about_blank_url);
792
    return *p ? S_OK : E_OUTOFMEMORY;
793 794 795 796
}

static HRESULT WINAPI HTMLDocument_put_domain(IHTMLDocument2 *iface, BSTR v)
{
797
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
798 799 800 801 802 803 804 805 806 807 808 809 810 811
    nsAString nsstr;
    nsresult nsres;

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

    nsAString_InitDepend(&nsstr, v);
    nsres = nsIDOMHTMLDocument_SetDomain(This->doc_node->nsdoc, &nsstr);
    nsAString_Finish(&nsstr);
    if(NS_FAILED(nsres)) {
        ERR("SetDomain failed: %08x\n", nsres);
        return E_INVALIDARG;
    }

    return S_OK;
812 813 814 815
}

static HRESULT WINAPI HTMLDocument_get_domain(IHTMLDocument2 *iface, BSTR *p)
{
816
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
817 818
    nsAString nsstr;
    nsresult nsres;
819 820 821

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

822 823 824 825 826 827 828 829
    nsAString_Init(&nsstr, NULL);
    nsres = nsIDOMHTMLDocument_GetDomain(This->doc_node->nsdoc, &nsstr);
    if(NS_SUCCEEDED(nsres) && This->window && This->window->uri) {
        const PRUnichar *str;
        HRESULT hres;

        nsAString_GetData(&nsstr, &str);
        if(!*str) {
830
            TRACE("Gecko returned empty string, fallback to loaded URL.\n");
831 832 833 834
            nsAString_Finish(&nsstr);
            hres = IUri_GetHost(This->window->uri, p);
            return FAILED(hres) ? hres : S_OK;
        }
835 836
    }

837
    return return_nsstr(nsres, &nsstr, p);
838 839 840 841
}

static HRESULT WINAPI HTMLDocument_put_cookie(IHTMLDocument2 *iface, BSTR v)
{
842
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
843 844 845 846 847 848 849 850 851 852 853
    BOOL bret;

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

    bret = InternetSetCookieExW(This->window->url, NULL, v, 0, 0);
    if(!bret) {
        FIXME("InternetSetCookieExW failed: %u\n", GetLastError());
        return HRESULT_FROM_WIN32(GetLastError());
    }

    return S_OK;
854 855 856 857
}

static HRESULT WINAPI HTMLDocument_get_cookie(IHTMLDocument2 *iface, BSTR *p)
{
858
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883
    DWORD size;
    BOOL bret;

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

    size = 0;
    bret = InternetGetCookieExW(This->window->url, NULL, NULL, &size, 0, NULL);
    if(!bret) {
        switch(GetLastError()) {
        case ERROR_INSUFFICIENT_BUFFER:
            break;
        case ERROR_NO_MORE_ITEMS:
            *p = NULL;
            return S_OK;
        default:
            FIXME("InternetGetCookieExW failed: %u\n", GetLastError());
            return HRESULT_FROM_WIN32(GetLastError());
        }
    }

    if(!size) {
        *p = NULL;
        return S_OK;
    }

884
    *p = SysAllocStringLen(NULL, size/sizeof(WCHAR)-1);
885 886 887 888 889 890 891 892 893 894
    if(!*p)
        return E_OUTOFMEMORY;

    bret = InternetGetCookieExW(This->window->url, NULL, *p, &size, 0, NULL);
    if(!bret) {
        ERR("InternetGetCookieExW failed: %u\n", GetLastError());
        return E_FAIL;
    }

    return S_OK;
895 896 897 898
}

static HRESULT WINAPI HTMLDocument_put_expando(IHTMLDocument2 *iface, VARIANT_BOOL v)
{
899
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
900
    FIXME("(%p)->(%x)\n", This, v);
901 902 903 904 905
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_expando(IHTMLDocument2 *iface, VARIANT_BOOL *p)
{
906
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
907
    FIXME("(%p)->(%p)\n", This, p);
908 909 910 911 912
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_charset(IHTMLDocument2 *iface, BSTR v)
{
913
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
914
    FIXME("(%p)->(%s)\n", This, debugstr_w(v));
915 916 917 918 919
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_charset(IHTMLDocument2 *iface, BSTR *p)
{
920
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
921 922 923 924 925 926 927 928 929 930 931 932 933
    nsAString charset_str;
    nsresult nsres;

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

    if(!This->doc_node->nsdoc) {
        FIXME("NULL nsdoc\n");
        return E_FAIL;
    }

    nsAString_Init(&charset_str, NULL);
    nsres = nsIDOMHTMLDocument_GetCharacterSet(This->doc_node->nsdoc, &charset_str);
    return return_nsstr(nsres, &charset_str, p);
934 935 936 937
}

static HRESULT WINAPI HTMLDocument_put_defaultCharset(IHTMLDocument2 *iface, BSTR v)
{
938
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
939
    FIXME("(%p)->(%s)\n", This, debugstr_w(v));
940 941 942 943 944
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_defaultCharset(IHTMLDocument2 *iface, BSTR *p)
{
945
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
946 947 948 949 950

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

    *p = charset_string_from_cp(GetACP());
    return *p ? S_OK : E_OUTOFMEMORY;
951 952 953 954
}

static HRESULT WINAPI HTMLDocument_get_mimeType(IHTMLDocument2 *iface, BSTR *p)
{
955
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
956
    FIXME("(%p)->(%p)\n", This, p);
957 958 959 960 961
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_fileSize(IHTMLDocument2 *iface, BSTR *p)
{
962
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
963
    FIXME("(%p)->(%p)\n", This, p);
964 965 966 967 968
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_fileCreatedDate(IHTMLDocument2 *iface, BSTR *p)
{
969
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
970
    FIXME("(%p)->(%p)\n", This, p);
971 972 973 974 975
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_fileModifiedDate(IHTMLDocument2 *iface, BSTR *p)
{
976
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
977
    FIXME("(%p)->(%p)\n", This, p);
978 979 980 981 982
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_fileUpdatedDate(IHTMLDocument2 *iface, BSTR *p)
{
983
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
984
    FIXME("(%p)->(%p)\n", This, p);
985 986 987 988 989
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_security(IHTMLDocument2 *iface, BSTR *p)
{
990
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
991
    FIXME("(%p)->(%p)\n", This, p);
992 993 994 995 996
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_protocol(IHTMLDocument2 *iface, BSTR *p)
{
997
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
998
    FIXME("(%p)->(%p)\n", This, p);
999 1000 1001 1002 1003
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_nameProp(IHTMLDocument2 *iface, BSTR *p)
{
1004
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1005
    FIXME("(%p)->(%p)\n", This, p);
1006 1007 1008
    return E_NOTIMPL;
}

1009
static HRESULT document_write(HTMLDocument *This, SAFEARRAY *psarray, BOOL ln)
1010
{
1011
    VARIANT *var, tmp;
1012
    JSContext *jsctx;
1013
    nsAString nsstr;
1014
    ULONG i, argc;
1015 1016 1017
    nsresult nsres;
    HRESULT hres;

1018
    if(!This->doc_node->nsdoc) {
1019 1020 1021 1022
        WARN("NULL nsdoc\n");
        return E_UNEXPECTED;
    }

1023 1024 1025
    if (!psarray)
        return S_OK;

1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036
    if(psarray->cDims != 1) {
        FIXME("cDims=%d\n", psarray->cDims);
        return E_INVALIDARG;
    }

    hres = SafeArrayAccessData(psarray, (void**)&var);
    if(FAILED(hres)) {
        WARN("SafeArrayAccessData failed: %08x\n", hres);
        return hres;
    }

1037
    V_VT(&tmp) = VT_EMPTY;
1038

1039
    jsctx = get_context_from_document(This->doc_node->nsdoc);
1040 1041
    argc = psarray->rgsabound[0].cElements;
    for(i=0; i < argc; i++) {
1042
        if(V_VT(var+i) == VT_BSTR) {
1043
            nsAString_InitDepend(&nsstr, V_BSTR(var+i));
1044
        }else {
1045
            hres = VariantChangeTypeEx(&tmp, var+i, MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT), 0, VT_BSTR);
1046 1047 1048 1049 1050 1051 1052 1053
            if(FAILED(hres)) {
                WARN("Could not convert %s to string\n", debugstr_variant(var+i));
                break;
            }
            nsAString_InitDepend(&nsstr, V_BSTR(&tmp));
        }

        if(!ln || i != argc-1)
1054
            nsres = nsIDOMHTMLDocument_Write(This->doc_node->nsdoc, &nsstr, jsctx);
1055
        else
1056
            nsres = nsIDOMHTMLDocument_Writeln(This->doc_node->nsdoc, &nsstr, jsctx);
1057 1058 1059 1060 1061 1062 1063
        nsAString_Finish(&nsstr);
        if(V_VT(var+i) != VT_BSTR)
            VariantClear(&tmp);
        if(NS_FAILED(nsres)) {
            ERR("Write failed: %08x\n", nsres);
            hres = E_FAIL;
            break;
1064 1065 1066 1067 1068
        }
    }

    SafeArrayUnaccessData(psarray);

1069
    return hres;
1070 1071
}

1072 1073
static HRESULT WINAPI HTMLDocument_write(IHTMLDocument2 *iface, SAFEARRAY *psarray)
{
1074
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1075 1076 1077 1078 1079 1080

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

    return document_write(This, psarray, FALSE);
}

1081 1082
static HRESULT WINAPI HTMLDocument_writeln(IHTMLDocument2 *iface, SAFEARRAY *psarray)
{
1083
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1084 1085 1086 1087

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

    return document_write(This, psarray, TRUE);
1088 1089 1090 1091 1092
}

static HRESULT WINAPI HTMLDocument_open(IHTMLDocument2 *iface, BSTR url, VARIANT name,
                        VARIANT features, VARIANT replace, IDispatch **pomWindowResult)
{
1093
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1094
    nsISupports *tmp;
1095 1096 1097 1098 1099 1100 1101
    nsresult nsres;

    static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};

    TRACE("(%p)->(%s %s %s %s %p)\n", This, debugstr_w(url), debugstr_variant(&name),
          debugstr_variant(&features), debugstr_variant(&replace), pomWindowResult);

1102
    if(!This->doc_node->nsdoc) {
1103 1104 1105 1106 1107 1108 1109 1110
        ERR("!nsdoc\n");
        return E_NOTIMPL;
    }

    if(!url || strcmpW(url, text_htmlW) || V_VT(&name) != VT_ERROR
       || V_VT(&features) != VT_ERROR || V_VT(&replace) != VT_ERROR)
        FIXME("unsupported args\n");

1111 1112
    nsres = nsIDOMHTMLDocument_Open(This->doc_node->nsdoc, NULL, NULL, NULL,
            get_context_from_document(This->doc_node->nsdoc), 0, &tmp);
1113 1114 1115 1116 1117
    if(NS_FAILED(nsres)) {
        ERR("Open failed: %08x\n", nsres);
        return E_FAIL;
    }

1118 1119 1120
    if(tmp)
        nsISupports_Release(tmp);

1121 1122
    *pomWindowResult = (IDispatch*)&This->window->base.IHTMLWindow2_iface;
    IHTMLWindow2_AddRef(&This->window->base.IHTMLWindow2_iface);
1123
    return S_OK;
1124 1125 1126 1127
}

static HRESULT WINAPI HTMLDocument_close(IHTMLDocument2 *iface)
{
1128
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1129 1130 1131 1132
    nsresult nsres;

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

1133
    if(!This->doc_node->nsdoc) {
1134 1135 1136 1137
        ERR("!nsdoc\n");
        return E_NOTIMPL;
    }

1138
    nsres = nsIDOMHTMLDocument_Close(This->doc_node->nsdoc);
1139 1140 1141 1142 1143 1144
    if(NS_FAILED(nsres)) {
        ERR("Close failed: %08x\n", nsres);
        return E_FAIL;
    }

    return S_OK;
1145 1146 1147 1148
}

static HRESULT WINAPI HTMLDocument_clear(IHTMLDocument2 *iface)
{
1149
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1150 1151 1152 1153
    nsresult nsres;

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

1154
    nsres = nsIDOMHTMLDocument_Clear(This->doc_node->nsdoc);
1155 1156 1157 1158 1159 1160
    if(NS_FAILED(nsres)) {
        ERR("Clear failed: %08x\n", nsres);
        return E_FAIL;
    }

    return S_OK;
1161 1162
}

1163 1164 1165 1166
static const WCHAR copyW[] =
    {'c','o','p','y',0};
static const WCHAR cutW[] =
    {'c','u','t',0};
1167 1168
static const WCHAR fontnameW[] =
    {'f','o','n','t','n','a','m','e',0};
1169 1170
static const WCHAR fontsizeW[] =
    {'f','o','n','t','s','i','z','e',0};
1171 1172
static const WCHAR indentW[] =
    {'i','n','d','e','n','t',0};
1173 1174 1175 1176 1177 1178
static const WCHAR insertorderedlistW[] =
    {'i','n','s','e','r','t','o','r','d','e','r','e','d','l','i','s','t',0};
static const WCHAR insertunorderedlistW[] =
    {'i','n','s','e','r','t','u','n','o','r','d','e','r','e','d','l','i','s','t',0};
static const WCHAR outdentW[] =
    {'o','u','t','d','e','n','t',0};
1179 1180
static const WCHAR pasteW[] =
    {'p','a','s','t','e',0};
1181 1182 1183 1184 1185 1186 1187
static const WCHAR respectvisibilityindesignW[] =
    {'r','e','s','p','e','c','t','v','i','s','i','b','i','l','i','t','y','i','n','d','e','s','i','g','n',0};

static const struct {
    const WCHAR *name;
    OLECMDID id;
}command_names[] = {
1188 1189
    {copyW, IDM_COPY},
    {cutW, IDM_CUT},
1190
    {fontnameW, IDM_FONTNAME},
1191
    {fontsizeW, IDM_FONTSIZE},
1192
    {indentW, IDM_INDENT},
1193 1194 1195
    {insertorderedlistW, IDM_ORDERLIST},
    {insertunorderedlistW, IDM_UNORDERLIST},
    {outdentW, IDM_OUTDENT},
1196
    {pasteW, IDM_PASTE},
1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214
    {respectvisibilityindesignW, IDM_RESPECTVISIBILITY_INDESIGN}
};

static BOOL cmdid_from_string(const WCHAR *str, OLECMDID *cmdid)
{
    int i;

    for(i = 0; i < sizeof(command_names)/sizeof(*command_names); i++) {
        if(!strcmpiW(command_names[i].name, str)) {
            *cmdid = command_names[i].id;
            return TRUE;
        }
    }

    FIXME("Unknown command %s\n", debugstr_w(str));
    return FALSE;
}

1215 1216 1217
static HRESULT WINAPI HTMLDocument_queryCommandSupported(IHTMLDocument2 *iface, BSTR cmdID,
                                                        VARIANT_BOOL *pfRet)
{
1218
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1219
    FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1220 1221 1222 1223 1224 1225
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_queryCommandEnabled(IHTMLDocument2 *iface, BSTR cmdID,
                                                        VARIANT_BOOL *pfRet)
{
1226
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1227
    FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1228 1229 1230 1231 1232 1233
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_queryCommandState(IHTMLDocument2 *iface, BSTR cmdID,
                                                        VARIANT_BOOL *pfRet)
{
1234
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1235
    FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1236 1237 1238 1239 1240 1241
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_queryCommandIndeterm(IHTMLDocument2 *iface, BSTR cmdID,
                                                        VARIANT_BOOL *pfRet)
{
1242
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1243
    FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1244 1245 1246 1247 1248 1249
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_queryCommandText(IHTMLDocument2 *iface, BSTR cmdID,
                                                        BSTR *pfRet)
{
1250
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1251
    FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1252 1253 1254 1255 1256 1257
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_queryCommandValue(IHTMLDocument2 *iface, BSTR cmdID,
                                                        VARIANT *pfRet)
{
1258
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1259
    FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1260 1261 1262 1263 1264 1265
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_execCommand(IHTMLDocument2 *iface, BSTR cmdID,
                                VARIANT_BOOL showUI, VARIANT value, VARIANT_BOOL *pfRet)
{
1266
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288
    OLECMDID cmdid;
    VARIANT ret;
    HRESULT hres;

    TRACE("(%p)->(%s %x %s %p)\n", This, debugstr_w(cmdID), showUI, debugstr_variant(&value), pfRet);

    if(!cmdid_from_string(cmdID, &cmdid))
        return OLECMDERR_E_NOTSUPPORTED;

    V_VT(&ret) = VT_EMPTY;
    hres = IOleCommandTarget_Exec(&This->IOleCommandTarget_iface, &CGID_MSHTML, cmdid,
            showUI ? 0 : OLECMDEXECOPT_DONTPROMPTUSER, &value, &ret);
    if(FAILED(hres))
        return hres;

    if(V_VT(&ret) != VT_EMPTY) {
        FIXME("Handle ret %s\n", debugstr_variant(&ret));
        VariantClear(&ret);
    }

    *pfRet = VARIANT_TRUE;
    return S_OK;
1289 1290 1291 1292 1293
}

static HRESULT WINAPI HTMLDocument_execCommandShowHelp(IHTMLDocument2 *iface, BSTR cmdID,
                                                        VARIANT_BOOL *pfRet)
{
1294
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1295
    FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1296 1297 1298 1299
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_createElement(IHTMLDocument2 *iface, BSTR eTag,
1300
                                                 IHTMLElement **newElem)
1301
{
1302
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1303
    HTMLElement *elem;
1304
    HRESULT hres;
1305 1306 1307

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

1308
    hres = create_element(This->doc_node, eTag, &elem);
1309 1310
    if(FAILED(hres))
        return hres;
1311

1312
    *newElem = &elem->IHTMLElement_iface;
1313
    return S_OK;
1314 1315 1316 1317
}

static HRESULT WINAPI HTMLDocument_put_onhelp(IHTMLDocument2 *iface, VARIANT v)
{
1318
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1319
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1320 1321 1322 1323 1324
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_onhelp(IHTMLDocument2 *iface, VARIANT *p)
{
1325
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1326
    FIXME("(%p)->(%p)\n", This, p);
1327 1328 1329 1330 1331
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_onclick(IHTMLDocument2 *iface, VARIANT v)
{
1332
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1333 1334 1335 1336

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

    return set_doc_event(This, EVENTID_CLICK, &v);
1337 1338 1339 1340
}

static HRESULT WINAPI HTMLDocument_get_onclick(IHTMLDocument2 *iface, VARIANT *p)
{
1341
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1342 1343 1344 1345

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

    return get_doc_event(This, EVENTID_CLICK, p);
1346 1347 1348 1349
}

static HRESULT WINAPI HTMLDocument_put_ondblclick(IHTMLDocument2 *iface, VARIANT v)
{
1350
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1351 1352 1353 1354

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

    return set_doc_event(This, EVENTID_DBLCLICK, &v);
1355 1356 1357 1358
}

static HRESULT WINAPI HTMLDocument_get_ondblclick(IHTMLDocument2 *iface, VARIANT *p)
{
1359
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1360 1361 1362 1363

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

    return get_doc_event(This, EVENTID_DBLCLICK, p);
1364 1365 1366 1367
}

static HRESULT WINAPI HTMLDocument_put_onkeyup(IHTMLDocument2 *iface, VARIANT v)
{
1368
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1369 1370 1371 1372

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

    return set_doc_event(This, EVENTID_KEYUP, &v);
1373 1374 1375 1376
}

static HRESULT WINAPI HTMLDocument_get_onkeyup(IHTMLDocument2 *iface, VARIANT *p)
{
1377
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1378 1379 1380 1381

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

    return get_doc_event(This, EVENTID_KEYUP, p);
1382 1383 1384 1385
}

static HRESULT WINAPI HTMLDocument_put_onkeydown(IHTMLDocument2 *iface, VARIANT v)
{
1386
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1387 1388 1389 1390

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

    return set_doc_event(This, EVENTID_KEYDOWN, &v);
1391 1392 1393 1394
}

static HRESULT WINAPI HTMLDocument_get_onkeydown(IHTMLDocument2 *iface, VARIANT *p)
{
1395
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1396 1397 1398 1399

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

    return get_doc_event(This, EVENTID_KEYDOWN, p);
1400 1401 1402 1403
}

static HRESULT WINAPI HTMLDocument_put_onkeypress(IHTMLDocument2 *iface, VARIANT v)
{
1404
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1405 1406 1407 1408

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

    return set_doc_event(This, EVENTID_KEYPRESS, &v);
1409 1410 1411 1412
}

static HRESULT WINAPI HTMLDocument_get_onkeypress(IHTMLDocument2 *iface, VARIANT *p)
{
1413
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1414 1415 1416 1417

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

    return get_doc_event(This, EVENTID_KEYPRESS, p);
1418 1419 1420 1421
}

static HRESULT WINAPI HTMLDocument_put_onmouseup(IHTMLDocument2 *iface, VARIANT v)
{
1422
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1423 1424 1425 1426

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

    return set_doc_event(This, EVENTID_MOUSEUP, &v);
1427 1428 1429 1430
}

static HRESULT WINAPI HTMLDocument_get_onmouseup(IHTMLDocument2 *iface, VARIANT *p)
{
1431
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1432 1433 1434 1435

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

    return get_doc_event(This, EVENTID_MOUSEUP, p);
1436 1437 1438 1439
}

static HRESULT WINAPI HTMLDocument_put_onmousedown(IHTMLDocument2 *iface, VARIANT v)
{
1440
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1441

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

    return set_doc_event(This, EVENTID_MOUSEDOWN, &v);
1445 1446 1447 1448
}

static HRESULT WINAPI HTMLDocument_get_onmousedown(IHTMLDocument2 *iface, VARIANT *p)
{
1449
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1450 1451 1452 1453

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

    return get_doc_event(This, EVENTID_MOUSEDOWN, p);
1454 1455 1456 1457
}

static HRESULT WINAPI HTMLDocument_put_onmousemove(IHTMLDocument2 *iface, VARIANT v)
{
1458
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1459

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

    return set_doc_event(This, EVENTID_MOUSEMOVE, &v);
1463 1464 1465 1466
}

static HRESULT WINAPI HTMLDocument_get_onmousemove(IHTMLDocument2 *iface, VARIANT *p)
{
1467
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1468 1469 1470 1471

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

    return get_doc_event(This, EVENTID_MOUSEMOVE, p);
1472 1473 1474 1475
}

static HRESULT WINAPI HTMLDocument_put_onmouseout(IHTMLDocument2 *iface, VARIANT v)
{
1476
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1477 1478 1479 1480

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

    return set_doc_event(This, EVENTID_MOUSEOUT, &v);
1481 1482 1483 1484
}

static HRESULT WINAPI HTMLDocument_get_onmouseout(IHTMLDocument2 *iface, VARIANT *p)
{
1485
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1486 1487 1488 1489

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

    return get_doc_event(This, EVENTID_MOUSEOUT, p);
1490 1491 1492 1493
}

static HRESULT WINAPI HTMLDocument_put_onmouseover(IHTMLDocument2 *iface, VARIANT v)
{
1494
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1495

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

    return set_doc_event(This, EVENTID_MOUSEOVER, &v);
1499 1500 1501 1502
}

static HRESULT WINAPI HTMLDocument_get_onmouseover(IHTMLDocument2 *iface, VARIANT *p)
{
1503
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1504 1505 1506 1507

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

    return get_doc_event(This, EVENTID_MOUSEOVER, p);
1508 1509 1510 1511
}

static HRESULT WINAPI HTMLDocument_put_onreadystatechange(IHTMLDocument2 *iface, VARIANT v)
{
1512
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1513 1514 1515 1516

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

    return set_doc_event(This, EVENTID_READYSTATECHANGE, &v);
1517 1518 1519 1520
}

static HRESULT WINAPI HTMLDocument_get_onreadystatechange(IHTMLDocument2 *iface, VARIANT *p)
{
1521
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1522 1523 1524 1525

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

    return get_doc_event(This, EVENTID_READYSTATECHANGE, p);
1526 1527 1528 1529
}

static HRESULT WINAPI HTMLDocument_put_onafterupdate(IHTMLDocument2 *iface, VARIANT v)
{
1530
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1531
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1532 1533 1534 1535 1536
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_onafterupdate(IHTMLDocument2 *iface, VARIANT *p)
{
1537
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1538
    FIXME("(%p)->(%p)\n", This, p);
1539 1540 1541 1542 1543
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_onrowexit(IHTMLDocument2 *iface, VARIANT v)
{
1544
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1545
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1546 1547 1548 1549 1550
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_onrowexit(IHTMLDocument2 *iface, VARIANT *p)
{
1551
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1552
    FIXME("(%p)->(%p)\n", This, p);
1553 1554 1555 1556 1557
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_onrowenter(IHTMLDocument2 *iface, VARIANT v)
{
1558
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1559
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1560 1561 1562 1563 1564
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_onrowenter(IHTMLDocument2 *iface, VARIANT *p)
{
1565
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1566
    FIXME("(%p)->(%p)\n", This, p);
1567 1568 1569 1570 1571
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_ondragstart(IHTMLDocument2 *iface, VARIANT v)
{
1572
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1573 1574 1575 1576

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

    return set_doc_event(This, EVENTID_DRAGSTART, &v);
1577 1578 1579 1580
}

static HRESULT WINAPI HTMLDocument_get_ondragstart(IHTMLDocument2 *iface, VARIANT *p)
{
1581
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1582 1583 1584 1585

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

    return get_doc_event(This, EVENTID_DRAGSTART, p);
1586 1587 1588 1589
}

static HRESULT WINAPI HTMLDocument_put_onselectstart(IHTMLDocument2 *iface, VARIANT v)
{
1590
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1591 1592 1593 1594

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

    return set_doc_event(This, EVENTID_SELECTSTART, &v);
1595 1596 1597 1598
}

static HRESULT WINAPI HTMLDocument_get_onselectstart(IHTMLDocument2 *iface, VARIANT *p)
{
1599
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1600 1601 1602 1603

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

    return get_doc_event(This, EVENTID_SELECTSTART, p);
1604 1605
}

1606
static HRESULT WINAPI HTMLDocument_elementFromPoint(IHTMLDocument2 *iface, LONG x, LONG y,
1607 1608
                                                        IHTMLElement **elementHit)
{
1609
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1610 1611 1612 1613 1614 1615 1616
    nsIDOMElement *nselem;
    HTMLDOMNode *node;
    nsresult nsres;
    HRESULT hres;

    TRACE("(%p)->(%d %d %p)\n", This, x, y, elementHit);

1617
    nsres = nsIDOMHTMLDocument_ElementFromPoint(This->doc_node->nsdoc, x, y, &nselem);
1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632
    if(NS_FAILED(nsres)) {
        ERR("ElementFromPoint failed: %08x\n", nsres);
        return E_FAIL;
    }

    if(!nselem) {
        *elementHit = NULL;
        return S_OK;
    }

    hres = get_node(This->doc_node, (nsIDOMNode*)nselem, TRUE, &node);
    nsIDOMElement_Release(nselem);
    if(FAILED(hres))
        return hres;

1633 1634 1635
    hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)elementHit);
    node_release(node);
    return hres;
1636 1637 1638 1639
}

static HRESULT WINAPI HTMLDocument_get_parentWindow(IHTMLDocument2 *iface, IHTMLWindow2 **p)
{
1640
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1641 1642 1643

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

1644
    *p = &This->window->base.IHTMLWindow2_iface;
1645 1646
    IHTMLWindow2_AddRef(*p);
    return S_OK;
1647 1648 1649
}

static HRESULT WINAPI HTMLDocument_get_styleSheets(IHTMLDocument2 *iface,
1650
                                                   IHTMLStyleSheetsCollection **p)
1651
{
1652
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1653 1654 1655 1656 1657 1658 1659
    nsIDOMStyleSheetList *nsstylelist;
    nsresult nsres;

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

    *p = NULL;

1660
    if(!This->doc_node->nsdoc) {
1661 1662
        WARN("NULL nsdoc\n");
        return E_UNEXPECTED;
1663 1664
    }

1665
    nsres = nsIDOMHTMLDocument_GetStyleSheets(This->doc_node->nsdoc, &nsstylelist);
1666 1667 1668 1669
    if(NS_FAILED(nsres)) {
        ERR("GetStyleSheets failed: %08x\n", nsres);
        return E_FAIL;
    }
1670 1671

    *p = HTMLStyleSheetsCollection_Create(nsstylelist);
1672
    nsIDOMStyleSheetList_Release(nsstylelist);
1673 1674

    return S_OK;
1675 1676 1677 1678
}

static HRESULT WINAPI HTMLDocument_put_onbeforeupdate(IHTMLDocument2 *iface, VARIANT v)
{
1679
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1680
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1681 1682 1683 1684 1685
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_onbeforeupdate(IHTMLDocument2 *iface, VARIANT *p)
{
1686
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1687
    FIXME("(%p)->(%p)\n", This, p);
1688 1689 1690 1691 1692
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_onerrorupdate(IHTMLDocument2 *iface, VARIANT v)
{
1693
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1694
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1695 1696 1697 1698 1699
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_onerrorupdate(IHTMLDocument2 *iface, VARIANT *p)
{
1700
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1701
    FIXME("(%p)->(%p)\n", This, p);
1702 1703 1704 1705 1706
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_toString(IHTMLDocument2 *iface, BSTR *String)
{
1707
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718

    static const WCHAR objectW[] = {'[','o','b','j','e','c','t',']',0};

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

    if(!String)
        return E_INVALIDARG;

    *String = SysAllocString(objectW);
    return *String ? S_OK : E_OUTOFMEMORY;

1719 1720 1721
}

static HRESULT WINAPI HTMLDocument_createStyleSheet(IHTMLDocument2 *iface, BSTR bstrHref,
1722
                                            LONG lIndex, IHTMLStyleSheet **ppnewStyleSheet)
1723
{
1724
    HTMLDocument *This = impl_from_IHTMLDocument2(iface);
1725 1726 1727 1728 1729
    nsIDOMHTMLHeadElement *head_elem;
    IHTMLStyleElement *style_elem;
    HTMLElement *elem;
    nsresult nsres;
    HRESULT hres;
1730

1731
    static const WCHAR styleW[] = {'s','t','y','l','e',0};
1732

1733 1734 1735 1736 1737 1738 1739 1740 1741 1742
    TRACE("(%p)->(%s %d %p)\n", This, debugstr_w(bstrHref), lIndex, ppnewStyleSheet);

    if(!This->doc_node->nsdoc) {
        FIXME("not a real doc object\n");
        return E_NOTIMPL;
    }

    if(lIndex != -1)
        FIXME("Unsupported lIndex %d\n", lIndex);

1743
    if(bstrHref && *bstrHref) {
1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754
        FIXME("semi-stub for href %s\n", debugstr_w(bstrHref));
        *ppnewStyleSheet = HTMLStyleSheet_Create(NULL);
        return S_OK;
    }

    hres = create_element(This->doc_node, styleW, &elem);
    if(FAILED(hres))
        return hres;

    nsres = nsIDOMHTMLDocument_GetHead(This->doc_node->nsdoc, &head_elem);
    if(NS_SUCCEEDED(nsres)) {
1755
        nsIDOMNode *head_node, *tmp_node;
1756

1757
        nsres = nsIDOMHTMLHeadElement_QueryInterface(head_elem, &IID_nsIDOMNode, (void**)&head_node);
1758
        nsIDOMHTMLHeadElement_Release(head_elem);
1759 1760 1761 1762
        assert(nsres == NS_OK);

        nsres = nsIDOMNode_AppendChild(head_node, elem->node.nsnode, &tmp_node);
        nsIDOMNode_Release(head_node);
1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777
        if(NS_SUCCEEDED(nsres) && tmp_node)
            nsIDOMNode_Release(tmp_node);
    }
    if(NS_FAILED(nsres)) {
        IHTMLElement_Release(&elem->IHTMLElement_iface);
        return E_FAIL;
    }

    hres = IHTMLElement_QueryInterface(&elem->IHTMLElement_iface, &IID_IHTMLStyleElement, (void**)&style_elem);
    assert(hres == S_OK);
    IHTMLElement_Release(&elem->IHTMLElement_iface);

    hres = IHTMLStyleElement_get_styleSheet(style_elem, ppnewStyleSheet);
    IHTMLStyleElement_Release(style_elem);
    return hres;
1778 1779
}

1780
static const IHTMLDocument2Vtbl HTMLDocumentVtbl = {
1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898
    HTMLDocument_QueryInterface,
    HTMLDocument_AddRef,
    HTMLDocument_Release,
    HTMLDocument_GetTypeInfoCount,
    HTMLDocument_GetTypeInfo,
    HTMLDocument_GetIDsOfNames,
    HTMLDocument_Invoke,
    HTMLDocument_get_Script,
    HTMLDocument_get_all,
    HTMLDocument_get_body,
    HTMLDocument_get_activeElement,
    HTMLDocument_get_images,
    HTMLDocument_get_applets,
    HTMLDocument_get_links,
    HTMLDocument_get_forms,
    HTMLDocument_get_anchors,
    HTMLDocument_put_title,
    HTMLDocument_get_title,
    HTMLDocument_get_scripts,
    HTMLDocument_put_designMode,
    HTMLDocument_get_designMode,
    HTMLDocument_get_selection,
    HTMLDocument_get_readyState,
    HTMLDocument_get_frames,
    HTMLDocument_get_embeds,
    HTMLDocument_get_plugins,
    HTMLDocument_put_alinkColor,
    HTMLDocument_get_alinkColor,
    HTMLDocument_put_bgColor,
    HTMLDocument_get_bgColor,
    HTMLDocument_put_fgColor,
    HTMLDocument_get_fgColor,
    HTMLDocument_put_linkColor,
    HTMLDocument_get_linkColor,
    HTMLDocument_put_vlinkColor,
    HTMLDocument_get_vlinkColor,
    HTMLDocument_get_referrer,
    HTMLDocument_get_location,
    HTMLDocument_get_lastModified,
    HTMLDocument_put_URL,
    HTMLDocument_get_URL,
    HTMLDocument_put_domain,
    HTMLDocument_get_domain,
    HTMLDocument_put_cookie,
    HTMLDocument_get_cookie,
    HTMLDocument_put_expando,
    HTMLDocument_get_expando,
    HTMLDocument_put_charset,
    HTMLDocument_get_charset,
    HTMLDocument_put_defaultCharset,
    HTMLDocument_get_defaultCharset,
    HTMLDocument_get_mimeType,
    HTMLDocument_get_fileSize,
    HTMLDocument_get_fileCreatedDate,
    HTMLDocument_get_fileModifiedDate,
    HTMLDocument_get_fileUpdatedDate,
    HTMLDocument_get_security,
    HTMLDocument_get_protocol,
    HTMLDocument_get_nameProp,
    HTMLDocument_write,
    HTMLDocument_writeln,
    HTMLDocument_open,
    HTMLDocument_close,
    HTMLDocument_clear,
    HTMLDocument_queryCommandSupported,
    HTMLDocument_queryCommandEnabled,
    HTMLDocument_queryCommandState,
    HTMLDocument_queryCommandIndeterm,
    HTMLDocument_queryCommandText,
    HTMLDocument_queryCommandValue,
    HTMLDocument_execCommand,
    HTMLDocument_execCommandShowHelp,
    HTMLDocument_createElement,
    HTMLDocument_put_onhelp,
    HTMLDocument_get_onhelp,
    HTMLDocument_put_onclick,
    HTMLDocument_get_onclick,
    HTMLDocument_put_ondblclick,
    HTMLDocument_get_ondblclick,
    HTMLDocument_put_onkeyup,
    HTMLDocument_get_onkeyup,
    HTMLDocument_put_onkeydown,
    HTMLDocument_get_onkeydown,
    HTMLDocument_put_onkeypress,
    HTMLDocument_get_onkeypress,
    HTMLDocument_put_onmouseup,
    HTMLDocument_get_onmouseup,
    HTMLDocument_put_onmousedown,
    HTMLDocument_get_onmousedown,
    HTMLDocument_put_onmousemove,
    HTMLDocument_get_onmousemove,
    HTMLDocument_put_onmouseout,
    HTMLDocument_get_onmouseout,
    HTMLDocument_put_onmouseover,
    HTMLDocument_get_onmouseover,
    HTMLDocument_put_onreadystatechange,
    HTMLDocument_get_onreadystatechange,
    HTMLDocument_put_onafterupdate,
    HTMLDocument_get_onafterupdate,
    HTMLDocument_put_onrowexit,
    HTMLDocument_get_onrowexit,
    HTMLDocument_put_onrowenter,
    HTMLDocument_get_onrowenter,
    HTMLDocument_put_ondragstart,
    HTMLDocument_get_ondragstart,
    HTMLDocument_put_onselectstart,
    HTMLDocument_get_onselectstart,
    HTMLDocument_elementFromPoint,
    HTMLDocument_get_parentWindow,
    HTMLDocument_get_styleSheets,
    HTMLDocument_put_onbeforeupdate,
    HTMLDocument_get_onbeforeupdate,
    HTMLDocument_put_onerrorupdate,
    HTMLDocument_get_onerrorupdate,
    HTMLDocument_toString,
    HTMLDocument_createStyleSheet
};

1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963
static inline HTMLDocument *impl_from_IHTMLDocument3(IHTMLDocument3 *iface)
{
    return CONTAINING_RECORD(iface, HTMLDocument, IHTMLDocument3_iface);
}

static HRESULT WINAPI HTMLDocument3_QueryInterface(IHTMLDocument3 *iface,
                                                  REFIID riid, void **ppv)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    return htmldoc_query_interface(This, riid, ppv);
}

static ULONG WINAPI HTMLDocument3_AddRef(IHTMLDocument3 *iface)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    return htmldoc_addref(This);
}

static ULONG WINAPI HTMLDocument3_Release(IHTMLDocument3 *iface)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    return htmldoc_release(This);
}

static HRESULT WINAPI HTMLDocument3_GetTypeInfoCount(IHTMLDocument3 *iface, UINT *pctinfo)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
}

static HRESULT WINAPI HTMLDocument3_GetTypeInfo(IHTMLDocument3 *iface, UINT iTInfo,
                                                LCID lcid, ITypeInfo **ppTInfo)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
}

static HRESULT WINAPI HTMLDocument3_GetIDsOfNames(IHTMLDocument3 *iface, REFIID riid,
                                                LPOLESTR *rgszNames, UINT cNames,
                                                LCID lcid, DISPID *rgDispId)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
            rgDispId);
}

static HRESULT WINAPI HTMLDocument3_Invoke(IHTMLDocument3 *iface, DISPID dispIdMember,
                            REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
                            VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
            pDispParams, pVarResult, pExcepInfo, puArgErr);
}

static HRESULT WINAPI HTMLDocument3_releaseCapture(IHTMLDocument3 *iface)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    FIXME("(%p)\n", This);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument3_recalc(IHTMLDocument3 *iface, VARIANT_BOOL fForce)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
1964 1965 1966 1967 1968

    WARN("(%p)->(%x)\n", This, fForce);

    /* Doing nothing here should be fine for us. */
    return S_OK;
1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045
}

static HRESULT WINAPI HTMLDocument3_createTextNode(IHTMLDocument3 *iface, BSTR text,
                                                   IHTMLDOMNode **newTextNode)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    nsIDOMText *nstext;
    HTMLDOMNode *node;
    nsAString text_str;
    nsresult nsres;
    HRESULT hres;

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

    if(!This->doc_node->nsdoc) {
        WARN("NULL nsdoc\n");
        return E_UNEXPECTED;
    }

    nsAString_InitDepend(&text_str, text);
    nsres = nsIDOMHTMLDocument_CreateTextNode(This->doc_node->nsdoc, &text_str, &nstext);
    nsAString_Finish(&text_str);
    if(NS_FAILED(nsres)) {
        ERR("CreateTextNode failed: %08x\n", nsres);
        return E_FAIL;
    }

    hres = HTMLDOMTextNode_Create(This->doc_node, (nsIDOMNode*)nstext, &node);
    nsIDOMText_Release(nstext);
    if(FAILED(hres))
        return hres;

    *newTextNode = &node->IHTMLDOMNode_iface;
    return S_OK;
}

static HRESULT WINAPI HTMLDocument3_get_documentElement(IHTMLDocument3 *iface, IHTMLElement **p)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    nsIDOMElement *nselem = NULL;
    HTMLDOMNode *node;
    nsresult nsres;
    HRESULT hres;

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

    if(This->window->readystate == READYSTATE_UNINITIALIZED) {
        *p = NULL;
        return S_OK;
    }

    if(!This->doc_node->nsdoc) {
        WARN("NULL nsdoc\n");
        return E_UNEXPECTED;
    }

    nsres = nsIDOMHTMLDocument_GetDocumentElement(This->doc_node->nsdoc, &nselem);
    if(NS_FAILED(nsres)) {
        ERR("GetDocumentElement failed: %08x\n", nsres);
        return E_FAIL;
    }

    if(!nselem) {
        *p = NULL;
        return S_OK;
    }

    hres = get_node(This->doc_node, (nsIDOMNode *)nselem, TRUE, &node);
    nsIDOMElement_Release(nselem);
    if(FAILED(hres))
        return hres;

    hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)p);
    node_release(node);
    return hres;
}

2046
static HRESULT WINAPI HTMLDocument3_get_uniqueID(IHTMLDocument3 *iface, BSTR *p)
2047 2048
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
2049 2050 2051

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

2052
    return elem_unique_id(++This->doc_node->unique_id, p);
2053 2054 2055 2056 2057 2058 2059 2060 2061
}

static HRESULT WINAPI HTMLDocument3_attachEvent(IHTMLDocument3 *iface, BSTR event,
                                                IDispatch* pDisp, VARIANT_BOOL *pfResult)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);

    TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(event), pDisp, pfResult);

2062
    return attach_event(&This->doc_node->node.event_target, event, pDisp, pfResult);
2063 2064 2065 2066 2067 2068 2069 2070 2071
}

static HRESULT WINAPI HTMLDocument3_detachEvent(IHTMLDocument3 *iface, BSTR event,
                                                IDispatch *pDisp)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);

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

2072
    return detach_event(&This->doc_node->node.event_target, event, pDisp);
2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175
}

static HRESULT WINAPI HTMLDocument3_put_onrowsdelete(IHTMLDocument3 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    FIXME("(%p)->()\n", This);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument3_get_onrowsdelete(IHTMLDocument3 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument3_put_onrowsinserted(IHTMLDocument3 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    FIXME("(%p)->()\n", This);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument3_get_onrowsinserted(IHTMLDocument3 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument3_put_oncellchange(IHTMLDocument3 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    FIXME("(%p)->()\n", This);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument3_get_oncellchange(IHTMLDocument3 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument3_put_ondatasetchanged(IHTMLDocument3 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    FIXME("(%p)->()\n", This);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument3_get_ondatasetchanged(IHTMLDocument3 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument3_put_ondataavailable(IHTMLDocument3 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    FIXME("(%p)->()\n", This);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument3_get_ondataavailable(IHTMLDocument3 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument3_put_ondatasetcomplete(IHTMLDocument3 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    FIXME("(%p)->()\n", This);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument3_get_ondatasetcomplete(IHTMLDocument3 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument3_put_onpropertychange(IHTMLDocument3 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    FIXME("(%p)->()\n", This);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument3_get_onpropertychange(IHTMLDocument3 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument3_put_dir(IHTMLDocument3 *iface, BSTR v)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194
    nsAString dir_str;
    nsresult nsres;

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

    if(!This->doc_node->nsdoc) {
        FIXME("NULL nsdoc\n");
        return E_UNEXPECTED;
    }

    nsAString_InitDepend(&dir_str, v);
    nsres = nsIDOMHTMLDocument_SetDir(This->doc_node->nsdoc, &dir_str);
    nsAString_Finish(&dir_str);
    if(NS_FAILED(nsres)) {
        ERR("SetDir failed: %08x\n", nsres);
        return E_FAIL;
    }

    return S_OK;
2195 2196 2197 2198 2199
}

static HRESULT WINAPI HTMLDocument3_get_dir(IHTMLDocument3 *iface, BSTR *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
2200 2201 2202 2203 2204 2205 2206 2207 2208 2209
    nsAString dir_str;
    nsresult nsres;

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

    if(!This->doc_node->nsdoc) {
        FIXME("NULL nsdoc\n");
        return E_UNEXPECTED;
    }

2210
    nsAString_Init(&dir_str, NULL);
2211 2212
    nsres = nsIDOMHTMLDocument_GetDir(This->doc_node->nsdoc, &dir_str);
    return return_nsstr(nsres, &dir_str, p);
2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384
}

static HRESULT WINAPI HTMLDocument3_put_oncontextmenu(IHTMLDocument3 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);

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

    return set_doc_event(This, EVENTID_CONTEXTMENU, &v);
}

static HRESULT WINAPI HTMLDocument3_get_oncontextmenu(IHTMLDocument3 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);

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

    return get_doc_event(This, EVENTID_CONTEXTMENU, p);
}

static HRESULT WINAPI HTMLDocument3_put_onstop(IHTMLDocument3 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    FIXME("(%p)->()\n", This);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument3_get_onstop(IHTMLDocument3 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument3_createDocumentFragment(IHTMLDocument3 *iface,
                                                           IHTMLDocument2 **ppNewDoc)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    nsIDOMDocumentFragment *doc_frag;
    HTMLDocumentNode *docnode;
    nsresult nsres;
    HRESULT hres;

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

    if(!This->doc_node->nsdoc) {
        FIXME("NULL nsdoc\n");
        return E_NOTIMPL;
    }

    nsres = nsIDOMHTMLDocument_CreateDocumentFragment(This->doc_node->nsdoc, &doc_frag);
    if(NS_FAILED(nsres)) {
        ERR("CreateDocumentFragment failed: %08x\n", nsres);
        return E_FAIL;
    }

    hres = create_document_fragment((nsIDOMNode*)doc_frag, This->doc_node, &docnode);
    nsIDOMDocumentFragment_Release(doc_frag);
    if(FAILED(hres))
        return hres;

    *ppNewDoc = &docnode->basedoc.IHTMLDocument2_iface;
    return S_OK;
}

static HRESULT WINAPI HTMLDocument3_get_parentDocument(IHTMLDocument3 *iface,
                                                       IHTMLDocument2 **p)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument3_put_enableDownload(IHTMLDocument3 *iface,
                                                       VARIANT_BOOL v)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    FIXME("(%p)->(%x)\n", This, v);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument3_get_enableDownload(IHTMLDocument3 *iface,
                                                       VARIANT_BOOL *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument3_put_baseUrl(IHTMLDocument3 *iface, BSTR v)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_w(v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument3_get_baseUrl(IHTMLDocument3 *iface, BSTR *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument3_get_childNodes(IHTMLDocument3 *iface, IDispatch **p)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);

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

    return IHTMLDOMNode_get_childNodes(&This->doc_node->node.IHTMLDOMNode_iface, p);
}

static HRESULT WINAPI HTMLDocument3_put_inheritStyleSheets(IHTMLDocument3 *iface,
                                                           VARIANT_BOOL v)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    FIXME("(%p)->()\n", This);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument3_get_inheritStyleSheets(IHTMLDocument3 *iface,
                                                           VARIANT_BOOL *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument3_put_onbeforeeditfocus(IHTMLDocument3 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    FIXME("(%p)->()\n", This);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument3_get_onbeforeeditfocus(IHTMLDocument3 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument3_getElementsByName(IHTMLDocument3 *iface, BSTR v,
                                                      IHTMLElementCollection **ppelColl)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    nsIDOMNodeList *node_list;
    nsAString selector_str;
    WCHAR *selector;
    nsresult nsres;

    static const WCHAR formatW[] = {'*','[','i','d','=','%','s',']',',','*','[','n','a','m','e','=','%','s',']',0};

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

    if(!This->doc_node || !This->doc_node->nsdoc) {
        /* We should probably return an empty collection. */
        FIXME("No nsdoc\n");
        return E_NOTIMPL;
    }

    selector = heap_alloc(2*SysStringLen(v)*sizeof(WCHAR) + sizeof(formatW));
    if(!selector)
        return E_OUTOFMEMORY;
    sprintfW(selector, formatW, v, v);

    /*
     * NOTE: IE getElementsByName implementation differs from Gecko. It searches both name and id attributes.
     * That's why we use CSS selector instead. We should also use name only when it applies to given element
     * types and search should be case insensitive. Those are currently not supported properly.
     */
    nsAString_InitDepend(&selector_str, selector);
2385
    nsres = nsIDOMHTMLDocument_QuerySelectorAll(This->doc_node->nsdoc, &selector_str, &node_list);
2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428
    nsAString_Finish(&selector_str);
    heap_free(selector);
    if(NS_FAILED(nsres)) {
        ERR("QuerySelectorAll failed: %08x\n", nsres);
        return E_FAIL;
    }

    *ppelColl = create_collection_from_nodelist(This->doc_node, node_list);
    nsIDOMNodeList_Release(node_list);
    return S_OK;
}


static HRESULT WINAPI HTMLDocument3_getElementById(IHTMLDocument3 *iface, BSTR v,
                                                   IHTMLElement **pel)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    HTMLElement *elem;
    HRESULT hres;

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

    hres = get_doc_elem_by_id(This->doc_node, v, &elem);
    if(FAILED(hres) || !elem) {
        *pel = NULL;
        return hres;
    }

    *pel = &elem->IHTMLElement_iface;
    return S_OK;
}


static HRESULT WINAPI HTMLDocument3_getElementsByTagName(IHTMLDocument3 *iface, BSTR v,
                                                         IHTMLElementCollection **pelColl)
{
    HTMLDocument *This = impl_from_IHTMLDocument3(iface);
    nsIDOMNodeList *nslist;
    nsAString id_str;
    nsresult nsres;

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

2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449
    if(This->doc_node->nsdoc) {
        nsAString_InitDepend(&id_str, v);
        nsres = nsIDOMHTMLDocument_GetElementsByTagName(This->doc_node->nsdoc, &id_str, &nslist);
        nsAString_Finish(&id_str);
        if(FAILED(nsres)) {
            ERR("GetElementByName failed: %08x\n", nsres);
            return E_FAIL;
        }
    }else {
        nsIDOMDocumentFragment *docfrag;
        nsAString nsstr;

        if(v) {
            const WCHAR *ptr;
            for(ptr=v; *ptr; ptr++) {
                if(!isalnumW(*ptr)) {
                    FIXME("Unsupported invalid tag %s\n", debugstr_w(v));
                    return E_NOTIMPL;
                }
            }
        }
2450

2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464
        nsres = nsIDOMNode_QueryInterface(This->doc_node->node.nsnode, &IID_nsIDOMDocumentFragment, (void**)&docfrag);
        if(NS_FAILED(nsres)) {
            ERR("Could not get nsIDOMDocumentFragment iface: %08x\n", nsres);
            return E_UNEXPECTED;
        }

        nsAString_InitDepend(&nsstr, v);
        nsres = nsIDOMDocumentFragment_QuerySelectorAll(docfrag, &nsstr, &nslist);
        nsAString_Finish(&nsstr);
        nsIDOMDocumentFragment_Release(docfrag);
        if(NS_FAILED(nsres)) {
            ERR("QuerySelectorAll failed: %08x\n", nsres);
            return E_FAIL;
        }
2465 2466
    }

2467

2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485
    *pelColl = create_collection_from_nodelist(This->doc_node, nslist);
    nsIDOMNodeList_Release(nslist);

    return S_OK;
}

static const IHTMLDocument3Vtbl HTMLDocument3Vtbl = {
    HTMLDocument3_QueryInterface,
    HTMLDocument3_AddRef,
    HTMLDocument3_Release,
    HTMLDocument3_GetTypeInfoCount,
    HTMLDocument3_GetTypeInfo,
    HTMLDocument3_GetIDsOfNames,
    HTMLDocument3_Invoke,
    HTMLDocument3_releaseCapture,
    HTMLDocument3_recalc,
    HTMLDocument3_createTextNode,
    HTMLDocument3_get_documentElement,
2486
    HTMLDocument3_get_uniqueID,
2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606
    HTMLDocument3_attachEvent,
    HTMLDocument3_detachEvent,
    HTMLDocument3_put_onrowsdelete,
    HTMLDocument3_get_onrowsdelete,
    HTMLDocument3_put_onrowsinserted,
    HTMLDocument3_get_onrowsinserted,
    HTMLDocument3_put_oncellchange,
    HTMLDocument3_get_oncellchange,
    HTMLDocument3_put_ondatasetchanged,
    HTMLDocument3_get_ondatasetchanged,
    HTMLDocument3_put_ondataavailable,
    HTMLDocument3_get_ondataavailable,
    HTMLDocument3_put_ondatasetcomplete,
    HTMLDocument3_get_ondatasetcomplete,
    HTMLDocument3_put_onpropertychange,
    HTMLDocument3_get_onpropertychange,
    HTMLDocument3_put_dir,
    HTMLDocument3_get_dir,
    HTMLDocument3_put_oncontextmenu,
    HTMLDocument3_get_oncontextmenu,
    HTMLDocument3_put_onstop,
    HTMLDocument3_get_onstop,
    HTMLDocument3_createDocumentFragment,
    HTMLDocument3_get_parentDocument,
    HTMLDocument3_put_enableDownload,
    HTMLDocument3_get_enableDownload,
    HTMLDocument3_put_baseUrl,
    HTMLDocument3_get_baseUrl,
    HTMLDocument3_get_childNodes,
    HTMLDocument3_put_inheritStyleSheets,
    HTMLDocument3_get_inheritStyleSheets,
    HTMLDocument3_put_onbeforeeditfocus,
    HTMLDocument3_get_onbeforeeditfocus,
    HTMLDocument3_getElementsByName,
    HTMLDocument3_getElementById,
    HTMLDocument3_getElementsByTagName
};

static inline HTMLDocument *impl_from_IHTMLDocument4(IHTMLDocument4 *iface)
{
    return CONTAINING_RECORD(iface, HTMLDocument, IHTMLDocument4_iface);
}

static HRESULT WINAPI HTMLDocument4_QueryInterface(IHTMLDocument4 *iface,
                                                   REFIID riid, void **ppv)
{
    HTMLDocument *This = impl_from_IHTMLDocument4(iface);
    return htmldoc_query_interface(This, riid, ppv);
}

static ULONG WINAPI HTMLDocument4_AddRef(IHTMLDocument4 *iface)
{
    HTMLDocument *This = impl_from_IHTMLDocument4(iface);
    return htmldoc_addref(This);
}

static ULONG WINAPI HTMLDocument4_Release(IHTMLDocument4 *iface)
{
    HTMLDocument *This = impl_from_IHTMLDocument4(iface);
    return htmldoc_release(This);
}

static HRESULT WINAPI HTMLDocument4_GetTypeInfoCount(IHTMLDocument4 *iface, UINT *pctinfo)
{
    HTMLDocument *This = impl_from_IHTMLDocument4(iface);
    return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
}

static HRESULT WINAPI HTMLDocument4_GetTypeInfo(IHTMLDocument4 *iface, UINT iTInfo,
                                                LCID lcid, ITypeInfo **ppTInfo)
{
    HTMLDocument *This = impl_from_IHTMLDocument4(iface);
    return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
}

static HRESULT WINAPI HTMLDocument4_GetIDsOfNames(IHTMLDocument4 *iface, REFIID riid,
                                                LPOLESTR *rgszNames, UINT cNames,
                                                LCID lcid, DISPID *rgDispId)
{
    HTMLDocument *This = impl_from_IHTMLDocument4(iface);
    return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
            rgDispId);
}

static HRESULT WINAPI HTMLDocument4_Invoke(IHTMLDocument4 *iface, DISPID dispIdMember,
                            REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
                            VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
    HTMLDocument *This = impl_from_IHTMLDocument4(iface);
    return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
            pDispParams, pVarResult, pExcepInfo, puArgErr);
}

static HRESULT WINAPI HTMLDocument4_focus(IHTMLDocument4 *iface)
{
    HTMLDocument *This = impl_from_IHTMLDocument4(iface);
    nsIDOMHTMLElement *nsbody;
    nsresult nsres;

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

    nsres = nsIDOMHTMLDocument_GetBody(This->doc_node->nsdoc, &nsbody);
    if(NS_FAILED(nsres) || !nsbody) {
        ERR("GetBody failed: %08x\n", nsres);
        return E_FAIL;
    }

    nsres = nsIDOMHTMLElement_Focus(nsbody);
    nsIDOMHTMLElement_Release(nsbody);
    if(NS_FAILED(nsres)) {
        ERR("Focus failed: %08x\n", nsres);
        return E_FAIL;
    }

    return S_OK;
}

static HRESULT WINAPI HTMLDocument4_hasFocus(IHTMLDocument4 *iface, VARIANT_BOOL *pfFocus)
{
    HTMLDocument *This = impl_from_IHTMLDocument4(iface);
2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621
    cpp_bool has_focus;
    nsresult nsres;

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

    if(!This->doc_node->nsdoc) {
        FIXME("Unimplemented for fragments.\n");
        return E_NOTIMPL;
    }

    nsres = nsIDOMHTMLDocument_HasFocus(This->doc_node->nsdoc, &has_focus);
    assert(nsres == NS_OK);

    *pfFocus = has_focus ? VARIANT_TRUE : VARIANT_FALSE;
    return S_OK;
2622 2623 2624 2625 2626
}

static HRESULT WINAPI HTMLDocument4_put_onselectionchange(IHTMLDocument4 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument4(iface);
2627 2628 2629 2630

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

    return set_doc_event(This, EVENTID_SELECTIONCHANGE, &v);
2631 2632 2633 2634 2635
}

static HRESULT WINAPI HTMLDocument4_get_onselectionchange(IHTMLDocument4 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument4(iface);
2636 2637 2638 2639

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

    return get_doc_event(This, EVENTID_SELECTIONCHANGE, p);
2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805
}

static HRESULT WINAPI HTMLDocument4_get_namespace(IHTMLDocument4 *iface, IDispatch **p)
{
    HTMLDocument *This = impl_from_IHTMLDocument4(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument4_createDocumentFromUrl(IHTMLDocument4 *iface, BSTR bstrUrl,
        BSTR bstrOptions, IHTMLDocument2 **newDoc)
{
    HTMLDocument *This = impl_from_IHTMLDocument4(iface);
    FIXME("(%p)->(%s %s %p)\n", This, debugstr_w(bstrUrl), debugstr_w(bstrOptions), newDoc);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument4_put_media(IHTMLDocument4 *iface, BSTR v)
{
    HTMLDocument *This = impl_from_IHTMLDocument4(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_w(v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument4_get_media(IHTMLDocument4 *iface, BSTR *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument4(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument4_createEventObject(IHTMLDocument4 *iface,
        VARIANT *pvarEventObject, IHTMLEventObj **ppEventObj)
{
    HTMLDocument *This = impl_from_IHTMLDocument4(iface);

    TRACE("(%p)->(%s %p)\n", This, debugstr_variant(pvarEventObject), ppEventObj);

    if(pvarEventObject && V_VT(pvarEventObject) != VT_ERROR && V_VT(pvarEventObject) != VT_EMPTY) {
        FIXME("unsupported pvarEventObject %s\n", debugstr_variant(pvarEventObject));
        return E_NOTIMPL;
    }

    return create_event_obj(ppEventObj);
}

static HRESULT WINAPI HTMLDocument4_fireEvent(IHTMLDocument4 *iface, BSTR bstrEventName,
        VARIANT *pvarEventObject, VARIANT_BOOL *pfCanceled)
{
    HTMLDocument *This = impl_from_IHTMLDocument4(iface);

    TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(bstrEventName), pvarEventObject, pfCanceled);

    return dispatch_event(&This->doc_node->node, bstrEventName, pvarEventObject, pfCanceled);
}

static HRESULT WINAPI HTMLDocument4_createRenderStyle(IHTMLDocument4 *iface, BSTR v,
        IHTMLRenderStyle **ppIHTMLRenderStyle)
{
    HTMLDocument *This = impl_from_IHTMLDocument4(iface);
    FIXME("(%p)->(%s %p)\n", This, debugstr_w(v), ppIHTMLRenderStyle);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument4_put_oncontrolselect(IHTMLDocument4 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument4(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument4_get_oncontrolselect(IHTMLDocument4 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument4(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument4_get_URLEncoded(IHTMLDocument4 *iface, BSTR *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument4(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static const IHTMLDocument4Vtbl HTMLDocument4Vtbl = {
    HTMLDocument4_QueryInterface,
    HTMLDocument4_AddRef,
    HTMLDocument4_Release,
    HTMLDocument4_GetTypeInfoCount,
    HTMLDocument4_GetTypeInfo,
    HTMLDocument4_GetIDsOfNames,
    HTMLDocument4_Invoke,
    HTMLDocument4_focus,
    HTMLDocument4_hasFocus,
    HTMLDocument4_put_onselectionchange,
    HTMLDocument4_get_onselectionchange,
    HTMLDocument4_get_namespace,
    HTMLDocument4_createDocumentFromUrl,
    HTMLDocument4_put_media,
    HTMLDocument4_get_media,
    HTMLDocument4_createEventObject,
    HTMLDocument4_fireEvent,
    HTMLDocument4_createRenderStyle,
    HTMLDocument4_put_oncontrolselect,
    HTMLDocument4_get_oncontrolselect,
    HTMLDocument4_get_URLEncoded
};

static inline HTMLDocument *impl_from_IHTMLDocument5(IHTMLDocument5 *iface)
{
    return CONTAINING_RECORD(iface, HTMLDocument, IHTMLDocument5_iface);
}

static HRESULT WINAPI HTMLDocument5_QueryInterface(IHTMLDocument5 *iface,
        REFIID riid, void **ppv)
{
    HTMLDocument *This = impl_from_IHTMLDocument5(iface);
    return htmldoc_query_interface(This, riid, ppv);
}

static ULONG WINAPI HTMLDocument5_AddRef(IHTMLDocument5 *iface)
{
    HTMLDocument *This = impl_from_IHTMLDocument5(iface);
    return htmldoc_addref(This);
}

static ULONG WINAPI HTMLDocument5_Release(IHTMLDocument5 *iface)
{
    HTMLDocument *This = impl_from_IHTMLDocument5(iface);
    return htmldoc_release(This);
}

static HRESULT WINAPI HTMLDocument5_GetTypeInfoCount(IHTMLDocument5 *iface, UINT *pctinfo)
{
    HTMLDocument *This = impl_from_IHTMLDocument5(iface);
    return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
}

static HRESULT WINAPI HTMLDocument5_GetTypeInfo(IHTMLDocument5 *iface, UINT iTInfo,
        LCID lcid, ITypeInfo **ppTInfo)
{
    HTMLDocument *This = impl_from_IHTMLDocument5(iface);
    return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
}

static HRESULT WINAPI HTMLDocument5_GetIDsOfNames(IHTMLDocument5 *iface, REFIID riid,
        LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
{
    HTMLDocument *This = impl_from_IHTMLDocument5(iface);
    return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
            rgDispId);
}

static HRESULT WINAPI HTMLDocument5_Invoke(IHTMLDocument5 *iface, DISPID dispIdMember,
                            REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
                            VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
    HTMLDocument *This = impl_from_IHTMLDocument5(iface);
    return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
            pDispParams, pVarResult, pExcepInfo, puArgErr);
}

static HRESULT WINAPI HTMLDocument5_put_onmousewheel(IHTMLDocument5 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument5(iface);
2806 2807 2808 2809

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

    return set_doc_event(This, EVENTID_MOUSEWHEEL, &v);
2810 2811 2812 2813 2814
}

static HRESULT WINAPI HTMLDocument5_get_onmousewheel(IHTMLDocument5 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument5(iface);
2815 2816 2817 2818

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

    return get_doc_event(This, EVENTID_MOUSEWHEEL, p);
2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830
}

static HRESULT WINAPI HTMLDocument5_get_doctype(IHTMLDocument5 *iface, IHTMLDOMNode **p)
{
    HTMLDocument *This = impl_from_IHTMLDocument5(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument5_get_implementation(IHTMLDocument5 *iface, IHTMLDOMImplementation **p)
{
    HTMLDocument *This = impl_from_IHTMLDocument5(iface);
2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845
    HTMLDocumentNode *doc_node = This->doc_node;

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

    if(!doc_node->dom_implementation) {
        HRESULT hres;

        hres = create_dom_implementation(&doc_node->dom_implementation);
        if(FAILED(hres))
            return hres;
    }

    IHTMLDOMImplementation_AddRef(doc_node->dom_implementation);
    *p = doc_node->dom_implementation;
    return S_OK;
2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901
}

static HRESULT WINAPI HTMLDocument5_createAttribute(IHTMLDocument5 *iface, BSTR bstrattrName,
        IHTMLDOMAttribute **ppattribute)
{
    HTMLDocument *This = impl_from_IHTMLDocument5(iface);
    HTMLDOMAttribute *attr;
    HRESULT hres;

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

    hres = HTMLDOMAttribute_Create(bstrattrName, NULL, 0, &attr);
    if(FAILED(hres))
        return hres;

    *ppattribute = &attr->IHTMLDOMAttribute_iface;
    return S_OK;
}

static HRESULT WINAPI HTMLDocument5_createComment(IHTMLDocument5 *iface, BSTR bstrdata,
        IHTMLDOMNode **ppRetNode)
{
    HTMLDocument *This = impl_from_IHTMLDocument5(iface);
    nsIDOMComment *nscomment;
    HTMLElement *elem;
    nsAString str;
    nsresult nsres;
    HRESULT hres;

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

    if(!This->doc_node->nsdoc) {
        WARN("NULL nsdoc\n");
        return E_UNEXPECTED;
    }

    nsAString_InitDepend(&str, bstrdata);
    nsres = nsIDOMHTMLDocument_CreateComment(This->doc_node->nsdoc, &str, &nscomment);
    nsAString_Finish(&str);
    if(NS_FAILED(nsres)) {
        ERR("CreateTextNode failed: %08x\n", nsres);
        return E_FAIL;
    }

    hres = HTMLCommentElement_Create(This->doc_node, (nsIDOMNode*)nscomment, &elem);
    nsIDOMComment_Release(nscomment);
    if(FAILED(hres))
        return hres;

    *ppRetNode = &elem->node.IHTMLDOMNode_iface;
    return S_OK;
}

static HRESULT WINAPI HTMLDocument5_put_onfocusin(IHTMLDocument5 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument5(iface);
2902 2903 2904 2905

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

    return set_doc_event(This, EVENTID_FOCUSIN, &v);
2906 2907 2908 2909 2910
}

static HRESULT WINAPI HTMLDocument5_get_onfocusin(IHTMLDocument5 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument5(iface);
2911 2912 2913 2914

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

    return get_doc_event(This, EVENTID_FOCUSIN, p);
2915 2916 2917 2918 2919
}

static HRESULT WINAPI HTMLDocument5_put_onfocusout(IHTMLDocument5 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument5(iface);
2920 2921 2922 2923

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

    return set_doc_event(This, EVENTID_FOCUSOUT, &v);
2924 2925 2926 2927 2928
}

static HRESULT WINAPI HTMLDocument5_get_onfocusout(IHTMLDocument5 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument5(iface);
2929 2930 2931 2932

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

    return get_doc_event(This, EVENTID_FOCUSOUT, p);
2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994
}

static HRESULT WINAPI HTMLDocument5_put_onactivate(IHTMLDocument5 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument5(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument5_get_onactivate(IHTMLDocument5 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument5(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument5_put_ondeactivate(IHTMLDocument5 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument5(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument5_get_ondeactivate(IHTMLDocument5 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument5(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument5_put_onbeforeactivate(IHTMLDocument5 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument5(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument5_get_onbeforeactivate(IHTMLDocument5 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument5(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument5_put_onbeforedeactivate(IHTMLDocument5 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument5(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument5_get_onbeforedeactivate(IHTMLDocument5 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument5(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument5_get_compatMode(IHTMLDocument5 *iface, BSTR *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument5(iface);

2995 2996
    static const WCHAR BackCompatW[] = {'B','a','c','k','C','o','m','p','a','t',0};
    static const WCHAR CSS1CompatW[] = {'C','S','S','1','C','o','m','p','a','t',0};
2997

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

3000 3001
    *p = SysAllocString(This->doc_node->document_mode == COMPAT_MODE_QUIRKS ? BackCompatW : CSS1CompatW);
    return *p ? S_OK : E_OUTOFMEMORY;
3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094
}

static const IHTMLDocument5Vtbl HTMLDocument5Vtbl = {
    HTMLDocument5_QueryInterface,
    HTMLDocument5_AddRef,
    HTMLDocument5_Release,
    HTMLDocument5_GetTypeInfoCount,
    HTMLDocument5_GetTypeInfo,
    HTMLDocument5_GetIDsOfNames,
    HTMLDocument5_Invoke,
    HTMLDocument5_put_onmousewheel,
    HTMLDocument5_get_onmousewheel,
    HTMLDocument5_get_doctype,
    HTMLDocument5_get_implementation,
    HTMLDocument5_createAttribute,
    HTMLDocument5_createComment,
    HTMLDocument5_put_onfocusin,
    HTMLDocument5_get_onfocusin,
    HTMLDocument5_put_onfocusout,
    HTMLDocument5_get_onfocusout,
    HTMLDocument5_put_onactivate,
    HTMLDocument5_get_onactivate,
    HTMLDocument5_put_ondeactivate,
    HTMLDocument5_get_ondeactivate,
    HTMLDocument5_put_onbeforeactivate,
    HTMLDocument5_get_onbeforeactivate,
    HTMLDocument5_put_onbeforedeactivate,
    HTMLDocument5_get_onbeforedeactivate,
    HTMLDocument5_get_compatMode
};

static inline HTMLDocument *impl_from_IHTMLDocument6(IHTMLDocument6 *iface)
{
    return CONTAINING_RECORD(iface, HTMLDocument, IHTMLDocument6_iface);
}

static HRESULT WINAPI HTMLDocument6_QueryInterface(IHTMLDocument6 *iface,
        REFIID riid, void **ppv)
{
    HTMLDocument *This = impl_from_IHTMLDocument6(iface);
    return htmldoc_query_interface(This, riid, ppv);
}

static ULONG WINAPI HTMLDocument6_AddRef(IHTMLDocument6 *iface)
{
    HTMLDocument *This = impl_from_IHTMLDocument6(iface);
    return htmldoc_addref(This);
}

static ULONG WINAPI HTMLDocument6_Release(IHTMLDocument6 *iface)
{
    HTMLDocument *This = impl_from_IHTMLDocument6(iface);
    return htmldoc_release(This);
}

static HRESULT WINAPI HTMLDocument6_GetTypeInfoCount(IHTMLDocument6 *iface, UINT *pctinfo)
{
    HTMLDocument *This = impl_from_IHTMLDocument6(iface);
    return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
}

static HRESULT WINAPI HTMLDocument6_GetTypeInfo(IHTMLDocument6 *iface, UINT iTInfo,
        LCID lcid, ITypeInfo **ppTInfo)
{
    HTMLDocument *This = impl_from_IHTMLDocument6(iface);
    return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
}

static HRESULT WINAPI HTMLDocument6_GetIDsOfNames(IHTMLDocument6 *iface, REFIID riid,
        LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
{
    HTMLDocument *This = impl_from_IHTMLDocument6(iface);
    return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
            rgDispId);
}

static HRESULT WINAPI HTMLDocument6_Invoke(IHTMLDocument6 *iface, DISPID dispIdMember,
                            REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
                            VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
    HTMLDocument *This = impl_from_IHTMLDocument6(iface);
    return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
            pDispParams, pVarResult, pExcepInfo, puArgErr);
}

static HRESULT WINAPI HTMLDocument6_get_compatible(IHTMLDocument6 *iface,
        IHTMLDocumentCompatibleInfoCollection **p)
{
    HTMLDocument *This = impl_from_IHTMLDocument6(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

3095
static HRESULT WINAPI HTMLDocument6_get_documentMode(IHTMLDocument6 *iface, VARIANT *p)
3096 3097
{
    HTMLDocument *This = impl_from_IHTMLDocument6(iface);
3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119

    static const int docmode_values[] = {
        5,  /* DOCMODE_QUIRKS */
        7,  /* DOCMODE_IE7 */
        8,  /* DOCMODE_IE8 */
        9,  /* DOCMODE_IE8 */
        10, /* DOCMODE_IE10 */
        11  /* DOCMODE_IE11 */
    };

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

    if(!This->doc_node) {
        FIXME("NULL doc_node\n");
        return E_UNEXPECTED;
    }

    assert(This->doc_node->document_mode < sizeof(docmode_values)/sizeof(*docmode_values));

    V_VT(p) = VT_I4;
    V_I4(p) = docmode_values[This->doc_node->document_mode];
    return S_OK;
3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184
}

static HRESULT WINAPI HTMLDocument6_get_onstorage(IHTMLDocument6 *iface,
        VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument6(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument6_put_onstorage(IHTMLDocument6 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument6(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument6_get_onstoragecommit(IHTMLDocument6 *iface,
        VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument6(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument6_put_onstoragecommit(IHTMLDocument6 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument6(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument6_getElementById(IHTMLDocument6 *iface,
        BSTR bstrId, IHTMLElement2 **p)
{
    HTMLDocument *This = impl_from_IHTMLDocument6(iface);
    FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrId), p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument6_updateSettings(IHTMLDocument6 *iface)
{
    HTMLDocument *This = impl_from_IHTMLDocument6(iface);
    FIXME("(%p)->()\n", This);
    return E_NOTIMPL;
}

static const IHTMLDocument6Vtbl HTMLDocument6Vtbl = {
    HTMLDocument6_QueryInterface,
    HTMLDocument6_AddRef,
    HTMLDocument6_Release,
    HTMLDocument6_GetTypeInfoCount,
    HTMLDocument6_GetTypeInfo,
    HTMLDocument6_GetIDsOfNames,
    HTMLDocument6_Invoke,
    HTMLDocument6_get_compatible,
    HTMLDocument6_get_documentMode,
    HTMLDocument6_put_onstorage,
    HTMLDocument6_get_onstorage,
    HTMLDocument6_put_onstoragecommit,
    HTMLDocument6_get_onstoragecommit,
    HTMLDocument6_getElementById,
    HTMLDocument6_updateSettings
};

3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481
static inline HTMLDocument *impl_from_IHTMLDocument7(IHTMLDocument7 *iface)
{
    return CONTAINING_RECORD(iface, HTMLDocument, IHTMLDocument7_iface);
}

static HRESULT WINAPI HTMLDocument7_QueryInterface(IHTMLDocument7 *iface, REFIID riid, void **ppv)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    return htmldoc_query_interface(This, riid, ppv);
}

static ULONG WINAPI HTMLDocument7_AddRef(IHTMLDocument7 *iface)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    return htmldoc_addref(This);
}

static ULONG WINAPI HTMLDocument7_Release(IHTMLDocument7 *iface)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    return htmldoc_release(This);
}

static HRESULT WINAPI HTMLDocument7_GetTypeInfoCount(IHTMLDocument7 *iface, UINT *pctinfo)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
}

static HRESULT WINAPI HTMLDocument7_GetTypeInfo(IHTMLDocument7 *iface, UINT iTInfo,
        LCID lcid, ITypeInfo **ppTInfo)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
}

static HRESULT WINAPI HTMLDocument7_GetIDsOfNames(IHTMLDocument7 *iface, REFIID riid,
        LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
            rgDispId);
}

static HRESULT WINAPI HTMLDocument7_Invoke(IHTMLDocument7 *iface, DISPID dispIdMember,
                            REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
                            VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
            pDispParams, pVarResult, pExcepInfo, puArgErr);
}

static HRESULT WINAPI HTMLDocument7_get_defaultView(IHTMLDocument7 *iface, IHTMLWindow2 **p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_createCDATASection(IHTMLDocument7 *iface, BSTR text, IHTMLDOMNode **newCDATASectionNode)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, newCDATASectionNode);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_getSelection(IHTMLDocument7 *iface, IHTMLSelection **ppIHTMLSelection)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, ppIHTMLSelection);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_getElementsByTagNameNS(IHTMLDocument7 *iface, VARIANT *pvarNS,
        BSTR bstrLocalName, IHTMLElementCollection **pelColl)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s %s %p)\n", This, debugstr_variant(pvarNS), debugstr_w(bstrLocalName), pelColl);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_createElementNS(IHTMLDocument7 *iface, VARIANT *pvarNS, BSTR bstrTag, IHTMLElement **newElem)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s %s %p)\n", This, debugstr_variant(pvarNS), debugstr_w(bstrTag), newElem);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_createAttributeNS(IHTMLDocument7 *iface, VARIANT *pvarNS,
        BSTR bstrAttrName, IHTMLDOMAttribute **ppAttribute)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s %s %p)\n", This, debugstr_variant(pvarNS), debugstr_w(bstrAttrName), ppAttribute);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_onmsthumbnailclick(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_onmsthumbnailclick(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_characterSet(IHTMLDocument7 *iface, BSTR *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_createElement(IHTMLDocument7 *iface, BSTR bstrTag, IHTMLElement **newElem)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrTag), newElem);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_createAttribute(IHTMLDocument7 *iface, BSTR bstrAttrName, IHTMLDOMAttribute **ppAttribute)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrAttrName), ppAttribute);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_getElementByClassName(IHTMLDocument7 *iface, BSTR v, IHTMLElementCollection **pel)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s %p)\n", This, debugstr_w(v), pel);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_createProcessingInstruction(IHTMLDocument7 *iface, BSTR target,
        BSTR data, IDOMProcessingInstruction **newProcessingInstruction)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s %s %p)\n", This, debugstr_w(target), debugstr_w(data), newProcessingInstruction);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_adoptNode(IHTMLDocument7 *iface, IHTMLDOMNode *pNodeSource, IHTMLDOMNode3 **ppNodeDest)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p %p)\n", This, pNodeSource, ppNodeDest);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_onmssitemodejumplistitemremoved(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_onmssitemodejumplistitemremoved(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_all(IHTMLDocument7 *iface, IHTMLElementCollection **p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_inputEncoding(IHTMLDocument7 *iface, BSTR *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_xmlEncoding(IHTMLDocument7 *iface, BSTR *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_xmlStandalone(IHTMLDocument7 *iface, VARIANT_BOOL v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%x)\n", This, v);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_xmlStandalone(IHTMLDocument7 *iface, VARIANT_BOOL *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_xmlVersion(IHTMLDocument7 *iface, BSTR v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_w(v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_xmlVersion(IHTMLDocument7 *iface, BSTR *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_hasAttributes(IHTMLDocument7 *iface, VARIANT_BOOL *pfHasAttributes)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, pfHasAttributes);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_onabort(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_onabort(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_onblur(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_onblur(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_oncanplay(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_oncanplay(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_oncanplaythrough(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_oncanplaythrough(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_onchange(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_onchange(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_ondrag(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
3482 3483 3484 3485

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

    return set_doc_event(This, EVENTID_DRAG, &v);
3486 3487 3488 3489 3490
}

static HRESULT WINAPI HTMLDocument7_get_ondrag(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
3491 3492 3493 3494

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

    return get_doc_event(This, EVENTID_DRAG, p);
3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793
}

static HRESULT WINAPI HTMLDocument7_put_ondragend(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_ondragend(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_ondragenter(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_ondragenter(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_ondragleave(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_ondragleave(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_ondragover(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_ondragover(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_ondrop(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_ondrop(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_ondurationchange(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_ondurationchange(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_onemptied(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_onemptied(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_onended(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_onended(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_onerror(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_onerror(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_onfocus(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_onfocus(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_oninput(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_oninput(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_onload(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_onload(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_onloadeddata(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_onloadeddata(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_onloadedmetadata(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_onloadedmetadata(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_onloadstart(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_onloadstart(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_onpause(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_onpause(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_onplay(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_onplay(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_onplaying(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_onplaying(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_onprogress(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_onprogress(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_onratechange(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_onratechange(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_onreset(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_onreset(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_onscroll(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
3794 3795 3796 3797

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

    return set_doc_event(This, EVENTID_SCROLL, &v);
3798 3799 3800 3801 3802
}

static HRESULT WINAPI HTMLDocument7_get_onscroll(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
3803 3804 3805 3806

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

    return get_doc_event(This, EVENTID_SCROLL, p);
3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091
}

static HRESULT WINAPI HTMLDocument7_put_onseekend(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_onseekend(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_onseeking(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_onseeking(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_onselect(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_onselect(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_onstalled(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_onstalled(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_onsubmit(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_onsubmit(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_onsuspend(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_onsuspend(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_ontimeupdate(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_ontimeupdate(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_onvolumechange(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_onvolumechange(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_onwaiting(IHTMLDocument7 *iface, VARIANT v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_onwaiting(IHTMLDocument7 *iface, VARIANT *p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_normalize(IHTMLDocument7 *iface)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)\n", This);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_importNode(IHTMLDocument7 *iface, IHTMLDOMNode *pNodeSource,
        VARIANT_BOOL fDeep, IHTMLDOMNode3 **ppNodeDest)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p %x %p)\n", This, pNodeSource, fDeep, ppNodeDest);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_parentWindow(IHTMLDocument7 *iface, IHTMLWindow2 **p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_put_body(IHTMLDocument7 *iface, IHTMLElement *v)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, v);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_body(IHTMLDocument7 *iface, IHTMLElement **p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument7_get_head(IHTMLDocument7 *iface, IHTMLElement **p)
{
    HTMLDocument *This = impl_from_IHTMLDocument7(iface);
    FIXME("(%p)->(%p)\n", This, p);
    return E_NOTIMPL;
}

static const IHTMLDocument7Vtbl HTMLDocument7Vtbl = {
    HTMLDocument7_QueryInterface,
    HTMLDocument7_AddRef,
    HTMLDocument7_Release,
    HTMLDocument7_GetTypeInfoCount,
    HTMLDocument7_GetTypeInfo,
    HTMLDocument7_GetIDsOfNames,
    HTMLDocument7_Invoke,
    HTMLDocument7_get_defaultView,
    HTMLDocument7_createCDATASection,
    HTMLDocument7_getSelection,
    HTMLDocument7_getElementsByTagNameNS,
    HTMLDocument7_createElementNS,
    HTMLDocument7_createAttributeNS,
    HTMLDocument7_put_onmsthumbnailclick,
    HTMLDocument7_get_onmsthumbnailclick,
    HTMLDocument7_get_characterSet,
    HTMLDocument7_createElement,
    HTMLDocument7_createAttribute,
    HTMLDocument7_getElementByClassName,
    HTMLDocument7_createProcessingInstruction,
    HTMLDocument7_adoptNode,
    HTMLDocument7_put_onmssitemodejumplistitemremoved,
    HTMLDocument7_get_onmssitemodejumplistitemremoved,
    HTMLDocument7_get_all,
    HTMLDocument7_get_inputEncoding,
    HTMLDocument7_get_xmlEncoding,
    HTMLDocument7_put_xmlStandalone,
    HTMLDocument7_get_xmlStandalone,
    HTMLDocument7_put_xmlVersion,
    HTMLDocument7_get_xmlVersion,
    HTMLDocument7_hasAttributes,
    HTMLDocument7_put_onabort,
    HTMLDocument7_get_onabort,
    HTMLDocument7_put_onblur,
    HTMLDocument7_get_onblur,
    HTMLDocument7_put_oncanplay,
    HTMLDocument7_get_oncanplay,
    HTMLDocument7_put_oncanplaythrough,
    HTMLDocument7_get_oncanplaythrough,
    HTMLDocument7_put_onchange,
    HTMLDocument7_get_onchange,
    HTMLDocument7_put_ondrag,
    HTMLDocument7_get_ondrag,
    HTMLDocument7_put_ondragend,
    HTMLDocument7_get_ondragend,
    HTMLDocument7_put_ondragenter,
    HTMLDocument7_get_ondragenter,
    HTMLDocument7_put_ondragleave,
    HTMLDocument7_get_ondragleave,
    HTMLDocument7_put_ondragover,
    HTMLDocument7_get_ondragover,
    HTMLDocument7_put_ondrop,
    HTMLDocument7_get_ondrop,
    HTMLDocument7_put_ondurationchange,
    HTMLDocument7_get_ondurationchange,
    HTMLDocument7_put_onemptied,
    HTMLDocument7_get_onemptied,
    HTMLDocument7_put_onended,
    HTMLDocument7_get_onended,
    HTMLDocument7_put_onerror,
    HTMLDocument7_get_onerror,
    HTMLDocument7_put_onfocus,
    HTMLDocument7_get_onfocus,
    HTMLDocument7_put_oninput,
    HTMLDocument7_get_oninput,
    HTMLDocument7_put_onload,
    HTMLDocument7_get_onload,
    HTMLDocument7_put_onloadeddata,
    HTMLDocument7_get_onloadeddata,
    HTMLDocument7_put_onloadedmetadata,
    HTMLDocument7_get_onloadedmetadata,
    HTMLDocument7_put_onloadstart,
    HTMLDocument7_get_onloadstart,
    HTMLDocument7_put_onpause,
    HTMLDocument7_get_onpause,
    HTMLDocument7_put_onplay,
    HTMLDocument7_get_onplay,
    HTMLDocument7_put_onplaying,
    HTMLDocument7_get_onplaying,
    HTMLDocument7_put_onprogress,
    HTMLDocument7_get_onprogress,
    HTMLDocument7_put_onratechange,
    HTMLDocument7_get_onratechange,
    HTMLDocument7_put_onreset,
    HTMLDocument7_get_onreset,
    HTMLDocument7_put_onscroll,
    HTMLDocument7_get_onscroll,
    HTMLDocument7_put_onseekend,
    HTMLDocument7_get_onseekend,
    HTMLDocument7_put_onseeking,
    HTMLDocument7_get_onseeking,
    HTMLDocument7_put_onselect,
    HTMLDocument7_get_onselect,
    HTMLDocument7_put_onstalled,
    HTMLDocument7_get_onstalled,
    HTMLDocument7_put_onsubmit,
    HTMLDocument7_get_onsubmit,
    HTMLDocument7_put_onsuspend,
    HTMLDocument7_get_onsuspend,
    HTMLDocument7_put_ontimeupdate,
    HTMLDocument7_get_ontimeupdate,
    HTMLDocument7_put_onvolumechange,
    HTMLDocument7_get_onvolumechange,
    HTMLDocument7_put_onwaiting,
    HTMLDocument7_get_onwaiting,
    HTMLDocument7_normalize,
    HTMLDocument7_importNode,
    HTMLDocument7_get_parentWindow,
    HTMLDocument7_put_body,
    HTMLDocument7_get_body,
    HTMLDocument7_get_head
};

4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153
static inline HTMLDocument *impl_from_IDocumentSelector(IDocumentSelector *iface)
{
    return CONTAINING_RECORD(iface, HTMLDocument, IDocumentSelector_iface);
}

static HRESULT WINAPI DocumentSelector_QueryInterface(IDocumentSelector *iface, REFIID riid, void **ppv)
{
    HTMLDocument *This = impl_from_IDocumentSelector(iface);
    return htmldoc_query_interface(This, riid, ppv);
}

static ULONG WINAPI DocumentSelector_AddRef(IDocumentSelector *iface)
{
    HTMLDocument *This = impl_from_IDocumentSelector(iface);
    return htmldoc_addref(This);
}

static ULONG WINAPI DocumentSelector_Release(IDocumentSelector *iface)
{
    HTMLDocument *This = impl_from_IDocumentSelector(iface);
    return htmldoc_release(This);
}

static HRESULT WINAPI DocumentSelector_GetTypeInfoCount(IDocumentSelector *iface, UINT *pctinfo)
{
    HTMLDocument *This = impl_from_IDocumentSelector(iface);
    return IDispatchEx_GetTypeInfoCount(&This->IDispatchEx_iface, pctinfo);
}

static HRESULT WINAPI DocumentSelector_GetTypeInfo(IDocumentSelector *iface, UINT iTInfo,
        LCID lcid, ITypeInfo **ppTInfo)
{
    HTMLDocument *This = impl_from_IDocumentSelector(iface);
    return IDispatchEx_GetTypeInfo(&This->IDispatchEx_iface, iTInfo, lcid, ppTInfo);
}

static HRESULT WINAPI DocumentSelector_GetIDsOfNames(IDocumentSelector *iface, REFIID riid,
        LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
{
    HTMLDocument *This = impl_from_IDocumentSelector(iface);
    return IDispatchEx_GetIDsOfNames(&This->IDispatchEx_iface, riid, rgszNames, cNames, lcid,
            rgDispId);
}

static HRESULT WINAPI DocumentSelector_Invoke(IDocumentSelector *iface, DISPID dispIdMember, REFIID riid,
        LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
    HTMLDocument *This = impl_from_IDocumentSelector(iface);
    return IDispatchEx_Invoke(&This->IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
            pDispParams, pVarResult, pExcepInfo, puArgErr);
}

static HRESULT WINAPI DocumentSelector_querySelector(IDocumentSelector *iface, BSTR v, IHTMLElement **pel)
{
    HTMLDocument *This = impl_from_IDocumentSelector(iface);
    FIXME("(%p)->(%s %p)\n", This, debugstr_w(v), pel);
    return E_NOTIMPL;
}

static HRESULT WINAPI DocumentSelector_querySelectorAll(IDocumentSelector *iface, BSTR v, IHTMLDOMChildrenCollection **pel)
{
    HTMLDocument *This = impl_from_IDocumentSelector(iface);
4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170
    nsIDOMNodeList *node_list;
    nsAString nsstr;
    nsresult nsres;

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

    nsAString_InitDepend(&nsstr, v);
    nsres = nsIDOMHTMLDocument_QuerySelectorAll(This->doc_node->nsdoc, &nsstr, &node_list);
    nsAString_Finish(&nsstr);
    if(NS_FAILED(nsres)) {
        ERR("QuerySelectorAll failed: %08x\n", nsres);
        return E_FAIL;
    }

    *pel = create_child_collection(This->doc_node, node_list);
    nsIDOMNodeList_Release(node_list);
    return *pel ? S_OK : E_OUTOFMEMORY;
4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184
}

static const IDocumentSelectorVtbl DocumentSelectorVtbl = {
    DocumentSelector_QueryInterface,
    DocumentSelector_AddRef,
    DocumentSelector_Release,
    DocumentSelector_GetTypeInfoCount,
    DocumentSelector_GetTypeInfo,
    DocumentSelector_GetIDsOfNames,
    DocumentSelector_Invoke,
    DocumentSelector_querySelector,
    DocumentSelector_querySelectorAll
};

4185 4186
static void HTMLDocument_on_advise(IUnknown *iface, cp_static_data_t *cp)
{
4187
    HTMLDocument *This = impl_from_IHTMLDocument2((IHTMLDocument2*)iface);
4188 4189

    if(This->window)
4190
        update_doc_cp_events(This->doc_node, cp);
4191 4192
}

4193 4194 4195 4196
static inline HTMLDocument *impl_from_ISupportErrorInfo(ISupportErrorInfo *iface)
{
    return CONTAINING_RECORD(iface, HTMLDocument, ISupportErrorInfo_iface);
}
4197 4198 4199

static HRESULT WINAPI SupportErrorInfo_QueryInterface(ISupportErrorInfo *iface, REFIID riid, void **ppv)
{
4200
    HTMLDocument *This = impl_from_ISupportErrorInfo(iface);
4201
    return htmldoc_query_interface(This, riid, ppv);
4202 4203 4204 4205
}

static ULONG WINAPI SupportErrorInfo_AddRef(ISupportErrorInfo *iface)
{
4206
    HTMLDocument *This = impl_from_ISupportErrorInfo(iface);
4207
    return htmldoc_addref(This);
4208 4209 4210 4211
}

static ULONG WINAPI SupportErrorInfo_Release(ISupportErrorInfo *iface)
{
4212
    HTMLDocument *This = impl_from_ISupportErrorInfo(iface);
4213
    return htmldoc_release(This);
4214 4215 4216 4217
}

static HRESULT WINAPI SupportErrorInfo_InterfaceSupportsErrorInfo(ISupportErrorInfo *iface, REFIID riid)
{
4218
    FIXME("(%p)->(%s)\n", iface, debugstr_mshtml_guid(riid));
4219 4220 4221 4222 4223 4224 4225 4226 4227 4228
    return S_FALSE;
}

static const ISupportErrorInfoVtbl SupportErrorInfoVtbl = {
    SupportErrorInfo_QueryInterface,
    SupportErrorInfo_AddRef,
    SupportErrorInfo_Release,
    SupportErrorInfo_InterfaceSupportsErrorInfo
};

4229 4230 4231 4232
static inline HTMLDocument *impl_from_IDispatchEx(IDispatchEx *iface)
{
    return CONTAINING_RECORD(iface, HTMLDocument, IDispatchEx_iface);
}
4233

4234 4235 4236 4237
static HRESULT dispid_from_elem_name(HTMLDocumentNode *This, BSTR name, DISPID *dispid)
{
    nsIDOMNodeList *node_list;
    nsAString name_str;
4238
    UINT32 len;
4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291
    unsigned i;
    nsresult nsres;

    if(!This->nsdoc)
        return DISP_E_UNKNOWNNAME;

    nsAString_InitDepend(&name_str, name);
    nsres = nsIDOMHTMLDocument_GetElementsByName(This->nsdoc, &name_str, &node_list);
    nsAString_Finish(&name_str);
    if(NS_FAILED(nsres))
        return E_FAIL;

    nsres = nsIDOMNodeList_GetLength(node_list, &len);
    nsIDOMNodeList_Release(node_list);
    if(NS_FAILED(nsres))
        return E_FAIL;

    if(!len)
        return DISP_E_UNKNOWNNAME;

    for(i=0; i < This->elem_vars_cnt; i++) {
        if(!strcmpW(name, This->elem_vars[i])) {
            *dispid = MSHTML_DISPID_CUSTOM_MIN+i;
            return S_OK;
        }
    }

    if(This->elem_vars_cnt == This->elem_vars_size) {
        WCHAR **new_vars;

        if(This->elem_vars_size) {
            new_vars = heap_realloc(This->elem_vars, This->elem_vars_size*2*sizeof(WCHAR*));
            if(!new_vars)
                return E_OUTOFMEMORY;
            This->elem_vars_size *= 2;
        }else {
            new_vars = heap_alloc(16*sizeof(WCHAR*));
            if(!new_vars)
                return E_OUTOFMEMORY;
            This->elem_vars_size = 16;
        }

        This->elem_vars = new_vars;
    }

    This->elem_vars[This->elem_vars_cnt] = heap_strdupW(name);
    if(!This->elem_vars[This->elem_vars_cnt])
        return E_OUTOFMEMORY;

    *dispid = MSHTML_DISPID_CUSTOM_MIN+This->elem_vars_cnt++;
    return S_OK;
}

4292 4293
static HRESULT WINAPI DocDispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
{
4294
    HTMLDocument *This = impl_from_IDispatchEx(iface);
4295

4296
    return htmldoc_query_interface(This, riid, ppv);
4297 4298 4299 4300
}

static ULONG WINAPI DocDispatchEx_AddRef(IDispatchEx *iface)
{
4301
    HTMLDocument *This = impl_from_IDispatchEx(iface);
4302

4303
    return htmldoc_addref(This);
4304 4305 4306 4307
}

static ULONG WINAPI DocDispatchEx_Release(IDispatchEx *iface)
{
4308
    HTMLDocument *This = impl_from_IDispatchEx(iface);
4309

4310
    return htmldoc_release(This);
4311 4312 4313 4314
}

static HRESULT WINAPI DocDispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
{
4315
    HTMLDocument *This = impl_from_IDispatchEx(iface);
4316

4317
    return IDispatchEx_GetTypeInfoCount(This->dispex, pctinfo);
4318 4319 4320 4321 4322
}

static HRESULT WINAPI DocDispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
                                               LCID lcid, ITypeInfo **ppTInfo)
{
4323
    HTMLDocument *This = impl_from_IDispatchEx(iface);
4324

4325
    return IDispatchEx_GetTypeInfo(This->dispex, iTInfo, lcid, ppTInfo);
4326 4327 4328 4329 4330 4331
}

static HRESULT WINAPI DocDispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
                                                 LPOLESTR *rgszNames, UINT cNames,
                                                 LCID lcid, DISPID *rgDispId)
{
4332
    HTMLDocument *This = impl_from_IDispatchEx(iface);
4333

4334
    return IDispatchEx_GetIDsOfNames(This->dispex, riid, rgszNames, cNames, lcid, rgDispId);
4335 4336 4337 4338 4339 4340
}

static HRESULT WINAPI DocDispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
                            REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
                            VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
4341
    HTMLDocument *This = impl_from_IDispatchEx(iface);
4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353

    TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
          lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);

    switch(dispIdMember) {
    case DISPID_READYSTATE:
        TRACE("DISPID_READYSTATE\n");

        if(!(wFlags & DISPATCH_PROPERTYGET))
            return E_INVALIDARG;

        V_VT(pVarResult) = VT_I4;
4354
        V_I4(pVarResult) = This->window->readystate;
4355 4356 4357
        return S_OK;
    }

4358
    return IDispatchEx_Invoke(This->dispex, dispIdMember, riid, lcid, wFlags, pDispParams,
4359 4360 4361 4362 4363
                              pVarResult, pExcepInfo, puArgErr);
}

static HRESULT WINAPI DocDispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
{
4364
    HTMLDocument *This = impl_from_IDispatchEx(iface);
4365
    HRESULT hres;
4366

4367 4368 4369 4370 4371
    hres = IDispatchEx_GetDispID(This->dispex, bstrName, grfdex, pid);
    if(hres != DISP_E_UNKNOWNNAME)
        return hres;

    return  dispid_from_elem_name(This->doc_node, bstrName, pid);
4372 4373 4374 4375 4376
}

static HRESULT WINAPI DocDispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
        VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
{
4377
    HTMLDocument *This = impl_from_IDispatchEx(iface);
4378

4379
    if(This->window && id == DISPID_IHTMLDOCUMENT2_LOCATION && (wFlags & DISPATCH_PROPERTYPUT))
4380
        return IDispatchEx_InvokeEx(&This->window->base.IDispatchEx_iface, DISPID_IHTMLWINDOW2_LOCATION,
4381
                lcid, wFlags, pdp, pvarRes, pei, pspCaller);
4382 4383


4384
    return IDispatchEx_InvokeEx(This->dispex, id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
4385 4386 4387 4388
}

static HRESULT WINAPI DocDispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
{
4389
    HTMLDocument *This = impl_from_IDispatchEx(iface);
4390

4391
    return IDispatchEx_DeleteMemberByName(This->dispex, bstrName, grfdex);
4392 4393 4394 4395
}

static HRESULT WINAPI DocDispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
{
4396
    HTMLDocument *This = impl_from_IDispatchEx(iface);
4397

4398
    return IDispatchEx_DeleteMemberByDispID(This->dispex, id);
4399 4400 4401 4402
}

static HRESULT WINAPI DocDispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
{
4403
    HTMLDocument *This = impl_from_IDispatchEx(iface);
4404

4405
    return IDispatchEx_GetMemberProperties(This->dispex, id, grfdexFetch, pgrfdex);
4406 4407 4408 4409
}

static HRESULT WINAPI DocDispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
{
4410
    HTMLDocument *This = impl_from_IDispatchEx(iface);
4411

4412
    return IDispatchEx_GetMemberName(This->dispex, id, pbstrName);
4413 4414 4415 4416
}

static HRESULT WINAPI DocDispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
{
4417
    HTMLDocument *This = impl_from_IDispatchEx(iface);
4418

4419
    return IDispatchEx_GetNextDispID(This->dispex, grfdex, id, pid);
4420 4421 4422 4423
}

static HRESULT WINAPI DocDispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
{
4424
    HTMLDocument *This = impl_from_IDispatchEx(iface);
4425

4426
    return IDispatchEx_GetNameSpaceParent(This->dispex, ppunk);
4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446
}

static const IDispatchExVtbl DocDispatchExVtbl = {
    DocDispatchEx_QueryInterface,
    DocDispatchEx_AddRef,
    DocDispatchEx_Release,
    DocDispatchEx_GetTypeInfoCount,
    DocDispatchEx_GetTypeInfo,
    DocDispatchEx_GetIDsOfNames,
    DocDispatchEx_Invoke,
    DocDispatchEx_GetDispID,
    DocDispatchEx_InvokeEx,
    DocDispatchEx_DeleteMemberByName,
    DocDispatchEx_DeleteMemberByDispID,
    DocDispatchEx_GetMemberProperties,
    DocDispatchEx_GetMemberName,
    DocDispatchEx_GetNextDispID,
    DocDispatchEx_GetNameSpaceParent
};

4447
static inline HTMLDocument *impl_from_IProvideMultipleClassInfo(IProvideMultipleClassInfo *iface)
4448
{
4449
    return CONTAINING_RECORD(iface, HTMLDocument, IProvideMultipleClassInfo_iface);
4450 4451
}

4452
static HRESULT WINAPI ProvideClassInfo_QueryInterface(IProvideMultipleClassInfo *iface,
4453 4454
        REFIID riid, void **ppv)
{
4455
    HTMLDocument *This = impl_from_IProvideMultipleClassInfo(iface);
4456 4457 4458
    return htmldoc_query_interface(This, riid, ppv);
}

4459
static ULONG WINAPI ProvideClassInfo_AddRef(IProvideMultipleClassInfo *iface)
4460
{
4461
    HTMLDocument *This = impl_from_IProvideMultipleClassInfo(iface);
4462 4463 4464
    return htmldoc_addref(This);
}

4465
static ULONG WINAPI ProvideClassInfo_Release(IProvideMultipleClassInfo *iface)
4466
{
4467
    HTMLDocument *This = impl_from_IProvideMultipleClassInfo(iface);
4468 4469 4470
    return htmldoc_release(This);
}

4471
static HRESULT WINAPI ProvideClassInfo_GetClassInfo(IProvideMultipleClassInfo *iface, ITypeInfo **ppTI)
4472
{
4473
    HTMLDocument *This = impl_from_IProvideMultipleClassInfo(iface);
4474
    TRACE("(%p)->(%p)\n", This, ppTI);
4475
    return get_class_typeinfo(&CLSID_HTMLDocument, ppTI);
4476 4477
}

4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501
static HRESULT WINAPI ProvideClassInfo2_GetGUID(IProvideMultipleClassInfo *iface, DWORD dwGuidKind, GUID *pGUID)
{
    HTMLDocument *This = impl_from_IProvideMultipleClassInfo(iface);
    FIXME("(%p)->(%u %p)\n", This, dwGuidKind, pGUID);
    return E_NOTIMPL;
}

static HRESULT WINAPI ProvideMultipleClassInfo_GetMultiTypeInfoCount(IProvideMultipleClassInfo *iface, ULONG *pcti)
{
    HTMLDocument *This = impl_from_IProvideMultipleClassInfo(iface);
    FIXME("(%p)->(%p)\n", This, pcti);
    *pcti = 1;
    return S_OK;
}

static HRESULT WINAPI ProvideMultipleClassInfo_GetInfoOfIndex(IProvideMultipleClassInfo *iface, ULONG iti,
        DWORD dwFlags, ITypeInfo **pptiCoClass, DWORD *pdwTIFlags, ULONG *pcdispidReserved, IID *piidPrimary, IID *piidSource)
{
    HTMLDocument *This = impl_from_IProvideMultipleClassInfo(iface);
    FIXME("(%p)->(%u %x %p %p %p %p %p)\n", This, iti, dwFlags, pptiCoClass, pdwTIFlags, pcdispidReserved, piidPrimary, piidSource);
    return E_NOTIMPL;
}

static const IProvideMultipleClassInfoVtbl ProvideMultipleClassInfoVtbl = {
4502 4503 4504
    ProvideClassInfo_QueryInterface,
    ProvideClassInfo_AddRef,
    ProvideClassInfo_Release,
4505 4506 4507 4508
    ProvideClassInfo_GetClassInfo,
    ProvideClassInfo2_GetGUID,
    ProvideMultipleClassInfo_GetMultiTypeInfoCount,
    ProvideMultipleClassInfo_GetInfoOfIndex
4509 4510
};

4511
static BOOL htmldoc_qi(HTMLDocument *This, REFIID riid, void **ppv)
4512 4513 4514
{
    *ppv = NULL;

4515
    if(IsEqualGUID(&IID_IUnknown, riid))
4516
        *ppv = &This->IHTMLDocument2_iface;
4517
    else if(IsEqualGUID(&IID_IDispatch, riid))
4518
        *ppv = &This->IDispatchEx_iface;
4519
    else if(IsEqualGUID(&IID_IDispatchEx, riid))
4520
        *ppv = &This->IDispatchEx_iface;
4521
    else if(IsEqualGUID(&IID_IHTMLDocument, riid))
4522
        *ppv = &This->IHTMLDocument2_iface;
4523
    else if(IsEqualGUID(&IID_IHTMLDocument2, riid))
4524
        *ppv = &This->IHTMLDocument2_iface;
4525
    else if(IsEqualGUID(&IID_IHTMLDocument3, riid))
4526
        *ppv = &This->IHTMLDocument3_iface;
4527
    else if(IsEqualGUID(&IID_IHTMLDocument4, riid))
4528
        *ppv = &This->IHTMLDocument4_iface;
4529
    else if(IsEqualGUID(&IID_IHTMLDocument5, riid))
4530
        *ppv = &This->IHTMLDocument5_iface;
4531
    else if(IsEqualGUID(&IID_IHTMLDocument6, riid))
4532
        *ppv = &This->IHTMLDocument6_iface;
4533
    else if(IsEqualGUID(&IID_IHTMLDocument7, riid))
4534
        *ppv = &This->IHTMLDocument7_iface;
4535 4536
    else if(IsEqualGUID(&IID_IDocumentSelector, riid))
        *ppv = &This->IDocumentSelector_iface;
4537
    else if(IsEqualGUID(&IID_IPersist, riid))
4538
        *ppv = &This->IPersistFile_iface;
4539
    else if(IsEqualGUID(&IID_IPersistMoniker, riid))
4540
        *ppv = &This->IPersistMoniker_iface;
4541
    else if(IsEqualGUID(&IID_IPersistFile, riid))
4542
        *ppv = &This->IPersistFile_iface;
4543
    else if(IsEqualGUID(&IID_IMonikerProp, riid))
4544
        *ppv = &This->IMonikerProp_iface;
4545
    else if(IsEqualGUID(&IID_IOleObject, riid))
4546
        *ppv = &This->IOleObject_iface;
4547
    else if(IsEqualGUID(&IID_IOleDocument, riid))
4548
        *ppv = &This->IOleDocument_iface;
4549
    else if(IsEqualGUID(&IID_IOleDocumentView, riid))
4550
        *ppv = &This->IOleDocumentView_iface;
4551
    else if(IsEqualGUID(&IID_IOleInPlaceActiveObject, riid))
4552
        *ppv = &This->IOleInPlaceActiveObject_iface;
4553
    else if(IsEqualGUID(&IID_IViewObject, riid))
4554
        *ppv = &This->IViewObjectEx_iface;
4555
    else if(IsEqualGUID(&IID_IViewObject2, riid))
4556
        *ppv = &This->IViewObjectEx_iface;
4557
    else if(IsEqualGUID(&IID_IViewObjectEx, riid))
4558
        *ppv = &This->IViewObjectEx_iface;
4559
    else if(IsEqualGUID(&IID_IOleWindow, riid))
4560
        *ppv = &This->IOleInPlaceActiveObject_iface;
4561
    else if(IsEqualGUID(&IID_IOleInPlaceObject, riid))
4562
        *ppv = &This->IOleInPlaceObjectWindowless_iface;
4563
    else if(IsEqualGUID(&IID_IOleInPlaceObjectWindowless, riid))
4564
        *ppv = &This->IOleInPlaceObjectWindowless_iface;
4565
    else if(IsEqualGUID(&IID_IServiceProvider, riid))
4566
        *ppv = &This->IServiceProvider_iface;
4567
    else if(IsEqualGUID(&IID_IOleCommandTarget, riid))
4568
        *ppv = &This->IOleCommandTarget_iface;
4569
    else if(IsEqualGUID(&IID_IOleControl, riid))
4570
        *ppv = &This->IOleControl_iface;
4571
    else if(IsEqualGUID(&IID_IHlinkTarget, riid))
4572
        *ppv = &This->IHlinkTarget_iface;
4573
    else if(IsEqualGUID(&IID_IConnectionPointContainer, riid))
4574
        *ppv = &This->cp_container.IConnectionPointContainer_iface;
4575
    else if(IsEqualGUID(&IID_IPersistStreamInit, riid))
4576
        *ppv = &This->IPersistStreamInit_iface;
4577
    else if(IsEqualGUID(&DIID_DispHTMLDocument, riid))
4578
        *ppv = &This->IHTMLDocument2_iface;
4579
    else if(IsEqualGUID(&IID_ISupportErrorInfo, riid))
4580
        *ppv = &This->ISupportErrorInfo_iface;
4581
    else if(IsEqualGUID(&IID_IPersistHistory, riid))
4582
        *ppv = &This->IPersistHistory_iface;
4583 4584 4585 4586 4587 4588 4589
    else if(IsEqualGUID(&IID_IObjectWithSite, riid))
        *ppv = &This->IObjectWithSite_iface;
    else if(IsEqualGUID(&IID_IOleContainer, riid))
        *ppv = &This->IOleContainer_iface;
    else if(IsEqualGUID(&IID_IObjectSafety, riid))
        *ppv = &This->IObjectSafety_iface;
    else if(IsEqualGUID(&IID_IProvideClassInfo, riid))
4590 4591 4592 4593 4594
        *ppv = &This->IProvideMultipleClassInfo_iface;
    else if(IsEqualGUID(&IID_IProvideClassInfo2, riid))
        *ppv = &This->IProvideMultipleClassInfo_iface;
    else if(IsEqualGUID(&IID_IProvideMultipleClassInfo, riid))
        *ppv = &This->IProvideMultipleClassInfo_iface;
4595
    else if(IsEqualGUID(&CLSID_CMarkup, riid)) {
4596
        FIXME("(%p)->(CLSID_CMarkup %p)\n", This, ppv);
4597
        *ppv = NULL;
4598 4599
    }else if(IsEqualGUID(&IID_IRunnableObject, riid)) {
        TRACE("(%p)->(IID_IRunnableObject %p) returning NULL\n", This, ppv);
4600
        *ppv = NULL;
4601 4602
    }else if(IsEqualGUID(&IID_IPersistPropertyBag, riid)) {
        TRACE("(%p)->(IID_IPersistPropertyBag %p) returning NULL\n", This, ppv);
4603
        *ppv = NULL;
4604 4605 4606
    }else if(IsEqualGUID(&IID_IExternalConnection, riid)) {
        TRACE("(%p)->(IID_IExternalConnection %p) returning NULL\n", This, ppv);
        *ppv = NULL;
4607 4608 4609
    }else if(IsEqualGUID(&IID_IStdMarshalInfo, riid)) {
        TRACE("(%p)->(IID_IStdMarshalInfo %p) returning NULL\n", This, ppv);
        *ppv = NULL;
4610
    }else {
4611
        return FALSE;
4612 4613
    }

4614 4615 4616
    if(*ppv)
        IUnknown_AddRef((IUnknown*)*ppv);
    return TRUE;
4617 4618
}

4619
static cp_static_data_t HTMLDocumentEvents_data = { HTMLDocumentEvents_tid, HTMLDocument_on_advise };
4620

4621 4622 4623 4624 4625 4626 4627 4628
static const cpc_entry_t HTMLDocument_cpc[] = {
    {&IID_IDispatch, &HTMLDocumentEvents_data},
    {&IID_IPropertyNotifySink},
    {&DIID_HTMLDocumentEvents, &HTMLDocumentEvents_data},
    {&DIID_HTMLDocumentEvents2},
    {NULL}
};

4629
static void init_doc(HTMLDocument *doc, IUnknown *outer, IDispatchEx *dispex)
4630
{
4631
    doc->IHTMLDocument2_iface.lpVtbl = &HTMLDocumentVtbl;
4632 4633 4634 4635
    doc->IHTMLDocument3_iface.lpVtbl = &HTMLDocument3Vtbl;
    doc->IHTMLDocument4_iface.lpVtbl = &HTMLDocument4Vtbl;
    doc->IHTMLDocument5_iface.lpVtbl = &HTMLDocument5Vtbl;
    doc->IHTMLDocument6_iface.lpVtbl = &HTMLDocument6Vtbl;
4636
    doc->IHTMLDocument7_iface.lpVtbl = &HTMLDocument7Vtbl;
4637
    doc->IDispatchEx_iface.lpVtbl = &DocDispatchExVtbl;
4638
    doc->IDocumentSelector_iface.lpVtbl = &DocumentSelectorVtbl;
4639
    doc->ISupportErrorInfo_iface.lpVtbl = &SupportErrorInfoVtbl;
4640
    doc->IProvideMultipleClassInfo_iface.lpVtbl = &ProvideMultipleClassInfoVtbl;
4641

4642
    doc->outer_unk = outer;
4643
    doc->dispex = dispex;
4644
    doc->task_magic = get_task_target_magic();
4645

4646 4647 4648 4649 4650 4651 4652 4653
    HTMLDocument_Persist_Init(doc);
    HTMLDocument_OleCmd_Init(doc);
    HTMLDocument_OleObj_Init(doc);
    HTMLDocument_View_Init(doc);
    HTMLDocument_Window_Init(doc);
    HTMLDocument_Service_Init(doc);
    HTMLDocument_Hlink_Init(doc);

4654
    ConnectionPointContainer_Init(&doc->cp_container, (IUnknown*)&doc->IHTMLDocument2_iface, HTMLDocument_cpc);
4655
}
4656

4657 4658
static void destroy_htmldoc(HTMLDocument *This)
{
4659
    remove_target_tasks(This->task_magic);
4660 4661 4662 4663

    ConnectionPointContainer_Destroy(&This->cp_container);
}

4664 4665 4666 4667
static inline HTMLDocumentNode *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
{
    return CONTAINING_RECORD(iface, HTMLDocumentNode, node);
}
4668 4669 4670

static HRESULT HTMLDocumentNode_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
{
4671
    HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
4672

4673 4674
    TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);

4675 4676 4677
    if(htmldoc_qi(&This->basedoc, riid, ppv))
        return *ppv ? S_OK : E_NOINTERFACE;

4678
    if(IsEqualGUID(&IID_IInternetHostSecurityManager, riid))
4679
        *ppv = &This->IInternetHostSecurityManager_iface;
4680
    else
4681 4682 4683 4684
        return HTMLDOMNode_QI(&This->node, riid, ppv);

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

4687
static void HTMLDocumentNode_destructor(HTMLDOMNode *iface)
4688
{
4689
    HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
4690 4691 4692 4693 4694
    unsigned i;

    for(i=0; i < This->elem_vars_cnt; i++)
        heap_free(This->elem_vars[i]);
    heap_free(This->elem_vars);
4695

4696
    detach_events(This);
4697 4698
    if(This->catmgr)
        ICatInformation_Release(This->catmgr);
4699

4700 4701
    detach_selection(This);
    detach_ranges(This);
4702

4703 4704 4705
    while(!list_empty(&This->plugin_hosts))
        detach_plugin_host(LIST_ENTRY(list_head(&This->plugin_hosts), PluginHost, entry));

4706
    if(!This->nsdoc && This->window) {
4707 4708 4709
        /* document fragments own reference to inner window */
        IHTMLWindow2_Release(&This->window->base.IHTMLWindow2_iface);
        This->window = NULL;
4710
    }
4711

4712
    heap_free(This->event_vector);
4713 4714 4715
    destroy_htmldoc(&This->basedoc);
}

4716 4717
static HRESULT HTMLDocumentNode_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
{
4718
    HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
4719 4720 4721 4722
    FIXME("%p\n", This);
    return E_NOTIMPL;
}

4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740
static void HTMLDocumentNode_traverse(HTMLDOMNode *iface, nsCycleCollectionTraversalCallback *cb)
{
    HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);

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

static void HTMLDocumentNode_unlink(HTMLDOMNode *iface)
{
    HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);

    if(This->nsdoc) {
        nsIDOMHTMLDocument *nsdoc = This->nsdoc;

        release_document_mutation(This);
        This->nsdoc = NULL;
        nsIDOMHTMLDocument_Release(nsdoc);
4741
        This->window = NULL;
4742 4743 4744
    }
}

4745
static const NodeImplVtbl HTMLDocumentNodeImplVtbl = {
4746
    &CLSID_HTMLDocument,
4747
    HTMLDocumentNode_QI,
4748
    HTMLDocumentNode_destructor,
4749
    HTMLDocument_cpc,
4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763
    HTMLDocumentNode_clone,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    HTMLDocumentNode_traverse,
    HTMLDocumentNode_unlink
4764 4765
};

4766 4767
static HRESULT HTMLDocumentFragment_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
{
4768
    HTMLDocumentNode *This = impl_from_HTMLDOMNode(iface);
4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779
    HTMLDocumentNode *new_node;
    HRESULT hres;

    hres = create_document_fragment(nsnode, This->node.doc, &new_node);
    if(FAILED(hres))
        return hres;

    *ret = &new_node->node;
    return S_OK;
}

4780 4781
static inline HTMLDocumentNode *impl_from_DispatchEx(DispatchEx *iface)
{
4782
    return CONTAINING_RECORD(iface, HTMLDocumentNode, node.event_target.dispex);
4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796
}

static HRESULT HTMLDocumentNode_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
        VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
{
    HTMLDocumentNode *This = impl_from_DispatchEx(dispex);
    nsIDOMNodeList *node_list;
    nsAString name_str;
    nsIDOMNode *nsnode;
    HTMLDOMNode *node;
    unsigned i;
    nsresult nsres;
    HRESULT hres;

4797
    if(flags != DISPATCH_PROPERTYGET && flags != (DISPATCH_METHOD|DISPATCH_PROPERTYGET)) {
4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826
        FIXME("unsupported flags %x\n", flags);
        return E_NOTIMPL;
    }

    i = id - MSHTML_DISPID_CUSTOM_MIN;

    if(!This->nsdoc || i >= This->elem_vars_cnt)
        return DISP_E_UNKNOWNNAME;

    nsAString_InitDepend(&name_str, This->elem_vars[i]);
    nsres = nsIDOMHTMLDocument_GetElementsByName(This->nsdoc, &name_str, &node_list);
    nsAString_Finish(&name_str);
    if(NS_FAILED(nsres))
        return E_FAIL;

    nsres = nsIDOMNodeList_Item(node_list, 0, &nsnode);
    nsIDOMNodeList_Release(node_list);
    if(NS_FAILED(nsres) || !nsnode)
        return DISP_E_UNKNOWNNAME;

    hres = get_node(This, nsnode, TRUE, &node);
    if(FAILED(hres))
        return hres;

    V_VT(res) = VT_DISPATCH;
    V_DISPATCH(res) = (IDispatch*)&node->IHTMLDOMNode_iface;
    return S_OK;
}

4827 4828 4829 4830 4831
static void HTMLDocumentNode_bind_event(DispatchEx *dispex, int eid)
{
    HTMLDocumentNode *This = impl_from_DispatchEx(dispex);
    ensure_doc_nsevent_handler(This, eid);
}
4832 4833 4834 4835

static const dispex_static_data_vtbl_t HTMLDocumentNode_dispex_vtbl = {
    NULL,
    NULL,
4836
    HTMLDocumentNode_invoke,
4837 4838 4839
    NULL,
    NULL,
    HTMLDocumentNode_bind_event
4840 4841
};

4842
static const NodeImplVtbl HTMLDocumentFragmentImplVtbl = {
4843
    &CLSID_HTMLDocument,
4844 4845
    HTMLDocumentNode_QI,
    HTMLDocumentNode_destructor,
4846
    HTMLDocument_cpc,
4847 4848 4849
    HTMLDocumentFragment_clone
};

4850 4851 4852 4853 4854 4855 4856
static const tid_t HTMLDocumentNode_iface_tids[] = {
    IHTMLDOMNode_tid,
    IHTMLDOMNode2_tid,
    IHTMLDocument2_tid,
    IHTMLDocument3_tid,
    IHTMLDocument4_tid,
    IHTMLDocument5_tid,
4857
    IHTMLDocument6_tid,
4858
    IDocumentSelector_tid,
4859 4860 4861 4862
    0
};

static dispex_static_data_t HTMLDocumentNode_dispex = {
4863
    &HTMLDocumentNode_dispex_vtbl,
4864 4865 4866 4867
    DispHTMLDocument_tid,
    HTMLDocumentNode_iface_tids
};

4868
static HTMLDocumentNode *alloc_doc_node(HTMLDocumentObj *doc_obj, HTMLInnerWindow *window)
4869 4870
{
    HTMLDocumentNode *doc;
4871

4872 4873
    doc = heap_alloc_zero(sizeof(HTMLDocumentNode));
    if(!doc)
4874
        return NULL;
4875

4876
    doc->ref = 1;
4877 4878
    doc->basedoc.doc_node = doc;
    doc->basedoc.doc_obj = doc_obj;
4879 4880
    doc->basedoc.window = window->base.outer_window;
    doc->window = window;
4881

4882
    init_dispex(&doc->node.event_target.dispex, (IUnknown*)&doc->node.IHTMLDOMNode_iface,
4883 4884
            &HTMLDocumentNode_dispex);
    init_doc(&doc->basedoc, (IUnknown*)&doc->node.IHTMLDOMNode_iface,
4885
            &doc->node.event_target.dispex.IDispatchEx_iface);
4886
    HTMLDocumentNode_SecMgr_Init(doc);
4887

4888 4889
    list_init(&doc->selection_list);
    list_init(&doc->range_list);
4890
    list_init(&doc->plugin_hosts);
4891 4892 4893 4894

    return doc;
}

4895
HRESULT create_doc_from_nsdoc(nsIDOMHTMLDocument *nsdoc, HTMLDocumentObj *doc_obj, HTMLInnerWindow *window, HTMLDocumentNode **ret)
4896 4897 4898 4899 4900 4901 4902
{
    HTMLDocumentNode *doc;

    doc = alloc_doc_node(doc_obj, window);
    if(!doc)
        return E_OUTOFMEMORY;

4903
    if(!doc_obj->basedoc.window || window->base.outer_window == doc_obj->basedoc.window)
4904
        doc->basedoc.cp_container.forward_container = &doc_obj->basedoc.cp_container;
4905

4906 4907
    HTMLDOMNode_Init(doc, &doc->node, (nsIDOMNode*)nsdoc);

4908
    nsIDOMHTMLDocument_AddRef(nsdoc);
4909
    doc->nsdoc = nsdoc;
4910

4911
    init_document_mutation(doc);
4912
    doc_init_events(doc);
4913

4914
    doc->node.vtbl = &HTMLDocumentNodeImplVtbl;
4915
    doc->node.cp_container = &doc->basedoc.cp_container;
4916

4917 4918 4919
    *ret = doc;
    return S_OK;
}
4920

4921
static HRESULT create_document_fragment(nsIDOMNode *nsnode, HTMLDocumentNode *doc_node, HTMLDocumentNode **ret)
4922 4923 4924
{
    HTMLDocumentNode *doc_frag;

4925
    doc_frag = alloc_doc_node(doc_node->basedoc.doc_obj, doc_node->window);
4926 4927 4928
    if(!doc_frag)
        return E_OUTOFMEMORY;

4929 4930
    IHTMLWindow2_AddRef(&doc_frag->window->base.IHTMLWindow2_iface);

4931
    HTMLDOMNode_Init(doc_node, &doc_frag->node, nsnode);
4932
    doc_frag->node.vtbl = &HTMLDocumentFragmentImplVtbl;
4933 4934 4935 4936 4937 4938
    doc_frag->node.cp_container = &doc_frag->basedoc.cp_container;

    *ret = doc_frag;
    return S_OK;
}

4939
static inline HTMLDocumentObj *impl_from_IUnknown(IUnknown *iface)
4940
{
4941
    return CONTAINING_RECORD(iface, HTMLDocumentObj, IUnknown_outer);
4942
}
4943

4944
static HRESULT WINAPI HTMLDocumentObj_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
4945
{
4946
    HTMLDocumentObj *This = impl_from_IUnknown(iface);
4947

4948 4949
    TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);

4950 4951 4952
    if(IsEqualGUID(&IID_IUnknown, riid)) {
        *ppv = &This->IUnknown_outer;
    }else if(htmldoc_qi(&This->basedoc, riid, ppv)) {
4953
        return *ppv ? S_OK : E_NOINTERFACE;
4954
    }else if(IsEqualGUID(&IID_ICustomDoc, riid)) {
4955
        *ppv = &This->ICustomDoc_iface;
4956 4957
    }else if(IsEqualGUID(&IID_ITargetContainer, riid)) {
        *ppv = &This->ITargetContainer_iface;
4958 4959
    }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
        return *ppv ? S_OK : E_NOINTERFACE;
4960
    }else {
4961
        FIXME("Unimplemented interface %s\n", debugstr_mshtml_guid(riid));
4962 4963 4964 4965 4966 4967
        *ppv = NULL;
        return E_NOINTERFACE;
    }

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

4970
static ULONG WINAPI HTMLDocumentObj_AddRef(IUnknown *iface)
4971
{
4972
    HTMLDocumentObj *This = impl_from_IUnknown(iface);
4973 4974 4975 4976 4977 4978 4979
    ULONG ref = InterlockedIncrement(&This->ref);

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

    return ref;
}

4980
static ULONG WINAPI HTMLDocumentObj_Release(IUnknown *iface)
4981
{
4982
    HTMLDocumentObj *This = impl_from_IUnknown(iface);
4983 4984 4985 4986 4987
    ULONG ref = InterlockedDecrement(&This->ref);

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

    if(!ref) {
4988 4989 4990 4991 4992
        nsIDOMWindowUtils *window_utils = NULL;

        if(This->basedoc.window && This->basedoc.window->nswindow)
            get_nsinterface((nsISupports*)This->basedoc.window->nswindow, &IID_nsIDOMWindowUtils, (void**)&window_utils);

4993 4994
        if(This->basedoc.doc_node) {
            This->basedoc.doc_node->basedoc.doc_obj = NULL;
4995
            htmldoc_release(&This->basedoc.doc_node->basedoc);
4996
        }
4997 4998
        if(This->basedoc.window) {
            This->basedoc.window->doc_obj = NULL;
4999
            IHTMLWindow2_Release(&This->basedoc.window->base.IHTMLWindow2_iface);
5000
        }
5001 5002
        if(This->basedoc.advise_holder)
            IOleAdviseHolder_Release(This->basedoc.advise_holder);
5003

5004 5005
        if(This->view_sink)
            IAdviseSink_Release(This->view_sink);
5006
        if(This->client)
5007
            IOleObject_SetClientSite(&This->basedoc.IOleObject_iface, NULL);
5008
        if(This->hostui)
5009
            ICustomDoc_SetUIHandler(&This->ICustomDoc_iface, NULL);
5010
        if(This->in_place_active)
5011
            IOleInPlaceObjectWindowless_InPlaceDeactivate(&This->basedoc.IOleInPlaceObjectWindowless_iface);
5012
        if(This->ipsite)
5013
            IOleDocumentView_SetInPlaceSite(&This->basedoc.IOleDocumentView_iface, NULL);
5014 5015
        if(This->undomgr)
            IOleUndoManager_Release(This->undomgr);
5016 5017
        if(This->editsvcs)
            IHTMLEditServices_Release(This->editsvcs);
5018 5019 5020 5021 5022
        if(This->tooltips_hwnd)
            DestroyWindow(This->tooltips_hwnd);

        if(This->hwnd)
            DestroyWindow(This->hwnd);
5023
        heap_free(This->mime);
5024

5025
        destroy_htmldoc(&This->basedoc);
5026
        release_dispex(&This->dispex);
5027

5028 5029
        if(This->nscontainer)
            NSContainer_Release(This->nscontainer);
5030
        heap_free(This);
5031 5032 5033 5034 5035 5036

        /* Force cycle collection */
        if(window_utils) {
            nsIDOMWindowUtils_CycleCollect(window_utils, NULL, 0);
            nsIDOMWindowUtils_Release(window_utils);
        }
5037 5038 5039 5040 5041
    }

    return ref;
}

5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077
static const IUnknownVtbl HTMLDocumentObjVtbl = {
    HTMLDocumentObj_QueryInterface,
    HTMLDocumentObj_AddRef,
    HTMLDocumentObj_Release
};

/**********************************************************
 * ICustomDoc implementation
 */

static inline HTMLDocumentObj *impl_from_ICustomDoc(ICustomDoc *iface)
{
    return CONTAINING_RECORD(iface, HTMLDocumentObj, ICustomDoc_iface);
}

static HRESULT WINAPI CustomDoc_QueryInterface(ICustomDoc *iface, REFIID riid, void **ppv)
{
    HTMLDocumentObj *This = impl_from_ICustomDoc(iface);

    return htmldoc_query_interface(&This->basedoc, riid, ppv);
}

static ULONG WINAPI CustomDoc_AddRef(ICustomDoc *iface)
{
    HTMLDocumentObj *This = impl_from_ICustomDoc(iface);

    return htmldoc_addref(&This->basedoc);
}

static ULONG WINAPI CustomDoc_Release(ICustomDoc *iface)
{
    HTMLDocumentObj *This = impl_from_ICustomDoc(iface);

    return htmldoc_release(&This->basedoc);
}

5078 5079
static HRESULT WINAPI CustomDoc_SetUIHandler(ICustomDoc *iface, IDocHostUIHandler *pUIHandler)
{
5080
    HTMLDocumentObj *This = impl_from_ICustomDoc(iface);
5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105
    IOleCommandTarget *cmdtrg;
    HRESULT hres;

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

    if(This->custom_hostui && This->hostui == pUIHandler)
        return S_OK;

    This->custom_hostui = TRUE;

    if(This->hostui)
        IDocHostUIHandler_Release(This->hostui);
    if(pUIHandler)
        IDocHostUIHandler_AddRef(pUIHandler);
    This->hostui = pUIHandler;
    if(!pUIHandler)
        return S_OK;

    hres = IDocHostUIHandler_QueryInterface(pUIHandler, &IID_IOleCommandTarget, (void**)&cmdtrg);
    if(SUCCEEDED(hres)) {
        FIXME("custom UI handler supports IOleCommandTarget\n");
        IOleCommandTarget_Release(cmdtrg);
    }

    return S_OK;
5106 5107 5108 5109 5110 5111 5112
}

static const ICustomDocVtbl CustomDocVtbl = {
    CustomDoc_QueryInterface,
    CustomDoc_AddRef,
    CustomDoc_Release,
    CustomDoc_SetUIHandler
5113 5114
};

5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127
static const tid_t HTMLDocumentObj_iface_tids[] = {
    IHTMLDocument2_tid,
    IHTMLDocument3_tid,
    IHTMLDocument4_tid,
    IHTMLDocument5_tid,
    0
};
static dispex_static_data_t HTMLDocumentObj_dispex = {
    NULL,
    DispHTMLDocument_tid,
    HTMLDocumentObj_iface_tids
};

5128
static HRESULT create_document_object(BOOL is_mhtml, IUnknown *outer, REFIID riid, void **ppv)
5129
{
5130
    mozIDOMWindowProxy *mozwindow;
5131
    HTMLDocumentObj *doc;
5132
    nsIDOMWindow *nswindow = NULL;
5133
    nsresult nsres;
5134 5135
    HRESULT hres;

5136 5137 5138 5139
    if(outer && !IsEqualGUID(&IID_IUnknown, riid)) {
        *ppv = NULL;
        return E_INVALIDARG;
    }
5140

5141 5142 5143 5144
    doc = heap_alloc_zero(sizeof(HTMLDocumentObj));
    if(!doc)
        return E_OUTOFMEMORY;

5145 5146 5147 5148
    doc->ref = 1;
    doc->IUnknown_outer.lpVtbl = &HTMLDocumentObjVtbl;
    doc->ICustomDoc_iface.lpVtbl = &CustomDocVtbl;

5149
    init_dispex(&doc->dispex, (IUnknown*)&doc->ICustomDoc_iface, &HTMLDocumentObj_dispex);
5150
    init_doc(&doc->basedoc, outer ? outer : &doc->IUnknown_outer, &doc->dispex.IDispatchEx_iface);
5151
    TargetContainer_Init(doc);
5152
    doc->basedoc.doc_obj = doc;
5153
    doc->is_mhtml = is_mhtml;
5154

5155 5156
    doc->usermode = UNKNOWN_USERMODE;

5157 5158
    init_binding_ui(doc);

5159
    hres = create_nscontainer(doc, &doc->nscontainer);
5160
    if(FAILED(hres)) {
5161 5162
        ERR("Failed to init Gecko, returning CLASS_E_CLASSNOTAVAILABLE\n");
        htmldoc_release(&doc->basedoc);
5163
        return hres;
5164 5165
    }

5166 5167 5168 5169 5170 5171 5172 5173
    if(IsEqualGUID(&IID_IUnknown, riid)) {
        *ppv = &doc->IUnknown_outer;
    }else {
        hres = htmldoc_query_interface(&doc->basedoc, riid, ppv);
        htmldoc_release(&doc->basedoc);
        if(FAILED(hres))
            return hres;
    }
5174

5175
    nsres = nsIWebBrowser_GetContentDOMWindow(doc->nscontainer->webbrowser, &mozwindow);
5176 5177
    if(NS_FAILED(nsres))
        ERR("GetContentDOMWindow failed: %08x\n", nsres);
5178

5179 5180 5181 5182
    nsres = mozIDOMWindowProxy_QueryInterface(mozwindow, &IID_nsIDOMWindow, (void**)&nswindow);
    mozIDOMWindowProxy_Release(mozwindow);
    assert(nsres == NS_OK);

5183
    hres = HTMLOuterWindow_Create(doc, nswindow, NULL /* FIXME */, &doc->basedoc.window);
5184 5185
    if(nswindow)
        nsIDOMWindow_Release(nswindow);
5186
    if(FAILED(hres)) {
5187
        htmldoc_release(&doc->basedoc);
5188 5189
        return hres;
    }
5190

5191 5192
    if(!doc->basedoc.doc_node && doc->basedoc.window->base.inner_window->doc) {
        doc->basedoc.doc_node = doc->basedoc.window->base.inner_window->doc;
5193 5194 5195
        htmldoc_addref(&doc->basedoc.doc_node->basedoc);
    }

5196 5197
    get_thread_hwnd();

5198
    return S_OK;
5199
}
5200

5201 5202 5203 5204 5205 5206
HRESULT HTMLDocument_Create(IUnknown *outer, REFIID riid, void **ppv)
{
    TRACE("(%p %s %p)\n", outer, debugstr_mshtml_guid(riid), ppv);
    return create_document_object(FALSE, outer, riid, ppv);
}

5207 5208
HRESULT MHTMLDocument_Create(IUnknown *outer, REFIID riid, void **ppv)
{
5209 5210
    TRACE("(%p %s %p)\n", outer, debugstr_mshtml_guid(riid), ppv);
    return create_document_object(TRUE, outer, riid, ppv);
5211
}