1 /////////////////////////////////////////////////////////////////////////////
2 // Name: include/gtk/wx/webview.h
3 // Purpose: GTK webkit backend for web view component
4 // Author: Robert Roebling, Marianne Gagnon
6 // Copyright: (c) 2010 Marianne Gagnon, 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_GTK_WEBKITCTRL_H_
11 #define _WX_GTK_WEBKITCTRL_H_
15 #if wxUSE_WEBVIEW_WEBKIT && defined(__WXGTK__)
17 #include "webkit/webkit.h"
18 #include "wx/sharedptr.h"
19 #include "wx/webview.h"
21 //-----------------------------------------------------------------------------
23 //-----------------------------------------------------------------------------
25 class WXDLLIMPEXP_WEB wxWebViewWebKit
: public wxWebView
28 wxWebViewWebKit() { Init(); }
30 wxWebViewWebKit(wxWindow
*parent
,
31 wxWindowID id
= wxID_ANY
,
32 const wxString
& url
= wxWebViewDefaultURLStr
,
33 const wxPoint
& pos
= wxDefaultPosition
,
34 const wxSize
& size
= wxDefaultSize
, long style
= 0,
35 const wxString
& name
= wxWebViewNameStr
)
39 Create(parent
, id
, url
, pos
, size
, style
, name
);
42 virtual bool Create(wxWindow
*parent
,
43 wxWindowID id
= wxID_ANY
,
44 const wxString
& url
= wxWebViewDefaultURLStr
,
45 const wxPoint
& pos
= wxDefaultPosition
,
46 const wxSize
& size
= wxDefaultSize
, long style
= 0,
47 const wxString
& name
= wxWebViewNameStr
);
49 virtual bool Enable( bool enable
= true );
54 static wxVisualAttributes
55 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
57 // helper to allow access to protected member from GTK callback
58 void MoveWindow(int x
, int y
, int width
, int height
)
60 DoMoveWindow(x
, y
, width
, height
);
64 virtual void LoadUrl(const wxString
& url
);
65 virtual void GoBack();
66 virtual void GoForward();
67 virtual void Reload(wxWebViewReloadFlags flags
= wxWEB_VIEW_RELOAD_DEFAULT
);
68 virtual bool CanGoBack() const;
69 virtual bool CanGoForward() const;
70 virtual void ClearHistory();
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 //We do not want to hide the other overloads
80 using wxWebView::SetPage
;
81 virtual void SetPage(const wxString
& html
, const wxString
& baseUrl
);
83 virtual bool IsBusy() const;
85 void SetZoomType(wxWebViewZoomType
);
86 wxWebViewZoomType
GetZoomType() const;
87 bool CanSetZoomType(wxWebViewZoomType
) const;
88 virtual wxWebViewZoom
GetZoom() const;
89 virtual void SetZoom(wxWebViewZoom
);
92 virtual bool CanCut() const;
93 virtual bool CanCopy() const;
94 virtual bool CanPaste() const;
99 //Undo / redo functionality
100 virtual bool CanUndo() const;
101 virtual bool CanRedo() const;
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 virtual void RunScript(const wxString
& javascript
);
119 //Virtual Filesystem Support
120 virtual void RegisterHandler(wxSharedPtr
<wxWebViewHandler
> handler
);
121 virtual wxVector
<wxSharedPtr
<wxWebViewHandler
> > GetHandlers() { return m_handlerList
; }
123 /** FIXME: hack to work around signals being received too early */
127 /** TODO: check if this can be made private
128 * The native control has a getter to check for busy state, but except in
129 * very recent versions of webkit this getter doesn't say everything we need
130 * (namely it seems to stay indefinitely busy when loading is cancelled by
137 //We use this flag to stop recursion when we load a page from the navigation
138 //callback, mainly when loading a VFS page
143 virtual GdkWindow
*GTKGetWindow(wxArrayGdkWindows
& windows
) const;
149 void SetWebkitZoom(float level
);
150 float GetWebkitZoom() const;
152 // focus event handler: calls GTKUpdateBitmap()
153 void GTKOnFocus(wxFocusEvent
& event
);
158 wxVector
<wxSharedPtr
<wxWebViewHandler
> > m_handlerList
;
160 wxDECLARE_DYNAMIC_CLASS(wxWebViewWebKit
);
163 #endif // wxUSE_WEBVIEW_WEBKIT && defined(__WXGTK__)