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 #include "wx/osx/webviewhistoryitem_webkit.h"
24 #include "wx/gtk/webviewhistoryitem_webkit.h"
25 #include "wx/msw/webviewhistoryitem_ie.h"
33 wxWEB_VIEW_ZOOM_SMALL
,
34 wxWEB_VIEW_ZOOM_MEDIUM
,
35 wxWEB_VIEW_ZOOM_LARGE
,
36 wxWEB_VIEW_ZOOM_LARGEST
39 enum wxWebViewZoomType
41 //Scales entire page, including images
42 wxWEB_VIEW_ZOOM_TYPE_LAYOUT
,
43 wxWEB_VIEW_ZOOM_TYPE_TEXT
46 enum wxWebViewNavigationError
48 wxWEB_NAV_ERR_CONNECTION
,
49 wxWEB_NAV_ERR_CERTIFICATE
,
51 wxWEB_NAV_ERR_SECURITY
,
52 wxWEB_NAV_ERR_NOT_FOUND
,
53 wxWEB_NAV_ERR_REQUEST
,
54 wxWEB_NAV_ERR_USER_CANCELLED
,
58 enum wxWebViewReloadFlags
60 //Default, may access cache
61 wxWEB_VIEW_RELOAD_DEFAULT
,
62 wxWEB_VIEW_RELOAD_NO_CACHE
67 wxWEB_VIEW_BACKEND_DEFAULT
,
68 wxWEB_VIEW_BACKEND_WEBKIT
,
72 //Base class for custom scheme handlers
73 class WXDLLIMPEXP_WEBVIEW wxWebViewHandler
76 wxWebViewHandler(const wxString
& scheme
) : m_scheme(scheme
) {}
77 virtual ~wxWebViewHandler() {}
78 virtual wxString
GetName() const { return m_scheme
; }
79 virtual wxFSFile
* GetFile(const wxString
&uri
) = 0;
84 extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewNameStr
[];
85 extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewDefaultURLStr
[];
87 class WXDLLIMPEXP_WEBVIEW wxWebView
: public wxControl
90 virtual ~wxWebView() {}
92 virtual bool Create(wxWindow
* parent
,
94 const wxString
& url
= wxWebViewDefaultURLStr
,
95 const wxPoint
& pos
= wxDefaultPosition
,
96 const wxSize
& size
= wxDefaultSize
,
98 const wxString
& name
= wxWebViewNameStr
) = 0;
100 static wxWebView
* New(wxWebViewBackend backend
= wxWEB_VIEW_BACKEND_DEFAULT
);
101 static wxWebView
* New(wxWindow
* parent
,
103 const wxString
& url
= wxWebViewDefaultURLStr
,
104 const wxPoint
& pos
= wxDefaultPosition
,
105 const wxSize
& size
= wxDefaultSize
,
106 wxWebViewBackend backend
= wxWEB_VIEW_BACKEND_DEFAULT
,
108 const wxString
& name
= wxWebViewNameStr
);
111 virtual wxString
GetCurrentTitle() const = 0;
112 virtual wxString
GetCurrentURL() const = 0;
113 // TODO: handle choosing a frame when calling GetPageSource()?
114 virtual wxString
GetPageSource() const = 0;
115 virtual wxString
GetPageText() const = 0;
116 virtual bool IsBusy() const = 0;
117 virtual bool IsEditable() const = 0;
118 virtual void LoadURL(const wxString
& url
) = 0;
119 virtual void Print() = 0;
120 virtual void RegisterHandler(wxSharedPtr
<wxWebViewHandler
> handler
) = 0;
121 virtual void Reload(wxWebViewReloadFlags flags
= wxWEB_VIEW_RELOAD_DEFAULT
) = 0;
122 virtual void RunScript(const wxString
& javascript
) = 0;
123 virtual void SetEditable(bool enable
= true) = 0;
124 virtual void SetPage(const wxString
& html
, const wxString
& baseUrl
) = 0;
125 virtual void SetPage(wxInputStream
& html
, wxString baseUrl
)
127 wxStringOutputStream stream
;
129 SetPage(stream
.GetString(), baseUrl
);
131 virtual void Stop() = 0;
134 virtual bool CanGoBack() const = 0;
135 virtual bool CanGoForward() const = 0;
136 virtual void GoBack() = 0;
137 virtual void GoForward() = 0;
138 virtual void ClearHistory() = 0;
139 virtual void EnableHistory(bool enable
= true) = 0;
140 virtual wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > GetBackwardHistory() = 0;
141 virtual wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > GetForwardHistory() = 0;
142 virtual void LoadHistoryItem(wxSharedPtr
<wxWebViewHistoryItem
> item
) = 0;
145 virtual bool CanSetZoomType(wxWebViewZoomType type
) const = 0;
146 virtual wxWebViewZoom
GetZoom() const = 0;
147 virtual wxWebViewZoomType
GetZoomType() const = 0;
148 virtual void SetZoom(wxWebViewZoom zoom
) = 0;
149 virtual void SetZoomType(wxWebViewZoomType zoomType
) = 0;
152 virtual void SelectAll() = 0;
153 virtual bool HasSelection() const = 0;
154 virtual void DeleteSelection() = 0;
155 virtual wxString
GetSelectedText() const = 0;
156 virtual wxString
GetSelectedSource() const = 0;
157 virtual void ClearSelection() = 0;
159 //Clipboard functions
160 virtual bool CanCut() const = 0;
161 virtual bool CanCopy() const = 0;
162 virtual bool CanPaste() const = 0;
163 virtual void Cut() = 0;
164 virtual void Copy() = 0;
165 virtual void Paste() = 0;
167 //Undo / redo functionality
168 virtual bool CanUndo() const = 0;
169 virtual bool CanRedo() const = 0;
170 virtual void Undo() = 0;
171 virtual void Redo() = 0;
173 wxDECLARE_ABSTRACT_CLASS(wxWebView
);
176 class WXDLLIMPEXP_WEBVIEW wxWebViewEvent
: public wxNotifyEvent
180 wxWebViewEvent(wxEventType type
, int id
, const wxString url
,
181 const wxString target
)
182 : wxNotifyEvent(type
, id
), m_url(url
), m_target(target
)
186 const wxString
& GetURL() const { return m_url
; }
187 const wxString
& GetTarget() const { return m_target
; }
189 virtual wxEvent
* Clone() const { return new wxWebViewEvent(*this); }
194 wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxWebViewEvent
);
197 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW
, wxEVT_COMMAND_WEB_VIEW_NAVIGATING
, wxWebViewEvent
);
198 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW
, wxEVT_COMMAND_WEB_VIEW_NAVIGATED
, wxWebViewEvent
);
199 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW
, wxEVT_COMMAND_WEB_VIEW_LOADED
, wxWebViewEvent
);
200 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW
, wxEVT_COMMAND_WEB_VIEW_ERROR
, wxWebViewEvent
);
201 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW
, wxEVT_COMMAND_WEB_VIEW_NEWWINDOW
, wxWebViewEvent
);
202 wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_WEBVIEW
, wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED
, wxWebViewEvent
);
204 typedef void (wxEvtHandler::*wxWebViewEventFunction
)
207 #define wxWebViewEventHandler(func) \
208 wxEVENT_HANDLER_CAST(wxWebViewEventFunction, func)
210 #define EVT_WEB_VIEW_NAVIGATING(id, fn) \
211 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NAVIGATING, id, \
212 wxWebViewEventHandler(fn))
214 #define EVT_WEB_VIEW_NAVIGATED(id, fn) \
215 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NAVIGATED, id, \
216 wxWebViewEventHandler(fn))
218 #define EVT_WEB_VIEW_LOADED(id, fn) \
219 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_LOADED, id, \
220 wxWebViewEventHandler(fn))
222 #define EVT_WEB_VIEW_ERRROR(id, fn) \
223 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_ERROR, id, \
224 wxWebViewEventHandler(fn))
226 #define EVT_WEB_VIEW_NEWWINDOW(id, fn) \
227 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_NEWWINDOW, id, \
228 wxWebViewEventHandler(fn))
230 #define EVT_WEB_VIEW_TITLE_CHANGED(id, fn) \
231 wx__DECLARE_EVT1(wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED, id, \
232 wxWebViewEventHandler(fn))
234 #endif // wxUSE_WEBVIEW
236 #endif // _WX_WEB_VIEW_H_