1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:07:35 +00:00

LibWeb: Rework the layout engine to use relative offsets

The box tree and line boxes now all store a relative offset from their
containing block, instead of an absolute (document-relative) position.

This removes a huge pain point from the layout system which was having
to adjust offsets recursively when something moved. It also makes some
layout logic significantly simpler.

Every box can still find its absolute position by walking its chain
of containing blocks and accumulating the translation from the root.
This is currently what we do both for rendering and hit testing.
This commit is contained in:
Andreas Kling 2020-06-10 10:42:29 +02:00
parent e836f09094
commit 656b01eb0f
21 changed files with 183 additions and 119 deletions

View file

@ -26,31 +26,39 @@
#pragma once
#include <AK/Weakable.h>
#include <LibGfx/FloatRect.h>
#include <LibWeb/Forward.h>
namespace Web {
class LayoutNode;
class RenderingContext;
class LineBoxFragment {
class LineBoxFragment : public Weakable<LineBoxFragment> {
friend class LineBox;
public:
LineBoxFragment(const LayoutNode& layout_node, int start, int length, const Gfx::FloatRect& rect)
LineBoxFragment(const LayoutNode& layout_node, int start, int length, const Gfx::FloatPoint& offset, const Gfx::FloatSize& size)
: m_layout_node(layout_node)
, m_start(start)
, m_length(length)
, m_rect(rect)
, m_offset(offset)
, m_size(size)
{
}
const LayoutNode& layout_node() const { return m_layout_node; }
int start() const { return m_start; }
int length() const { return m_length; }
const Gfx::FloatRect& rect() const { return m_rect; }
Gfx::FloatRect& rect() { return m_rect; }
const Gfx::FloatRect absolute_rect() const;
float width() const { return m_rect.width(); }
const Gfx::FloatPoint& offset() const { return m_offset; }
void set_offset(const Gfx::FloatPoint& offset) { m_offset = offset; }
const Gfx::FloatSize& size() const { return m_size; }
void set_width(float width) { m_size.set_width(width); }
float width() const { return m_size.width(); }
float height() const { return m_size.height(); }
float absolute_x() const { return absolute_rect().x(); }
void render(RenderingContext&);
@ -63,7 +71,8 @@ private:
const LayoutNode& m_layout_node;
int m_start { 0 };
int m_length { 0 };
Gfx::FloatRect m_rect;
Gfx::FloatPoint m_offset;
Gfx::FloatSize m_size;
};
}