2020-03-19 15:07:56 -03:00
|
|
|
/*
|
2024-10-04 08:19:50 -03:00
|
|
|
* Copyright (c) 2020-2022, Andreas Kling <andreas@ladybird.org>
|
2020-03-19 15:07:56 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-03-19 15:07:56 -03:00
|
|
|
*/
|
|
|
|
|
|
2020-11-22 11:53:01 -03:00
|
|
|
#include <LibWeb/Layout/CanvasBox.h>
|
2022-03-10 10:02:25 -03:00
|
|
|
#include <LibWeb/Painting/CanvasPaintable.h>
|
2020-03-19 15:07:56 -03:00
|
|
|
|
2020-11-22 11:53:01 -03:00
|
|
|
namespace Web::Layout {
|
2020-03-19 15:07:56 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC_DEFINE_ALLOCATOR(CanvasBox);
|
2024-04-06 14:16:04 -03:00
|
|
|
|
2024-12-20 12:35:12 -03:00
|
|
|
CanvasBox::CanvasBox(DOM::Document& document, HTML::HTMLCanvasElement& element, GC::Ref<CSS::ComputedProperties> style)
|
2020-11-22 11:53:01 -03:00
|
|
|
: ReplacedBox(document, element, move(style))
|
2020-03-19 15:07:56 -03:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-14 16:21:51 -03:00
|
|
|
CanvasBox::~CanvasBox() = default;
|
2020-03-19 15:07:56 -03:00
|
|
|
|
2026-01-11 03:31:07 -03:00
|
|
|
CSS::SizeWithAspectRatio CanvasBox::compute_auto_content_box_size() const
|
2020-03-19 15:07:56 -03:00
|
|
|
{
|
2026-01-11 03:31:07 -03:00
|
|
|
auto width = dom_node().width();
|
|
|
|
|
auto height = dom_node().height();
|
|
|
|
|
if (width == 0 || height == 0)
|
|
|
|
|
return { width, height, {} };
|
|
|
|
|
return { width, height, CSSPixelFraction(width, height) };
|
2020-03-19 15:07:56 -03:00
|
|
|
}
|
|
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<Painting::Paintable> CanvasBox::create_paintable() const
|
2020-03-19 15:07:56 -03:00
|
|
|
{
|
2022-03-10 10:02:25 -03:00
|
|
|
return Painting::CanvasPaintable::create(*this);
|
2020-03-19 15:07:56 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|