Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Browser: Add find-in-page UI #25580

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion Userland/Applications/Browser/BrowserWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,31 @@ BrowserWindow::BrowserWindow(WebView::CookieJar& cookie_jar, Vector<URL::URL> co
auto app_icon = GUI::Icon::default_icon("app-browser"sv);
m_bookmarks_bar = Browser::BookmarksBarWidget::construct(Browser::bookmarks_file_path(), true);

// Search Widget
auto& search_widget = widget->add<GUI::Widget>();
search_widget.set_layout<GUI::HorizontalBoxLayout>();
search_widget.set_fixed_height(30);
search_widget.set_visible(false);

auto& search_bar = search_widget.add<GUI::TextBox>();
search_bar.set_fixed_width(200);
search_bar.set_placeholder("Find in page...");

auto& find_next_button = search_widget.add<GUI::Button>("Next");
find_next_button.on_click = [this, &search_bar] {
active_tab().find_next();
};

auto& find_prev_button = search_widget.add<GUI::Button>("Previous");
find_prev_button.on_click = [this, &search_bar] {
active_tab().find_previous();
};

auto& close_search_button = search_widget.add<GUI::Button>("Close");
close_search_button.on_click = [&search_widget] {
search_widget.set_visible(false);
};

restore_size_and_position("Browser"sv, "Window"sv, { { 730, 560 } });
save_size_and_position_on_close("Browser"sv, "Window"sv);
set_icon(app_icon.bitmap_for_size(16));
Expand Down Expand Up @@ -776,7 +801,10 @@ void BrowserWindow::update_displayed_zoom_level()
active_tab().update_reset_zoom_button();
update_zoom_menu();
}

void BrowserWindow::update_actions() {
// Ensure find-in-page is hooked correctly to the active tab.
if (this != &window().active_tab()) return;
}
void BrowserWindow::show_task_manager_window()
{
if (!m_task_manager_window) {
Expand Down
67 changes: 67 additions & 0 deletions Userland/Applications/Browser/Tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,73 @@ Tab::~Tab()
{
close_sub_widgets();
}
void Tab::find_in_page(StringView query)
{
if (query.is_empty()) {
view().clear_find_highlights();
return;
}
view().search_for_text(query);
}

void Tab::find_next()
{
view().find_next_match();
}

void Tab::find_previous()
{
view().find_previous_match();
}

// Other existing methods remain unchanged...

URL::URL Tab::url() const
{
return m_web_content_view->url();
}

void Tab::reload()
{
view().reload();
}

void Tab::go_back()
{
view().traverse_the_history_by_delta(-1);
}

void Tab::go_forward()
{
view().traverse_the_history_by_delta(1);
}

void Tab::update_actions()
{
auto& window = this->window();
if (this != &window.active_tab())
return;
window.go_back_action().set_enabled(m_can_navigate_back);
window.go_forward_action().set_enabled(m_can_navigate_forward);
}

void Tab::load(URL::URL const& url)
{
m_web_content_view->load(url);
m_location_box->set_focus(false);
}

BrowserWindow const& Tab::window() const
{
return static_cast<BrowserWindow const&>(*Widget::window());
}

BrowserWindow& Tab::window()
{
return static_cast<BrowserWindow&>(*Widget::window());
}

}

void Tab::start_download(const URL::URL& url)
{
Expand Down
Loading