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