Add ability to gather metrics to BubbleManager.
[chromium-blink-merge.git] / chrome / browser / ui / libgtk2ui / gtk2_status_icon.cc
blobbe66aa6a7aa51a69066aec5e873cba5d3d73efe0
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.
5 #include "chrome/browser/ui/libgtk2ui/gtk2_status_icon.h"
7 #include <gtk/gtk.h>
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"
15 namespace libgtk2ui {
17 Gtk2StatusIcon::Gtk2StatusIcon(const gfx::ImageSkia& image,
18 const base::string16& tool_tip) {
19 GdkPixbuf* pixbuf = GdkPixbufFromSkBitmap(*image.bitmap());
20 gtk_status_icon_ = gtk_status_icon_new_from_pixbuf(pixbuf);
21 g_object_unref(pixbuf);
23 g_signal_connect(gtk_status_icon_, "activate", G_CALLBACK(OnClickThunk),
24 this);
25 g_signal_connect(gtk_status_icon_, "popup_menu",
26 G_CALLBACK(OnContextMenuRequestedThunk), this);
27 SetToolTip(tool_tip);
30 Gtk2StatusIcon::~Gtk2StatusIcon() {
31 gtk_status_icon_set_visible(gtk_status_icon_, FALSE);
32 g_object_unref(gtk_status_icon_);
35 void Gtk2StatusIcon::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);
41 void Gtk2StatusIcon::SetToolTip(const base::string16& tool_tip) {
42 gtk_status_icon_set_tooltip_text(gtk_status_icon_,
43 base::UTF16ToUTF8(tool_tip).c_str());
46 void Gtk2StatusIcon::UpdatePlatformContextMenu(ui::MenuModel* model) {
47 menu_.reset();
48 if (model)
49 menu_.reset(new AppIndicatorIconMenu(model));
52 void Gtk2StatusIcon::RefreshPlatformContextMenu() {
53 if (menu_.get())
54 menu_->Refresh();
57 void Gtk2StatusIcon::OnClick(GtkStatusIcon* status_icon) {
58 if (delegate())
59 delegate()->OnClick();
62 void Gtk2StatusIcon::OnContextMenuRequested(GtkStatusIcon* status_icon,
63 guint button,
64 guint32 activate_time) {
65 if (menu_.get()) {
66 gtk_menu_popup(menu_->GetGtkMenu(),
67 NULL,
68 NULL,
69 gtk_status_icon_position_menu,
70 gtk_status_icon_,
71 button,
72 activate_time);
76 } // namespace libgtk2ui