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