OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
13 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" | 13 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" |
14 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 14 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
15 #include "chrome/browser/ui/gtk/gtk_util.h" | 15 #include "chrome/browser/ui/gtk/gtk_util.h" |
16 #include "content/public/browser/notification_source.h" | 16 #include "content/public/browser/notification_source.h" |
17 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
18 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
19 #include "third_party/skia/include/core/SkBitmap.h" | 19 #include "third_party/skia/include/core/SkBitmap.h" |
20 #include "ui/base/gtk/gtk_hig_constants.h" | 20 #include "ui/base/gtk/gtk_hig_constants.h" |
21 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
22 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
23 #include "ui/base/text/text_elider.h" | |
24 #include "ui/gfx/canvas.h" | 23 #include "ui/gfx/canvas.h" |
25 #include "ui/gfx/gtk_util.h" | 24 #include "ui/gfx/gtk_util.h" |
26 #include "ui/gfx/image/image.h" | 25 #include "ui/gfx/image/image.h" |
| 26 #include "ui/gfx/text_elider.h" |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 // A checkmark is drawn in the lower-right corner of the active avatar image. | 30 // A checkmark is drawn in the lower-right corner of the active avatar image. |
31 // This value is the x offset, in pixels, from that position. | 31 // This value is the x offset, in pixels, from that position. |
32 const int kCheckMarkXOffset = 2; | 32 const int kCheckMarkXOffset = 2; |
33 | 33 |
34 // The maximum width of a user name in pixels. Anything longer than this will be | 34 // The maximum width of a user name in pixels. Anything longer than this will be |
35 // elided. | 35 // elided. |
36 const int kUserNameMaxWidth = 200; | 36 const int kUserNameMaxWidth = 200; |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 } | 220 } |
221 | 221 |
222 GtkWidget* avatar_image = gtk_image_new_from_pixbuf(avatar_pixbuf); | 222 GtkWidget* avatar_image = gtk_image_new_from_pixbuf(avatar_pixbuf); |
223 g_object_unref(avatar_pixbuf); | 223 g_object_unref(avatar_pixbuf); |
224 gtk_misc_set_alignment(GTK_MISC(avatar_image), 0, 0); | 224 gtk_misc_set_alignment(GTK_MISC(avatar_image), 0, 0); |
225 gtk_box_pack_start(GTK_BOX(item_hbox), avatar_image, FALSE, FALSE, 0); | 225 gtk_box_pack_start(GTK_BOX(item_hbox), avatar_image, FALSE, FALSE, 0); |
226 | 226 |
227 // The user name label. | 227 // The user name label. |
228 GtkWidget* item_vbox = gtk_vbox_new(FALSE, 0); | 228 GtkWidget* item_vbox = gtk_vbox_new(FALSE, 0); |
229 GtkWidget* name_label = NULL; | 229 GtkWidget* name_label = NULL; |
230 string16 elided_name = ui::ElideText(item_.name, | 230 string16 elided_name = gfx::ElideText(item_.name, |
231 gfx::Font(), | 231 gfx::Font(), |
232 kUserNameMaxWidth, | 232 kUserNameMaxWidth, |
233 ui::ELIDE_AT_END); | 233 gfx::ELIDE_AT_END); |
234 | 234 |
235 name_label = theme_service->BuildLabel(UTF16ToUTF8(elided_name), | 235 name_label = theme_service->BuildLabel(UTF16ToUTF8(elided_name), |
236 ui::kGdkBlack); | 236 ui::kGdkBlack); |
237 if (item_.active) { | 237 if (item_.active) { |
238 char* markup = g_markup_printf_escaped( | 238 char* markup = g_markup_printf_escaped( |
239 "<span weight='bold'>%s</span>", UTF16ToUTF8(elided_name).c_str()); | 239 "<span weight='bold'>%s</span>", UTF16ToUTF8(elided_name).c_str()); |
240 gtk_label_set_markup(GTK_LABEL(name_label), markup); | 240 gtk_label_set_markup(GTK_LABEL(name_label), markup); |
241 g_free(markup); | 241 g_free(markup); |
242 } | 242 } |
243 | 243 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 | 280 |
281 GtkSizeGroup* size_group = gtk_size_group_new(GTK_SIZE_GROUP_BOTH); | 281 GtkSizeGroup* size_group = gtk_size_group_new(GTK_SIZE_GROUP_BOTH); |
282 gtk_size_group_add_widget(size_group, status_label_); | 282 gtk_size_group_add_widget(size_group, status_label_); |
283 gtk_size_group_add_widget(size_group, link_alignment_); | 283 gtk_size_group_add_widget(size_group, link_alignment_); |
284 g_object_unref(size_group); | 284 g_object_unref(size_group); |
285 } | 285 } |
286 | 286 |
287 gtk_box_pack_start(GTK_BOX(item_hbox), item_vbox, TRUE, TRUE, 0); | 287 gtk_box_pack_start(GTK_BOX(item_hbox), item_vbox, TRUE, TRUE, 0); |
288 gtk_container_add(GTK_CONTAINER(widget_.get()), item_hbox); | 288 gtk_container_add(GTK_CONTAINER(widget_.get()), item_hbox); |
289 } | 289 } |
OLD | NEW |