mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-25 15:39:55 +00:00
LibGUI: Add hook when a context menu is requested on a tab
This commit is contained in:
parent
ff98f55b85
commit
bf2e6325a4
Notes:
sideshowbarker
2024-07-19 06:16:28 +09:00
Author: https://github.com/FalseHonesty Commit: https://github.com/SerenityOS/serenity/commit/bf2e6325a43 Pull-request: https://github.com/SerenityOS/serenity/pull/2291 Reviewed-by: https://github.com/awesomekling
2 changed files with 17 additions and 0 deletions
|
@ -370,4 +370,19 @@ void TabWidget::keydown_event(KeyEvent& event)
|
|||
Widget::keydown_event(event);
|
||||
}
|
||||
|
||||
void TabWidget::context_menu_event(ContextMenuEvent& context_menu_event)
|
||||
{
|
||||
for (size_t i = 0; i < m_tabs.size(); ++i) {
|
||||
auto button_rect = this->button_rect(i);
|
||||
if (!button_rect.contains(context_menu_event.position()))
|
||||
continue;
|
||||
auto* widget = m_tabs[i].widget;
|
||||
deferred_invoke([this, widget, context_menu_event](auto&) {
|
||||
if (on_context_menu_request && widget)
|
||||
on_context_menu_request(*widget, context_menu_event);
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -84,6 +84,7 @@ public:
|
|||
|
||||
Function<void(Widget&)> on_change;
|
||||
Function<void(Widget&)> on_middle_click;
|
||||
Function<void(Widget&, const ContextMenuEvent&)> on_context_menu_request;
|
||||
|
||||
protected:
|
||||
TabWidget();
|
||||
|
@ -95,6 +96,7 @@ protected:
|
|||
virtual void mousemove_event(MouseEvent&) override;
|
||||
virtual void leave_event(Core::Event&) override;
|
||||
virtual void keydown_event(KeyEvent&) override;
|
||||
virtual void context_menu_event(ContextMenuEvent&) override;
|
||||
|
||||
private:
|
||||
Gfx::Rect child_rect_for_size(const Gfx::Size&) const;
|
||||
|
|
Loading…
Reference in a new issue