From 6b2a916069a0df08856c6d9fa66c6bf5d0244df0 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 21 Sep 2022 19:33:57 +0100 Subject: [PATCH] LibWeb+WebContent: Move Serenity EventLoop and Font plugins into LibWeb These are exactly what's wanted by headless-browser too, so this saves us some duplication. LibWeb already links LibCore so it should not cause any issues for Ladybird. --- Userland/Libraries/LibWeb/CMakeLists.txt | 3 +++ .../Platform}/EventLoopPluginSerenity.cpp | 6 ++--- .../Platform}/EventLoopPluginSerenity.h | 4 ++-- .../LibWeb/Platform}/FontPluginSerenity.cpp | 24 +++++++++---------- .../LibWeb/Platform}/FontPluginSerenity.h | 6 ++--- .../LibWeb/Platform}/TimerSerenity.cpp | 2 +- .../LibWeb/Platform}/TimerSerenity.h | 4 ++-- Userland/Services/WebContent/CMakeLists.txt | 3 --- Userland/Services/WebContent/main.cpp | 8 +++---- 9 files changed, 30 insertions(+), 30 deletions(-) rename Userland/{Services/WebContent => Libraries/LibWeb/Platform}/EventLoopPluginSerenity.cpp (84%) rename Userland/{Services/WebContent => Libraries/LibWeb/Platform}/EventLoopPluginSerenity.h (83%) rename Userland/{Services/WebContent => Libraries/LibWeb/Platform}/FontPluginSerenity.cpp (62%) rename Userland/{Services/WebContent => Libraries/LibWeb/Platform}/FontPluginSerenity.h (69%) rename Userland/{Services/WebContent => Libraries/LibWeb/Platform}/TimerSerenity.cpp (98%) rename Userland/{Services/WebContent => Libraries/LibWeb/Platform}/TimerSerenity.h (91%) diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index a3de5c4cb4..7312fe898f 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -356,9 +356,12 @@ set(SOURCES Painting/StackingContext.cpp Painting/TextPaintable.cpp Platform/EventLoopPlugin.cpp + Platform/EventLoopPluginSerenity.cpp Platform/FontPlugin.cpp + Platform/FontPluginSerenity.cpp Platform/ImageCodecPlugin.cpp Platform/Timer.cpp + Platform/TimerSerenity.cpp RequestIdleCallback/IdleDeadline.cpp ResizeObserver/ResizeObserver.cpp SVG/AttributeNames.cpp diff --git a/Userland/Services/WebContent/EventLoopPluginSerenity.cpp b/Userland/Libraries/LibWeb/Platform/EventLoopPluginSerenity.cpp similarity index 84% rename from Userland/Services/WebContent/EventLoopPluginSerenity.cpp rename to Userland/Libraries/LibWeb/Platform/EventLoopPluginSerenity.cpp index 15a6c17dd1..db035a1778 100644 --- a/Userland/Services/WebContent/EventLoopPluginSerenity.cpp +++ b/Userland/Libraries/LibWeb/Platform/EventLoopPluginSerenity.cpp @@ -5,12 +5,12 @@ */ #include "EventLoopPluginSerenity.h" -#include "TimerSerenity.h" #include #include #include +#include -namespace WebContent { +namespace Web::Platform { EventLoopPluginSerenity::EventLoopPluginSerenity() = default; EventLoopPluginSerenity::~EventLoopPluginSerenity() = default; @@ -26,7 +26,7 @@ void EventLoopPluginSerenity::deferred_invoke(Function function) Core::deferred_invoke(move(function)); } -NonnullRefPtr EventLoopPluginSerenity::create_timer() +NonnullRefPtr EventLoopPluginSerenity::create_timer() { return TimerSerenity::create(); } diff --git a/Userland/Services/WebContent/EventLoopPluginSerenity.h b/Userland/Libraries/LibWeb/Platform/EventLoopPluginSerenity.h similarity index 83% rename from Userland/Services/WebContent/EventLoopPluginSerenity.h rename to Userland/Libraries/LibWeb/Platform/EventLoopPluginSerenity.h index 0493ac7ab1..9e04e64112 100644 --- a/Userland/Services/WebContent/EventLoopPluginSerenity.h +++ b/Userland/Libraries/LibWeb/Platform/EventLoopPluginSerenity.h @@ -8,7 +8,7 @@ #include -namespace WebContent { +namespace Web::Platform { class EventLoopPluginSerenity final : public Web::Platform::EventLoopPlugin { public: @@ -17,7 +17,7 @@ public: virtual void spin_until(Function goal_condition) override; virtual void deferred_invoke(Function) override; - virtual NonnullRefPtr create_timer() override; + virtual NonnullRefPtr create_timer() override; }; } diff --git a/Userland/Services/WebContent/FontPluginSerenity.cpp b/Userland/Libraries/LibWeb/Platform/FontPluginSerenity.cpp similarity index 62% rename from Userland/Services/WebContent/FontPluginSerenity.cpp rename to Userland/Libraries/LibWeb/Platform/FontPluginSerenity.cpp index b9377b8843..4d588f47d3 100644 --- a/Userland/Services/WebContent/FontPluginSerenity.cpp +++ b/Userland/Libraries/LibWeb/Platform/FontPluginSerenity.cpp @@ -8,7 +8,7 @@ #include #include -namespace WebContent { +namespace Web::Platform { FontPluginSerenity::FontPluginSerenity() { @@ -26,26 +26,26 @@ Gfx::Font& FontPluginSerenity::default_fixed_width_font() return Gfx::FontDatabase::default_fixed_width_font(); } -String FontPluginSerenity::generic_font_name(Web::Platform::GenericFont generic_font) +String FontPluginSerenity::generic_font_name(GenericFont generic_font) { // FIXME: Replace hard-coded font names with a relevant call to FontDatabase. // Currently, we cannot request the default font's name, or request it at a specific size and weight. // So, hard-coded font names it is. switch (generic_font) { - case Web::Platform::GenericFont::SansSerif: - case Web::Platform::GenericFont::UiSansSerif: - case Web::Platform::GenericFont::Cursive: - case Web::Platform::GenericFont::UiRounded: + case GenericFont::SansSerif: + case GenericFont::UiSansSerif: + case GenericFont::Cursive: + case GenericFont::UiRounded: return "Katica"; - case Web::Platform::GenericFont::Monospace: - case Web::Platform::GenericFont::UiMonospace: + case GenericFont::Monospace: + case GenericFont::UiMonospace: return "Csilla"; - case Web::Platform::GenericFont::Serif: - case Web::Platform::GenericFont::UiSerif: + case GenericFont::Serif: + case GenericFont::UiSerif: return "Roman"; - case Web::Platform::GenericFont::Fantasy: + case GenericFont::Fantasy: return "Comic Book"; - case Web::Platform::GenericFont::__Count: + case GenericFont::__Count: VERIFY_NOT_REACHED(); } VERIFY_NOT_REACHED(); diff --git a/Userland/Services/WebContent/FontPluginSerenity.h b/Userland/Libraries/LibWeb/Platform/FontPluginSerenity.h similarity index 69% rename from Userland/Services/WebContent/FontPluginSerenity.h rename to Userland/Libraries/LibWeb/Platform/FontPluginSerenity.h index 371b0833a6..9ea8c0a1be 100644 --- a/Userland/Services/WebContent/FontPluginSerenity.h +++ b/Userland/Libraries/LibWeb/Platform/FontPluginSerenity.h @@ -9,16 +9,16 @@ #include #include -namespace WebContent { +namespace Web::Platform { -class FontPluginSerenity final : public Web::Platform::FontPlugin { +class FontPluginSerenity final : public FontPlugin { public: FontPluginSerenity(); virtual ~FontPluginSerenity(); virtual Gfx::Font& default_font() override; virtual Gfx::Font& default_fixed_width_font() override; - virtual String generic_font_name(Web::Platform::GenericFont) override; + virtual String generic_font_name(GenericFont) override; }; } diff --git a/Userland/Services/WebContent/TimerSerenity.cpp b/Userland/Libraries/LibWeb/Platform/TimerSerenity.cpp similarity index 98% rename from Userland/Services/WebContent/TimerSerenity.cpp rename to Userland/Libraries/LibWeb/Platform/TimerSerenity.cpp index a702ba2eca..cef22b8768 100644 --- a/Userland/Services/WebContent/TimerSerenity.cpp +++ b/Userland/Libraries/LibWeb/Platform/TimerSerenity.cpp @@ -8,7 +8,7 @@ #include #include -namespace WebContent { +namespace Web::Platform { NonnullRefPtr TimerSerenity::create() { diff --git a/Userland/Services/WebContent/TimerSerenity.h b/Userland/Libraries/LibWeb/Platform/TimerSerenity.h similarity index 91% rename from Userland/Services/WebContent/TimerSerenity.h rename to Userland/Libraries/LibWeb/Platform/TimerSerenity.h index d0f9200839..4f368c8a5d 100644 --- a/Userland/Services/WebContent/TimerSerenity.h +++ b/Userland/Libraries/LibWeb/Platform/TimerSerenity.h @@ -10,9 +10,9 @@ #include #include -namespace WebContent { +namespace Web::Platform { -class TimerSerenity final : public Web::Platform::Timer { +class TimerSerenity final : public Timer { public: static NonnullRefPtr create(); diff --git a/Userland/Services/WebContent/CMakeLists.txt b/Userland/Services/WebContent/CMakeLists.txt index ca7b7395a8..e4643e70c4 100644 --- a/Userland/Services/WebContent/CMakeLists.txt +++ b/Userland/Services/WebContent/CMakeLists.txt @@ -10,11 +10,8 @@ compile_ipc(WebContentClient.ipc WebContentClientEndpoint.h) set(SOURCES ConnectionFromClient.cpp ConsoleGlobalObject.cpp - EventLoopPluginSerenity.cpp - FontPluginSerenity.cpp ImageCodecPluginSerenity.cpp PageHost.cpp - TimerSerenity.cpp WebContentClientEndpoint.h WebContentConsoleClient.cpp WebContentServerEndpoint.h diff --git a/Userland/Services/WebContent/main.cpp b/Userland/Services/WebContent/main.cpp index ce7c2c5266..ea5c757617 100644 --- a/Userland/Services/WebContent/main.cpp +++ b/Userland/Services/WebContent/main.cpp @@ -4,8 +4,6 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include "EventLoopPluginSerenity.h" -#include "FontPluginSerenity.h" #include "ImageCodecPluginSerenity.h" #include #include @@ -14,6 +12,8 @@ #include #include #include +#include +#include #include #include #include @@ -30,9 +30,9 @@ ErrorOr serenity_main(Main::Arguments) TRY(Core::System::unveil("/tmp/user/%uid/portal/websocket", "rw")); TRY(Core::System::unveil(nullptr, nullptr)); - Web::Platform::EventLoopPlugin::install(*new WebContent::EventLoopPluginSerenity); + Web::Platform::EventLoopPlugin::install(*new Web::Platform::EventLoopPluginSerenity); Web::Platform::ImageCodecPlugin::install(*new WebContent::ImageCodecPluginSerenity); - Web::Platform::FontPlugin::install(*new WebContent::FontPluginSerenity); + Web::Platform::FontPlugin::install(*new Web::Platform::FontPluginSerenity); Web::WebSockets::WebSocketClientManager::initialize(TRY(WebView::WebSocketClientManagerAdapter::try_create())); Web::ResourceLoader::initialize(TRY(WebView::RequestServerAdapter::try_create()));