1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common interface and events for web view component
4 // Author: Marianne Gagnon
6 // Copyright: (c) 2010 Marianne Gagnon, 2011 Steven Lamerton
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_WEB_VIEW_H_
11 #define _WX_WEB_VIEW_H_
17 #include "wx/control.h"
19 #include "wx/sstream.h"
20 #include "wx/sharedptr.h"
21 #include "wx/vector.h"
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"
30 #error "wxWebView not implemented on this platform."
39 wxWEB_VIEW_ZOOM_SMALL
,
40 wxWEB_VIEW_ZOOM_MEDIUM
,
41 wxWEB_VIEW_ZOOM_LARGE
,
42 wxWEB_VIEW_ZOOM_LARGEST
45 enum wxWebViewZoomType
47 //Scales entire page, including images
48 wxWEB_VIEW_ZOOM_TYPE_LAYOUT
,
49 wxWEB_VIEW_ZOOM_TYPE_TEXT
52 enum wxWebViewNavigationError
54 wxWEB_NAV_ERR_CONNECTION
,
55 wxWEB_NAV_ERR_CERTIFICATE
,
57 wxWEB_NAV_ERR_SECURITY
,
58 wxWEB_NAV_ERR_NOT_FOUND
,
59 wxWEB_NAV_ERR_REQUEST
,
60 wxWEB_NAV_ERR_USER_CANCELLED
,
64 enum wxWebViewReloadFlags
66 //Default, may access cache
67 wxWEB_VIEW_RELOAD_DEFAULT
,
68 wxWEB_VIEW_RELOAD_NO_CACHE
71 enum wxWebViewFindFlags
73 wxWEB_VIEW_FIND_WRAP
= 0x0001,
74 wxWEB_VIEW_FIND_ENTIRE_WORD
= 0x0002,
75 wxWEB_VIEW_FIND_MATCH_CASE
= 0x0004,
76 wxWEB_VIEW_FIND_HIGHLIGHT_RESULT
= 0x0008,
77 wxWEB_VIEW_FIND_BACKWARDS
= 0x0010,
78 wxWEB_VIEW_FIND_DEFAULT
= 0
83 wxWEB_VIEW_BACKEND_DEFAULT
,
84 wxWEB_VIEW_BACKEND_WEBKIT
,
88 //Base class for custom scheme handlers
89 class WXDLLIMPEXP_WEBVIEW wxWebViewHandler
92 wxWebViewHandler(const wxString
& scheme
) : m_scheme(scheme
) {}
93 virtual ~wxWebViewHandler() {}
94 virtual wxString
GetName() const { return m_scheme
; }
95 virtual wxFSFile
* GetFile(const wxString
&uri
) = 0;
100 extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewNameStr
[];
101 extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewDefaultURLStr
[];
103 class WXDLLIMPEXP_WEBVIEW wxWebView
: public wxControl
106 virtual ~wxWebView() {}
108 virtual bool Create(wxWindow
* parent
,
110 const wxString
& url
= wxWebViewDefaultURLStr
,
111 const wxPoint
& pos
= wxDefaultPosition
,
112 const wxSize
& size
= wxDefaultSize
,
114 const wxString
& name
= wxWebViewNameStr
) = 0;
116 static wxWebView
* New(wxWebViewBackend backend
= wxWEB_VIEW_BACKEND_DEFAULT
);
117 static wxWebView
* New(wxWindow
* parent
,
119 const wxString
& url
= wxWebViewDefaultURLStr
,
120 const wxPoint
& pos
= wxDefaultPosition
,
121 const wxSize
& size
= wxDefaultSize
,
122 wxWebViewBackend backend
= wxWEB_VIEW_BACKEND_DEFAULT
,
124 const wxString
& name
= wxWebViewNameStr
);
127 virtual wxString
GetCurrentTitle() const = 0;
128 virtual wxString
GetCurrentURL() const = 0;
129 // TODO: handle choosing a frame when calling GetPageSource()?
130 virtual wxString
GetPageSource() const = 0;
131 virtual wxString
GetPageText() const = 0;
132 virtual bool IsBusy() const = 0;
133 virtual bool IsEditable() const = 0;
134 virtual void LoadURL(const wxString
& url
) = 0;
135 virtual void Print() = 0;
136 virtual void RegisterHandler(wxSharedPtr
<wxWebViewHandler
> handler
) = 0;
137 virtual void Reload(wxWebViewReloadFlags flags
= wxWEB_VIEW_RELOAD_DEFAULT
) = 0;
138 virtual void RunScript(const wxString
& javascript
) = 0;
139 virtual void SetEditable(bool enable
= true) = 0;
140 void SetPage(const wxString
& html
, const wxString
& baseUrl
)
142 DoSetPage(html
, baseUrl
);
144 void SetPage(wxInputStream
& html
, wxString baseUrl
)
146 wxStringOutputStream stream
;
148 DoSetPage(stream
.GetString(), baseUrl
);
150 virtual void Stop() = 0;
153 virtual bool CanGoBack() const = 0;
154 virtual bool CanGoForward() const = 0;
155 virtual void GoBack() = 0;
156 virtual void GoForward() = 0;
157 virtual void ClearHistory() = 0;
158 virtual void EnableHistory(bool enable
= true) = 0;
159 virtual wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > GetBackwardHistory() = 0;
160 virtual wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > GetForwardHistory() = 0;
161 virtual void LoadHistoryItem(wxSharedPtr
<wxWebViewHistoryItem
> item
) = 0;
164 virtual bool CanSetZoomType(wxWebViewZoomType type
) const = 0;
165 virtual wxWebViewZoom
GetZoom() const = 0;
166 virtual wxWebViewZoomType
GetZoomType() const = 0;
167 virtual void SetZoom(wxWebViewZoom zoom
) = 0;
168 virtual void SetZoomType(wxWebViewZoomType zoomType
) = 0;
171 virtual void SelectAll() = 0;
172 virtual bool HasSelection() const = 0;
173 virtual void DeleteSelection() = 0;
174 virtual wxString
GetSelectedText() const = 0;
175 virtual wxString
GetSelectedSource() const = 0;
176 virtual void ClearSelection() = 0;
178 //Clipboard functions
179 virtual bool CanCut() const = 0;
180 virtual bool CanCopy() const = 0;
181 virtual bool CanPaste() const = 0;
182 virtual void Cut() = 0;
183 virtual void Copy() = 0;
184 virtual void Paste() = 0;
186 //Undo / redo functionality
187 virtual bool CanUndo() const = 0;
188 virtual bool CanRedo() const = 0;
189 virtual void Undo() = 0;
190 virtual void Redo() = 0;
192 //Get the pointer to the underlying native engine.
193 virtual void* GetNativeBackend() const = 0;
195 virtual long Find(const wxString
& text
, int flags
= wxWEB_VIEW_FIND_DEFAULT
) = 0;
198 virtual void DoSetPage(const wxString
& html
, const wxString
& baseUrl
) = 0;
200 wxDECLARE_ABSTRACT_CLASS(wxWebView
);
203 class WXDLLIMPEXP_WEBVIEW wxWebViewEvent
: public wxNotifyEvent
207 wxWebViewEvent(wxEventType type
, int id
, const wxString url
,
208 const wxString target
)
209 : wxNotifyEvent(type
, id
), m_url(url
), m_target(target
)
213 const wxString
& GetURL() const { return m_url
; }
214 const wxString
& GetTarget() const { return m_target
; }
216 virtual wxEvent
* Clone() const { return new wxWebViewEvent(*this); }
221 wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxWebViewEvent
);
224 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW
, wxEVT_COMMAND_WEB_VIEW_NAVIGATING
, wxWebViewEvent
);
225 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW
, wxEVT_COMMAND_WEB_VIEW_NAVIGATED
, wxWebViewEvent
);
226 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW
, wxEVT_COMMAND_WEB_VIEW_LOADED
, wxWebViewEvent
);
227 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW
, wxEVT_COMMAND_WEB_VIEW_ERROR
, wxWebViewEvent
);
228 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW
, wxEVT_COMMAND_WEB_VIEW_NEWWINDOW
, wxWebViewEvent
);
229 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW
, wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED
, wxWebViewEvent
);
231 typedef void (wxEvtHandler::*wxWebViewEventFunction
)
234 #define wxWebViewEventHandler(func) \
235 wxEVENT_HANDLER_CAST(wxWebViewEventFunction, func)
237 #define EVT_WEB_VIEW_NAVIGATING(id, fn) \
238 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NAVIGATING, id, \
239 wxWebViewEventHandler(fn))
241 #define EVT_WEB_VIEW_NAVIGATED(id, fn) \
242 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NAVIGATED, id, \
243 wxWebViewEventHandler(fn))
245 #define EVT_WEB_VIEW_LOADED(id, fn) \
246 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_LOADED, id, \
247 wxWebViewEventHandler(fn))
249 #define EVT_WEB_VIEW_ERROR(id, fn) \
250 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_ERROR, id, \
251 wxWebViewEventHandler(fn))
253 #define EVT_WEB_VIEW_NEWWINDOW(id, fn) \
254 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, id, \
255 wxWebViewEventHandler(fn))
257 #define EVT_WEB_VIEW_TITLE_CHANGED(id, fn) \
258 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED, id, \
259 wxWebViewEventHandler(fn))
261 #endif // wxUSE_WEBVIEW
263 #endif // _WX_WEB_VIEW_H_