| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/gtk/status_icons/status_icon_gtk.h" | |
| 6 | |
| 7 #include "base/strings/string16.h" | |
| 8 #include "base/strings/utf_string_conversions.h" | |
| 9 #include "chrome/browser/ui/gtk/menu_gtk.h" | |
| 10 #include "third_party/skia/include/core/SkBitmap.h" | |
| 11 #include "ui/gfx/gtk_util.h" | |
| 12 #include "ui/gfx/image/image_skia.h" | |
| 13 | |
| 14 StatusIconGtk::StatusIconGtk() { | |
| 15 icon_ = gtk_status_icon_new(); | |
| 16 gtk_status_icon_set_visible(icon_, TRUE); | |
| 17 | |
| 18 g_signal_connect(icon_, "activate", | |
| 19 G_CALLBACK(OnClickThunk), this); | |
| 20 g_signal_connect(icon_, "popup-menu", | |
| 21 G_CALLBACK(OnPopupMenuThunk), this); | |
| 22 } | |
| 23 | |
| 24 StatusIconGtk::~StatusIconGtk() { | |
| 25 gtk_status_icon_set_visible(icon_, FALSE); | |
| 26 g_object_unref(icon_); | |
| 27 } | |
| 28 | |
| 29 void StatusIconGtk::SetImage(const gfx::ImageSkia& image) { | |
| 30 if (image.isNull()) | |
| 31 return; | |
| 32 | |
| 33 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(*image.bitmap()); | |
| 34 gtk_status_icon_set_from_pixbuf(icon_, pixbuf); | |
| 35 g_object_unref(pixbuf); | |
| 36 } | |
| 37 | |
| 38 void StatusIconGtk::SetPressedImage(const gfx::ImageSkia& image) { | |
| 39 // Ignore pressed images, since the standard on Linux is to not highlight | |
| 40 // pressed status icons. | |
| 41 } | |
| 42 | |
| 43 void StatusIconGtk::SetToolTip(const base::string16& tool_tip) { | |
| 44 gtk_status_icon_set_tooltip_text(icon_, base::UTF16ToUTF8(tool_tip).c_str()); | |
| 45 } | |
| 46 | |
| 47 void StatusIconGtk::DisplayBalloon(const gfx::ImageSkia& icon, | |
| 48 const base::string16& title, | |
| 49 const base::string16& contents) { | |
| 50 notification_.DisplayBalloon(icon, title, contents); | |
| 51 } | |
| 52 | |
| 53 void StatusIconGtk::OnClick(GtkWidget* widget) { | |
| 54 DispatchClickEvent(); | |
| 55 } | |
| 56 | |
| 57 void StatusIconGtk::UpdatePlatformContextMenu(StatusIconMenuModel* model) { | |
| 58 if (!model) | |
| 59 menu_.reset(); | |
| 60 else | |
| 61 menu_.reset(new MenuGtk(NULL, model)); | |
| 62 } | |
| 63 | |
| 64 void StatusIconGtk::OnPopupMenu(GtkWidget* widget, guint button, guint time) { | |
| 65 // If we have a menu - display it. | |
| 66 if (menu_.get()) | |
| 67 menu_->PopupAsContextForStatusIcon(time, button, icon_); | |
| 68 } | |
| OLD | NEW |