summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-13 22:23:18 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-13 22:23:18 +0000
commit701cf8d354f62ad1a71976f95230b1c1dd8ae5b4 (patch)
tree187aa480f61b36ff63f3766c3e2df51dbf69f1bd /chrome/browser
parent1897eb149d1d1cec1e6c5c69d207edabb3bc4f22 (diff)
downloadchromium_src-701cf8d354f62ad1a71976f95230b1c1dd8ae5b4.zip
chromium_src-701cf8d354f62ad1a71976f95230b1c1dd8ae5b4.tar.gz
chromium_src-701cf8d354f62ad1a71976f95230b1c1dd8ae5b4.tar.bz2
Implement tooltips for the Go/Stop button in Linux.
BUG=9381 Review URL: http://codereview.chromium.org/67064 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13618 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/gtk/browser_toolbar_gtk.cc2
-rw-r--r--chrome/browser/gtk/go_button_gtk.cc39
-rw-r--r--chrome/browser/gtk/go_button_gtk.h8
-rw-r--r--chrome/browser/gtk/go_button_gtk_unittest.cc2
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.h5
5 files changed, 48 insertions, 8 deletions
diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc
index 60eb7c1..f5301ce 100644
--- a/chrome/browser/gtk/browser_toolbar_gtk.cc
+++ b/chrome/browser/gtk/browser_toolbar_gtk.cc
@@ -125,7 +125,7 @@ void BrowserToolbarGtk::Init(Profile* profile,
location_bar_->Init();
gtk_box_pack_start(GTK_BOX(toolbar_), location_bar_->widget(), TRUE, TRUE, 0);
- go_.reset(new GoButtonGtk(browser_));
+ go_.reset(new GoButtonGtk(location_bar_.get(), browser_));
gtk_box_pack_start(GTK_BOX(toolbar_), go_->widget(), FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(toolbar_), gtk_label_new(" "), FALSE, FALSE, 0);
diff --git a/chrome/browser/gtk/go_button_gtk.cc b/chrome/browser/gtk/go_button_gtk.cc
index 2f32e64..21e3536 100644
--- a/chrome/browser/gtk/go_button_gtk.cc
+++ b/chrome/browser/gtk/go_button_gtk.cc
@@ -7,10 +7,14 @@
#include "base/message_loop.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/browser.h"
+#include "chrome/browser/gtk/location_bar_view_gtk.h"
+#include "chrome/common/l10n_util.h"
+#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
-GoButtonGtk::GoButtonGtk(Browser* browser)
- : browser_(browser),
+GoButtonGtk::GoButtonGtk(LocationBarViewGtk* location_bar, Browser* browser)
+ : location_bar_(location_bar),
+ browser_(browser),
button_delay_(0),
stop_timer_(this),
intended_mode_(MODE_GO),
@@ -37,8 +41,7 @@ GoButtonGtk::GoButtonGtk(Browser* browser)
G_CALLBACK(OnClicked), this);
GTK_WIDGET_UNSET_FLAGS(widget_.get(), GTK_CAN_FOCUS);
- // TODO(willchan): Implement tooltips.
- gtk_widget_set_tooltip_text(widget_.get(), "Implement toggleable tooltips");
+ SetTooltip();
}
GoButtonGtk::~GoButtonGtk() {
@@ -48,10 +51,11 @@ GoButtonGtk::~GoButtonGtk() {
void GoButtonGtk::ChangeMode(Mode mode) {
if (mode != visible_mode_) {
gtk_widget_queue_draw(widget_.get());
+ visible_mode_ = mode;
+ SetTooltip();
}
stop_timer_.RevokeAll();
intended_mode_ = mode;
- visible_mode_ = mode;
}
void GoButtonGtk::ScheduleChangeMode(Mode mode) {
@@ -154,3 +158,28 @@ gboolean GoButtonGtk::OnClicked(GtkButton* widget, GoButtonGtk* button) {
return TRUE;
}
+
+void GoButtonGtk::SetTooltip() {
+ if (visible_mode_ == MODE_GO) {
+ // |location_bar_| can be NULL in tests.
+ std::wstring current_text(
+ location_bar_ ? location_bar_->location_entry()->GetText() :
+ L"");
+ if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) {
+ l10n_util::WrapStringWithLTRFormatting(&current_text);
+ }
+
+ // TODO(pkasting): http://b/868940 Use the right strings at the right
+ // times by asking the autocomplete system what to do. Don't hardcode
+ // "Google" as the search provider name.
+ gtk_widget_set_tooltip_text(
+ widget_.get(),
+ true ? l10n_util::GetStringFUTF8(
+ IDS_TOOLTIP_GO_SITE, WideToUTF16(current_text)).c_str() :
+ l10n_util::GetStringFUTF8(IDS_TOOLTIP_GO_SEARCH, UTF8ToUTF16("Google"),
+ WideToUTF16(current_text)).c_str());
+ } else {
+ gtk_widget_set_tooltip_text(
+ widget_.get(), l10n_util::GetStringUTF8(IDS_TOOLTIP_STOP).c_str());
+ }
+}
diff --git a/chrome/browser/gtk/go_button_gtk.h b/chrome/browser/gtk/go_button_gtk.h
index 047feec..e69f842 100644
--- a/chrome/browser/gtk/go_button_gtk.h
+++ b/chrome/browser/gtk/go_button_gtk.h
@@ -13,6 +13,7 @@
#include "chrome/common/owned_widget_gtk.h"
class Browser;
+class LocationBarViewGtk;
class Task;
class GoButtonGtk {
@@ -20,7 +21,7 @@ class GoButtonGtk {
enum Mode { MODE_GO = 0, MODE_STOP };
enum ButtonState { BS_NORMAL = 0, BS_HOT };
- explicit GoButtonGtk(Browser* browser);
+ GoButtonGtk(LocationBarViewGtk* location_bar, Browser* browser);
~GoButtonGtk();
GtkWidget* widget() const { return widget_.get(); }
@@ -46,8 +47,13 @@ class GoButtonGtk {
static gboolean OnLeave(GtkButton* widget, GoButtonGtk* button);
static gboolean OnClicked(GtkButton* widget, GoButtonGtk* button);
+ void SetToggled();
+
Task* CreateButtonTimerTask();
void OnButtonTimer();
+ void SetTooltip();
+
+ LocationBarViewGtk* const location_bar_;
// Keep a pointer to the Browser object to execute commands on it.
Browser* const browser_;
diff --git a/chrome/browser/gtk/go_button_gtk_unittest.cc b/chrome/browser/gtk/go_button_gtk_unittest.cc
index e6158cd..e61c201 100644
--- a/chrome/browser/gtk/go_button_gtk_unittest.cc
+++ b/chrome/browser/gtk/go_button_gtk_unittest.cc
@@ -42,7 +42,7 @@ namespace {
class GoButtonGtkTest : public testing::Test {
protected:
- GoButtonGtkTest() : go_(NULL), peer_(&go_) { }
+ GoButtonGtkTest() : go_(NULL, NULL), peer_(&go_) { }
protected:
GoButtonGtk go_;
diff --git a/chrome/browser/gtk/location_bar_view_gtk.h b/chrome/browser/gtk/location_bar_view_gtk.h
index 8f4d017..104352c 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.h
+++ b/chrome/browser/gtk/location_bar_view_gtk.h
@@ -12,6 +12,7 @@
#include "base/basictypes.h"
#include "base/scoped_ptr.h"
#include "chrome/browser/autocomplete/autocomplete_edit.h"
+#include "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h"
#include "chrome/browser/location_bar.h"
#include "chrome/common/owned_widget_gtk.h"
#include "chrome/common/page_transition_types.h"
@@ -43,6 +44,10 @@ class LocationBarViewGtk : public AutocompleteEditController,
// restore saved state that the tab holds.
void Update(const TabContents* tab_for_state_restoring);
+ AutocompleteEditView* location_entry() {
+ return location_entry_.get();
+ }
+
// Implement the AutocompleteEditController interface.
virtual void OnAutocompleteAccept(const GURL& url,
WindowOpenDisposition disposition,