1 ///////////////////////////////////////////////////////////////////////////// 2 // Name: include/gtk/wx/webview.h 3 // Purpose: GTK webkit backend for web view component 4 // Author: Robert Roebling, Marianne Gagnon 5 // Copyright: (c) 2010 Marianne Gagnon, 1998 Robert Roebling 6 // Licence: wxWindows licence 7 ///////////////////////////////////////////////////////////////////////////// 8 9 #ifndef _WX_GTK_WEBKITCTRL_H_ 10 #define _WX_GTK_WEBKITCTRL_H_ 11 12 #include "wx/defs.h" 13 14 // NOTE: this header is used for both the WebKit1 and WebKit2 implementations 15 #if wxUSE_WEBVIEW && (wxUSE_WEBVIEW_WEBKIT || wxUSE_WEBVIEW_WEBKIT2) && defined(__WXGTK__) 16 17 #include "wx/sharedptr.h" 18 #include "wx/webview.h" 19 #if wxUSE_WEBVIEW_WEBKIT2 20 #include <glib.h> 21 #include <gio/gio.h> 22 #endif 23 24 typedef struct _WebKitWebView WebKitWebView; 25 26 //----------------------------------------------------------------------------- 27 // wxWebViewWebKit 28 //----------------------------------------------------------------------------- 29 30 class WXDLLIMPEXP_WEBVIEW wxWebViewWebKit : public wxWebView 31 { 32 public: 33 wxWebViewWebKit(); 34 35 wxWebViewWebKit(wxWindow *parent, 36 wxWindowID id = wxID_ANY, 37 const wxString& url = wxWebViewDefaultURLStr, 38 const wxPoint& pos = wxDefaultPosition, 39 const wxSize& size = wxDefaultSize, long style = 0, 40 const wxString& name = wxASCII_STR(wxWebViewNameStr)) 41 { 42 Create(parent, id, url, pos, size, style, name); 43 } 44 45 virtual bool Create(wxWindow *parent, 46 wxWindowID id = wxID_ANY, 47 const wxString& url = wxWebViewDefaultURLStr, 48 const wxPoint& pos = wxDefaultPosition, 49 const wxSize& size = wxDefaultSize, long style = 0, 50 const wxString& name = wxASCII_STR(wxWebViewNameStr)) wxOVERRIDE; 51 52 virtual ~wxWebViewWebKit(); 53 54 virtual bool Enable( bool enable = true ) wxOVERRIDE; 55 56 // implementation 57 // -------------- 58 59 static wxVisualAttributes 60 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); 61 62 virtual void Stop() wxOVERRIDE; 63 virtual void LoadURL(const wxString& url) wxOVERRIDE; 64 virtual void GoBack() wxOVERRIDE; 65 virtual void GoForward() wxOVERRIDE; 66 virtual void Reload(wxWebViewReloadFlags flags = wxWEBVIEW_RELOAD_DEFAULT) wxOVERRIDE; 67 virtual bool CanGoBack() const wxOVERRIDE; 68 virtual bool CanGoForward() const wxOVERRIDE; 69 virtual void ClearHistory() wxOVERRIDE; 70 virtual void EnableContextMenu(bool enable = true) wxOVERRIDE; 71 virtual void EnableHistory(bool enable = true) wxOVERRIDE; 72 virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetBackwardHistory() wxOVERRIDE; 73 virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetForwardHistory() wxOVERRIDE; 74 virtual void LoadHistoryItem(wxSharedPtr<wxWebViewHistoryItem> item) wxOVERRIDE; 75 virtual wxString GetCurrentURL() const wxOVERRIDE; 76 virtual wxString GetCurrentTitle() const wxOVERRIDE; 77 virtual wxString GetPageSource() const wxOVERRIDE; 78 virtual wxString GetPageText() const wxOVERRIDE; 79 virtual void Print() wxOVERRIDE; 80 virtual bool IsBusy() const wxOVERRIDE; 81 #if wxUSE_WEBVIEW_WEBKIT2 82 virtual void EnableAccessToDevTools(bool enable = true) wxOVERRIDE; 83 virtual bool IsAccessToDevToolsEnabled() const wxOVERRIDE; 84 virtual bool SetUserAgent(const wxString& userAgent) wxOVERRIDE; 85 #endif 86 87 void SetZoomType(wxWebViewZoomType) wxOVERRIDE; 88 wxWebViewZoomType GetZoomType() const wxOVERRIDE; 89 bool CanSetZoomType(wxWebViewZoomType) const wxOVERRIDE; 90 virtual float GetZoomFactor() const wxOVERRIDE; 91 virtual void SetZoomFactor(float) wxOVERRIDE; 92 93 //Clipboard functions 94 virtual bool CanCut() const wxOVERRIDE; 95 virtual bool CanCopy() const wxOVERRIDE; 96 virtual bool CanPaste() const wxOVERRIDE; 97 virtual void Cut() wxOVERRIDE; 98 virtual void Copy() wxOVERRIDE; 99 virtual void Paste() wxOVERRIDE; 100 101 //Undo / redo functionality 102 virtual bool CanUndo() const wxOVERRIDE; 103 virtual bool CanRedo() const wxOVERRIDE; 104 virtual void Undo() wxOVERRIDE; 105 virtual void Redo() wxOVERRIDE; 106 107 //Find function 108 virtual long Find(const wxString& text, int flags = wxWEBVIEW_FIND_DEFAULT) wxOVERRIDE; 109 110 //Editing functions 111 virtual void SetEditable(bool enable = true) wxOVERRIDE; 112 virtual bool IsEditable() const wxOVERRIDE; 113 114 //Selection 115 virtual void DeleteSelection() wxOVERRIDE; 116 virtual bool HasSelection() const wxOVERRIDE; 117 virtual void SelectAll() wxOVERRIDE; 118 virtual wxString GetSelectedText() const wxOVERRIDE; 119 virtual wxString GetSelectedSource() const wxOVERRIDE; 120 virtual void ClearSelection() wxOVERRIDE; 121 122 virtual bool RunScript(const wxString& javascript, wxString* output = NULL) const wxOVERRIDE; 123 #if wxUSE_WEBVIEW_WEBKIT2 124 virtual bool AddScriptMessageHandler(const wxString& name) wxOVERRIDE; 125 virtual bool RemoveScriptMessageHandler(const wxString& name) wxOVERRIDE; 126 virtual bool AddUserScript(const wxString& javascript, 127 wxWebViewUserScriptInjectionTime injectionTime = wxWEBVIEW_INJECT_AT_DOCUMENT_START) wxOVERRIDE; 128 virtual void RemoveAllUserScripts() wxOVERRIDE; 129 #endif 130 131 //Virtual Filesystem Support 132 virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler) wxOVERRIDE; GetHandlers()133 virtual wxVector<wxSharedPtr<wxWebViewHandler> > GetHandlers() { return m_handlerList; } 134 GetNativeBackend()135 virtual void* GetNativeBackend() const wxOVERRIDE { return m_web_view; } 136 137 /** TODO: check if this can be made private 138 * The native control has a getter to check for busy state, but except in 139 * very recent versions of webkit this getter doesn't say everything we need 140 * (namely it seems to stay indefinitely busy when loading is cancelled by 141 * user) 142 */ 143 bool m_busy; 144 145 wxString m_vfsurl; 146 147 //We use this flag to stop recursion when we load a page from the navigation 148 //callback, mainly when loading a VFS page 149 bool m_guard; 150 //This flag is use to indicate when a navigation event is the result of a 151 //create-web-view signal and so we need to send a new window event 152 bool m_creating; 153 154 protected: 155 virtual void DoSetPage(const wxString& html, const wxString& baseUrl) wxOVERRIDE; 156 157 virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const wxOVERRIDE; 158 159 private: 160 161 void ZoomIn(); 162 void ZoomOut(); 163 void SetWebkitZoom(float level); 164 float GetWebkitZoom() const; 165 166 //Find helper function 167 void FindClear(); 168 169 // focus event handler: calls GTKUpdateBitmap() 170 void GTKOnFocus(wxFocusEvent& event); 171 172 #if wxUSE_WEBVIEW_WEBKIT2 173 bool CanExecuteEditingCommand(const gchar* command) const; 174 void SetupWebExtensionServer(); 175 GDBusProxy *GetExtensionProxy() const; 176 bool RunScriptSync(const wxString& javascript, wxString* output = NULL) const; 177 #endif 178 179 WebKitWebView *m_web_view; 180 wxString m_customUserAgent; 181 int m_historyLimit; 182 183 wxVector<wxSharedPtr<wxWebViewHandler> > m_handlerList; 184 185 //variables used for Find() 186 int m_findFlags; 187 wxString m_findText; 188 int m_findPosition; 189 int m_findCount; 190 191 #if wxUSE_WEBVIEW_WEBKIT2 192 //Used for webkit2 extension 193 GDBusServer *m_dbusServer; 194 GDBusProxy *m_extension; 195 #endif 196 197 wxDECLARE_DYNAMIC_CLASS(wxWebViewWebKit); 198 }; 199 200 class WXDLLIMPEXP_WEBVIEW wxWebViewFactoryWebKit : public wxWebViewFactory 201 { 202 public: Create()203 virtual wxWebView* Create() wxOVERRIDE { return new wxWebViewWebKit; } 204 virtual wxWebView* Create(wxWindow* parent, 205 wxWindowID id, 206 const wxString& url = wxWebViewDefaultURLStr, 207 const wxPoint& pos = wxDefaultPosition, 208 const wxSize& size = wxDefaultSize, 209 long style = 0, 210 const wxString& name = wxASCII_STR(wxWebViewNameStr)) wxOVERRIDE 211 { return new wxWebViewWebKit(parent, id, url, pos, size, style, name); } 212 #if wxUSE_WEBVIEW_WEBKIT2 213 virtual wxVersionInfo GetVersionInfo() wxOVERRIDE; 214 #endif 215 }; 216 217 218 #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT && defined(__WXGTK__) 219 220 #endif 221