ladybird/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp
Andreas Kling 561612f219 LibWeb: Add Layout::FormattingState
The purpose of this new object will be to keep track of various states
during an ongoing layout.

Until now, we've been updating layout tree nodes as we go during layout,
which adds an invisible layer of implicit serialization to the whole
layout system.

My idea with FormattingState is that running layout will produce a
result entirely contained within the FormattingState object. At the end
of layout, it can then be applied to the layout tree, or simply queried
for some metrics we were trying to determine.

When doing subtree layouts to determine intrinsic sizes, we will
eventually be able to clone the current FormattingState, and run the
subtree layout in isolation, opening up opportunities for parallelism.

This first patch doesn't go very far though, it merely adds the object
as a skeleton class, and makes sure the root BFC has one. :^)
2022-02-21 18:35:12 +01:00

43 lines
1.3 KiB
C++

/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Format.h>
#include <LibWeb/Layout/SVGFormattingContext.h>
#include <LibWeb/Layout/SVGGeometryBox.h>
namespace Web::Layout {
SVGFormattingContext::SVGFormattingContext(FormattingState& state, Box& box, FormattingContext* parent)
: FormattingContext(Type::SVG, state, box, parent)
{
}
SVGFormattingContext::~SVGFormattingContext()
{
}
void SVGFormattingContext::run(Box& box, LayoutMode)
{
box.for_each_in_subtree_of_type<SVGBox>([&](auto& descendant) {
if (is<SVGGeometryBox>(descendant)) {
auto& geometry_box = static_cast<SVGGeometryBox&>(descendant);
auto& path = geometry_box.dom_node().get_path();
auto bounding_box = path.bounding_box();
// Stroke increases the path's size by stroke_width/2 per side.
auto stroke_width = geometry_box.dom_node().stroke_width().value_or(0);
bounding_box.inflate(stroke_width, stroke_width);
geometry_box.set_offset(bounding_box.top_left());
geometry_box.set_content_size(bounding_box.size());
}
return IterationDecision::Continue;
});
}
}