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 = 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 = wxWebViewNameStr); 51 52 virtual ~wxWebViewWebKit(); 53 54 virtual bool Enable( bool enable = true ); 55 56 // implementation 57 // -------------- 58 59 static wxVisualAttributes 60 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); 61 62 virtual void Stop(); 63 virtual void LoadURL(const wxString& url); 64 virtual void GoBack(); 65 virtual void GoForward(); 66 virtual void Reload(wxWebViewReloadFlags flags = wxWEBVIEW_RELOAD_DEFAULT); 67 virtual bool CanGoBack() const; 68 virtual bool CanGoForward() const; 69 virtual void ClearHistory(); 70 virtual void EnableContextMenu(bool enable = true); 71 virtual void EnableHistory(bool enable = true); 72 virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetBackwardHistory(); 73 virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetForwardHistory(); 74 virtual void LoadHistoryItem(wxSharedPtr<wxWebViewHistoryItem> item); 75 virtual wxString GetCurrentURL() const; 76 virtual wxString GetCurrentTitle() const; 77 virtual wxString GetPageSource() const; 78 virtual wxString GetPageText() const; 79 virtual void Print(); 80 virtual bool IsBusy() const; 81 82 void SetZoomType(wxWebViewZoomType); 83 wxWebViewZoomType GetZoomType() const; 84 bool CanSetZoomType(wxWebViewZoomType) const; 85 virtual wxWebViewZoom GetZoom() const; 86 virtual void SetZoom(wxWebViewZoom); 87 88 //Clipboard functions 89 virtual bool CanCut() const; 90 virtual bool CanCopy() const; 91 virtual bool CanPaste() const; 92 virtual void Cut(); 93 virtual void Copy(); 94 virtual void Paste(); 95 96 //Undo / redo functionality 97 virtual bool CanUndo() const; 98 virtual bool CanRedo() const; 99 virtual void Undo(); 100 virtual void Redo(); 101 102 //Find function 103 virtual long Find(const wxString& text, int flags = wxWEBVIEW_FIND_DEFAULT); 104 105 //Editing functions 106 virtual void SetEditable(bool enable = true); 107 virtual bool IsEditable() const; 108 109 //Selection 110 virtual void DeleteSelection(); 111 virtual bool HasSelection() const; 112 virtual void SelectAll(); 113 virtual wxString GetSelectedText() const; 114 virtual wxString GetSelectedSource() const; 115 virtual void ClearSelection(); 116 117 virtual void RunScript(const wxString& javascript); 118 119 //Virtual Filesystem Support 120 virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler); GetHandlers()121 virtual wxVector<wxSharedPtr<wxWebViewHandler> > GetHandlers() { return m_handlerList; } 122 GetNativeBackend()123 virtual void* GetNativeBackend() const { return m_web_view; } 124 125 /** TODO: check if this can be made private 126 * The native control has a getter to check for busy state, but except in 127 * very recent versions of webkit this getter doesn't say everything we need 128 * (namely it seems to stay indefinitely busy when loading is cancelled by 129 * user) 130 */ 131 bool m_busy; 132 133 wxString m_vfsurl; 134 135 //We use this flag to stop recursion when we load a page from the navigation 136 //callback, mainly when loading a VFS page 137 bool m_guard; 138 //This flag is use to indicate when a navigation event is the result of a 139 //create-web-view signal and so we need to send a new window event 140 bool m_creating; 141 142 protected: 143 virtual void DoSetPage(const wxString& html, const wxString& baseUrl); 144 145 virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const; 146 147 private: 148 149 void ZoomIn(); 150 void ZoomOut(); 151 void SetWebkitZoom(float level); 152 float GetWebkitZoom() const; 153 154 //Find helper function 155 void FindClear(); 156 157 // focus event handler: calls GTKUpdateBitmap() 158 void GTKOnFocus(wxFocusEvent& event); 159 160 #if wxUSE_WEBVIEW_WEBKIT2 161 bool CanExecuteEditingCommand(const gchar* command) const; 162 void SetupWebExtensionServer(); 163 #endif 164 165 WebKitWebView *m_web_view; 166 int m_historyLimit; 167 168 wxVector<wxSharedPtr<wxWebViewHandler> > m_handlerList; 169 170 //variables used for Find() 171 int m_findFlags; 172 wxString m_findText; 173 int m_findPosition; 174 int m_findCount; 175 176 #if wxUSE_WEBVIEW_WEBKIT2 177 //Used for webkit2 extension 178 GDBusServer *m_dbusServer; 179 GDBusProxy *m_extension; 180 #endif 181 182 wxDECLARE_DYNAMIC_CLASS(wxWebViewWebKit); 183 }; 184 185 class WXDLLIMPEXP_WEBVIEW wxWebViewFactoryWebKit : public wxWebViewFactory 186 { 187 public: Create()188 virtual wxWebView* Create() { return new wxWebViewWebKit; } 189 virtual wxWebView* Create(wxWindow* parent, 190 wxWindowID id, 191 const wxString& url = wxWebViewDefaultURLStr, 192 const wxPoint& pos = wxDefaultPosition, 193 const wxSize& size = wxDefaultSize, 194 long style = 0, 195 const wxString& name = wxWebViewNameStr) 196 { return new wxWebViewWebKit(parent, id, url, pos, size, style, name); } 197 }; 198 199 200 #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT && defined(__WXGTK__) 201 202 #endif 203