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