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