Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: chrome/browser/gtk/go_button_gtk.cc

Issue 67064: Implement tooltips for the Go/Stop button in Linux. (Closed)
Patch Set: Add a NULL check on location_bar_ for tests. Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/gtk/go_button_gtk.h ('k') | chrome/browser/gtk/go_button_gtk_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/gtk/go_button_gtk.h" 5 #include "chrome/browser/gtk/go_button_gtk.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "chrome/app/chrome_dll_resource.h" 8 #include "chrome/app/chrome_dll_resource.h"
9 #include "chrome/browser/browser.h" 9 #include "chrome/browser/browser.h"
10 #include "chrome/browser/gtk/location_bar_view_gtk.h"
11 #include "chrome/common/l10n_util.h"
12 #include "grit/generated_resources.h"
10 #include "grit/theme_resources.h" 13 #include "grit/theme_resources.h"
11 14
12 GoButtonGtk::GoButtonGtk(Browser* browser) 15 GoButtonGtk::GoButtonGtk(LocationBarViewGtk* location_bar, Browser* browser)
13 : browser_(browser), 16 : location_bar_(location_bar),
17 browser_(browser),
14 button_delay_(0), 18 button_delay_(0),
15 stop_timer_(this), 19 stop_timer_(this),
16 intended_mode_(MODE_GO), 20 intended_mode_(MODE_GO),
17 visible_mode_(MODE_GO), 21 visible_mode_(MODE_GO),
18 state_(BS_NORMAL), 22 state_(BS_NORMAL),
19 go_(IDR_GO, IDR_GO_P, IDR_GO_H, 0), 23 go_(IDR_GO, IDR_GO_P, IDR_GO_H, 0),
20 stop_(IDR_STOP, IDR_STOP_P, IDR_STOP_H, 0), 24 stop_(IDR_STOP, IDR_STOP_P, IDR_STOP_H, 0),
21 widget_(gtk_button_new()) { 25 widget_(gtk_button_new()) {
22 gtk_widget_set_size_request(widget_.get(), 26 gtk_widget_set_size_request(widget_.get(),
23 gdk_pixbuf_get_width(go_.pixbufs(0)), 27 gdk_pixbuf_get_width(go_.pixbufs(0)),
24 gdk_pixbuf_get_height(go_.pixbufs(0))); 28 gdk_pixbuf_get_height(go_.pixbufs(0)));
25 29
26 gtk_widget_set_app_paintable(widget_.get(), TRUE); 30 gtk_widget_set_app_paintable(widget_.get(), TRUE);
27 // We effectively double-buffer by virtue of having only one image... 31 // We effectively double-buffer by virtue of having only one image...
28 gtk_widget_set_double_buffered(widget_.get(), FALSE); 32 gtk_widget_set_double_buffered(widget_.get(), FALSE);
29 33
30 g_signal_connect(G_OBJECT(widget_.get()), "expose-event", 34 g_signal_connect(G_OBJECT(widget_.get()), "expose-event",
31 G_CALLBACK(OnExpose), this); 35 G_CALLBACK(OnExpose), this);
32 g_signal_connect(G_OBJECT(widget_.get()), "enter", 36 g_signal_connect(G_OBJECT(widget_.get()), "enter",
33 G_CALLBACK(OnEnter), this); 37 G_CALLBACK(OnEnter), this);
34 g_signal_connect(G_OBJECT(widget_.get()), "leave", 38 g_signal_connect(G_OBJECT(widget_.get()), "leave",
35 G_CALLBACK(OnLeave), this); 39 G_CALLBACK(OnLeave), this);
36 g_signal_connect(G_OBJECT(widget_.get()), "clicked", 40 g_signal_connect(G_OBJECT(widget_.get()), "clicked",
37 G_CALLBACK(OnClicked), this); 41 G_CALLBACK(OnClicked), this);
38 GTK_WIDGET_UNSET_FLAGS(widget_.get(), GTK_CAN_FOCUS); 42 GTK_WIDGET_UNSET_FLAGS(widget_.get(), GTK_CAN_FOCUS);
39 43
40 // TODO(willchan): Implement tooltips. 44 SetTooltip();
41 gtk_widget_set_tooltip_text(widget_.get(), "Implement toggleable tooltips");
42 } 45 }
43 46
44 GoButtonGtk::~GoButtonGtk() { 47 GoButtonGtk::~GoButtonGtk() {
45 widget_.Destroy(); 48 widget_.Destroy();
46 } 49 }
47 50
48 void GoButtonGtk::ChangeMode(Mode mode) { 51 void GoButtonGtk::ChangeMode(Mode mode) {
49 if (mode != visible_mode_) { 52 if (mode != visible_mode_) {
50 gtk_widget_queue_draw(widget_.get()); 53 gtk_widget_queue_draw(widget_.get());
54 visible_mode_ = mode;
55 SetTooltip();
51 } 56 }
52 stop_timer_.RevokeAll(); 57 stop_timer_.RevokeAll();
53 intended_mode_ = mode; 58 intended_mode_ = mode;
54 visible_mode_ = mode;
55 } 59 }
56 60
57 void GoButtonGtk::ScheduleChangeMode(Mode mode) { 61 void GoButtonGtk::ScheduleChangeMode(Mode mode) {
58 if (mode == MODE_STOP) { 62 if (mode == MODE_STOP) {
59 // If we still have a timer running, we can't yet change to a stop sign, 63 // If we still have a timer running, we can't yet change to a stop sign,
60 // so we'll queue up the change for when the timer expires or for when 64 // so we'll queue up the change for when the timer expires or for when
61 // the mouse exits the button. 65 // the mouse exits the button.
62 if (!stop_timer_.empty() && state() == BS_HOT) { 66 if (!stop_timer_.empty() && state() == BS_HOT) {
63 intended_mode_ = MODE_STOP; 67 intended_mode_ = MODE_STOP;
64 } else { 68 } else {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 // to MODE_STOP here as we want to wait for the browser to tell 151 // to MODE_STOP here as we want to wait for the browser to tell
148 // us that it has started loading (and this may occur only after 152 // us that it has started loading (and this may occur only after
149 // some delay). 153 // some delay).
150 MessageLoop::current()->PostDelayedTask(FROM_HERE, 154 MessageLoop::current()->PostDelayedTask(FROM_HERE,
151 button->CreateButtonTimerTask(), 155 button->CreateButtonTimerTask(),
152 button->button_delay_); 156 button->button_delay_);
153 } 157 }
154 158
155 return TRUE; 159 return TRUE;
156 } 160 }
161
162 void GoButtonGtk::SetTooltip() {
163 if (visible_mode_ == MODE_GO) {
164 // |location_bar_| can be NULL in tests.
165 std::wstring current_text(
166 location_bar_ ? location_bar_->location_entry()->GetText() :
167 L"");
168 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) {
169 l10n_util::WrapStringWithLTRFormatting(&current_text);
170 }
171
172 // TODO(pkasting): http://b/868940 Use the right strings at the right
173 // times by asking the autocomplete system what to do. Don't hardcode
174 // "Google" as the search provider name.
175 gtk_widget_set_tooltip_text(
176 widget_.get(),
177 true ? l10n_util::GetStringFUTF8(
178 IDS_TOOLTIP_GO_SITE, WideToUTF16(current_text)).c_str() :
179 l10n_util::GetStringFUTF8(IDS_TOOLTIP_GO_SEARCH, UTF8ToUTF16("Google"),
180 WideToUTF16(current_text)).c_str());
181 } else {
182 gtk_widget_set_tooltip_text(
183 widget_.get(), l10n_util::GetStringUTF8(IDS_TOOLTIP_STOP).c_str());
184 }
185 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/go_button_gtk.h ('k') | chrome/browser/gtk/go_button_gtk_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698