1// Copyright (c) 2013 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#ifndef UI_MESSAGE_CENTER_COCOA_POPUP_COLLECTION_H_ 6#define UI_MESSAGE_CENTER_COCOA_POPUP_COLLECTION_H_ 7 8#import <Cocoa/Cocoa.h> 9 10#include <set> 11 12#include "base/mac/scoped_block.h" 13#import "base/mac/scoped_nsobject.h" 14#import "base/memory/scoped_ptr.h" 15#include "ui/message_center/message_center_export.h" 16 17namespace message_center { 18class MessageCenter; 19class MessageCenterObserver; 20} 21 22namespace message_center { 23typedef void(^AnimationEndedCallback)(); 24} 25 26// A popup collection interfaces with the MessageCenter as an observer. It will 27// arrange notifications on the screen as popups, starting in the upper-right 28// corner, going to the bottom of the screen. This class maintains ownership of 29// the Cocoa controllers and windows of the notifications. 30MESSAGE_CENTER_EXPORT 31@interface MCPopupCollection : NSObject { 32 @private 33 // The message center that is responsible for the notifications. Weak, global. 34 message_center::MessageCenter* messageCenter_; 35 36 // MessageCenterObserver implementation. 37 scoped_ptr<message_center::MessageCenterObserver> observer_; 38 39 // Array of all on-screen popup notifications. 40 base::scoped_nsobject<NSMutableArray> popups_; 41 42 // Array of all on-screen popup notifications that are being faded out 43 // for removal. 44 base::scoped_nsobject<NSMutableArray> popupsBeingRemoved_; 45 46 // For testing only. If not a zero rect, this is the screen size to use 47 // for laying out popups. 48 NSRect testingScreenFrame_; 49 50 // The duration of the popup animation, in the number of seconds. 51 NSTimeInterval popupAnimationDuration_; 52 53 // Set of notification IDs for those popups to be updated when all existing 54 // animations end. 55 std::set<std::string> pendingUpdateNotificationIDs_; 56 57 // Set of notification IDs for those popups to be closed when all existing 58 // animations end. 59 std::set<std::string> pendingRemoveNotificationIDs_; 60 61 // Set of notification IDs for those popups that are being animated due to 62 // showing, bounds change or closing. 63 std::set<std::string> animatingNotificationIDs_; 64 65 // For testing only. If set, the callback will be called when the animation 66 // ends. 67 base::mac::ScopedBlock<message_center::AnimationEndedCallback> 68 testingAnimationEndedCallback_; 69} 70 71// Designated initializer that construct an instance to observe |messageCenter|. 72- (id)initWithMessageCenter:(message_center::MessageCenter*)messageCenter; 73 74// Returns true if an animation is being played. 75- (BOOL)isAnimating; 76 77// Returns the duration of the popup animation. 78- (NSTimeInterval)popupAnimationDuration; 79 80// Called when the animation of a popup ends. 81- (void)onPopupAnimationEnded:(const std::string&)notificationID; 82 83@end 84 85@interface MCPopupCollection (ExposedForTesting) 86- (NSArray*)popups; 87 88// Setter for the testingScreenFrame_. 89- (void)setScreenFrame:(NSRect)frame; 90 91// Setter for changing the animation duration. The testing code could set it 92// to a very small value to expedite the test running. 93- (void)setAnimationDuration:(NSTimeInterval)duration; 94 95// Setter for testingAnimationEndedCallback_. The testing code could set it 96// to get called back when the animation ends. 97- (void)setAnimationEndedCallback: 98 (message_center::AnimationEndedCallback)callback; 99@end 100 101#endif // UI_MESSAGE_CENTER_COCOA_POPUP_COLLECTION_H_ 102