summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk
diff options
context:
space:
mode:
authortc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-24 18:38:12 +0000
committertc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-24 18:38:12 +0000
commitcd20e924b7103c66da8299c3eaa15f5900ae1de8 (patch)
tree530f1898fc8cdaff3c5b751beb0a618475d967f7 /chrome/browser/gtk
parent3a9059af548b217862ab7471531e719627cfa816 (diff)
downloadchromium_src-cd20e924b7103c66da8299c3eaa15f5900ae1de8.zip
chromium_src-cd20e924b7103c66da8299c3eaa15f5900ae1de8.tar.gz
chromium_src-cd20e924b7103c66da8299c3eaa15f5900ae1de8.tar.bz2
Make the find bar blue. Hooks up the prev/next buttons and the
close button. Review URL: http://codereview.chromium.org/50079 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12378 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk')
-rw-r--r--chrome/browser/gtk/find_bar_gtk.cc104
-rw-r--r--chrome/browser/gtk/find_bar_gtk.h14
2 files changed, 106 insertions, 12 deletions
diff --git a/chrome/browser/gtk/find_bar_gtk.cc b/chrome/browser/gtk/find_bar_gtk.cc
index a779a2b8..d6fb447 100644
--- a/chrome/browser/gtk/find_bar_gtk.cc
+++ b/chrome/browser/gtk/find_bar_gtk.cc
@@ -6,13 +6,22 @@
#include <gdk/gdkkeysyms.h>
+#include "base/gfx/gtk_util.h"
#include "base/string_util.h"
#include "chrome/browser/find_bar_controller.h"
+#include "chrome/browser/gtk/custom_button.h"
#include "chrome/browser/gtk/tab_contents_container_gtk.h"
#include "chrome/browser/tab_contents/web_contents.h"
+#include "chrome/common/l10n_util.h"
+#include "grit/generated_resources.h"
namespace {
+const GdkColor kBackgroundColor = GDK_COLOR_RGB(0xe6, 0xed, 0xf4);
+
+// Padding around the container.
+const int kBarPadding = 4;
+
gboolean EntryContentsChanged(GtkWindow* window, FindBarGtk* find_bar) {
find_bar->ContentsChanged();
return FALSE;
@@ -28,26 +37,76 @@ gboolean KeyPressEvent(GtkWindow* window, GdkEventKey* event,
}
FindBarGtk::FindBarGtk() {
- // TODO(tc): Pull out widget creation into an Init() method.
- find_text_ = gtk_entry_new();
- gtk_widget_show(find_text_);
-
- container_.Own(gtk_hbox_new(false, 2));
- gtk_box_pack_end(GTK_BOX(container_.get()), 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);
+ InitWidgets();
}
FindBarGtk::~FindBarGtk() {
container_.Destroy();
}
+void FindBarGtk::InitWidgets() {
+ // The find bar is basically an hbox with a gtkentry (text box) followed by 3
+ // buttons (previous result, next result, close). We wrap the hbox in a gtk
+ // alignment and a gtk event box to get the padding and light blue
+ // background.
+ GtkWidget* hbox = gtk_hbox_new(false, 0);
+ container_.Own(gfx::CreateGtkBorderBin(hbox, &kBackgroundColor, kBarPadding,
+ kBarPadding, kBarPadding, kBarPadding));
+
+ close_button_.reset(new CustomDrawButton(IDR_CLOSE_BAR, IDR_CLOSE_BAR_P,
+ IDR_CLOSE_BAR_H, 0));
+ g_signal_connect(G_OBJECT(close_button_->widget()), "clicked",
+ G_CALLBACK(OnButtonPressed), this);
+ gtk_widget_set_tooltip_text(close_button_->widget(),
+ WideToUTF8(l10n_util::GetString(IDS_FIND_IN_PAGE_CLOSE_TOOLTIP))
+ .c_str());
+ // Wrap the close X in a vbox to vertically align it.
+ GtkWidget* centering_vbox = gtk_vbox_new(FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(centering_vbox),
+ close_button_->widget(), TRUE, FALSE, 0);
+ gtk_box_pack_end(GTK_BOX(hbox), centering_vbox, FALSE, FALSE, 0);
+
+ find_next_button_.reset(new CustomDrawButton(IDR_FINDINPAGE_NEXT,
+ IDR_FINDINPAGE_NEXT_H, IDR_FINDINPAGE_NEXT_H, IDR_FINDINPAGE_NEXT_P));
+ g_signal_connect(G_OBJECT(find_next_button_->widget()), "clicked",
+ G_CALLBACK(OnButtonPressed), this);
+ gtk_widget_set_tooltip_text(find_next_button_->widget(),
+ WideToUTF8(l10n_util::GetString(IDS_FIND_IN_PAGE_NEXT_TOOLTIP))
+ .c_str());
+ gtk_box_pack_end(GTK_BOX(hbox), find_next_button_->widget(),
+ FALSE, FALSE, 0);
+
+ find_previous_button_.reset(new CustomDrawButton(IDR_FINDINPAGE_PREV,
+ IDR_FINDINPAGE_PREV_H, IDR_FINDINPAGE_PREV_H, IDR_FINDINPAGE_PREV_P));
+ g_signal_connect(G_OBJECT(find_previous_button_->widget()), "clicked",
+ G_CALLBACK(OnButtonPressed), this);
+ gtk_widget_set_tooltip_text(find_previous_button_->widget(),
+ WideToUTF8(l10n_util::GetString(IDS_FIND_IN_PAGE_PREVIOUS_TOOLTIP))
+ .c_str());
+ gtk_box_pack_end(GTK_BOX(hbox), find_previous_button_->widget(),
+ FALSE, FALSE, 0);
+
+ find_text_ = gtk_entry_new();
+ // Force the text widget height so it lines up with the buttons regardless of
+ // font size.
+ gtk_widget_set_size_request(find_text_, -1, 20);
+ gtk_entry_set_has_frame(GTK_ENTRY(find_text_), FALSE);
+ // TODO(tc): We need a border around the find box. This should probably be
+ // drawn by the background. I tried drawing one using
+ // gfx::CreateGtkBorderBin, but I couldn't get it to draw a 1px border on
+ // top and bottom.
+ gtk_box_pack_end(GTK_BOX(hbox), 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_.get());
+ gtk_widget_show_all(container_.get());
gtk_widget_grab_focus(find_text_);
}
@@ -57,6 +116,9 @@ void FindBarGtk::Hide(bool animate) {
}
void FindBarGtk::SetFocusAndSelection() {
+ gtk_widget_grab_focus(find_text_);
+ // Select all the text.
+ gtk_entry_select_region(GTK_ENTRY(find_text_), 0, -1);
}
void FindBarGtk::ClearResults(const FindNotificationDetails& results) {
@@ -67,6 +129,8 @@ void FindBarGtk::StopAnimation() {
}
void FindBarGtk::SetFindText(const string16& find_text) {
+ std::string find_text_utf8 = UTF16ToUTF8(find_text);
+ gtk_entry_set_text(GTK_ENTRY(find_text_), find_text_utf8.c_str());
}
void FindBarGtk::UpdateUIForFindResult(const FindNotificationDetails& result,
@@ -105,3 +169,19 @@ void FindBarGtk::ContentsChanged() {
void FindBarGtk::EscapePressed() {
find_bar_controller_->EndFindSession();
}
+
+// static
+void FindBarGtk::OnButtonPressed(GtkWidget* button, FindBarGtk* find_bar) {
+ if (button == find_bar->close_button_->widget()) {
+ find_bar->find_bar_controller_->EndFindSession();
+ } else if (button == find_bar->find_previous_button_->widget() ||
+ button == find_bar->find_next_button_->widget()) {
+ std::string find_text_utf8(
+ gtk_entry_get_text(GTK_ENTRY(find_bar->find_text_)));
+ find_bar->find_bar_controller_->web_contents()->StartFinding(
+ UTF8ToUTF16(find_text_utf8),
+ button == find_bar->find_next_button_->widget());
+ } else {
+ NOTREACHED();
+ }
+}
diff --git a/chrome/browser/gtk/find_bar_gtk.h b/chrome/browser/gtk/find_bar_gtk.h
index 73b87ee..bf79d50 100644
--- a/chrome/browser/gtk/find_bar_gtk.h
+++ b/chrome/browser/gtk/find_bar_gtk.h
@@ -8,9 +8,11 @@
#include <gtk/gtk.h>
#include "base/basictypes.h"
+#include "base/scoped_ptr.h"
#include "chrome/browser/find_bar.h"
#include "chrome/common/owned_widget_gtk.h"
+class CustomDrawButton;
class FindBarController;
class TabContentsContainerGtk;
class WebContents;
@@ -49,12 +51,24 @@ class FindBarGtk : public FindBar {
virtual void RestoreSavedFocus();
private:
+ void InitWidgets();
+
+ // Callback for previous, next, and close button.
+ static void OnButtonPressed(GtkWidget* button, FindBarGtk* find_bar);
+
// GtkHBox containing the find bar widgets.
OwnedWidgetGtk container_;
// The widget where text is entered.
GtkWidget* find_text_;
+ // The next and previous match buttons.
+ scoped_ptr<CustomDrawButton> find_previous_button_;
+ scoped_ptr<CustomDrawButton> find_next_button_;
+
+ // The X to close the find bar.
+ scoped_ptr<CustomDrawButton> close_button_;
+
// Pointer back to the owning controller.
FindBarController* find_bar_controller_;