1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-08 05:27:14 +09:00
ladybird/Libraries/LibWeb/Layout/Viewport.h
Jelle Raaijmakers c3a5e8e266 LibWeb: Invalidate viewport's text blocks cache on layout update
156c1083e9 introduced a text blocks cache
for better performance when searching through text on a page, but when
we partially recreate the layout tree, this cache does not get
invalidated. We now rebuild the entire text blocks cache after a layout
update.
2025-05-15 11:44:32 +01:00

50 lines
1.2 KiB
C++

/*
* Copyright (c) 2018-2023, Andreas Kling <andreas@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/DOM/Document.h>
#include <LibWeb/Layout/BlockContainer.h>
namespace Web::Layout {
class Viewport final : public BlockContainer {
GC_CELL(Viewport, BlockContainer);
GC_DECLARE_ALLOCATOR(Viewport);
public:
explicit Viewport(DOM::Document&, GC::Ref<CSS::ComputedProperties>);
virtual ~Viewport() override;
struct TextPosition {
GC::Ref<DOM::Text> dom_node;
size_t start_offset { 0 };
};
struct TextBlock {
String text;
Vector<TextPosition> positions;
};
Vector<TextBlock> const& text_blocks();
void invalidate_text_blocks_cache() { m_text_blocks.clear(); }
const DOM::Document& dom_node() const { return static_cast<const DOM::Document&>(*Node::dom_node()); }
virtual void visit_edges(Visitor&) override;
private:
virtual GC::Ptr<Painting::Paintable> create_paintable() const override;
void update_text_blocks();
virtual bool is_viewport() const override { return true; }
Optional<Vector<TextBlock>> m_text_blocks;
};
template<>
inline bool Node::fast_is<Viewport>() const { return is_viewport(); }
}