Skip to content

Commit af1c26f

Browse files
Baitinqlinusg
authored andcommitted
Browser: Go back/forward when pressing back/forward mouse buttons
This currently doesn't work when running Serenity through QEMU, as it doesn't pass the side button events over to Serenity due to some bug or missing feature.
1 parent 2f3ebce commit af1c26f

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

Userland/Applications/Browser/Tab.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,16 @@ Tab::Tab(BrowserWindow& window)
445445
load(url);
446446
};
447447

448+
view().on_back_button = [this] {
449+
if (m_history.can_go_back())
450+
go_back();
451+
};
452+
453+
view().on_forward_button = [this] {
454+
if (m_history.can_go_forward())
455+
go_forward();
456+
};
457+
448458
m_tab_context_menu = GUI::Menu::construct();
449459
m_tab_context_menu->add_action(GUI::CommonActions::make_reload_action([this](auto&) {
450460
reload();

Userland/Libraries/LibWebView/OutOfProcessWebView.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ void OutOfProcessWebView::mousedown_event(GUI::MouseEvent& event)
174174
void OutOfProcessWebView::mouseup_event(GUI::MouseEvent& event)
175175
{
176176
enqueue_input_event(event);
177+
178+
if (event.button() == GUI::MouseButton::Backward && on_back_button) {
179+
on_back_button();
180+
} else if (event.button() == GUI::MouseButton::Forward && on_forward_button) {
181+
on_forward_button();
182+
}
177183
}
178184

179185
void OutOfProcessWebView::mousemove_event(GUI::MouseEvent& event)

Userland/Libraries/LibWebView/OutOfProcessWebView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ class OutOfProcessWebView final
111111
Function<Gfx::IntRect()> on_maximize_window;
112112
Function<Gfx::IntRect()> on_minimize_window;
113113
Function<Gfx::IntRect()> on_fullscreen_window;
114+
Function<void()> on_back_button;
115+
Function<void()> on_forward_button;
114116

115117
private:
116118
OutOfProcessWebView();

0 commit comments

Comments
 (0)