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

Side by Side Diff: chrome/browser/ui/gtk/avatar_menu_item_gtk.cc

Issue 8921003: Linux/Gtk: Drawing a focus-ring around the avatar menu items to highlight selection. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 9 years 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/ui/gtk/avatar_menu_item_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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/ui/gtk/avatar_menu_item_gtk.h" 5 #include "chrome/browser/ui/gtk/avatar_menu_item_gtk.h"
6 6
7 #include <gdk/gdkkeysyms.h> 7 #include <gdk/gdkkeysyms.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 gtk_widget_hide(link_alignment_); 113 gtk_widget_hide(link_alignment_);
114 } 114 }
115 115
116 void AvatarMenuItemGtk::ShowEditLink() { 116 void AvatarMenuItemGtk::ShowEditLink() {
117 gtk_widget_hide(status_label_); 117 gtk_widget_hide(status_label_);
118 gtk_widget_show(link_alignment_); 118 gtk_widget_show(link_alignment_);
119 } 119 }
120 120
121 gboolean AvatarMenuItemGtk::OnProfileFocusIn(GtkWidget* widget, 121 gboolean AvatarMenuItemGtk::OnProfileFocusIn(GtkWidget* widget,
122 GdkEventFocus* event) { 122 GdkEventFocus* event) {
123 gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, &highlighted_color_);
124 if (item_.active) 123 if (item_.active)
125 ShowEditLink(); 124 ShowEditLink();
126 125
127 return FALSE; 126 return FALSE;
128 } 127 }
129 128
130 gboolean AvatarMenuItemGtk::OnProfileFocusOut(GtkWidget* widget, 129 gboolean AvatarMenuItemGtk::OnProfileFocusOut(GtkWidget* widget,
131 GdkEventFocus* event) { 130 GdkEventFocus* event) {
132 gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, unhighlighted_color_);
133 if (item_.active) 131 if (item_.active)
134 ShowStatusLabel(); 132 ShowStatusLabel();
135 133
136 return FALSE; 134 return FALSE;
137 } 135 }
138 136
139 gboolean AvatarMenuItemGtk::OnProfileEnter(GtkWidget* widget, 137 gboolean AvatarMenuItemGtk::OnProfileEnter(GtkWidget* widget,
140 GdkEventCrossing* event) { 138 GdkEventCrossing* event) {
141 if (event->detail == GDK_NOTIFY_INFERIOR) 139 if (event->detail == GDK_NOTIFY_INFERIOR)
142 return FALSE; 140 return FALSE;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 // delegate_->EditProfile() will close the avatar bubble which in turn 192 // delegate_->EditProfile() will close the avatar bubble which in turn
195 // try to destroy this AvatarMenuItemGtk. 193 // try to destroy this AvatarMenuItemGtk.
196 // This is not OK to do this from the signal handler, so we'll 194 // This is not OK to do this from the signal handler, so we'll
197 // defer it. 195 // defer it.
198 MessageLoop::current()->PostTask( 196 MessageLoop::current()->PostTask(
199 FROM_HERE, 197 FROM_HERE,
200 base::Bind(&AvatarMenuItemGtk::EditProfile, 198 base::Bind(&AvatarMenuItemGtk::EditProfile,
201 weak_factory_.GetWeakPtr())); 199 weak_factory_.GetWeakPtr()));
202 } 200 }
203 201
202 gboolean AvatarMenuItemGtk::OnEventBoxExpose(GtkWidget* widget,
203 GdkEventExpose* event) {
204 // Draw the focus rectangle.
205 if (gtk_widget_has_focus(widget)) {
206 GtkAllocation allocation;
207 gtk_widget_get_allocation(widget, &allocation);
Elliot Glaysher 2011/12/12 20:48:24 Thank you for getting this right. (Sadly, there's
208 gtk_paint_focus(widget->style, widget->window,
209 gtk_widget_get_state(widget),
210 &event->area, widget, NULL,
211 0, 0,
212 allocation.width, allocation.height);
213 }
214
215 return TRUE;
216 }
217
204 void AvatarMenuItemGtk::Init(GtkThemeService* theme_service) { 218 void AvatarMenuItemGtk::Init(GtkThemeService* theme_service) {
205 widget_.Own(gtk_event_box_new()); 219 widget_.Own(gtk_event_box_new());
206 220
207 g_signal_connect(widget_.get(), "button-press-event", 221 g_signal_connect(widget_.get(), "button-press-event",
208 G_CALLBACK(OnProfileClickThunk), this); 222 G_CALLBACK(OnProfileClickThunk), this);
209 g_signal_connect(widget_.get(), "enter-notify-event", 223 g_signal_connect(widget_.get(), "enter-notify-event",
210 G_CALLBACK(OnProfileEnterThunk), this); 224 G_CALLBACK(OnProfileEnterThunk), this);
211 g_signal_connect(widget_.get(), "leave-notify-event", 225 g_signal_connect(widget_.get(), "leave-notify-event",
212 G_CALLBACK(OnProfileLeaveThunk), this); 226 G_CALLBACK(OnProfileLeaveThunk), this);
213 g_signal_connect(widget_.get(), "focus-in-event", 227 g_signal_connect(widget_.get(), "focus-in-event",
214 G_CALLBACK(OnProfileFocusInThunk), this); 228 G_CALLBACK(OnProfileFocusInThunk), this);
215 g_signal_connect(widget_.get(), "focus-out-event", 229 g_signal_connect(widget_.get(), "focus-out-event",
216 G_CALLBACK(OnProfileFocusOutThunk), this); 230 G_CALLBACK(OnProfileFocusOutThunk), this);
217 g_signal_connect(widget_.get(), "key-press-event", 231 g_signal_connect(widget_.get(), "key-press-event",
218 G_CALLBACK(OnProfileKeyPressThunk), this); 232 G_CALLBACK(OnProfileKeyPressThunk), this);
233 g_signal_connect_after(widget_.get(), "expose-event",
234 G_CALLBACK(OnEventBoxExposeThunk), this);
219 235
220 GtkWidget* item_hbox = gtk_hbox_new(FALSE, ui::kControlSpacing); 236 GtkWidget* item_hbox = gtk_hbox_new(FALSE, ui::kControlSpacing);
221 GdkPixbuf* avatar_pixbuf = NULL; 237 GdkPixbuf* avatar_pixbuf = NULL;
222 238
223 // If this profile is active then draw a check mark on the bottom right 239 // If this profile is active then draw a check mark on the bottom right
224 // of the profile icon. 240 // of the profile icon.
225 if (item_.active) { 241 if (item_.active) {
226 const SkBitmap* avatar_image = item_.icon.ToSkBitmap(); 242 const SkBitmap* avatar_image = item_.icon.ToSkBitmap();
227 gfx::CanvasSkia canvas(avatar_image->width(), 243 gfx::CanvasSkia canvas(avatar_image->width(),
228 avatar_image->height(), 244 avatar_image->height(),
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 311
296 GtkSizeGroup* size_group = gtk_size_group_new(GTK_SIZE_GROUP_BOTH); 312 GtkSizeGroup* size_group = gtk_size_group_new(GTK_SIZE_GROUP_BOTH);
297 gtk_size_group_add_widget(size_group, status_label_); 313 gtk_size_group_add_widget(size_group, status_label_);
298 gtk_size_group_add_widget(size_group, link_alignment_); 314 gtk_size_group_add_widget(size_group, link_alignment_);
299 g_object_unref(size_group); 315 g_object_unref(size_group);
300 } 316 }
301 317
302 gtk_box_pack_start(GTK_BOX(item_hbox), item_vbox, TRUE, TRUE, 0); 318 gtk_box_pack_start(GTK_BOX(item_hbox), item_vbox, TRUE, TRUE, 0);
303 gtk_container_add(GTK_CONTAINER(widget_.get()), item_hbox); 319 gtk_container_add(GTK_CONTAINER(widget_.get()), item_hbox);
304 } 320 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/avatar_menu_item_gtk.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698