mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 13:57:35 +00:00
LibWeb: Generate a TextPaintable for every Layout::TextNode
This is prep work for moving event handling over to the painting tree.
This commit is contained in:
parent
aae356baf1
commit
4d98851aea
7 changed files with 68 additions and 1 deletions
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <LibWeb/Layout/BlockContainer.h>
|
||||
#include <LibWeb/Layout/FormattingState.h>
|
||||
#include <LibWeb/Layout/TextNode.h>
|
||||
|
||||
namespace Web::Layout {
|
||||
|
||||
|
@ -28,6 +29,8 @@ FormattingState::NodeState const& FormattingState::get(NodeWithStyleAndBoxModelM
|
|||
|
||||
void FormattingState::commit()
|
||||
{
|
||||
HashTable<Layout::TextNode*> text_nodes;
|
||||
|
||||
for (auto& it : nodes) {
|
||||
auto& node = const_cast<Layout::NodeWithStyleAndBoxModelMetrics&>(*it.key);
|
||||
auto& node_state = *it.value;
|
||||
|
@ -49,10 +52,20 @@ void FormattingState::commit()
|
|||
paint_box.set_overflow_data(move(node_state.overflow_data));
|
||||
paint_box.set_containing_line_box_fragment(node_state.containing_line_box_fragment);
|
||||
|
||||
if (is<Layout::BlockContainer>(box))
|
||||
if (is<Layout::BlockContainer>(box)) {
|
||||
for (auto& line_box : node_state.line_boxes) {
|
||||
for (auto& fragment : line_box.fragments()) {
|
||||
if (fragment.layout_node().is_text_node())
|
||||
text_nodes.set(static_cast<Layout::TextNode*>(const_cast<Layout::Node*>(&fragment.layout_node())));
|
||||
}
|
||||
}
|
||||
static_cast<Painting::PaintableWithLines&>(paint_box).set_line_boxes(move(node_state.line_boxes));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (auto* text_node : text_nodes)
|
||||
text_node->set_paintable(text_node->create_paintable());
|
||||
}
|
||||
|
||||
Gfx::FloatRect margin_box_rect(Box const& box, FormattingState const& state)
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <LibWeb/Layout/InlineFormattingContext.h>
|
||||
#include <LibWeb/Layout/Label.h>
|
||||
#include <LibWeb/Layout/TextNode.h>
|
||||
#include <LibWeb/Painting/TextPaintable.h>
|
||||
|
||||
namespace Web::Layout {
|
||||
|
||||
|
@ -366,4 +367,9 @@ Optional<TextNode::Chunk> TextNode::ChunkIterator::try_commit_chunk(Utf8View::It
|
|||
return {};
|
||||
}
|
||||
|
||||
OwnPtr<Painting::Paintable> TextNode::create_paintable() const
|
||||
{
|
||||
return Painting::TextPaintable::create(*this);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -52,6 +52,8 @@ public:
|
|||
|
||||
void compute_text_for_rendering(bool collapse, bool previous_is_empty_or_ends_in_whitespace);
|
||||
|
||||
virtual OwnPtr<Painting::Paintable> create_paintable() const override;
|
||||
|
||||
private:
|
||||
virtual bool is_text_node() const final { return true; }
|
||||
virtual bool wants_mouse_events() const override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue