Parcourir la source

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.
Andrew Kaster il y a 2 ans
Parent
commit
506b03740c

+ 5 - 1
Ladybird/BrowserWindow.cpp

@@ -26,7 +26,9 @@
 #include <QTabBar>
 
 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);
 }
+
+}

+ 6 - 2
Ladybird/BrowserWindow.h

@@ -17,12 +17,14 @@
 #include <QTabWidget>
 #include <QToolBar>
 
-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;
 };
+
+}

+ 2 - 2
Ladybird/ConsoleWidget.cpp

@@ -20,10 +20,10 @@
 #include <QTextEdit>
 #include <QVBoxLayout>
 
-bool is_using_dark_system_theme(QWidget&);
-
 namespace Ladybird {
 
+bool is_using_dark_system_theme(QWidget&);
+
 ConsoleWidget::ConsoleWidget()
 {
     setLayout(new QVBoxLayout);

+ 2 - 2
Ladybird/ConsoleWidget.h

@@ -16,10 +16,10 @@
 #include <QWidget>
 
 class QLineEdit;
-class WebContentView;
-
 namespace Ladybird {
 
+class WebContentView;
+
 class ConsoleWidget final : public QWidget {
     Q_OBJECT
 public:

+ 2 - 2
Ladybird/HelperProcess.cpp

@@ -11,7 +11,7 @@ ErrorOr<NonnullRefPtr<WebView::WebContentClient>> 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<NonnullRefPtr<WebView::WebContentClient>> 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);

+ 1 - 1
Ladybird/HelperProcess.h

@@ -19,6 +19,6 @@ ErrorOr<NonnullRefPtr<WebView::WebContentClient>> launch_web_content_process(Web
     WebView::EnableCallgrindProfiling,
     WebView::IsLayoutTestMode,
     WebView::UseJavaScriptBytecode,
-    UseLagomNetworking);
+    Ladybird::UseLagomNetworking);
 
 ErrorOr<NonnullRefPtr<Protocol::RequestClient>> launch_request_server_process(ReadonlySpan<String> candidate_request_server_paths);

+ 4 - 0
Ladybird/LocationEdit.cpp

@@ -12,6 +12,8 @@
 #include <QTextLayout>
 #include <QTimer>
 
+namespace Ladybird {
+
 LocationEdit::LocationEdit(QWidget* parent)
     : QLineEdit(parent)
 {
@@ -86,3 +88,5 @@ void LocationEdit::highlight_location()
     QInputMethodEvent event(QString(), attributes);
     QCoreApplication::sendEvent(this, &event);
 }
+
+}

+ 4 - 0
Ladybird/LocationEdit.h

@@ -8,6 +8,8 @@
 
 #include <QLineEdit>
 
+namespace Ladybird {
+
 class LocationEdit final : public QLineEdit {
     Q_OBJECT
 public:
@@ -19,3 +21,5 @@ private:
 
     void highlight_location();
 };
+
+}

+ 4 - 0
Ladybird/RequestManagerQt.cpp

@@ -8,6 +8,8 @@
 #include <AK/JsonObject.h>
 #include <QNetworkCookie>
 
+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() });
 }
+
+}

+ 4 - 0
Ladybird/RequestManagerQt.h

@@ -10,6 +10,8 @@
 #include <QtNetwork/QNetworkAccessManager>
 #include <QtNetwork/QNetworkReply>
 
+namespace Ladybird {
+
 class RequestManagerQt
     : public QObject
     , public Web::ResourceLoaderConnector {
@@ -57,3 +59,5 @@ private:
     HashMap<QNetworkReply*, NonnullRefPtr<Request>> m_pending;
     QNetworkAccessManager* m_qnam { nullptr };
 };
+
+}

+ 1 - 1
Ladybird/Settings.cpp

@@ -9,7 +9,7 @@
 #include <AK/URL.h>
 #include <BrowserSettings/Defaults.h>
 
-namespace Browser {
+namespace Ladybird {
 
 static QString rebase_default_url_on_serenity_resource_root(StringView default_url)
 {

+ 1 - 1
Ladybird/Settings.h

@@ -9,7 +9,7 @@
 #include <AK/DeprecatedString.h>
 #include <QSettings>
 
-namespace Browser {
+namespace Ladybird {
 
 class Settings : public QObject {
 public:

+ 5 - 1
Ladybird/SettingsDialog.cpp

@@ -9,7 +9,9 @@
 #include <QCloseEvent>
 #include <QLabel>
 
-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());
 }
+
+}

+ 4 - 0
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 };
 };
+
+}

+ 5 - 2
Ladybird/TVGIconEngine.cpp

@@ -4,6 +4,8 @@
  * SPDX-License-Identifier: BSD-2-Clause
  */
 
+#include "TVGIconEngine.h"
+#include "Utilities.h"
 #include <AK/MemoryStream.h>
 #include <AK/String.h>
 #include <LibGfx/Painter.h>
@@ -12,8 +14,7 @@
 #include <QPainter>
 #include <QPixmapCache>
 
-#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;
 }
+
+}

+ 4 - 0
Ladybird/TVGIconEngine.h

@@ -12,6 +12,8 @@
 #include <LibGfx/ImageFormats/TinyVGLoader.h>
 #include <QIconEngine>
 
+namespace Ladybird {
+
 class TVGIconEngine : public QIconEngine {
 public:
     TVGIconEngine(Gfx::TinyVGDecodedImageData const& image_data)
@@ -62,3 +64,5 @@ private:
     NonnullRefPtr<Gfx::TinyVGDecodedImageData> m_image_data;
     unsigned m_cache_id { next_cache_id() };
 };
+
+}

+ 6 - 1
Ladybird/Tab.cpp

@@ -30,7 +30,10 @@
 #include <QResizeEvent>
 
 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);
 }
+
+}

+ 4 - 3
Ladybird/Tab.h

@@ -18,12 +18,11 @@
 #include <QToolButton>
 #include <QWidget>
 
-class BrowserWindow;
-
 namespace Ladybird {
+
+class BrowserWindow;
 class ConsoleWidget;
 class InspectorWidget;
-}
 
 class Tab final : public QWidget {
     Q_OBJECT
@@ -117,3 +116,5 @@ private:
     OwnPtr<QMenu> m_console_context_menu;
     Ladybird::InspectorWidget* m_inspector_widget { nullptr };
 };
+
+}

+ 4 - 0
Ladybird/Types.h

@@ -6,7 +6,11 @@
 
 #pragma once
 
+namespace Ladybird {
+
 enum UseLagomNetworking {
     No,
     Yes
 };
+
+}

+ 1 - 1
Ladybird/WebContent/main.cpp

@@ -77,7 +77,7 @@ ErrorOr<int> 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);

+ 4 - 0
Ladybird/WebContentView.cpp

@@ -49,6 +49,8 @@
 #include <QTimer>
 #include <QToolTip>
 
+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<String> WebContentView::dump_layout_tree()
 {
     return String::from_deprecated_string(client().dump_layout_tree());
 }
+
+}

+ 4 - 0
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;
 };
+
+}

+ 1 - 2
Ladybird/WebDriver/main.cpp

@@ -4,7 +4,6 @@
  * SPDX-License-Identifier: BSD-2-Clause
  */
 
-#include "../HelperProcess.h"
 #include "../Utilities.h"
 #include <AK/Platform.h>
 #include <LibCore/ArgsParser.h>
@@ -58,7 +57,7 @@ static ErrorOr<pid_t> launch_headless_browser(DeprecatedString const& socket_pat
 
 ErrorOr<int> 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;

+ 20 - 16
Ladybird/main.cpp

@@ -22,7 +22,24 @@
 #include <LibSQL/SQLClient.h>
 #include <QApplication>
 
-AK::OwnPtr<Browser::Settings> s_settings;
+namespace Ladybird {
+
+OwnPtr<Ladybird::Settings> 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<void> handle_attached_debugger()
 {
@@ -102,8 +119,8 @@ ErrorOr<int> 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<int> 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;
-}

+ 1 - 1
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));