Implement extended history api in gtk
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/SOC2011_WEBVIEW@68122 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
5cbda74b66
commit
19fc1a2f0d
@ -14,8 +14,40 @@
|
||||
|
||||
#if wxUSE_WEBVIEW_WEBKIT
|
||||
|
||||
#include "webkit/webkit.h"
|
||||
#include "wx/sharedptr.h"
|
||||
#include "wx/webview.h"
|
||||
|
||||
//A set of hash function so we can map wxWebHistoryItems to WebKitWebHistoryItems
|
||||
class SharedPtrHash
|
||||
{
|
||||
public:
|
||||
SharedPtrHash() { }
|
||||
|
||||
unsigned long operator()( const wxSharedPtr<wxWebHistoryItem> & item ) const
|
||||
{
|
||||
|
||||
return wxPointerHash()(item.get());
|
||||
}
|
||||
SharedPtrHash& operator=(const SharedPtrHash&) { return *this; }
|
||||
};
|
||||
|
||||
class SharedPtrEqual
|
||||
{
|
||||
public:
|
||||
SharedPtrEqual() { }
|
||||
bool operator()( const wxSharedPtr<wxWebHistoryItem> & a,
|
||||
const wxSharedPtr<wxWebHistoryItem> & b ) const
|
||||
{
|
||||
return wxPointerEqual()(a.get(), b.get());
|
||||
}
|
||||
|
||||
SharedPtrEqual& operator=(const SharedPtrEqual&) { return *this; }
|
||||
};
|
||||
|
||||
WX_DECLARE_HASH_MAP(wxSharedPtr<wxWebHistoryItem>, WebKitWebHistoryItem*,
|
||||
SharedPtrHash, SharedPtrEqual, HistoryItemHash);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxWebViewWebKit
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -72,6 +104,9 @@ public:
|
||||
virtual bool CanGoForward();
|
||||
virtual void ClearHistory();
|
||||
virtual void EnableHistory(bool enable = true);
|
||||
virtual wxVector<wxSharedPtr<wxWebHistoryItem> > GetBackwardHistory();
|
||||
virtual wxVector<wxSharedPtr<wxWebHistoryItem> > GetForwardHistory();
|
||||
virtual void LoadHistoryItem(wxSharedPtr<wxWebHistoryItem> item);
|
||||
virtual wxString GetCurrentURL();
|
||||
virtual wxString GetCurrentTitle();
|
||||
virtual wxString GetPageSource();
|
||||
@ -110,6 +145,7 @@ private:
|
||||
|
||||
GtkWidget *web_view;
|
||||
gint m_historyLimit;
|
||||
HistoryItemHash m_historyMap;
|
||||
|
||||
// FIXME: try to get DECLARE_DYNAMIC_CLASS macros & stuff right
|
||||
//DECLARE_DYNAMIC_CLASS(wxWebViewWebKit)
|
||||
|
@ -439,6 +439,56 @@ void wxWebViewWebKit::EnableHistory(bool enable)
|
||||
}
|
||||
}
|
||||
|
||||
wxVector<wxSharedPtr<wxWebHistoryItem> > wxWebViewWebKit::GetBackwardHistory()
|
||||
{
|
||||
wxVector<wxSharedPtr<wxWebHistoryItem> > backhist;
|
||||
WebKitWebBackForwardList* history;
|
||||
history = webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view));
|
||||
GList* list = webkit_web_back_forward_list_get_back_list_with_limit(history,
|
||||
m_historyLimit);
|
||||
//We need to iterate in reverse to get the order we desire
|
||||
for(int i = g_list_length(list) - 1; i >= 0 ; i--)
|
||||
{
|
||||
WebKitWebHistoryItem* gtkitem = (WebKitWebHistoryItem*)g_list_nth_data(list, i);
|
||||
wxSharedPtr<wxWebHistoryItem> item(new wxWebHistoryItem(
|
||||
webkit_web_history_item_get_uri(gtkitem),
|
||||
webkit_web_history_item_get_title(gtkitem)));
|
||||
backhist.push_back(item);
|
||||
m_historyMap[item] = gtkitem;
|
||||
}
|
||||
return backhist;
|
||||
}
|
||||
|
||||
wxVector<wxSharedPtr<wxWebHistoryItem> > wxWebViewWebKit::GetForwardHistory()
|
||||
{
|
||||
wxVector<wxSharedPtr<wxWebHistoryItem> > forwardhist;
|
||||
WebKitWebBackForwardList* history;
|
||||
history = webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view));
|
||||
GList* list = webkit_web_back_forward_list_get_forward_list_with_limit(history,
|
||||
m_historyLimit);
|
||||
for(guint i = 0; i < g_list_length(list); i++)
|
||||
{
|
||||
WebKitWebHistoryItem* gtkitem = (WebKitWebHistoryItem*)g_list_nth_data(list, i);
|
||||
wxSharedPtr<wxWebHistoryItem> item(new wxWebHistoryItem(
|
||||
webkit_web_history_item_get_uri(gtkitem),
|
||||
webkit_web_history_item_get_title(gtkitem)));
|
||||
forwardhist.push_back(item);
|
||||
m_historyMap[item] = gtkitem;
|
||||
}
|
||||
return forwardhist;
|
||||
}
|
||||
|
||||
void wxWebViewWebKit::LoadHistoryItem(wxSharedPtr<wxWebHistoryItem> item)
|
||||
{
|
||||
WebKitWebHistoryItem* gtkitem = m_historyMap[item];
|
||||
if(gtkitem)
|
||||
{
|
||||
WebKitWebBackForwardList* history;
|
||||
history = webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view));
|
||||
webkit_web_back_forward_list_go_to_item(history, gtkitem);
|
||||
}
|
||||
}
|
||||
|
||||
wxString wxWebViewWebKit::GetCurrentURL()
|
||||
{
|
||||
// FIXME: check which encoding the web kit control uses instead of
|
||||
|
Loading…
Reference in New Issue
Block a user