2020-03-19 19:07:56 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-03-19 19:07:56 +01:00
|
|
|
*/
|
|
|
|
|
2021-02-10 08:25:35 +01:00
|
|
|
#include <LibGfx/Painter.h>
|
2020-11-22 15:53:01 +01:00
|
|
|
#include <LibWeb/Layout/CanvasBox.h>
|
2020-03-19 19:07:56 +01:00
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
namespace Web::Layout {
|
2020-03-19 19:07:56 +01:00
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
CanvasBox::CanvasBox(DOM::Document& document, HTML::HTMLCanvasElement& element, NonnullRefPtr<CSS::StyleProperties> style)
|
|
|
|
: ReplacedBox(document, element, move(style))
|
2020-03-19 19:07:56 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
CanvasBox::~CanvasBox()
|
2020-03-19 19:07:56 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
void CanvasBox::prepare_for_replaced_layout()
|
2020-03-19 19:07:56 +01:00
|
|
|
{
|
2020-06-05 19:23:49 +02:00
|
|
|
set_has_intrinsic_width(true);
|
|
|
|
set_has_intrinsic_height(true);
|
2020-11-22 14:46:36 +01:00
|
|
|
set_intrinsic_width(dom_node().width());
|
|
|
|
set_intrinsic_height(dom_node().height());
|
2020-03-19 19:07:56 +01:00
|
|
|
}
|
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
void CanvasBox::paint(PaintContext& context, PaintPhase phase)
|
2020-03-19 19:07:56 +01:00
|
|
|
{
|
|
|
|
if (!is_visible())
|
|
|
|
return;
|
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
ReplacedBox::paint(context, phase);
|
2020-06-18 18:57:35 +02:00
|
|
|
|
|
|
|
if (phase == PaintPhase::Foreground) {
|
|
|
|
// FIXME: This should be done at a different level. Also rect() does not include padding etc!
|
|
|
|
if (!context.viewport_rect().intersects(enclosing_int_rect(absolute_rect())))
|
|
|
|
return;
|
2020-03-19 19:07:56 +01:00
|
|
|
|
2020-11-22 14:46:36 +01:00
|
|
|
if (dom_node().bitmap())
|
|
|
|
context.painter().draw_scaled_bitmap(enclosing_int_rect(absolute_rect()), *dom_node().bitmap(), dom_node().bitmap()->rect());
|
2020-06-18 18:57:35 +02:00
|
|
|
}
|
2020-03-19 19:07:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|