diff --git a/Userland/Applications/Browser/History.cpp b/Userland/Applications/Browser/History.cpp index da960f8432..9a2484ea70 100644 --- a/Userland/Applications/Browser/History.cpp +++ b/Userland/Applications/Browser/History.cpp @@ -34,16 +34,16 @@ URL History::current() const return m_items[m_current]; } -void History::go_back() +void History::go_back(int steps) { - VERIFY(can_go_back()); - m_current--; + VERIFY(can_go_back(steps)); + m_current -= steps; } -void History::go_forward() +void History::go_forward(int steps) { - VERIFY(can_go_forward()); - m_current++; + VERIFY(can_go_forward(steps)); + m_current += steps; } void History::clear() @@ -52,4 +52,22 @@ void History::clear() m_current = -1; } +const Vector History::get_back_history() +{ + Vector back_history; + for (int i = m_current - 1; i >= 0; i--) { + back_history.append(m_items[i]); + } + return back_history; +} + +const Vector History::get_forward_history() +{ + Vector forward_history; + for (int i = m_current + 1; i < static_cast(m_items.size()); i++) { + forward_history.append(m_items[i]); + } + return forward_history; +} + } diff --git a/Userland/Applications/Browser/History.h b/Userland/Applications/Browser/History.h index 55b0b4935f..ac91a84a5b 100644 --- a/Userland/Applications/Browser/History.h +++ b/Userland/Applications/Browser/History.h @@ -17,13 +17,14 @@ public: void push(const URL&); URL current() const; + const Vector get_back_history(); + const Vector get_forward_history(); - void go_back(); - void go_forward(); - - bool can_go_back() { return m_current > 0; } - bool can_go_forward() { return m_current + 1 < static_cast(m_items.size()); } + void go_back(int steps = 1); + void go_forward(int steps = 1); + bool can_go_back(int steps = 1) { return (m_current - steps) >= 0; } + bool can_go_forward(int steps = 1) { return (m_current + steps) < static_cast(m_items.size()); } void clear(); private: diff --git a/Userland/Applications/Browser/Tab.cpp b/Userland/Applications/Browser/Tab.cpp index 7573132c40..373e756ace 100644 --- a/Userland/Applications/Browser/Tab.cpp +++ b/Userland/Applications/Browser/Tab.cpp @@ -92,8 +92,36 @@ Tab::Tab(BrowserWindow& window, Type type) else m_web_content_view = webview_container.add(); - toolbar.add_action(window.go_back_action()); - toolbar.add_action(window.go_forward_action()); + auto& go_back_button = toolbar.add_action(window.go_back_action()); + go_back_button.on_context_menu_request = [this](auto& context_menu_event) { + if (!m_history.can_go_back()) + return; + int i = 0; + m_go_back_context_menu = GUI::Menu::construct(); + for (auto& url : m_history.get_back_history()) { + i++; + m_go_back_context_menu->add_action(GUI::Action::create(url.to_string(), + Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-html.png"), + [this, i](auto&) { go_back(i); })); + } + m_go_back_context_menu->popup(context_menu_event.screen_position()); + }; + + auto& go_forward_button = toolbar.add_action(window.go_forward_action()); + go_forward_button.on_context_menu_request = [this](auto& context_menu_event) { + if (!m_history.can_go_forward()) + return; + int i = 0; + m_go_forward_context_menu = GUI::Menu::construct(); + for (auto& url : m_history.get_forward_history()) { + i++; + m_go_forward_context_menu->add_action(GUI::Action::create(url.to_string(), + Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-html.png"), + [this, i](auto&) { go_forward(i); })); + } + m_go_forward_context_menu->popup(context_menu_event.screen_position()); + }; + toolbar.add_action(window.go_home_action()); toolbar.add_action(window.reload_action()); @@ -315,16 +343,16 @@ void Tab::reload() load(url()); } -void Tab::go_back() +void Tab::go_back(int steps) { - m_history.go_back(); + m_history.go_back(steps); update_actions(); load(m_history.current(), LoadType::HistoryNavigation); } -void Tab::go_forward() +void Tab::go_forward(int steps) { - m_history.go_forward(); + m_history.go_forward(steps); update_actions(); load(m_history.current(), LoadType::HistoryNavigation); } diff --git a/Userland/Applications/Browser/Tab.h b/Userland/Applications/Browser/Tab.h index bd9246a37a..6561145a91 100644 --- a/Userland/Applications/Browser/Tab.h +++ b/Userland/Applications/Browser/Tab.h @@ -46,8 +46,8 @@ public: void load(const URL&, LoadType = LoadType::Normal); void reload(); - void go_back(); - void go_forward(); + void go_back(int steps = 1); + void go_forward(int steps = 1); void did_become_active(); void context_menu_requested(const Gfx::IntPoint& screen_position); @@ -104,7 +104,8 @@ private: RefPtr m_tab_context_menu; RefPtr m_page_context_menu; - + RefPtr m_go_back_context_menu; + RefPtr m_go_forward_context_menu; String m_title; RefPtr m_icon;