From 506b03740c8879abd0b658b91a7a67c90fedcf02 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Wed, 2 Aug 2023 11:52:59 -0600 Subject: [PATCH] Ladybird: Move classes and types into the Ladybird namespace We were super inconsistent about this, with most "new" classes living in the Ladybird namespace, while "old" ones were in the global namespace, or even sitting in the Browser namespace. --- Ladybird/BrowserWindow.cpp | 6 ++++- Ladybird/BrowserWindow.h | 8 ++++-- Ladybird/ConsoleWidget.cpp | 4 +-- Ladybird/ConsoleWidget.h | 4 +-- Ladybird/HelperProcess.cpp | 4 +-- Ladybird/HelperProcess.h | 2 +- Ladybird/LocationEdit.cpp | 4 +++ Ladybird/LocationEdit.h | 4 +++ Ladybird/RequestManagerQt.cpp | 4 +++ Ladybird/RequestManagerQt.h | 4 +++ Ladybird/Settings.cpp | 2 +- Ladybird/Settings.h | 2 +- Ladybird/SettingsDialog.cpp | 6 ++++- Ladybird/SettingsDialog.h | 4 +++ Ladybird/TVGIconEngine.cpp | 7 +++-- Ladybird/TVGIconEngine.h | 4 +++ Ladybird/Tab.cpp | 7 ++++- Ladybird/Tab.h | 7 ++--- Ladybird/Types.h | 4 +++ Ladybird/WebContent/main.cpp | 2 +- Ladybird/WebContentView.cpp | 4 +++ Ladybird/WebContentView.h | 4 +++ Ladybird/WebDriver/main.cpp | 3 +-- Ladybird/main.cpp | 36 ++++++++++++++----------- Userland/Utilities/headless-browser.cpp | 2 +- 25 files changed, 99 insertions(+), 39 deletions(-) diff --git a/Ladybird/BrowserWindow.cpp b/Ladybird/BrowserWindow.cpp index ae44684351f..24727f4ed9e 100644 --- a/Ladybird/BrowserWindow.cpp +++ b/Ladybird/BrowserWindow.cpp @@ -26,7 +26,9 @@ #include extern DeprecatedString s_serenity_resource_root; -extern Browser::Settings* s_settings; + +namespace Ladybird { +extern Settings* s_settings; static QIcon const& app_icon() { @@ -688,3 +690,5 @@ bool BrowserWindow::eventFilter(QObject* obj, QEvent* event) return QMainWindow::eventFilter(obj, event); } + +} diff --git a/Ladybird/BrowserWindow.h b/Ladybird/BrowserWindow.h index d0a25fba39a..cd33b8a42a2 100644 --- a/Ladybird/BrowserWindow.h +++ b/Ladybird/BrowserWindow.h @@ -17,12 +17,14 @@ #include #include -class WebContentView; - namespace Browser { class CookieJar; } +namespace Ladybird { + +class WebContentView; + class BrowserWindow : public QMainWindow { Q_OBJECT public: @@ -119,3 +121,5 @@ private: WebView::UseJavaScriptBytecode m_use_javascript_bytecode; UseLagomNetworking m_use_lagom_networking; }; + +} diff --git a/Ladybird/ConsoleWidget.cpp b/Ladybird/ConsoleWidget.cpp index 1b34ba12646..01cf82376ae 100644 --- a/Ladybird/ConsoleWidget.cpp +++ b/Ladybird/ConsoleWidget.cpp @@ -20,10 +20,10 @@ #include #include -bool is_using_dark_system_theme(QWidget&); - namespace Ladybird { +bool is_using_dark_system_theme(QWidget&); + ConsoleWidget::ConsoleWidget() { setLayout(new QVBoxLayout); diff --git a/Ladybird/ConsoleWidget.h b/Ladybird/ConsoleWidget.h index 98f93aa6b12..2b087299846 100644 --- a/Ladybird/ConsoleWidget.h +++ b/Ladybird/ConsoleWidget.h @@ -16,10 +16,10 @@ #include class QLineEdit; -class WebContentView; - namespace Ladybird { +class WebContentView; + class ConsoleWidget final : public QWidget { Q_OBJECT public: diff --git a/Ladybird/HelperProcess.cpp b/Ladybird/HelperProcess.cpp index e1637d88a2f..638e47fd8dc 100644 --- a/Ladybird/HelperProcess.cpp +++ b/Ladybird/HelperProcess.cpp @@ -11,7 +11,7 @@ ErrorOr> launch_web_content_process(Web WebView::EnableCallgrindProfiling enable_callgrind_profiling, WebView::IsLayoutTestMode is_layout_test_mode, WebView::UseJavaScriptBytecode use_javascript_bytecode, - UseLagomNetworking use_lagom_networking) + Ladybird::UseLagomNetworking use_lagom_networking) { int socket_fds[2] {}; TRY(Core::System::socketpair(AF_LOCAL, SOCK_STREAM, 0, socket_fds)); @@ -55,7 +55,7 @@ ErrorOr> launch_web_content_process(Web arguments.append("--layout-test-mode"sv); if (use_javascript_bytecode == WebView::UseJavaScriptBytecode::Yes) arguments.append("--use-bytecode"sv); - if (use_lagom_networking == UseLagomNetworking::Yes) + if (use_lagom_networking == Ladybird::UseLagomNetworking::Yes) arguments.append("--use-lagom-networking"sv); result = Core::System::exec(arguments[0], arguments.span(), Core::System::SearchInPath::Yes); diff --git a/Ladybird/HelperProcess.h b/Ladybird/HelperProcess.h index a4a175079a7..2946f38ead6 100644 --- a/Ladybird/HelperProcess.h +++ b/Ladybird/HelperProcess.h @@ -19,6 +19,6 @@ ErrorOr> launch_web_content_process(Web WebView::EnableCallgrindProfiling, WebView::IsLayoutTestMode, WebView::UseJavaScriptBytecode, - UseLagomNetworking); + Ladybird::UseLagomNetworking); ErrorOr> launch_request_server_process(ReadonlySpan candidate_request_server_paths); diff --git a/Ladybird/LocationEdit.cpp b/Ladybird/LocationEdit.cpp index a9d9b9ba4d9..eb7bae563b6 100644 --- a/Ladybird/LocationEdit.cpp +++ b/Ladybird/LocationEdit.cpp @@ -12,6 +12,8 @@ #include #include +namespace Ladybird { + LocationEdit::LocationEdit(QWidget* parent) : QLineEdit(parent) { @@ -86,3 +88,5 @@ void LocationEdit::highlight_location() QInputMethodEvent event(QString(), attributes); QCoreApplication::sendEvent(this, &event); } + +} diff --git a/Ladybird/LocationEdit.h b/Ladybird/LocationEdit.h index f2607e0fc1b..9cec05d144f 100644 --- a/Ladybird/LocationEdit.h +++ b/Ladybird/LocationEdit.h @@ -8,6 +8,8 @@ #include +namespace Ladybird { + class LocationEdit final : public QLineEdit { Q_OBJECT public: @@ -19,3 +21,5 @@ private: void highlight_location(); }; + +} diff --git a/Ladybird/RequestManagerQt.cpp b/Ladybird/RequestManagerQt.cpp index 7138243e89a..cce30fc8f49 100644 --- a/Ladybird/RequestManagerQt.cpp +++ b/Ladybird/RequestManagerQt.cpp @@ -8,6 +8,8 @@ #include #include +namespace Ladybird { + RequestManagerQt::RequestManagerQt() { m_qnam = new QNetworkAccessManager(this); @@ -107,3 +109,5 @@ void RequestManagerQt::Request::did_finish() bool success = http_status_code != 0; on_buffered_request_finish(success, buffer.length(), response_headers, http_status_code, ReadonlyBytes { buffer.data(), (size_t)buffer.size() }); } + +} diff --git a/Ladybird/RequestManagerQt.h b/Ladybird/RequestManagerQt.h index eb7e13bb2ba..9728db76e31 100644 --- a/Ladybird/RequestManagerQt.h +++ b/Ladybird/RequestManagerQt.h @@ -10,6 +10,8 @@ #include #include +namespace Ladybird { + class RequestManagerQt : public QObject , public Web::ResourceLoaderConnector { @@ -57,3 +59,5 @@ private: HashMap> m_pending; QNetworkAccessManager* m_qnam { nullptr }; }; + +} diff --git a/Ladybird/Settings.cpp b/Ladybird/Settings.cpp index 85c97f207be..4a8a7ec3e7e 100644 --- a/Ladybird/Settings.cpp +++ b/Ladybird/Settings.cpp @@ -9,7 +9,7 @@ #include #include -namespace Browser { +namespace Ladybird { static QString rebase_default_url_on_serenity_resource_root(StringView default_url) { diff --git a/Ladybird/Settings.h b/Ladybird/Settings.h index e23448bc6c7..6662bde11f5 100644 --- a/Ladybird/Settings.h +++ b/Ladybird/Settings.h @@ -9,7 +9,7 @@ #include #include -namespace Browser { +namespace Ladybird { class Settings : public QObject { public: diff --git a/Ladybird/SettingsDialog.cpp b/Ladybird/SettingsDialog.cpp index f6027e43c3b..3b3e8aa6208 100644 --- a/Ladybird/SettingsDialog.cpp +++ b/Ladybird/SettingsDialog.cpp @@ -9,7 +9,9 @@ #include #include -extern Browser::Settings* s_settings; +namespace Ladybird { + +extern Settings* s_settings; SettingsDialog::SettingsDialog(QMainWindow* window) : m_window(window) @@ -44,3 +46,5 @@ void SettingsDialog::save() // FIXME: Validate data. s_settings->set_new_tab_page(m_new_tab_page->text()); } + +} diff --git a/Ladybird/SettingsDialog.h b/Ladybird/SettingsDialog.h index cfeeff0b07f..2a8402f8648 100644 --- a/Ladybird/SettingsDialog.h +++ b/Ladybird/SettingsDialog.h @@ -12,6 +12,8 @@ #pragma once +namespace Ladybird { + class SettingsDialog : public QDialog { Q_OBJECT public: @@ -27,3 +29,5 @@ private: QLineEdit* m_new_tab_page { nullptr }; QMainWindow* m_window { nullptr }; }; + +} diff --git a/Ladybird/TVGIconEngine.cpp b/Ladybird/TVGIconEngine.cpp index 74b2dd137d2..0ec4aac205c 100644 --- a/Ladybird/TVGIconEngine.cpp +++ b/Ladybird/TVGIconEngine.cpp @@ -4,6 +4,8 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include "TVGIconEngine.h" +#include "Utilities.h" #include #include #include @@ -12,8 +14,7 @@ #include #include -#include "TVGIconEngine.h" -#include "Utilities.h" +namespace Ladybird { void TVGIconEngine::paint(QPainter* qpainter, QRect const& rect, QIcon::Mode mode, QIcon::State state) { @@ -70,3 +71,5 @@ TVGIconEngine* TVGIconEngine::from_file(QString const& path) return new TVGIconEngine(tvg.release_value()); return nullptr; } + +} diff --git a/Ladybird/TVGIconEngine.h b/Ladybird/TVGIconEngine.h index 68cd1071f6c..eecb5230ca2 100644 --- a/Ladybird/TVGIconEngine.h +++ b/Ladybird/TVGIconEngine.h @@ -12,6 +12,8 @@ #include #include +namespace Ladybird { + class TVGIconEngine : public QIconEngine { public: TVGIconEngine(Gfx::TinyVGDecodedImageData const& image_data) @@ -62,3 +64,5 @@ private: NonnullRefPtr m_image_data; unsigned m_cache_id { next_cache_id() }; }; + +} diff --git a/Ladybird/Tab.cpp b/Ladybird/Tab.cpp index 58a34443713..ae146115c5e 100644 --- a/Ladybird/Tab.cpp +++ b/Ladybird/Tab.cpp @@ -30,7 +30,10 @@ #include extern DeprecatedString s_serenity_resource_root; -extern Browser::Settings* s_settings; + +namespace Ladybird { + +extern Settings* s_settings; static QIcon create_tvg_icon_with_theme_colors(QString name, QPalette const& palette) { @@ -691,3 +694,5 @@ void Tab::close_sub_widgets() close_widget_window(m_console_widget); close_widget_window(m_inspector_widget); } + +} diff --git a/Ladybird/Tab.h b/Ladybird/Tab.h index a99169323fa..2d472a73547 100644 --- a/Ladybird/Tab.h +++ b/Ladybird/Tab.h @@ -18,12 +18,11 @@ #include #include -class BrowserWindow; - namespace Ladybird { + +class BrowserWindow; class ConsoleWidget; class InspectorWidget; -} class Tab final : public QWidget { Q_OBJECT @@ -117,3 +116,5 @@ private: OwnPtr m_console_context_menu; Ladybird::InspectorWidget* m_inspector_widget { nullptr }; }; + +} diff --git a/Ladybird/Types.h b/Ladybird/Types.h index 1468c40ba34..8611e39c635 100644 --- a/Ladybird/Types.h +++ b/Ladybird/Types.h @@ -6,7 +6,11 @@ #pragma once +namespace Ladybird { + enum UseLagomNetworking { No, Yes }; + +} diff --git a/Ladybird/WebContent/main.cpp b/Ladybird/WebContent/main.cpp index b43cc7ad173..1be9cd931df 100644 --- a/Ladybird/WebContent/main.cpp +++ b/Ladybird/WebContent/main.cpp @@ -77,7 +77,7 @@ ErrorOr serenity_main(Main::Arguments arguments) auto protocol_client = TRY(launch_request_server_process(candidate_request_server_paths)); Web::ResourceLoader::initialize(TRY(WebView::RequestServerAdapter::try_create(move(protocol_client)))); } else { - Web::ResourceLoader::initialize(RequestManagerQt::create()); + Web::ResourceLoader::initialize(Ladybird::RequestManagerQt::create()); } JS::Bytecode::Interpreter::set_enabled(use_javascript_bytecode); diff --git a/Ladybird/WebContentView.cpp b/Ladybird/WebContentView.cpp index b7d4e733f5c..5280c3b73d1 100644 --- a/Ladybird/WebContentView.cpp +++ b/Ladybird/WebContentView.cpp @@ -49,6 +49,8 @@ #include #include +namespace Ladybird { + bool is_using_dark_system_theme(QWidget&); WebContentView::WebContentView(StringView webdriver_content_ipc_path, WebView::EnableCallgrindProfiling enable_callgrind_profiling, WebView::UseJavaScriptBytecode use_javascript_bytecode, UseLagomNetworking use_lagom_networking) @@ -820,3 +822,5 @@ ErrorOr WebContentView::dump_layout_tree() { return String::from_deprecated_string(client().dump_layout_tree()); } + +} diff --git a/Ladybird/WebContentView.h b/Ladybird/WebContentView.h index b01125a61cd..2c633cfa379 100644 --- a/Ladybird/WebContentView.h +++ b/Ladybird/WebContentView.h @@ -34,6 +34,8 @@ class WebContentClient; using WebView::WebContentClient; +namespace Ladybird { + class Tab; class WebContentView final @@ -117,3 +119,5 @@ private: StringView m_webdriver_content_ipc_path; }; + +} diff --git a/Ladybird/WebDriver/main.cpp b/Ladybird/WebDriver/main.cpp index 5734753ba60..76fcf3b6725 100644 --- a/Ladybird/WebDriver/main.cpp +++ b/Ladybird/WebDriver/main.cpp @@ -4,7 +4,6 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include "../HelperProcess.h" #include "../Utilities.h" #include #include @@ -58,7 +57,7 @@ static ErrorOr launch_headless_browser(DeprecatedString const& socket_pat ErrorOr serenity_main(Main::Arguments arguments) { - // Note: only creating this to get access to its static methods in HelperProcess + // Note: only creating this to get access to its static methods in Utilities QCoreApplication application(arguments.argc, arguments.argv); auto listen_address = "0.0.0.0"sv; diff --git a/Ladybird/main.cpp b/Ladybird/main.cpp index 886cad9558e..c1bb7bd03af 100644 --- a/Ladybird/main.cpp +++ b/Ladybird/main.cpp @@ -22,7 +22,24 @@ #include #include -AK::OwnPtr s_settings; +namespace Ladybird { + +OwnPtr s_settings; + +bool is_using_dark_system_theme(QWidget& widget) +{ + // FIXME: Qt does not provide any method to query if the system is using a dark theme. We will have to implement + // platform-specific methods if we wish to have better detection. For now, this inspects if Qt is using a + // dark color for widget backgrounds using Rec. 709 luma coefficients. + // https://en.wikipedia.org/wiki/Rec._709#Luma_coefficients + + auto color = widget.palette().color(widget.backgroundRole()); + auto luma = 0.2126f * color.redF() + 0.7152f * color.greenF() + 0.0722f * color.blueF(); + + return luma <= 0.5f; +} + +} static ErrorOr handle_attached_debugger() { @@ -102,8 +119,8 @@ ErrorOr serenity_main(Main::Arguments arguments) auto cookie_jar = database ? TRY(Browser::CookieJar::create(*database)) : Browser::CookieJar::create(); - s_settings = adopt_own_if_nonnull(new Browser::Settings()); - BrowserWindow window(cookie_jar, webdriver_content_ipc_path, enable_callgrind_profiling ? WebView::EnableCallgrindProfiling::Yes : WebView::EnableCallgrindProfiling::No, use_ast_interpreter ? WebView::UseJavaScriptBytecode::No : WebView::UseJavaScriptBytecode::Yes, use_lagom_networking ? UseLagomNetworking::Yes : UseLagomNetworking::No); + Ladybird::s_settings = adopt_own_if_nonnull(new Ladybird::Settings()); + Ladybird::BrowserWindow window(cookie_jar, webdriver_content_ipc_path, enable_callgrind_profiling ? WebView::EnableCallgrindProfiling::Yes : WebView::EnableCallgrindProfiling::No, use_ast_interpreter ? WebView::UseJavaScriptBytecode::No : WebView::UseJavaScriptBytecode::Yes, use_lagom_networking ? Ladybird::UseLagomNetworking::Yes : Ladybird::UseLagomNetworking::No); window.setWindowTitle("Ladybird"); window.resize(800, 600); window.show(); @@ -116,16 +133,3 @@ ErrorOr serenity_main(Main::Arguments arguments) return event_loop.exec(); } - -bool is_using_dark_system_theme(QWidget& widget) -{ - // FIXME: Qt does not provide any method to query if the system is using a dark theme. We will have to implement - // platform-specific methods if we wish to have better detection. For now, this inspects if Qt is using a - // dark color for widget backgrounds using Rec. 709 luma coefficients. - // https://en.wikipedia.org/wiki/Rec._709#Luma_coefficients - - auto color = widget.palette().color(widget.backgroundRole()); - auto luma = 0.2126f * color.redF() + 0.7152f * color.greenF() + 0.0722f * color.blueF(); - - return luma <= 0.5f; -} diff --git a/Userland/Utilities/headless-browser.cpp b/Userland/Utilities/headless-browser.cpp index b060cde6778..f841b0e42ee 100644 --- a/Userland/Utilities/headless-browser.cpp +++ b/Userland/Utilities/headless-browser.cpp @@ -58,7 +58,7 @@ public: (void)use_javascript_bytecode; #else auto candidate_web_content_paths = TRY(get_paths_for_helper_process("WebContent"sv)); - view->m_client_state.client = TRY(launch_web_content_process(*view, candidate_web_content_paths, WebView::EnableCallgrindProfiling::No, is_layout_test_mode, use_javascript_bytecode, UseLagomNetworking::No)); + view->m_client_state.client = TRY(launch_web_content_process(*view, candidate_web_content_paths, WebView::EnableCallgrindProfiling::No, is_layout_test_mode, use_javascript_bytecode, Ladybird::UseLagomNetworking::No)); #endif view->client().async_update_system_theme(move(theme));