1 ///////////////////////////////////////////////////////////////////////////// 2 // Name: include/wx/osx/webkit.h 3 // Purpose: wxWebViewWebKit - embeddable web kit control, 4 // OS X implementation of web view component 5 // Author: Jethro Grassie / Kevin Ollivier / Marianne Gagnon 6 // Modified by: 7 // Created: 2004-4-16 8 // Copyright: (c) Jethro Grassie / Kevin Ollivier / Marianne Gagnon 9 // Licence: wxWindows licence 10 ///////////////////////////////////////////////////////////////////////////// 11 12 #ifndef _WX_WEBKIT_H 13 #define _WX_WEBKIT_H 14 15 #include "wx/defs.h" 16 17 #if wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT && defined(__WXOSX__) 18 19 #include "wx/control.h" 20 #include "wx/webview.h" 21 22 #include "wx/osx/core/objcid.h" 23 24 // ---------------------------------------------------------------------------- 25 // Web Kit Control 26 // ---------------------------------------------------------------------------- 27 28 WX_DECLARE_STRING_HASH_MAP(wxSharedPtr<wxWebViewHandler>, wxStringToWebHandlerMap); 29 30 class WXDLLIMPEXP_WEBVIEW wxWebViewWebKit : public wxWebView 31 { 32 public: 33 wxDECLARE_DYNAMIC_CLASS(wxWebViewWebKit); 34 wxWebViewWebKit()35 wxWebViewWebKit() {} 36 wxWebViewWebKit(wxWindow *parent, 37 wxWindowID winID = wxID_ANY, 38 const wxString& strURL = wxASCII_STR(wxWebViewDefaultURLStr), 39 const wxPoint& pos = wxDefaultPosition, 40 const wxSize& size = wxDefaultSize, long style = 0, 41 const wxString& name = wxASCII_STR(wxWebViewNameStr)) 42 { 43 Create(parent, winID, strURL, pos, size, style, name); 44 } 45 bool Create(wxWindow *parent, 46 wxWindowID winID = wxID_ANY, 47 const wxString& strURL = wxASCII_STR(wxWebViewDefaultURLStr), 48 const wxPoint& pos = wxDefaultPosition, 49 const wxSize& size = wxDefaultSize, long style = 0, 50 const wxString& name = wxASCII_STR(wxWebViewNameStr)) wxOVERRIDE; 51 virtual ~wxWebViewWebKit(); 52 53 virtual bool CanGoBack() const wxOVERRIDE; 54 virtual bool CanGoForward() const wxOVERRIDE; 55 virtual void GoBack() wxOVERRIDE; 56 virtual void GoForward() wxOVERRIDE; 57 virtual void Reload(wxWebViewReloadFlags flags = wxWEBVIEW_RELOAD_DEFAULT) wxOVERRIDE; 58 virtual void Stop() wxOVERRIDE; 59 60 virtual void Print() wxOVERRIDE; 61 62 virtual void LoadURL(const wxString& url) wxOVERRIDE; 63 virtual wxString GetCurrentURL() const wxOVERRIDE; 64 virtual wxString GetCurrentTitle() const wxOVERRIDE; 65 virtual float GetZoomFactor() const wxOVERRIDE; 66 virtual void SetZoomFactor(float zoom) wxOVERRIDE; 67 68 virtual void SetZoomType(wxWebViewZoomType zoomType) wxOVERRIDE; 69 virtual wxWebViewZoomType GetZoomType() const wxOVERRIDE; 70 virtual bool CanSetZoomType(wxWebViewZoomType type) const wxOVERRIDE; 71 72 virtual bool IsBusy() const wxOVERRIDE; 73 74 virtual bool IsAccessToDevToolsEnabled() const wxOVERRIDE; 75 virtual void EnableAccessToDevTools(bool enable = true) wxOVERRIDE; 76 virtual bool SetUserAgent(const wxString& userAgent) wxOVERRIDE; 77 78 //History functions 79 virtual void ClearHistory() wxOVERRIDE; 80 virtual void EnableHistory(bool enable = true) wxOVERRIDE; 81 virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetBackwardHistory() wxOVERRIDE; 82 virtual wxVector<wxSharedPtr<wxWebViewHistoryItem> > GetForwardHistory() wxOVERRIDE; 83 virtual void LoadHistoryItem(wxSharedPtr<wxWebViewHistoryItem> item) wxOVERRIDE; 84 85 virtual void Paste() wxOVERRIDE; 86 87 //Undo / redo functionality 88 virtual bool CanUndo() const wxOVERRIDE; 89 virtual bool CanRedo() const wxOVERRIDE; 90 virtual void Undo() wxOVERRIDE; 91 virtual void Redo() wxOVERRIDE; 92 93 //Editing functions 94 virtual void SetEditable(bool enable = true) wxOVERRIDE; 95 virtual bool IsEditable() const wxOVERRIDE; 96 97 bool RunScript(const wxString& javascript, wxString* output = NULL) const wxOVERRIDE; 98 virtual bool AddScriptMessageHandler(const wxString& name) wxOVERRIDE; 99 virtual bool RemoveScriptMessageHandler(const wxString& name) wxOVERRIDE; 100 virtual bool AddUserScript(const wxString& javascript, 101 wxWebViewUserScriptInjectionTime injectionTime = wxWEBVIEW_INJECT_AT_DOCUMENT_START) wxOVERRIDE; 102 virtual void RemoveAllUserScripts() wxOVERRIDE; 103 104 //Virtual Filesystem Support 105 virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler) wxOVERRIDE; 106 GetNativeBackend()107 virtual void* GetNativeBackend() const wxOVERRIDE { return m_webView; } 108 109 protected: 110 virtual void DoSetPage(const wxString& html, const wxString& baseUrl) wxOVERRIDE; 111 112 wxDECLARE_EVENT_TABLE(); 113 114 private: 115 OSXWebViewPtr m_webView; 116 wxStringToWebHandlerMap m_handlers; 117 wxString m_customUserAgent; 118 119 WX_NSObject m_navigationDelegate; 120 WX_NSObject m_UIDelegate; 121 122 bool RunScriptSync(const wxString& javascript, wxString* output = NULL) const; 123 }; 124 125 class WXDLLIMPEXP_WEBVIEW wxWebViewFactoryWebKit : public wxWebViewFactory 126 { 127 public: Create()128 virtual wxWebView* Create() wxOVERRIDE { return new wxWebViewWebKit; } 129 virtual wxWebView* Create(wxWindow* parent, 130 wxWindowID id, 131 const wxString& url = wxWebViewDefaultURLStr, 132 const wxPoint& pos = wxDefaultPosition, 133 const wxSize& size = wxDefaultSize, 134 long style = 0, 135 const wxString& name = wxASCII_STR(wxWebViewNameStr)) wxOVERRIDE 136 { return new wxWebViewWebKit(parent, id, url, pos, size, style, name); } 137 virtual wxVersionInfo GetVersionInfo() wxOVERRIDE; 138 }; 139 140 #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT 141 142 #endif // _WX_WEBKIT_H_ 143