mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:17:34 +00:00
LibWeb: Fire the contextmenu event on right click (if not holding shift)
This now allows websites such as Discord, YouTube and your favourite "Right Click" xkcd comic to open a custom context menu when you right click. You can bypass this by holding shift, just like Firefox.
This commit is contained in:
parent
91d8665ab4
commit
e038901555
3 changed files with 22 additions and 18 deletions
|
@ -255,8 +255,11 @@ bool EventHandler::handle_mouseup(CSSPixelPoint position, unsigned button, unsig
|
||||||
handled_event = true;
|
handled_event = true;
|
||||||
|
|
||||||
bool run_activation_behavior = true;
|
bool run_activation_behavior = true;
|
||||||
if (node.ptr() == m_mousedown_target && button == GUI::MouseButton::Primary) {
|
if (node.ptr() == m_mousedown_target) {
|
||||||
run_activation_behavior = node->dispatch_event(UIEvents::MouseEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::click, offset, client_offset, page_offset, button).release_value_but_fixme_should_propagate_errors());
|
if (button == GUI::MouseButton::Primary)
|
||||||
|
run_activation_behavior = node->dispatch_event(UIEvents::MouseEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::click, offset, client_offset, page_offset, button).release_value_but_fixme_should_propagate_errors());
|
||||||
|
else if (button == GUI::MouseButton::Secondary && !(modifiers & Mod_Shift)) // Allow the user to bypass custom context menus by holding shift, like Firefox.
|
||||||
|
run_activation_behavior = node->dispatch_event(UIEvents::MouseEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::contextmenu, offset, client_offset, page_offset, button).release_value_but_fixme_should_propagate_errors());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (run_activation_behavior) {
|
if (run_activation_behavior) {
|
||||||
|
|
|
@ -14,21 +14,22 @@ namespace Web::UIEvents::EventNames {
|
||||||
|
|
||||||
// FIXME: This is not all of the events
|
// FIXME: This is not all of the events
|
||||||
|
|
||||||
#define ENUMERATE_UI_EVENTS \
|
#define ENUMERATE_UI_EVENTS \
|
||||||
__ENUMERATE_UI_EVENT(auxclick) \
|
__ENUMERATE_UI_EVENT(auxclick) \
|
||||||
__ENUMERATE_UI_EVENT(click) \
|
__ENUMERATE_UI_EVENT(click) \
|
||||||
__ENUMERATE_UI_EVENT(dblclick) \
|
__ENUMERATE_UI_EVENT(contextmenu) \
|
||||||
__ENUMERATE_UI_EVENT(keydown) \
|
__ENUMERATE_UI_EVENT(dblclick) \
|
||||||
__ENUMERATE_UI_EVENT(keypress) \
|
__ENUMERATE_UI_EVENT(keydown) \
|
||||||
__ENUMERATE_UI_EVENT(keyup) \
|
__ENUMERATE_UI_EVENT(keypress) \
|
||||||
__ENUMERATE_UI_EVENT(mousedown) \
|
__ENUMERATE_UI_EVENT(keyup) \
|
||||||
__ENUMERATE_UI_EVENT(mouseenter) \
|
__ENUMERATE_UI_EVENT(mousedown) \
|
||||||
__ENUMERATE_UI_EVENT(mouseleave) \
|
__ENUMERATE_UI_EVENT(mouseenter) \
|
||||||
__ENUMERATE_UI_EVENT(mousemove) \
|
__ENUMERATE_UI_EVENT(mouseleave) \
|
||||||
__ENUMERATE_UI_EVENT(mouseout) \
|
__ENUMERATE_UI_EVENT(mousemove) \
|
||||||
__ENUMERATE_UI_EVENT(mouseover) \
|
__ENUMERATE_UI_EVENT(mouseout) \
|
||||||
__ENUMERATE_UI_EVENT(mouseup) \
|
__ENUMERATE_UI_EVENT(mouseover) \
|
||||||
__ENUMERATE_UI_EVENT(resize) \
|
__ENUMERATE_UI_EVENT(mouseup) \
|
||||||
|
__ENUMERATE_UI_EVENT(resize) \
|
||||||
__ENUMERATE_UI_EVENT(wheel)
|
__ENUMERATE_UI_EVENT(wheel)
|
||||||
|
|
||||||
#define __ENUMERATE_UI_EVENT(name) extern FlyString name;
|
#define __ENUMERATE_UI_EVENT(name) extern FlyString name;
|
||||||
|
|
|
@ -77,7 +77,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<MouseEvent>> MouseEvent::create_from_platfo
|
||||||
|
|
||||||
void MouseEvent::set_event_characteristics()
|
void MouseEvent::set_event_characteristics()
|
||||||
{
|
{
|
||||||
if (type().is_one_of(EventNames::mousedown, EventNames::mousemove, EventNames::mouseout, EventNames::mouseover, EventNames::mouseup, HTML::EventNames::click, EventNames::dblclick)) {
|
if (type().is_one_of(EventNames::mousedown, EventNames::mousemove, EventNames::mouseout, EventNames::mouseover, EventNames::mouseup, HTML::EventNames::click, EventNames::dblclick, EventNames::contextmenu)) {
|
||||||
set_bubbles(true);
|
set_bubbles(true);
|
||||||
set_cancelable(true);
|
set_cancelable(true);
|
||||||
set_composed(true);
|
set_composed(true);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue