OLD | NEW |
| (Empty) |
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 <memory> | |
9 | |
10 #include "base/files/file_path.h" | |
11 #include "base/macros.h" | |
12 #include "base/memory/weak_ptr.h" | |
13 #include "base/nix/xdg_util.h" | |
14 #include "chrome/browser/ui/libgtk2ui/gtk2_signal.h" | |
15 #include "ui/views/linux_ui/status_icon_linux.h" | |
16 | |
17 typedef struct _AppIndicator AppIndicator; | |
18 typedef struct _GtkWidget GtkWidget; | |
19 | |
20 class SkBitmap; | |
21 | |
22 namespace gfx { | |
23 class ImageSkia; | |
24 } | |
25 | |
26 namespace ui { | |
27 class MenuModel; | |
28 } | |
29 | |
30 namespace libgtk2ui { | |
31 class AppIndicatorIconMenu; | |
32 | |
33 // Status icon implementation which uses libappindicator. | |
34 class AppIndicatorIcon : public views::StatusIconLinux { | |
35 public: | |
36 // The id uniquely identifies the new status icon from other chrome status | |
37 // icons. | |
38 AppIndicatorIcon(std::string id, | |
39 const gfx::ImageSkia& image, | |
40 const base::string16& tool_tip); | |
41 ~AppIndicatorIcon() override; | |
42 | |
43 // Indicates whether libappindicator so could be opened. | |
44 static bool CouldOpen(); | |
45 | |
46 // Overridden from views::StatusIconLinux: | |
47 void SetImage(const gfx::ImageSkia& image) override; | |
48 void SetToolTip(const base::string16& tool_tip) override; | |
49 void UpdatePlatformContextMenu(ui::MenuModel* menu) override; | |
50 void RefreshPlatformContextMenu() override; | |
51 | |
52 private: | |
53 struct SetImageFromFileParams { | |
54 // The temporary directory in which the icon(s) were written. | |
55 base::FilePath parent_temp_dir; | |
56 | |
57 // The icon theme path to pass to libappindicator. | |
58 std::string icon_theme_path; | |
59 | |
60 // The icon name to pass to libappindicator. | |
61 std::string icon_name; | |
62 }; | |
63 | |
64 // Writes |bitmap| to a temporary directory on a worker thread. The temporary | |
65 // directory is selected based on KDE's quirks. | |
66 static SetImageFromFileParams WriteKDE4TempImageOnWorkerThread( | |
67 const SkBitmap& bitmap, | |
68 const base::FilePath& existing_temp_dir); | |
69 | |
70 // Writes |bitmap| to a temporary directory on a worker thread. The temporary | |
71 // directory is selected based on Unity's quirks. | |
72 static SetImageFromFileParams WriteUnityTempImageOnWorkerThread( | |
73 const SkBitmap& bitmap, | |
74 int icon_change_count, | |
75 const std::string& id); | |
76 | |
77 void SetImageFromFile(const SetImageFromFileParams& params); | |
78 void SetMenu(); | |
79 | |
80 // Sets a menu item at the top of the menu as a replacement for the status | |
81 // icon click action. Clicking on this menu item should simulate a status icon | |
82 // click by despatching a click event. | |
83 void UpdateClickActionReplacementMenuItem(); | |
84 | |
85 // Callback for when the status icon click replacement menu item is activated. | |
86 void OnClickActionReplacementMenuItemActivated(); | |
87 | |
88 std::string id_; | |
89 std::string tool_tip_; | |
90 | |
91 // Used to select KDE or Unity for image setting. | |
92 base::nix::DesktopEnvironment desktop_env_; | |
93 | |
94 // Gtk status icon wrapper | |
95 AppIndicator* icon_; | |
96 | |
97 std::unique_ptr<AppIndicatorIconMenu> menu_; | |
98 ui::MenuModel* menu_model_; | |
99 | |
100 base::FilePath temp_dir_; | |
101 int icon_change_count_; | |
102 | |
103 base::WeakPtrFactory<AppIndicatorIcon> weak_factory_; | |
104 | |
105 DISALLOW_COPY_AND_ASSIGN(AppIndicatorIcon); | |
106 }; | |
107 | |
108 } // namespace libgtk2ui | |
109 | |
110 #endif // CHROME_BROWSER_UI_LIBGTK2UI_APP_INDICATOR_ICON_H_ | |
OLD | NEW |