1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:17:44 +00:00

Presenter: Rearchitect on top of LibWeb

This patch replaces the bespoke rendering engine in Presenter with a
simple pipeline that turns presentations into single-page HTML files.
The HTML is then loaded into an OutOfProcessWebView.

This achieves a number of things, most importantly:
- Access to all the CSS features supported by LibWeb
- Sandboxed, multi-process rendering

The code could be simplified a lot further, but I wanted to get the new
architecture in place without changing anything about the file format.
This commit is contained in:
Andreas Kling 2023-01-09 00:44:32 +01:00 committed by Linus Groh
parent ed3c2cbdf6
commit 3110f5b328
10 changed files with 267 additions and 268 deletions

View file

@ -1,16 +1,13 @@
/*
* Copyright (c) 2022, kleines Filmröllchen <filmroellchen@serenityos.org>
* Copyright (c) 2023, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "Slide.h"
#include "Presentation.h"
#include <AK/JsonObject.h>
#include <AK/NonnullRefPtrVector.h>
#include <LibGUI/Window.h>
#include <LibGfx/Painter.h>
#include <LibGfx/Size.h>
#include <LibGfx/TextAlignment.h>
Slide::Slide(NonnullRefPtrVector<SlideObject> slide_objects, DeprecatedString title)
: m_slide_objects(move(slide_objects))
@ -18,7 +15,7 @@ Slide::Slide(NonnullRefPtrVector<SlideObject> slide_objects, DeprecatedString ti
{
}
ErrorOr<Slide> Slide::parse_slide(JsonObject const& slide_json, NonnullRefPtr<GUI::Window> window)
ErrorOr<Slide> Slide::parse_slide(JsonObject const& slide_json)
{
// FIXME: Use the text with the "title" role for a title, if there is no title given.
auto title = slide_json.get("title"sv).as_string_or("Untitled slide");
@ -34,20 +31,18 @@ ErrorOr<Slide> Slide::parse_slide(JsonObject const& slide_json, NonnullRefPtr<GU
return Error::from_string_view("Slides must be objects"sv);
auto const& slide_object_json = maybe_slide_object_json.as_object();
auto slide_object = TRY(SlideObject::parse_slide_object(slide_object_json, window));
auto slide_object = TRY(SlideObject::parse_slide_object(slide_object_json));
slide_objects.append(move(slide_object));
}
return Slide { move(slide_objects), title };
}
void Slide::paint(Gfx::Painter& painter, unsigned int current_frame, Gfx::FloatSize display_scale) const
ErrorOr<HTMLElement> Slide::render(Presentation const& presentation) const
{
for (auto const& object : m_slide_objects) {
if (object.is_visible_during_frame(current_frame))
object.paint(painter, display_scale);
}
// FIXME: Move this to user settings.
painter.draw_text(painter.clip_rect(), title(), Gfx::TextAlignment::BottomCenter);
HTMLElement wrapper;
wrapper.tag_name = "div"sv;
for (auto const& object : m_slide_objects)
TRY(wrapper.children.try_append(TRY(object.render(presentation))));
return wrapper;
}