mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:57:35 +00:00
Ladybird: Allow creating new tabs with plain HTML
This will allow us to internally create a new tab with HTML, to be used by the View Source command.
This commit is contained in:
parent
9c4ce1b80b
commit
a718a1f3a6
10 changed files with 83 additions and 29 deletions
|
@ -28,6 +28,11 @@
|
||||||
fromTab:(nullable Tab*)tab
|
fromTab:(nullable Tab*)tab
|
||||||
activateTab:(Web::HTML::ActivateTab)activate_tab;
|
activateTab:(Web::HTML::ActivateTab)activate_tab;
|
||||||
|
|
||||||
|
- (nonnull TabController*)createNewTab:(StringView)html
|
||||||
|
url:(URL const&)url
|
||||||
|
fromTab:(nullable Tab*)tab
|
||||||
|
activateTab:(Web::HTML::ActivateTab)activate_tab;
|
||||||
|
|
||||||
- (void)removeTab:(nonnull TabController*)controller;
|
- (void)removeTab:(nonnull TabController*)controller;
|
||||||
|
|
||||||
- (Browser::CookieJar&)cookieJar;
|
- (Browser::CookieJar&)cookieJar;
|
||||||
|
|
|
@ -86,19 +86,20 @@
|
||||||
fromTab:(Tab*)tab
|
fromTab:(Tab*)tab
|
||||||
activateTab:(Web::HTML::ActivateTab)activate_tab
|
activateTab:(Web::HTML::ActivateTab)activate_tab
|
||||||
{
|
{
|
||||||
auto* controller = [[TabController alloc] init:url.value_or(m_new_tab_page_url)];
|
auto* controller = [self createNewTab:activate_tab fromTab:tab];
|
||||||
[controller showWindow:nil];
|
[controller loadURL:url.value_or(m_new_tab_page_url)];
|
||||||
|
|
||||||
if (tab) {
|
return controller;
|
||||||
[[tab tabGroup] addWindow:controller.window];
|
}
|
||||||
|
|
||||||
// FIXME: Can we create the tabbed window above without it becoming active in the first place?
|
- (nonnull TabController*)createNewTab:(StringView)html
|
||||||
if (activate_tab == Web::HTML::ActivateTab::No) {
|
url:(URL const&)url
|
||||||
[tab orderFront:nil];
|
fromTab:(nullable Tab*)tab
|
||||||
}
|
activateTab:(Web::HTML::ActivateTab)activate_tab
|
||||||
}
|
{
|
||||||
|
auto* controller = [self createNewTab:activate_tab fromTab:tab];
|
||||||
|
[controller loadHTML:html url:url];
|
||||||
|
|
||||||
[self.managed_tabs addObject:controller];
|
|
||||||
return controller;
|
return controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,6 +125,25 @@
|
||||||
|
|
||||||
#pragma mark - Private methods
|
#pragma mark - Private methods
|
||||||
|
|
||||||
|
- (nonnull TabController*)createNewTab:(Web::HTML::ActivateTab)activate_tab
|
||||||
|
fromTab:(nullable Tab*)tab
|
||||||
|
{
|
||||||
|
auto* controller = [[TabController alloc] init];
|
||||||
|
[controller showWindow:nil];
|
||||||
|
|
||||||
|
if (tab) {
|
||||||
|
[[tab tabGroup] addWindow:controller.window];
|
||||||
|
|
||||||
|
// FIXME: Can we create the tabbed window above without it becoming active in the first place?
|
||||||
|
if (activate_tab == Web::HTML::ActivateTab::No) {
|
||||||
|
[tab orderFront:nil];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[self.managed_tabs addObject:controller];
|
||||||
|
return controller;
|
||||||
|
}
|
||||||
|
|
||||||
- (void)closeCurrentTab:(id)sender
|
- (void)closeCurrentTab:(id)sender
|
||||||
{
|
{
|
||||||
auto* current_window = [NSApp keyWindow];
|
auto* current_window = [NSApp keyWindow];
|
||||||
|
|
|
@ -13,7 +13,8 @@
|
||||||
|
|
||||||
@interface LadybirdWebView : NSClipView
|
@interface LadybirdWebView : NSClipView
|
||||||
|
|
||||||
- (void)load:(URL const&)url;
|
- (void)loadURL:(URL const&)url;
|
||||||
|
- (void)loadHTML:(StringView)html url:(URL const&)url;
|
||||||
|
|
||||||
- (void)handleResize;
|
- (void)handleResize;
|
||||||
- (void)handleScroll;
|
- (void)handleScroll;
|
||||||
|
|
|
@ -100,11 +100,16 @@ struct HideCursor {
|
||||||
|
|
||||||
#pragma mark - Public methods
|
#pragma mark - Public methods
|
||||||
|
|
||||||
- (void)load:(URL const&)url
|
- (void)loadURL:(URL const&)url
|
||||||
{
|
{
|
||||||
m_web_view_bridge->load(url);
|
m_web_view_bridge->load(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)loadHTML:(StringView)html url:(URL const&)url
|
||||||
|
{
|
||||||
|
m_web_view_bridge->load_html(html, url);
|
||||||
|
}
|
||||||
|
|
||||||
- (void)handleResize
|
- (void)handleResize
|
||||||
{
|
{
|
||||||
[self updateViewportRect:Ladybird::WebViewBridge::ForResize::Yes];
|
[self updateViewportRect:Ladybird::WebViewBridge::ForResize::Yes];
|
||||||
|
@ -364,7 +369,7 @@ struct HideCursor {
|
||||||
fromTab:[self tab]
|
fromTab:[self tab]
|
||||||
activateTab:Web::HTML::ActivateTab::Yes];
|
activateTab:Web::HTML::ActivateTab::Yes];
|
||||||
} else {
|
} else {
|
||||||
[[self tabController] load:url];
|
[[self tabController] loadURL:url];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -13,9 +13,10 @@
|
||||||
|
|
||||||
@interface TabController : NSWindowController <NSWindowDelegate>
|
@interface TabController : NSWindowController <NSWindowDelegate>
|
||||||
|
|
||||||
- (instancetype)init:(URL)url;
|
- (instancetype)init;
|
||||||
|
|
||||||
- (void)load:(URL const&)url;
|
- (void)loadURL:(URL const&)url;
|
||||||
|
- (void)loadHTML:(StringView)html url:(URL const&)url;
|
||||||
|
|
||||||
- (void)onLoadStart:(URL const&)url isRedirect:(BOOL)isRedirect;
|
- (void)onLoadStart:(URL const&)url isRedirect:(BOOL)isRedirect;
|
||||||
- (void)onTitleChange:(DeprecatedString const&)title;
|
- (void)onTitleChange:(DeprecatedString const&)title;
|
||||||
|
|
|
@ -32,7 +32,6 @@ enum class IsHistoryNavigation {
|
||||||
|
|
||||||
@interface TabController () <NSToolbarDelegate, NSSearchFieldDelegate>
|
@interface TabController () <NSToolbarDelegate, NSSearchFieldDelegate>
|
||||||
{
|
{
|
||||||
URL m_url;
|
|
||||||
DeprecatedString m_title;
|
DeprecatedString m_title;
|
||||||
|
|
||||||
Browser::History m_history;
|
Browser::History m_history;
|
||||||
|
@ -63,7 +62,7 @@ enum class IsHistoryNavigation {
|
||||||
@synthesize new_tab_toolbar_item = _new_tab_toolbar_item;
|
@synthesize new_tab_toolbar_item = _new_tab_toolbar_item;
|
||||||
@synthesize tab_overview_toolbar_item = _tab_overview_toolbar_item;
|
@synthesize tab_overview_toolbar_item = _tab_overview_toolbar_item;
|
||||||
|
|
||||||
- (instancetype)init:(URL)url
|
- (instancetype)init
|
||||||
{
|
{
|
||||||
if (self = [super init]) {
|
if (self = [super init]) {
|
||||||
self.toolbar = [[NSToolbar alloc] initWithIdentifier:TOOLBAR_IDENTIFIER];
|
self.toolbar = [[NSToolbar alloc] initWithIdentifier:TOOLBAR_IDENTIFIER];
|
||||||
|
@ -72,7 +71,6 @@ enum class IsHistoryNavigation {
|
||||||
[self.toolbar setAllowsUserCustomization:NO];
|
[self.toolbar setAllowsUserCustomization:NO];
|
||||||
[self.toolbar setSizeMode:NSToolbarSizeModeRegular];
|
[self.toolbar setSizeMode:NSToolbarSizeModeRegular];
|
||||||
|
|
||||||
m_url = move(url);
|
|
||||||
m_is_history_navigation = IsHistoryNavigation::No;
|
m_is_history_navigation = IsHistoryNavigation::No;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,9 +79,14 @@ enum class IsHistoryNavigation {
|
||||||
|
|
||||||
#pragma mark - Public methods
|
#pragma mark - Public methods
|
||||||
|
|
||||||
- (void)load:(URL const&)url
|
- (void)loadURL:(URL const&)url
|
||||||
{
|
{
|
||||||
[[self tab].web_view load:url];
|
[[self tab].web_view loadURL:url];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)loadHTML:(StringView)html url:(URL const&)url
|
||||||
|
{
|
||||||
|
[[self tab].web_view loadHTML:html url:url];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)onLoadStart:(URL const&)url isRedirect:(BOOL)isRedirect
|
- (void)onLoadStart:(URL const&)url isRedirect:(BOOL)isRedirect
|
||||||
|
@ -121,7 +124,7 @@ enum class IsHistoryNavigation {
|
||||||
m_history.go_back();
|
m_history.go_back();
|
||||||
|
|
||||||
auto url = m_history.current().url;
|
auto url = m_history.current().url;
|
||||||
[self load:url];
|
[self loadURL:url];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)navigateForward:(id)sender
|
- (void)navigateForward:(id)sender
|
||||||
|
@ -134,7 +137,7 @@ enum class IsHistoryNavigation {
|
||||||
m_history.go_forward();
|
m_history.go_forward();
|
||||||
|
|
||||||
auto url = m_history.current().url;
|
auto url = m_history.current().url;
|
||||||
[self load:url];
|
[self loadURL:url];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)reload:(id)sender
|
- (void)reload:(id)sender
|
||||||
|
@ -146,7 +149,7 @@ enum class IsHistoryNavigation {
|
||||||
m_is_history_navigation = IsHistoryNavigation::Yes;
|
m_is_history_navigation = IsHistoryNavigation::Yes;
|
||||||
|
|
||||||
auto url = m_history.current().url;
|
auto url = m_history.current().url;
|
||||||
[self load:url];
|
[self loadURL:url];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)clearHistory
|
- (void)clearHistory
|
||||||
|
@ -312,8 +315,6 @@ enum class IsHistoryNavigation {
|
||||||
- (IBAction)showWindow:(id)sender
|
- (IBAction)showWindow:(id)sender
|
||||||
{
|
{
|
||||||
self.window = [[Tab alloc] init];
|
self.window = [[Tab alloc] init];
|
||||||
[self load:m_url];
|
|
||||||
|
|
||||||
[self.window setDelegate:self];
|
[self.window setDelegate:self];
|
||||||
|
|
||||||
[self.window setToolbar:self.toolbar];
|
[self.window setToolbar:self.toolbar];
|
||||||
|
@ -397,7 +398,7 @@ enum class IsHistoryNavigation {
|
||||||
|
|
||||||
auto* url_string = [[text_view textStorage] string];
|
auto* url_string = [[text_view textStorage] string];
|
||||||
auto url = Ladybird::sanitize_url(url_string);
|
auto url = Ladybird::sanitize_url(url_string);
|
||||||
[self load:url];
|
[self loadURL:url];
|
||||||
|
|
||||||
[self.window makeFirstResponder:nil];
|
[self.window makeFirstResponder:nil];
|
||||||
return YES;
|
return YES;
|
||||||
|
|
|
@ -429,6 +429,20 @@ void BrowserWindow::debug_request(DeprecatedString const& request, DeprecatedStr
|
||||||
}
|
}
|
||||||
|
|
||||||
Tab& BrowserWindow::new_tab(QString const& url, Web::HTML::ActivateTab activate_tab)
|
Tab& BrowserWindow::new_tab(QString const& url, Web::HTML::ActivateTab activate_tab)
|
||||||
|
{
|
||||||
|
auto& tab = create_new_tab(activate_tab);
|
||||||
|
tab.navigate(url);
|
||||||
|
return tab;
|
||||||
|
}
|
||||||
|
|
||||||
|
Tab& BrowserWindow::new_tab(StringView html, URL const& url, Web::HTML::ActivateTab activate_tab)
|
||||||
|
{
|
||||||
|
auto& tab = create_new_tab(activate_tab);
|
||||||
|
tab.load_html(html, url);
|
||||||
|
return tab;
|
||||||
|
}
|
||||||
|
|
||||||
|
Tab& BrowserWindow::create_new_tab(Web::HTML::ActivateTab activate_tab)
|
||||||
{
|
{
|
||||||
auto tab = make<Tab>(this, m_webdriver_content_ipc_path, m_enable_callgrind_profiling, m_use_lagom_networking);
|
auto tab = make<Tab>(this, m_webdriver_content_ipc_path, m_enable_callgrind_profiling, m_use_lagom_networking);
|
||||||
auto tab_ptr = tab.ptr();
|
auto tab_ptr = tab.ptr();
|
||||||
|
@ -500,9 +514,6 @@ Tab& BrowserWindow::new_tab(QString const& url, Web::HTML::ActivateTab activate_
|
||||||
};
|
};
|
||||||
|
|
||||||
tab_ptr->focus_location_editor();
|
tab_ptr->focus_location_editor();
|
||||||
|
|
||||||
tab_ptr->navigate(url);
|
|
||||||
|
|
||||||
return *tab_ptr;
|
return *tab_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,6 +73,7 @@ public slots:
|
||||||
void tab_title_changed(int index, QString const&);
|
void tab_title_changed(int index, QString const&);
|
||||||
void tab_favicon_changed(int index, QIcon const& icon);
|
void tab_favicon_changed(int index, QIcon const& icon);
|
||||||
Tab& new_tab(QString const&, Web::HTML::ActivateTab);
|
Tab& new_tab(QString const&, Web::HTML::ActivateTab);
|
||||||
|
Tab& new_tab(StringView html, URL const& url, Web::HTML::ActivateTab);
|
||||||
void activate_tab(int index);
|
void activate_tab(int index);
|
||||||
void close_tab(int index);
|
void close_tab(int index);
|
||||||
void close_current_tab();
|
void close_current_tab();
|
||||||
|
@ -98,6 +99,8 @@ private:
|
||||||
virtual void wheelEvent(QWheelEvent*) override;
|
virtual void wheelEvent(QWheelEvent*) override;
|
||||||
virtual void closeEvent(QCloseEvent*) override;
|
virtual void closeEvent(QCloseEvent*) override;
|
||||||
|
|
||||||
|
Tab& create_new_tab(Web::HTML::ActivateTab activate_tab);
|
||||||
|
|
||||||
void debug_request(DeprecatedString const& request, DeprecatedString const& argument = "");
|
void debug_request(DeprecatedString const& request, DeprecatedString const& argument = "");
|
||||||
|
|
||||||
void set_current_tab(Tab* tab);
|
void set_current_tab(Tab* tab);
|
||||||
|
|
|
@ -566,6 +566,11 @@ void Tab::navigate(QString url_qstring)
|
||||||
view().load(url_string);
|
view().load(url_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Tab::load_html(StringView html, URL const& url)
|
||||||
|
{
|
||||||
|
view().load_html(html, url);
|
||||||
|
}
|
||||||
|
|
||||||
void Tab::back()
|
void Tab::back()
|
||||||
{
|
{
|
||||||
if (!m_history.can_go_back())
|
if (!m_history.can_go_back())
|
||||||
|
|
|
@ -34,6 +34,8 @@ public:
|
||||||
WebContentView& view() { return *m_view; }
|
WebContentView& view() { return *m_view; }
|
||||||
|
|
||||||
void navigate(QString);
|
void navigate(QString);
|
||||||
|
void load_html(StringView, URL const&);
|
||||||
|
|
||||||
void back();
|
void back();
|
||||||
void forward();
|
void forward();
|
||||||
void reload();
|
void reload();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue