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

Side by Side Diff: chrome/browser/ui/libgtk2ui/app_indicator_icon_fallback.cc

Issue 291893009: Fall back to X11 system tray icons if libappindicator is not available (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/libgtk2ui/app_indicator_icon_fallback.h"
6
7 #include <gtk/gtk.h>
8
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/ui/libgtk2ui/app_indicator_icon_menu.h"
11 #include "chrome/browser/ui/libgtk2ui/skia_utils_gtk2.h"
12 #include "ui/base/models/menu_model.h"
13 #include "ui/gfx/image/image_skia.h"
14
15 namespace libgtk2ui {
16
17 AppIndicatorIconFallback::AppIndicatorIconFallback(
18 const gfx::ImageSkia& image,
19 const base::string16& tool_tip) {
20 GdkPixbuf* pixbuf = GdkPixbufFromSkBitmap(*image.bitmap());
21 gtk_status_icon_ = gtk_status_icon_new_from_pixbuf(pixbuf);
22 g_object_unref(pixbuf);
23
24 g_signal_connect(gtk_status_icon_, "activate", G_CALLBACK(OnClickThunk),
25 this);
26 g_signal_connect(gtk_status_icon_, "popup_menu",
27 G_CALLBACK(OnContextMenuRequestedThunk), this);
28 SetToolTip(tool_tip);
29 }
30
31 AppIndicatorIconFallback::~AppIndicatorIconFallback() {
32 g_object_unref(gtk_status_icon_);
33 }
34
35 void AppIndicatorIconFallback::SetImage(const gfx::ImageSkia& image) {
36 GdkPixbuf* pixbuf = GdkPixbufFromSkBitmap(*image.bitmap());
37 gtk_status_icon_set_from_pixbuf(gtk_status_icon_, pixbuf);
38 g_object_unref(pixbuf);
39 }
40
41 void AppIndicatorIconFallback::SetPressedImage(const gfx::ImageSkia& image) {
42 // Ignore pressed images, since the standard on Linux is to not highlight
43 // pressed status icons.
44 }
45
46 void AppIndicatorIconFallback::SetToolTip(const base::string16& tool_tip) {
47 gtk_status_icon_set_tooltip_text(gtk_status_icon_,
48 base::UTF16ToUTF8(tool_tip).c_str());
49 }
50
51 void AppIndicatorIconFallback::UpdatePlatformContextMenu(ui::MenuModel* model) {
52 menu_.reset();
53 if (model)
54 menu_.reset(new AppIndicatorIconMenu(model));
55 }
56
57 void AppIndicatorIconFallback::RefreshPlatformContextMenu() {
58 if (menu_.get())
59 menu_->Refresh();
60 }
61
62 void AppIndicatorIconFallback::OnClick(
63 GtkStatusIcon* status_icon) {
64 if (delegate())
65 delegate()->OnClick();
Elliot Glaysher 2014/05/27 23:25:51 To make sure I understand this, this fires when th
pkotwicz 2014/05/27 23:50:12 Yes, that's correct
66 }
67
68 void AppIndicatorIconFallback::OnContextMenuRequested(
69 GtkStatusIcon* status_icon,
70 guint button,
71 guint32 activate_time) {
72 if (menu_.get()) {
73 gtk_menu_popup(menu_->GetGtkMenu(),
74 NULL,
75 NULL,
76 gtk_status_icon_position_menu,
77 gtk_status_icon_,
78 button,
79 activate_time);
80 }
81 }
82
83 } // namespace libgtk2ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698