mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-25 17:25:08 +02:00
Tabs opened from links on AppKit can be created before their URL is loaded. That left background open-url tabs with the location field as their stored responder, so switching to them later restored address-bar focus instead of web content focus. Track each tab's preferred responder, restore it when AppKit makes the tab key, and mark page-backed open-url tabs to prefer the web view. Blank new-tab pages still keep the location field focused.
64 lines
1.5 KiB
Plaintext
64 lines
1.5 KiB
Plaintext
/*
|
|
* Copyright (c) 2024, Tim Flynn <trflynn89@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#import <Interface/LadybirdWebView.h>
|
|
#import <Interface/LadybirdWebViewWindow.h>
|
|
|
|
#if !__has_feature(objc_arc)
|
|
# error "This project requires ARC"
|
|
#endif
|
|
|
|
@interface LadybirdWebViewWindow ()
|
|
@end
|
|
|
|
@implementation LadybirdWebViewWindow
|
|
|
|
- (instancetype)initWithWebView:(LadybirdWebView*)web_view
|
|
windowRect:(NSRect)window_rect
|
|
{
|
|
static constexpr auto style_mask = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable;
|
|
|
|
self = [super initWithContentRect:window_rect
|
|
styleMask:style_mask
|
|
backing:NSBackingStoreBuffered
|
|
defer:NO];
|
|
|
|
if (self) {
|
|
self.web_view = web_view;
|
|
|
|
if (self.web_view == nil)
|
|
self.web_view = [[LadybirdWebView alloc] init:nil];
|
|
|
|
[self.web_view setClipsToBounds:YES];
|
|
}
|
|
|
|
return self;
|
|
}
|
|
|
|
#pragma mark - NSWindow
|
|
|
|
- (void)setIsVisible:(BOOL)flag
|
|
{
|
|
[self.web_view handleVisibility:flag];
|
|
[super setIsVisible:flag];
|
|
}
|
|
|
|
- (void)setIsMiniaturized:(BOOL)flag
|
|
{
|
|
[self.web_view handleVisibility:!flag];
|
|
[super setIsMiniaturized:flag];
|
|
}
|
|
|
|
- (void)becomeKeyWindow
|
|
{
|
|
[super becomeKeyWindow];
|
|
|
|
if (self.preferred_first_responder && [self firstResponder] != self.preferred_first_responder)
|
|
[self makeFirstResponder:self.preferred_first_responder];
|
|
}
|
|
|
|
@end
|