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// Handles the visible notification (or balloons).
6
7#ifndef CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_H_
8#define CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_H_
9
10#include <deque>
11#include <string>
12
13#include "base/callback.h"
14
15class Balloon;
16class GURL;
17class Notification;
18class Profile;
19
20namespace gfx {
21class Size;
22}
23
24class BalloonCollection {
25 public:
26  class BalloonSpaceChangeListener {
27   public:
28    virtual ~BalloonSpaceChangeListener() {}
29
30    // Called when there is more or less space for balloons due to
31    // monitor size changes or balloons disappearing.
32    virtual void OnBalloonSpaceChanged() = 0;
33  };
34
35  // Do not change existing values without migration path; these
36  // are stored as integers in user preferences.
37  enum PositionPreference {
38    UPPER_RIGHT        = 0,
39    LOWER_RIGHT        = 1,
40    UPPER_LEFT         = 2,
41    LOWER_LEFT         = 3,
42
43    // The default position is different on different platforms.
44    DEFAULT_POSITION   = -1
45  };
46
47  static BalloonCollection* Create();
48
49  BalloonCollection();
50
51  virtual ~BalloonCollection();
52
53  // Adds a new balloon for the specified notification.
54  virtual void Add(const Notification& notification,
55                   Profile* profile) = 0;
56
57  // Returns true if any balloon has this notification id.
58  virtual const Notification* FindById(const std::string& id) const = 0;
59
60  // Removes any balloons that have this notification id. Returns
61  // true if anything was removed.
62  virtual bool RemoveById(const std::string& id) = 0;
63
64  // Removes any balloons that have this source origin. Returns
65  // true if anything was removed.
66  virtual bool RemoveBySourceOrigin(const GURL& source_origin) = 0;
67
68  // Removes any balloons matching |profile. Returns true if any were removed.
69  virtual bool RemoveByProfile(Profile* profile) = 0;
70
71  // Removes all balloons.
72  virtual void RemoveAll() = 0;
73
74  // Is there room to add another notification?
75  virtual bool HasSpace() const = 0;
76
77  // Request the resizing of a balloon.
78  virtual void ResizeBalloon(Balloon* balloon, const gfx::Size& size) = 0;
79
80  // Set the position preference for the collection.
81  virtual void SetPositionPreference(PositionPreference position) = 0;
82
83  // Update for new screen dimensions.
84  virtual void DisplayChanged() = 0;
85
86  // Inform the collection that a balloon was closed.
87  virtual void OnBalloonClosed(Balloon* source) = 0;
88
89  // Get const collection of the active balloons.
90  typedef std::deque<Balloon*> Balloons;
91  virtual const Balloons& GetActiveBalloons() = 0;
92
93  BalloonSpaceChangeListener* space_change_listener() {
94    return space_change_listener_;
95  }
96  void set_space_change_listener(BalloonSpaceChangeListener* listener) {
97    space_change_listener_ = listener;
98  }
99
100  void set_on_collection_changed_callback(const base::Closure& callback) {
101    on_collection_changed_callback_ = callback;
102  }
103
104 protected:
105  // Non-owned pointer to an object listening for space changes.
106  BalloonSpaceChangeListener* space_change_listener_;
107
108  // For use only with testing. This callback is invoked when a balloon
109  // is added or removed from the collection.
110  base::Closure on_collection_changed_callback_;
111};
112
113#endif  // CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_H_
114