diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 4ec37c8ac5..da7b9397b8 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -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 diff --git a/Userland/Libraries/LibWeb/Layout/FormattingState.cpp b/Userland/Libraries/LibWeb/Layout/FormattingState.cpp index 9e04b8166a..7b70b43628 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingState.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingState.cpp @@ -6,6 +6,7 @@ #include #include +#include namespace Web::Layout { @@ -28,6 +29,8 @@ FormattingState::NodeState const& FormattingState::get(NodeWithStyleAndBoxModelM void FormattingState::commit() { + HashTable text_nodes; + for (auto& it : nodes) { auto& node = const_cast(*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(box)) + if (is(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(const_cast(&fragment.layout_node()))); + } + } static_cast(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) diff --git a/Userland/Libraries/LibWeb/Layout/TextNode.cpp b/Userland/Libraries/LibWeb/Layout/TextNode.cpp index 2eb20df53b..a5b6394547 100644 --- a/Userland/Libraries/LibWeb/Layout/TextNode.cpp +++ b/Userland/Libraries/LibWeb/Layout/TextNode.cpp @@ -14,6 +14,7 @@ #include #include #include +#include namespace Web::Layout { @@ -366,4 +367,9 @@ Optional TextNode::ChunkIterator::try_commit_chunk(Utf8View::It return {}; } +OwnPtr TextNode::create_paintable() const +{ + return Painting::TextPaintable::create(*this); +} + } diff --git a/Userland/Libraries/LibWeb/Layout/TextNode.h b/Userland/Libraries/LibWeb/Layout/TextNode.h index 384cd8fbe1..c4fc62d67e 100644 --- a/Userland/Libraries/LibWeb/Layout/TextNode.h +++ b/Userland/Libraries/LibWeb/Layout/TextNode.h @@ -52,6 +52,8 @@ public: void compute_text_for_rendering(bool collapse, bool previous_is_empty_or_ends_in_whitespace); + virtual OwnPtr create_paintable() const override; + private: virtual bool is_text_node() const final { return true; } virtual bool wants_mouse_events() const override; diff --git a/Userland/Libraries/LibWeb/Painting/Paintable.h b/Userland/Libraries/LibWeb/Painting/Paintable.h index f9199bd787..e81e0ad5c0 100644 --- a/Userland/Libraries/LibWeb/Painting/Paintable.h +++ b/Userland/Libraries/LibWeb/Painting/Paintable.h @@ -9,6 +9,7 @@ #include #include #include +#include #include namespace Web::Painting { diff --git a/Userland/Libraries/LibWeb/Painting/TextPaintable.cpp b/Userland/Libraries/LibWeb/Painting/TextPaintable.cpp new file mode 100644 index 0000000000..69db64ffdc --- /dev/null +++ b/Userland/Libraries/LibWeb/Painting/TextPaintable.cpp @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +namespace Web::Painting { + +NonnullOwnPtr TextPaintable::create(Layout::TextNode const& layout_node) +{ + return adopt_own(*new TextPaintable(layout_node)); +} + +TextPaintable::TextPaintable(Layout::TextNode const& layout_node) + : Paintable(layout_node) +{ +} + +} diff --git a/Userland/Libraries/LibWeb/Painting/TextPaintable.h b/Userland/Libraries/LibWeb/Painting/TextPaintable.h new file mode 100644 index 0000000000..88137191b9 --- /dev/null +++ b/Userland/Libraries/LibWeb/Painting/TextPaintable.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Web::Painting { + +class TextPaintable : public Paintable { +public: + static NonnullOwnPtr create(Layout::TextNode const&); + + Layout::TextNode const& layout_node() const { return static_cast(Paintable::layout_node()); } + +private: + explicit TextPaintable(Layout::TextNode const&); +}; + +}