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
17 #include "webkit/webkit.h"
18 #include "wx/sharedptr.h"
19 #include "wx/webview.h"
21 //A set of hash function so we can map wxWebHistoryItems to WebKitWebHistoryItems
27 unsigned long operator()( const wxSharedPtr
<wxWebHistoryItem
> & item
) const
30 return wxPointerHash()(item
.get());
32 SharedPtrHash
& operator=(const SharedPtrHash
&) { return *this; }
39 bool operator()( const wxSharedPtr
<wxWebHistoryItem
> & a
,
40 const wxSharedPtr
<wxWebHistoryItem
> & b
) const
42 return wxPointerEqual()(a
.get(), b
.get());
45 SharedPtrEqual
& operator=(const SharedPtrEqual
&) { return *this; }
48 WX_DECLARE_HASH_MAP(wxSharedPtr
<wxWebHistoryItem
>, WebKitWebHistoryItem
*,
49 SharedPtrHash
, SharedPtrEqual
, HistoryItemHash
);
51 //-----------------------------------------------------------------------------
53 //-----------------------------------------------------------------------------
55 class WXDLLIMPEXP_WEB wxWebViewWebKit
: public wxWebView
58 wxWebViewWebKit() { Init(); }
60 wxWebViewWebKit(wxWindow
*parent
,
61 wxWindowID id
= wxID_ANY
,
62 const wxString
& url
= wxWebViewDefaultURLStr
,
63 const wxPoint
& pos
= wxDefaultPosition
,
64 const wxSize
& size
= wxDefaultSize
, long style
= 0,
65 const wxString
& name
= wxWebViewNameStr
)
69 Create(parent
, id
, url
, pos
, size
, style
, name
);
72 virtual bool Create(wxWindow
*parent
,
73 wxWindowID id
= wxID_ANY
,
74 const wxString
& url
= wxWebViewDefaultURLStr
,
75 const wxPoint
& pos
= wxDefaultPosition
,
76 const wxSize
& size
= wxDefaultSize
, long style
= 0,
77 const wxString
& name
= wxWebViewNameStr
);
79 virtual bool Enable( bool enable
= true );
84 static wxVisualAttributes
85 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
87 // helper to allow access to protected member from GTK callback
88 void MoveWindow(int x
, int y
, int width
, int height
)
90 DoMoveWindow(x
, y
, width
, height
);
95 void SetWebkitZoom(float level
);
96 float GetWebkitZoom();
99 virtual void LoadUrl(const wxString
& url
);
100 virtual void GoBack();
101 virtual void GoForward();
102 virtual void Reload(wxWebViewReloadFlags flags
= wxWEB_VIEW_RELOAD_DEFAULT
);
103 virtual bool CanGoBack();
104 virtual bool CanGoForward();
105 virtual void ClearHistory();
106 virtual void EnableHistory(bool enable
= true);
107 virtual wxVector
<wxSharedPtr
<wxWebHistoryItem
> > GetBackwardHistory();
108 virtual wxVector
<wxSharedPtr
<wxWebHistoryItem
> > GetForwardHistory();
109 virtual void LoadHistoryItem(wxSharedPtr
<wxWebHistoryItem
> item
);
110 virtual wxString
GetCurrentURL();
111 virtual wxString
GetCurrentTitle();
112 virtual wxString
GetPageSource();
113 virtual void SetPage(const wxString
& html
, const wxString
& baseUrl
);
114 virtual void Print();
115 virtual bool IsBusy();
117 void SetZoomType(wxWebViewZoomType
);
118 wxWebViewZoomType
GetZoomType() const;
119 bool CanSetZoomType(wxWebViewZoomType
) const;
120 virtual wxWebViewZoom
GetZoom();
121 virtual void SetZoom(wxWebViewZoom
);
123 //Clipboard functions
124 virtual bool CanCut();
125 virtual bool CanCopy();
126 virtual bool CanPaste();
129 virtual void Paste();
131 //Undo / redo functionality
132 virtual bool CanUndo();
133 virtual bool CanRedo();
137 /** FIXME: hack to work around signals being received too early */
141 /** TODO: check if this can be made private
142 * The native control has a getter to check for busy state, but except in
143 * very recent versions of webkit this getter doesn't say everything we need
144 * (namely it seems to stay indefinitely busy when loading is cancelled by
151 virtual GdkWindow
*GTKGetWindow(wxArrayGdkWindows
& windows
) const;
155 // focus event handler: calls GTKUpdateBitmap()
156 void GTKOnFocus(wxFocusEvent
& event
);
160 HistoryItemHash m_historyMap
;
162 // FIXME: try to get DECLARE_DYNAMIC_CLASS macros & stuff right
163 //DECLARE_DYNAMIC_CLASS(wxWebViewWebKit)
166 #endif // if wxHAVE_WEB_BACKEND_GTK_WEBKIT