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.
5 #ifndef CHROME_BROWSER_UI_LIBGTK2UI_APP_INDICATOR_ICON_H_
6 #define CHROME_BROWSER_UI_LIBGTK2UI_APP_INDICATOR_ICON_H_
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"
14 typedef struct _AppIndicator AppIndicator
;
15 typedef struct _GtkWidget GtkWidget
;
28 class AppIndicatorIconMenu
;
30 // Status icon implementation which uses libappindicator.
31 class AppIndicatorIcon
: public views::StatusIconLinux
{
33 // The id uniquely identifies the new status icon from other chrome status
35 AppIndicatorIcon(std::string id
,
36 const gfx::ImageSkia
& image
,
37 const base::string16
& tool_tip
);
38 ~AppIndicatorIcon() override
;
40 // Indicates whether libappindicator so could be opened.
41 static bool CouldOpen();
43 // Overridden from views::StatusIconLinux:
44 void SetImage(const gfx::ImageSkia
& image
) override
;
45 void SetToolTip(const base::string16
& tool_tip
) override
;
46 void UpdatePlatformContextMenu(ui::MenuModel
* menu
) override
;
47 void RefreshPlatformContextMenu() override
;
50 struct SetImageFromFileParams
{
51 // The temporary directory in which the icon(s) were written.
52 base::FilePath parent_temp_dir
;
54 // The icon theme path to pass to libappindicator.
55 std::string icon_theme_path
;
57 // The icon name to pass to libappindicator.
58 std::string icon_name
;
61 // Writes |bitmap| to a temporary directory on a worker thread. The temporary
62 // directory is selected based on KDE's quirks.
63 static SetImageFromFileParams
WriteKDE4TempImageOnWorkerThread(
64 const SkBitmap
& bitmap
,
65 const base::FilePath
& existing_temp_dir
);
67 // Writes |bitmap| to a temporary directory on a worker thread. The temporary
68 // directory is selected based on Unity's quirks.
69 static SetImageFromFileParams
WriteUnityTempImageOnWorkerThread(
70 const SkBitmap
& bitmap
,
71 int icon_change_count
,
72 const std::string
& id
);
74 void SetImageFromFile(const SetImageFromFileParams
& params
);
77 // Sets a menu item at the top of the menu as a replacement for the status
78 // icon click action. Clicking on this menu item should simulate a status icon
79 // click by despatching a click event.
80 void UpdateClickActionReplacementMenuItem();
82 // Callback for when the status icon click replacement menu item is activated.
83 void OnClickActionReplacementMenuItemActivated();
86 std::string tool_tip_
;
88 // Whether the user is using KDE.
91 // Gtk status icon wrapper
94 scoped_ptr
<AppIndicatorIconMenu
> menu_
;
95 ui::MenuModel
* menu_model_
;
97 base::FilePath temp_dir_
;
98 int icon_change_count_
;
100 base::WeakPtrFactory
<AppIndicatorIcon
> weak_factory_
;
102 DISALLOW_COPY_AND_ASSIGN(AppIndicatorIcon
);
105 } // namespace libgtk2ui
107 #endif // CHROME_BROWSER_UI_LIBGTK2UI_APP_INDICATOR_ICON_H_