-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathwebview_chromium3.h
266 lines (212 loc) · 9.32 KB
/
webview_chromium3.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/////////////////////////////////////////////////////////////////////////////
// Author: Steven Lamerton
// Copyright: (c) 2013 Steven Lamerton
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_WEBVIEWCHROMIUM3_H_
#define _WX_WEBVIEWCHROMIUM3_H_
#if CEF_API == 3
#include <wx/control.h>
#include <wx/webview.h>
#include <wx/sharedptr.h>
#include <wx/vector.h>
#include <wx/webview.h>
#include <wx/timer.h>
#ifdef __VISUALC__
#pragma warning(push)
#pragma warning(disable:4100)
#endif
#include <include/cef_browser.h>
#include <include/cef_client.h>
#ifdef __VISUALC__
#pragma warning(pop)
#endif
extern const char wxWebViewBackendChromium[];
class wxWebViewChromium;
// ClientHandler implementation.
class ClientHandler : public CefClient,
public CefContextMenuHandler,
public CefDisplayHandler,
public CefLifeSpanHandler,
public CefLoadHandler
{
public:
ClientHandler() {};
virtual ~ClientHandler() {};
virtual CefRefPtr<CefContextMenuHandler> GetContextMenuHandler() { return this; }
virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() { return this; }
virtual CefRefPtr<CefLoadHandler> GetLoadHandler() { return this; }
virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() { return this; }
// CefDisplayHandler methods
virtual void OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
bool isLoading, bool canGoBack,
bool canGoForward);
virtual void OnAddressChange(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& url);
virtual void OnTitleChange(CefRefPtr<CefBrowser> browser,
const CefString& title);
virtual bool OnConsoleMessage(CefRefPtr<CefBrowser> browser,
const CefString& message,
const CefString& source,
int line);
// CefContextMenuHandler methods
virtual void OnBeforeContextMenu(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefContextMenuParams> params,
CefRefPtr<CefMenuModel> model);
virtual bool OnContextMenuCommand(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefContextMenuParams> params,
int command_id,
CefContextMenuHandler::EventFlags event_flags);
virtual void OnContextMenuDismissed(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame);
// CefLifeSpanHandler methods
virtual bool OnBeforePopup(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& target_url,
const CefString& target_frame_name,
const CefPopupFeatures& popupFeatures,
CefWindowInfo& windowInfo,
CefRefPtr<CefClient>& client,
CefBrowserSettings& settings,
bool* no_javascript_access);
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser);
virtual bool DoClose(CefRefPtr<CefBrowser> browser);
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser);
// CefLoadHandler methods
virtual void OnLoadStart(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame);
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int httpStatusCode);
virtual void OnLoadError(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
ErrorCode errorCode,
const CefString& errorText,
const CefString& failedUrl);
CefRefPtr<CefBrowser> GetBrowser() { return m_browser; }
void SetWebView(wxWebViewChromium *webview) { m_webview = webview; }
private:
CefRefPtr<CefBrowser> m_browser;
wxWebViewChromium *m_webview;
int m_browserId;
IMPLEMENT_REFCOUNTING(ClientHandler);
};
class WXDLLIMPEXP_WEBVIEW wxWebViewChromium : public wxWebView
{
public:
wxWebViewChromium() {}
wxWebViewChromium(wxWindow* parent,
wxWindowID id,
const wxString& url = wxWebViewDefaultURLStr,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxWebViewNameStr)
{
Create(parent, id, url, pos, size, style, name);
}
~wxWebViewChromium();
void OnSize(wxSizeEvent &event);
void SetPageSource(const wxString& pageSource);
void SetPageText(const wxString& pageText);
bool Create(wxWindow* parent,
wxWindowID id,
const wxString& url = wxWebViewDefaultURLStr,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxWebViewNameStr);
virtual void LoadURL(const wxString& url);
virtual void LoadHistoryItem(wxSharedPtr<wxWebViewHistoryItem> item);
virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetBackwardHistory();
virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetForwardHistory();
virtual bool CanGoForward() const;
virtual bool CanGoBack() const;
virtual void GoBack();
virtual void GoForward();
virtual void ClearHistory();
virtual void EnableHistory(bool enable = true);
virtual void Stop();
virtual void Reload(wxWebViewReloadFlags flags = wxWEBVIEW_RELOAD_DEFAULT);
virtual wxString GetPageSource() const;
virtual wxString GetPageText() const;
virtual bool IsBusy() const;
virtual wxString GetCurrentURL() const;
virtual wxString GetCurrentTitle() const;
virtual void SetZoomType(wxWebViewZoomType type);
virtual wxWebViewZoomType GetZoomType() const;
virtual bool CanSetZoomType(wxWebViewZoomType type) const;
virtual void Print();
virtual wxWebViewZoom GetZoom() const;
virtual void SetZoom(wxWebViewZoom zoom);
virtual void* GetNativeBackend() const;
virtual long Find(const wxString& text, int flags = wxWEBVIEW_FIND_DEFAULT) { return wxNOT_FOUND; }
//Clipboard functions
virtual bool CanCut() const { return true; }
virtual bool CanCopy() const { return true; }
virtual bool CanPaste() const { return true; }
virtual void Cut();
virtual void Copy();
virtual void Paste();
//Undo / redo functionality
virtual bool CanUndo() const { return true; }
virtual bool CanRedo() const { return true; }
virtual void Undo();
virtual void Redo();
//Editing functions
virtual void SetEditable(bool enable = true);
virtual bool IsEditable() const { return false; }
//Selection
virtual void SelectAll();
virtual bool HasSelection() const { return false; }
virtual void DeleteSelection();
virtual wxString GetSelectedText() const { return ""; }
virtual wxString GetSelectedSource() const { return ""; }
virtual void ClearSelection();
virtual void RunScript(const wxString& javascript);
//Virtual Filesystem Support
virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler);
static bool StartUp(int &code, const wxString &path = "");
// If using a separate subprocess then return the result of this function
static int StartUpSubprocess();
static void Shutdown();
protected:
virtual void DoSetPage(const wxString& html, const wxString& baseUrl);
private:
//History related variables, we currently use our own implementation
wxVector<wxSharedPtr<wxWebViewHistoryItem> > m_historyList;
int m_historyPosition;
bool m_historyLoadingFromList;
bool m_historyEnabled;
//We need to store the title and zoom ourselves
wxString m_title;
wxWebViewZoom m_zoomLevel;
//The timer calls the CEF event loop
wxTimer *m_timer;
// Current main frame page source
wxString m_pageSource;
// The text of the current page
wxString m_pageText;
//We also friend ClientHandler so it can access the history
friend class ClientHandler;
CefRefPtr<ClientHandler> m_clientHandler;
wxDECLARE_DYNAMIC_CLASS(wxWebViewChromium);
};
class WXDLLIMPEXP_WEBVIEW wxWebViewFactoryChromium : public wxWebViewFactory
{
public:
virtual wxWebView* Create() { return new wxWebViewChromium; }
virtual wxWebView* Create(wxWindow* parent,
wxWindowID id,
const wxString& url = wxWebViewDefaultURLStr,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxWebViewNameStr)
{ return new wxWebViewChromium(parent, id, url, pos, size, style, name); }
};
#endif
#endif // _WX_WEBVIEWCHROMIUM3_H_