summaryrefslogtreecommitdiffstats
path: root/chrome/browser/notifications/balloon_collection.h
blob: 743edb5d60665d2a62de6b35eed805d9c371544a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Handles the visible notification (or balloons).

#ifndef CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_H_
#define CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_H_
#pragma once

#include <deque>
#include <string>

#include "base/callback_old.h"
#include "base/memory/scoped_ptr.h"

class Balloon;
class GURL;
class Notification;
class Profile;

namespace gfx {
class Size;
}  // namespace gfx

class BalloonCollection {
 public:
  class BalloonSpaceChangeListener {
   public:
    virtual ~BalloonSpaceChangeListener() {}

    // Called when there is more or less space for balloons due to
    // monitor size changes or balloons disappearing.
    virtual void OnBalloonSpaceChanged() = 0;
  };

  // Do not change existing values without migration path; these
  // are stored as integers in user preferences.
  enum PositionPreference {
    UPPER_RIGHT        = 0,
    LOWER_RIGHT        = 1,
    UPPER_LEFT         = 2,
    LOWER_LEFT         = 3,

    // The default position is different on different platforms.
    DEFAULT_POSITION   = -1
  };

  static BalloonCollection* Create();

  BalloonCollection();

  virtual ~BalloonCollection();

  // Adds a new balloon for the specified notification.
  virtual void Add(const Notification& notification,
                   Profile* profile) = 0;

  // Removes any balloons that have this notification id.  Returns
  // true if anything was removed.
  virtual bool RemoveById(const std::string& id) = 0;

  // Removes any balloons that have this source origin.  Returns
  // true if anything was removed.
  virtual bool RemoveBySourceOrigin(const GURL& source_origin) = 0;

  // Removes all balloons.
  virtual void RemoveAll() = 0;

  // Is there room to add another notification?
  virtual bool HasSpace() const = 0;

  // Request the resizing of a balloon.
  virtual void ResizeBalloon(Balloon* balloon, const gfx::Size& size) = 0;

  // Set the position preference for the collection.
  virtual void SetPositionPreference(PositionPreference position) = 0;

  // Update for new screen dimensions.
  virtual void DisplayChanged() = 0;

  // Inform the collection that a balloon was closed.
  virtual void OnBalloonClosed(Balloon* source) = 0;

  // Get const collection of the active balloons.
  typedef std::deque<Balloon*> Balloons;
  virtual const Balloons& GetActiveBalloons() = 0;

  BalloonSpaceChangeListener* space_change_listener() {
    return space_change_listener_;
  }
  void set_space_change_listener(BalloonSpaceChangeListener* listener) {
    space_change_listener_ = listener;
  }

  void set_on_collection_changed_callback(Callback0::Type* callback) {
    on_collection_changed_callback_.reset(callback);
  }

 protected:
  // Non-owned pointer to an object listening for space changes.
  BalloonSpaceChangeListener* space_change_listener_;

  // For use only with testing. This callback is invoked when a balloon
  // is added or removed from the collection.
  scoped_ptr<Callback0::Type> on_collection_changed_callback_;
};

#endif  // CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_H_