mirror of
https://github.com/SerenityOS/serenity.git
synced 2026-11-07 04:29:30 -10:00
This adds a global search term stored in BrowserWindow that is shared across all tabs. When opening Find in Page (Ctrl+F), the widget now uses the following priority logic: 1. If there's text selected on the page, use that 2. If the search box is empty, use the global search term 3. Otherwise, keep the existing text To imitatates Chromium's logic, the global search term is updated whenever the user types, navigates matches, or when a selection populates the search box.
51 lines
1.3 KiB
C++
51 lines
1.3 KiB
C++
/*
|
||
* Copyright (c) 2026, Fırat Kızılboğa <[email protected]>
|
||
*
|
||
* SPDX-License-Identifier: BSD-2-Clause
|
||
*/
|
||
|
||
#pragma once
|
||
|
||
#include <AK/Function.h>
|
||
#include <LibGUI/Button.h>
|
||
#include <LibGUI/CheckBox.h>
|
||
#include <LibGUI/Event.h>
|
||
#include <LibGUI/Label.h>
|
||
#include <LibGUI/TextBox.h>
|
||
#include <LibGUI/Widget.h>
|
||
#include <LibWebView/OutOfProcessWebView.h>
|
||
|
||
namespace Browser {
|
||
|
||
class FindInPageWidget final
|
||
: public GUI::Widget {
|
||
C_OBJECT(FindInPageWidget);
|
||
|
||
public:
|
||
virtual ~FindInPageWidget() override = default;
|
||
|
||
void initialize(WebView::OutOfProcessWebView& web_view);
|
||
void show(String const& global_term);
|
||
|
||
Function<void(String const&)> on_search_text_change;
|
||
|
||
private:
|
||
FindInPageWidget();
|
||
virtual void keydown_event(GUI::KeyEvent&) override;
|
||
|
||
void find_text_changed();
|
||
void notify_search_text_changed();
|
||
void update_result_label(size_t current_match_index, Optional<size_t> const& total_match_count);
|
||
|
||
RefPtr<WebView::OutOfProcessWebView> m_web_content_view;
|
||
|
||
RefPtr<GUI::Button> m_close_button;
|
||
RefPtr<GUI::Button> m_previous_button;
|
||
RefPtr<GUI::Button> m_next_button;
|
||
RefPtr<GUI::TextBox> m_search_textbox;
|
||
RefPtr<GUI::CheckBox> m_match_case_checkbox;
|
||
RefPtr<GUI::Label> m_result_label;
|
||
};
|
||
|
||
}
|