diff --git a/Userland/Applications/Browser/BrowserWindow.cpp b/Userland/Applications/Browser/BrowserWindow.cpp index e3be87a7f55fef..5da8b6f8ef107a 100644 --- a/Userland/Applications/Browser/BrowserWindow.cpp +++ b/Userland/Applications/Browser/BrowserWindow.cpp @@ -59,6 +59,31 @@ BrowserWindow::BrowserWindow(WebView::CookieJar& cookie_jar, Vector 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(); + search_widget.set_layout(); + search_widget.set_fixed_height(30); + search_widget.set_visible(false); + + auto& search_bar = search_widget.add(); + search_bar.set_fixed_width(200); + search_bar.set_placeholder("Find in page..."); + + auto& find_next_button = search_widget.add("Next"); + find_next_button.on_click = [this, &search_bar] { + active_tab().find_next(); + }; + + auto& find_prev_button = search_widget.add("Previous"); + find_prev_button.on_click = [this, &search_bar] { + active_tab().find_previous(); + }; + + auto& close_search_button = search_widget.add("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)); @@ -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) { diff --git a/Userland/Applications/Browser/Tab.cpp b/Userland/Applications/Browser/Tab.cpp index b88f6d36861d02..d73dc003ff30a7 100644 --- a/Userland/Applications/Browser/Tab.cpp +++ b/Userland/Applications/Browser/Tab.cpp @@ -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(*Widget::window()); +} + +BrowserWindow& Tab::window() +{ + return static_cast(*Widget::window()); +} + +} void Tab::start_download(const URL::URL& url) {