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

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

Issue 3161033: More reload button cleanup: Use widget() everywhere. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/reload_button_gtk.h" 5 #include "chrome/browser/gtk/reload_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 "chrome/app/chrome_dll_resource.h" 9 #include "chrome/app/chrome_dll_resource.h"
10 #include "chrome/browser/browser.h" 10 #include "chrome/browser/browser.h"
(...skipping 16 matching lines...) Expand all
27 browser_(browser), 27 browser_(browser),
28 button_delay_(0), 28 button_delay_(0),
29 pretend_timer_is_running_for_unittest_(false), 29 pretend_timer_is_running_for_unittest_(false),
30 intended_mode_(MODE_RELOAD), 30 intended_mode_(MODE_RELOAD),
31 visible_mode_(MODE_RELOAD), 31 visible_mode_(MODE_RELOAD),
32 theme_provider_(browser ? 32 theme_provider_(browser ?
33 GtkThemeProvider::GetFrom(browser->profile()) : NULL), 33 GtkThemeProvider::GetFrom(browser->profile()) : NULL),
34 reload_(theme_provider_, IDR_RELOAD, IDR_RELOAD_P, IDR_RELOAD_H, 0), 34 reload_(theme_provider_, IDR_RELOAD, IDR_RELOAD_P, IDR_RELOAD_H, 0),
35 stop_(theme_provider_, IDR_STOP, IDR_STOP_P, IDR_STOP_H, 0), 35 stop_(theme_provider_, IDR_STOP, IDR_STOP_P, IDR_STOP_H, 0),
36 widget_(gtk_chrome_button_new()) { 36 widget_(gtk_chrome_button_new()) {
37 gtk_widget_set_size_request(widget_.get(), reload_.Width(), reload_.Height()); 37 gtk_widget_set_size_request(widget(), reload_.Width(), reload_.Height());
38 38
39 gtk_widget_set_app_paintable(widget_.get(), TRUE); 39 gtk_widget_set_app_paintable(widget(), TRUE);
40 40
41 g_signal_connect(widget_.get(), "clicked", 41 g_signal_connect(widget(), "clicked", G_CALLBACK(OnClickedThunk), this);
42 G_CALLBACK(OnClickedThunk), this); 42 g_signal_connect(widget(), "expose-event", G_CALLBACK(OnExposeThunk), this);
43 g_signal_connect(widget_.get(), "expose-event", 43 g_signal_connect(widget(), "leave-notify-event",
44 G_CALLBACK(OnExposeThunk), this);
45 g_signal_connect(widget_.get(), "leave-notify-event",
46 G_CALLBACK(OnLeaveNotifyThunk), this); 44 G_CALLBACK(OnLeaveNotifyThunk), this);
47 GTK_WIDGET_UNSET_FLAGS(widget_.get(), GTK_CAN_FOCUS); 45 GTK_WIDGET_UNSET_FLAGS(widget(), GTK_CAN_FOCUS);
48 46
49 gtk_widget_set_has_tooltip(widget_.get(), TRUE); 47 gtk_widget_set_has_tooltip(widget(), TRUE);
50 g_signal_connect(widget_.get(), "query-tooltip", 48 g_signal_connect(widget(), "query-tooltip", G_CALLBACK(OnQueryTooltipThunk),
51 G_CALLBACK(OnQueryTooltipThunk), this); 49 this);
52 50
53 hover_controller_.Init(widget()); 51 hover_controller_.Init(widget());
54 gtk_util::SetButtonTriggersNavigation(widget()); 52 gtk_util::SetButtonTriggersNavigation(widget());
55 53
56 if (theme_provider_) { 54 if (theme_provider_) {
57 theme_provider_->InitThemesFor(this); 55 theme_provider_->InitThemesFor(this);
58 registrar_.Add(this, 56 registrar_.Add(this,
59 NotificationType::BROWSER_THEME_CHANGED, 57 NotificationType::BROWSER_THEME_CHANGED,
60 Source<GtkThemeProvider>(theme_provider_)); 58 Source<GtkThemeProvider>(theme_provider_));
61 } 59 }
62 } 60 }
63 61
64 ReloadButtonGtk::~ReloadButtonGtk() { 62 ReloadButtonGtk::~ReloadButtonGtk() {
65 widget_.Destroy(); 63 widget_.Destroy();
66 } 64 }
67 65
68 void ReloadButtonGtk::ChangeMode(Mode mode, bool force) { 66 void ReloadButtonGtk::ChangeMode(Mode mode, bool force) {
69 intended_mode_ = mode; 67 intended_mode_ = mode;
70 68
71 // If the change is forced, or the user isn't hovering the icon, or it's safe 69 // If the change is forced, or the user isn't hovering the icon, or it's safe
72 // to change it to the other image type, make the change immediately; 70 // to change it to the other image type, make the change immediately;
73 // otherwise we'll let it happen later. 71 // otherwise we'll let it happen later.
74 if (force || GTK_WIDGET_STATE(widget()) == GTK_STATE_NORMAL || 72 if (force || GTK_WIDGET_STATE(widget()) == GTK_STATE_NORMAL ||
75 ((mode == MODE_STOP) ? 73 ((mode == MODE_STOP) ?
76 !timer_running() : (visible_mode_ != MODE_STOP))) { 74 !timer_running() : (visible_mode_ != MODE_STOP))) {
77 timer_.Stop(); 75 timer_.Stop();
78 visible_mode_ = mode; 76 visible_mode_ = mode;
79 77
80 UpdateThemeButtons(); 78 UpdateThemeButtons();
81 gtk_widget_queue_draw(widget_.get()); 79 gtk_widget_queue_draw(widget());
82 } 80 }
83 } 81 }
84 82
85 void ReloadButtonGtk::Observe(NotificationType type, 83 void ReloadButtonGtk::Observe(NotificationType type,
86 const NotificationSource& source, 84 const NotificationSource& source,
87 const NotificationDetails& details) { 85 const NotificationDetails& details) {
88 DCHECK(NotificationType::BROWSER_THEME_CHANGED == type); 86 DCHECK(NotificationType::BROWSER_THEME_CHANGED == type);
89 87
90 GtkThemeProvider* provider = static_cast<GtkThemeProvider*>( 88 GtkThemeProvider* provider = static_cast<GtkThemeProvider*>(
91 Source<GtkThemeProvider>(source).ptr()); 89 Source<GtkThemeProvider>(source).ptr());
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 } 178 }
181 179
182 void ReloadButtonGtk::UpdateThemeButtons() { 180 void ReloadButtonGtk::UpdateThemeButtons() {
183 bool use_gtk = theme_provider_ && theme_provider_->UseGtkTheme(); 181 bool use_gtk = theme_provider_ && theme_provider_->UseGtkTheme();
184 182
185 if (use_gtk) { 183 if (use_gtk) {
186 GdkPixbuf* pixbuf = gtk_widget_render_icon(widget(), 184 GdkPixbuf* pixbuf = gtk_widget_render_icon(widget(),
187 (intended_mode_ == MODE_RELOAD) ? GTK_STOCK_REFRESH : GTK_STOCK_STOP, 185 (intended_mode_ == MODE_RELOAD) ? GTK_STOCK_REFRESH : GTK_STOCK_STOP,
188 GTK_ICON_SIZE_SMALL_TOOLBAR, NULL); 186 GTK_ICON_SIZE_SMALL_TOOLBAR, NULL);
189 187
190 gtk_button_set_image(GTK_BUTTON(widget_.get()), 188 gtk_button_set_image(GTK_BUTTON(widget()),
191 gtk_image_new_from_pixbuf(pixbuf)); 189 gtk_image_new_from_pixbuf(pixbuf));
192 g_object_unref(pixbuf); 190 g_object_unref(pixbuf);
193 191
194 gtk_widget_set_size_request(widget_.get(), -1, -1); 192 gtk_widget_set_size_request(widget(), -1, -1);
195 GtkRequisition req; 193 GtkRequisition req;
196 gtk_widget_size_request(widget(), &req); 194 gtk_widget_size_request(widget(), &req);
197 GtkButtonWidth = std::max(GtkButtonWidth, req.width); 195 GtkButtonWidth = std::max(GtkButtonWidth, req.width);
198 gtk_widget_set_size_request(widget_.get(), GtkButtonWidth, -1); 196 gtk_widget_set_size_request(widget(), GtkButtonWidth, -1);
199 197
200 gtk_widget_set_app_paintable(widget_.get(), FALSE); 198 gtk_widget_set_app_paintable(widget(), FALSE);
201 gtk_widget_set_double_buffered(widget_.get(), TRUE); 199 gtk_widget_set_double_buffered(widget(), TRUE);
202 } else { 200 } else {
203 gtk_button_set_image(GTK_BUTTON(widget()), NULL); 201 gtk_button_set_image(GTK_BUTTON(widget()), NULL);
204 202
205 gtk_widget_set_size_request(widget_.get(), reload_.Width(), 203 gtk_widget_set_size_request(widget(), reload_.Width(), reload_.Height());
206 reload_.Height());
207 204
208 gtk_widget_set_app_paintable(widget_.get(), TRUE); 205 gtk_widget_set_app_paintable(widget(), TRUE);
209 // We effectively double-buffer by virtue of having only one image... 206 // We effectively double-buffer by virtue of having only one image...
210 gtk_widget_set_double_buffered(widget_.get(), FALSE); 207 gtk_widget_set_double_buffered(widget(), FALSE);
211 } 208 }
212 209
213 gtk_chrome_button_set_use_gtk_rendering( 210 gtk_chrome_button_set_use_gtk_rendering(GTK_CHROME_BUTTON(widget()), use_gtk);
214 GTK_CHROME_BUTTON(widget_.get()), use_gtk);
215 } 211 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698