Home | History | Annotate | Download | only in status_icons
      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
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/ui/gtk/status_icons/status_icon_gtk.h"
      6 
      7 #include "base/string16.h"
      8 #include "base/logging.h"
      9 #include "base/utf_string_conversions.h"
     10 #include "chrome/browser/ui/gtk/menu_gtk.h"
     11 #include "third_party/skia/include/core/SkBitmap.h"
     12 #include "ui/gfx/gtk_util.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   g_object_unref(icon_);
     26 }
     27 
     28 void StatusIconGtk::SetImage(const SkBitmap& image) {
     29   if (image.isNull())
     30     return;
     31 
     32   GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&image);
     33   gtk_status_icon_set_from_pixbuf(icon_, pixbuf);
     34   g_object_unref(pixbuf);
     35 }
     36 
     37 void StatusIconGtk::SetPressedImage(const SkBitmap& image) {
     38   // Ignore pressed images, since the standard on Linux is to not highlight
     39   // pressed status icons.
     40 }
     41 
     42 void StatusIconGtk::SetToolTip(const string16& tool_tip) {
     43   gtk_status_icon_set_tooltip(icon_, UTF16ToUTF8(tool_tip).c_str());
     44 }
     45 
     46 void StatusIconGtk::DisplayBalloon(const string16& title,
     47                                    const string16& contents) {
     48   // TODO(atwilson): Figure out the right thing to do here.
     49   // http://crbug.com/74970
     50 }
     51 
     52 void StatusIconGtk::OnClick(GtkWidget* widget) {
     53   DispatchClickEvent();
     54 }
     55 
     56 void StatusIconGtk::UpdatePlatformContextMenu(ui::MenuModel* model) {
     57   if (!model)
     58     menu_.reset();
     59   else
     60     menu_.reset(new MenuGtk(NULL, model));
     61 }
     62 
     63 void StatusIconGtk::OnPopupMenu(GtkWidget* widget, guint button, guint time) {
     64   // If we have a menu - display it.
     65   if (menu_.get())
     66     menu_->PopupAsContextForStatusIcon(time, button, icon_);
     67 }
     68