Tidy up webview.h. Remove all of the doxygen comments which have now been moved to...
[wxWidgets.git] / include / wx / webview.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: webview.h
3 // Purpose: Common interface and events for web view component
4 // Author: Marianne Gagnon
5 // Id: $Id$
6 // Copyright: (c) 2010 Marianne Gagnon, 2011 Steven Lamerton
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifndef _WX_WEB_VIEW_H_
11 #define _WX_WEB_VIEW_H_
12
13 #include "wx/setup.h"
14
15 #if wxUSE_WEB
16
17 #include "wx/control.h"
18 #include "wx/event.h"
19 #include "wx/sstream.h"
20 #include "wx/sharedptr.h"
21 #include "wx/vector.h"
22
23 #include "wx/osx/webviewhistoryitem_webkit.h"
24 #include "wx/gtk/webviewhistoryitem_webkit.h"
25 #include "wx/msw/webviewhistoryitem_ie.h"
26
27 class wxFSFile;
28 class wxFileSystem;
29
30 enum wxWebViewZoom
31 {
32 wxWEB_VIEW_ZOOM_TINY,
33 wxWEB_VIEW_ZOOM_SMALL,
34 wxWEB_VIEW_ZOOM_MEDIUM,
35 wxWEB_VIEW_ZOOM_LARGE,
36 wxWEB_VIEW_ZOOM_LARGEST
37 };
38
39 enum wxWebViewZoomType
40 {
41 //Scales entire page, including images
42 wxWEB_VIEW_ZOOM_TYPE_LAYOUT,
43 wxWEB_VIEW_ZOOM_TYPE_TEXT
44 };
45
46 enum wxWebViewNavigationError
47 {
48 wxWEB_NAV_ERR_CONNECTION,
49 wxWEB_NAV_ERR_CERTIFICATE,
50 wxWEB_NAV_ERR_AUTH,
51 wxWEB_NAV_ERR_SECURITY,
52 wxWEB_NAV_ERR_NOT_FOUND,
53 wxWEB_NAV_ERR_REQUEST,
54 wxWEB_NAV_ERR_USER_CANCELLED,
55 wxWEB_NAV_ERR_OTHER
56 };
57
58 enum wxWebViewReloadFlags
59 {
60 //Default, may access cache
61 wxWEB_VIEW_RELOAD_DEFAULT,
62 wxWEB_VIEW_RELOAD_NO_CACHE
63 };
64
65 enum wxWebViewBackend
66 {
67 wxWEB_VIEW_BACKEND_DEFAULT,
68 wxWEB_VIEW_BACKEND_WEBKIT,
69 wxWEB_VIEW_BACKEND_IE
70 };
71
72 //Base class for custom scheme handlers
73 class WXDLLIMPEXP_WEB wxWebViewHandler
74 {
75 public:
76 wxWebViewHandler(const wxString& scheme) : m_scheme(scheme) {}
77 virtual wxString GetName() const { return m_scheme; }
78 virtual wxFSFile* GetFile(const wxString &uri) = 0;
79 private:
80 wxString m_scheme;
81 };
82
83 extern WXDLLIMPEXP_DATA_WEB(const char) wxWebViewNameStr[];
84 extern WXDLLIMPEXP_DATA_WEB(const char) wxWebViewDefaultURLStr[];
85
86 class WXDLLIMPEXP_WEB wxWebView : public wxControl
87 {
88 public:
89
90 virtual bool Create(wxWindow* parent,
91 wxWindowID id,
92 const wxString& url,
93 const wxPoint& pos,
94 const wxSize& size,
95 long style,
96 const wxString& name) = 0;
97
98 static wxWebView* New(wxWebViewBackend backend = wxWEB_VIEW_BACKEND_DEFAULT);
99 static wxWebView* New(wxWindow* parent,
100 wxWindowID id,
101 const wxString& url = wxWebViewDefaultURLStr,
102 const wxPoint& pos = wxDefaultPosition,
103 const wxSize& size = wxDefaultSize,
104 wxWebViewBackend backend = wxWEB_VIEW_BACKEND_DEFAULT,
105 long style = 0,
106 const wxString& name = wxWebViewNameStr);
107
108 //General methods
109 virtual wxString GetCurrentTitle() const = 0;
110 virtual wxString GetCurrentURL() const = 0;
111 // TODO: handle choosing a frame when calling GetPageSource()?
112 virtual wxString GetPageSource() const = 0;
113 virtual wxString GetPageText() const = 0;
114 virtual bool IsBusy() const = 0;
115 virtual bool IsEditable() const = 0;
116 virtual void LoadUrl(const wxString& url) = 0;
117 virtual void Print() = 0;
118 virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler) = 0;
119 virtual void Reload(wxWebViewReloadFlags flags = wxWEB_VIEW_RELOAD_DEFAULT) = 0;
120 virtual void RunScript(const wxString& javascript) = 0;
121 virtual void SetEditable(bool enable = true) = 0;
122 virtual void SetPage(const wxString& html, const wxString& baseUrl) = 0;
123 virtual void SetPage(wxInputStream& html, wxString baseUrl)
124 {
125 wxStringOutputStream stream;
126 stream.Write(html);
127 SetPage(stream.GetString(), baseUrl);
128 }
129 virtual void Stop() = 0;
130
131 //History
132 virtual bool CanGoBack() const = 0;
133 virtual bool CanGoForward() const = 0;
134 virtual void GoBack() = 0;
135 virtual void GoForward() = 0;
136 virtual void ClearHistory() = 0;
137 virtual void EnableHistory(bool enable = true) = 0;
138 virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetBackwardHistory() = 0;
139 virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetForwardHistory() = 0;
140 virtual void LoadHistoryItem(wxSharedPtr<wxWebViewHistoryItem> item) = 0;
141
142 //Zoom
143 virtual bool CanSetZoomType(wxWebViewZoomType type) const = 0;
144 virtual wxWebViewZoom GetZoom() const = 0;
145 virtual wxWebViewZoomType GetZoomType() const = 0;
146 virtual void SetZoom(wxWebViewZoom zoom) = 0;
147 virtual void SetZoomType(wxWebViewZoomType zoomType) = 0;
148
149 //Selection
150 virtual void SelectAll() = 0;
151 virtual bool HasSelection() const = 0;
152 virtual void DeleteSelection() = 0;
153 virtual wxString GetSelectedText() const = 0;
154 virtual wxString GetSelectedSource() const = 0;
155 virtual void ClearSelection() = 0;
156
157 //Clipboard functions
158 virtual bool CanCut() const = 0;
159 virtual bool CanCopy() const = 0;
160 virtual bool CanPaste() const = 0;
161 virtual void Cut() = 0;
162 virtual void Copy() = 0;
163 virtual void Paste() = 0;
164
165 //Undo / redo functionality
166 virtual bool CanUndo() const = 0;
167 virtual bool CanRedo() const = 0;
168 virtual void Undo() = 0;
169 virtual void Redo() = 0;
170
171 wxDECLARE_ABSTRACT_CLASS(wxWebView);
172 };
173
174 class WXDLLIMPEXP_WEB wxWebViewEvent : public wxCommandEvent
175 {
176 public:
177 wxWebViewEvent() {}
178 wxWebViewEvent(wxEventType type, int id, const wxString url,
179 const wxString target, bool canVeto)
180 : wxCommandEvent(type, id)
181 {
182 m_url = url;
183 m_target = target;
184 m_vetoed = false;
185 m_canVeto = canVeto;
186 }
187
188
189 const wxString& GetURL() const { return m_url; }
190 const wxString& GetTarget() const { return m_target; }
191
192 virtual wxEvent* Clone() const { return new wxWebViewEvent(*this); }
193
194 bool CanVeto() const { return m_canVeto; }
195 bool IsVetoed() const { return m_vetoed; }
196
197 void Veto() { wxASSERT(m_canVeto); m_vetoed = true; }
198
199 private:
200 wxString m_url;
201 wxString m_target;
202 bool m_canVeto;
203 bool m_vetoed;
204
205 wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxWebViewEvent);
206 };
207
208 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEB, wxEVT_COMMAND_WEB_VIEW_NAVIGATING, wxWebViewEvent );
209 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEB, wxEVT_COMMAND_WEB_VIEW_NAVIGATED, wxWebViewEvent );
210 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEB, wxEVT_COMMAND_WEB_VIEW_LOADED, wxWebViewEvent );
211 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEB, wxEVT_COMMAND_WEB_VIEW_ERROR, wxWebViewEvent );
212 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEB, wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, wxWebViewEvent );
213 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEB, wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED, wxWebViewEvent );
214
215 typedef void (wxEvtHandler::*wxWebViewEventFunction)
216 (wxWebViewEvent&);
217
218 #define wxWebViewEventHandler(func) \
219 wxEVENT_HANDLER_CAST(wxWebViewEventFunction, func)
220
221 #define EVT_WEB_VIEW_NAVIGATING(id, fn) \
222 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NAVIGATING, id, \
223 wxWebViewEventHandler(fn))
224
225 #define EVT_WEB_VIEW_NAVIGATED(id, fn) \
226 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NAVIGATED, id, \
227 wxWebViewEventHandler(fn))
228
229 #define EVT_WEB_VIEW_LOADED(id, fn) \
230 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_LOADED, id, \
231 wxWebViewEventHandler(fn))
232
233 #define EVT_WEB_VIEW_ERRROR(id, fn) \
234 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_ERROR, id, \
235 wxWebViewEventHandler(fn))
236
237 #define EVT_WEB_VIEW_NEWWINDOW(id, fn) \
238 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, id, \
239 wxWebViewEventHandler(fn))
240
241 #define EVT_WEB_VIEW_TITLE_CHANGED(id, fn) \
242 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED, id, \
243 wxWebViewEventHandler(fn))
244
245 #endif // wxUSE_WEB
246
247 #endif // _WX_WEB_VIEW_H_