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

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

Issue 149681: GTK Themes: Make the omnibox area look more native. (Closed)
Patch Set: Change names for Dean Created 11 years, 5 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/location_bar_view_gtk.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 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "chrome/app/chrome_dll_resource.h" 10 #include "chrome/app/chrome_dll_resource.h"
11 #include "chrome/browser/browser.h" 11 #include "chrome/browser/browser.h"
12 #include "chrome/browser/gtk/gtk_theme_provider.h"
12 #include "chrome/browser/gtk/location_bar_view_gtk.h" 13 #include "chrome/browser/gtk/location_bar_view_gtk.h"
13 #include "chrome/browser/gtk/gtk_theme_provider.h"
14 #include "chrome/browser/profile.h" 14 #include "chrome/browser/profile.h"
15 #include "chrome/common/notification_service.h"
15 #include "grit/generated_resources.h" 16 #include "grit/generated_resources.h"
16 #include "grit/theme_resources.h" 17 #include "grit/theme_resources.h"
17 18
18 GoButtonGtk::GoButtonGtk(LocationBarViewGtk* location_bar, Browser* browser) 19 GoButtonGtk::GoButtonGtk(LocationBarViewGtk* location_bar, Browser* browser)
19 : location_bar_(location_bar), 20 : location_bar_(location_bar),
20 browser_(browser), 21 browser_(browser),
21 button_delay_(0), 22 button_delay_(0),
22 stop_timer_(this), 23 stop_timer_(this),
23 intended_mode_(MODE_GO), 24 intended_mode_(MODE_GO),
24 visible_mode_(MODE_GO), 25 visible_mode_(MODE_GO),
25 state_(BS_NORMAL), 26 state_(BS_NORMAL),
26 go_(browser ? GtkThemeProvider::GetFrom(browser->profile()) : NULL, 27 theme_provider_(browser ?
27 IDR_GO, IDR_GO_P, IDR_GO_H, 0), 28 GtkThemeProvider::GetFrom(browser->profile()) : NULL),
28 stop_(browser ? GtkThemeProvider::GetFrom(browser->profile()) : NULL, 29 go_(theme_provider_, IDR_GO, IDR_GO_P, IDR_GO_H, 0),
29 IDR_STOP, IDR_STOP_P, IDR_STOP_H, 0), 30 stop_(theme_provider_, IDR_STOP, IDR_STOP_P, IDR_STOP_H, 0),
30 widget_(gtk_button_new()) { 31 widget_(gtk_button_new()) {
31 gtk_widget_set_size_request(widget_.get(), 32 gtk_widget_set_size_request(widget_.get(),
32 gdk_pixbuf_get_width(go_.pixbufs(0)), 33 gdk_pixbuf_get_width(go_.pixbufs(0)),
33 gdk_pixbuf_get_height(go_.pixbufs(0))); 34 gdk_pixbuf_get_height(go_.pixbufs(0)));
34 35
35 gtk_widget_set_app_paintable(widget_.get(), TRUE); 36 gtk_widget_set_app_paintable(widget_.get(), TRUE);
36 // We effectively double-buffer by virtue of having only one image... 37 // We effectively double-buffer by virtue of having only one image...
37 gtk_widget_set_double_buffered(widget_.get(), FALSE); 38 gtk_widget_set_double_buffered(widget_.get(), FALSE);
38 39
39 g_signal_connect(G_OBJECT(widget_.get()), "expose-event", 40 g_signal_connect(G_OBJECT(widget_.get()), "expose-event",
40 G_CALLBACK(OnExpose), this); 41 G_CALLBACK(OnExpose), this);
41 g_signal_connect(G_OBJECT(widget_.get()), "enter", 42 g_signal_connect(G_OBJECT(widget_.get()), "enter",
42 G_CALLBACK(OnEnter), this); 43 G_CALLBACK(OnEnter), this);
43 g_signal_connect(G_OBJECT(widget_.get()), "leave", 44 g_signal_connect(G_OBJECT(widget_.get()), "leave",
44 G_CALLBACK(OnLeave), this); 45 G_CALLBACK(OnLeave), this);
45 g_signal_connect(G_OBJECT(widget_.get()), "clicked", 46 g_signal_connect(G_OBJECT(widget_.get()), "clicked",
46 G_CALLBACK(OnClicked), this); 47 G_CALLBACK(OnClicked), this);
47 GTK_WIDGET_UNSET_FLAGS(widget_.get(), GTK_CAN_FOCUS); 48 GTK_WIDGET_UNSET_FLAGS(widget_.get(), GTK_CAN_FOCUS);
48 49
49 SetTooltip(); 50 SetTooltip();
51
52 if (theme_provider_) {
53 theme_provider_->InitThemesFor(this);
54 registrar_.Add(this,
55 NotificationType::BROWSER_THEME_CHANGED,
56 NotificationService::AllSources());
57 }
50 } 58 }
51 59
52 GoButtonGtk::~GoButtonGtk() { 60 GoButtonGtk::~GoButtonGtk() {
53 widget_.Destroy(); 61 widget_.Destroy();
54 } 62 }
55 63
56 void GoButtonGtk::ChangeMode(Mode mode, bool force) { 64 void GoButtonGtk::ChangeMode(Mode mode, bool force) {
57 intended_mode_ = mode; 65 intended_mode_ = mode;
58 66
59 // If the change is forced, or the user isn't hovering the icon, or it's safe 67 // If the change is forced, or the user isn't hovering the icon, or it's safe
60 // to change it to the other image type, make the change immediately; 68 // to change it to the other image type, make the change immediately;
61 // otherwise we'll let it happen later. 69 // otherwise we'll let it happen later.
62 if (force || (state() != BS_HOT) || ((mode == MODE_STOP) ? 70 if (force || (state() != BS_HOT) || ((mode == MODE_STOP) ?
63 stop_timer_.empty() : (visible_mode_ != MODE_STOP))) { 71 stop_timer_.empty() : (visible_mode_ != MODE_STOP))) {
64 stop_timer_.RevokeAll(); 72 stop_timer_.RevokeAll();
65 gtk_widget_queue_draw(widget_.get()); 73 gtk_widget_queue_draw(widget_.get());
66 SetTooltip(); 74 SetTooltip();
67 visible_mode_ = mode; 75 visible_mode_ = mode;
76
77 UpdateThemeButtons();
68 } 78 }
69 } 79 }
70 80
81 void GoButtonGtk::Observe(NotificationType type,
82 const NotificationSource& source, const NotificationDetails& details) {
83 DCHECK(NotificationType::BROWSER_THEME_CHANGED == type);
84
85 GtkThemeProvider* provider = static_cast<GtkThemeProvider*>(
86 Source<GtkThemeProvider>(source).ptr());
87 DCHECK(provider == theme_provider_);
88 UpdateThemeButtons();
89 }
90
71 Task* GoButtonGtk::CreateButtonTimerTask() { 91 Task* GoButtonGtk::CreateButtonTimerTask() {
72 return stop_timer_.NewRunnableMethod(&GoButtonGtk::OnButtonTimer); 92 return stop_timer_.NewRunnableMethod(&GoButtonGtk::OnButtonTimer);
73 } 93 }
74 94
75 void GoButtonGtk::OnButtonTimer() { 95 void GoButtonGtk::OnButtonTimer() {
76 stop_timer_.RevokeAll(); 96 stop_timer_.RevokeAll();
77 ChangeMode(intended_mode_, true); 97 ChangeMode(intended_mode_, true);
78 } 98 }
79 99
80 // static 100 // static
81 gboolean GoButtonGtk::OnExpose(GtkWidget* widget, 101 gboolean GoButtonGtk::OnExpose(GtkWidget* widget,
82 GdkEventExpose* e, 102 GdkEventExpose* e,
83 GoButtonGtk* button) { 103 GoButtonGtk* button) {
84 if (button->visible_mode_ == MODE_GO) { 104 if (button->theme_provider_->UseGtkTheme()) {
85 return button->go_.OnExpose(widget, e); 105 return FALSE;
86 } else { 106 } else {
87 return button->stop_.OnExpose(widget, e); 107 if (button->visible_mode_ == MODE_GO) {
108 return button->go_.OnExpose(widget, e);
109 } else {
110 return button->stop_.OnExpose(widget, e);
111 }
88 } 112 }
89 } 113 }
90 114
91 // static 115 // static
92 gboolean GoButtonGtk::OnEnter(GtkButton* widget, GoButtonGtk* button) { 116 gboolean GoButtonGtk::OnEnter(GtkButton* widget, GoButtonGtk* button) {
93 DCHECK_EQ(BS_NORMAL, button->state()); 117 DCHECK_EQ(BS_NORMAL, button->state());
94 button->state_ = BS_HOT; 118 button->state_ = BS_HOT;
95 return TRUE; 119 return TRUE;
96 } 120 }
97 121
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 widget_.get(), 190 widget_.get(),
167 true ? l10n_util::GetStringFUTF8( 191 true ? l10n_util::GetStringFUTF8(
168 IDS_TOOLTIP_GO_SITE, WideToUTF16(current_text)).c_str() : 192 IDS_TOOLTIP_GO_SITE, WideToUTF16(current_text)).c_str() :
169 l10n_util::GetStringFUTF8(IDS_TOOLTIP_GO_SEARCH, UTF8ToUTF16("Google"), 193 l10n_util::GetStringFUTF8(IDS_TOOLTIP_GO_SEARCH, UTF8ToUTF16("Google"),
170 WideToUTF16(current_text)).c_str()); 194 WideToUTF16(current_text)).c_str());
171 } else { 195 } else {
172 gtk_widget_set_tooltip_text( 196 gtk_widget_set_tooltip_text(
173 widget_.get(), l10n_util::GetStringUTF8(IDS_TOOLTIP_STOP).c_str()); 197 widget_.get(), l10n_util::GetStringUTF8(IDS_TOOLTIP_STOP).c_str());
174 } 198 }
175 } 199 }
200
201 void GoButtonGtk::UpdateThemeButtons() {
202 if (theme_provider_->UseGtkTheme()) {
203 // TODO(erg): Waiting for Glen to make a version of these that don't have a
204 // button border on it.
205 if (intended_mode_ == MODE_GO) {
206 gtk_button_set_image(
207 GTK_BUTTON(widget_.get()),
208 gtk_image_new_from_stock(GTK_STOCK_MEDIA_PLAY, GTK_ICON_SIZE_BUTTON));
209 } else {
210 gtk_button_set_image(
211 GTK_BUTTON(widget_.get()),
212 gtk_image_new_from_stock(GTK_STOCK_STOP, GTK_ICON_SIZE_BUTTON));
213 }
214
215 gtk_widget_set_size_request(widget_.get(), -1, -1);
216 gtk_widget_set_app_paintable(widget_.get(), FALSE);
217 gtk_widget_set_double_buffered(widget_.get(), TRUE);
218 } else {
219 gtk_widget_set_size_request(widget_.get(),
220 gdk_pixbuf_get_width(go_.pixbufs(0)),
221 gdk_pixbuf_get_height(go_.pixbufs(0)));
222
223 gtk_widget_set_app_paintable(widget_.get(), TRUE);
224 // We effectively double-buffer by virtue of having only one image...
225 gtk_widget_set_double_buffered(widget_.get(), FALSE);
226 }
227 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/go_button_gtk.h ('k') | chrome/browser/gtk/location_bar_view_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698