mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 09:17:35 +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
4 changed files with 43 additions and 0 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue