mshtml: Added put_backgroundColor implementation.
[wine] / dlls / mshtml / mshtml_private.h
1 /*
2  * Copyright 2005-2006 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 "docobj.h"
20 #include "mshtml.h"
21 #include "mshtmhst.h"
22 #include "hlink.h"
23
24 #ifdef INIT_GUID
25 #include "initguid.h"
26 #endif
27
28 #include "nsiface.h"
29
30 #define GENERATE_MSHTML_NS_FAILURE(code) \
31     ((nsresult) ((PRUint32)(1<<31) | ((PRUint32)(0x45+6)<<16) | (PRUint32)(code)))
32
33 #define NS_OK                     ((nsresult)0x00000000L)
34 #define NS_ERROR_FAILURE          ((nsresult)0x80004005L)
35 #define NS_NOINTERFACE            ((nsresult)0x80004002L)
36 #define NS_ERROR_NOT_IMPLEMENTED  ((nsresult)0x80004001L)
37 #define NS_ERROR_INVALID_ARG      ((nsresult)0x80070057L) 
38 #define NS_ERROR_UNEXPECTED       ((nsresult)0x8000ffffL)
39 #define NS_ERROR_UNKNOWN_PROTOCOL ((nsresult)0x804b0012L)
40
41 #define WINE_NS_LOAD_FROM_MONIKER GENERATE_MSHTML_NS_FAILURE(0)
42
43 #define NS_FAILED(res) ((res) & 0x80000000)
44 #define NS_SUCCEEDED(res) (!NS_FAILED(res))
45
46 #define NSAPI WINAPI
47
48 #define NS_ELEMENT_NODE   1
49 #define NS_DOCUMENT_NODE  9
50
51 typedef struct HTMLDOMNode HTMLDOMNode;
52 typedef struct ConnectionPoint ConnectionPoint;
53 typedef struct BSCallback BSCallback;
54
55 typedef enum {
56     UNKNOWN_USERMODE,
57     BROWSEMODE,
58     EDITMODE        
59 } USERMODE;
60
61 struct HTMLDocument {
62     const IHTMLDocument2Vtbl              *lpHTMLDocument2Vtbl;
63     const IHTMLDocument3Vtbl              *lpHTMLDocument3Vtbl;
64     const IPersistMonikerVtbl             *lpPersistMonikerVtbl;
65     const IPersistFileVtbl                *lpPersistFileVtbl;
66     const IMonikerPropVtbl                *lpMonikerPropVtbl;
67     const IOleObjectVtbl                  *lpOleObjectVtbl;
68     const IOleDocumentVtbl                *lpOleDocumentVtbl;
69     const IOleDocumentViewVtbl            *lpOleDocumentViewVtbl;
70     const IOleInPlaceActiveObjectVtbl     *lpOleInPlaceActiveObjectVtbl;
71     const IViewObject2Vtbl                *lpViewObject2Vtbl;
72     const IOleInPlaceObjectWindowlessVtbl *lpOleInPlaceObjectWindowlessVtbl;
73     const IServiceProviderVtbl            *lpServiceProviderVtbl;
74     const IOleCommandTargetVtbl           *lpOleCommandTargetVtbl;
75     const IOleControlVtbl                 *lpOleControlVtbl;
76     const IHlinkTargetVtbl                *lpHlinkTargetVtbl;
77     const IConnectionPointContainerVtbl   *lpConnectionPointContainerVtbl;
78     const IPersistStreamInitVtbl          *lpPersistStreamInitVtbl;
79
80     LONG ref;
81
82     NSContainer *nscontainer;
83
84     IOleClientSite *client;
85     IDocHostUIHandler *hostui;
86     IOleInPlaceSite *ipsite;
87     IOleInPlaceFrame *frame;
88
89     BSCallback *bscallback;
90
91     HWND hwnd;
92     HWND tooltips_hwnd;
93
94     DOCHOSTUIINFO hostinfo;
95
96     USERMODE usermode;
97     READYSTATE readystate;
98     BOOL in_place_active;
99     BOOL ui_active;
100     BOOL window_active;
101     BOOL has_key_path;
102     BOOL container_locked;
103
104     ConnectionPoint *cp_htmldocevents;
105     ConnectionPoint *cp_htmldocevents2;
106     ConnectionPoint *cp_propnotif;
107
108     HTMLDOMNode *nodes;
109 };
110
111 struct NSContainer {
112     const nsIWebBrowserChromeVtbl       *lpWebBrowserChromeVtbl;
113     const nsIContextMenuListenerVtbl    *lpContextMenuListenerVtbl;
114     const nsIURIContentListenerVtbl     *lpURIContentListenerVtbl;
115     const nsIEmbeddingSiteWindowVtbl    *lpEmbeddingSiteWindowVtbl;
116     const nsITooltipListenerVtbl        *lpTooltipListenerVtbl;
117     const nsIInterfaceRequestorVtbl     *lpInterfaceRequestorVtbl;
118     const nsIWeakReferenceVtbl          *lpWeakReferenceVtbl;
119     const nsISupportsWeakReferenceVtbl  *lpSupportsWeakReferenceVtbl;
120
121     nsIWebBrowser *webbrowser;
122     nsIWebNavigation *navigation;
123     nsIBaseWindow *window;
124     nsIWebBrowserFocus *focus;
125
126     LONG ref;
127
128     NSContainer *parent;
129     HTMLDocument *doc;
130
131     nsIURIContentListener *content_listener;
132
133     HWND hwnd;
134
135     BSCallback *bscallback; /* hack */
136 };
137
138 typedef struct {
139     const nsIHttpChannelVtbl *lpHttpChannelVtbl;
140     const nsIUploadChannelVtbl *lpUploadChannelVtbl;
141
142     LONG ref;
143
144     nsIChannel *channel;
145     nsIHttpChannel *http_channel;
146     nsIWineURI *uri;
147     nsIInputStream *post_data_stream;
148     nsILoadGroup *load_group;
149     nsIInterfaceRequestor *notif_callback;
150     nsLoadFlags load_flags;
151     nsIURI *original_uri;
152     char *content;
153 } nsChannel;
154
155 typedef struct {
156     const nsIInputStreamVtbl *lpInputStreamVtbl;
157
158     LONG ref;
159
160     char buf[1024];
161     DWORD buf_size;
162 } nsProtocolStream;
163
164 struct BSCallback {
165     const IBindStatusCallbackVtbl *lpBindStatusCallbackVtbl;
166     const IServiceProviderVtbl    *lpServiceProviderVtbl;
167     const IHttpNegotiate2Vtbl     *lpHttpNegotiate2Vtbl;
168     const IInternetBindInfoVtbl   *lpInternetBindInfoVtbl;
169
170     LONG ref;
171
172     LPWSTR headers;
173     HGLOBAL post_data;
174     ULONG post_data_len;
175     ULONG readed;
176
177     nsChannel *nschannel;
178     nsIStreamListener *nslistener;
179     nsISupports *nscontext;
180
181     IMoniker *mon;
182     IBinding *binding;
183
184     HTMLDocument *doc;
185
186     nsProtocolStream *nsstream;
187 };
188
189 struct HTMLDOMNode {
190     const IHTMLDOMNodeVtbl *lpHTMLDOMNodeVtbl;
191
192     void (*destructor)(IUnknown*);
193
194     enum {
195         NT_UNKNOWN,
196         NT_HTMLELEM
197     } node_type;
198
199     union {
200         IUnknown *unk;
201         IHTMLElement *elem;
202     } impl;
203
204     nsIDOMNode *nsnode;
205     HTMLDocument *doc;
206
207     HTMLDOMNode *next;
208 };
209
210 typedef struct {
211     const IHTMLElementVtbl *lpHTMLElementVtbl;
212     const IHTMLElement2Vtbl *lpHTMLElement2Vtbl;
213
214     void (*destructor)(IUnknown*);
215
216     nsIDOMHTMLElement *nselem;
217     HTMLDOMNode *node;
218
219     IUnknown *impl;
220 } HTMLElement;
221
222 typedef struct {
223     const IHTMLTextContainerVtbl *lpHTMLTextContainerVtbl;
224
225     HTMLElement *element;
226 } HTMLTextContainer;
227
228 #define HTMLDOC(x)       ((IHTMLDocument2*)               &(x)->lpHTMLDocument2Vtbl)
229 #define HTMLDOC3(x)      ((IHTMLDocument3*)               &(x)->lpHTMLDocument3Vtbl)
230 #define PERSIST(x)       ((IPersist*)                     &(x)->lpPersistFileVtbl)
231 #define PERSISTMON(x)    ((IPersistMoniker*)              &(x)->lpPersistMonikerVtbl)
232 #define PERSISTFILE(x)   ((IPersistFile*)                 &(x)->lpPersistFileVtbl)
233 #define MONPROP(x)       ((IMonikerProp*)                 &(x)->lpMonikerPropVtbl)
234 #define OLEOBJ(x)        ((IOleObject*)                   &(x)->lpOleObjectVtbl)
235 #define OLEDOC(x)        ((IOleDocument*)                 &(x)->lpOleDocumentVtbl)
236 #define DOCVIEW(x)       ((IOleDocumentView*)             &(x)->lpOleDocumentViewVtbl)
237 #define OLEWIN(x)        ((IOleWindow*)                   &(x)->lpOleInPlaceActiveObjectVtbl)
238 #define ACTOBJ(x)        ((IOleInPlaceActiveObject*)      &(x)->lpOleInPlaceActiveObjectVtbl)
239 #define VIEWOBJ(x)       ((IViewObject*)                  &(x)->lpViewObject2Vtbl)
240 #define VIEWOBJ2(x)      ((IViewObject2*)                 &(x)->lpViewObject2Vtbl)
241 #define INPLACEOBJ(x)    ((IOleInPlaceObject*)            &(x)->lpOleInPlaceObjectWindowlessVtbl)
242 #define INPLACEWIN(x)    ((IOleInPlaceObjectWindowless*)  &(x)->lpOleInPlaceObjectWindowlessVtbl)
243 #define SERVPROV(x)      ((IServiceProvider*)             &(x)->lpServiceProviderVtbl)
244 #define CMDTARGET(x)     ((IOleCommandTarget*)            &(x)->lpOleCommandTargetVtbl)
245 #define CONTROL(x)       ((IOleControl*)                  &(x)->lpOleControlVtbl)
246 #define HLNKTARGET(x)    ((IHlinkTarget*)                 &(x)->lpHlinkTargetVtbl)
247 #define CONPTCONT(x)     ((IConnectionPointContainer*)    &(x)->lpConnectionPointContainerVtbl)
248 #define PERSTRINIT(x)    ((IPersistStreamInit*)           &(x)->lpPersistStreamInitVtbl)
249
250 #define NSWBCHROME(x)    ((nsIWebBrowserChrome*)          &(x)->lpWebBrowserChromeVtbl)
251 #define NSCML(x)         ((nsIContextMenuListener*)       &(x)->lpContextMenuListenerVtbl)
252 #define NSURICL(x)       ((nsIURIContentListener*)        &(x)->lpURIContentListenerVtbl)
253 #define NSEMBWNDS(x)     ((nsIEmbeddingSiteWindow*)       &(x)->lpEmbeddingSiteWindowVtbl)
254 #define NSIFACEREQ(x)    ((nsIInterfaceRequestor*)        &(x)->lpInterfaceRequestorVtbl)
255 #define NSTOOLTIP(x)     ((nsITooltipListener*)           &(x)->lpTooltipListenerVtbl)
256 #define NSWEAKREF(x)     ((nsIWeakReference*)             &(x)->lpWeakReferenceVtbl)
257 #define NSSUPWEAKREF(x)  ((nsISupportsWeakReference*)     &(x)->lpSupportsWeakReferenceVtbl)
258
259 #define NSCHANNEL(x)     ((nsIChannel*)        &(x)->lpHttpChannelVtbl)
260 #define NSHTTPCHANNEL(x) ((nsIHttpChannel*)    &(x)->lpHttpChannelVtbl)
261 #define NSUPCHANNEL(x)   ((nsIUploadChannel*)  &(x)->lpUploadChannelVtbl)
262
263 #define HTTPNEG(x)       ((IHttpNegotiate2*)              &(x)->lpHttpNegotiate2Vtbl)
264 #define STATUSCLB(x)     ((IBindStatusCallback*)          &(x)->lpBindStatusCallbackVtbl)
265 #define BINDINFO(x)      ((IInternetBindInfo*)            &(x)->lpInternetBindInfoVtbl);
266
267 #define HTMLELEM(x)      ((IHTMLElement*)                 &(x)->lpHTMLElementVtbl)
268 #define HTMLELEM2(x)     ((IHTMLElement2*)                &(x)->lpHTMLElement2Vtbl)
269 #define HTMLDOMNODE(x)   ((IHTMLDOMNode*)                 &(x)->lpHTMLDOMNodeVtbl)
270
271 #define HTMLTEXTCONT(x)  ((IHTMLTextContainer*)           &(x)->lpHTMLTextContainerVtbl)
272
273 #define DEFINE_THIS(cls,ifc,iface) ((cls*)((BYTE*)(iface)-offsetof(cls,lp ## ifc ## Vtbl)))
274
275 HRESULT HTMLDocument_Create(IUnknown*,REFIID,void**);
276 HRESULT HTMLLoadOptions_Create(IUnknown*,REFIID,void**);
277
278 void HTMLDocument_HTMLDocument3_Init(HTMLDocument*);
279 void HTMLDocument_Persist_Init(HTMLDocument*);
280 void HTMLDocument_OleCmd_Init(HTMLDocument*);
281 void HTMLDocument_OleObj_Init(HTMLDocument*);
282 void HTMLDocument_View_Init(HTMLDocument*);
283 void HTMLDocument_Window_Init(HTMLDocument*);
284 void HTMLDocument_Service_Init(HTMLDocument*);
285 void HTMLDocument_Hlink_Init(HTMLDocument*);
286 void HTMLDocument_ConnectionPoints_Init(HTMLDocument*);
287
288 void HTMLDocument_ConnectionPoints_Destroy(HTMLDocument*);
289
290 NSContainer *NSContainer_Create(HTMLDocument*,NSContainer*);
291 void NSContainer_Release(NSContainer*);
292
293 void HTMLDocument_LockContainer(HTMLDocument*,BOOL);
294 void HTMLDocument_ShowContextMenu(HTMLDocument*,DWORD,POINT*);
295
296 void show_tooltip(HTMLDocument*,DWORD,DWORD,LPCWSTR);
297 void hide_tooltip(HTMLDocument*);
298 HRESULT get_client_disp_property(IOleClientSite*,DISPID,VARIANT*);
299
300 HRESULT ProtocolFactory_Create(REFCLSID,REFIID,void**);
301
302 void close_gecko(void);
303 void register_nsservice(nsIComponentRegistrar*,nsIServiceManager*);
304 void init_nsio(nsIComponentManager*,nsIComponentRegistrar*);
305
306 void hlink_frame_navigate(HTMLDocument*,IHlinkFrame*,LPCWSTR,nsIInputStream*,DWORD);
307
308 void call_property_onchanged(ConnectionPoint*,DISPID);
309
310 void *nsalloc(size_t);
311 void nsfree(void*);
312
313 void nsACString_Init(nsACString*,const char*);
314 PRUint32 nsACString_GetData(const nsACString*,const char**,PRBool*);
315 void nsACString_Finish(nsACString*);
316
317 void nsAString_Init(nsAString*,const PRUnichar*);
318 PRUint32 nsAString_GetData(const nsAString*,const PRUnichar**,PRBool*);
319 void nsAString_Finish(nsAString*);
320
321 nsIInputStream *create_nsstream(const char*,PRInt32);
322 nsICommandParams *create_nscommand_params(void);
323 void nsnode_to_nsstring(nsIDOMNode*,nsAString*);
324
325 BSCallback *create_bscallback(IMoniker*);
326 HRESULT start_binding(BSCallback*);
327 void set_document_bscallback(HTMLDocument*,BSCallback*);
328
329 IHlink *Hlink_Create(void);
330 IHTMLSelectionObject *HTMLSelectionObject_Create(nsISelection*);
331 IHTMLTxtRange *HTMLTxtRange_Create(nsISelection*);
332 IHTMLStyle *HTMLStyle_Create(nsIDOMCSSStyleDeclaration*);
333
334 void HTMLElement_Create(HTMLDOMNode*);
335 void HTMLBodyElement_Create(HTMLElement*);
336 void HTMLInputElement_Create(HTMLElement*);
337 void HTMLSelectElement_Create(HTMLElement*);
338 void HTMLTextAreaElement_Create(HTMLElement*);
339
340 void HTMLElement2_Init(HTMLElement*);
341
342 void HTMLTextContainer_Init(HTMLTextContainer*,HTMLElement*);
343
344 HRESULT HTMLDOMNode_QI(HTMLDOMNode*,REFIID,void**);
345 HRESULT HTMLElement_QI(HTMLElement*,REFIID,void**);
346
347 HTMLDOMNode *get_node(HTMLDocument*,nsIDOMNode*);
348 void release_nodes(HTMLDocument*);
349
350 void install_wine_gecko(void);
351
352 extern DWORD mshtml_tls;
353
354 typedef struct task_t {
355     HTMLDocument *doc;
356
357     enum {
358         TASK_SETDOWNLOADSTATE,
359         TASK_PARSECOMPLETE,
360         TASK_SETPROGRESS
361     } task_id;
362
363     struct task_t *next;
364 } task_t;
365
366 typedef struct {
367     HWND thread_hwnd;
368     task_t *task_queue_head;
369     task_t *task_queue_tail;
370 } thread_data_t;
371
372 thread_data_t *get_thread_data(BOOL);
373 HWND get_thread_hwnd(void);
374 void push_task(task_t*);
375 void remove_doc_tasks(HTMLDocument*);
376
377 DEFINE_GUID(CLSID_AboutProtocol, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
378 DEFINE_GUID(CLSID_JSProtocol, 0x3050F3B2, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
379 DEFINE_GUID(CLSID_MailtoProtocol, 0x3050F3DA, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
380 DEFINE_GUID(CLSID_ResProtocol, 0x3050F3BC, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
381 DEFINE_GUID(CLSID_SysimageProtocol, 0x76E67A63, 0x06E9, 0x11D2, 0xA8,0x40, 0x00,0x60,0x08,0x05,0x93,0x82);
382
383 DEFINE_GUID(CLSID_CMarkup,0x3050f4fb,0x98b5,0x11cf,0xbb,0x82,0x00,0xaa,0x00,0xbd,0xce,0x0b);
384
385 extern LONG module_ref;
386 #define LOCK_MODULE()   InterlockedIncrement(&module_ref)
387 #define UNLOCK_MODULE() InterlockedDecrement(&module_ref)
388
389 /* memory allocation functions */
390
391 static inline void *mshtml_alloc(size_t len)
392 {
393     return HeapAlloc(GetProcessHeap(), 0, len);
394 }
395
396 static inline void *mshtml_alloc_zero(size_t len)
397 {
398     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
399 }
400
401 static inline void *mshtml_realloc(void *mem, size_t len)
402 {
403     return HeapReAlloc(GetProcessHeap(), 0, mem, len);
404 }
405
406 static inline BOOL mshtml_free(void *mem)
407 {
408     return HeapFree(GetProcessHeap(), 0, mem);
409 }
410
411 HINSTANCE get_shdoclc(void);
412
413 extern HINSTANCE hInst;