mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2026-04-05 13:43:29 +00:00
UI/AppKit: Handle cmd+left mouse clicks on bookmarks
This commit is contained in:
Notes:
github-actions[bot]
2026-04-04 14:24:03 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/22dc7808aeb Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8758
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include <AK/Math.h>
|
||||
#include <LibWebView/Application.h>
|
||||
#include <LibWebView/Menu.h>
|
||||
|
||||
#import <Interface/BookmarkFolder.h>
|
||||
@@ -145,6 +146,18 @@ static constexpr CGFloat const BOOKMARK_FOLDER_ROOT_VERTICAL_SHIFT = 10;
|
||||
return;
|
||||
}
|
||||
|
||||
if ([event modifierFlags] & NSEventModifierFlagCommand) {
|
||||
if (auto* type = Ladybird::get_control_property(self, @"type"); [type isEqualToString:@"bookmark"]) {
|
||||
auto bookmark_id = Ladybird::ns_string_to_string(Ladybird::get_control_property(self, @"id"));
|
||||
auto activate_tab = ([event modifierFlags] & NSEventModifierFlagShift) ? Web::HTML::ActivateTab::No : Web::HTML::ActivateTab::Yes;
|
||||
|
||||
WebView::Application::the().open_bookmark_in_new_tab(bookmark_id, activate_tab);
|
||||
[self.bookmarks_bar closeBookmarkFolders];
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (auto submenu = m_menu.strong_ref(); submenu && submenu->size() > 0) {
|
||||
[self.parent_folder openChildFolder:*submenu relativeToView:self];
|
||||
} else if (auto action = m_action.strong_ref()) {
|
||||
|
||||
@@ -288,6 +288,19 @@ static Optional<WebView::Menu&> find_bookmark_folder_by_id(WebView::Menu& menu,
|
||||
}
|
||||
|
||||
- (void)showContextMenuForEvent:(NSEvent*)event
|
||||
{
|
||||
if (auto* button = [self bookmarkButtonForEvent:event]) {
|
||||
[self showContextMenu:button event:event];
|
||||
return;
|
||||
}
|
||||
|
||||
self.selected_bookmark_menu_item_id = @"";
|
||||
self.selected_bookmark_menu_target_folder_id = nil;
|
||||
|
||||
[NSMenu popUpContextMenu:self.bookmarks_bar_context_menu withEvent:event forView:self];
|
||||
}
|
||||
|
||||
- (NSView*)bookmarkButtonForEvent:(NSEvent*)event
|
||||
{
|
||||
auto location = [event locationInWindow];
|
||||
|
||||
@@ -299,14 +312,10 @@ static Optional<WebView::Menu&> find_bookmark_folder_by_id(WebView::Menu& menu,
|
||||
if (!NSPointInRect(point, [button bounds]))
|
||||
continue;
|
||||
|
||||
[self showContextMenu:button event:event];
|
||||
return;
|
||||
return button;
|
||||
}
|
||||
|
||||
self.selected_bookmark_menu_item_id = @"";
|
||||
self.selected_bookmark_menu_target_folder_id = nil;
|
||||
|
||||
[NSMenu popUpContextMenu:self.bookmarks_bar_context_menu withEvent:event forView:self];
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)rightMouseDown:(NSEvent*)event
|
||||
@@ -321,6 +330,19 @@ static Optional<WebView::Menu&> find_bookmark_folder_by_id(WebView::Menu& menu,
|
||||
return;
|
||||
}
|
||||
|
||||
if ([event modifierFlags] & NSEventModifierFlagCommand) {
|
||||
if (auto* button = [self bookmarkButtonForEvent:event]) {
|
||||
if (auto* type = Ladybird::get_control_property(button, @"type"); [type isEqualToString:@"bookmark"]) {
|
||||
auto bookmark_id = Ladybird::ns_string_to_string(Ladybird::get_control_property(button, @"id"));
|
||||
auto activate_tab = ([event modifierFlags] & NSEventModifierFlagShift) ? Web::HTML::ActivateTab::No : Web::HTML::ActivateTab::Yes;
|
||||
|
||||
WebView::Application::the().open_bookmark_in_new_tab(bookmark_id, activate_tab);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
[super mouseDown:event];
|
||||
}
|
||||
|
||||
@@ -330,10 +352,10 @@ static Optional<WebView::Menu&> find_bookmark_folder_by_id(WebView::Menu& menu,
|
||||
if (!hit)
|
||||
return nil;
|
||||
|
||||
// Route ctrl+left-clicks to the BookmarksBar so we can show the appropriate context menu, rather than letting
|
||||
// Route cmd and ctrl+left clicks to the BookmarksBar so we can handle the action appropriately, rather than letting
|
||||
// NSButton swallow the event for its own click tracking.
|
||||
auto* event = [NSApp currentEvent];
|
||||
if ([event type] == NSEventTypeLeftMouseDown && ([event modifierFlags] & NSEventModifierFlagControl))
|
||||
if ([event type] == NSEventTypeLeftMouseDown && ([event modifierFlags] & (NSEventModifierFlagControl | NSEventModifierFlagCommand)))
|
||||
return self;
|
||||
|
||||
return hit;
|
||||
|
||||
Reference in New Issue
Block a user