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