1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 02:47:34 +00:00

LibHTML: Rewrite inline and text layout

Inline layout is now done by LayoutBlock. Blocks with inline children
will split them into line boxes during layout.

A LayoutBlock can have zero or more LineBox objects. Each LineBox
represents one visual line.

A LineBox can have any number of LineBoxFragment children. A fragment
is an offset+length into a specific LayoutNode.

To paint a LayoutBlock with inline children, we walk its line boxes,
and walk their fragments, painting each fragment at a time by calling
LineBoxFragment::render(), which in turn calls the LayoutNode via
LayoutText::render_fragment(). Hit testing works similarly.

This is very incomplete and has many bugs, but should make it easier
for us to move forward with this code.
This commit is contained in:
Andreas Kling 2019-10-03 15:20:13 +02:00
parent 5966fcff31
commit 1d65cf367f
12 changed files with 339 additions and 187 deletions

View file

@ -1,11 +1,12 @@
#pragma once
#include <LibHTML/DOM/Text.h>
#include <LibHTML/Layout/LayoutNode.h>
#include <LibHTML/Layout/LayoutInline.h>
class Font;
class LineBoxFragment;
class LayoutText : public LayoutNode {
class LayoutText : public LayoutInline {
public:
LayoutText(const Text&, StyleProperties&&);
virtual ~LayoutText() override;
@ -16,25 +17,19 @@ public:
virtual const char* class_name() const override { return "LayoutText"; }
virtual bool is_text() const final { return true; }
virtual void layout() override;
virtual void render(RenderingContext&) override;
struct Run {
Point pos;
String text;
};
void render_fragment(RenderingContext&, const LineBoxFragment&) const;
const Vector<Run>& runs() const { return m_runs; }
virtual HitTestResult hit_test(const Point&) const override;
virtual void split_into_lines(LayoutBlock& container) override;
private:
template<typename Callback>
void for_each_run(Callback) const;
void for_each_word(Callback) const;
template<typename Callback>
void for_each_source_line(Callback) const;
void load_font();
void compute_runs();
Vector<Run> m_runs;
RefPtr<Font> m_font;
};