1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:17:35 +00:00

Ladybird: Implement a JavaScript console for the AppKit chrome

This adds menu items to open an interactive JavaScript console for a web
page. This more or less mimics the Qt implementation of the console.
Hooks are included to tie the lifetime of the console window with the
tab it belongs to; if the tab is closed, the console window is closed.
This commit is contained in:
Timothy Flynn 2023-08-26 22:43:35 -04:00 committed by Andrew Kaster
parent bf59e06d2a
commit 4d26e4650f
11 changed files with 306 additions and 0 deletions

View file

@ -12,6 +12,8 @@
#include <LibGfx/ShareableBitmap.h>
#import <Application/ApplicationDelegate.h>
#import <UI/Console.h>
#import <UI/ConsoleController.h>
#import <UI/LadybirdWebView.h>
#import <UI/Tab.h>
#import <UI/TabController.h>
@ -29,6 +31,8 @@ static constexpr CGFloat const WINDOW_HEIGHT = 800;
@property (nonatomic, strong) NSString* title;
@property (nonatomic, strong) NSImage* favicon;
@property (nonatomic, strong) ConsoleController* console_controller;
@end
@implementation Tab
@ -95,6 +99,31 @@ static constexpr CGFloat const WINDOW_HEIGHT = 800;
return self;
}
#pragma mark - Public methods
- (void)tabWillClose
{
if (self.console_controller != nil) {
[self.console_controller.window close];
}
}
- (void)openConsole:(id)sender
{
if (self.console_controller != nil) {
[self.console_controller.window makeKeyAndOrderFront:sender];
return;
}
self.console_controller = [[ConsoleController alloc] init:self];
[self.console_controller showWindow:nil];
}
- (void)onConsoleClosed
{
self.console_controller = nil;
}
#pragma mark - Private methods
- (TabController*)tabController
@ -185,6 +214,11 @@ static constexpr CGFloat const WINDOW_HEIGHT = 800;
self.title = Ladybird::string_to_ns_string(url.serialize());
self.favicon = [Tab defaultFavicon];
[self updateTabTitleAndFavicon];
if (self.console_controller != nil) {
auto* console = (Console*)[self.console_controller window];
[console reset];
}
}
- (void)onTitleChange:(DeprecatedString const&)title