File: app_indicator_icon.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (110 lines) | stat: -rw-r--r-- 3,351 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_LIBGTKUI_APP_INDICATOR_ICON_H_
#define CHROME_BROWSER_UI_LIBGTKUI_APP_INDICATOR_ICON_H_

#include <memory>

#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/nix/xdg_util.h"
#include "chrome/browser/ui/libgtkui/gtk_signal.h"
#include "ui/views/linux_ui/status_icon_linux.h"

typedef struct _AppIndicator AppIndicator;
typedef struct _GtkWidget GtkWidget;

class SkBitmap;

namespace gfx {
class ImageSkia;
}

namespace ui {
class MenuModel;
}

namespace libgtkui {
class AppIndicatorIconMenu;

// Status icon implementation which uses libappindicator.
class AppIndicatorIcon : public views::StatusIconLinux {
 public:
  // The id uniquely identifies the new status icon from other chrome status
  // icons.
  AppIndicatorIcon(std::string id,
                   const gfx::ImageSkia& image,
                   const base::string16& tool_tip);
  ~AppIndicatorIcon() override;

  // Indicates whether libappindicator so could be opened.
  static bool CouldOpen();

  // Overridden from views::StatusIconLinux:
  void SetImage(const gfx::ImageSkia& image) override;
  void SetToolTip(const base::string16& tool_tip) override;
  void UpdatePlatformContextMenu(ui::MenuModel* menu) override;
  void RefreshPlatformContextMenu() override;

 private:
  struct SetImageFromFileParams {
    // The temporary directory in which the icon(s) were written.
    base::FilePath parent_temp_dir;

    // The icon theme path to pass to libappindicator.
    std::string icon_theme_path;

    // The icon name to pass to libappindicator.
    std::string icon_name;
  };

  // Writes |bitmap| to a temporary directory on a worker thread. The temporary
  // directory is selected based on KDE's quirks.
  static SetImageFromFileParams WriteKDE4TempImageOnWorkerThread(
      const SkBitmap& bitmap,
      const base::FilePath& existing_temp_dir);

  // Writes |bitmap| to a temporary directory on a worker thread. The temporary
  // directory is selected based on Unity's quirks.
  static SetImageFromFileParams WriteUnityTempImageOnWorkerThread(
      const SkBitmap& bitmap,
      int icon_change_count,
      const std::string& id);

  void SetImageFromFile(const SetImageFromFileParams& params);
  void SetMenu();

  // Sets a menu item at the top of the menu as a replacement for the status
  // icon click action. Clicking on this menu item should simulate a status icon
  // click by despatching a click event.
  void UpdateClickActionReplacementMenuItem();

  // Callback for when the status icon click replacement menu item is activated.
  void OnClickActionReplacementMenuItemActivated();

  std::string id_;
  std::string tool_tip_;

  // Used to select KDE or Unity for image setting.
  base::nix::DesktopEnvironment desktop_env_;

  // Gtk status icon wrapper
  AppIndicator* icon_;

  std::unique_ptr<AppIndicatorIconMenu> menu_;
  ui::MenuModel* menu_model_;

  base::FilePath temp_dir_;
  int icon_change_count_;

  base::WeakPtrFactory<AppIndicatorIcon> weak_factory_;

  DISALLOW_COPY_AND_ASSIGN(AppIndicatorIcon);
};

}  // namespace libgtkui

#endif  // CHROME_BROWSER_UI_LIBGTKUI_APP_INDICATOR_ICON_H_