diff options
author | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-10 19:26:19 +0000 |
---|---|---|
committer | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-10 19:26:19 +0000 |
commit | 31b1bc3aee74415fc8333f537da2dde64f0e08f9 (patch) | |
tree | 754865e0f773e0fb4fc647ae61eb43a8a79d775c | |
parent | ef47b8c0779d03237d4a20cb419ec4935deaa491 (diff) | |
download | chromium_src-31b1bc3aee74415fc8333f537da2dde64f0e08f9.zip chromium_src-31b1bc3aee74415fc8333f537da2dde64f0e08f9.tar.gz chromium_src-31b1bc3aee74415fc8333f537da2dde64f0e08f9.tar.bz2 |
First cut at the find bar.
Ctrl+F will display a box (pushing down the web contents) that typing
into will cause webkit to highlight on the page. Esc will dismiss the
box.
I also changed the gtk_widget_show_all in browser window to be a regular gtk_widget_show. Child widgets need to manually show themselves now.
Review URL: http://codereview.chromium.org/42026
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11364 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/browser.cc | 6 | ||||
-rw-r--r-- | chrome/browser/browser.h | 4 | ||||
-rw-r--r-- | chrome/browser/browser.scons | 1 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_toolbar_gtk.cc | 2 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_window_gtk.cc | 15 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_window_gtk.h | 6 | ||||
-rw-r--r-- | chrome/browser/gtk/find_bar_gtk.cc | 70 | ||||
-rw-r--r-- | chrome/browser/gtk/find_bar_gtk.h | 47 | ||||
-rw-r--r-- | chrome/browser/gtk/tab_contents_container_gtk.cc | 7 | ||||
-rw-r--r-- | chrome/browser/gtk/tab_contents_container_gtk.h | 5 |
10 files changed, 149 insertions, 14 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 43e4a49..dea7ae1 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -863,6 +863,7 @@ void Browser::Paste() { UserMetrics::RecordAction(L"Paste", profile_); ui_controls::SendKeyPress(L'V', true, false, false); } +#endif // #if defined(OS_WIN) void Browser::Find() { UserMetrics::RecordAction(L"Find", profile_); @@ -878,7 +879,6 @@ void Browser::FindPrevious() { UserMetrics::RecordAction(L"FindPrevious", profile_); FindInPage(true, false); } -#endif // #if defined(OS_WIN) void Browser::ZoomIn() { UserMetrics::RecordAction(L"ZoomPlus", profile_); @@ -1202,12 +1202,12 @@ void Browser::ExecuteCommand(int id) { case IDC_COPY: Copy(); break; case IDC_COPY_URL: CopyCurrentPageURL(); break; case IDC_PASTE: Paste(); break; +#endif // Find-in-page case IDC_FIND: Find(); break; case IDC_FIND_NEXT: FindNext(); break; case IDC_FIND_PREVIOUS: FindPrevious(); break; -#endif // Zoom case IDC_ZOOM_PLUS: ZoomIn(); break; @@ -2439,7 +2439,6 @@ GURL Browser::GetHomePage() { return home_page; } -#if defined(OS_WIN) void Browser::FindInPage(bool find_next, bool forward_direction) { window_->ShowFindBar(); if (find_next) { @@ -2448,7 +2447,6 @@ void Browser::FindInPage(bool find_next, bool forward_direction) { forward_direction); } } -#endif // OS_WIN void Browser::CloseFrame() { window_->Close(); diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h index dc9ebbd..d6977822 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -295,12 +295,12 @@ class Browser : public TabStripModelDelegate, void Copy(); void CopyCurrentPageURL(); void Paste(); +#endif // Find-in-page void Find(); void FindNext(); void FindPrevious(); -#endif // Zoom void ZoomIn(); @@ -546,12 +546,10 @@ class Browser : public TabStripModelDelegate, // has not been set. GURL GetHomePage(); -#if defined(OS_WIN) // Shows the Find Bar, optionally selecting the next entry that matches the // existing search string for that Tab. |forward_direction| controls the // search direction. void FindInPage(bool find_next, bool forward_direction); -#endif // Closes the frame. // TODO(beng): figure out if we need this now that the frame itself closes diff --git a/chrome/browser/browser.scons b/chrome/browser/browser.scons index 7c820b4..fd164282 100644 --- a/chrome/browser/browser.scons +++ b/chrome/browser/browser.scons @@ -746,6 +746,7 @@ if env.Bit('linux'): 'gtk/custom_button.cc', 'gtk/download_item_gtk.cc', 'gtk/download_shelf_gtk.cc', + 'gtk/find_bar_gtk.cc', 'gtk/location_bar_view_gtk.cc', 'gtk/menu_gtk.cc', 'gtk/nine_box.cc', diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc index 0196267..ff770c6 100644 --- a/chrome/browser/gtk/browser_toolbar_gtk.cc +++ b/chrome/browser/gtk/browser_toolbar_gtk.cc @@ -133,6 +133,8 @@ void BrowserToolbarGtk::Init(Profile* profile, GtkAccelGroup* accel_group) { l10n_util::GetStringF(IDS_APPMENU_TOOLTIP, l10n_util::GetString(IDS_PRODUCT_NAME)))); app_menu_.reset(new MenuGtk(this, GetStandardAppMenu(), accel_group_)); + + gtk_widget_show_all(toolbar_); } void BrowserToolbarGtk::AddToolbarToBox(GtkWidget* box) { diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc index 8ac350e..484b5ff 100644 --- a/chrome/browser/gtk/browser_window_gtk.cc +++ b/chrome/browser/gtk/browser_window_gtk.cc @@ -9,6 +9,7 @@ #include "base/path_service.h" #include "chrome/browser/browser.h" #include "chrome/browser/gtk/browser_toolbar_gtk.h" +#include "chrome/browser/gtk/find_bar_gtk.h" #include "chrome/browser/gtk/nine_box.h" #include "chrome/browser/gtk/status_bubble_gtk.h" #include "chrome/browser/gtk/tab_contents_container_gtk.h" @@ -131,7 +132,6 @@ gboolean BrowserWindowGtk::OnContentAreaExpose(GtkWidget* widget, void BrowserWindowGtk::Init() { window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); - gtk_window_set_title(window_, "Chromium"); gtk_window_set_default_size(window_, 640, 480); g_signal_connect(G_OBJECT(window_), "destroy", G_CALLBACK(MainWindowDestroyed), this); @@ -169,7 +169,11 @@ void BrowserWindowGtk::Init() { toolbar_->Init(browser_->profile(), accel_group); toolbar_->AddToolbarToBox(vbox_); - contents_container_.reset(new TabContentsContainerGtk()); + find_bar_.reset(new FindBarGtk()); + + contents_container_.reset(new TabContentsContainerGtk( + find_bar_->gtk_widget())); + contents_container_->AddContainerToBox(vbox_); // Note that calling this the first time is necessary to get the @@ -180,10 +184,11 @@ void BrowserWindowGtk::Init() { status_bubble_.reset(new StatusBubbleGtk(window_)); gtk_container_add(GTK_CONTAINER(window_), vbox_); + gtk_widget_show(vbox_); } void BrowserWindowGtk::Show() { - gtk_widget_show_all(GTK_WIDGET(window_)); + gtk_widget_show(GTK_WIDGET(window_)); } void BrowserWindowGtk::SetBounds(const gfx::Rect& bounds) { @@ -306,7 +311,7 @@ void BrowserWindowGtk::ToggleBookmarkBar() { } void BrowserWindowGtk::ShowFindBar() { - NOTIMPLEMENTED(); + find_bar_->Show(); } void BrowserWindowGtk::ShowAboutChromeDialog() { @@ -384,6 +389,8 @@ void BrowserWindowGtk::TabSelectedAt(TabContents* old_contents, UpdateTitleBar(); toolbar_->SetProfile(new_contents->profile()); UpdateToolbar(new_contents, true); + + find_bar_->ChangeWebContents(new_contents->AsWebContents()); } void BrowserWindowGtk::TabStripEmpty() { diff --git a/chrome/browser/gtk/browser_window_gtk.h b/chrome/browser/gtk/browser_window_gtk.h index c42ad97..df1fbdd 100644 --- a/chrome/browser/gtk/browser_window_gtk.h +++ b/chrome/browser/gtk/browser_window_gtk.h @@ -13,6 +13,7 @@ #include "chrome/browser/tabs/tab_strip_model.h" class BrowserToolbarGtk; +class FindBarGtk; class LocationBar; class NineBox; class StatusBubbleGtk; @@ -119,6 +120,11 @@ class BrowserWindowGtk : public BrowserWindow, // (along with associated infobars, shelves, and other things that are part // of the content area). scoped_ptr<TabContentsContainerGtk> contents_container_; + + // The Find Bar. This may be NULL if there is no Find Bar, and if it is + // non-NULL, it may or may not be visible. It is possible for the Find Bar + // to move among windows as tabs are dragged around. + scoped_ptr<FindBarGtk> find_bar_; }; #endif // CHROME_BROWSER_GTK_BROWSER_WINDOW_GTK_H_ diff --git a/chrome/browser/gtk/find_bar_gtk.cc b/chrome/browser/gtk/find_bar_gtk.cc new file mode 100644 index 0000000..5bfe1c6 --- /dev/null +++ b/chrome/browser/gtk/find_bar_gtk.cc @@ -0,0 +1,70 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/gtk/find_bar_gtk.h" + +#include <gdk/gdkkeysyms.h> + +#include "base/string_util.h" +#include "chrome/browser/gtk/tab_contents_container_gtk.h" +#include "chrome/browser/tab_contents/web_contents.h" + +namespace { + +gboolean EntryContentsChanged(GtkWindow* window, FindBarGtk* find_bar) { + find_bar->ContentsChanged(); + return FALSE; +} + +gboolean KeyPressEvent(GtkWindow* window, GdkEventKey* event, + FindBarGtk* find_bar) { + if (GDK_Escape == event->keyval) + find_bar->Hide(); + return FALSE; +} + +} + +FindBarGtk::FindBarGtk() : web_contents_(NULL) { + find_text_ = gtk_entry_new(); + gtk_widget_show(find_text_); + + container_ = gtk_hbox_new(false, 2); + gtk_box_pack_end(GTK_BOX(container_), find_text_, FALSE, FALSE, 0); + + g_signal_connect(G_OBJECT(find_text_), "changed", + G_CALLBACK(EntryContentsChanged), this); + g_signal_connect(G_OBJECT(find_text_), "key-press-event", + G_CALLBACK(KeyPressEvent), this); +} + +void FindBarGtk::Show() { + // TODO(tc): This should be an animated slide in. + gtk_widget_show(container_); + gtk_widget_grab_focus(find_text_); +} + +void FindBarGtk::Hide() { + gtk_widget_hide(container_); + if (web_contents_) + web_contents_->StopFinding(true); +} + +void FindBarGtk::ContentsChanged() { + if (!web_contents_) + return; + + std::string new_contents(gtk_entry_get_text(GTK_ENTRY(find_text_))); + + if (new_contents.length() > 0) { + web_contents_->StartFinding(UTF8ToWide(new_contents), true); + } else { + // The textbox is empty so we reset. + web_contents_->StopFinding(true); // true = clear selection on page. + } +} + +void FindBarGtk::ChangeWebContents(WebContents* contents) { + web_contents_ = contents; +} diff --git a/chrome/browser/gtk/find_bar_gtk.h b/chrome/browser/gtk/find_bar_gtk.h new file mode 100644 index 0000000..9a38ce9 --- /dev/null +++ b/chrome/browser/gtk/find_bar_gtk.h @@ -0,0 +1,47 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_GTK_FIND_BAR_GTK_H_ +#define CHROME_BROWSER_GTK_FIND_BAR_GTK_H_ + +#include <string> + +#include <gtk/gtk.h> + +class TabContentsContainerGtk; +class WebContents; + +// Currently this class contains both a model and a view. We may want to +// eventually pull out the model specific bits and share with Windows. +class FindBarGtk { + public: + FindBarGtk(); + ~FindBarGtk() { } + + // Show the find dialog if it's not already showing. The Find dialog is + // positioned above the web contents area (TabContentsContainerGtk). + void Show(); + void Hide(); + + // Callback when the text in the find box changes. + void ContentsChanged(); + + // Callback from BrowserWindowGtk when the web contents changes. + void ChangeWebContents(WebContents* contents); + + GtkWidget* gtk_widget() const { return container_; } + + private: + // GtkHBox containing the find bar widgets. + GtkWidget* container_; + + // The widget where text is entered. + GtkWidget* find_text_; + + // A non-owning pointer to the web contents associated with the find bar. + // This can be NULL. + WebContents* web_contents_; +}; + +#endif // CHROME_BROWSER_GTK_FIND_BAR_GTK_H_ diff --git a/chrome/browser/gtk/tab_contents_container_gtk.cc b/chrome/browser/gtk/tab_contents_container_gtk.cc index 7813143..0b38c76 100644 --- a/chrome/browser/gtk/tab_contents_container_gtk.cc +++ b/chrome/browser/gtk/tab_contents_container_gtk.cc @@ -10,9 +10,12 @@ #include "chrome/common/notification_service.h" -TabContentsContainerGtk::TabContentsContainerGtk() +TabContentsContainerGtk::TabContentsContainerGtk(GtkWidget* findbar) : tab_contents_(NULL), vbox_(gtk_vbox_new(FALSE, 0)) { + DCHECK(findbar); + gtk_box_pack_start(GTK_BOX(vbox_), findbar, FALSE, FALSE, 0); + gtk_widget_show(vbox_); } TabContentsContainerGtk::~TabContentsContainerGtk() { @@ -44,7 +47,7 @@ void TabContentsContainerGtk::SetTabContents(TabContents* tab_contents) { gfx::NativeView widget = tab_contents_->GetNativeView(); if (widget) { - gtk_box_pack_start(GTK_BOX(vbox_), widget, TRUE, TRUE, 0); + gtk_box_pack_end(GTK_BOX(vbox_), widget, TRUE, TRUE, 0); gtk_widget_show_all(widget); } } diff --git a/chrome/browser/gtk/tab_contents_container_gtk.h b/chrome/browser/gtk/tab_contents_container_gtk.h index c8868b6..19e8c92 100644 --- a/chrome/browser/gtk/tab_contents_container_gtk.h +++ b/chrome/browser/gtk/tab_contents_container_gtk.h @@ -15,7 +15,10 @@ class TabContents; class TabContentsContainerGtk : public NotificationObserver { public: - TabContentsContainerGtk(); + // |findbar| is a pointer to the find bar container widget. Since the + // position is relative to the tab contents, we position the find bar using + // the tab contents container. + explicit TabContentsContainerGtk(GtkWidget* findbar); ~TabContentsContainerGtk(); // Inserts our GtkWidget* hierarchy into a GtkBox managed by our owner. |