Move ComputedProperties and CascadedProperties out of the GC. They no longer contain strong references to GC-managed data. Keep computed styles alive from DOM elements and animation updates with RefPtr. Pass style into layout constructors by reference, since layout only copies the values it needs while building nodes. Use GC::Weak for cascade source links, so entries no longer keep the style declaration or shadow root alive.
56 lines
1.8 KiB
C++
56 lines
1.8 KiB
C++
/*
|
|
* Copyright (c) 2018-2024, Andreas Kling <andreas@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
|
|
#include <LibWeb/DOM/Document.h>
|
|
#include <LibWeb/HTML/HTMLObjectElement.h>
|
|
#include <LibWeb/HTML/Navigable.h>
|
|
#include <LibWeb/Layout/NavigableContainerViewport.h>
|
|
#include <LibWeb/Layout/Viewport.h>
|
|
#include <LibWeb/Painting/NavigableContainerViewportPaintable.h>
|
|
#include <LibWeb/SVG/SVGSVGElement.h>
|
|
|
|
namespace Web::Layout {
|
|
|
|
GC_DEFINE_ALLOCATOR(NavigableContainerViewport);
|
|
|
|
NavigableContainerViewport::NavigableContainerViewport(DOM::Document& document, HTML::NavigableContainer& element, CSS::ComputedProperties const& style)
|
|
: ReplacedBox(document, element, style)
|
|
{
|
|
}
|
|
|
|
NavigableContainerViewport::~NavigableContainerViewport() = default;
|
|
|
|
CSS::SizeWithAspectRatio NavigableContainerViewport::natural_size() const
|
|
{
|
|
if (!is<HTML::HTMLObjectElement>(dom_node()))
|
|
return {};
|
|
|
|
if (auto const* content_document = dom_node().content_document_without_origin_check()) {
|
|
if (auto const* root = content_document->document_element();
|
|
root && root->is_svg_svg_element()) {
|
|
|
|
auto metrics = SVG::SVGSVGElement::negotiate_natural_metrics(static_cast<SVG::SVGSVGElement const&>(*root));
|
|
return { metrics.width, metrics.height, metrics.aspect_ratio };
|
|
}
|
|
}
|
|
return {};
|
|
}
|
|
|
|
void NavigableContainerViewport::did_set_content_size()
|
|
{
|
|
ReplacedBox::did_set_content_size();
|
|
|
|
if (dom_node().content_navigable())
|
|
dom_node().content_navigable()->set_viewport_size(paintable_box()->content_size());
|
|
}
|
|
|
|
RefPtr<Painting::Paintable> NavigableContainerViewport::create_paintable() const
|
|
{
|
|
return Painting::NavigableContainerViewportPaintable::create(*this);
|
|
}
|
|
|
|
}
|