• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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 #pragma once
8 
9 #include "base/memory/scoped_ptr.h"
10 #include "base/observer_list.h"
11 #include "base/string16.h"
12 
13 class SkBitmap;
14 
15 namespace ui {
16 class MenuModel;
17 }
18 
19 class StatusIcon {
20  public:
21   StatusIcon();
22   virtual ~StatusIcon();
23 
24   // Sets the image associated with this status icon.
25   virtual void SetImage(const SkBitmap& image) = 0;
26 
27   // Sets the image associated with this status icon when pressed.
28   virtual void SetPressedImage(const SkBitmap& image) = 0;
29 
30   // Sets the hover text for this status icon.
31   virtual void SetToolTip(const string16& tool_tip) = 0;
32 
33   // Displays a notification balloon with the specified contents.
34   virtual void DisplayBalloon(const string16& title,
35                               const string16& contents) = 0;
36 
37   // Set the context menu for this icon. The icon takes ownership of the passed
38   // context menu. Passing NULL results in no menu at all.
39   void SetContextMenu(ui::MenuModel* menu);
40 
41   class Observer {
42    public:
~Observer()43     virtual ~Observer() {}
44 
45     // Called when the user clicks on the system tray icon. Clicks that result
46     // in the context menu being displayed will not be passed to this observer
47     // (i.e. if there's a context menu set on this status icon, and the user
48     // right clicks on the icon to display the context menu, OnClicked will not
49     // be called).
50     virtual void OnClicked() = 0;
51   };
52 
53   // Adds/Removes an observer for clicks on the status icon. If an observer is
54   // registered, then left clicks on the status icon will result in the observer
55   // being called, otherwise, both left and right clicks will display the
56   // context menu (if any).
57   void AddObserver(Observer* observer);
58   void RemoveObserver(Observer* observer);
59 
60   // Returns true if there are registered click observers.
61   bool HasObservers();
62 
63   // Dispatches a click event to the observers.
64   void DispatchClickEvent();
65 
66  protected:
67   // Invoked after a call to SetContextMenu() to let the platform-specific
68   // subclass update the native context menu based on the new model. If NULL is
69   // passed, subclass should destroy the native context menu.
70   virtual void UpdatePlatformContextMenu(ui::MenuModel* model) = 0;
71 
72  private:
73   ObserverList<Observer> observers_;
74   // Context menu, if any.
75   scoped_ptr<ui::MenuModel> context_menu_contents_;
76   DISALLOW_COPY_AND_ASSIGN(StatusIcon);
77 };
78 
79 #endif  // CHROME_BROWSER_STATUS_ICONS_STATUS_ICON_H_
80