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
8 // Copyright: (c) Jethro Grassie / Kevin Ollivier / Marianne Gagnon
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
17 #if wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT && (defined(__WXOSX_COCOA__) \
18 || defined(__WXOSX_CARBON__))
20 #include "wx/control.h"
21 #include "wx/webview.h"
23 #include "wx/osx/core/objcid.h"
25 // ----------------------------------------------------------------------------
27 // ----------------------------------------------------------------------------
29 class WXDLLIMPEXP_WEBVIEW wxWebViewWebKit
: public wxWebView
32 wxDECLARE_DYNAMIC_CLASS(wxWebViewWebKit
);
35 wxWebViewWebKit(wxWindow
*parent
,
36 wxWindowID winID
= wxID_ANY
,
37 const wxString
& strURL
= wxWebViewDefaultURLStr
,
38 const wxPoint
& pos
= wxDefaultPosition
,
39 const wxSize
& size
= wxDefaultSize
, long style
= 0,
40 const wxString
& name
= wxWebViewNameStr
)
42 Create(parent
, winID
, strURL
, pos
, size
, style
, name
);
44 bool Create(wxWindow
*parent
,
45 wxWindowID winID
= wxID_ANY
,
46 const wxString
& strURL
= wxWebViewDefaultURLStr
,
47 const wxPoint
& pos
= wxDefaultPosition
,
48 const wxSize
& size
= wxDefaultSize
, long style
= 0,
49 const wxString
& name
= wxWebViewNameStr
);
50 virtual ~wxWebViewWebKit();
52 virtual bool CanGoBack() const;
53 virtual bool CanGoForward() const;
54 virtual void GoBack();
55 virtual void GoForward();
56 virtual void Reload(wxWebViewReloadFlags flags
= wxWEBVIEW_RELOAD_DEFAULT
);
58 virtual wxString
GetPageSource() const;
59 virtual wxString
GetPageText() const;
63 virtual void LoadURL(const wxString
& url
);
64 virtual wxString
GetCurrentURL() const;
65 virtual wxString
GetCurrentTitle() const;
66 virtual wxWebViewZoom
GetZoom() const;
67 virtual void SetZoom(wxWebViewZoom zoom
);
69 virtual void SetZoomType(wxWebViewZoomType zoomType
);
70 virtual wxWebViewZoomType
GetZoomType() const;
71 virtual bool CanSetZoomType(wxWebViewZoomType type
) const;
73 virtual bool IsBusy() const { return m_busy
; }
76 virtual void ClearHistory();
77 virtual void EnableHistory(bool enable
= true);
78 virtual wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > GetBackwardHistory();
79 virtual wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > GetForwardHistory();
80 virtual void LoadHistoryItem(wxSharedPtr
<wxWebViewHistoryItem
> item
);
82 //Undo / redo functionality
83 virtual bool CanUndo() const;
84 virtual bool CanRedo() const;
89 virtual long Find(const wxString
& text
, int flags
= wxWEBVIEW_FIND_DEFAULT
)
97 virtual bool CanCut() const { return true; }
98 virtual bool CanCopy() const { return true; }
99 virtual bool CanPaste() const { return true; }
102 virtual void Paste();
105 virtual void SetEditable(bool enable
= true);
106 virtual bool IsEditable() const;
109 virtual void DeleteSelection();
110 virtual bool HasSelection() const;
111 virtual void SelectAll();
112 virtual wxString
GetSelectedText() const;
113 virtual wxString
GetSelectedSource() const;
114 virtual void ClearSelection();
116 void RunScript(const wxString
& javascript
);
118 //Virtual Filesystem Support
119 virtual void RegisterHandler(wxSharedPtr
<wxWebViewHandler
> handler
);
121 virtual void* GetNativeBackend() const { return m_webView
; }
123 // ---- methods not from the parent (common) interface
124 bool CanGetPageSource() const;
126 void SetScrollPos(int pos
);
129 bool CanIncreaseTextSize() const;
130 void IncreaseTextSize();
131 bool CanDecreaseTextSize() const;
132 void DecreaseTextSize();
134 float GetWebkitZoom() const;
135 void SetWebkitZoom(float zoom
);
137 // don't hide base class virtuals
138 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= true )
139 { return wxControl::SetScrollPos(orient
, pos
, refresh
); }
140 virtual int GetScrollPos( int orient
) const
141 { return wxControl::GetScrollPos(orient
); }
143 //we need to resize the webview when the control size changes
144 void OnSize(wxSizeEvent
&event
);
145 void OnMove(wxMoveEvent
&event
);
146 void OnMouseEvents(wxMouseEvent
&event
);
151 virtual void DoSetPage(const wxString
& html
, const wxString
& baseUrl
);
153 DECLARE_EVENT_TABLE()
154 void MacVisibilityChanged();
158 wxWindowID m_windowID
;
159 wxString m_pageTitle
;
163 // we may use this later to setup our own mouse events,
164 // so leave it in for now.
165 void* m_webKitCtrlEventHandler
;
166 //It should be WebView*, but WebView is an Objective-C class
167 //TODO: look into using DECLARE_WXCOCOA_OBJC_CLASS rather than this.
170 class WXDLLIMPEXP_WEBVIEW wxWebViewFactoryWebKit
: public wxWebViewFactory
173 virtual wxWebView
* Create() { return new wxWebViewWebKit
; }
174 virtual wxWebView
* Create(wxWindow
* parent
,
176 const wxString
& url
= wxWebViewDefaultURLStr
,
177 const wxPoint
& pos
= wxDefaultPosition
,
178 const wxSize
& size
= wxDefaultSize
,
180 const wxString
& name
= wxWebViewNameStr
)
181 { return new wxWebViewWebKit(parent
, id
, url
, pos
, size
, style
, name
); }
184 #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT
186 #endif // _WX_WEBKIT_H_