summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/Painting
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2023-04-04 18:32:09 -0400
committerLinus Groh <mail@linusgroh.de>2023-04-07 16:02:22 +0200
commitf156d3d5e5bab6026d44c32445342d9b05aab895 (patch)
treee5013dcba53ea1332f520c16c05d9e98c269b43d /Userland/Libraries/LibWeb/Painting
parent725d7c36993c3b39958e5847270ee6942da04239 (diff)
downloadserenity-f156d3d5e5bab6026d44c32445342d9b05aab895.zip
LibWeb: Create a basic layout node for HTMLVideoElement
Diffstat (limited to 'Userland/Libraries/LibWeb/Painting')
-rw-r--r--Userland/Libraries/LibWeb/Painting/VideoPaintable.cpp50
-rw-r--r--Userland/Libraries/LibWeb/Painting/VideoPaintable.h28
2 files changed, 78 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Painting/VideoPaintable.cpp b/Userland/Libraries/LibWeb/Painting/VideoPaintable.cpp
new file mode 100644
index 0000000000..f7551246e4
--- /dev/null
+++ b/Userland/Libraries/LibWeb/Painting/VideoPaintable.cpp
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibWeb/HTML/HTMLVideoElement.h>
+#include <LibWeb/Layout/VideoBox.h>
+#include <LibWeb/Painting/BorderRadiusCornerClipper.h>
+#include <LibWeb/Painting/VideoPaintable.h>
+
+namespace Web::Painting {
+
+JS::NonnullGCPtr<VideoPaintable> VideoPaintable::create(Layout::VideoBox const& layout_box)
+{
+ return layout_box.heap().allocate_without_realm<VideoPaintable>(layout_box);
+}
+
+VideoPaintable::VideoPaintable(Layout::VideoBox const& layout_box)
+ : PaintableBox(layout_box)
+{
+}
+
+Layout::VideoBox const& VideoPaintable::layout_box() const
+{
+ return static_cast<Layout::VideoBox const&>(layout_node());
+}
+
+void VideoPaintable::paint(PaintContext& context, PaintPhase phase) const
+{
+ if (!is_visible())
+ return;
+
+ // FIXME: This should be done at a different level.
+ if (is_out_of_view(context))
+ return;
+
+ PaintableBox::paint(context, phase);
+
+ if (phase != PaintPhase::Foreground)
+ return;
+
+ if (auto const& bitmap = layout_box().dom_node().current_frame()) {
+ auto image_rect = context.rounded_device_rect(absolute_rect());
+ ScopedCornerRadiusClip corner_clip { context, context.painter(), image_rect, normalized_border_radii_data(ShrinkRadiiForBorders::Yes) };
+ context.painter().draw_scaled_bitmap(image_rect.to_type<int>(), *bitmap, bitmap->rect(), 1.0f, to_gfx_scaling_mode(computed_values().image_rendering()));
+ }
+}
+
+}
diff --git a/Userland/Libraries/LibWeb/Painting/VideoPaintable.h b/Userland/Libraries/LibWeb/Painting/VideoPaintable.h
new file mode 100644
index 0000000000..d5e6092a27
--- /dev/null
+++ b/Userland/Libraries/LibWeb/Painting/VideoPaintable.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <LibWeb/Forward.h>
+#include <LibWeb/Painting/PaintableBox.h>
+
+namespace Web::Painting {
+
+class VideoPaintable final : public PaintableBox {
+ JS_CELL(VideoPaintable, PaintableBox);
+
+public:
+ static JS::NonnullGCPtr<VideoPaintable> create(Layout::VideoBox const&);
+
+ virtual void paint(PaintContext&, PaintPhase) const override;
+
+ Layout::VideoBox const& layout_box() const;
+
+private:
+ VideoPaintable(Layout::VideoBox const&);
+};
+
+}