mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 13:37:44 +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:
parent
bf59e06d2a
commit
4d26e4650f
11 changed files with 306 additions and 0 deletions
63
Ladybird/AppKit/UI/ConsoleController.mm
Normal file
63
Ladybird/AppKit/UI/ConsoleController.mm
Normal file
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#import <UI/Console.h>
|
||||
#import <UI/ConsoleController.h>
|
||||
#import <UI/LadybirdWebView.h>
|
||||
#import <UI/Tab.h>
|
||||
|
||||
#if !__has_feature(objc_arc)
|
||||
# error "This project requires ARC"
|
||||
#endif
|
||||
|
||||
@interface ConsoleController () <NSWindowDelegate>
|
||||
|
||||
@property (nonatomic, strong) Tab* tab;
|
||||
|
||||
@end
|
||||
|
||||
@implementation ConsoleController
|
||||
|
||||
- (instancetype)init:(Tab*)tab
|
||||
{
|
||||
if (self = [super init]) {
|
||||
self.tab = tab;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark - Private methods
|
||||
|
||||
- (Console*)console
|
||||
{
|
||||
return (Console*)[self window];
|
||||
}
|
||||
|
||||
#pragma mark - NSWindowController
|
||||
|
||||
- (IBAction)showWindow:(id)sender
|
||||
{
|
||||
self.window = [[Console alloc] init:self.tab];
|
||||
[self.window setDelegate:self];
|
||||
[self.window makeKeyAndOrderFront:sender];
|
||||
}
|
||||
|
||||
#pragma mark - NSWindowDelegate
|
||||
|
||||
- (void)windowWillClose:(NSNotification*)notification
|
||||
{
|
||||
[self.tab onConsoleClosed];
|
||||
}
|
||||
|
||||
- (void)windowDidResize:(NSNotification*)notification
|
||||
{
|
||||
if (![[self window] inLiveResize]) {
|
||||
[[[self console] web_view] handleResize];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
Loading…
Add table
Add a link
Reference in a new issue