balloon_collection.h revision 513209b27ff55e2841eac0e4120199c23acce758
1// Copyright (c) 2010 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 13#include "base/callback.h" 14#include "base/scoped_ptr.h" 15 16class Balloon; 17class Notification; 18class Profile; 19 20namespace gfx { 21class Size; 22} // namespace gfx 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 static BalloonCollection* Create(); 36 37 BalloonCollection() 38 : space_change_listener_(NULL) { 39 } 40 41 virtual ~BalloonCollection() {} 42 43 // Adds a new balloon for the specified notification. 44 virtual void Add(const Notification& notification, 45 Profile* profile) = 0; 46 47 // Removes a balloon from the collection if present. Returns 48 // true if anything was removed. 49 virtual bool Remove(const Notification& notification) = 0; 50 51 // Is there room to add another notification? 52 virtual bool HasSpace() const = 0; 53 54 // Request the resizing of a balloon. 55 virtual void ResizeBalloon(Balloon* balloon, const gfx::Size& size) = 0; 56 57 // Update for new screen dimensions. 58 virtual void DisplayChanged() = 0; 59 60 // Inform the collection that a balloon was closed. 61 virtual void OnBalloonClosed(Balloon* source) = 0; 62 63 // Get const collection of the active balloons. 64 typedef std::deque<Balloon*> Balloons; 65 virtual const Balloons& GetActiveBalloons() = 0; 66 67 BalloonSpaceChangeListener* space_change_listener() { 68 return space_change_listener_; 69 } 70 void set_space_change_listener(BalloonSpaceChangeListener* listener) { 71 space_change_listener_ = listener; 72 } 73 74 void set_on_collection_changed_callback(Callback0::Type* callback) { 75 on_collection_changed_callback_.reset(callback); 76 } 77 78 protected: 79 // Non-owned pointer to an object listening for space changes. 80 BalloonSpaceChangeListener* space_change_listener_; 81 82 // For use only with testing. This callback is invoked when a balloon 83 // is added or removed from the collection. 84 scoped_ptr<Callback0::Type> on_collection_changed_callback_; 85}; 86 87#endif // CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_H_ 88