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_CONTROLLER_H_ 6 #define UI_MESSAGE_CENTER_COCOA_POPUP_CONTROLLER_H_ 7 8 #import <Cocoa/Cocoa.h> 9 10 #include <string> 11 12 #import "base/mac/scoped_nsobject.h" 13 #import "ui/base/cocoa/tracking_area.h" 14 #include "ui/message_center/message_center_export.h" 15 16 namespace message_center { 17 class MessageCenter; 18 class Notification; 19 } 20 21 @class MCNotificationController; 22 @class MCPopupCollection; 23 24 // A window controller that hosts a notification as a popup balloon on the 25 // user's desktop. The window controller manages its lifetime because the 26 // popup collection will be destructed when the last popup is closed. 27 MESSAGE_CENTER_EXPORT 28 @interface MCPopupController : NSWindowController<NSAnimationDelegate> { 29 @private 30 // Global message center. Weak. 31 message_center::MessageCenter* messageCenter_; 32 33 // The collection that contains the popup. Weak. 34 MCPopupCollection* popupCollection_; 35 36 // The view controller that provide's the popup content view. 37 base::scoped_nsobject<MCNotificationController> notificationController_; 38 39 // If the swipe-away gesture received NSEventPhaseEnded. 40 BOOL swipeGestureEnded_; 41 42 // The frame of the popup before any swipe animation started. Used to 43 // calculate the animating position of the window when swiping away. 44 NSRect originalFrame_; 45 46 // Is the popup currently being closed? 47 BOOL isClosing_; 48 49 // The current bounds of the popup frame if no animation is playing. 50 // Otherwise, it is the target bounds of the popup frame. 51 NSRect bounds_; 52 53 // Used to play animation when the popup shows, changes bounds and closes. 54 base::scoped_nsobject<NSViewAnimation> boundsAnimation_; 55 56 // Used to track the popup for mouse entered and exited events. 57 ui::ScopedCrTrackingArea trackingArea_; 58 } 59 60 // Designated initializer. 61 - (id)initWithNotification:(const message_center::Notification*)notification 62 messageCenter:(message_center::MessageCenter*)messageCenter 63 popupCollection:(MCPopupCollection*)popupCollection; 64 65 // Accessor for the view controller. 66 - (MCNotificationController*)notificationController; 67 68 // Accessor for the notification model object. 69 - (const message_center::Notification*)notification; 70 71 // Gets the notification ID. This string is owned by the NotificationController 72 // rather than the model object, so it's safe to use after the Notification has 73 // been deleted. 74 - (const std::string&)notificationID; 75 76 // Shows the window with the sliding animation. 77 - (void)showWithAnimation:(NSRect)newBounds; 78 79 // Closes the window with the fade-out animation. 80 - (void)closeWithAnimation; 81 82 // Tells that the popupCollection_ is gone. 83 - (void)markPopupCollectionGone; 84 85 // Returns the window bounds. This is the target bounds to go to if the bounds 86 // animation is playing. 87 - (NSRect)bounds; 88 89 // Changes the window bounds with animation. 90 - (void)setBounds:(NSRect)newBounds; 91 92 @end 93 94 #endif // UI_MESSAGE_CENTER_COCOA_POPUP_CONTROLLER_H_ 95