mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-14 18:30:38 +00:00
Ladybird: Implement the View Source action for the AppKit chrome
This opens a new tab to display the current tab's source as HTML.
This commit is contained in:
parent
a6bdf8c2a9
commit
390da2985f
Notes:
sideshowbarker
2024-07-17 08:59:18 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/390da2985f Pull-request: https://github.com/SerenityOS/serenity/pull/20824 Reviewed-by: https://github.com/ADKaster ✅
4 changed files with 43 additions and 0 deletions
|
@ -36,6 +36,7 @@
|
|||
- (NSMenuItem*)createEditMenu;
|
||||
- (NSMenuItem*)createViewMenu;
|
||||
- (NSMenuItem*)createHistoryMenu;
|
||||
- (NSMenuItem*)createInspectMenu;
|
||||
- (NSMenuItem*)createDebugMenu;
|
||||
- (NSMenuItem*)createWindowsMenu;
|
||||
- (NSMenuItem*)createHelpMenu;
|
||||
|
@ -56,6 +57,7 @@
|
|||
[[NSApp mainMenu] addItem:[self createEditMenu]];
|
||||
[[NSApp mainMenu] addItem:[self createViewMenu]];
|
||||
[[NSApp mainMenu] addItem:[self createHistoryMenu]];
|
||||
[[NSApp mainMenu] addItem:[self createInspectMenu]];
|
||||
[[NSApp mainMenu] addItem:[self createDebugMenu]];
|
||||
[[NSApp mainMenu] addItem:[self createWindowsMenu]];
|
||||
[[NSApp mainMenu] addItem:[self createHelpMenu]];
|
||||
|
@ -332,6 +334,19 @@
|
|||
return menu;
|
||||
}
|
||||
|
||||
- (NSMenuItem*)createInspectMenu
|
||||
{
|
||||
auto* menu = [[NSMenuItem alloc] init];
|
||||
auto* submenu = [[NSMenu alloc] initWithTitle:@"Inspect"];
|
||||
|
||||
[submenu addItem:[[NSMenuItem alloc] initWithTitle:@"View Source"
|
||||
action:@selector(viewSource:)
|
||||
keyEquivalent:@""]];
|
||||
|
||||
[menu setSubmenu:submenu];
|
||||
return menu;
|
||||
}
|
||||
|
||||
- (NSMenuItem*)createDebugMenu
|
||||
{
|
||||
auto* menu = [[NSMenuItem alloc] init];
|
||||
|
|
|
@ -22,4 +22,6 @@
|
|||
|
||||
- (void)setPreferredColorScheme:(Web::CSS::PreferredColorScheme)color_scheme;
|
||||
|
||||
- (void)viewSource;
|
||||
|
||||
@end
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <AK/URL.h>
|
||||
#include <LibGfx/ImageFormats/PNGWriter.h>
|
||||
#include <LibGfx/ShareableBitmap.h>
|
||||
#include <LibWebView/SourceHighlighter.h>
|
||||
#include <UI/LadybirdWebViewBridge.h>
|
||||
|
||||
#import <Application/ApplicationDelegate.h>
|
||||
|
@ -132,6 +133,11 @@ struct HideCursor {
|
|||
m_web_view_bridge->set_preferred_color_scheme(color_scheme);
|
||||
}
|
||||
|
||||
- (void)viewSource
|
||||
{
|
||||
m_web_view_bridge->get_source();
|
||||
}
|
||||
|
||||
#pragma mark - Private methods
|
||||
|
||||
- (void)updateViewportRect:(Ladybird::WebViewBridge::ForResize)for_resize
|
||||
|
@ -587,6 +593,16 @@ struct HideCursor {
|
|||
|
||||
return Ladybird::ns_rect_to_gfx_rect([[self window] frame]);
|
||||
};
|
||||
|
||||
m_web_view_bridge->on_received_source = [self](auto const& url, auto const& source) {
|
||||
auto* delegate = (ApplicationDelegate*)[NSApp delegate];
|
||||
auto html = WebView::highlight_source(url, source);
|
||||
|
||||
[delegate createNewTab:html
|
||||
url:url
|
||||
fromTab:[self tab]
|
||||
activateTab:Web::HTML::ActivateTab::Yes];
|
||||
};
|
||||
}
|
||||
|
||||
- (Tab*)tab
|
||||
|
@ -721,6 +737,11 @@ static void copy_text_to_clipboard(StringView text)
|
|||
[_page_context_menu addItem:[[NSMenuItem alloc] initWithTitle:@"Take Full Screenshot"
|
||||
action:@selector(takeFullScreenshot:)
|
||||
keyEquivalent:@""]];
|
||||
[_page_context_menu addItem:[NSMenuItem separatorItem]];
|
||||
|
||||
[_page_context_menu addItem:[[NSMenuItem alloc] initWithTitle:@"View Source"
|
||||
action:@selector(viewSource:)
|
||||
keyEquivalent:@""]];
|
||||
}
|
||||
|
||||
return _page_context_menu;
|
||||
|
|
|
@ -158,6 +158,11 @@ enum class IsHistoryNavigation {
|
|||
[self updateNavigationButtonStates];
|
||||
}
|
||||
|
||||
- (void)viewSource:(id)sender
|
||||
{
|
||||
[[[self tab] web_view] viewSource];
|
||||
}
|
||||
|
||||
- (void)focusLocationToolbarItem
|
||||
{
|
||||
[self.window makeFirstResponder:self.location_toolbar_item.view];
|
||||
|
|
Loading…
Reference in a new issue