mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2026-04-18 09:50:27 +00:00
Instead, compute them on demand. This affects ReplacedBox and its subclasses. This commit is centered around a new Box::auto_content_box_size method. It returns a SizeWithAspectRatio representing the natural size of a replaced element, or the size derived from attributes for text input and textarea. These values are used when the corresponding axis is auto or indefinite. Although introducing this API choke-point for sizing replaced and replaced-like elements was the main goal, it's notable that layout becomes more robust in the face of dynamic changes due to reduced potential for stale size values (at the cost of extra calculations and allocations).
34 lines
952 B
C++
34 lines
952 B
C++
/*
|
|
* Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
|
|
* Copyright (c) 2022-2024, Andreas Kling <andreas@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibWeb/CSS/Parser/Parser.h>
|
|
#include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
|
|
#include <LibWeb/Layout/ReplacedBox.h>
|
|
#include <LibWeb/Layout/SVGGeometryBox.h>
|
|
#include <LibWeb/Painting/SVGSVGPaintable.h>
|
|
|
|
namespace Web::Layout {
|
|
|
|
GC_DEFINE_ALLOCATOR(SVGSVGBox);
|
|
|
|
SVGSVGBox::SVGSVGBox(DOM::Document& document, SVG::SVGSVGElement& element, GC::Ref<CSS::ComputedProperties> style)
|
|
: ReplacedBox(document, element, style)
|
|
{
|
|
}
|
|
|
|
GC::Ptr<Painting::Paintable> SVGSVGBox::create_paintable() const
|
|
{
|
|
return Painting::SVGSVGPaintable::create(*this);
|
|
}
|
|
|
|
CSS::SizeWithAspectRatio SVGSVGBox::natural_size() const
|
|
{
|
|
auto metrics = SVG::SVGSVGElement::negotiate_natural_metrics(dom_node());
|
|
return { metrics.width, metrics.height, metrics.aspect_ratio };
|
|
}
|
|
|
|
}
|