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 "chrome/browser/ui/libgtk2ui/gtk2_signal.h" 11 #include "ui/linux_ui/status_icon_linux.h" 12 13 typedef struct _AppIndicator AppIndicator; 14 typedef struct _GtkWidget GtkWidget; 15 16 namespace gfx { 17 class ImageSkia; 18 } 19 20 namespace libgtk2ui { 21 22 class AppIndicatorIcon : public StatusIconLinux { 23 public: 24 // The id uniquely identifies the new status icon from other chrome status 25 // icons. 26 explicit AppIndicatorIcon(std::string id, 27 const gfx::ImageSkia& image, 28 const string16& tool_tip); 29 virtual ~AppIndicatorIcon(); 30 31 // Indicates whether libappindicator so could be opened. 32 static bool CouldOpen(); 33 34 // Overridden from StatusIcon: 35 virtual void SetImage(const gfx::ImageSkia& image) OVERRIDE; 36 virtual void SetPressedImage(const gfx::ImageSkia& image) OVERRIDE; 37 virtual void SetToolTip(const string16& tool_tip) OVERRIDE; 38 39 protected: 40 // Overridden from StatusIcon. 41 virtual void UpdatePlatformContextMenu(ui::MenuModel* menu) OVERRIDE; 42 43 private: 44 void SetImageFromFile(base::FilePath icon_file_path); 45 void SetMenu(); 46 47 // Adds a menu item to the top of the existing gtk_menu as a replacement for 48 // the status icon click action or creates a new gtk menu with the menu item 49 // if a menu doesn't exist. Clicking on this menu item should simulate a 50 // status icon click by despatching a click event. 51 void CreateClickActionReplacement(); 52 void DestroyMenu(); 53 54 static base::FilePath CreateTempImageFile(gfx::ImageSkia* image, 55 int icon_change_count, 56 std::string id); 57 static void DeletePath(base::FilePath icon_file_path); 58 59 // Updates all the enabled/checked states and the dynamic labels. 60 void UpdateMenu(); 61 62 // Callback for when the status icon click replacement menu item is clicked. 63 CHROMEGTK_CALLBACK_0(AppIndicatorIcon, void, OnClick); 64 65 // Callback for when a menu item is clicked. 66 CHROMEGTK_CALLBACK_0(AppIndicatorIcon, void, OnMenuItemActivated); 67 68 std::string id_; 69 std::string tool_tip_; 70 71 // Gtk status icon wrapper 72 AppIndicator* icon_; 73 74 GtkWidget* gtk_menu_; 75 ui::MenuModel* menu_model_; 76 77 base::FilePath icon_file_path_; 78 int icon_change_count_; 79 bool block_activation_; 80 }; 81 82 } // namespace libgtk2ui 83 84 #endif // CHROME_BROWSER_UI_LIBGTK2UI_APP_INDICATOR_ICON_H_ 85