mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-11 17:37:33 +02:00
The Paintable tree and its supplemental painting data structures were GC allocated because that was the easiest way to manage it and avoid leaks introduced by ref cycles. This included the Paintable subclasses themselves plus StackingContext, ChromeWidget, Scrollbar, ResizeHandle, and scroll-frame state. We are now trying to reduce GC allocation churn on layout and painting updates, so keeping this short-lived rendering tree outside the JS heap is a better fit. Move Paintable to RefCountedTreeNode, make painting helpers ref-counted or weakly reference Paintables, and update the layout and event-handler call sites to use RefPtr/WeakPtr ownership.
53 lines
1.4 KiB
C++
53 lines
1.4 KiB
C++
/*
|
|
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibGfx/Bitmap.h>
|
|
#include <LibWeb/HTML/HTMLVideoElement.h>
|
|
#include <LibWeb/Layout/VideoBox.h>
|
|
#include <LibWeb/Painting/VideoPaintable.h>
|
|
|
|
namespace Web::Layout {
|
|
|
|
GC_DEFINE_ALLOCATOR(VideoBox);
|
|
|
|
VideoBox::VideoBox(DOM::Document& document, DOM::Element& element, GC::Ref<CSS::ComputedProperties> style)
|
|
: ReplacedBox(document, element, style)
|
|
{
|
|
}
|
|
|
|
HTML::HTMLVideoElement& VideoBox::dom_node()
|
|
{
|
|
return static_cast<HTML::HTMLVideoElement&>(*ReplacedBox::dom_node());
|
|
}
|
|
|
|
HTML::HTMLVideoElement const& VideoBox::dom_node() const
|
|
{
|
|
return static_cast<HTML::HTMLVideoElement const&>(*ReplacedBox::dom_node());
|
|
}
|
|
|
|
bool VideoBox::can_have_children() const
|
|
{
|
|
// If we allow children when controls are disabled, innerText may be non-empty.
|
|
return dom_node().shadow_root() != nullptr;
|
|
}
|
|
|
|
CSS::SizeWithAspectRatio VideoBox::natural_size() const
|
|
{
|
|
auto natural_size = dom_node().natural_element_size();
|
|
if (!natural_size.has_value())
|
|
return {};
|
|
if (natural_size->is_empty())
|
|
return { 0, 0, {} };
|
|
return { natural_size->width(), natural_size->height(), natural_size->width() / natural_size->height() };
|
|
}
|
|
|
|
RefPtr<Painting::Paintable> VideoBox::create_paintable() const
|
|
{
|
|
return Painting::VideoPaintable::create(*this);
|
|
}
|
|
|
|
}
|