htmldoc.c 54.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright 2005 Jacek Caban
 *
 * 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 23 24 25 26 27 28 29
 */

#include "config.h"

#include <stdarg.h>
#include <stdio.h>

#define COBJMACROS

#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "ole2.h"
30
#include "perhist.h"
31 32 33 34

#include "wine/debug.h"

#include "mshtml_private.h"
35
#include "htmlevent.h"
36 37 38

WINE_DEFAULT_DEBUG_CHANNEL(mshtml);

39 40
#define HTMLDOC_THIS(iface) DEFINE_THIS(HTMLDocument, HTMLDocument2, iface)

41 42
static HRESULT WINAPI HTMLDocument_QueryInterface(IHTMLDocument2 *iface, REFIID riid, void **ppvObject)
{
43
    HTMLDocument *This = HTMLDOC_THIS(iface);
44 45 46

    *ppvObject = NULL;
    if(IsEqualGUID(&IID_IUnknown, riid)) {
47
        TRACE("(%p)->(IID_IUnknown, %p)\n", This, ppvObject);
48 49
        *ppvObject = HTMLDOC(This);
    }else if(IsEqualGUID(&IID_IDispatch, riid)) {
50
        TRACE("(%p)->(IID_IDispatch, %p)\n", This, ppvObject);
51 52 53 54
        *ppvObject = DISPATCHEX(This);
    }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
        TRACE("(%p)->(IID_IDispatchEx, %p)\n", This, ppvObject);
        *ppvObject = DISPATCHEX(This);
55
    }else if(IsEqualGUID(&IID_IHTMLDocument, riid)) {
56
        TRACE("(%p)->(IID_IHTMLDocument, %p)\n", This, ppvObject);
57 58
        *ppvObject = HTMLDOC(This);
    }else if(IsEqualGUID(&IID_IHTMLDocument2, riid)) {
59
        TRACE("(%p)->(IID_IHTMLDocument2, %p)\n", This, ppvObject);
60
        *ppvObject = HTMLDOC(This);
61 62 63
    }else if(IsEqualGUID(&IID_IHTMLDocument3, riid)) {
        TRACE("(%p)->(IID_IHTMLDocument3, %p)\n", This, ppvObject);
        *ppvObject = HTMLDOC3(This);
64 65 66
    }else if(IsEqualGUID(&IID_IHTMLDocument4, riid)) {
        TRACE("(%p)->(IID_IHTMLDocument4, %p)\n", This, ppvObject);
        *ppvObject = HTMLDOC4(This);
67 68 69
    }else if(IsEqualGUID(&IID_IHTMLDocument5, riid)) {
        TRACE("(%p)->(IID_IHTMLDocument5, %p)\n", This, ppvObject);
        *ppvObject = HTMLDOC5(This);
70 71 72 73 74 75 76 77 78 79 80 81
    }else if(IsEqualGUID(&IID_IPersist, riid)) {
        TRACE("(%p)->(IID_IPersist, %p)\n", This, ppvObject);
        *ppvObject = PERSIST(This);
    }else if(IsEqualGUID(&IID_IPersistMoniker, riid)) {
        TRACE("(%p)->(IID_IPersistMoniker, %p)\n", This, ppvObject);
        *ppvObject = PERSISTMON(This);
    }else if(IsEqualGUID(&IID_IPersistFile, riid)) {
        TRACE("(%p)->(IID_IPersistFile, %p)\n", This, ppvObject);
        *ppvObject = PERSISTFILE(This);
    }else if(IsEqualGUID(&IID_IMonikerProp, riid)) {
        TRACE("(%p)->(IID_IMonikerProp, %p)\n", This, ppvObject);
        *ppvObject = MONPROP(This);
82 83 84 85 86 87
    }else if(IsEqualGUID(&IID_IOleObject, riid)) {
        TRACE("(%p)->(IID_IOleObject, %p)\n", This, ppvObject);
        *ppvObject = OLEOBJ(This);
    }else if(IsEqualGUID(&IID_IOleDocument, riid)) {
        TRACE("(%p)->(IID_IOleDocument, %p)\n", This, ppvObject);
        *ppvObject = OLEDOC(This);
88 89 90
    }else if(IsEqualGUID(&IID_IOleDocumentView, riid)) {
        TRACE("(%p)->(IID_IOleDocumentView, %p)\n", This, ppvObject);
        *ppvObject = DOCVIEW(This);
91 92 93
    }else if(IsEqualGUID(&IID_IOleInPlaceActiveObject, riid)) {
        TRACE("(%p)->(IID_IOleInPlaceActiveObject, %p)\n", This, ppvObject);
        *ppvObject = ACTOBJ(This);
94 95 96 97 98 99
    }else if(IsEqualGUID(&IID_IViewObject, riid)) {
        TRACE("(%p)->(IID_IViewObject, %p)\n", This, ppvObject);
        *ppvObject = VIEWOBJ(This);
    }else if(IsEqualGUID(&IID_IViewObject2, riid)) {
        TRACE("(%p)->(IID_IViewObject2, %p)\n", This, ppvObject);
        *ppvObject = VIEWOBJ2(This);
100 101 102 103 104 105 106 107 108
    }else if(IsEqualGUID(&IID_IOleWindow, riid)) {
        TRACE("(%p)->(IID_IOleWindow, %p)\n", This, ppvObject);
        *ppvObject = OLEWIN(This);
    }else if(IsEqualGUID(&IID_IOleInPlaceObject, riid)) {
        TRACE("(%p)->(IID_IOleInPlaceObject, %p)\n", This, ppvObject);
        *ppvObject = INPLACEOBJ(This);
    }else if(IsEqualGUID(&IID_IOleInPlaceObjectWindowless, riid)) {
        TRACE("(%p)->(IID_IOleInPlaceObjectWindowless, %p)\n", This, ppvObject);
        *ppvObject = INPLACEWIN(This);
109 110 111
    }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
        TRACE("(%p)->(IID_IServiceProvider, %p)\n", This, ppvObject);
        *ppvObject = SERVPROV(This);
112 113 114
    }else if(IsEqualGUID(&IID_IOleCommandTarget, riid)) {
        TRACE("(%p)->(IID_IOleCommandTarget, %p)\n", This, ppvObject);
        *ppvObject = CMDTARGET(This);
115 116 117
    }else if(IsEqualGUID(&IID_IOleControl, riid)) {
        TRACE("(%p)->(IID_IOleControl, %p)\n", This, ppvObject);
        *ppvObject = CONTROL(This);
118 119 120
    }else if(IsEqualGUID(&IID_IHlinkTarget, riid)) {
        TRACE("(%p)->(IID_IHlinkTarget, %p)\n", This, ppvObject);
        *ppvObject = HLNKTARGET(This);
121 122
    }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
        TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppvObject);
123
        *ppvObject = CONPTCONT(&This->cp_container);
124 125 126
    }else if(IsEqualGUID(&IID_IPersistStreamInit, riid)) {
        TRACE("(%p)->(IID_IPersistStreamInit %p)\n", This, ppvObject);
        *ppvObject = PERSTRINIT(This);
127 128 129
    }else if(IsEqualGUID(&IID_ICustomDoc, riid)) {
        TRACE("(%p)->(IID_ICustomDoc %p)\n", This, ppvObject);
        *ppvObject = CUSTOMDOC(This);
130 131 132
    }else if(IsEqualGUID(&DIID_DispHTMLDocument, riid)) {
        TRACE("(%p)->(DIID_DispHTMLDocument %p)\n", This, ppvObject);
        *ppvObject = HTMLDOC(This);
133 134 135
    }else if(IsEqualGUID(&IID_ISupportErrorInfo, riid)) {
        TRACE("(%p)->(IID_ISupportErrorInfo %p)\n", This, ppvObject);
        *ppvObject = SUPPERRINFO(This);
136
    }else if(IsEqualGUID(&IID_IPersistHistory, riid)) {
137 138
        TRACE("(%p)->(IID_IPersistHistory %p)\n", This, ppvObject);
        *ppvObject = PERSISTHIST(This);
139 140 141
    }else if(IsEqualGUID(&CLSID_CMarkup, riid)) {
        FIXME("(%p)->(CLSID_CMarkup %p)\n", This, ppvObject);
        return E_NOINTERFACE;
142 143 144
    }else if(IsEqualGUID(&IID_IRunnableObject, riid)) {
        TRACE("(%p)->(IID_IRunnableObject %p) returning NULL\n", This, ppvObject);
        return E_NOINTERFACE;
145 146 147
    }else if(IsEqualGUID(&IID_IPersistPropertyBag, riid)) {
        TRACE("(%p)->(IID_IPersistPropertyBag %p) returning NULL\n", This, ppvObject);
        return E_NOINTERFACE;
148 149 150
    }else if(IsEqualGUID(&IID_IMarshal, riid)) {
        TRACE("(%p)->(IID_IMarshal %p) returning NULL\n", This, ppvObject);
        return E_NOINTERFACE;
151 152
    }else if(dispex_query_interface(&This->dispex, riid, ppvObject)) {
        return *ppvObject ? S_OK : E_NOINTERFACE;
153
    }
154

155 156 157 158 159 160 161 162 163 164 165
    if(*ppvObject) {
        IHTMLDocument2_AddRef(iface);
        return S_OK;
    }

    FIXME("(%p)->(%s %p) interface not supported\n", This, debugstr_guid(riid), ppvObject);
    return E_NOINTERFACE;
}

static ULONG WINAPI HTMLDocument_AddRef(IHTMLDocument2 *iface)
{
166
    HTMLDocument *This = HTMLDOC_THIS(iface);
167
    ULONG ref = InterlockedIncrement(&This->ref);
168
    TRACE("(%p) ref = %u\n", This, ref);
169 170 171 172 173
    return ref;
}

static ULONG WINAPI HTMLDocument_Release(IHTMLDocument2 *iface)
{
174
    HTMLDocument *This = HTMLDOC_THIS(iface);
175 176
    ULONG ref = InterlockedDecrement(&This->ref);

177
    TRACE("(%p) ref = %u\n", This, ref);
178

179
    if(!ref) {
180
        remove_doc_tasks(This);
181
        release_script_hosts(This);
182

183
        if(This->client)
184 185 186
            IOleObject_SetClientSite(OLEOBJ(This), NULL);
        if(This->in_place_active)
            IOleInPlaceObjectWindowless_InPlaceDeactivate(INPLACEWIN(This));
187
        if(This->ipsite)
188
            IOleDocumentView_SetInPlaceSite(DOCVIEW(This), NULL);
189 190
        if(This->undomgr)
            IOleUndoManager_Release(This->undomgr);
191

192
        set_document_bscallback(This, NULL);
193
        set_current_mon(This, NULL);
194

195 196
        if(This->tooltips_hwnd)
            DestroyWindow(This->tooltips_hwnd);
197 198
        if(This->hwnd)
            DestroyWindow(This->hwnd);
199

200 201 202 203 204
        if(This->option_factory) {
            This->option_factory->doc = NULL;
            IHTMLOptionElementFactory_Release(HTMLOPTFACTORY(This->option_factory));
        }

205 206 207
        if(This->location)
            This->location->doc = NULL;

208 209 210
        if(This->window)
            IHTMLWindow2_Release(HTMLWINDOW2(This->window));

211 212 213
        if(This->event_target)
            release_event_target(This->event_target);

214
        heap_free(This->mime);
215
        detach_selection(This);
216
        detach_ranges(This);
217
        release_nodes(This);
218

219
        ConnectionPointContainer_Destroy(&This->cp_container);
220

221 222
        if(This->nsdoc) {
            remove_mutation_observer(This->nscontainer, This->nsdoc);
223
            nsIDOMHTMLDocument_Release(This->nsdoc);
224
        }
225
        if(This->nscontainer)
226 227
            NSContainer_Release(This->nscontainer);

228
        heap_free(This);
229
    }
230 231 232 233 234 235

    return ref;
}

static HRESULT WINAPI HTMLDocument_GetTypeInfoCount(IHTMLDocument2 *iface, UINT *pctinfo)
{
236
    HTMLDocument *This = HTMLDOC_THIS(iface);
237 238

    return IDispatchEx_GetTypeInfoCount(DISPATCHEX(This), pctinfo);
239 240 241 242 243
}

static HRESULT WINAPI HTMLDocument_GetTypeInfo(IHTMLDocument2 *iface, UINT iTInfo,
                                                LCID lcid, ITypeInfo **ppTInfo)
{
244
    HTMLDocument *This = HTMLDOC_THIS(iface);
245 246

    return IDispatchEx_GetTypeInfo(DISPATCHEX(This), iTInfo, lcid, ppTInfo);
247 248 249 250 251 252
}

static HRESULT WINAPI HTMLDocument_GetIDsOfNames(IHTMLDocument2 *iface, REFIID riid,
                                                LPOLESTR *rgszNames, UINT cNames,
                                                LCID lcid, DISPID *rgDispId)
{
253
    HTMLDocument *This = HTMLDOC_THIS(iface);
254 255

    return IDispatchEx_GetIDsOfNames(DISPATCHEX(This), riid, rgszNames, cNames, lcid, rgDispId);
256 257 258 259 260 261
}

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

264 265
    return IDispatchEx_Invoke(DISPATCHEX(This), dispIdMember, riid, lcid, wFlags, pDispParams,
            pVarResult, pExcepInfo, puArgErr);
266 267 268 269
}

static HRESULT WINAPI HTMLDocument_get_Script(IHTMLDocument2 *iface, IDispatch **p)
{
270
    HTMLDocument *This = HTMLDOC_THIS(iface);
271 272 273 274 275 276

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

    *p = (IDispatch*)HTMLWINDOW2(This->window);
    IDispatch_AddRef(*p);
    return S_OK;
277 278 279 280
}

static HRESULT WINAPI HTMLDocument_get_all(IHTMLDocument2 *iface, IHTMLElementCollection **p)
{
281
    HTMLDocument *This = HTMLDOC_THIS(iface);
282 283
    nsIDOMElement *nselem = NULL;
    nsresult nsres;
284 285 286

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

287 288 289
    if(!This->nsdoc) {
        WARN("NULL nsdoc\n");
        return E_UNEXPECTED;
290 291
    }

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

298 299 300 301
    if(nselem) {
        *p = create_all_collection(get_node(This, (nsIDOMNode*)nselem, TRUE), TRUE);
        nsIDOMElement_Release(nselem);
    }else {
302 303
        *p = NULL;
    }
304

305
    return S_OK;
306 307 308 309
}

static HRESULT WINAPI HTMLDocument_get_body(IHTMLDocument2 *iface, IHTMLElement **p)
{
310 311 312 313 314 315 316
    HTMLDocument *This = HTMLDOC_THIS(iface);
    nsIDOMHTMLElement *nsbody = NULL;
    HTMLDOMNode *node;
    nsresult nsres;

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

317 318 319
    if(!This->nsdoc) {
        WARN("NULL nsdoc\n");
        return E_UNEXPECTED;
320 321
    }

322 323
    nsres = nsIDOMHTMLDocument_GetBody(This->nsdoc, &nsbody);
    if(NS_FAILED(nsres)) {
324
        TRACE("Could not get body: %08x\n", nsres);
325
        return E_UNEXPECTED;
326 327
    }

328 329 330
    if(nsbody) {
        node = get_node(This, (nsIDOMNode*)nsbody, TRUE);
        nsIDOMHTMLElement_Release(nsbody);
331

332 333 334 335
        IHTMLDOMNode_QueryInterface(HTMLDOMNODE(node), &IID_IHTMLElement, (void**)p);
    }else {
        *p = NULL;
    }
336 337 338

    TRACE("*p = %p\n", *p);
    return S_OK;
339 340 341 342
}

static HRESULT WINAPI HTMLDocument_get_activeElement(IHTMLDocument2 *iface, IHTMLElement **p)
{
343 344
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
345 346 347 348 349
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_images(IHTMLDocument2 *iface, IHTMLElementCollection **p)
{
350
    HTMLDocument *This = HTMLDOC_THIS(iface);
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 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;

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

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

    if(nscoll) {
        *p = create_collection_from_htmlcol(This, (IUnknown*)HTMLDOC(This), nscoll);
        nsIDOMElement_Release(nscoll);
    }

    return S_OK;
378 379 380 381
}

static HRESULT WINAPI HTMLDocument_get_applets(IHTMLDocument2 *iface, IHTMLElementCollection **p)
{
382
    HTMLDocument *This = HTMLDOC_THIS(iface);
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 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;

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

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

    if(nscoll) {
        *p = create_collection_from_htmlcol(This, (IUnknown*)HTMLDOC(This), nscoll);
        nsIDOMElement_Release(nscoll);
    }

    return S_OK;
410 411 412 413
}

static HRESULT WINAPI HTMLDocument_get_links(IHTMLDocument2 *iface, IHTMLElementCollection **p)
{
414
    HTMLDocument *This = HTMLDOC_THIS(iface);
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 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;

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

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

    if(nscoll) {
        *p = create_collection_from_htmlcol(This, (IUnknown*)HTMLDOC(This), nscoll);
        nsIDOMElement_Release(nscoll);
    }

    return S_OK;
442 443 444 445
}

static HRESULT WINAPI HTMLDocument_get_forms(IHTMLDocument2 *iface, IHTMLElementCollection **p)
{
446
    HTMLDocument *This = HTMLDOC_THIS(iface);
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 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;

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

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

    if(nscoll) {
        *p = create_collection_from_htmlcol(This, (IUnknown*)HTMLDOC(This), nscoll);
        nsIDOMElement_Release(nscoll);
    }

    return S_OK;
474 475 476 477
}

static HRESULT WINAPI HTMLDocument_get_anchors(IHTMLDocument2 *iface, IHTMLElementCollection **p)
{
478
    HTMLDocument *This = HTMLDOC_THIS(iface);
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505
    nsIDOMHTMLCollection *nscoll = NULL;
    nsresult nsres;

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

    if(!p)
        return E_INVALIDARG;

    *p = NULL;

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

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

    if(nscoll) {
        *p = create_collection_from_htmlcol(This, (IUnknown*)HTMLDOC(This), nscoll);
        nsIDOMElement_Release(nscoll);
    }

    return S_OK;
506 507 508 509
}

static HRESULT WINAPI HTMLDocument_put_title(IHTMLDocument2 *iface, BSTR v)
{
510
    HTMLDocument *This = HTMLDOC_THIS(iface);
511 512 513 514 515
    nsAString nsstr;
    nsresult nsres;

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

516 517 518
    if(!This->nsdoc) {
        WARN("NULL nsdoc\n");
        return E_UNEXPECTED;
519 520 521
    }

    nsAString_Init(&nsstr, v);
522
    nsres = nsIDOMHTMLDocument_SetTitle(This->nsdoc, &nsstr);
523 524 525 526 527
    nsAString_Finish(&nsstr);
    if(NS_FAILED(nsres))
        ERR("SetTitle failed: %08x\n", nsres);

    return S_OK;
528 529 530 531
}

static HRESULT WINAPI HTMLDocument_get_title(IHTMLDocument2 *iface, BSTR *p)
{
532
    HTMLDocument *This = HTMLDOC_THIS(iface);
533 534 535 536 537 538
    const PRUnichar *ret;
    nsAString nsstr;
    nsresult nsres;

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

539 540 541
    if(!This->nsdoc) {
        WARN("NULL nsdoc\n");
        return E_UNEXPECTED;
542 543 544 545
    }


    nsAString_Init(&nsstr, NULL);
546 547 548 549 550 551
    nsres = nsIDOMHTMLDocument_GetTitle(This->nsdoc, &nsstr);
    if (NS_SUCCEEDED(nsres)) {
        nsAString_GetData(&nsstr, &ret);
        *p = SysAllocString(ret);
    }
    nsAString_Finish(&nsstr);
552

553
    if(NS_FAILED(nsres)) {
554
        ERR("GetTitle failed: %08x\n", nsres);
555 556
        return E_FAIL;
    }
557 558

    return S_OK;
559 560 561 562
}

static HRESULT WINAPI HTMLDocument_get_scripts(IHTMLDocument2 *iface, IHTMLElementCollection **p)
{
563 564
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
565 566 567 568 569
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_designMode(IHTMLDocument2 *iface, BSTR v)
{
570 571
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_w(v));
572 573 574 575 576
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_designMode(IHTMLDocument2 *iface, BSTR *p)
{
577
    HTMLDocument *This = HTMLDOC_THIS(iface);
578 579 580 581 582 583 584 585 586
    static WCHAR szOff[] = {'O','f','f',0};
    FIXME("(%p)->(%p) always returning Off\n", This, p);

    if(!p)
        return E_INVALIDARG;

    *p = SysAllocString(szOff);

    return S_OK;
587 588 589 590
}

static HRESULT WINAPI HTMLDocument_get_selection(IHTMLDocument2 *iface, IHTMLSelectionObject **p)
{
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605
    HTMLDocument *This = HTMLDOC_THIS(iface);
    nsISelection *nsselection = NULL;

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

    if(This->nscontainer) {
        nsIDOMWindow *dom_window = NULL;

        nsIWebBrowser_GetContentDOMWindow(This->nscontainer->webbrowser, &dom_window);
        if(dom_window) {
            nsIDOMWindow_GetSelection(dom_window, &nsselection);
            nsIDOMWindow_Release(dom_window);
        }
    }

606
    *p = HTMLSelectionObject_Create(This, nsselection);
607
    return S_OK;
608 609 610 611
}

static HRESULT WINAPI HTMLDocument_get_readyState(IHTMLDocument2 *iface, BSTR *p)
{
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634
    HTMLDocument *This = HTMLDOC_THIS(iface);

    static const WCHAR wszUninitialized[] = {'u','n','i','n','i','t','i','a','l','i','z','e','d',0};
    static const WCHAR wszLoading[] = {'l','o','a','d','i','n','g',0};
    static const WCHAR wszLoaded[] = {'l','o','a','d','e','d',0};
    static const WCHAR wszInteractive[] = {'i','n','t','e','r','a','c','t','i','v','e',0};
    static const WCHAR wszComplete[] = {'c','o','m','p','l','e','t','e',0};

    static const LPCWSTR readystate_str[] = {
        wszUninitialized,
        wszLoading,
        wszLoaded,
        wszInteractive,
        wszComplete
    };

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

    if(!p)
        return E_POINTER;

    *p = SysAllocString(readystate_str[This->readystate]);
    return S_OK;
635 636 637 638
}

static HRESULT WINAPI HTMLDocument_get_frames(IHTMLDocument2 *iface, IHTMLFramesCollection2 **p)
{
639 640
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
641 642 643 644 645
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_embeds(IHTMLDocument2 *iface, IHTMLElementCollection **p)
{
646 647
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
648 649 650 651 652
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_plugins(IHTMLDocument2 *iface, IHTMLElementCollection **p)
{
653 654
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
655 656 657 658 659
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_alinkColor(IHTMLDocument2 *iface, VARIANT v)
{
660 661
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)\n", This);
662 663 664 665 666
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_alinkColor(IHTMLDocument2 *iface, VARIANT *p)
{
667 668
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
669 670 671 672 673
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_bgColor(IHTMLDocument2 *iface, VARIANT v)
{
674 675
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)\n", This);
676 677 678 679 680
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_bgColor(IHTMLDocument2 *iface, VARIANT *p)
{
681 682
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
683 684 685 686 687
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_fgColor(IHTMLDocument2 *iface, VARIANT v)
{
688 689
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)\n", This);
690 691 692 693 694
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_fgColor(IHTMLDocument2 *iface, VARIANT *p)
{
695 696
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
697 698 699 700 701
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_linkColor(IHTMLDocument2 *iface, VARIANT v)
{
702 703
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->()\n", This);
704 705 706 707 708
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_linkColor(IHTMLDocument2 *iface, VARIANT *p)
{
709 710
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
711 712 713 714 715
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_vlinkColor(IHTMLDocument2 *iface, VARIANT v)
{
716 717
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)\n", This);
718 719 720 721 722
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_vlinkColor(IHTMLDocument2 *iface, VARIANT *p)
{
723 724
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
725 726 727 728 729
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_referrer(IHTMLDocument2 *iface, BSTR *p)
{
730 731
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
732 733 734 735 736
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_location(IHTMLDocument2 *iface, IHTMLLocation **p)
{
737 738 739 740 741 742 743 744 745 746 747
    HTMLDocument *This = HTMLDOC_THIS(iface);

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

    if(This->location)
        IHTMLLocation_AddRef(HTMLLOCATION(This->location));
    else
        This->location = HTMLLocation_Create(This);

    *p = HTMLLOCATION(This->location);
    return S_OK;
748 749 750 751
}

static HRESULT WINAPI HTMLDocument_get_lastModified(IHTMLDocument2 *iface, BSTR *p)
{
752 753
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
754 755 756 757 758
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_URL(IHTMLDocument2 *iface, BSTR v)
{
759 760
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_w(v));
761 762 763 764 765
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_URL(IHTMLDocument2 *iface, BSTR *p)
{
766 767 768 769 770 771 772 773 774
    HTMLDocument *This = HTMLDOC_THIS(iface);

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

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

    *p = SysAllocString(This->url ? This->url : about_blank_url);
    return S_OK;
775 776 777 778
}

static HRESULT WINAPI HTMLDocument_put_domain(IHTMLDocument2 *iface, BSTR v)
{
779 780
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_w(v));
781 782 783 784 785
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_domain(IHTMLDocument2 *iface, BSTR *p)
{
786 787
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
788 789 790 791 792
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_cookie(IHTMLDocument2 *iface, BSTR v)
{
793 794
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_w(v));
795 796 797 798 799
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_cookie(IHTMLDocument2 *iface, BSTR *p)
{
800 801
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
802 803 804 805 806
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_expando(IHTMLDocument2 *iface, VARIANT_BOOL v)
{
807 808
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%x)\n", This, v);
809 810 811 812 813
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_expando(IHTMLDocument2 *iface, VARIANT_BOOL *p)
{
814 815
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
816 817 818 819 820
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_charset(IHTMLDocument2 *iface, BSTR v)
{
821 822
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_w(v));
823 824 825 826 827
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_charset(IHTMLDocument2 *iface, BSTR *p)
{
828 829
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
830 831 832 833 834
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_defaultCharset(IHTMLDocument2 *iface, BSTR v)
{
835 836
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_w(v));
837 838 839 840 841
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_defaultCharset(IHTMLDocument2 *iface, BSTR *p)
{
842 843
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
844 845 846 847 848
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_mimeType(IHTMLDocument2 *iface, BSTR *p)
{
849 850
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
851 852 853 854 855
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_fileSize(IHTMLDocument2 *iface, BSTR *p)
{
856 857
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
858 859 860 861 862
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_fileCreatedDate(IHTMLDocument2 *iface, BSTR *p)
{
863 864
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
865 866 867 868 869
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_fileModifiedDate(IHTMLDocument2 *iface, BSTR *p)
{
870 871
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
872 873 874 875 876
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_fileUpdatedDate(IHTMLDocument2 *iface, BSTR *p)
{
877 878
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
879 880 881 882 883
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_security(IHTMLDocument2 *iface, BSTR *p)
{
884 885
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
886 887 888 889 890
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_protocol(IHTMLDocument2 *iface, BSTR *p)
{
891 892
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
893 894 895 896 897
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_nameProp(IHTMLDocument2 *iface, BSTR *p)
{
898 899
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
900 901 902 903 904
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_write(IHTMLDocument2 *iface, SAFEARRAY *psarray)
{
905 906 907
    HTMLDocument *This = HTMLDOC_THIS(iface);
    nsAString nsstr;
    VARIANT *var;
908
    ULONG i;
909 910 911 912 913
    nsresult nsres;
    HRESULT hres;

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

914 915 916 917 918
    if(!This->nsdoc) {
        WARN("NULL nsdoc\n");
        return E_UNEXPECTED;
    }

919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934
    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;
    }

    nsAString_Init(&nsstr, NULL);

    for(i=0; i < psarray->rgsabound[0].cElements; i++) {
        if(V_VT(var+i) == VT_BSTR) {
            nsAString_SetData(&nsstr, V_BSTR(var+i));
935
            nsres = nsIDOMHTMLDocument_Write(This->nsdoc, &nsstr);
936 937 938 939 940 941 942 943 944 945 946
            if(NS_FAILED(nsres))
                ERR("Write failed: %08x\n", nsres);
        }else {
            FIXME("vt=%d\n", V_VT(var+i));
        }
    }

    nsAString_Finish(&nsstr);
    SafeArrayUnaccessData(psarray);

    return S_OK;
947 948 949 950
}

static HRESULT WINAPI HTMLDocument_writeln(IHTMLDocument2 *iface, SAFEARRAY *psarray)
{
951 952
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, psarray);
953 954 955 956 957 958
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_open(IHTMLDocument2 *iface, BSTR url, VARIANT name,
                        VARIANT features, VARIANT replace, IDispatch **pomWindowResult)
{
959
    HTMLDocument *This = HTMLDOC_THIS(iface);
960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984
    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);

    if(!This->nsdoc) {
        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");

    nsres = nsIDOMHTMLDocument_Open(This->nsdoc);
    if(NS_FAILED(nsres)) {
        ERR("Open failed: %08x\n", nsres);
        return E_FAIL;
    }

    *pomWindowResult = (IDispatch*)HTMLWINDOW2(This->window);
    IHTMLWindow2_AddRef(HTMLWINDOW2(This->window));
    return S_OK;
985 986 987 988
}

static HRESULT WINAPI HTMLDocument_close(IHTMLDocument2 *iface)
{
989
    HTMLDocument *This = HTMLDOC_THIS(iface);
990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005
    nsresult nsres;

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

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

    nsres = nsIDOMHTMLDocument_Close(This->nsdoc);
    if(NS_FAILED(nsres)) {
        ERR("Close failed: %08x\n", nsres);
        return E_FAIL;
    }

    return S_OK;
1006 1007 1008 1009
}

static HRESULT WINAPI HTMLDocument_clear(IHTMLDocument2 *iface)
{
1010 1011
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)\n", This);
1012 1013 1014 1015 1016 1017
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_queryCommandSupported(IHTMLDocument2 *iface, BSTR cmdID,
                                                        VARIANT_BOOL *pfRet)
{
1018 1019
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1020 1021 1022 1023 1024 1025
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_queryCommandEnabled(IHTMLDocument2 *iface, BSTR cmdID,
                                                        VARIANT_BOOL *pfRet)
{
1026 1027
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1028 1029 1030 1031 1032 1033
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_queryCommandState(IHTMLDocument2 *iface, BSTR cmdID,
                                                        VARIANT_BOOL *pfRet)
{
1034 1035
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1036 1037 1038 1039 1040 1041
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_queryCommandIndeterm(IHTMLDocument2 *iface, BSTR cmdID,
                                                        VARIANT_BOOL *pfRet)
{
1042 1043
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1044 1045 1046 1047 1048 1049
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_queryCommandText(IHTMLDocument2 *iface, BSTR cmdID,
                                                        BSTR *pfRet)
{
1050 1051
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1052 1053 1054 1055 1056 1057
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_queryCommandValue(IHTMLDocument2 *iface, BSTR cmdID,
                                                        VARIANT *pfRet)
{
1058 1059
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1060 1061 1062 1063 1064 1065
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_execCommand(IHTMLDocument2 *iface, BSTR cmdID,
                                VARIANT_BOOL showUI, VARIANT value, VARIANT_BOOL *pfRet)
{
1066 1067
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%s %x %p)\n", This, debugstr_w(cmdID), showUI, pfRet);
1068 1069 1070 1071 1072 1073
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_execCommandShowHelp(IHTMLDocument2 *iface, BSTR cmdID,
                                                        VARIANT_BOOL *pfRet)
{
1074 1075
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1076 1077 1078 1079
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_createElement(IHTMLDocument2 *iface, BSTR eTag,
1080
                                                 IHTMLElement **newElem)
1081
{
1082
    HTMLDocument *This = HTMLDOC_THIS(iface);
1083 1084 1085 1086 1087 1088 1089
    nsIDOMElement *nselem;
    HTMLElement *elem;
    nsAString tag_str;
    nsresult nsres;

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

1090 1091 1092 1093
    if(!This->nsdoc) {
        WARN("NULL nsdoc\n");
        return E_UNEXPECTED;
    }
1094 1095

    nsAString_Init(&tag_str, eTag);
1096
    nsres = nsIDOMDocument_CreateElement(This->nsdoc, &tag_str, &nselem);
1097 1098 1099 1100 1101 1102
    nsAString_Finish(&tag_str);
    if(NS_FAILED(nsres)) {
        ERR("CreateElement failed: %08x\n", nsres);
        return E_FAIL;
    }

1103
    elem = HTMLElement_Create(This, (nsIDOMNode*)nselem, TRUE);
1104 1105 1106 1107 1108
    nsIDOMElement_Release(nselem);

    *newElem = HTMLELEM(elem);
    IHTMLElement_AddRef(HTMLELEM(elem));
    return S_OK;
1109 1110 1111 1112
}

static HRESULT WINAPI HTMLDocument_put_onhelp(IHTMLDocument2 *iface, VARIANT v)
{
1113 1114
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)\n", This);
1115 1116 1117 1118 1119
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_onhelp(IHTMLDocument2 *iface, VARIANT *p)
{
1120 1121
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
1122 1123 1124 1125 1126
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_onclick(IHTMLDocument2 *iface, VARIANT v)
{
1127 1128
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)\n", This);
1129 1130 1131 1132 1133
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_onclick(IHTMLDocument2 *iface, VARIANT *p)
{
1134 1135
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
1136 1137 1138 1139 1140
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_ondblclick(IHTMLDocument2 *iface, VARIANT v)
{
1141 1142
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)\n", This);
1143 1144 1145 1146 1147
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_ondblclick(IHTMLDocument2 *iface, VARIANT *p)
{
1148 1149
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
1150 1151 1152 1153 1154
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_onkeyup(IHTMLDocument2 *iface, VARIANT v)
{
1155
    HTMLDocument *This = HTMLDOC_THIS(iface);
1156 1157 1158 1159

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

    return set_doc_event(This, EVENTID_KEYUP, &v);
1160 1161 1162 1163
}

static HRESULT WINAPI HTMLDocument_get_onkeyup(IHTMLDocument2 *iface, VARIANT *p)
{
1164
    HTMLDocument *This = HTMLDOC_THIS(iface);
1165 1166 1167 1168

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

    return get_doc_event(This, EVENTID_KEYUP, p);
1169 1170 1171 1172
}

static HRESULT WINAPI HTMLDocument_put_onkeydown(IHTMLDocument2 *iface, VARIANT v)
{
1173
    HTMLDocument *This = HTMLDOC_THIS(iface);
1174 1175 1176 1177

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

    return set_doc_event(This, EVENTID_KEYDOWN, &v);
1178 1179 1180 1181
}

static HRESULT WINAPI HTMLDocument_get_onkeydown(IHTMLDocument2 *iface, VARIANT *p)
{
1182
    HTMLDocument *This = HTMLDOC_THIS(iface);
1183 1184 1185 1186

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

    return get_doc_event(This, EVENTID_KEYDOWN, p);
1187 1188 1189 1190
}

static HRESULT WINAPI HTMLDocument_put_onkeypress(IHTMLDocument2 *iface, VARIANT v)
{
1191 1192
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)\n", This);
1193 1194 1195 1196 1197
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_onkeypress(IHTMLDocument2 *iface, VARIANT *p)
{
1198 1199
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
1200 1201 1202 1203 1204
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_onmouseup(IHTMLDocument2 *iface, VARIANT v)
{
1205 1206
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)\n", This);
1207 1208 1209 1210 1211
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_onmouseup(IHTMLDocument2 *iface, VARIANT *p)
{
1212 1213
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
1214 1215 1216 1217 1218
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_onmousedown(IHTMLDocument2 *iface, VARIANT v)
{
1219 1220
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)\n", This);
1221 1222 1223 1224 1225
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_onmousedown(IHTMLDocument2 *iface, VARIANT *p)
{
1226 1227
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
1228 1229 1230 1231 1232
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_onmousemove(IHTMLDocument2 *iface, VARIANT v)
{
1233 1234
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)\n", This);
1235 1236 1237 1238 1239
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_onmousemove(IHTMLDocument2 *iface, VARIANT *p)
{
1240 1241
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
1242 1243 1244 1245 1246
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_onmouseout(IHTMLDocument2 *iface, VARIANT v)
{
1247 1248
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)\n", This);
1249 1250 1251 1252 1253
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_onmouseout(IHTMLDocument2 *iface, VARIANT *p)
{
1254 1255
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
1256 1257 1258 1259 1260
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_onmouseover(IHTMLDocument2 *iface, VARIANT v)
{
1261
    HTMLDocument *This = HTMLDOC_THIS(iface);
1262 1263 1264 1265

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

    return set_doc_event(This, EVENTID_MOUSEOVER, &v);
1266 1267 1268 1269
}

static HRESULT WINAPI HTMLDocument_get_onmouseover(IHTMLDocument2 *iface, VARIANT *p)
{
1270
    HTMLDocument *This = HTMLDOC_THIS(iface);
1271 1272 1273 1274

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

    return get_doc_event(This, EVENTID_MOUSEOVER, p);
1275 1276 1277 1278
}

static HRESULT WINAPI HTMLDocument_put_onreadystatechange(IHTMLDocument2 *iface, VARIANT v)
{
1279 1280
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)\n", This);
1281 1282 1283 1284 1285
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_onreadystatechange(IHTMLDocument2 *iface, VARIANT *p)
{
1286 1287
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
1288 1289 1290 1291 1292
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_onafterupdate(IHTMLDocument2 *iface, VARIANT v)
{
1293 1294
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)\n", This);
1295 1296 1297 1298 1299
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_onafterupdate(IHTMLDocument2 *iface, VARIANT *p)
{
1300 1301
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
1302 1303 1304 1305 1306
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_onrowexit(IHTMLDocument2 *iface, VARIANT v)
{
1307 1308
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)\n", This);
1309 1310 1311 1312 1313
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_onrowexit(IHTMLDocument2 *iface, VARIANT *p)
{
1314 1315
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
1316 1317 1318 1319 1320
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_onrowenter(IHTMLDocument2 *iface, VARIANT v)
{
1321 1322
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)\n", This);
1323 1324 1325 1326 1327
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_onrowenter(IHTMLDocument2 *iface, VARIANT *p)
{
1328 1329
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
1330 1331 1332 1333 1334
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_ondragstart(IHTMLDocument2 *iface, VARIANT v)
{
1335
    HTMLDocument *This = HTMLDOC_THIS(iface);
1336 1337 1338 1339

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

    return set_doc_event(This, EVENTID_DRAGSTART, &v);
1340 1341 1342 1343
}

static HRESULT WINAPI HTMLDocument_get_ondragstart(IHTMLDocument2 *iface, VARIANT *p)
{
1344
    HTMLDocument *This = HTMLDOC_THIS(iface);
1345 1346 1347 1348

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

    return get_doc_event(This, EVENTID_DRAGSTART, p);
1349 1350 1351 1352
}

static HRESULT WINAPI HTMLDocument_put_onselectstart(IHTMLDocument2 *iface, VARIANT v)
{
1353
    HTMLDocument *This = HTMLDOC_THIS(iface);
1354 1355 1356 1357

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

    return set_doc_event(This, EVENTID_SELECTSTART, &v);
1358 1359 1360 1361
}

static HRESULT WINAPI HTMLDocument_get_onselectstart(IHTMLDocument2 *iface, VARIANT *p)
{
1362
    HTMLDocument *This = HTMLDOC_THIS(iface);
1363 1364 1365 1366

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

    return get_doc_event(This, EVENTID_SELECTSTART, p);
1367 1368
}

1369
static HRESULT WINAPI HTMLDocument_elementFromPoint(IHTMLDocument2 *iface, LONG x, LONG y,
1370 1371
                                                        IHTMLElement **elementHit)
{
1372
    HTMLDocument *This = HTMLDOC_THIS(iface);
1373
    FIXME("(%p)->(%d %d %p)\n", This, x, y, elementHit);
1374 1375 1376 1377 1378
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_parentWindow(IHTMLDocument2 *iface, IHTMLWindow2 **p)
{
1379 1380 1381 1382 1383 1384 1385
    HTMLDocument *This = HTMLDOC_THIS(iface);

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

    *p = HTMLWINDOW2(This->window);
    IHTMLWindow2_AddRef(*p);
    return S_OK;
1386 1387 1388
}

static HRESULT WINAPI HTMLDocument_get_styleSheets(IHTMLDocument2 *iface,
1389
                                                   IHTMLStyleSheetsCollection **p)
1390
{
1391 1392 1393 1394 1395 1396 1397 1398 1399
    HTMLDocument *This = HTMLDOC_THIS(iface);
    nsIDOMStyleSheetList *nsstylelist;
    nsIDOMDocumentStyle *nsdocstyle;
    nsresult nsres;

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

    *p = NULL;

1400 1401 1402
    if(!This->nsdoc) {
        WARN("NULL nsdoc\n");
        return E_UNEXPECTED;
1403 1404
    }

1405 1406
    nsIDOMHTMLDocument_QueryInterface(This->nsdoc, &IID_nsIDOMDocumentStyle, (void**)&nsdocstyle);
    nsres = nsIDOMDocumentStyle_GetStyleSheets(nsdocstyle, &nsstylelist);
1407
    nsIDOMDocumentStyle_Release(nsdocstyle);
1408 1409 1410 1411
    if(NS_FAILED(nsres)) {
        ERR("GetStyleSheets failed: %08x\n", nsres);
        return E_FAIL;
    }
1412 1413 1414 1415 1416

    *p = HTMLStyleSheetsCollection_Create(nsstylelist);
    nsIDOMDocumentStyle_Release(nsstylelist);

    return S_OK;
1417 1418 1419 1420
}

static HRESULT WINAPI HTMLDocument_put_onbeforeupdate(IHTMLDocument2 *iface, VARIANT v)
{
1421 1422
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)\n", This);
1423 1424 1425 1426 1427
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_onbeforeupdate(IHTMLDocument2 *iface, VARIANT *p)
{
1428 1429
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
1430 1431 1432 1433 1434
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_put_onerrorupdate(IHTMLDocument2 *iface, VARIANT v)
{
1435 1436
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)\n", This);
1437 1438 1439 1440 1441
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_get_onerrorupdate(IHTMLDocument2 *iface, VARIANT *p)
{
1442 1443
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, p);
1444 1445 1446 1447 1448
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_toString(IHTMLDocument2 *iface, BSTR *String)
{
1449 1450
    HTMLDocument *This = HTMLDOC_THIS(iface);
    FIXME("(%p)->(%p)\n", This, String);
1451 1452 1453 1454
    return E_NOTIMPL;
}

static HRESULT WINAPI HTMLDocument_createStyleSheet(IHTMLDocument2 *iface, BSTR bstrHref,
1455
                                            LONG lIndex, IHTMLStyleSheet **ppnewStyleSheet)
1456
{
1457 1458
    HTMLDocument *This = HTMLDOC_THIS(iface);

1459
    FIXME("(%p)->(%s %d %p) semi-stub\n", This, debugstr_w(bstrHref), lIndex, ppnewStyleSheet);
1460

1461
    *ppnewStyleSheet = HTMLStyleSheet_Create(NULL);
1462
    return S_OK;
1463 1464
}

1465
static const IHTMLDocument2Vtbl HTMLDocumentVtbl = {
1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583
    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
};

1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616
#define SUPPINFO_THIS(iface) DEFINE_THIS(HTMLDocument, SupportErrorInfo, iface)

static HRESULT WINAPI SupportErrorInfo_QueryInterface(ISupportErrorInfo *iface, REFIID riid, void **ppv)
{
    HTMLDocument *This = SUPPINFO_THIS(iface);
    return IHTMLDocument_QueryInterface(HTMLDOC(This), riid, ppv);
}

static ULONG WINAPI SupportErrorInfo_AddRef(ISupportErrorInfo *iface)
{
    HTMLDocument *This = SUPPINFO_THIS(iface);
    return IHTMLDocument_AddRef(HTMLDOC(This));
}

static ULONG WINAPI SupportErrorInfo_Release(ISupportErrorInfo *iface)
{
    HTMLDocument *This = SUPPINFO_THIS(iface);
    return IHTMLDocument_Release(HTMLDOC(This));
}

static HRESULT WINAPI SupportErrorInfo_InterfaceSupportsErrorInfo(ISupportErrorInfo *iface, REFIID riid)
{
    FIXME("(%p)->(%s)\n", iface, debugstr_guid(riid));
    return S_FALSE;
}

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

1617 1618 1619 1620 1621 1622
#define DISPEX_THIS(iface) DEFINE_THIS(HTMLDocument, IDispatchEx, iface)

static HRESULT WINAPI DocDispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
{
    HTMLDocument *This = DISPEX_THIS(iface);

1623
    return IHTMLDocument2_QueryInterface(HTMLDOC(This), riid, ppv);
1624 1625 1626 1627 1628 1629
}

static ULONG WINAPI DocDispatchEx_AddRef(IDispatchEx *iface)
{
    HTMLDocument *This = DISPEX_THIS(iface);

1630
    return IHTMLDocument2_AddRef(HTMLDOC(This));
1631 1632 1633 1634 1635 1636
}

static ULONG WINAPI DocDispatchEx_Release(IDispatchEx *iface)
{
    HTMLDocument *This = DISPEX_THIS(iface);

1637
    return IHTMLDocument2_Release(HTMLDOC(This));
1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765
}

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

    return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->dispex), pctinfo);
}

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

    return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->dispex), iTInfo, lcid, ppTInfo);
}

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

    return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->dispex), riid, rgszNames, cNames, lcid, rgDispId);
}

static HRESULT WINAPI DocDispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
                            REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
                            VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
    HTMLDocument *This = DISPEX_THIS(iface);

    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;
        V_I4(pVarResult) = This->readystate;
        return S_OK;
    }

    return IDispatchEx_Invoke(DISPATCHEX(&This->dispex), dispIdMember, riid, lcid, wFlags, pDispParams,
                              pVarResult, pExcepInfo, puArgErr);
}

static HRESULT WINAPI DocDispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
{
    HTMLDocument *This = DISPEX_THIS(iface);

    return IDispatchEx_GetDispID(DISPATCHEX(&This->dispex), bstrName, grfdex, pid);
}

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

    return IDispatchEx_InvokeEx(DISPATCHEX(&This->dispex), id, lcid, wFlags, pdp, pvarRes, pei, pspCaller);
}

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

    return IDispatchEx_DeleteMemberByName(DISPATCHEX(&This->dispex), bstrName, grfdex);
}

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

    return IDispatchEx_DeleteMemberByDispID(DISPATCHEX(&This->dispex), id);
}

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

    return IDispatchEx_GetMemberProperties(DISPATCHEX(&This->dispex), id, grfdexFetch, pgrfdex);
}

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

    return IDispatchEx_GetMemberName(DISPATCHEX(&This->dispex), id, pbstrName);
}

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

    return IDispatchEx_GetNextDispID(DISPATCHEX(&This->dispex), grfdex, id, pid);
}

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

    return IDispatchEx_GetNameSpaceParent(DISPATCHEX(&This->dispex), ppunk);
}

#undef DISPEX_THIS

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
};

1766 1767 1768 1769 1770 1771 1772
static const tid_t HTMLDocument_iface_tids[] = {
    IHTMLDocument2_tid,
    IHTMLDocument3_tid,
    IHTMLDocument4_tid,
    IHTMLDocument5_tid,
    0
};
1773
static dispex_static_data_t HTMLDocument_dispex = {
1774
    NULL,
1775 1776
    DispHTMLDocument_tid,
    NULL,
1777
    HTMLDocument_iface_tids
1778 1779
};

1780 1781 1782 1783 1784 1785 1786
static HRESULT alloc_doc(HTMLDocument **ret)
{
    HTMLDocument *doc;

    doc = heap_alloc_zero(sizeof(HTMLDocument));
    doc->lpHTMLDocument2Vtbl = &HTMLDocumentVtbl;
    doc->lpIDispatchExVtbl = &DocDispatchExVtbl;
1787
    doc->lpSupportErrorInfoVtbl = &SupportErrorInfoVtbl;
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
    doc->ref = 1;
    doc->readystate = READYSTATE_UNINITIALIZED;
    doc->scriptmode = SCRIPTMODE_GECKO;

    list_init(&doc->bindings);
    list_init(&doc->script_hosts);
    list_init(&doc->selection_list);
    list_init(&doc->range_list);

    HTMLDocument_HTMLDocument3_Init(doc);
    HTMLDocument_HTMLDocument5_Init(doc);
    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);

    ConnectionPointContainer_Init(&doc->cp_container, (IUnknown*)HTMLDOC(doc));
    ConnectionPoint_Init(&doc->cp_propnotif, &doc->cp_container, &IID_IPropertyNotifySink);
    ConnectionPoint_Init(&doc->cp_htmldocevents, &doc->cp_container, &DIID_HTMLDocumentEvents);
    ConnectionPoint_Init(&doc->cp_htmldocevents2, &doc->cp_container, &DIID_HTMLDocumentEvents2);

    init_dispex(&doc->dispex, (IUnknown*)HTMLDOC(doc), &HTMLDocument_dispex);

    *ret = doc;
    return S_OK;
}

HRESULT create_doc_from_nsdoc(nsIDOMHTMLDocument *nsdoc, HTMLDocument **ret)
1819
{
1820
    HTMLDocument *doc;
1821 1822
    HRESULT hres;

1823 1824 1825
    hres = alloc_doc(&doc);
    if(FAILED(hres))
        return hres;
1826

1827 1828
    nsIDOMHTMLDocument_AddRef(nsdoc);
    doc->nsdoc = nsdoc;
1829

1830
    hres = HTMLWindow_Create(doc, NULL, &doc->window);
1831
    if(FAILED(hres)) {
1832
        IHTMLDocument_Release(HTMLDOC(doc));
1833 1834 1835
        return hres;
    }

1836 1837 1838
    *ret = doc;
    return S_OK;
}
1839

1840 1841 1842
HRESULT HTMLDocument_Create(IUnknown *pUnkOuter, REFIID riid, void** ppvObject)
{
    HTMLDocument *doc;
1843
    nsIDOMWindow *nswindow = NULL;
1844 1845 1846
    HRESULT hres;

    TRACE("(%p %s %p)\n", pUnkOuter, debugstr_guid(riid), ppvObject);
1847

1848 1849 1850
    hres = alloc_doc(&doc);
    if(FAILED(hres))
        return hres;
1851

1852 1853 1854 1855 1856 1857 1858
    hres = IHTMLDocument_QueryInterface(HTMLDOC(doc), riid, ppvObject);
    IHTMLDocument_Release(HTMLDOC(doc));
    if(FAILED(hres))
        return hres;

    doc->nscontainer = NSContainer_Create(doc, NULL);
    update_nsdocument(doc);
1859

1860 1861
    if(doc->nscontainer) {
        nsresult nsres;
1862

1863 1864 1865 1866 1867 1868
        nsres = nsIWebBrowser_GetContentDOMWindow(doc->nscontainer->webbrowser, &nswindow);
        if(NS_FAILED(nsres))
            ERR("GetContentDOMWindow failed: %08x\n", nsres);
    }

    hres = HTMLWindow_Create(doc, nswindow, &doc->window);
1869 1870
    if(nswindow)
        nsIDOMWindow_Release(nswindow);
1871 1872 1873 1874
    if(FAILED(hres)) {
        IHTMLDocument_Release(HTMLDOC(doc));
        return hres;
    }
1875

1876 1877
    get_thread_hwnd();

1878
    return S_OK;
1879
}