mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:27:45 +00:00
Ladybird/AppKit: Remove the standalone JavaScript console
This commit is contained in:
parent
c4daaa9902
commit
dc04385465
9 changed files with 0 additions and 306 deletions
|
@ -415,9 +415,6 @@
|
||||||
[submenu addItem:[[NSMenuItem alloc] initWithTitle:@"View Source"
|
[submenu addItem:[[NSMenuItem alloc] initWithTitle:@"View Source"
|
||||||
action:@selector(viewSource:)
|
action:@selector(viewSource:)
|
||||||
keyEquivalent:@""]];
|
keyEquivalent:@""]];
|
||||||
[submenu addItem:[[NSMenuItem alloc] initWithTitle:@"Open Console"
|
|
||||||
action:@selector(openConsole:)
|
|
||||||
keyEquivalent:@"J"]];
|
|
||||||
[submenu addItem:[[NSMenuItem alloc] initWithTitle:@"Open Inspector"
|
[submenu addItem:[[NSMenuItem alloc] initWithTitle:@"Open Inspector"
|
||||||
action:@selector(openInspector:)
|
action:@selector(openInspector:)
|
||||||
keyEquivalent:@"I"]];
|
keyEquivalent:@"I"]];
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#import <System/Cocoa.h>
|
|
||||||
|
|
||||||
@class LadybirdWebView;
|
|
||||||
@class Tab;
|
|
||||||
|
|
||||||
@interface Console : NSWindow
|
|
||||||
|
|
||||||
- (instancetype)init:(Tab*)tab;
|
|
||||||
|
|
||||||
- (void)reset;
|
|
||||||
|
|
||||||
@property (nonatomic, strong) LadybirdWebView* web_view;
|
|
||||||
|
|
||||||
@end
|
|
|
@ -1,163 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <AK/OwnPtr.h>
|
|
||||||
#include <LibWebView/ConsoleClient.h>
|
|
||||||
|
|
||||||
#import <UI/Console.h>
|
|
||||||
#import <UI/LadybirdWebView.h>
|
|
||||||
#import <UI/Tab.h>
|
|
||||||
#import <Utilities/Conversions.h>
|
|
||||||
|
|
||||||
#if !__has_feature(objc_arc)
|
|
||||||
# error "This project requires ARC"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static constexpr CGFloat const WINDOW_WIDTH = 520;
|
|
||||||
static constexpr CGFloat const WINDOW_HEIGHT = 600;
|
|
||||||
|
|
||||||
@interface Console () <NSTextFieldDelegate>
|
|
||||||
{
|
|
||||||
OwnPtr<WebView::ConsoleClient> m_console_client;
|
|
||||||
}
|
|
||||||
|
|
||||||
@property (nonatomic, strong) Tab* tab;
|
|
||||||
@property (nonatomic, strong) NSScrollView* scroll_view;
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation Console
|
|
||||||
|
|
||||||
@synthesize tab = _tab;
|
|
||||||
|
|
||||||
- (instancetype)init:(Tab*)tab
|
|
||||||
{
|
|
||||||
auto tab_rect = [tab frame];
|
|
||||||
auto position_x = tab_rect.origin.x + (tab_rect.size.width - WINDOW_WIDTH) / 2;
|
|
||||||
auto position_y = tab_rect.origin.y + (tab_rect.size.height - WINDOW_HEIGHT) / 2;
|
|
||||||
|
|
||||||
auto window_rect = NSMakeRect(position_x, position_y, WINDOW_WIDTH, WINDOW_HEIGHT);
|
|
||||||
auto style_mask = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable;
|
|
||||||
|
|
||||||
self = [super initWithContentRect:window_rect
|
|
||||||
styleMask:style_mask
|
|
||||||
backing:NSBackingStoreBuffered
|
|
||||||
defer:NO];
|
|
||||||
|
|
||||||
if (self) {
|
|
||||||
self.tab = tab;
|
|
||||||
|
|
||||||
self.web_view = [[LadybirdWebView alloc] init:nil];
|
|
||||||
[self.web_view setPostsBoundsChangedNotifications:YES];
|
|
||||||
|
|
||||||
m_console_client = make<WebView::ConsoleClient>([[tab web_view] view], [[self web_view] view]);
|
|
||||||
|
|
||||||
self.scroll_view = [[NSScrollView alloc] initWithFrame:[self frame]];
|
|
||||||
[self.scroll_view setHasVerticalScroller:YES];
|
|
||||||
[self.scroll_view setHasHorizontalScroller:YES];
|
|
||||||
[self.scroll_view setLineScroll:24];
|
|
||||||
|
|
||||||
[self.scroll_view setContentView:self.web_view];
|
|
||||||
[self.scroll_view setDocumentView:[[NSView alloc] init]];
|
|
||||||
|
|
||||||
auto* font = [NSFont monospacedSystemFontOfSize:12.0
|
|
||||||
weight:NSFontWeightRegular];
|
|
||||||
|
|
||||||
auto* prompt_indicator_attributes = @{
|
|
||||||
NSForegroundColorAttributeName : [NSColor systemCyanColor],
|
|
||||||
NSFontAttributeName : font,
|
|
||||||
};
|
|
||||||
auto* prompt_indicator_attribute = [[NSAttributedString alloc] initWithString:@">>"
|
|
||||||
attributes:prompt_indicator_attributes];
|
|
||||||
auto* prompt_indicator = [NSTextField labelWithAttributedString:prompt_indicator_attribute];
|
|
||||||
|
|
||||||
auto* prompt_text = [[NSTextField alloc] init];
|
|
||||||
[prompt_text setPlaceholderString:@"Enter JavaScript statement"];
|
|
||||||
[prompt_text setDelegate:self];
|
|
||||||
[prompt_text setBordered:YES];
|
|
||||||
[prompt_text setBezeled:YES];
|
|
||||||
[prompt_text setFont:font];
|
|
||||||
|
|
||||||
auto* clear_button = [NSButton buttonWithImage:[NSImage imageNamed:NSImageNameStopProgressTemplate]
|
|
||||||
target:self
|
|
||||||
action:@selector(clearConsole:)];
|
|
||||||
[clear_button setToolTip:@"Clear the console output"];
|
|
||||||
|
|
||||||
auto* controls_stack_view = [NSStackView stackViewWithViews:@[ prompt_indicator, prompt_text, clear_button ]];
|
|
||||||
[controls_stack_view setOrientation:NSUserInterfaceLayoutOrientationHorizontal];
|
|
||||||
[controls_stack_view setEdgeInsets:NSEdgeInsetsMake(8, 8, 8, 8)];
|
|
||||||
|
|
||||||
auto* content_stack_view = [NSStackView stackViewWithViews:@[ self.scroll_view, controls_stack_view ]];
|
|
||||||
[content_stack_view setOrientation:NSUserInterfaceLayoutOrientationVertical];
|
|
||||||
[content_stack_view setSpacing:0];
|
|
||||||
|
|
||||||
[self setContentView:content_stack_view];
|
|
||||||
[self setTitle:@"Console"];
|
|
||||||
[self setIsVisible:YES];
|
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter]
|
|
||||||
addObserver:self
|
|
||||||
selector:@selector(onContentScroll:)
|
|
||||||
name:NSViewBoundsDidChangeNotification
|
|
||||||
object:[self.scroll_view contentView]];
|
|
||||||
}
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma mark - Public methods
|
|
||||||
|
|
||||||
- (void)reset
|
|
||||||
{
|
|
||||||
m_console_client->reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma mark - Private methods
|
|
||||||
|
|
||||||
- (void)onContentScroll:(NSNotification*)notification
|
|
||||||
{
|
|
||||||
[[self web_view] handleScroll];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)clearConsole:(id)sender
|
|
||||||
{
|
|
||||||
m_console_client->clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma mark - NSTextFieldDelegate
|
|
||||||
|
|
||||||
- (BOOL)control:(NSControl*)control
|
|
||||||
textView:(NSTextView*)text_view
|
|
||||||
doCommandBySelector:(SEL)selector
|
|
||||||
{
|
|
||||||
if (selector == @selector(moveUp:)) {
|
|
||||||
if (auto script = m_console_client->previous_history_item(); script.has_value())
|
|
||||||
[text_view setString:Ladybird::string_to_ns_string(*script)];
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selector == @selector(moveDown:)) {
|
|
||||||
if (auto script = m_console_client->next_history_item(); script.has_value())
|
|
||||||
[text_view setString:Ladybird::string_to_ns_string(*script)];
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selector != @selector(insertNewline:)) {
|
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto* ns_script = [[text_view textStorage] string];
|
|
||||||
auto script = Ladybird::ns_string_to_string(ns_script);
|
|
||||||
|
|
||||||
if (!script.bytes_as_string_view().is_whitespace()) {
|
|
||||||
m_console_client->execute(move(script));
|
|
||||||
[text_view setString:@""];
|
|
||||||
}
|
|
||||||
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
|
@ -1,17 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#import <System/Cocoa.h>
|
|
||||||
|
|
||||||
@class Tab;
|
|
||||||
|
|
||||||
@interface ConsoleController : NSWindowController
|
|
||||||
|
|
||||||
- (instancetype)init:(Tab*)tab;
|
|
||||||
|
|
||||||
@end
|
|
|
@ -1,68 +0,0 @@
|
||||||
/*
|
|
||||||
* 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];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)windowDidChangeBackingProperties:(NSNotification*)notification
|
|
||||||
{
|
|
||||||
[[[self console] web_view] handleDevicePixelRatioChange];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
|
@ -14,9 +14,6 @@
|
||||||
|
|
||||||
- (void)tabWillClose;
|
- (void)tabWillClose;
|
||||||
|
|
||||||
- (void)openConsole:(id)sender;
|
|
||||||
- (void)onConsoleClosed;
|
|
||||||
|
|
||||||
- (void)openInspector:(id)sender;
|
- (void)openInspector:(id)sender;
|
||||||
- (void)onInspectorClosed;
|
- (void)onInspectorClosed;
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,6 @@
|
||||||
#include <LibGfx/ShareableBitmap.h>
|
#include <LibGfx/ShareableBitmap.h>
|
||||||
|
|
||||||
#import <Application/ApplicationDelegate.h>
|
#import <Application/ApplicationDelegate.h>
|
||||||
#import <UI/Console.h>
|
|
||||||
#import <UI/ConsoleController.h>
|
|
||||||
#import <UI/Inspector.h>
|
#import <UI/Inspector.h>
|
||||||
#import <UI/InspectorController.h>
|
#import <UI/InspectorController.h>
|
||||||
#import <UI/LadybirdWebView.h>
|
#import <UI/LadybirdWebView.h>
|
||||||
|
@ -34,7 +32,6 @@ static constexpr CGFloat const WINDOW_HEIGHT = 800;
|
||||||
@property (nonatomic, strong) NSString* title;
|
@property (nonatomic, strong) NSString* title;
|
||||||
@property (nonatomic, strong) NSImage* favicon;
|
@property (nonatomic, strong) NSImage* favicon;
|
||||||
|
|
||||||
@property (nonatomic, strong) ConsoleController* console_controller;
|
|
||||||
@property (nonatomic, strong) InspectorController* inspector_controller;
|
@property (nonatomic, strong) InspectorController* inspector_controller;
|
||||||
|
|
||||||
@property (nonatomic, assign) URL last_url;
|
@property (nonatomic, assign) URL last_url;
|
||||||
|
@ -114,30 +111,11 @@ static constexpr CGFloat const WINDOW_HEIGHT = 800;
|
||||||
|
|
||||||
- (void)tabWillClose
|
- (void)tabWillClose
|
||||||
{
|
{
|
||||||
if (self.console_controller != nil) {
|
|
||||||
[self.console_controller.window close];
|
|
||||||
}
|
|
||||||
if (self.inspector_controller != nil) {
|
if (self.inspector_controller != nil) {
|
||||||
[self.inspector_controller.window close];
|
[self.inspector_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;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)openInspector:(id)sender
|
- (void)openInspector:(id)sender
|
||||||
{
|
{
|
||||||
if (self.inspector_controller != nil) {
|
if (self.inspector_controller != nil) {
|
||||||
|
@ -258,10 +236,6 @@ static constexpr CGFloat const WINDOW_HEIGHT = 800;
|
||||||
self.favicon = [Tab defaultFavicon];
|
self.favicon = [Tab defaultFavicon];
|
||||||
[self updateTabTitleAndFavicon];
|
[self updateTabTitleAndFavicon];
|
||||||
|
|
||||||
if (self.console_controller != nil) {
|
|
||||||
auto* console = (Console*)[self.console_controller window];
|
|
||||||
[console reset];
|
|
||||||
}
|
|
||||||
if (self.inspector_controller != nil) {
|
if (self.inspector_controller != nil) {
|
||||||
auto* inspector = (Inspector*)[self.inspector_controller window];
|
auto* inspector = (Inspector*)[self.inspector_controller window];
|
||||||
[inspector reset];
|
[inspector reset];
|
||||||
|
|
|
@ -137,8 +137,6 @@ elseif (APPLE)
|
||||||
AppKit/Application/Application.mm
|
AppKit/Application/Application.mm
|
||||||
AppKit/Application/ApplicationDelegate.mm
|
AppKit/Application/ApplicationDelegate.mm
|
||||||
AppKit/Application/EventLoopImplementation.mm
|
AppKit/Application/EventLoopImplementation.mm
|
||||||
AppKit/UI/Console.mm
|
|
||||||
AppKit/UI/ConsoleController.mm
|
|
||||||
AppKit/UI/Event.mm
|
AppKit/UI/Event.mm
|
||||||
AppKit/UI/Inspector.mm
|
AppKit/UI/Inspector.mm
|
||||||
AppKit/UI/InspectorController.mm
|
AppKit/UI/InspectorController.mm
|
||||||
|
|
|
@ -114,8 +114,6 @@ executable("ladybird_executable") {
|
||||||
"AppKit/Application/Application.mm",
|
"AppKit/Application/Application.mm",
|
||||||
"AppKit/Application/ApplicationDelegate.mm",
|
"AppKit/Application/ApplicationDelegate.mm",
|
||||||
"AppKit/Application/EventLoopImplementation.mm",
|
"AppKit/Application/EventLoopImplementation.mm",
|
||||||
"AppKit/UI/Console.mm",
|
|
||||||
"AppKit/UI/ConsoleController.mm",
|
|
||||||
"AppKit/UI/Event.mm",
|
"AppKit/UI/Event.mm",
|
||||||
"AppKit/UI/Inspector.mm",
|
"AppKit/UI/Inspector.mm",
|
||||||
"AppKit/UI/InspectorController.mm",
|
"AppKit/UI/InspectorController.mm",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue