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

LibWeb: Add inline-level iterator that enumerates items for line layout

This patch adds a new mechanism that allows InlineFormattingContext to
build line boxes incrementally instead of all-in-one go.

Incremental build will eventually allow much better support for CSS
floating objects.
This commit is contained in:
Andreas Kling 2022-01-17 15:07:19 +01:00
parent 9358f108c4
commit 1f603c54ff
6 changed files with 248 additions and 13 deletions

View file

@ -0,0 +1,64 @@
/*
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Noncopyable.h>
#include <LibWeb/Layout/Box.h>
#include <LibWeb/Layout/TextNode.h>
namespace Web::Layout {
// This class iterates over all the inline-level objects within an inline formatting context.
// By repeatedly calling next() with the remaining available width on the current line,
// it returns an "Item" representing the next piece of inline-level content to be placed on the line.
class InlineLevelIterator {
AK_MAKE_NONCOPYABLE(InlineLevelIterator);
AK_MAKE_NONMOVABLE(InlineLevelIterator);
public:
struct Item {
enum class Type {
Text,
Element,
ForcedBreak,
};
Type type {};
Layout::Node* node { nullptr };
size_t offset_in_node { 0 };
size_t length_in_node { 0 };
float width { 0.0f };
};
explicit InlineLevelIterator(Layout::Box& container, LayoutMode layout_mode)
: m_container(container)
, m_current_node(container.first_child())
, m_layout_mode(layout_mode)
{
}
Optional<Item> next(float available_width);
private:
void skip_to_next();
void enter_text_node(Layout::TextNode&);
Layout::Box& m_container;
Layout::Node* m_current_node { nullptr };
LayoutMode const m_layout_mode;
struct TextNodeContext {
bool do_collapse {};
bool do_wrap_lines {};
bool do_respect_linebreaks {};
TextNode::ChunkIterator chunk_iterator;
};
Optional<TextNodeContext> m_text_node_context;
};
}