From f32989a3e71ee665f084f2f3887969d57fef335a Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 5 May 2020 22:42:21 +0200 Subject: [PATCH] LibWeb: Add hook when context menu is requested by right-clicking link --- Libraries/LibWeb/HtmlView.cpp | 15 ++++++++++----- Libraries/LibWeb/HtmlView.h | 1 + 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Libraries/LibWeb/HtmlView.cpp b/Libraries/LibWeb/HtmlView.cpp index afd468b862c..9808b73878b 100644 --- a/Libraries/LibWeb/HtmlView.cpp +++ b/Libraries/LibWeb/HtmlView.cpp @@ -234,11 +234,16 @@ void HtmlView::mousedown_event(GUI::MouseEvent& event) if (RefPtr link = node->enclosing_link_element()) { dbg() << "HtmlView: clicking on a link to " << link->href(); - if (link->href().starts_with("javascript:")) { - run_javascript_url(link->href()); - } else { - if (on_link_click) - on_link_click(link->href(), link->target(), event.modifiers()); + if (event.button() == GUI::MouseButton::Left) { + if (link->href().starts_with("javascript:")) { + run_javascript_url(link->href()); + } else { + if (on_link_click) + on_link_click(link->href(), link->target(), event.modifiers()); + } + } else if (event.button() == GUI::MouseButton::Right) { + if (on_link_context_menu_request) + on_link_context_menu_request(link->href(), event.position().translated(screen_relative_rect().location())); } } else { if (event.button() == GUI::MouseButton::Left) { diff --git a/Libraries/LibWeb/HtmlView.h b/Libraries/LibWeb/HtmlView.h index 7c6c37bdad1..6c47830bda7 100644 --- a/Libraries/LibWeb/HtmlView.h +++ b/Libraries/LibWeb/HtmlView.h @@ -58,6 +58,7 @@ public: void set_should_show_line_box_borders(bool value) { m_should_show_line_box_borders = value; } Function on_link_click; + Function on_link_context_menu_request; Function on_link_hover; Function on_title_change; Function on_load_start;