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

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

Issue 3135034: Cleanup: Put signal handlers in alphabetical order. Group a couple other thi... (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 | « chrome/browser/gtk/reload_button_gtk.h ('k') | 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 20 matching lines...) Expand all
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_.get(), reload_.Width(), reload_.Height());
38 38
39 gtk_widget_set_app_paintable(widget_.get(), TRUE); 39 gtk_widget_set_app_paintable(widget_.get(), TRUE);
40 40
41 g_signal_connect(widget_.get(), "clicked",
42 G_CALLBACK(OnClickedThunk), this);
41 g_signal_connect(widget_.get(), "expose-event", 43 g_signal_connect(widget_.get(), "expose-event",
42 G_CALLBACK(OnExposeThunk), this); 44 G_CALLBACK(OnExposeThunk), this);
43 g_signal_connect(widget_.get(), "leave-notify-event", 45 g_signal_connect(widget_.get(), "leave-notify-event",
44 G_CALLBACK(OnLeaveNotifyThunk), this); 46 G_CALLBACK(OnLeaveNotifyThunk), this);
45 g_signal_connect(widget_.get(), "clicked",
46 G_CALLBACK(OnClickedThunk), this);
47 GTK_WIDGET_UNSET_FLAGS(widget_.get(), GTK_CAN_FOCUS); 47 GTK_WIDGET_UNSET_FLAGS(widget_.get(), GTK_CAN_FOCUS);
48 48
49 gtk_widget_set_has_tooltip(widget_.get(), TRUE); 49 gtk_widget_set_has_tooltip(widget_.get(), TRUE);
50 g_signal_connect(widget_.get(), "query-tooltip", 50 g_signal_connect(widget_.get(), "query-tooltip",
51 G_CALLBACK(OnQueryTooltipThunk), this); 51 G_CALLBACK(OnQueryTooltipThunk), this);
52 52
53 hover_controller_.Init(widget()); 53 hover_controller_.Init(widget());
54 gtk_util::SetButtonTriggersNavigation(widget()); 54 gtk_util::SetButtonTriggersNavigation(widget());
55 55
56 if (theme_provider_) { 56 if (theme_provider_) {
(...skipping 12 matching lines...) Expand all
69 intended_mode_ = mode; 69 intended_mode_ = mode;
70 70
71 // If the change is forced, or the user isn't hovering the icon, or it's safe 71 // 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; 72 // to change it to the other image type, make the change immediately;
73 // otherwise we'll let it happen later. 73 // otherwise we'll let it happen later.
74 if (force || GTK_WIDGET_STATE(widget()) == GTK_STATE_NORMAL || 74 if (force || GTK_WIDGET_STATE(widget()) == GTK_STATE_NORMAL ||
75 ((mode == MODE_STOP) ? 75 ((mode == MODE_STOP) ?
76 !timer_running() : (visible_mode_ != MODE_STOP))) { 76 !timer_running() : (visible_mode_ != MODE_STOP))) {
77 timer_.Stop(); 77 timer_.Stop();
78 visible_mode_ = mode; 78 visible_mode_ = mode;
79 gtk_widget_queue_draw(widget_.get());
80 79
81 UpdateThemeButtons(); 80 UpdateThemeButtons();
81 gtk_widget_queue_draw(widget_.get());
82 } 82 }
83 } 83 }
84 84
85 void ReloadButtonGtk::Observe(NotificationType type, 85 void ReloadButtonGtk::Observe(NotificationType type,
86 const NotificationSource& source, 86 const NotificationSource& source,
87 const NotificationDetails& details) { 87 const NotificationDetails& details) {
88 DCHECK(NotificationType::BROWSER_THEME_CHANGED == type); 88 DCHECK(NotificationType::BROWSER_THEME_CHANGED == type);
89 89
90 GtkThemeProvider* provider = static_cast<GtkThemeProvider*>( 90 GtkThemeProvider* provider = static_cast<GtkThemeProvider*>(
91 Source<GtkThemeProvider>(source).ptr()); 91 Source<GtkThemeProvider>(source).ptr());
92 DCHECK_EQ(provider, theme_provider_); 92 DCHECK_EQ(provider, theme_provider_);
93 GtkButtonWidth = 0; 93 GtkButtonWidth = 0;
94 UpdateThemeButtons(); 94 UpdateThemeButtons();
95 } 95 }
96 96
97 void ReloadButtonGtk::OnButtonTimer() { 97 void ReloadButtonGtk::OnButtonTimer() {
98 ChangeMode(intended_mode_, true); 98 ChangeMode(intended_mode_, true);
99 } 99 }
100 100
101 gboolean ReloadButtonGtk::OnExpose(GtkWidget* widget,
102 GdkEventExpose* e) {
103 if (theme_provider_ && theme_provider_->UseGtkTheme())
104 return FALSE;
105 return ((visible_mode_ == MODE_RELOAD) ? reload_ : stop_).OnExpose(
106 widget, e, hover_controller_.GetCurrentValue());
107 }
108
109 gboolean ReloadButtonGtk::OnLeaveNotify(GtkWidget* widget,
110 GdkEventCrossing* event) {
111 ChangeMode(intended_mode_, true);
112 return FALSE;
113 }
114
115 void ReloadButtonGtk::OnClicked(GtkWidget* sender) { 101 void ReloadButtonGtk::OnClicked(GtkWidget* sender) {
116 if (visible_mode_ == MODE_STOP) { 102 if (visible_mode_ == MODE_STOP) {
117 if (browser_) 103 if (browser_)
118 browser_->Stop(); 104 browser_->Stop();
119 105
120 // The user has clicked, so we can feel free to update the button, 106 // The user has clicked, so we can feel free to update the button,
121 // even if the mouse is still hovering. 107 // even if the mouse is still hovering.
122 ChangeMode(MODE_RELOAD, true); 108 ChangeMode(MODE_RELOAD, true);
123 } else if (!timer_running()) { 109 } else if (!timer_running()) {
124 // Shift-clicking or Ctrl-clicking the reload button means we should ignore 110 // Shift-clicking or Ctrl-clicking the reload button means we should ignore
(...skipping 22 matching lines...) Expand all
147 if (browser_) 133 if (browser_)
148 browser_->ExecuteCommandWithDisposition(command, disposition); 134 browser_->ExecuteCommandWithDisposition(command, disposition);
149 135
150 // Figure out the system double-click time. 136 // Figure out the system double-click time.
151 if (button_delay_ == 0) { 137 if (button_delay_ == 0) {
152 GtkSettings* settings = gtk_settings_get_default(); 138 GtkSettings* settings = gtk_settings_get_default();
153 g_object_get(G_OBJECT(settings), "gtk-double-click-time", &button_delay_, 139 g_object_get(G_OBJECT(settings), "gtk-double-click-time", &button_delay_,
154 NULL); 140 NULL);
155 } 141 }
156 142
157 // Stop the timer.
158 timer_.Stop();
159
160 // Start a timer - while this timer is running, the reload button cannot be 143 // Start a timer - while this timer is running, the reload button cannot be
161 // changed to a stop button. We do not set |intended_mode_| to MODE_STOP 144 // changed to a stop button. We do not set |intended_mode_| to MODE_STOP
162 // here as we want to wait for the browser to tell us that it has started 145 // here as we want to wait for the browser to tell us that it has started
163 // loading (and this may occur only after some delay). 146 // loading (and this may occur only after some delay).
147 timer_.Stop();
164 timer_.Start(base::TimeDelta::FromMilliseconds(button_delay_), this, 148 timer_.Start(base::TimeDelta::FromMilliseconds(button_delay_), this,
165 &ReloadButtonGtk::OnButtonTimer); 149 &ReloadButtonGtk::OnButtonTimer);
166 } 150 }
167 } 151 }
168 152
153 gboolean ReloadButtonGtk::OnExpose(GtkWidget* widget,
154 GdkEventExpose* e) {
155 if (theme_provider_ && theme_provider_->UseGtkTheme())
156 return FALSE;
157 return ((visible_mode_ == MODE_RELOAD) ? reload_ : stop_).OnExpose(
158 widget, e, hover_controller_.GetCurrentValue());
159 }
160
161 gboolean ReloadButtonGtk::OnLeaveNotify(GtkWidget* widget,
162 GdkEventCrossing* event) {
163 is_mouse_hovered_ = false;
164 ChangeMode(intended_mode_, false);
165 return FALSE;
166 }
167
169 gboolean ReloadButtonGtk::OnQueryTooltip(GtkWidget* sender, 168 gboolean ReloadButtonGtk::OnQueryTooltip(GtkWidget* sender,
170 gint x, 169 gint x,
171 gint y, 170 gint y,
172 gboolean keyboard_mode, 171 gboolean keyboard_mode,
173 GtkTooltip* tooltip) { 172 GtkTooltip* tooltip) {
174 // |location_bar_| can be NULL in tests. 173 // |location_bar_| can be NULL in tests.
175 if (!location_bar_) 174 if (!location_bar_)
176 return FALSE; 175 return FALSE;
177 176
178 gtk_tooltip_set_text(tooltip, l10n_util::GetStringUTF8( 177 gtk_tooltip_set_text(tooltip, l10n_util::GetStringUTF8(
(...skipping 29 matching lines...) Expand all
208 reload_.Height()); 207 reload_.Height());
209 208
210 gtk_widget_set_app_paintable(widget_.get(), TRUE); 209 gtk_widget_set_app_paintable(widget_.get(), TRUE);
211 // We effectively double-buffer by virtue of having only one image... 210 // We effectively double-buffer by virtue of having only one image...
212 gtk_widget_set_double_buffered(widget_.get(), FALSE); 211 gtk_widget_set_double_buffered(widget_.get(), FALSE);
213 } 212 }
214 213
215 gtk_chrome_button_set_use_gtk_rendering( 214 gtk_chrome_button_set_use_gtk_rendering(
216 GTK_CHROME_BUTTON(widget_.get()), use_gtk); 215 GTK_CHROME_BUTTON(widget_.get()), use_gtk);
217 } 216 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/reload_button_gtk.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698