mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 15:42:44 +00:00 
			
		
		
		
	Ladybird/Qt: Rename new_tab to new_tab_from_url and make it take AK::URL
Instead of having QString be the API for these load() calls, just pipe AK::URL throughout the UI.
This commit is contained in:
		
							parent
							
								
									a91680dd55
								
							
						
					
					
						commit
						c75bd4ed15
					
				
					 6 changed files with 29 additions and 17 deletions
				
			
		|  | @ -381,10 +381,10 @@ BrowserWindow::BrowserWindow(Vector<URL> const& initial_urls, WebView::CookieJar | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     QObject::connect(about_action, &QAction::triggered, this, [this] { |     QObject::connect(about_action, &QAction::triggered, this, [this] { | ||||||
|         new_tab("about:version", Web::HTML::ActivateTab::Yes); |         new_tab_from_url("about:version"sv, Web::HTML::ActivateTab::Yes); | ||||||
|     }); |     }); | ||||||
|     QObject::connect(new_tab_action, &QAction::triggered, this, [this] { |     QObject::connect(new_tab_action, &QAction::triggered, this, [this] { | ||||||
|         new_tab(Settings::the()->new_tab_page(), Web::HTML::ActivateTab::Yes); |         new_tab_from_url(ak_url_from_qstring(Settings::the()->new_tab_page()), Web::HTML::ActivateTab::Yes); | ||||||
|     }); |     }); | ||||||
|     QObject::connect(open_file_action, &QAction::triggered, this, &BrowserWindow::open_file); |     QObject::connect(open_file_action, &QAction::triggered, this, &BrowserWindow::open_file); | ||||||
|     QObject::connect(settings_action, &QAction::triggered, this, [this] { |     QObject::connect(settings_action, &QAction::triggered, this, [this] { | ||||||
|  | @ -448,8 +448,7 @@ BrowserWindow::BrowserWindow(Vector<URL> const& initial_urls, WebView::CookieJar | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     for (size_t i = 0; i < initial_urls.size(); ++i) { |     for (size_t i = 0; i < initial_urls.size(); ++i) { | ||||||
|         auto url_string = qstring_from_ak_string(initial_urls[i].serialize()); |         new_tab_from_url(initial_urls[i], (i == 0) ? Web::HTML::ActivateTab::Yes : Web::HTML::ActivateTab::No); | ||||||
|         new_tab(url_string, (i == 0) ? Web::HTML::ActivateTab::Yes : Web::HTML::ActivateTab::No); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     setCentralWidget(m_tabs_container); |     setCentralWidget(m_tabs_container); | ||||||
|  | @ -470,7 +469,7 @@ void BrowserWindow::debug_request(ByteString const& request, ByteString const& a | ||||||
|     m_current_tab->debug_request(request, argument); |     m_current_tab->debug_request(request, argument); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| Tab& BrowserWindow::new_tab(QString const& url, Web::HTML::ActivateTab activate_tab) | Tab& BrowserWindow::new_tab_from_url(AK::URL const& url, Web::HTML::ActivateTab activate_tab) | ||||||
| { | { | ||||||
|     auto& tab = create_new_tab(activate_tab); |     auto& tab = create_new_tab(activate_tab); | ||||||
|     tab.navigate(url); |     tab.navigate(url); | ||||||
|  | @ -501,19 +500,19 @@ Tab& BrowserWindow::create_new_tab(Web::HTML::ActivateTab activate_tab) | ||||||
| 
 | 
 | ||||||
|     QObject::connect(&tab->view(), &WebContentView::urls_dropped, this, [this](auto& urls) { |     QObject::connect(&tab->view(), &WebContentView::urls_dropped, this, [this](auto& urls) { | ||||||
|         VERIFY(urls.size()); |         VERIFY(urls.size()); | ||||||
|         m_current_tab->navigate(urls[0].toString()); |         m_current_tab->navigate(ak_url_from_qurl(urls[0])); | ||||||
| 
 | 
 | ||||||
|         for (qsizetype i = 1; i < urls.size(); ++i) |         for (qsizetype i = 1; i < urls.size(); ++i) | ||||||
|             new_tab(urls[i].toString(), Web::HTML::ActivateTab::No); |             new_tab_from_url(ak_url_from_qurl(urls[i]), Web::HTML::ActivateTab::No); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     tab->view().on_new_tab = [this](auto activate_tab) { |     tab->view().on_new_tab = [this](auto activate_tab) { | ||||||
|         auto& tab = new_tab("about:blank", activate_tab); |         auto& tab = new_tab_from_url("about:blank"sv, activate_tab); | ||||||
|         return tab.view().handle(); |         return tab.view().handle(); | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     tab->view().on_tab_open_request = [this](auto url, auto activate_tab) { |     tab->view().on_tab_open_request = [this](auto url, auto activate_tab) { | ||||||
|         auto& tab = new_tab(qstring_from_ak_string(url.to_byte_string()), activate_tab); |         auto& tab = new_tab_from_url(url, activate_tab); | ||||||
|         return tab.view().handle(); |         return tab.view().handle(); | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -73,7 +73,7 @@ public slots: | ||||||
|     void device_pixel_ratio_changed(qreal dpi); |     void device_pixel_ratio_changed(qreal dpi); | ||||||
|     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_from_url(AK::URL const&, Web::HTML::ActivateTab); | ||||||
|     Tab& new_tab_from_content(StringView html, Web::HTML::ActivateTab); |     Tab& new_tab_from_content(StringView html, Web::HTML::ActivateTab); | ||||||
|     void activate_tab(int index); |     void activate_tab(int index); | ||||||
|     void close_tab(int index); |     void close_tab(int index); | ||||||
|  |  | ||||||
|  | @ -21,3 +21,13 @@ QString qstring_from_ak_string(StringView ak_string) | ||||||
| { | { | ||||||
|     return QString::fromUtf8(ak_string.characters_without_null_termination(), static_cast<qsizetype>(ak_string.length())); |     return QString::fromUtf8(ak_string.characters_without_null_termination(), static_cast<qsizetype>(ak_string.length())); | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | AK::URL ak_url_from_qstring(QString const& qstring) | ||||||
|  | { | ||||||
|  |     return AK::URL(qstring.toUtf8().data()); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | AK::URL ak_url_from_qurl(QUrl const& qurl) | ||||||
|  | { | ||||||
|  |     return AK::URL(qurl.toString().toUtf8().data()); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -10,8 +10,12 @@ | ||||||
| #include <AK/Error.h> | #include <AK/Error.h> | ||||||
| #include <AK/String.h> | #include <AK/String.h> | ||||||
| #include <AK/StringView.h> | #include <AK/StringView.h> | ||||||
|  | #include <AK/URL.h> | ||||||
| #include <QString> | #include <QString> | ||||||
|  | #include <QUrl> | ||||||
| 
 | 
 | ||||||
| AK::ByteString ak_byte_string_from_qstring(QString const&); | AK::ByteString ak_byte_string_from_qstring(QString const&); | ||||||
| String ak_string_from_qstring(QString const&); | String ak_string_from_qstring(QString const&); | ||||||
| QString qstring_from_ak_string(StringView); | QString qstring_from_ak_string(StringView); | ||||||
|  | AK::URL ak_url_from_qstring(QString const&); | ||||||
|  | AK::URL ak_url_from_qurl(QUrl const&); | ||||||
|  |  | ||||||
|  | @ -309,7 +309,7 @@ Tab::Tab(BrowserWindow* window, WebContentOptions const& web_content_options, St | ||||||
|     search_selected_text_action->setIcon(load_icon_from_uri("resource://icons/16x16/find.png"sv)); |     search_selected_text_action->setIcon(load_icon_from_uri("resource://icons/16x16/find.png"sv)); | ||||||
|     QObject::connect(search_selected_text_action, &QAction::triggered, this, [this]() { |     QObject::connect(search_selected_text_action, &QAction::triggered, this, [this]() { | ||||||
|         auto url = MUST(String::formatted(Settings::the()->search_engine().query_url, URL::percent_encode(*m_page_context_menu_search_text))); |         auto url = MUST(String::formatted(Settings::the()->search_engine().query_url, URL::percent_encode(*m_page_context_menu_search_text))); | ||||||
|         m_window->new_tab(qstring_from_ak_string(url), Web::HTML::ActivateTab::Yes); |         m_window->new_tab_from_url(AK::URL(url), Web::HTML::ActivateTab::Yes); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     auto take_screenshot = [this](auto type) { |     auto take_screenshot = [this](auto type) { | ||||||
|  | @ -658,10 +658,9 @@ void Tab::focus_location_editor() | ||||||
|     m_location_edit->selectAll(); |     m_location_edit->selectAll(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Tab::navigate(QString const& url_qstring) | void Tab::navigate(AK::URL const& url) | ||||||
| { | { | ||||||
|     auto url_string = ak_string_from_qstring(url_qstring); |     view().load(url); | ||||||
|     view().load(url_string); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Tab::load_html(StringView html) | void Tab::load_html(StringView html) | ||||||
|  | @ -716,14 +715,14 @@ void Tab::copy_link_url(URL const& url) | ||||||
| 
 | 
 | ||||||
| void Tab::location_edit_return_pressed() | void Tab::location_edit_return_pressed() | ||||||
| { | { | ||||||
|     navigate(m_location_edit->text()); |     navigate(ak_url_from_qurl(m_location_edit->text())); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Tab::open_file() | void Tab::open_file() | ||||||
| { | { | ||||||
|     auto filename = QFileDialog::getOpenFileName(this, "Open file", QDir::homePath(), "All Files (*.*)"); |     auto filename = QFileDialog::getOpenFileName(this, "Open file", QDir::homePath(), "All Files (*.*)"); | ||||||
|     if (!filename.isNull()) |     if (!filename.isNull()) | ||||||
|         navigate(filename); |         navigate(ak_url_from_qstring(filename)); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| int Tab::tab_index() | int Tab::tab_index() | ||||||
|  |  | ||||||
|  | @ -33,7 +33,7 @@ public: | ||||||
| 
 | 
 | ||||||
|     WebContentView& view() { return *m_view; } |     WebContentView& view() { return *m_view; } | ||||||
| 
 | 
 | ||||||
|     void navigate(QString const&); |     void navigate(AK::URL const&); | ||||||
|     void load_html(StringView); |     void load_html(StringView); | ||||||
| 
 | 
 | ||||||
|     void back(); |     void back(); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andrew Kaster
						Andrew Kaster