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