Home | History | Annotate | Download | only in libgtk2ui
      1 // Copyright 2013 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 #ifndef CHROME_BROWSER_UI_LIBGTK2UI_APP_INDICATOR_ICON_H_
      6 #define CHROME_BROWSER_UI_LIBGTK2UI_APP_INDICATOR_ICON_H_
      7 
      8 #include "base/files/file_path.h"
      9 #include "base/memory/scoped_ptr.h"
     10 #include "base/memory/weak_ptr.h"
     11 #include "chrome/browser/ui/libgtk2ui/gtk2_signal.h"
     12 #include "ui/views/linux_ui/status_icon_linux.h"
     13 
     14 typedef struct _AppIndicator AppIndicator;
     15 typedef struct _GtkWidget GtkWidget;
     16 
     17 namespace gfx {
     18 class ImageSkia;
     19 }
     20 
     21 namespace ui {
     22 class MenuModel;
     23 }
     24 
     25 namespace libgtk2ui {
     26 class AppIndicatorIconMenu;
     27 
     28 // Status icon implementation which uses libappindicator.
     29 class AppIndicatorIcon : public views::StatusIconLinux {
     30  public:
     31   // The id uniquely identifies the new status icon from other chrome status
     32   // icons.
     33   AppIndicatorIcon(std::string id,
     34                    const gfx::ImageSkia& image,
     35                    const base::string16& tool_tip);
     36   virtual ~AppIndicatorIcon();
     37 
     38   // Indicates whether libappindicator so could be opened.
     39   static bool CouldOpen();
     40 
     41   // Overridden from views::StatusIconLinux:
     42   virtual void SetImage(const gfx::ImageSkia& image) OVERRIDE;
     43   virtual void SetPressedImage(const gfx::ImageSkia& image) OVERRIDE;
     44   virtual void SetToolTip(const base::string16& tool_tip) OVERRIDE;
     45   virtual void UpdatePlatformContextMenu(ui::MenuModel* menu) OVERRIDE;
     46   virtual void RefreshPlatformContextMenu() OVERRIDE;
     47 
     48  private:
     49   void SetImageFromFile(const base::FilePath& icon_file_path);
     50   void SetMenu();
     51 
     52   // Sets a menu item at the top of the menu as a replacement for the status
     53   // icon click action. Clicking on this menu item should simulate a status icon
     54   // click by despatching a click event.
     55   void UpdateClickActionReplacementMenuItem();
     56 
     57   // Callback for when the status icon click replacement menu item is activated.
     58   void OnClickActionReplacementMenuItemActivated();
     59 
     60   std::string id_;
     61   std::string tool_tip_;
     62 
     63   // Whether the user is using KDE.
     64   bool using_kde4_;
     65 
     66   // Gtk status icon wrapper
     67   AppIndicator* icon_;
     68 
     69   scoped_ptr<AppIndicatorIconMenu> menu_;
     70   ui::MenuModel* menu_model_;
     71 
     72   base::FilePath icon_file_path_;
     73   int icon_change_count_;
     74 
     75   base::WeakPtrFactory<AppIndicatorIcon> weak_factory_;
     76 
     77   DISALLOW_COPY_AND_ASSIGN(AppIndicatorIcon);
     78 };
     79 
     80 }  // namespace libgtk2ui
     81 
     82 #endif  // CHROME_BROWSER_UI_LIBGTK2UI_APP_INDICATOR_ICON_H_
     83