Skip to content

Commit

Permalink
LibWeb: Fire auxclick event on middle click
Browse files Browse the repository at this point in the history
Previously, no event was fired on middle click. This change also allows
the UI to open a link in a new tab on middle click.
  • Loading branch information
tcl3 committed Jun 21, 2024
1 parent ad5c738 commit 7db3cd0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions Tests/LibWeb/Text/expected/UIEvents/auxevent.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
auxclick event fired
22 changes: 22 additions & 0 deletions Tests/LibWeb/Text/input/UIEvents/auxevent.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<style>
body {
margin: 0px;
padding: 5px;
width: 200px;
height: 200px;
}
</style>
<script src="../include.js"></script>
<script>
asyncTest(done => {
document.body.onauxclick = () => {
println("auxclick event fired");
done();
};

window.onload = () => {
internals.middleClick(10, 10);
};
});
</script>
2 changes: 2 additions & 0 deletions Userland/Libraries/LibWeb/Page/EventHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ bool EventHandler::handle_mouseup(CSSPixelPoint viewport_position, CSSPixelPoint
if (node.ptr() == m_mousedown_target) {
if (button == UIEvents::MouseButton::Primary) {
run_activation_behavior = node->dispatch_event(UIEvents::MouseEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::click, screen_position, page_offset, client_offset, offset, {}, 1, button, modifiers).release_value_but_fixme_should_propagate_errors());
} else if (button == UIEvents::MouseButton::Middle) {
run_activation_behavior = node->dispatch_event(UIEvents::MouseEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::auxclick, screen_position, page_offset, client_offset, offset, {}, 1, button, modifiers).release_value_but_fixme_should_propagate_errors());
} else if (button == UIEvents::MouseButton::Secondary) {
// Allow the user to bypass custom context menus by holding shift, like Firefox.
if ((modifiers & UIEvents::Mod_Shift) == 0)
Expand Down

0 comments on commit 7db3cd0

Please sign in to comment.