2022-03-10 13:02:25 +00:00
|
|
|
/*
|
2024-10-04 11:19:50 +00:00
|
|
|
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
|
2022-03-10 13:02:25 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
2024-09-25 13:44:58 +00:00
|
|
|
#include <LibWeb/HTML/TraversableNavigable.h>
|
2022-03-10 13:02:25 +00:00
|
|
|
#include <LibWeb/Painting/CanvasPaintable.h>
|
|
|
|
|
|
|
|
namespace Web::Painting {
|
|
|
|
|
2024-04-06 17:16:04 +00:00
|
|
|
JS_DEFINE_ALLOCATOR(CanvasPaintable);
|
|
|
|
|
2023-01-11 11:51:49 +00:00
|
|
|
JS::NonnullGCPtr<CanvasPaintable> CanvasPaintable::create(Layout::CanvasBox const& layout_box)
|
2022-03-10 13:02:25 +00:00
|
|
|
{
|
2023-01-11 11:51:49 +00:00
|
|
|
return layout_box.heap().allocate_without_realm<CanvasPaintable>(layout_box);
|
2022-03-10 13:02:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CanvasPaintable::CanvasPaintable(Layout::CanvasBox const& layout_box)
|
2022-03-10 14:50:57 +00:00
|
|
|
: PaintableBox(layout_box)
|
2022-03-10 13:02:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Layout::CanvasBox const& CanvasPaintable::layout_box() const
|
|
|
|
{
|
2022-03-10 14:50:57 +00:00
|
|
|
return static_cast<Layout::CanvasBox const&>(layout_node());
|
2022-03-10 13:02:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CanvasPaintable::paint(PaintContext& context, PaintPhase phase) const
|
|
|
|
{
|
2023-09-18 11:08:20 +00:00
|
|
|
if (!is_visible())
|
2022-03-10 13:02:25 +00:00
|
|
|
return;
|
|
|
|
|
2022-03-10 14:50:57 +00:00
|
|
|
PaintableBox::paint(context, phase);
|
2022-03-10 13:02:25 +00:00
|
|
|
|
|
|
|
if (phase == PaintPhase::Foreground) {
|
2022-10-31 19:46:55 +00:00
|
|
|
auto canvas_rect = context.rounded_device_rect(absolute_rect());
|
2023-10-15 02:27:48 +00:00
|
|
|
ScopedCornerRadiusClip corner_clip { context, canvas_rect, normalized_border_radii_data(ShrinkRadiiForBorders::Yes) };
|
2022-03-10 13:02:25 +00:00
|
|
|
|
2024-09-25 13:44:58 +00:00
|
|
|
if (layout_box().dom_node().surface()) {
|
|
|
|
auto surface = layout_box().dom_node().surface();
|
|
|
|
|
2022-06-04 03:27:48 +00:00
|
|
|
// FIXME: Remove this const_cast.
|
|
|
|
const_cast<HTML::HTMLCanvasElement&>(layout_box().dom_node()).present();
|
2024-09-25 13:44:58 +00:00
|
|
|
auto scaling_mode = to_gfx_scaling_mode(computed_values().image_rendering(), surface->rect(), canvas_rect.to_type<int>());
|
|
|
|
context.display_list_recorder().draw_painting_surface(canvas_rect.to_type<int>(), *layout_box().dom_node().surface(), surface->rect(), scaling_mode);
|
2022-06-04 03:27:48 +00:00
|
|
|
}
|
2022-03-10 13:02:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|