mshtml: Implement IHTMLDOMNode previousSibling.
[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 "docobjectservice.h"
22 #include "comcat.h"
23 #include "mshtml.h"
24 #include "mshtmhst.h"
25 #include "hlink.h"
26 #include "perhist.h"
27 #include "dispex.h"
28 #include "objsafe.h"
29
30 #include "wine/list.h"
31 #include "wine/unicode.h"
32
33 #ifdef INIT_GUID
34 #include "initguid.h"
35 #endif
36
37 #include "nsiface.h"
38
39 #define NS_ERROR_GENERATE_FAILURE(module,code) \
40     ((nsresult) (((PRUint32)(1<<31)) | ((PRUint32)(module+0x45)<<16) | ((PRUint32)(code))))
41
42 #define NS_OK                     ((nsresult)0x00000000L)
43 #define NS_ERROR_FAILURE          ((nsresult)0x80004005L)
44 #define NS_ERROR_OUT_OF_MEMORY    ((nsresult)0x8007000EL)
45 #define NS_NOINTERFACE            ((nsresult)0x80004002L)
46 #define NS_ERROR_NOT_IMPLEMENTED  ((nsresult)0x80004001L)
47 #define NS_ERROR_NOT_AVAILABLE    ((nsresult)0x80040111L)
48 #define NS_ERROR_INVALID_ARG      ((nsresult)0x80070057L) 
49 #define NS_ERROR_UNEXPECTED       ((nsresult)0x8000ffffL)
50
51 #define NS_ERROR_MODULE_NETWORK    6
52
53 #define NS_BINDING_ABORTED         NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 2)
54 #define NS_ERROR_UNKNOWN_PROTOCOL  NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 18)
55
56 #define NS_FAILED(res) ((res) & 0x80000000)
57 #define NS_SUCCEEDED(res) (!NS_FAILED(res))
58
59 #define NSAPI WINAPI
60
61 #define MSHTML_E_NODOC    0x800a025c
62
63 typedef struct HTMLDOMNode HTMLDOMNode;
64 typedef struct ConnectionPoint ConnectionPoint;
65 typedef struct BSCallback BSCallback;
66 typedef struct event_target_t event_target_t;
67
68 #define TID_LIST \
69     XIID(NULL) \
70     XDIID(DispCEventObj) \
71     XDIID(DispCPlugins) \
72     XDIID(DispDOMChildrenCollection) \
73     XDIID(DispHTMLAnchorElement) \
74     XDIID(DispHTMLBody) \
75     XDIID(DispHTMLCommentElement) \
76     XDIID(DispHTMLCurrentStyle) \
77     XDIID(DispHTMLDocument) \
78     XDIID(DispHTMLDOMAttribute) \
79     XDIID(DispHTMLDOMTextNode) \
80     XDIID(DispHTMLElementCollection) \
81     XDIID(DispHTMLEmbed) \
82     XDIID(DispHTMLFormElement) \
83     XDIID(DispHTMLGenericElement) \
84     XDIID(DispHTMLFrameElement) \
85     XDIID(DispHTMLIFrame) \
86     XDIID(DispHTMLImg) \
87     XDIID(DispHTMLInputElement) \
88     XDIID(DispHTMLLocation) \
89     XDIID(DispHTMLNavigator) \
90     XDIID(DispHTMLObjectElement) \
91     XDIID(DispHTMLOptionElement) \
92     XDIID(DispHTMLScreen) \
93     XDIID(DispHTMLScriptElement) \
94     XDIID(DispHTMLSelectElement) \
95     XDIID(DispHTMLStyle) \
96     XDIID(DispHTMLStyleElement) \
97     XDIID(DispHTMLStyleSheetsCollection) \
98     XDIID(DispHTMLTable) \
99     XDIID(DispHTMLTableRow) \
100     XDIID(DispHTMLTextAreaElement) \
101     XDIID(DispHTMLUnknownElement) \
102     XDIID(DispHTMLWindow2) \
103     XDIID(HTMLDocumentEvents) \
104     XIID(IHTMLAnchorElement) \
105     XIID(IHTMLBodyElement) \
106     XIID(IHTMLBodyElement2) \
107     XIID(IHTMLCommentElement) \
108     XIID(IHTMLCurrentStyle) \
109     XIID(IHTMLCurrentStyle2) \
110     XIID(IHTMLCurrentStyle3) \
111     XIID(IHTMLCurrentStyle4) \
112     XIID(IHTMLDocument2) \
113     XIID(IHTMLDocument3) \
114     XIID(IHTMLDocument4) \
115     XIID(IHTMLDocument5) \
116     XIID(IHTMLDOMAttribute) \
117     XIID(IHTMLDOMChildrenCollection) \
118     XIID(IHTMLDOMNode) \
119     XIID(IHTMLDOMNode2) \
120     XIID(IHTMLDOMTextNode) \
121     XIID(IHTMLElement) \
122     XIID(IHTMLElement2) \
123     XIID(IHTMLElement3) \
124     XIID(IHTMLElement4) \
125     XIID(IHTMLElementCollection) \
126     XIID(IHTMLEmbedElement) \
127     XIID(IHTMLEventObj) \
128     XIID(IHTMLFiltersCollection) \
129     XIID(IHTMLFormElement) \
130     XIID(IHTMLFrameBase) \
131     XIID(IHTMLFrameBase2) \
132     XIID(IHTMLFrameElement3) \
133     XIID(IHTMLGenericElement) \
134     XIID(IHTMLIFrameElement) \
135     XIID(IHTMLImageElementFactory) \
136     XIID(IHTMLImgElement) \
137     XIID(IHTMLInputElement) \
138     XIID(IHTMLLocation) \
139     XIID(IHTMLObjectElement) \
140     XIID(IHTMLOptionElement) \
141     XIID(IHTMLPluginsCollection) \
142     XIID(IHTMLRect) \
143     XIID(IHTMLScreen) \
144     XIID(IHTMLScriptElement) \
145     XIID(IHTMLSelectElement) \
146     XIID(IHTMLStyle) \
147     XIID(IHTMLStyle2) \
148     XIID(IHTMLStyle3) \
149     XIID(IHTMLStyle4) \
150     XIID(IHTMLStyleElement) \
151     XIID(IHTMLStyleSheetsCollection) \
152     XIID(IHTMLTable) \
153     XIID(IHTMLTableRow) \
154     XIID(IHTMLTextAreaElement) \
155     XIID(IHTMLTextContainer) \
156     XIID(IHTMLUniqueName) \
157     XIID(IHTMLWindow2) \
158     XIID(IHTMLWindow3) \
159     XIID(IHTMLWindow4) \
160     XIID(IOmNavigator)
161
162 typedef enum {
163 #define XIID(iface) iface ## _tid,
164 #define XDIID(iface) iface ## _tid,
165 TID_LIST
166 #undef XIID
167 #undef XDIID
168     LAST_tid
169 } tid_t;
170
171 typedef struct dispex_data_t dispex_data_t;
172 typedef struct dispex_dynamic_data_t dispex_dynamic_data_t;
173
174 #define MSHTML_DISPID_CUSTOM_MIN 0x60000000
175 #define MSHTML_DISPID_CUSTOM_MAX 0x6fffffff
176 #define MSHTML_CUSTOM_DISPID_CNT (MSHTML_DISPID_CUSTOM_MAX-MSHTML_DISPID_CUSTOM_MIN)
177
178 typedef struct DispatchEx DispatchEx;
179
180 typedef struct {
181     HRESULT (*value)(DispatchEx*,LCID,WORD,DISPPARAMS*,VARIANT*,EXCEPINFO*,IServiceProvider*);
182     HRESULT (*get_dispid)(DispatchEx*,BSTR,DWORD,DISPID*);
183     HRESULT (*invoke)(DispatchEx*,DISPID,LCID,WORD,DISPPARAMS*,VARIANT*,EXCEPINFO*,IServiceProvider*);
184 } dispex_static_data_vtbl_t;
185
186 typedef struct {
187     const dispex_static_data_vtbl_t *vtbl;
188     const tid_t disp_tid;
189     dispex_data_t *data;
190     const tid_t* const iface_tids;
191 } dispex_static_data_t;
192
193 struct DispatchEx {
194     IDispatchEx IDispatchEx_iface;
195
196     IUnknown *outer;
197
198     dispex_static_data_t *data;
199     dispex_dynamic_data_t *dynamic_data;
200 };
201
202 void init_dispex(DispatchEx*,IUnknown*,dispex_static_data_t*);
203 void release_dispex(DispatchEx*);
204 BOOL dispex_query_interface(DispatchEx*,REFIID,void**);
205 HRESULT dispex_get_dprop_ref(DispatchEx*,const WCHAR*,BOOL,VARIANT**);
206 HRESULT get_dispids(tid_t,DWORD*,DISPID**);
207 HRESULT remove_prop(DispatchEx*,BSTR,VARIANT_BOOL*);
208 void release_typelib(void);
209
210 typedef struct HTMLWindow HTMLWindow;
211 typedef struct HTMLDocumentNode HTMLDocumentNode;
212 typedef struct HTMLDocumentObj HTMLDocumentObj;
213 typedef struct HTMLFrameBase HTMLFrameBase;
214 typedef struct NSContainer NSContainer;
215
216 typedef enum {
217     SCRIPTMODE_GECKO,
218     SCRIPTMODE_ACTIVESCRIPT
219 } SCRIPTMODE;
220
221 typedef struct ScriptHost ScriptHost;
222
223 typedef enum {
224     GLOBAL_SCRIPTVAR,
225     GLOBAL_ELEMENTVAR
226 } global_prop_type_t;
227
228 typedef struct {
229     global_prop_type_t type;
230     WCHAR *name;
231     ScriptHost *script_host;
232     DISPID id;
233 } global_prop_t;
234
235 typedef struct {
236     IHTMLOptionElementFactory IHTMLOptionElementFactory_iface;
237
238     LONG ref;
239
240     HTMLWindow *window;
241 } HTMLOptionElementFactory;
242
243 typedef struct {
244     DispatchEx dispex;
245     IHTMLImageElementFactory IHTMLImageElementFactory_iface;
246
247     LONG ref;
248
249     HTMLWindow *window;
250 } HTMLImageElementFactory;
251
252 struct HTMLLocation {
253     DispatchEx dispex;
254     IHTMLLocation IHTMLLocation_iface;
255
256     LONG ref;
257
258     HTMLWindow *window;
259 };
260
261 typedef struct {
262     HTMLWindow *window;
263     LONG ref;
264 }  windowref_t;
265
266 typedef struct nsChannelBSC nsChannelBSC;
267
268 struct HTMLWindow {
269     DispatchEx dispex;
270     IHTMLWindow2       IHTMLWindow2_iface;
271     IHTMLWindow3       IHTMLWindow3_iface;
272     IHTMLWindow4       IHTMLWindow4_iface;
273     IHTMLPrivateWindow IHTMLPrivateWindow_iface;
274     IDispatchEx        IDispatchEx_iface;
275     IServiceProvider   IServiceProvider_iface;
276
277     LONG ref;
278
279     windowref_t *window_ref;
280     LONG task_magic;
281
282     HTMLDocumentNode *doc;
283     HTMLDocumentObj *doc_obj;
284     nsIDOMWindow *nswindow;
285     HTMLWindow *parent;
286     HTMLFrameBase *frame_element;
287     READYSTATE readystate;
288
289     nsChannelBSC *bscallback;
290     IMoniker *mon;
291     LPOLESTR url;
292
293     IHTMLEventObj *event;
294
295     SCRIPTMODE scriptmode;
296     struct list script_hosts;
297
298     HTMLOptionElementFactory *option_factory;
299     HTMLImageElementFactory *image_factory;
300     HTMLLocation *location;
301     IHTMLScreen *screen;
302
303     global_prop_t *global_props;
304     DWORD global_prop_cnt;
305     DWORD global_prop_size;
306
307     struct list children;
308     struct list sibling_entry;
309     struct list entry;
310 };
311
312 typedef enum {
313     UNKNOWN_USERMODE,
314     BROWSEMODE,
315     EDITMODE        
316 } USERMODE;
317
318 typedef struct _cp_static_data_t {
319     tid_t tid;
320     void (*on_advise)(IUnknown*,struct _cp_static_data_t*);
321     DWORD id_cnt;
322     DISPID *ids;
323 } cp_static_data_t;
324
325 typedef struct ConnectionPointContainer {
326     IConnectionPointContainer IConnectionPointContainer_iface;
327
328     ConnectionPoint *cp_list;
329     IUnknown *outer;
330     struct ConnectionPointContainer *forward_container;
331 } ConnectionPointContainer;
332
333 struct ConnectionPoint {
334     IConnectionPoint IConnectionPoint_iface;
335
336     ConnectionPointContainer *container;
337
338     union {
339         IUnknown *unk;
340         IDispatch *disp;
341         IPropertyNotifySink *propnotif;
342     } *sinks;
343     DWORD sinks_size;
344
345     const IID *iid;
346     cp_static_data_t *data;
347
348     ConnectionPoint *next;
349 };
350
351 struct HTMLDocument {
352     IHTMLDocument2              IHTMLDocument2_iface;
353     IHTMLDocument3              IHTMLDocument3_iface;
354     IHTMLDocument4              IHTMLDocument4_iface;
355     IHTMLDocument5              IHTMLDocument5_iface;
356     IHTMLDocument6              IHTMLDocument6_iface;
357     IPersistMoniker             IPersistMoniker_iface;
358     IPersistFile                IPersistFile_iface;
359     IPersistHistory             IPersistHistory_iface;
360     IMonikerProp                IMonikerProp_iface;
361     IOleObject                  IOleObject_iface;
362     IOleDocument                IOleDocument_iface;
363     IOleDocumentView            IOleDocumentView_iface;
364     IOleInPlaceActiveObject     IOleInPlaceActiveObject_iface;
365     IViewObjectEx               IViewObjectEx_iface;
366     IOleInPlaceObjectWindowless IOleInPlaceObjectWindowless_iface;
367     IServiceProvider            IServiceProvider_iface;
368     IOleCommandTarget           IOleCommandTarget_iface;
369     IOleControl                 IOleControl_iface;
370     IHlinkTarget                IHlinkTarget_iface;
371     IPersistStreamInit          IPersistStreamInit_iface;
372     IDispatchEx                 IDispatchEx_iface;
373     ISupportErrorInfo           ISupportErrorInfo_iface;
374     IObjectWithSite             IObjectWithSite_iface;
375     IOleContainer               IOleContainer_iface;
376     IObjectSafety               IObjectSafety_iface;
377
378     IUnknown *unk_impl;
379     IDispatchEx *dispex;
380
381     HTMLDocumentObj *doc_obj;
382     HTMLDocumentNode *doc_node;
383
384     HTMLWindow *window;
385
386     LONG task_magic;
387
388     ConnectionPointContainer cp_container;
389     ConnectionPoint cp_htmldocevents;
390     ConnectionPoint cp_htmldocevents2;
391     ConnectionPoint cp_propnotif;
392     ConnectionPoint cp_dispatch;
393
394     IOleAdviseHolder *advise_holder;
395 };
396
397 static inline HRESULT htmldoc_query_interface(HTMLDocument *This, REFIID riid, void **ppv)
398 {
399     return IUnknown_QueryInterface(This->unk_impl, riid, ppv);
400 }
401
402 static inline ULONG htmldoc_addref(HTMLDocument *This)
403 {
404     return IUnknown_AddRef(This->unk_impl);
405 }
406
407 static inline ULONG htmldoc_release(HTMLDocument *This)
408 {
409     return IUnknown_Release(This->unk_impl);
410 }
411
412 struct HTMLDocumentObj {
413     HTMLDocument basedoc;
414     DispatchEx dispex;
415     ICustomDoc ICustomDoc_iface;
416
417     LONG ref;
418
419     NSContainer *nscontainer;
420
421     IOleClientSite *client;
422     IDocHostUIHandler *hostui;
423     BOOL custom_hostui;
424     IOleInPlaceSite *ipsite;
425     IOleInPlaceFrame *frame;
426     IOleInPlaceUIWindow *ip_window;
427     IAdviseSink *view_sink;
428     IDocObjectService *doc_object_service;
429
430     DOCHOSTUIINFO hostinfo;
431
432     IOleUndoManager *undomgr;
433
434     HWND hwnd;
435     HWND tooltips_hwnd;
436
437     BOOL request_uiactivate;
438     BOOL in_place_active;
439     BOOL ui_active;
440     BOOL window_active;
441     BOOL hostui_setup;
442     BOOL container_locked;
443     BOOL focus;
444     INT download_state;
445
446     USERMODE usermode;
447     LPWSTR mime;
448
449     DWORD update;
450 };
451
452 struct NSContainer {
453     nsIWebBrowserChrome      nsIWebBrowserChrome_iface;
454     nsIContextMenuListener   nsIContextMenuListener_iface;
455     nsIURIContentListener    nsIURIContentListener_iface;
456     nsIEmbeddingSiteWindow   nsIEmbeddingSiteWindow_iface;
457     nsITooltipListener       nsITooltipListener_iface;
458     nsIInterfaceRequestor    nsIInterfaceRequestor_iface;
459     nsIWeakReference         nsIWeakReference_iface;
460     nsISupportsWeakReference nsISupportsWeakReference_iface;
461
462     nsIWebBrowser *webbrowser;
463     nsIWebNavigation *navigation;
464     nsIBaseWindow *window;
465     nsIWebBrowserFocus *focus;
466
467     nsIEditor *editor;
468     nsIController *editor_controller;
469
470     LONG ref;
471
472     NSContainer *parent;
473     HTMLDocumentObj *doc;
474
475     nsIURIContentListener *content_listener;
476
477     HWND hwnd;
478 };
479
480 typedef struct nsWineURI nsWineURI;
481
482 HRESULT set_wine_url(nsWineURI*,LPCWSTR);
483 nsresult on_start_uri_open(NSContainer*,nsIURI*,PRBool*);
484
485 /* Keep sync with request_method_strings in nsio.c */
486 typedef enum {
487     METHOD_GET,
488     METHOD_PUT,
489     METHOD_POST
490 } REQUEST_METHOD;
491
492 typedef struct {
493     nsIHttpChannel         nsIHttpChannel_iface;
494     nsIUploadChannel       nsIUploadChannel_iface;
495     nsIHttpChannelInternal nsIHttpChannelInternal_iface;
496
497     LONG ref;
498
499     nsWineURI *uri;
500     nsIInputStream *post_data_stream;
501     nsILoadGroup *load_group;
502     nsIInterfaceRequestor *notif_callback;
503     nsISupports *owner;
504     nsLoadFlags load_flags;
505     nsIURI *original_uri;
506     nsIURI *referrer;
507     char *content_type;
508     char *charset;
509     PRUint32 response_status;
510     REQUEST_METHOD request_method;
511     struct list response_headers;
512     struct list request_headers;
513     UINT url_scheme;
514 } nsChannel;
515
516 typedef struct {
517     struct list entry;
518     WCHAR *header;
519     WCHAR *data;
520 } http_header_t;
521
522 HRESULT set_http_header(struct list*,const WCHAR*,int,const WCHAR*,int);
523
524 typedef struct {
525     HRESULT (*qi)(HTMLDOMNode*,REFIID,void**);
526     void (*destructor)(HTMLDOMNode*);
527     HRESULT (*clone)(HTMLDOMNode*,nsIDOMNode*,HTMLDOMNode**);
528     event_target_t **(*get_event_target)(HTMLDOMNode*);
529     HRESULT (*call_event)(HTMLDOMNode*,DWORD,BOOL*);
530     HRESULT (*put_disabled)(HTMLDOMNode*,VARIANT_BOOL);
531     HRESULT (*get_disabled)(HTMLDOMNode*,VARIANT_BOOL*);
532     HRESULT (*get_document)(HTMLDOMNode*,IDispatch**);
533     HRESULT (*get_readystate)(HTMLDOMNode*,BSTR*);
534     HRESULT (*get_dispid)(HTMLDOMNode*,BSTR,DWORD,DISPID*);
535     HRESULT (*invoke)(HTMLDOMNode*,DISPID,LCID,WORD,DISPPARAMS*,VARIANT*,EXCEPINFO*,IServiceProvider*);
536     HRESULT (*bind_to_tree)(HTMLDOMNode*);
537 } NodeImplVtbl;
538
539 struct HTMLDOMNode {
540     DispatchEx dispex;
541     IHTMLDOMNode  IHTMLDOMNode_iface;
542     IHTMLDOMNode2 IHTMLDOMNode2_iface;
543     const NodeImplVtbl *vtbl;
544
545     LONG ref;
546
547     nsIDOMNode *nsnode;
548     HTMLDocumentNode *doc;
549     event_target_t *event_target;
550     ConnectionPointContainer *cp_container;
551
552     HTMLDOMNode *next;
553 };
554
555 typedef struct {
556     HTMLDOMNode node;
557     ConnectionPointContainer cp_container;
558
559     IHTMLElement  IHTMLElement_iface;
560     IHTMLElement2 IHTMLElement2_iface;
561     IHTMLElement3 IHTMLElement3_iface;
562     IHTMLElement4 IHTMLElement4_iface;
563
564     nsIDOMHTMLElement *nselem;
565     HTMLStyle *style;
566     struct list attrs;
567 } HTMLElement;
568
569 #define HTMLELEMENT_TIDS    \
570     IHTMLDOMNode_tid,       \
571     IHTMLDOMNode2_tid,      \
572     IHTMLElement_tid,       \
573     IHTMLElement2_tid,      \
574     IHTMLElement3_tid,      \
575     IHTMLElement4_tid
576
577 typedef struct {
578     HTMLElement element;
579
580     IHTMLTextContainer IHTMLTextContainer_iface;
581
582     ConnectionPoint cp;
583 } HTMLTextContainer;
584
585 struct HTMLFrameBase {
586     HTMLElement element;
587
588     IHTMLFrameBase  IHTMLFrameBase_iface;
589     IHTMLFrameBase2 IHTMLFrameBase2_iface;
590
591     HTMLWindow *content_window;
592
593     nsIDOMHTMLFrameElement *nsframe;
594     nsIDOMHTMLIFrameElement *nsiframe;
595 };
596
597 typedef struct nsDocumentEventListener nsDocumentEventListener;
598
599 struct HTMLDocumentNode {
600     HTMLDOMNode node;
601     HTMLDocument basedoc;
602
603     IInternetHostSecurityManager IInternetHostSecurityManager_iface;
604
605     nsIDocumentObserver          nsIDocumentObserver_iface;
606
607     LONG ref;
608
609     nsIDOMHTMLDocument *nsdoc;
610     HTMLDOMNode *nodes;
611     BOOL content_ready;
612     event_target_t *body_event_target;
613
614     IInternetSecurityManager *secmgr;
615     ICatInformation *catmgr;
616     nsDocumentEventListener *nsevent_listener;
617     BOOL *event_vector;
618
619     BOOL skip_mutation_notif;
620
621     struct list bindings;
622     struct list selection_list;
623     struct list range_list;
624     struct list plugin_hosts;
625 };
626
627 HRESULT HTMLDocument_Create(IUnknown*,REFIID,void**);
628 HRESULT HTMLLoadOptions_Create(IUnknown*,REFIID,void**);
629 HRESULT create_doc_from_nsdoc(nsIDOMHTMLDocument*,HTMLDocumentObj*,HTMLWindow*,HTMLDocumentNode**);
630 HRESULT create_document_fragment(nsIDOMNode*,HTMLDocumentNode*,HTMLDocumentNode**);
631
632 HRESULT HTMLWindow_Create(HTMLDocumentObj*,nsIDOMWindow*,HTMLWindow*,HTMLWindow**);
633 void update_window_doc(HTMLWindow*);
634 HTMLWindow *nswindow_to_window(const nsIDOMWindow*);
635 nsIDOMWindow *get_nsdoc_window(nsIDOMDocument*);
636 HTMLOptionElementFactory *HTMLOptionElementFactory_Create(HTMLWindow*);
637 HTMLImageElementFactory *HTMLImageElementFactory_Create(HTMLWindow*);
638 HRESULT HTMLLocation_Create(HTMLWindow*,HTMLLocation**);
639 IOmNavigator *OmNavigator_Create(void);
640 HRESULT HTMLScreen_Create(IHTMLScreen**);
641
642 void HTMLDocument_HTMLDocument3_Init(HTMLDocument*);
643 void HTMLDocument_HTMLDocument5_Init(HTMLDocument*);
644 void HTMLDocument_Persist_Init(HTMLDocument*);
645 void HTMLDocument_OleCmd_Init(HTMLDocument*);
646 void HTMLDocument_OleObj_Init(HTMLDocument*);
647 void HTMLDocument_View_Init(HTMLDocument*);
648 void HTMLDocument_Window_Init(HTMLDocument*);
649 void HTMLDocument_Service_Init(HTMLDocument*);
650 void HTMLDocument_Hlink_Init(HTMLDocument*);
651
652 void HTMLDocumentNode_SecMgr_Init(HTMLDocumentNode*);
653
654 HRESULT HTMLCurrentStyle_Create(HTMLElement*,IHTMLCurrentStyle**);
655
656 void ConnectionPoint_Init(ConnectionPoint*,ConnectionPointContainer*,REFIID,cp_static_data_t*);
657 void ConnectionPointContainer_Init(ConnectionPointContainer*,IUnknown*);
658 void ConnectionPointContainer_Destroy(ConnectionPointContainer*);
659
660 NSContainer *NSContainer_Create(HTMLDocumentObj*,NSContainer*);
661 void NSContainer_Release(NSContainer*);
662 nsresult create_chrome_window(nsIWebBrowserChrome*,nsIWebBrowserChrome**);
663
664 void init_mutation(nsIComponentManager*);
665 void init_document_mutation(HTMLDocumentNode*);
666 void release_document_mutation(HTMLDocumentNode*);
667
668 void HTMLDocument_LockContainer(HTMLDocumentObj*,BOOL);
669 void show_context_menu(HTMLDocumentObj*,DWORD,POINT*,IDispatch*);
670 void notif_focus(HTMLDocumentObj*);
671
672 void show_tooltip(HTMLDocumentObj*,DWORD,DWORD,LPCWSTR);
673 void hide_tooltip(HTMLDocumentObj*);
674 HRESULT get_client_disp_property(IOleClientSite*,DISPID,VARIANT*);
675
676 HRESULT ProtocolFactory_Create(REFCLSID,REFIID,void**);
677
678 BOOL load_gecko(BOOL);
679 void close_gecko(void);
680 void register_nsservice(nsIComponentRegistrar*,nsIServiceManager*);
681 void init_nsio(nsIComponentManager*,nsIComponentRegistrar*);
682 void release_nsio(void);
683 BOOL is_gecko_path(const char*);
684
685 HRESULT nsuri_to_url(LPCWSTR,BOOL,BSTR*);
686 HRESULT create_doc_uri(HTMLWindow*,WCHAR*,nsWineURI**);
687 HRESULT load_nsuri(HTMLWindow*,nsWineURI*,nsChannelBSC*,DWORD);
688
689 HRESULT hlink_frame_navigate(HTMLDocument*,LPCWSTR,nsIInputStream*,DWORD,BOOL*);
690 HRESULT navigate_url(HTMLWindow*,const WCHAR*,const WCHAR*);
691 HRESULT set_frame_doc(HTMLFrameBase*,nsIDOMDocument*);
692 HRESULT set_moniker(HTMLDocument*,IMoniker*,IBindCtx*,nsChannelBSC*,BOOL);
693
694 void call_property_onchanged(ConnectionPoint*,DISPID);
695 HRESULT call_set_active_object(IOleInPlaceUIWindow*,IOleInPlaceActiveObject*);
696
697 void *nsalloc(size_t) __WINE_ALLOC_SIZE(1);
698 void nsfree(void*);
699
700 void nsACString_InitDepend(nsACString*,const char*);
701 void nsACString_SetData(nsACString*,const char*);
702 PRUint32 nsACString_GetData(const nsACString*,const char**);
703 void nsACString_Finish(nsACString*);
704
705 BOOL nsAString_Init(nsAString*,const PRUnichar*);
706 void nsAString_InitDepend(nsAString*,const PRUnichar*);
707 void nsAString_SetData(nsAString*,const PRUnichar*);
708 PRUint32 nsAString_GetData(const nsAString*,const PRUnichar**);
709 void nsAString_Finish(nsAString*);
710 HRESULT return_nsstr(nsresult,nsAString*,BSTR*);
711
712 nsICommandParams *create_nscommand_params(void);
713 HRESULT nsnode_to_nsstring(nsIDOMNode*,nsAString*);
714 void get_editor_controller(NSContainer*);
715 nsresult get_nsinterface(nsISupports*,REFIID,void**);
716
717 void init_nsevents(HTMLDocumentNode*);
718 void release_nsevents(HTMLDocumentNode*);
719 void add_nsevent_listener(HTMLDocumentNode*,nsIDOMNode*,LPCWSTR);
720
721 void set_window_bscallback(HTMLWindow*,nsChannelBSC*);
722 void set_current_mon(HTMLWindow*,IMoniker*);
723 HRESULT start_binding(HTMLWindow*,HTMLDocumentNode*,BSCallback*,IBindCtx*);
724 HRESULT async_start_doc_binding(HTMLWindow*,nsChannelBSC*);
725 void abort_document_bindings(HTMLDocumentNode*);
726
727 HRESULT bind_mon_to_buffer(HTMLDocumentNode*,IMoniker*,void**,DWORD*);
728
729 HRESULT create_channelbsc(IMoniker*,WCHAR*,BYTE*,DWORD,nsChannelBSC**);
730 HRESULT channelbsc_load_stream(nsChannelBSC*,IStream*);
731 void channelbsc_set_channel(nsChannelBSC*,nsChannel*,nsIStreamListener*,nsISupports*);
732 IMoniker *get_channelbsc_mon(nsChannelBSC*);
733
734 void set_ready_state(HTMLWindow*,READYSTATE);
735
736 HRESULT HTMLSelectionObject_Create(HTMLDocumentNode*,nsISelection*,IHTMLSelectionObject**);
737 HRESULT HTMLTxtRange_Create(HTMLDocumentNode*,nsIDOMRange*,IHTMLTxtRange**);
738 HRESULT HTMLStyle_Create(nsIDOMCSSStyleDeclaration*,HTMLStyle**);
739 IHTMLStyleSheet *HTMLStyleSheet_Create(nsIDOMStyleSheet*);
740 IHTMLStyleSheetsCollection *HTMLStyleSheetsCollection_Create(nsIDOMStyleSheetList*);
741
742 void detach_selection(HTMLDocumentNode*);
743 void detach_ranges(HTMLDocumentNode*);
744 HRESULT get_node_text(HTMLDOMNode*,BSTR*);
745
746 HRESULT create_nselem(HTMLDocumentNode*,const WCHAR*,nsIDOMHTMLElement**);
747
748 HRESULT HTMLDOMTextNode_Create(HTMLDocumentNode*,nsIDOMNode*,HTMLDOMNode**);
749
750 typedef struct {
751     DispatchEx dispex;
752     IHTMLDOMAttribute IHTMLDOMAttribute_iface;
753
754     LONG ref;
755
756     DISPID dispid;
757     HTMLElement *elem;
758     struct list entry;
759 } HTMLDOMAttribute;
760
761 HRESULT HTMLDOMAttribute_Create(HTMLElement*,DISPID,HTMLDOMAttribute**);
762
763 HRESULT HTMLElement_Create(HTMLDocumentNode*,nsIDOMNode*,BOOL,HTMLElement**);
764 HRESULT HTMLCommentElement_Create(HTMLDocumentNode*,nsIDOMNode*,HTMLElement**);
765 HRESULT HTMLAnchorElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**);
766 HRESULT HTMLBodyElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**);
767 HRESULT HTMLEmbedElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**);
768 HRESULT HTMLFormElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**);
769 HRESULT HTMLFrameElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**);
770 HRESULT HTMLIFrame_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**);
771 HRESULT HTMLStyleElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**);
772 HRESULT HTMLImgElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**);
773 HRESULT HTMLInputElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**);
774 HRESULT HTMLObjectElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**);
775 HRESULT HTMLOptionElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**);
776 HRESULT HTMLScriptElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**);
777 HRESULT HTMLSelectElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**);
778 HRESULT HTMLTable_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**);
779 HRESULT HTMLTableRow_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**);
780 HRESULT HTMLTextAreaElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**);
781 HRESULT HTMLGenericElement_Create(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**);
782
783 void HTMLDOMNode_Init(HTMLDocumentNode*,HTMLDOMNode*,nsIDOMNode*);
784 void HTMLElement_Init(HTMLElement*,HTMLDocumentNode*,nsIDOMHTMLElement*,dispex_static_data_t*);
785 void HTMLElement2_Init(HTMLElement*);
786 void HTMLElement3_Init(HTMLElement*);
787 void HTMLTextContainer_Init(HTMLTextContainer*,HTMLDocumentNode*,nsIDOMHTMLElement*,dispex_static_data_t*);
788 void HTMLFrameBase_Init(HTMLFrameBase*,HTMLDocumentNode*,nsIDOMHTMLElement*,dispex_static_data_t*);
789
790 HRESULT HTMLDOMNode_QI(HTMLDOMNode*,REFIID,void**);
791 void HTMLDOMNode_destructor(HTMLDOMNode*);
792
793 HRESULT HTMLElement_QI(HTMLDOMNode*,REFIID,void**);
794 void HTMLElement_destructor(HTMLDOMNode*);
795 HRESULT HTMLElement_clone(HTMLDOMNode*,nsIDOMNode*,HTMLDOMNode**);
796
797 HRESULT HTMLFrameBase_QI(HTMLFrameBase*,REFIID,void**);
798 void HTMLFrameBase_destructor(HTMLFrameBase*);
799
800 HRESULT get_node(HTMLDocumentNode*,nsIDOMNode*,BOOL,HTMLDOMNode**);
801 void release_nodes(HTMLDocumentNode*);
802
803 void release_script_hosts(HTMLWindow*);
804 void connect_scripts(HTMLWindow*);
805 void doc_insert_script(HTMLWindow*,nsIDOMHTMLScriptElement*);
806 IDispatch *script_parse_event(HTMLWindow*,LPCWSTR);
807 HRESULT exec_script(HTMLWindow*,const WCHAR*,const WCHAR*,VARIANT*);
808 void set_script_mode(HTMLWindow*,SCRIPTMODE);
809 BOOL find_global_prop(HTMLWindow*,BSTR,DWORD,ScriptHost**,DISPID*);
810 IDispatch *get_script_disp(ScriptHost*);
811 HRESULT search_window_props(HTMLWindow*,BSTR,DWORD,DISPID*);
812
813 IHTMLElementCollection *create_all_collection(HTMLDOMNode*,BOOL);
814 IHTMLElementCollection *create_collection_from_nodelist(HTMLDocumentNode*,IUnknown*,nsIDOMNodeList*);
815 IHTMLElementCollection *create_collection_from_htmlcol(HTMLDocumentNode*,IUnknown*,nsIDOMHTMLCollection*);
816
817 /* commands */
818 typedef struct {
819     DWORD id;
820     HRESULT (*query)(HTMLDocument*,OLECMD*);
821     HRESULT (*exec)(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
822 } cmdtable_t;
823
824 extern const cmdtable_t editmode_cmds[];
825
826 void do_ns_command(HTMLDocument*,const char*,nsICommandParams*);
827
828 /* timer */
829 #define UPDATE_UI       0x0001
830 #define UPDATE_TITLE    0x0002
831
832 void update_doc(HTMLDocument*,DWORD);
833 void update_title(HTMLDocumentObj*);
834
835 /* editor */
836 void init_editor(HTMLDocument*);
837 void handle_edit_event(HTMLDocument*,nsIDOMEvent*);
838 HRESULT editor_exec_copy(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
839 HRESULT editor_exec_cut(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
840 HRESULT editor_exec_paste(HTMLDocument*,DWORD,VARIANT*,VARIANT*);
841 void handle_edit_load(HTMLDocument*);
842 HRESULT editor_is_dirty(HTMLDocument*);
843 void set_dirty(HTMLDocument*,VARIANT_BOOL);
844
845 extern DWORD mshtml_tls;
846
847 typedef struct task_t task_t;
848 typedef void (*task_proc_t)(task_t*);
849
850 struct task_t {
851     LONG target_magic;
852     task_proc_t proc;
853     struct task_t *next;
854 };
855
856 typedef struct {
857     task_t header;
858     HTMLDocumentObj *doc;
859 } docobj_task_t;
860
861 typedef struct {
862     HWND thread_hwnd;
863     task_t *task_queue_head;
864     task_t *task_queue_tail;
865     struct list timer_list;
866 } thread_data_t;
867
868 thread_data_t *get_thread_data(BOOL);
869 HWND get_thread_hwnd(void);
870
871 LONG get_task_target_magic(void);
872 void push_task(task_t*,task_proc_t,LONG);
873 void remove_target_tasks(LONG);
874
875 DWORD set_task_timer(HTMLDocument*,DWORD,BOOL,IDispatch*);
876 HRESULT clear_task_timer(HTMLDocument*,BOOL,DWORD);
877
878 const char *debugstr_variant(const VARIANT*);
879
880 DEFINE_GUID(CLSID_AboutProtocol, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
881 DEFINE_GUID(CLSID_JSProtocol, 0x3050F3B2, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
882 DEFINE_GUID(CLSID_MailtoProtocol, 0x3050F3DA, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
883 DEFINE_GUID(CLSID_ResProtocol, 0x3050F3BC, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
884 DEFINE_GUID(CLSID_SysimageProtocol, 0x76E67A63, 0x06E9, 0x11D2, 0xA8,0x40, 0x00,0x60,0x08,0x05,0x93,0x82);
885
886 DEFINE_GUID(CLSID_CMarkup,0x3050f4fb,0x98b5,0x11cf,0xbb,0x82,0x00,0xaa,0x00,0xbd,0xce,0x0b);
887
888 DEFINE_OLEGUID(CGID_DocHostCmdPriv, 0x000214D4L, 0, 0);
889
890 /* memory allocation functions */
891
892 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc(size_t len)
893 {
894     return HeapAlloc(GetProcessHeap(), 0, len);
895 }
896
897 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t len)
898 {
899     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
900 }
901
902 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc(void *mem, size_t len)
903 {
904     return HeapReAlloc(GetProcessHeap(), 0, mem, len);
905 }
906
907 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc_zero(void *mem, size_t len)
908 {
909     return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len);
910 }
911
912 static inline BOOL heap_free(void *mem)
913 {
914     return HeapFree(GetProcessHeap(), 0, mem);
915 }
916
917 static inline LPWSTR heap_strdupW(LPCWSTR str)
918 {
919     LPWSTR ret = NULL;
920
921     if(str) {
922         DWORD size;
923
924         size = (strlenW(str)+1)*sizeof(WCHAR);
925         ret = heap_alloc(size);
926         memcpy(ret, str, size);
927     }
928
929     return ret;
930 }
931
932 static inline LPWSTR heap_strndupW(LPCWSTR str, unsigned len)
933 {
934     LPWSTR ret = NULL;
935
936     if(str) {
937         ret = heap_alloc((len+1)*sizeof(WCHAR));
938         memcpy(ret, str, len*sizeof(WCHAR));
939         ret[len] = 0;
940     }
941
942     return ret;
943 }
944
945 static inline char *heap_strdupA(const char *str)
946 {
947     char *ret = NULL;
948
949     if(str) {
950         DWORD size;
951
952         size = strlen(str)+1;
953         ret = heap_alloc(size);
954         memcpy(ret, str, size);
955     }
956
957     return ret;
958 }
959
960 static inline WCHAR *heap_strdupAtoW(const char *str)
961 {
962     LPWSTR ret = NULL;
963
964     if(str) {
965         DWORD len;
966
967         len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
968         ret = heap_alloc(len*sizeof(WCHAR));
969         MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
970     }
971
972     return ret;
973 }
974
975 static inline char *heap_strdupWtoA(LPCWSTR str)
976 {
977     char *ret = NULL;
978
979     if(str) {
980         DWORD size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
981         ret = heap_alloc(size);
982         WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
983     }
984
985     return ret;
986 }
987
988 static inline void windowref_addref(windowref_t *ref)
989 {
990     InterlockedIncrement(&ref->ref);
991 }
992
993 static inline void windowref_release(windowref_t *ref)
994 {
995     if(!InterlockedDecrement(&ref->ref))
996         heap_free(ref);
997 }
998
999 HDC get_display_dc(void);
1000 HINSTANCE get_shdoclc(void);
1001 void set_statustext(HTMLDocumentObj*,INT,LPCWSTR);
1002
1003 extern HINSTANCE hInst;