diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2022-09-21 19:33:57 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-09-21 20:42:36 +0100 |
commit | 6b2a916069a0df08856c6d9fa66c6bf5d0244df0 (patch) | |
tree | 0785afae53930cffeb33fd76b361eede441d5653 /Userland/Libraries/LibWeb | |
parent | 69dd158f91480551a4b7e1205c3fab77c507fc1a (diff) | |
download | serenity-6b2a916069a0df08856c6d9fa66c6bf5d0244df0.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibWeb')
7 files changed, 264 insertions, 0 deletions
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/Libraries/LibWeb/Platform/EventLoopPluginSerenity.cpp b/Userland/Libraries/LibWeb/Platform/EventLoopPluginSerenity.cpp new file mode 100644 index 0000000000..db035a1778 --- /dev/null +++ b/Userland/Libraries/LibWeb/Platform/EventLoopPluginSerenity.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "EventLoopPluginSerenity.h" +#include <AK/Function.h> +#include <AK/NonnullRefPtr.h> +#include <LibCore/EventLoop.h> +#include <LibWeb/Platform/TimerSerenity.h> + +namespace Web::Platform { + +EventLoopPluginSerenity::EventLoopPluginSerenity() = default; +EventLoopPluginSerenity::~EventLoopPluginSerenity() = default; + +void EventLoopPluginSerenity::spin_until(Function<bool()> goal_condition) +{ + Core::EventLoop::current().spin_until(move(goal_condition)); +} + +void EventLoopPluginSerenity::deferred_invoke(Function<void()> function) +{ + VERIFY(function); + Core::deferred_invoke(move(function)); +} + +NonnullRefPtr<Timer> EventLoopPluginSerenity::create_timer() +{ + return TimerSerenity::create(); +} + +} diff --git a/Userland/Libraries/LibWeb/Platform/EventLoopPluginSerenity.h b/Userland/Libraries/LibWeb/Platform/EventLoopPluginSerenity.h new file mode 100644 index 0000000000..9e04e64112 --- /dev/null +++ b/Userland/Libraries/LibWeb/Platform/EventLoopPluginSerenity.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <LibWeb/Platform/EventLoopPlugin.h> + +namespace Web::Platform { + +class EventLoopPluginSerenity final : public Web::Platform::EventLoopPlugin { +public: + EventLoopPluginSerenity(); + virtual ~EventLoopPluginSerenity() override; + + virtual void spin_until(Function<bool()> goal_condition) override; + virtual void deferred_invoke(Function<void()>) override; + virtual NonnullRefPtr<Timer> create_timer() override; +}; + +} diff --git a/Userland/Libraries/LibWeb/Platform/FontPluginSerenity.cpp b/Userland/Libraries/LibWeb/Platform/FontPluginSerenity.cpp new file mode 100644 index 0000000000..4d588f47d3 --- /dev/null +++ b/Userland/Libraries/LibWeb/Platform/FontPluginSerenity.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "FontPluginSerenity.h" +#include <AK/String.h> +#include <LibGfx/Font/FontDatabase.h> + +namespace Web::Platform { + +FontPluginSerenity::FontPluginSerenity() +{ +} + +FontPluginSerenity::~FontPluginSerenity() = default; + +Gfx::Font& FontPluginSerenity::default_font() +{ + return Gfx::FontDatabase::default_font(); +} + +Gfx::Font& FontPluginSerenity::default_fixed_width_font() +{ + return Gfx::FontDatabase::default_fixed_width_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 GenericFont::SansSerif: + case GenericFont::UiSansSerif: + case GenericFont::Cursive: + case GenericFont::UiRounded: + return "Katica"; + case GenericFont::Monospace: + case GenericFont::UiMonospace: + return "Csilla"; + case GenericFont::Serif: + case GenericFont::UiSerif: + return "Roman"; + case GenericFont::Fantasy: + return "Comic Book"; + case GenericFont::__Count: + VERIFY_NOT_REACHED(); + } + VERIFY_NOT_REACHED(); +} + +} diff --git a/Userland/Libraries/LibWeb/Platform/FontPluginSerenity.h b/Userland/Libraries/LibWeb/Platform/FontPluginSerenity.h new file mode 100644 index 0000000000..9ea8c0a1be --- /dev/null +++ b/Userland/Libraries/LibWeb/Platform/FontPluginSerenity.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <AK/Vector.h> +#include <LibWeb/Platform/FontPlugin.h> + +namespace Web::Platform { + +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(GenericFont) override; +}; + +} diff --git a/Userland/Libraries/LibWeb/Platform/TimerSerenity.cpp b/Userland/Libraries/LibWeb/Platform/TimerSerenity.cpp new file mode 100644 index 0000000000..cef22b8768 --- /dev/null +++ b/Userland/Libraries/LibWeb/Platform/TimerSerenity.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "TimerSerenity.h" +#include <AK/NonnullRefPtr.h> +#include <LibCore/Timer.h> + +namespace Web::Platform { + +NonnullRefPtr<TimerSerenity> TimerSerenity::create() +{ + return adopt_ref(*new TimerSerenity); +} + +TimerSerenity::TimerSerenity() + : m_timer(Core::Timer::construct()) +{ + m_timer->on_timeout = [this] { + if (on_timeout) + on_timeout(); + }; +} + +TimerSerenity::~TimerSerenity() = default; + +void TimerSerenity::start() +{ + m_timer->start(); +} + +void TimerSerenity::start(int interval_ms) +{ + m_timer->start(interval_ms); +} + +void TimerSerenity::restart() +{ + m_timer->restart(); +} + +void TimerSerenity::restart(int interval_ms) +{ + m_timer->restart(interval_ms); +} + +void TimerSerenity::stop() +{ + m_timer->stop(); +} + +void TimerSerenity::set_active(bool active) +{ + m_timer->set_active(active); +} + +bool TimerSerenity::is_active() const +{ + return m_timer->is_active(); +} + +int TimerSerenity::interval() const +{ + return m_timer->interval(); +} + +void TimerSerenity::set_interval(int interval_ms) +{ + m_timer->set_interval(interval_ms); +} + +bool TimerSerenity::is_single_shot() const +{ + return m_timer->is_single_shot(); +} + +void TimerSerenity::set_single_shot(bool single_shot) +{ + m_timer->set_single_shot(single_shot); +} + +} diff --git a/Userland/Libraries/LibWeb/Platform/TimerSerenity.h b/Userland/Libraries/LibWeb/Platform/TimerSerenity.h new file mode 100644 index 0000000000..4f368c8a5d --- /dev/null +++ b/Userland/Libraries/LibWeb/Platform/TimerSerenity.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <AK/NonnullRefPtr.h> +#include <LibCore/Forward.h> +#include <LibWeb/Platform/Timer.h> + +namespace Web::Platform { + +class TimerSerenity final : public Timer { +public: + static NonnullRefPtr<TimerSerenity> create(); + + virtual ~TimerSerenity(); + + virtual void start() override; + virtual void start(int interval_ms) override; + virtual void restart() override; + virtual void restart(int interval_ms) override; + virtual void stop() override; + + virtual void set_active(bool) override; + + virtual bool is_active() const override; + virtual int interval() const override; + virtual void set_interval(int interval_ms) override; + + virtual bool is_single_shot() const override; + virtual void set_single_shot(bool) override; + +private: + TimerSerenity(); + + NonnullRefPtr<Core::Timer> m_timer; +}; + +} |