• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 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_STATUS_ICONS_STATUS_ICON_H_
6 #define CHROME_BROWSER_STATUS_ICONS_STATUS_ICON_H_
7 
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/observer_list.h"
11 #include "base/strings/string16.h"
12 #include "chrome/browser/status_icons/status_icon_menu_model.h"
13 
14 namespace gfx {
15 class ImageSkia;
16 }
17 
18 class StatusIconObserver;
19 
20 class StatusIcon {
21  public:
22   StatusIcon();
23   virtual ~StatusIcon();
24 
25   // Sets the image associated with this status icon.
26   virtual void SetImage(const gfx::ImageSkia& image) = 0;
27 
28   // Sets the image associated with this status icon when pressed.
29   virtual void SetPressedImage(const gfx::ImageSkia& image) = 0;
30 
31   // Sets the hover text for this status icon. This is also used as the label
32   // for the menu item which is created as a replacement for the status icon
33   // click action on platforms that do not support custom click actions for the
34   // status icon (e.g. Ubuntu Unity).
35   virtual void SetToolTip(const base::string16& tool_tip) = 0;
36 
37   // Displays a notification balloon with the specified contents.
38   // Depending on the platform it might not appear by the icon tray.
39   virtual void DisplayBalloon(const gfx::ImageSkia& icon,
40                               const base::string16& title,
41                               const base::string16& contents) = 0;
42 
43   // Set the context menu for this icon. The icon takes ownership of the passed
44   // context menu. Passing NULL results in no menu at all.
45   void SetContextMenu(scoped_ptr<StatusIconMenuModel> menu);
46 
47   // Adds/Removes an observer for clicks on the status icon. If an observer is
48   // registered, then left clicks on the status icon will result in the observer
49   // being called, otherwise, both left and right clicks will display the
50   // context menu (if any).
51   void AddObserver(StatusIconObserver* observer);
52   void RemoveObserver(StatusIconObserver* observer);
53 
54   // Returns true if there are registered click observers.
55   bool HasObservers() const;
56 
57   // Dispatches a click event to the observers.
58   void DispatchClickEvent();
59 #if defined(OS_WIN)
60   void DispatchBalloonClickEvent();
61 #endif
62 
63   // Attempts to make the status icon directly visible on system UI.  Currently
64   // this only applies to Windows, where status icons are hidden by default
65   // inside an overflow window.
66   // WARNING: This currently uses undocumented Windows APIs and spawns a worker
67   // thread to do it.  Use sparingly.
68   virtual void ForceVisible();
69 
70  protected:
71   // Invoked after a call to SetContextMenu() to let the platform-specific
72   // subclass update the native context menu based on the new model. If NULL is
73   // passed, subclass should destroy the native context menu.
74   virtual void UpdatePlatformContextMenu(StatusIconMenuModel* model) = 0;
75 
76  private:
77   ObserverList<StatusIconObserver> observers_;
78 
79   // Context menu, if any.
80   scoped_ptr<StatusIconMenuModel> context_menu_contents_;
81 
82   DISALLOW_COPY_AND_ASSIGN(StatusIcon);
83 };
84 
85 #endif  // CHROME_BROWSER_STATUS_ICONS_STATUS_ICON_H_
86