From 152a58083fbe9ad9ff15f41472e0a2fdf9f73fb3 Mon Sep 17 00:00:00 2001 From: Steve Lamerton Date: Thu, 30 Jun 2011 10:03:25 +0000 Subject: [PATCH] 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 --- include/wx/gtk/webview_webkit.h | 3 +++ include/wx/msw/webview_ie.h | 2 ++ include/wx/webview.h | 3 +++ interface/wx/webview.h | 10 ++++++++++ samples/web/web.cpp | 23 +++++++++++++++++++++++ src/gtk/webview_webkit.cpp | 25 +++++++++++++++++++++++++ 6 files changed, 66 insertions(+) diff --git a/include/wx/gtk/webview_webkit.h b/include/wx/gtk/webview_webkit.h index 04364f913d..dfd6f2877e 100644 --- a/include/wx/gtk/webview_webkit.h +++ b/include/wx/gtk/webview_webkit.h @@ -70,6 +70,8 @@ public: virtual void Reload(wxWebViewReloadFlags flags = wxWEB_VIEW_RELOAD_DEFAULT); virtual bool CanGoBack(); virtual bool CanGoForward(); + virtual void ClearHistory(); + virtual void EnableHistory(bool enable = true); virtual wxString GetCurrentURL(); virtual wxString GetCurrentTitle(); virtual wxString GetPageSource(); @@ -107,6 +109,7 @@ private: void GTKOnFocus(wxFocusEvent& event); GtkWidget *web_view; + gint m_historyLimit; // FIXME: try to get DECLARE_DYNAMIC_CLASS macros & stuff right //DECLARE_DYNAMIC_CLASS(wxWebViewWebKit) diff --git a/include/wx/msw/webview_ie.h b/include/wx/msw/webview_ie.h index 23cf573ce6..216df27b93 100644 --- a/include/wx/msw/webview_ie.h +++ b/include/wx/msw/webview_ie.h @@ -50,6 +50,8 @@ public: virtual bool CanGoBack() { return m_canNavigateBack; } virtual void GoBack(); virtual void GoForward(); + virtual void ClearHistory() {}; + virtual void EnableHistory(bool enable = true) {}; virtual void Stop(); virtual void Reload(wxWebViewReloadFlags flags = wxWEB_VIEW_RELOAD_DEFAULT); diff --git a/include/wx/webview.h b/include/wx/webview.h index f689e05caf..53317c3421 100644 --- a/include/wx/webview.h +++ b/include/wx/webview.h @@ -173,6 +173,9 @@ public: */ 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. * May trigger an error event of type wxWEB_NAV_ERR_USER_CANCELLED. diff --git a/interface/wx/webview.h b/interface/wx/webview.h index f93f42d452..fafba64940 100644 --- a/interface/wx/webview.h +++ b/interface/wx/webview.h @@ -199,6 +199,16 @@ public: */ 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 @param url the URL where the HTML document to display can be found diff --git a/samples/web/web.cpp b/samples/web/web.cpp index 71ecf356da..cd2fa488fa 100644 --- a/samples/web/web.cpp +++ b/samples/web/web.cpp @@ -60,6 +60,8 @@ public: void OnForward(wxCommandEvent& evt); void OnStop(wxCommandEvent& evt); void OnReload(wxCommandEvent& evt); + void OnClearHistory(wxCommandEvent& evt); + void OnEnableHistory(wxCommandEvent& evt); void OnNavigationRequest(wxWebNavigationEvent& evt); void OnNavigationComplete(wxWebNavigationEvent& evt); void OnDocumentLoaded(wxWebNavigationEvent& evt); @@ -89,6 +91,7 @@ private: wxMenuItem* m_tools_largest; wxMenuItem* m_tools_handle_navigation; wxMenuItem* m_tools_handle_new_window; + wxMenuItem* m_tools_enable_history; wxTimer* m_timer; int m_animation_angle; @@ -188,10 +191,14 @@ WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample") m_tools_menu->AppendSeparator(); 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_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 m_tools_handle_navigation->Check(); m_tools_handle_new_window->Check(); + m_tools_enable_history->Check(); // Connect the toolbar events @@ -236,6 +243,10 @@ WebFrame::WebFrame() : wxFrame(NULL, wxID_ANY, "wxWebView Sample") wxCommandEventHandler(WebFrame::OnSetZoom), NULL, this ); Connect(m_tools_largest->GetId(), wxEVT_COMMAND_MENU_SELECTED, 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) @@ -348,6 +359,18 @@ void WebFrame::OnReload(wxCommandEvent& evt) 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 * when the user clicks a link) diff --git a/src/gtk/webview_webkit.cpp b/src/gtk/webview_webkit.cpp index 3f4c7c69bd..4c79cfb81c 100644 --- a/src/gtk/webview_webkit.cpp +++ b/src/gtk/webview_webkit.cpp @@ -323,6 +323,11 @@ bool wxWebViewWebKit::Create(wxWindow *parent, /* Open a webpage */ 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; return true; @@ -413,6 +418,26 @@ bool wxWebViewWebKit::CanGoForward() 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() { -- 2.47.2