]> git.saurik.com Git - wxWidgets.git/blame - include/wx/webview.h
using Run of base class
[wxWidgets.git] / include / wx / webview.h
CommitLineData
61b98a2d
SL
1/////////////////////////////////////////////////////////////////////////////
2// Name: webview.h
3// Purpose: Common interface and events for web view component
4// Author: Marianne Gagnon
153530af 5// Copyright: (c) 2010 Marianne Gagnon, 2011 Steven Lamerton
61b98a2d
SL
6// Licence: wxWindows licence
7/////////////////////////////////////////////////////////////////////////////
8
236cff73
SL
9#ifndef _WX_WEBVIEW_H_
10#define _WX_WEBVIEW_H_
61b98a2d 11
99644bf1 12#include "wx/defs.h"
9c805dec 13
88cc66f7 14#if wxUSE_WEBVIEW
9c805dec 15
407f2162
SC
16#include "wx/control.h"
17#include "wx/event.h"
18#include "wx/sstream.h"
5cbda74b 19#include "wx/sharedptr.h"
ae26e17b 20#include "wx/vector.h"
5cbda74b 21
37bea8d2
VZ
22#if defined(__WXOSX__)
23 #include "wx/osx/webviewhistoryitem_webkit.h"
24#elif defined(__WXGTK__)
25 #include "wx/gtk/webviewhistoryitem_webkit.h"
26#elif defined(__WXMSW__)
27 #include "wx/msw/webviewhistoryitem_ie.h"
28#else
29 #error "wxWebView not implemented on this platform."
30#endif
eafdb19c 31
29365629 32class wxFSFile;
eff8f795 33class wxFileSystem;
4c687fff 34class wxWebView;
29365629 35
61b98a2d
SL
36enum wxWebViewZoom
37{
236cff73
SL
38 wxWEBVIEW_ZOOM_TINY,
39 wxWEBVIEW_ZOOM_SMALL,
40 wxWEBVIEW_ZOOM_MEDIUM,
41 wxWEBVIEW_ZOOM_LARGE,
42 wxWEBVIEW_ZOOM_LARGEST
61b98a2d
SL
43};
44
61b98a2d
SL
45enum wxWebViewZoomType
46{
9af51222 47 //Scales entire page, including images
236cff73
SL
48 wxWEBVIEW_ZOOM_TYPE_LAYOUT,
49 wxWEBVIEW_ZOOM_TYPE_TEXT
61b98a2d
SL
50};
51
04fa04d8 52enum wxWebViewNavigationError
61b98a2d 53{
236cff73
SL
54 wxWEBVIEW_NAV_ERR_CONNECTION,
55 wxWEBVIEW_NAV_ERR_CERTIFICATE,
56 wxWEBVIEW_NAV_ERR_AUTH,
57 wxWEBVIEW_NAV_ERR_SECURITY,
58 wxWEBVIEW_NAV_ERR_NOT_FOUND,
59 wxWEBVIEW_NAV_ERR_REQUEST,
60 wxWEBVIEW_NAV_ERR_USER_CANCELLED,
61 wxWEBVIEW_NAV_ERR_OTHER
61b98a2d
SL
62};
63
61b98a2d
SL
64enum wxWebViewReloadFlags
65{
9af51222 66 //Default, may access cache
236cff73
SL
67 wxWEBVIEW_RELOAD_DEFAULT,
68 wxWEBVIEW_RELOAD_NO_CACHE
61b98a2d
SL
69};
70
66ac0400
SL
71enum wxWebViewFindFlags
72{
236cff73
SL
73 wxWEBVIEW_FIND_WRAP = 0x0001,
74 wxWEBVIEW_FIND_ENTIRE_WORD = 0x0002,
75 wxWEBVIEW_FIND_MATCH_CASE = 0x0004,
76 wxWEBVIEW_FIND_HIGHLIGHT_RESULT = 0x0008,
77 wxWEBVIEW_FIND_BACKWARDS = 0x0010,
78 wxWEBVIEW_FIND_DEFAULT = 0
66ac0400
SL
79};
80
9e3d4a32 81//Base class for custom scheme handlers
467d261e 82class WXDLLIMPEXP_WEBVIEW wxWebViewHandler
29365629
SL
83{
84public:
7d8d6163 85 wxWebViewHandler(const wxString& scheme) : m_scheme(scheme) {}
5b91ac06 86 virtual ~wxWebViewHandler() {}
7d8d6163 87 virtual wxString GetName() const { return m_scheme; }
29365629 88 virtual wxFSFile* GetFile(const wxString &uri) = 0;
7d8d6163
SL
89private:
90 wxString m_scheme;
29365629
SL
91};
92
467d261e
SL
93extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewNameStr[];
94extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewDefaultURLStr[];
4c687fff
SL
95extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewBackendDefault[];
96extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewBackendIE[];
97extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewBackendWebKit[];
98
99class WXDLLIMPEXP_WEBVIEW wxWebViewFactory : public wxObject
100{
101public:
102 virtual wxWebView* Create() = 0;
103 virtual wxWebView* Create(wxWindow* parent,
104 wxWindowID id,
105 const wxString& url = wxWebViewDefaultURLStr,
106 const wxPoint& pos = wxDefaultPosition,
107 const wxSize& size = wxDefaultSize,
108 long style = 0,
109 const wxString& name = wxWebViewNameStr) = 0;
110};
111
112WX_DECLARE_STRING_HASH_MAP(wxSharedPtr<wxWebViewFactory>, wxStringWebViewFactoryMap);
61b98a2d 113
467d261e 114class WXDLLIMPEXP_WEBVIEW wxWebView : public wxControl
61b98a2d
SL
115{
116public:
c420d57b
SL
117 wxWebView()
118 {
119 m_showMenu = true;
120 }
121
39498710 122 virtual ~wxWebView() {}
61b98a2d 123
61b98a2d
SL
124 virtual bool Create(wxWindow* parent,
125 wxWindowID id,
cce10ca0
RD
126 const wxString& url = wxWebViewDefaultURLStr,
127 const wxPoint& pos = wxDefaultPosition,
128 const wxSize& size = wxDefaultSize,
129 long style = 0,
130 const wxString& name = wxWebViewNameStr) = 0;
61b98a2d 131
4c687fff
SL
132 // Factory methods allowing the use of custom factories registered with
133 // RegisterFactory
134 static wxWebView* New(const wxString& backend = wxWebViewBackendDefault);
61b98a2d 135 static wxWebView* New(wxWindow* parent,
4c687fff
SL
136 wxWindowID id,
137 const wxString& url = wxWebViewDefaultURLStr,
138 const wxPoint& pos = wxDefaultPosition,
139 const wxSize& size = wxDefaultSize,
140 const wxString& backend = wxWebViewBackendDefault,
141 long style = 0,
142 const wxString& name = wxWebViewNameStr);
143
144 static void RegisterFactory(const wxString& backend,
145 wxSharedPtr<wxWebViewFactory> factory);
146
147 // General methods
c420d57b
SL
148 virtual void EnableContextMenu(bool enable = true)
149 {
150 m_showMenu = enable;
151 }
9af51222
SL
152 virtual wxString GetCurrentTitle() const = 0;
153 virtual wxString GetCurrentURL() const = 0;
154 // TODO: handle choosing a frame when calling GetPageSource()?
155 virtual wxString GetPageSource() const = 0;
156 virtual wxString GetPageText() const = 0;
157 virtual bool IsBusy() const = 0;
c420d57b 158 virtual bool IsContextMenuEnabled() const { return m_showMenu; }
9af51222 159 virtual bool IsEditable() const = 0;
4d0dddc7 160 virtual void LoadURL(const wxString& url) = 0;
9af51222
SL
161 virtual void Print() = 0;
162 virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler) = 0;
236cff73 163 virtual void Reload(wxWebViewReloadFlags flags = wxWEBVIEW_RELOAD_DEFAULT) = 0;
9af51222
SL
164 virtual void RunScript(const wxString& javascript) = 0;
165 virtual void SetEditable(bool enable = true) = 0;
a977376a
VZ
166 void SetPage(const wxString& html, const wxString& baseUrl)
167 {
168 DoSetPage(html, baseUrl);
169 }
170 void SetPage(wxInputStream& html, wxString baseUrl)
9af51222
SL
171 {
172 wxStringOutputStream stream;
173 stream.Write(html);
a977376a 174 DoSetPage(stream.GetString(), baseUrl);
9af51222
SL
175 }
176 virtual void Stop() = 0;
61b98a2d 177
9af51222 178 //History
e669ddde 179 virtual bool CanGoBack() const = 0;
e669ddde 180 virtual bool CanGoForward() const = 0;
61b98a2d 181 virtual void GoBack() = 0;
61b98a2d 182 virtual void GoForward() = 0;
152a5808
SL
183 virtual void ClearHistory() = 0;
184 virtual void EnableHistory(bool enable = true) = 0;
c13d6ac1
SL
185 virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetBackwardHistory() = 0;
186 virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetForwardHistory() = 0;
187 virtual void LoadHistoryItem(wxSharedPtr<wxWebViewHistoryItem> item) = 0;
152a5808 188
9af51222
SL
189 //Zoom
190 virtual bool CanSetZoomType(wxWebViewZoomType type) const = 0;
e669ddde 191 virtual wxWebViewZoom GetZoom() const = 0;
9af51222 192 virtual wxWebViewZoomType GetZoomType() const = 0;
61b98a2d 193 virtual void SetZoom(wxWebViewZoom zoom) = 0;
61b98a2d
SL
194 virtual void SetZoomType(wxWebViewZoomType zoomType) = 0;
195
9af51222 196 //Selection
63a65070 197 virtual void SelectAll() = 0;
e669ddde 198 virtual bool HasSelection() const = 0;
63a65070 199 virtual void DeleteSelection() = 0;
e669ddde
SL
200 virtual wxString GetSelectedText() const = 0;
201 virtual wxString GetSelectedSource() const = 0;
41933aa5 202 virtual void ClearSelection() = 0;
63a65070 203
4681a3ea 204 //Clipboard functions
e669ddde
SL
205 virtual bool CanCut() const = 0;
206 virtual bool CanCopy() const = 0;
207 virtual bool CanPaste() const = 0;
4681a3ea
SL
208 virtual void Cut() = 0;
209 virtual void Copy() = 0;
210 virtual void Paste() = 0;
97e49559
SL
211
212 //Undo / redo functionality
e669ddde
SL
213 virtual bool CanUndo() const = 0;
214 virtual bool CanRedo() const = 0;
97e49559
SL
215 virtual void Undo() = 0;
216 virtual void Redo() = 0;
eff8f795 217
b6a49c2b
VZ
218 //Get the pointer to the underlying native engine.
219 virtual void* GetNativeBackend() const = 0;
66ac0400 220 //Find function
236cff73 221 virtual long Find(const wxString& text, int flags = wxWEBVIEW_FIND_DEFAULT) = 0;
b6a49c2b 222
a977376a
VZ
223protected:
224 virtual void DoSetPage(const wxString& html, const wxString& baseUrl) = 0;
225
c420d57b 226private:
4c687fff
SL
227 static void InitFactoryMap();
228 static wxStringWebViewFactoryMap::iterator FindFactory(const wxString &backend);
229
c420d57b 230 bool m_showMenu;
4c687fff 231 static wxStringWebViewFactoryMap m_factoryMap;
c420d57b 232
cddf4541 233 wxDECLARE_ABSTRACT_CLASS(wxWebView);
61b98a2d
SL
234};
235
467d261e 236class WXDLLIMPEXP_WEBVIEW wxWebViewEvent : public wxNotifyEvent
61b98a2d
SL
237{
238public:
04fa04d8
SL
239 wxWebViewEvent() {}
240 wxWebViewEvent(wxEventType type, int id, const wxString url,
3225a4b8
SL
241 const wxString target)
242 : wxNotifyEvent(type, id), m_url(url), m_target(target)
243 {}
61b98a2d 244
61b98a2d 245
9af51222 246 const wxString& GetURL() const { return m_url; }
61b98a2d
SL
247 const wxString& GetTarget() const { return m_target; }
248
04fa04d8 249 virtual wxEvent* Clone() const { return new wxWebViewEvent(*this); }
61b98a2d 250private:
e40741b9 251 wxString m_url;
61b98a2d 252 wxString m_target;
61b98a2d 253
04fa04d8 254 wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxWebViewEvent);
61b98a2d
SL
255};
256
ce7fe42e
VZ
257wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_WEBVIEW_NAVIGATING, wxWebViewEvent );
258wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_WEBVIEW_NAVIGATED, wxWebViewEvent );
259wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_WEBVIEW_LOADED, wxWebViewEvent );
260wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_WEBVIEW_ERROR, wxWebViewEvent );
261wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_WEBVIEW_NEWWINDOW, wxWebViewEvent );
262wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW, wxEVT_WEBVIEW_TITLE_CHANGED, wxWebViewEvent );
61b98a2d 263
04fa04d8
SL
264typedef void (wxEvtHandler::*wxWebViewEventFunction)
265 (wxWebViewEvent&);
61b98a2d 266
04fa04d8
SL
267#define wxWebViewEventHandler(func) \
268 wxEVENT_HANDLER_CAST(wxWebViewEventFunction, func)
61b98a2d 269
236cff73 270#define EVT_WEBVIEW_NAVIGATING(id, fn) \
ce7fe42e 271 wx__DECLARE_EVT1(wxEVT_WEBVIEW_NAVIGATING, id, \
04fa04d8 272 wxWebViewEventHandler(fn))
61b98a2d 273
236cff73 274#define EVT_WEBVIEW_NAVIGATED(id, fn) \
ce7fe42e 275 wx__DECLARE_EVT1(wxEVT_WEBVIEW_NAVIGATED, id, \
04fa04d8 276 wxWebViewEventHandler(fn))
61b98a2d 277
236cff73 278#define EVT_WEBVIEW_LOADED(id, fn) \
ce7fe42e 279 wx__DECLARE_EVT1(wxEVT_WEBVIEW_LOADED, id, \
04fa04d8 280 wxWebViewEventHandler(fn))
61b98a2d 281
236cff73 282#define EVT_WEBVIEW_ERROR(id, fn) \
ce7fe42e 283 wx__DECLARE_EVT1(wxEVT_WEBVIEW_ERROR, id, \
04fa04d8 284 wxWebViewEventHandler(fn))
61b98a2d 285
236cff73 286#define EVT_WEBVIEW_NEWWINDOW(id, fn) \
ce7fe42e 287 wx__DECLARE_EVT1(wxEVT_WEBVIEW_NEWWINDOW, id, \
04fa04d8 288 wxWebViewEventHandler(fn))
853b6cd0 289
236cff73 290#define EVT_WEBVIEW_TITLE_CHANGED(id, fn) \
ce7fe42e 291 wx__DECLARE_EVT1(wxEVT_WEBVIEW_TITLE_CHANGED, id, \
04fa04d8 292 wxWebViewEventHandler(fn))
153530af 293
ce7fe42e
VZ
294// old wxEVT_COMMAND_* constants
295#define wxEVT_COMMAND_WEBVIEW_NAVIGATING wxEVT_WEBVIEW_NAVIGATING
296#define wxEVT_COMMAND_WEBVIEW_NAVIGATED wxEVT_WEBVIEW_NAVIGATED
297#define wxEVT_COMMAND_WEBVIEW_LOADED wxEVT_WEBVIEW_LOADED
298#define wxEVT_COMMAND_WEBVIEW_ERROR wxEVT_WEBVIEW_ERROR
299#define wxEVT_COMMAND_WEBVIEW_NEWWINDOW wxEVT_WEBVIEW_NEWWINDOW
300#define wxEVT_COMMAND_WEBVIEW_TITLE_CHANGED wxEVT_WEBVIEW_TITLE_CHANGED
301
88cc66f7 302#endif // wxUSE_WEBVIEW
9c805dec 303
236cff73 304#endif // _WX_WEBVIEW_H_