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.
5 // Handles the visible notification (or balloons).
7 #ifndef CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_H_
8 #define CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_H_
13 #include "base/callback.h"
24 class BalloonCollection {
26 class BalloonSpaceChangeListener {
28 virtual ~BalloonSpaceChangeListener() {}
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;
35 // Do not change existing values without migration path; these
36 // are stored as integers in user preferences.
37 enum PositionPreference {
43 // The default position is different on different platforms.
47 static BalloonCollection* Create();
51 virtual ~BalloonCollection();
53 // Adds a new balloon for the specified notification.
54 virtual void Add(const Notification& notification,
55 Profile* profile) = 0;
57 // Returns true if any balloon has this notification id.
58 virtual const Notification* FindById(const std::string& id) const = 0;
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;
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;
68 // Removes any balloons matching |profile. Returns true if any were removed.
69 virtual bool RemoveByProfile(Profile* profile) = 0;
71 // Removes all balloons.
72 virtual void RemoveAll() = 0;
74 // Is there room to add another notification?
75 virtual bool HasSpace() const = 0;
77 // Request the resizing of a balloon.
78 virtual void ResizeBalloon(Balloon* balloon, const gfx::Size& size) = 0;
80 // Set the position preference for the collection.
81 virtual void SetPositionPreference(PositionPreference position) = 0;
83 // Update for new screen dimensions.
84 virtual void DisplayChanged() = 0;
86 // Inform the collection that a balloon was closed.
87 virtual void OnBalloonClosed(Balloon* source) = 0;
89 // Get const collection of the active balloons.
90 typedef std::deque<Balloon*> Balloons;
91 virtual const Balloons& GetActiveBalloons() = 0;
93 BalloonSpaceChangeListener* space_change_listener() {
94 return space_change_listener_;
96 void set_space_change_listener(BalloonSpaceChangeListener* listener) {
97 space_change_listener_ = listener;
100 void set_on_collection_changed_callback(const base::Closure& callback) {
101 on_collection_changed_callback_ = callback;
105 // Non-owned pointer to an object listening for space changes.
106 BalloonSpaceChangeListener* space_change_listener_;
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_;
113 #endif // CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_H_