mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-07 08:29:58 +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
|
@ -299,6 +299,7 @@ set(SOURCES
|
|||
Painting/SVGGraphicsPaintable.cpp
|
||||
Painting/SVGPaintable.cpp
|
||||
Painting/SVGSVGPaintable.cpp
|
||||
Painting/TextPaintable.cpp
|
||||
Painting/ShadowPainting.cpp
|
||||
Painting/StackingContext.cpp
|
||||
RequestIdleCallback/IdleDeadline.cpp
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <AK/NonnullOwnPtr.h>
|
||||
#include <LibWeb/Layout/Box.h>
|
||||
#include <LibWeb/Layout/LineBox.h>
|
||||
#include <LibWeb/Layout/TextNode.h>
|
||||
#include <LibWeb/Painting/StackingContext.h>
|
||||
|
||||
namespace Web::Painting {
|
||||
|
|
21
Userland/Libraries/LibWeb/Painting/TextPaintable.cpp
Normal file
21
Userland/Libraries/LibWeb/Painting/TextPaintable.cpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/Painting/TextPaintable.h>
|
||||
|
||||
namespace Web::Painting {
|
||||
|
||||
NonnullOwnPtr<TextPaintable> TextPaintable::create(Layout::TextNode const& layout_node)
|
||||
{
|
||||
return adopt_own(*new TextPaintable(layout_node));
|
||||
}
|
||||
|
||||
TextPaintable::TextPaintable(Layout::TextNode const& layout_node)
|
||||
: Paintable(layout_node)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
23
Userland/Libraries/LibWeb/Painting/TextPaintable.h
Normal file
23
Userland/Libraries/LibWeb/Painting/TextPaintable.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/Painting/Paintable.h>
|
||||
|
||||
namespace Web::Painting {
|
||||
|
||||
class TextPaintable : public Paintable {
|
||||
public:
|
||||
static NonnullOwnPtr<TextPaintable> create(Layout::TextNode const&);
|
||||
|
||||
Layout::TextNode const& layout_node() const { return static_cast<Layout::TextNode const&>(Paintable::layout_node()); }
|
||||
|
||||
private:
|
||||
explicit TextPaintable(Layout::TextNode const&);
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in a new issue