mshtml: Added IHTMLElement2::get_readyState implementation.
[wine] / dlls / mshtml / mshtml_private.h
1 /*
2  * Copyright 2005-2009 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #include "wingdi.h"
20 #include "docobj.h"
21 #include "comcat.h"
22 #include "mshtml.h"
23 #include "mshtmhst.h"
24 #include "hlink.h"
25 #include "perhist.h"
26 #include "dispex.h"
27
28 #include "wine/list.h"
29 #include "wine/unicode.h"
30
31 #ifdef INIT_GUID
32 #include "initguid.h"
33 #endif
34
35 #include "nsiface.h"
36
37 #define NS_OK                     ((nsresult)0x00000000L)
38 #define NS_ERROR_FAILURE          ((nsresult)0x80004005L)
39 #define NS_NOINTERFACE            ((nsresult)0x80004002L)
40 #define NS_ERROR_NOT_IMPLEMENTED  ((nsresult)0x80004001L)
41 #define NS_ERROR_INVALID_ARG      ((nsresult)0x80070057L) 
42 #define NS_ERROR_UNEXPECTED       ((nsresult)0x8000ffffL)
43 #define NS_ERROR_UNKNOWN_PROTOCOL ((nsresult)0x804b0012L)
44
45 #define NS_FAILED(res) ((res) & 0x80000000)
46 #define NS_SUCCEEDED(res) (!NS_FAILED(res))
47
48 #define NSAPI WINAPI
49
50 #define MSHTML_E_NODOC    0x800a025c
51
52 typedef struct HTMLDOMNode HTMLDOMNode;
53 typedef struct ConnectionPoint ConnectionPoint;
54 typedef struct BSCallback BSCallback;
55 typedef struct nsChannelBSC nsChannelBSC;
56 typedef struct event_target_t event_target_t;
57
58 /* NOTE: make sure to keep in sync with dispex.c */
59 typedef enum {
60     NULL_tid,
61     DispCEventObj_tid,
62     DispDOMChildrenCollection_tid,
63     DispHTMLAnchorElement_tid,
64     DispHTMLBody_tid,
65     DispHTMLCommentElement_tid,
66     DispHTMLCurrentStyle_tid,
67     DispHTMLDocument_tid,
68     DispHTMLDOMTextNode_tid,
69     DispHTMLElementCollection_tid,
70     DispHTMLGenericElement_tid,
71     DispHTMLIFrame_tid,
72     DispHTMLImg_tid,
73     DispHTMLInputElement_tid,
74     DispHTMLLocation_tid,
75     DispHTMLNavigator_tid,
76     DispHTMLOptionElement_tid,
77     DispHTMLScreen_tid,
78     DispHTMLSelectElement_tid,
79     DispHTMLStyle_tid,
80     DispHTMLTable_tid,
81     DispHTMLTableRow_tid,
82     DispHTMLUnknownElement_tid,
83     DispHTMLWindow2_tid,
84     HTMLDocumentEvents_tid,
85     IHTMLAnchorElement_tid,
86     IHTMLBodyElement_tid,
87     IHTMLBodyElement2_tid,
88     IHTMLCommentElement_tid,
89     IHTMLCurrentStyle_tid,
90     IHTMLCurrentStyle2_tid,
91     IHTMLCurrentStyle3_tid,
92     IHTMLCurrentStyle4_tid,
93     IHTMLDocument2_tid,
94     IHTMLDocument3_tid,
95     IHTMLDocument4_tid,
96     IHTMLDocument5_tid,
97     IHTMLDOMChildrenCollection_tid,
98     IHTMLDOMNode_tid,
99     IHTMLDOMNode2_tid,
100     IHTMLDOMTextNode_tid,
101     IHTMLElement_tid,
102     IHTMLElement2_tid,
103     IHTMLElement3_tid,
104     IHTMLElement4_tid,
105     IHTMLElementCollection_tid,
106     IHTMLEventObj_tid,
107     IHTMLFrameBase_tid,
108     IHTMLFrameBase2_tid,
109     IHTMLGenericElement_tid,
110     IHTMLImageElementFactory_tid,
111     IHTMLImgElement_tid,
112     IHTMLInputElement_tid,
113     IHTMLLocation_tid,
114     IHTMLOptionElement_tid,
115     IHTMLScreen_tid,
116     IHTMLSelectElement_tid,
117     IHTMLStyle_tid,
118     IHTMLStyle2_tid,
119     IHTMLStyle3_tid,
120     IHTMLStyle4_tid,
121     IHTMLTable_tid,
122     IHTMLTableRow_tid,
123     IHTMLTextContainer_tid,
124     IHTMLUniqueName_tid,
125     IHTMLWindow2_tid,
126     IHTMLWindow3_tid,
127     IHTMLWindow4_tid,
128     IOmNavigator_tid,
129     LAST_tid
130 } tid_t;
131
132 typedef struct dispex_data_t dispex_data_t;
133 typedef struct dispex_dynamic_data_t dispex_dynamic_data_t;
134
135 #define MSHTML_DISPID_CUSTOM_MIN 0x60000000
136 #define MSHTML_DISPID_CUSTOM_MAX 0x6fffffff
137
138 typedef struct {
139     HRESULT (*value)(IUnknown*,LCID,WORD,DISPPARAMS*,VARIANT*,EXCEPINFO*,IServiceProvider*);
140     HRESULT (*get_dispid)(IUnknown*,BSTR,DWORD,DISPID*);
141     HRESULT (*invoke)(IUnknown*,DISPID,LCID,WORD,DISPPARAMS*,VARIANT*,EXCEPINFO*,IServiceProvider*);
142 } dispex_static_data_vtbl_t;
143
144 typedef struct {
145     const dispex_static_data_vtbl_t *vtbl;
146     const tid_t disp_tid;
147     dispex_data_t *data;
148     const tid_t* const iface_tids;
149 } dispex_static_data_t;
150
151 typedef struct {
152     const IDispatchExVtbl  *lpIDispatchExVtbl;
153
154     IUnknown *outer;
155
156     dispex_static_data_t *data;
157     dispex_dynamic_data_t *dynamic_data;
158 } DispatchEx;
159
160 void init_dispex(DispatchEx*,IUnknown*,dispex_static_data_t*);
161 void release_dispex(DispatchEx*);
162 BOOL dispex_query_interface(DispatchEx*,REFIID,void**);
163 HRESULT dispex_get_dprop_ref(DispatchEx*,const WCHAR*,BOOL,VARIANT**);
164 HRESULT get_dispids(tid_t,DWORD*,DISPID**);
165
166 typedef struct HTMLDocumentNode HTMLDocumentNode;
167 typedef struct HTMLDocumentObj HTMLDocumentObj;
168 typedef struct HTMLFrameBase HTMLFrameBase;
169
170 typedef enum {
171     SCRIPTMODE_GECKO,
172     SCRIPTMODE_ACTIVESCRIPT
173 } SCRIPTMODE;
174
175 typedef struct ScriptHost ScriptHost;
176
177 typedef enum {
178     GLOBAL_SCRIPTVAR,
179     GLOBAL_ELEMENTVAR
180 } global_prop_type_t;
181
182 typedef struct {
183     global_prop_type_t type;
184     WCHAR *name;
185     ScriptHost *script_host;
186     DISPID id;
187 } global_prop_t;
188
189 typedef struct {
190     const IHTMLOptionElementFactoryVtbl *lpHTMLOptionElementFactoryVtbl;
191
192     LONG ref;
193
194     HTMLWindow *window;
195 } HTMLOptionElementFactory;
196
197 typedef struct {
198     DispatchEx dispex;
199     const IHTMLImageElementFactoryVtbl *lpHTMLImageElementFactoryVtbl;
200
201     LONG ref;
202
203     HTMLWindow *window;
204 } HTMLImageElementFactory;
205
206 struct HTMLLocation {
207     DispatchEx dispex;
208     const IHTMLLocationVtbl *lpHTMLLocationVtbl;
209
210     LONG ref;
211
212     HTMLWindow *window;
213 };
214
215 typedef struct {
216     HTMLWindow *window;
217     LONG ref;
218 }  windowref_t;
219
220 struct HTMLWindow {
221     DispatchEx dispex;
222     const IHTMLWindow2Vtbl *lpHTMLWindow2Vtbl;
223     const IHTMLWindow3Vtbl *lpHTMLWindow3Vtbl;
224     const IHTMLWindow4Vtbl *lpHTMLWindow4Vtbl;
225     const IDispatchExVtbl  *lpIDispatchExVtbl;
226
227     LONG ref;
228
229     windowref_t *window_ref;
230     LONG task_magic;
231
232     HTMLDocumentNode *doc;
233     HTMLDocumentObj *doc_obj;
234     nsIDOMWindow *nswindow;
235     HTMLWindow *parent;
236     HTMLFrameBase *frame_element;
237     READYSTATE readystate;
238
239     nsChannelBSC *bscallback;
240     IMoniker *mon;
241     LPOLESTR url;
242
243     event_target_t *event_target;
244     IHTMLEventObj *event;
245
246     SCRIPTMODE scriptmode;
247     struct list script_hosts;
248
249     HTMLOptionElementFactory *option_factory;
250     HTMLImageElementFactory *image_factory;
251     HTMLLocation *location;
252     IHTMLScreen *screen;
253
254     global_prop_t *global_props;
255     DWORD global_prop_cnt;
256     DWORD global_prop_size;
257
258     struct list children;
259     struct list sibling_entry;
260     struct list entry;
261 };
262
263 typedef enum {
264     UNKNOWN_USERMODE,
265     BROWSEMODE,
266     EDITMODE        
267 } USERMODE;
268
269 typedef struct {
270     tid_t tid;
271     DWORD id_cnt;
272     DISPID *ids;
273 } cp_static_data_t;
274
275 typedef struct ConnectionPointContainer {
276     const IConnectionPointContainerVtbl  *lpConnectionPointContainerVtbl;
277
278     ConnectionPoint *cp_list;
279     IUnknown *outer;
280     struct ConnectionPointContainer *forward_container;
281 } ConnectionPointContainer;
282
283 struct ConnectionPoint {
284     const IConnectionPointVtbl *lpConnectionPointVtbl;
285
286     IConnectionPointContainer *container;
287
288     union {
289         IUnknown *unk;
290         IDispatch *disp;
291         IPropertyNotifySink *propnotif;
292     } *sinks;
293     DWORD sinks_size;
294
295     const IID *iid;
296     cp_static_data_t *data;
297
298     ConnectionPoint *next;
299 };
300
301 struct HTMLDocument {
302     const IHTMLDocument2Vtbl              *lpHTMLDocument2Vtbl;
303     const IHTMLDocument3Vtbl              *lpHTMLDocument3Vtbl;
304     const IHTMLDocument4Vtbl              *lpHTMLDocument4Vtbl;
305     const IHTMLDocument5Vtbl              *lpHTMLDocument5Vtbl;
306     const IHTMLDocument6Vtbl              *lpHTMLDocument6Vtbl;
307     const IPersistMonikerVtbl             *lpPersistMonikerVtbl;
308     const IPersistFileVtbl                *lpPersistFileVtbl;
309     const IPersistHistoryVtbl             *lpPersistHistoryVtbl;
310     const IMonikerPropVtbl                *lpMonikerPropVtbl;
311     const IOleObjectVtbl                  *lpOleObjectVtbl;
312     const IOleDocumentVtbl                *lpOleDocumentVtbl;
313     const IOleDocumentViewVtbl            *lpOleDocumentViewVtbl;
314     const IOleInPlaceActiveObjectVtbl     *lpOleInPlaceActiveObjectVtbl;
315     const IViewObject2Vtbl                *lpViewObject2Vtbl;
316     const IOleInPlaceObjectWindowlessVtbl *lpOleInPlaceObjectWindowlessVtbl;
317     const IServiceProviderVtbl            *lpServiceProviderVtbl;
318     const IOleCommandTargetVtbl           *lpOleCommandTargetVtbl;
319     const IOleControlVtbl                 *lpOleControlVtbl;
320     const IHlinkTargetVtbl                *lpHlinkTargetVtbl;
321     const IPersistStreamInitVtbl          *lpPersistStreamInitVtbl;
322     const IDispatchExVtbl                 *lpIDispatchExVtbl;
323     const ISupportErrorInfoVtbl           *lpSupportErrorInfoVtbl;
324
325     IUnknown *unk_impl;
326     IDispatchEx *dispex;
327
328     HTMLDocumentObj *doc_obj;
329     HTMLDocumentNode *doc_node;
330
331     HTMLWindow *window;
332
333     LONG task_magic;
334
335     ConnectionPointContainer cp_container;
336     ConnectionPoint cp_htmldocevents;
337     ConnectionPoint cp_htmldocevents2;
338     ConnectionPoint cp_propnotif;
339 };
340
341 static inline HRESULT htmldoc_query_interface(HTMLDocument *This, REFIID riid, void **ppv)
342 {
343     return IUnknown_QueryInterface(This->unk_impl, riid, ppv);
344 }
345
346 static inline ULONG htmldoc_addref(HTMLDocument *This)
347 {
348     return IUnknown_AddRef(This->unk_impl);
349 }
350
351 static inline ULONG htmldoc_release(HTMLDocument *This)
352 {
353     return IUnknown_Release(This->unk_impl);
354 }
355
356 struct HTMLDocumentObj {
357     HTMLDocument basedoc;
358     DispatchEx dispex;
359     const ICustomDocVtbl  *lpCustomDocVtbl;
360
361     LONG ref;
362
363     NSContainer *nscontainer;
364
365     IOleClientSite *client;
366     IDocHostUIHandler *hostui;
367     IOleInPlaceSite *ipsite;
368     IOleInPlaceFrame *frame;
369     IOleInPlaceUIWindow *ip_window;
370
371     DOCHOSTUIINFO hostinfo;
372
373     IOleUndoManager *undomgr;
374
375     HWND hwnd;
376     HWND tooltips_hwnd;
377
378     BOOL in_place_active;
379     BOOL ui_active;
380     BOOL window_active;
381     BOOL has_key_path;
382     BOOL container_locked;
383     BOOL focus;
384
385     USERMODE usermode;
386     LPWSTR mime;
387
388     DWORD update;
389 };
390
391 struct NSContainer {
392     const nsIWebBrowserChromeVtbl       *lpWebBrowserChromeVtbl;
393     const nsIContextMenuListenerVtbl    *lpContextMenuListenerVtbl;
394     const nsIURIContentListenerVtbl     *lpURIContentListenerVtbl;
395     const nsIEmbeddingSiteWindowVtbl    *lpEmbeddingSiteWindowVtbl;
396     const nsITooltipListenerVtbl        *lpTooltipListenerVtbl;
397     const nsIInterfaceRequestorVtbl     *lpInterfaceRequestorVtbl;
398     const nsIWeakReferenceVtbl          *lpWeakReferenceVtbl;
399     const nsISupportsWeakReferenceVtbl  *lpSupportsWeakReferenceVtbl;
400
401     nsIWebBrowser *webbrowser;
402     nsIWebNavigation *navigation;
403     nsIBaseWindow *window;
404     nsIWebBrowserFocus *focus;
405
406     nsIEditor *editor;
407     nsIController *editor_controller;
408
409     LONG ref;
410
411     NSContainer *parent;
412     HTMLDocumentObj *doc;
413
414     nsIURIContentListener *content_listener;
415
416     HWND hwnd;
417
418     nsChannelBSC *bscallback; /* hack */
419     HWND reset_focus; /* hack */
420 };
421
422 typedef struct {
423     const nsIHttpChannelVtbl *lpHttpChannelVtbl;
424     const nsIUploadChannelVtbl *lpUploadChannelVtbl;
425     const nsIHttpChannelInternalVtbl *lpIHttpChannelInternalVtbl;
426
427     LONG ref;
428
429     nsIChannel *channel;
430     nsIHttpChannel *http_channel;
431     nsIHttpChannelInternal *http_channel_internal;
432     nsIWineURI *uri;
433     nsIInputStream *post_data_stream;
434     nsILoadGroup *load_group;
435     nsIInterfaceRequestor *notif_callback;
436     nsISupports *owner;
437     nsLoadFlags load_flags;
438     nsIURI *original_uri;
439     char *content_type;
440     char *charset;
441     PRUint32 response_status;
442 } nsChannel;
443
444 typedef struct {
445     HRESULT (*qi)(HTMLDOMNode*,REFIID,void**);
446     void (*destructor)(HTMLDOMNode*);
447     event_target_t **(*get_event_target)(HTMLDOMNode*);
448     HRESULT (*call_event)(HTMLDOMNode*,DWORD,BOOL*);
449     HRESULT (*put_disabled)(HTMLDOMNode*,VARIANT_BOOL);
450     HRESULT (*get_disabled)(HTMLDOMNode*,VARIANT_BOOL*);
451     HRESULT (*get_document)(HTMLDOMNode*,IDispatch**);
452     HRESULT (*get_readystate)(HTMLDOMNode*,BSTR*);
453 } NodeImplVtbl;
454
455 struct HTMLDOMNode {
456     DispatchEx dispex;
457     const IHTMLDOMNodeVtbl   *lpHTMLDOMNodeVtbl;
458     const IHTMLDOMNode2Vtbl  *lpHTMLDOMNode2Vtbl;
459     const NodeImplVtbl *vtbl;
460
461     LONG ref;
462
463     nsIDOMNode *nsnode;
464     HTMLDocumentNode *doc;
465     event_target_t *event_target;
466     ConnectionPointContainer *cp_container;
467
468     HTMLDOMNode *next;
469 };
470
471 typedef struct {
472     HTMLDOMNode node;
473     ConnectionPointContainer cp_container;
474
475     const IHTMLElementVtbl   *lpHTMLElementVtbl;
476     const IHTMLElement2Vtbl  *lpHTMLElement2Vtbl;
477     const IHTMLElement3Vtbl  *lpHTMLElement3Vtbl;
478
479     nsIDOMHTMLElement *nselem;
480 } HTMLElement;
481
482 typedef struct {
483     HTMLElement element;
484
485     const IHTMLTextContainerVtbl *lpHTMLTextContainerVtbl;
486
487     ConnectionPoint cp;
488 } HTMLTextContainer;
489
490 struct HTMLFrameBase {
491     HTMLElement element;
492
493     const IHTMLFrameBaseVtbl   *lpIHTMLFrameBaseVtbl;
494     const IHTMLFrameBase2Vtbl  *lpIHTMLFrameBase2Vtbl;
495
496     HTMLWindow *content_window;
497 };
498
499 typedef struct _mutation_queue_t {
500     DWORD type;
501     nsISupports *nsiface;
502
503     struct _mutation_queue_t *next;
504 } mutation_queue_t;
505
506 typedef struct nsDocumentEventListener nsDocumentEventListener;
507
508 struct HTMLDocumentNode {
509     HTMLDOMNode node;
510     HTMLDocument basedoc;
511
512     const IInternetHostSecurityManagerVtbl *lpIInternetHostSecurityManagerVtbl;
513
514     const nsIDocumentObserverVtbl  *lpIDocumentObserverVtbl;
515     const nsIRunnableVtbl  *lpIRunnableVtbl;
516
517     LONG ref;
518
519     nsIDOMHTMLDocument *nsdoc;
520     HTMLDOMNode *nodes;
521     BOOL content_ready;
522
523     IInternetSecurityManager *secmgr;
524     ICatInformation *catmgr;
525     nsDocumentEventListener *nsevent_listener;
526     BOOL *event_vector;
527
528     mutation_queue_t *mutation_queue;
529     mutation_queue_t *mutation_queue_tail;
530
531     struct list bindings;
532     struct list selection_list;
533     struct list range_list;
534 };
535
536 #define HTMLWINDOW2(x)   ((IHTMLWindow2*)                 &(x)->lpHTMLWindow2Vtbl)
537 #define HTMLWINDOW3(x)   ((IHTMLWindow3*)                 &(x)->lpHTMLWindow3Vtbl)
538 #define HTMLWINDOW4(x)   ((IHTMLWindow4*)                 &(x)->lpHTMLWindow4Vtbl)
539
540 #define HTMLDOC(x)       ((IHTMLDocument2*)               &(x)->lpHTMLDocument2Vtbl)
541 #define HTMLDOC3(x)      ((IHTMLDocument3*)               &(x)->lpHTMLDocument3Vtbl)
542 #define HTMLDOC4(x)      ((IHTMLDocument4*)               &(x)->lpHTMLDocument4Vtbl)
543 #define HTMLDOC5(x)      ((IHTMLDocument5*)               &(x)->lpHTMLDocument5Vtbl)
544 #define HTMLDOC6(x)      ((IHTMLDocument6*)               &(x)->lpHTMLDocument6Vtbl)
545 #define PERSIST(x)       ((IPersist*)                     &(x)->lpPersistFileVtbl)
546 #define PERSISTMON(x)    ((IPersistMoniker*)              &(x)->lpPersistMonikerVtbl)
547 #define PERSISTFILE(x)   ((IPersistFile*)                 &(x)->lpPersistFileVtbl)
548 #define MONPROP(x)       ((IMonikerProp*)                 &(x)->lpMonikerPropVtbl)
549 #define OLEOBJ(x)        ((IOleObject*)                   &(x)->lpOleObjectVtbl)
550 #define OLEDOC(x)        ((IOleDocument*)                 &(x)->lpOleDocumentVtbl)
551 #define DOCVIEW(x)       ((IOleDocumentView*)             &(x)->lpOleDocumentViewVtbl)
552 #define OLEWIN(x)        ((IOleWindow*)                   &(x)->lpOleInPlaceActiveObjectVtbl)
553 #define ACTOBJ(x)        ((IOleInPlaceActiveObject*)      &(x)->lpOleInPlaceActiveObjectVtbl)
554 #define VIEWOBJ(x)       ((IViewObject*)                  &(x)->lpViewObject2Vtbl)
555 #define VIEWOBJ2(x)      ((IViewObject2*)                 &(x)->lpViewObject2Vtbl)
556 #define INPLACEOBJ(x)    ((IOleInPlaceObject*)            &(x)->lpOleInPlaceObjectWindowlessVtbl)
557 #define INPLACEWIN(x)    ((IOleInPlaceObjectWindowless*)  &(x)->lpOleInPlaceObjectWindowlessVtbl)
558 #define SERVPROV(x)      ((IServiceProvider*)             &(x)->lpServiceProviderVtbl)
559 #define CMDTARGET(x)     ((IOleCommandTarget*)            &(x)->lpOleCommandTargetVtbl)
560 #define CONTROL(x)       ((IOleControl*)                  &(x)->lpOleControlVtbl)
561 #define HLNKTARGET(x)    ((IHlinkTarget*)                 &(x)->lpHlinkTargetVtbl)
562 #define CONPTCONT(x)     ((IConnectionPointContainer*)    &(x)->lpConnectionPointContainerVtbl)
563 #define PERSTRINIT(x)    ((IPersistStreamInit*)           &(x)->lpPersistStreamInitVtbl)
564 #define PERSISTHIST(x)   ((IPersistHistory*)              &(x)->lpPersistHistoryVtbl)
565 #define CUSTOMDOC(x)     ((ICustomDoc*)                   &(x)->lpCustomDocVtbl)
566
567 #define NSWBCHROME(x)    ((nsIWebBrowserChrome*)          &(x)->lpWebBrowserChromeVtbl)
568 #define NSCML(x)         ((nsIContextMenuListener*)       &(x)->lpContextMenuListenerVtbl)
569 #define NSURICL(x)       ((nsIURIContentListener*)        &(x)->lpURIContentListenerVtbl)
570 #define NSEMBWNDS(x)     ((nsIEmbeddingSiteWindow*)       &(x)->lpEmbeddingSiteWindowVtbl)
571 #define NSIFACEREQ(x)    ((nsIInterfaceRequestor*)        &(x)->lpInterfaceRequestorVtbl)
572 #define NSTOOLTIP(x)     ((nsITooltipListener*)           &(x)->lpTooltipListenerVtbl)
573 #define NSEVENTLIST(x)   ((nsIDOMEventListener*)          &(x)->lpDOMEventListenerVtbl)
574 #define NSWEAKREF(x)     ((nsIWeakReference*)             &(x)->lpWeakReferenceVtbl)
575 #define NSSUPWEAKREF(x)  ((nsISupportsWeakReference*)     &(x)->lpSupportsWeakReferenceVtbl)
576
577 #define NSDOCOBS(x)      ((nsIDocumentObserver*)          &(x)->lpIDocumentObserverVtbl)
578
579 #define NSRUNNABLE(x)    ((nsIRunnable*)  &(x)->lpIRunnableVtbl)
580
581 #define NSCHANNEL(x)     ((nsIChannel*)        &(x)->lpHttpChannelVtbl)
582 #define NSHTTPCHANNEL(x) ((nsIHttpChannel*)    &(x)->lpHttpChannelVtbl)
583 #define NSUPCHANNEL(x)   ((nsIUploadChannel*)  &(x)->lpUploadChannelVtbl)
584 #define NSHTTPINTERNAL(x) ((nsIHttpChannelInternal*)  &(x)->lpIHttpChannelInternalVtbl)
585
586 #define HTTPNEG(x)       ((IHttpNegotiate2*)              &(x)->lpHttpNegotiate2Vtbl)
587 #define STATUSCLB(x)     ((IBindStatusCallback*)          &(x)->lpBindStatusCallbackVtbl)
588 #define BINDINFO(x)      ((IInternetBindInfo*)            &(x)->lpInternetBindInfoVtbl);
589
590 #define HTMLELEM(x)      ((IHTMLElement*)                 &(x)->lpHTMLElementVtbl)
591 #define HTMLELEM2(x)     ((IHTMLElement2*)                &(x)->lpHTMLElement2Vtbl)
592 #define HTMLELEM3(x)     ((IHTMLElement3*)                &(x)->lpHTMLElement3Vtbl)
593 #define HTMLDOMNODE(x)   ((IHTMLDOMNode*)                 &(x)->lpHTMLDOMNodeVtbl)
594 #define HTMLDOMNODE2(x)  ((IHTMLDOMNode2*)                &(x)->lpHTMLDOMNode2Vtbl)
595
596 #define HTMLTEXTCONT(x)  ((IHTMLTextContainer*)           &(x)->lpHTMLTextContainerVtbl)
597 #define HTMLFRAMEBASE(x) ((IHTMLFrameBase*)               &(x)->lpIHTMLFrameBaseVtbl)
598 #define HTMLFRAMEBASE2(x) ((IHTMLFrameBase2*)             &(x)->lpIHTMLFrameBase2Vtbl)
599
600 #define HTMLOPTFACTORY(x)  ((IHTMLOptionElementFactory*)  &(x)->lpHTMLOptionElementFactoryVtbl)
601 #define HTMLIMGFACTORY(x)  ((IHTMLImageElementFactory*)   &(x)->lpHTMLImageElementFactoryVtbl)
602 #define HTMLLOCATION(x)    ((IHTMLLocation*)              &(x)->lpHTMLLocationVtbl)
603
604 #define DISPATCHEX(x)    ((IDispatchEx*) &(x)->lpIDispatchExVtbl)
605
606 #define SUPPERRINFO(x)   ((ISupportErrorInfo*) &(x)->lpSupportErrorInfoVtbl)
607
608 #define HOSTSECMGR(x)    ((IInternetHostSecurityManager*)  &(x)->lpIInternetHostSecurityManagerVtbl)
609
610 #define DEFINE_THIS2(cls,ifc,iface) ((cls*)((BYTE*)(iface)-offsetof(cls,ifc)))
611 #define DEFINE_THIS(cls,ifc,iface) DEFINE_THIS2(cls,lp ## ifc ## Vtbl,iface)
612
613 HRESULT HTMLDocument_Create(IUnknown*,REFIID,void**);
614 HRESULT HTMLLoadOptions_Create(IUnknown*,REFIID,void**);
615 HRESULT create_doc_from_nsdoc(nsIDOMHTMLDocument*,HTMLDocumentObj*,HTMLWindow*,HTMLDocumentNode**);
616
617 HRESULT HTMLWindow_Create(HTMLDocumentObj*,nsIDOMWindow*,HTMLWindow*,HTMLWindow**);
618 void update_window_doc(HTMLWindow*);
619 HTMLWindow *nswindow_to_window(const nsIDOMWindow*);
620 nsIDOMWindow *get_nsdoc_window(nsIDOMDocument*);
621 HTMLOptionElementFactory *HTMLOptionElementFactory_Create(HTMLWindow*);
622 HTMLImageElementFactory *HTMLImageElementFactory_Create(HTMLWindow*);
623 HRESULT HTMLLocation_Create(HTMLWindow*,HTMLLocation**);
624 IOmNavigator *OmNavigator_Create(void);
625 HRESULT HTMLScreen_Create(IHTMLScreen**);
626
627 void HTMLDocument_HTMLDocument3_Init(HTMLDocument*);
628 void HTMLDocument_HTMLDocument5_Init(HTMLDocument*);
629 void HTMLDocument_Persist_Init(HTMLDocument*);
630 void HTMLDocument_OleCmd_Init(HTMLDocument*);
631 void HTMLDocument_OleObj_Init(HTMLDocument*);
632 void HTMLDocument_View_Init(HTMLDocument*);
633 void HTMLDocument_Window_Init(HTMLDocument*);
634 void HTMLDocument_Service_Init(HTMLDocument*);
635 void HTMLDocument_Hlink_Init(HTMLDocument*);
636
637 void HTMLDocumentNode_SecMgr_Init(HTMLDocumentNode*);
638
639 HRESULT HTMLCurrentStyle_Create(HTMLElement*,IHTMLCurrentStyle**);
640
641 void ConnectionPoint_Init(ConnectionPoint*,ConnectionPointContainer*,REFIID,cp_static_data_t*);
642 void ConnectionPointContainer_Init(ConnectionPointContainer*,IUnknown*);
643 void ConnectionPointContainer_Destroy(ConnectionPointContainer*);
644
645 NSContainer *NSContainer_Create(HTMLDocumentObj*,NSContainer*);
646 void NSContainer_Release(NSContainer*);
647
648 void init_mutation(HTMLDocumentNode*);
649 void release_mutation(HTMLDocumentNode*);
650
651 void HTMLDocument_LockContainer(HTMLDocumentObj*,BOOL);
652 void show_context_menu(HTMLDocumentObj*,DWORD,POINT*,IDispatch*);
653 void notif_focus(HTMLDocumentObj*);
654
655 void show_tooltip(HTMLDocumentObj*,DWORD,DWORD,LPCWSTR);
656 void hide_tooltip(HTMLDocumentObj*);
657 HRESULT get_client_disp_property(IOleClientSite*,DISPID,VARIANT*);
658
659 HRESULT ProtocolFactory_Create(REFCLSID,REFIID,void**);
660
661 BOOL load_gecko(BOOL);
662 void close_gecko(void);
663 void register_nsservice(nsIComponentRegistrar*,nsIServiceManager*);
664 void init_nsio(nsIComponentManager*,nsIComponentRegistrar*);
665 void release_nsio(void);
666 BOOL install_wine_gecko(BOOL);
667
668 HRESULT nsuri_to_url(LPCWSTR,BOOL,BSTR*);
669
670 HRESULT hlink_frame_navigate(HTMLDocument*,LPCWSTR,nsIInputStream*,DWORD);
671 HRESULT navigate_url(HTMLDocumentNode*,OLECHAR*);
672
673 void call_property_onchanged(ConnectionPoint*,DISPID);
674 HRESULT call_set_active_object(IOleInPlaceUIWindow*,IOleInPlaceActiveObject*);
675
676 void *nsalloc(size_t) __WINE_ALLOC_SIZE(1);
677 void nsfree(void*);
678
679 void nsACString_Init(nsACString*,const char*);
680 void nsACString_SetData(nsACString*,const char*);
681 PRUint32 nsACString_GetData(const nsACString*,const char**);
682 void nsACString_Finish(nsACString*);
683
684 void nsAString_Init(nsAString*,const PRUnichar*);
685 void nsAString_SetData(nsAString*,const PRUnichar*);
686 PRUint32 nsAString_GetData(const nsAString*,const PRUnichar**);
687 void nsAString_Finish(nsAString*);
688
689 nsICommandParams *create_nscommand_params(void);
690 HRESULT nsnode_to_nsstring(nsIDOMNode*,nsAString*);
691 void get_editor_controller(NSContainer*);
692 nsresult get_nsinterface(nsISupports*,REFIID,void**);
693
694 void init_nsevents(HTMLDocumentNode*);
695 void release_nsevents(HTMLDocumentNode*);
696 void add_nsevent_listener(HTMLDocumentNode*,LPCWSTR);
697
698 void set_window_bscallback(HTMLWindow*,nsChannelBSC*);
699 void set_current_mon(HTMLWindow*,IMoniker*);
700 HRESULT start_binding(HTMLWindow*,HTMLDocumentNode*,BSCallback*,IBindCtx*);
701 void abort_document_bindings(HTMLDocumentNode*);
702
703 HRESULT bind_mon_to_buffer(HTMLDocumentNode*,IMoniker*,void**,DWORD*);
704
705 nsChannelBSC *create_channelbsc(IMoniker*);
706 HRESULT channelbsc_load_stream(nsChannelBSC*,IStream*);
707 void channelbsc_set_channel(nsChannelBSC*,nsChannel*,nsIStreamListener*,nsISupports*);
708 IMoniker *get_channelbsc_mon(nsChannelBSC*);
709
710 void set_ready_state(HTMLWindow*,READYSTATE);
711
712 HRESULT HTMLSelectionObject_Create(HTMLDocumentNode*,nsISelection*,IHTMLSelectionObject**);
713 HRESULT HTMLTxtRange_Create(HTMLDocumentNode*,nsIDOMRange*,IHTMLTxtRange**);
714 IHTMLStyle *HTMLStyle_Create(nsIDOMCSSStyleDeclaration*);
715 IHTMLStyleSheet *HTMLStyleSheet_Create(nsIDOMStyleSheet*);
716 IHTMLStyleSheetsCollection *HTMLStyleSheetsCollection_Create(nsIDOMStyleSheetList*);
717
718 void detach_selection(HTMLDocumentNode*);
719 void detach_ranges(HTMLDocumentNode*);
720 HRESULT get_node_text(HTMLDOMNode*,BSTR*);
721
722 HRESULT create_nselem(HTMLDocumentNode*,const WCHAR*,nsIDOMHTMLElement**);
723
724 HTMLDOMNode *HTMLDOMTextNode_Create(HTMLDocumentNode*,nsIDOMNode*);
725
726 HTMLElement *HTMLElement_Create(HTMLDocumentNode*,nsIDOMNode*,BOOL);
727 HTMLElement *HTMLCommentElement_Create(HTMLDocumentNode*,nsIDOMNode*);
728 HTMLElement *HTMLAnchorElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
729 HTMLElement *HTMLBodyElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
730 HTMLElement *HTMLFrameElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLWindow*);
731 HTMLElement *HTMLIFrame_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLWindow*);
732 HTMLElement *HTMLImgElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
733 HTMLElement *HTMLInputElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
734 HTMLElement *HTMLOptionElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
735 HTMLElement *HTMLScriptElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
736 HTMLElement *HTMLSelectElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
737 HTMLElement *HTMLTable_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
738 HTMLElement *HTMLTableRow_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
739 HTMLElement *HTMLTextAreaElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
740 HTMLElement *HTMLGenericElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*);
741
742 void HTMLDOMNode_Init(HTMLDocumentNode*,HTMLDOMNode*,nsIDOMNode*);
743 void HTMLElement_Init(HTMLElement*,HTMLDocumentNode*,nsIDOMHTMLElement*,dispex_static_data_t*);
744 void HTMLElement2_Init(HTMLElement*);
745 void HTMLElement3_Init(HTMLElement*);
746 void HTMLTextContainer_Init(HTMLTextContainer*,HTMLDocumentNode*,nsIDOMHTMLElement*,dispex_static_data_t*);
747 void HTMLFrameBase_Init(HTMLFrameBase*,HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLWindow*,dispex_static_data_t*);
748
749 HRESULT HTMLDOMNode_QI(HTMLDOMNode*,REFIID,void**);
750 void HTMLDOMNode_destructor(HTMLDOMNode*);
751
752 HRESULT HTMLElement_QI(HTMLDOMNode*,REFIID,void**);
753 void HTMLElement_destructor(HTMLDOMNode*);
754
755 HRESULT HTMLFrameBase_QI(HTMLFrameBase*,REFIID,void**);
756 void HTMLFrameBase_destructor(HTMLFrameBase*);
757
758 HTMLDOMNode *get_node(HTMLDocumentNode*,nsIDOMNode*,BOOL);
759 void release_nodes(HTMLDocumentNode*);
760
761 void release_script_hosts(HTMLWindow*);
762 void connect_scripts(HTMLWindow*);
763 void doc_insert_script(HTMLWindow*,nsIDOMHTMLScriptElement*);
764 IDispatch *script_parse_event(HTMLWindow*,LPCWSTR);
765 void set_script_mode(HTMLWindow*,SCRIPTMODE);
766 BOOL find_global_prop(HTMLWindow*,BSTR,DWORD,ScriptHost**,DISPID*);
767 IDispatch *get_script_disp(ScriptHost*);
768
769 IHTMLElementCollection *create_all_collection(HTMLDOMNode*,BOOL);
770 IHTMLElementCollection *create_collection_from_nodelist(HTMLDocumentNode*,IUnknown*,nsIDOMNodeList*);
771 IHTMLElementCollection *create_collection_from_htmlcol(HTMLDocumentNode*,IUnknown*,nsIDOMHTMLCollection*);
772
773 /* commands */
774 typedef struct {
775     DWORD id;
776     HRESULT (*query)(HTMLDocument*,OLECMD*);
777     HRESULT (*exec)(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
778 } cmdtable_t;
779
780 extern const cmdtable_t editmode_cmds[];
781
782 void do_ns_command(HTMLDocument*,const char*,nsICommandParams*);
783
784 /* timer */
785 #define UPDATE_UI       0x0001
786 #define UPDATE_TITLE    0x0002
787
788 void update_doc(HTMLDocument*,DWORD);
789 void update_title(HTMLDocumentObj*);
790
791 /* editor */
792 void init_editor(HTMLDocument*);
793 void set_ns_editmode(NSContainer*);
794 void handle_edit_event(HTMLDocument*,nsIDOMEvent*);
795 HRESULT editor_exec_copy(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
796 HRESULT editor_exec_cut(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
797 HRESULT editor_exec_paste(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
798 void handle_edit_load(HTMLDocument*);
799 HRESULT editor_is_dirty(HTMLDocument*);
800 void set_dirty(HTMLDocument*,VARIANT_BOOL);
801
802 extern DWORD mshtml_tls;
803
804 typedef struct task_t task_t;
805 typedef void (*task_proc_t)(task_t*);
806
807 struct task_t {
808     LONG target_magic;
809     task_proc_t proc;
810     struct task_t *next;
811 };
812
813 typedef struct {
814     task_t header;
815     HTMLDocumentObj *doc;
816 } docobj_task_t;
817
818 typedef struct {
819     HWND thread_hwnd;
820     task_t *task_queue_head;
821     task_t *task_queue_tail;
822     struct list timer_list;
823 } thread_data_t;
824
825 thread_data_t *get_thread_data(BOOL);
826 HWND get_thread_hwnd(void);
827
828 LONG get_task_target_magic(void);
829 void push_task(task_t*,task_proc_t,LONG);
830 void remove_target_tasks(LONG);
831
832 DWORD set_task_timer(HTMLDocument*,DWORD,BOOL,IDispatch*);
833 HRESULT clear_task_timer(HTMLDocument*,BOOL,DWORD);
834
835 void release_typelib(void);
836 HRESULT call_disp_func(IDispatch*,DISPPARAMS*);
837
838 const char *debugstr_variant(const VARIANT*);
839
840 DEFINE_GUID(CLSID_AboutProtocol, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
841 DEFINE_GUID(CLSID_JSProtocol, 0x3050F3B2, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
842 DEFINE_GUID(CLSID_MailtoProtocol, 0x3050F3DA, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
843 DEFINE_GUID(CLSID_ResProtocol, 0x3050F3BC, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
844 DEFINE_GUID(CLSID_SysimageProtocol, 0x76E67A63, 0x06E9, 0x11D2, 0xA8,0x40, 0x00,0x60,0x08,0x05,0x93,0x82);
845
846 DEFINE_GUID(CLSID_CMarkup,0x3050f4fb,0x98b5,0x11cf,0xbb,0x82,0x00,0xaa,0x00,0xbd,0xce,0x0b);
847
848 /* memory allocation functions */
849
850 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc(size_t len)
851 {
852     return HeapAlloc(GetProcessHeap(), 0, len);
853 }
854
855 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t len)
856 {
857     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
858 }
859
860 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc(void *mem, size_t len)
861 {
862     return HeapReAlloc(GetProcessHeap(), 0, mem, len);
863 }
864
865 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc_zero(void *mem, size_t len)
866 {
867     return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len);
868 }
869
870 static inline BOOL heap_free(void *mem)
871 {
872     return HeapFree(GetProcessHeap(), 0, mem);
873 }
874
875 static inline LPWSTR heap_strdupW(LPCWSTR str)
876 {
877     LPWSTR ret = NULL;
878
879     if(str) {
880         DWORD size;
881
882         size = (strlenW(str)+1)*sizeof(WCHAR);
883         ret = heap_alloc(size);
884         memcpy(ret, str, size);
885     }
886
887     return ret;
888 }
889
890 static inline char *heap_strdupA(const char *str)
891 {
892     char *ret = NULL;
893
894     if(str) {
895         DWORD size;
896
897         size = strlen(str)+1;
898         ret = heap_alloc(size);
899         memcpy(ret, str, size);
900     }
901
902     return ret;
903 }
904
905 static inline WCHAR *heap_strdupAtoW(const char *str)
906 {
907     LPWSTR ret = NULL;
908
909     if(str) {
910         DWORD len;
911
912         len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
913         ret = heap_alloc(len*sizeof(WCHAR));
914         MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
915     }
916
917     return ret;
918 }
919
920 static inline char *heap_strdupWtoA(LPCWSTR str)
921 {
922     char *ret = NULL;
923
924     if(str) {
925         DWORD size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
926         ret = heap_alloc(size);
927         WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
928     }
929
930     return ret;
931 }
932
933 static inline void windowref_addref(windowref_t *ref)
934 {
935     InterlockedIncrement(&ref->ref);
936 }
937
938 static inline void windowref_release(windowref_t *ref)
939 {
940     if(!InterlockedDecrement(&ref->ref))
941         heap_free(ref);
942 }
943
944 HDC get_display_dc(void);
945 HINSTANCE get_shdoclc(void);
946
947 extern HINSTANCE hInst;