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
9 // Copyright: (c) Jethro Grassie / Kevin Ollivier / Marianne Gagnon
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
18 #if wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT && (defined(__WXOSX_COCOA__) \
19 || defined(__WXOSX_CARBON__))
21 #include "wx/control.h"
22 #include "wx/webview.h"
24 #include "wx/osx/core/objcid.h"
26 // ----------------------------------------------------------------------------
28 // ----------------------------------------------------------------------------
30 class WXDLLIMPEXP_WEBVIEW wxWebViewWebKit
: public wxWebView
33 wxDECLARE_DYNAMIC_CLASS(wxWebViewWebKit
);
36 wxWebViewWebKit(wxWindow
*parent
,
37 wxWindowID winID
= wxID_ANY
,
38 const wxString
& strURL
= wxWebViewDefaultURLStr
,
39 const wxPoint
& pos
= wxDefaultPosition
,
40 const wxSize
& size
= wxDefaultSize
, long style
= 0,
41 const wxString
& name
= wxWebViewNameStr
)
43 Create(parent
, winID
, strURL
, pos
, size
, style
, name
);
45 bool Create(wxWindow
*parent
,
46 wxWindowID winID
= wxID_ANY
,
47 const wxString
& strURL
= wxWebViewDefaultURLStr
,
48 const wxPoint
& pos
= wxDefaultPosition
,
49 const wxSize
& size
= wxDefaultSize
, long style
= 0,
50 const wxString
& name
= wxWebViewNameStr
);
51 virtual ~wxWebViewWebKit();
53 virtual bool CanGoBack() const;
54 virtual bool CanGoForward() const;
55 virtual void GoBack();
56 virtual void GoForward();
57 virtual void Reload(wxWebViewReloadFlags flags
= wxWEB_VIEW_RELOAD_DEFAULT
);
59 virtual wxString
GetPageSource() const;
60 virtual wxString
GetPageText() const;
64 virtual void LoadURL(const wxString
& url
);
65 virtual wxString
GetCurrentURL() const;
66 virtual wxString
GetCurrentTitle() const;
67 virtual wxWebViewZoom
GetZoom() const;
68 virtual void SetZoom(wxWebViewZoom zoom
);
70 virtual void SetZoomType(wxWebViewZoomType zoomType
);
71 virtual wxWebViewZoomType
GetZoomType() const;
72 virtual bool CanSetZoomType(wxWebViewZoomType type
) const;
74 virtual bool IsBusy() const { return m_busy
; }
77 virtual void ClearHistory();
78 virtual void EnableHistory(bool enable
= true);
79 virtual wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > GetBackwardHistory();
80 virtual wxVector
<wxSharedPtr
<wxWebViewHistoryItem
> > GetForwardHistory();
81 virtual void LoadHistoryItem(wxSharedPtr
<wxWebViewHistoryItem
> item
);
83 //Undo / redo functionality
84 virtual bool CanUndo() const;
85 virtual bool CanRedo() const;
90 virtual long Find(const wxString
& text
, int flags
= wxWEB_VIEW_FIND_DEFAULT
)
98 virtual bool CanCut() const { return true; }
99 virtual bool CanCopy() const { return true; }
100 virtual bool CanPaste() const { return true; }
103 virtual void Paste();
106 virtual void SetEditable(bool enable
= true);
107 virtual bool IsEditable() const;
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();
117 void RunScript(const wxString
& javascript
);
119 //Virtual Filesystem Support
120 virtual void RegisterHandler(wxSharedPtr
<wxWebViewHandler
> handler
);
122 virtual void* GetNativeBackend() const { return m_webView
; }
124 // ---- methods not from the parent (common) interface
125 bool CanGetPageSource() const;
127 void SetScrollPos(int pos
);
130 bool CanIncreaseTextSize() const;
131 void IncreaseTextSize();
132 bool CanDecreaseTextSize() const;
133 void DecreaseTextSize();
135 float GetWebkitZoom() const;
136 void SetWebkitZoom(float zoom
);
138 // don't hide base class virtuals
139 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= true )
140 { return wxControl::SetScrollPos(orient
, pos
, refresh
); }
141 virtual int GetScrollPos( int orient
) const
142 { return wxControl::GetScrollPos(orient
); }
144 //we need to resize the webview when the control size changes
145 void OnSize(wxSizeEvent
&event
);
146 void OnMove(wxMoveEvent
&event
);
147 void OnMouseEvents(wxMouseEvent
&event
);
152 virtual void DoSetPage(const wxString
& html
, const wxString
& baseUrl
);
154 DECLARE_EVENT_TABLE()
155 void MacVisibilityChanged();
159 wxWindowID m_windowID
;
160 wxString m_pageTitle
;
164 // we may use this later to setup our own mouse events,
165 // so leave it in for now.
166 void* m_webKitCtrlEventHandler
;
167 //It should be WebView*, but WebView is an Objective-C class
168 //TODO: look into using DECLARE_WXCOCOA_OBJC_CLASS rather than this.
171 class WXDLLIMPEXP_WEBVIEW wxWebViewFactoryWebKit
: public wxWebViewFactory
174 virtual wxWebView
* Create() { return new wxWebViewWebKit
; }
175 virtual wxWebView
* Create(wxWindow
* parent
,
177 const wxString
& url
= wxWebViewDefaultURLStr
,
178 const wxPoint
& pos
= wxDefaultPosition
,
179 const wxSize
& size
= wxDefaultSize
,
181 const wxString
& name
= wxWebViewNameStr
)
182 { return new wxWebViewWebKit(parent
, id
, url
, pos
, size
, style
, name
); }
185 #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT
187 #endif // _WX_WEBKIT_H_