mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-05 01:42:54 +00:00
The first step of the find in page algorithm is to walk the layout tree of each document on the page and construct a list of strings against which to search for matches. Previously, this was being done for each new query, even when the page content hadn't been updated. The output of this process is now cached in the viewport node of the associated document. This ensures that this process is no longer repeated unnceessarily.
49 lines
1.2 KiB
C++
49 lines
1.2 KiB
C++
/*
|
|
* Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.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 {
|
|
JS_CELL(Viewport, BlockContainer);
|
|
JS_DECLARE_ALLOCATOR(Viewport);
|
|
|
|
public:
|
|
explicit Viewport(DOM::Document&, NonnullRefPtr<CSS::StyleProperties>);
|
|
virtual ~Viewport() override;
|
|
|
|
struct TextPosition {
|
|
JS::NonnullGCPtr<DOM::Text> dom_node;
|
|
size_t start_offset { 0 };
|
|
};
|
|
struct TextBlock {
|
|
String text;
|
|
Vector<TextPosition> positions;
|
|
};
|
|
Vector<TextBlock> const& text_blocks();
|
|
|
|
const DOM::Document& dom_node() const { return static_cast<const DOM::Document&>(*Node::dom_node()); }
|
|
|
|
virtual void visit_edges(Visitor&) override;
|
|
|
|
private:
|
|
virtual JS::GCPtr<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(); }
|
|
|
|
}
|