Add basic history api and implement it under gtk.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/SOC2011_WEBVIEW@68108 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Steve Lamerton
2011-06-30 10:03:25 +00:00
parent 9a00d07834
commit 152a58083f
6 changed files with 66 additions and 0 deletions

View File

@@ -70,6 +70,8 @@ public:
virtual void Reload(wxWebViewReloadFlags flags = wxWEB_VIEW_RELOAD_DEFAULT); virtual void Reload(wxWebViewReloadFlags flags = wxWEB_VIEW_RELOAD_DEFAULT);
virtual bool CanGoBack(); virtual bool CanGoBack();
virtual bool CanGoForward(); virtual bool CanGoForward();
virtual void ClearHistory();
virtual void EnableHistory(bool enable = true);
virtual wxString GetCurrentURL(); virtual wxString GetCurrentURL();
virtual wxString GetCurrentTitle(); virtual wxString GetCurrentTitle();
virtual wxString GetPageSource(); virtual wxString GetPageSource();
@@ -107,6 +109,7 @@ private:
void GTKOnFocus(wxFocusEvent& event); void GTKOnFocus(wxFocusEvent& event);
GtkWidget *web_view; GtkWidget *web_view;
gint m_historyLimit;
// FIXME: try to get DECLARE_DYNAMIC_CLASS macros & stuff right // FIXME: try to get DECLARE_DYNAMIC_CLASS macros & stuff right
//DECLARE_DYNAMIC_CLASS(wxWebViewWebKit) //DECLARE_DYNAMIC_CLASS(wxWebViewWebKit)

View File

@@ -50,6 +50,8 @@ public:
virtual bool CanGoBack() { return m_canNavigateBack; } virtual bool CanGoBack() { return m_canNavigateBack; }
virtual void GoBack(); virtual void GoBack();
virtual void GoForward(); virtual void GoForward();
virtual void ClearHistory() {};
virtual void EnableHistory(bool enable = true) {};
virtual void Stop(); virtual void Stop();
virtual void Reload(wxWebViewReloadFlags flags = wxWEB_VIEW_RELOAD_DEFAULT); virtual void Reload(wxWebViewReloadFlags flags = wxWEB_VIEW_RELOAD_DEFAULT);

View File

@@ -173,6 +173,9 @@ public:
*/ */
virtual void LoadUrl(const wxString& url) = 0; virtual void LoadUrl(const wxString& url) = 0;
virtual void ClearHistory() = 0;
virtual void EnableHistory(bool enable = true) = 0;
/** /**
* Stop the current page loading process, if any. * Stop the current page loading process, if any.
* May trigger an error event of type wxWEB_NAV_ERR_USER_CANCELLED. * May trigger an error event of type wxWEB_NAV_ERR_USER_CANCELLED.

View File

@@ -199,6 +199,16 @@ public:
*/ */
virtual void GoForward() = 0; virtual void GoForward() = 0;
/**
Clear the history, this will also remove the visible page.
*/
virtual void ClearHistory() = 0;
/**
Enable or disable the history. This will also clear the history.
*/
virtual void EnableHistory(bool enable = true) = 0;
/** /**
Load a HTMl document (web page) from a URL Load a HTMl document (web page) from a URL
@param url the URL where the HTML document to display can be found @param url the URL where the HTML document to display can be found

View File

@@ -60,6 +60,8 @@ public:
void OnForward(wxCommandEvent& evt); void OnForward(wxCommandEvent& evt);
void OnStop(wxCommandEvent& evt); void OnStop(wxCommandEvent& evt);
void OnReload(wxCommandEvent& evt); void OnReload(wxCommandEvent& evt);
void OnClearHistory(wxCommandEvent& evt);
void OnEnableHistory(wxCommandEvent& evt);
void OnNavigationRequest(wxWebNavigationEvent& evt); void OnNavigationRequest(wxWebNavigationEvent& evt);
void OnNavigationComplete(wxWebNavigationEvent& evt); void OnNavigationComplete(wxWebNavigationEvent& evt);
void OnDocumentLoaded(wxWebNavigationEvent& evt); void OnDocumentLoaded(wxWebNavigationEvent& evt);
@@ -89,6 +91,7 @@ private:
wxMenuItem* m_tools_largest; wxMenuItem* m_tools_largest;
wxMenuItem* m_tools_handle_navigation; wxMenuItem* m_tools_handle_navigation;
wxMenuItem* m_tools_handle_new_window; wxMenuItem* m_tools_handle_new_window;
wxMenuItem* m_tools_enable_history;
wxTimer* m_timer; wxTimer* m_timer;
int m_animation_angle; int m_animation_angle;
@@ -188,10 +191,14 @@ WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample")
m_tools_menu->AppendSeparator(); m_tools_menu->AppendSeparator();
m_tools_handle_navigation = m_tools_menu->AppendCheckItem(wxID_ANY, _("Handle Navigation")); m_tools_handle_navigation = m_tools_menu->AppendCheckItem(wxID_ANY, _("Handle Navigation"));
m_tools_handle_new_window = m_tools_menu->AppendCheckItem(wxID_ANY, _("Handle New Windows")); m_tools_handle_new_window = m_tools_menu->AppendCheckItem(wxID_ANY, _("Handle New Windows"));
m_tools_menu->AppendSeparator();
wxMenuItem* clearhist = m_tools_menu->Append(wxID_ANY, _("Clear History"));
m_tools_enable_history = m_tools_menu->AppendCheckItem(wxID_ANY, _("Enable History"));
//By default we want to handle navigation and new windows //By default we want to handle navigation and new windows
m_tools_handle_navigation->Check(); m_tools_handle_navigation->Check();
m_tools_handle_new_window->Check(); m_tools_handle_new_window->Check();
m_tools_enable_history->Check();
// Connect the toolbar events // Connect the toolbar events
@@ -236,6 +243,10 @@ WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample")
wxCommandEventHandler(WebFrame::OnSetZoom), NULL, this ); wxCommandEventHandler(WebFrame::OnSetZoom), NULL, this );
Connect(m_tools_largest->GetId(), wxEVT_COMMAND_MENU_SELECTED, Connect(m_tools_largest->GetId(), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(WebFrame::OnSetZoom), NULL, this ); wxCommandEventHandler(WebFrame::OnSetZoom), NULL, this );
Connect(clearhist->GetId(), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(WebFrame::OnClearHistory), NULL, this );
Connect(m_tools_enable_history->GetId(), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(WebFrame::OnEnableHistory), NULL, this );
} }
void WebFrame::OnAnimationTimer(wxTimerEvent& evt) void WebFrame::OnAnimationTimer(wxTimerEvent& evt)
@@ -348,6 +359,18 @@ void WebFrame::OnReload(wxCommandEvent& evt)
UpdateState(); UpdateState();
} }
void WebFrame::OnClearHistory(wxCommandEvent& evt)
{
m_browser->ClearHistory();
UpdateState();
}
void WebFrame::OnEnableHistory(wxCommandEvent& evt)
{
m_browser->EnableHistory(m_tools_enable_history->IsChecked());
UpdateState();
}
/** /**
* Callback invoked when there is a request to load a new page (for instance * Callback invoked when there is a request to load a new page (for instance
* when the user clicks a link) * when the user clicks a link)

View File

@@ -323,6 +323,11 @@ bool wxWebViewWebKit::Create(wxWindow *parent,
/* Open a webpage */ /* Open a webpage */
webkit_web_view_load_uri (WEBKIT_WEB_VIEW (web_view), url); webkit_web_view_load_uri (WEBKIT_WEB_VIEW (web_view), url);
//Get the initial history limit so we can enable and disable it later
WebKitWebBackForwardList* history;
history = webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view));
m_historyLimit = webkit_web_back_forward_list_get_limit(history);
m_ready = true; m_ready = true;
return true; return true;
@@ -413,6 +418,26 @@ bool wxWebViewWebKit::CanGoForward()
return webkit_web_view_can_go_forward (WEBKIT_WEB_VIEW(web_view)); return webkit_web_view_can_go_forward (WEBKIT_WEB_VIEW(web_view));
} }
void wxWebViewWebKit::ClearHistory()
{
WebKitWebBackForwardList* history;
history = webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view));
webkit_web_back_forward_list_clear(history);
}
void wxWebViewWebKit::EnableHistory(bool enable)
{
WebKitWebBackForwardList* history;
history = webkit_web_view_get_back_forward_list(WEBKIT_WEB_VIEW(web_view));
if(enable)
{
webkit_web_back_forward_list_set_limit(history, m_historyLimit);
}
else
{
webkit_web_back_forward_list_set_limit(history, 0);
}
}
wxString wxWebViewWebKit::GetCurrentURL() wxString wxWebViewWebKit::GetCurrentURL()
{ {