Home | History | Annotate | Download | only in cocoa
      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_TRAY_VIEW_CONTROLLER_H_
      6 #define UI_MESSAGE_CENTER_COCOA_TRAY_VIEW_CONTROLLER_H_
      7 
      8 #import <Cocoa/Cocoa.h>
      9 
     10 #include <list>
     11 #include <map>
     12 #include <string>
     13 
     14 #include "base/mac/scoped_block.h"
     15 #import "base/mac/scoped_nsobject.h"
     16 #include "base/strings/string16.h"
     17 #include "ui/message_center/message_center_export.h"
     18 
     19 @class HoverImageButton;
     20 @class MCNotificationController;
     21 @class MCSettingsController;
     22 
     23 namespace message_center {
     24 class MessageCenter;
     25 }
     26 
     27 @class HoverImageButton;
     28 @class MCClipView;
     29 
     30 namespace message_center {
     31 typedef void(^TrayAnimationEndedCallback)();
     32 }
     33 
     34 // The view controller responsible for the content of the message center tray
     35 // UI. This hosts a scroll view of all the notifications, as well as buttons
     36 // to enter quiet mode and the settings panel.
     37 MESSAGE_CENTER_EXPORT
     38 @interface MCTrayViewController : NSViewController<NSAnimationDelegate> {
     39  @private
     40   // Controller of the notifications, where action messages are forwarded. Weak.
     41   message_center::MessageCenter* messageCenter_;
     42 
     43   // The back button shown while the settings are open.
     44   base::scoped_nsobject<HoverImageButton> backButton_;
     45 
     46   // The "Notifications" label at the top.
     47   base::scoped_nsobject<NSTextField> title_;
     48 
     49   // The scroll view that contains all the notifications in its documentView.
     50   base::scoped_nsobject<NSScrollView> scrollView_;
     51 
     52   // The clip view that manages how scrollView_'s documentView is clipped.
     53   base::scoped_nsobject<MCClipView> clipView_;
     54 
     55   // Array of MCNotificationController objects, which the array owns.
     56   base::scoped_nsobject<NSMutableArray> notifications_;
     57 
     58   // Map of notification IDs to weak pointers of the view controllers in
     59   // |notifications_|.
     60   std::map<std::string, MCNotificationController*> notificationsMap_;
     61 
     62   // The pause button that enters quiet mode.
     63   base::scoped_nsobject<HoverImageButton> pauseButton_;
     64 
     65   // The clear all notifications button. Hidden when there are no notifications.
     66   base::scoped_nsobject<HoverImageButton> clearAllButton_;
     67 
     68   // The settings button that shows the settings UI.
     69   base::scoped_nsobject<HoverImageButton> settingsButton_;
     70 
     71   // Array of MCNotificationController objects pending removal by the user.
     72   // The object is owned by the array.
     73   base::scoped_nsobject<NSMutableArray> notificationsPendingRemoval_;
     74 
     75   // Used to animate multiple notifications simultaneously when they're being
     76   // removed or repositioned.
     77   base::scoped_nsobject<NSViewAnimation> animation_;
     78 
     79   // The controller of the settings view. Only set while the view is open.
     80   base::scoped_nsobject<MCSettingsController> settingsController_;
     81 
     82   // The flag which is set when the notification removal animation is still
     83   // in progress and the user clicks "Clear All" button. The clear-all animation
     84   // will be delayed till the existing animation completes.
     85   BOOL clearAllDelayed_;
     86 
     87   // The flag which is set when the clear-all animation is in progress.
     88   BOOL clearAllInProgress_;
     89 
     90   // List of weak pointers of the view controllers that are visible in the
     91   // scroll view and waiting to slide off one by one when the user clicks
     92   // "Clear All" button.
     93   std::list<MCNotificationController*> visibleNotificationsPendingClear_;
     94 
     95   // Array of NSViewAnimation objects, which the array owns.
     96   base::scoped_nsobject<NSMutableArray> clearAllAnimations_;
     97 
     98   // The duration of the bounds animation, in the number of seconds.
     99   NSTimeInterval animationDuration_;
    100 
    101   // The delay to start animating clearing next notification, in the number of
    102   // seconds.
    103   NSTimeInterval animateClearingNextNotificationDelay_;
    104 
    105   // For testing only. If set, the callback will be called when the animation
    106   // ends.
    107   base::mac::ScopedBlock<message_center::TrayAnimationEndedCallback>
    108       testingAnimationEndedCallback_;
    109 }
    110 
    111 // The title that is displayed at the top of the message center tray.
    112 @property(copy, nonatomic) NSString* trayTitle;
    113 
    114 // Designated initializer.
    115 - (id)initWithMessageCenter:(message_center::MessageCenter*)messageCenter;
    116 
    117 // Called when the window is being closed.
    118 - (void)onWindowClosing;
    119 
    120 // Callback for when the MessageCenter model changes.
    121 - (void)onMessageCenterTrayChanged;
    122 
    123 // Action for the quiet mode button.
    124 - (void)toggleQuietMode:(id)sender;
    125 
    126 // Action for the clear all button.
    127 - (void)clearAllNotifications:(id)sender;
    128 
    129 // Action for the settings button.
    130 - (void)showSettings:(id)sender;
    131 
    132 // Updates the settings dialog in response to contents change due to something
    133 // like selecting a different profile.
    134 - (void)updateSettings;
    135 
    136 // Hides the settings dialog if it's open.
    137 - (void)showMessages:(id)sender;
    138 
    139 // Cleans up settings data structures.  Called when messages are shown and when
    140 // closing the center directly from the settings.
    141 - (void)cleanupSettings;
    142 
    143 // Scroll to the topmost notification in the tray.
    144 - (void)scrollToTop;
    145 
    146 // Returns true if an animation is being played.
    147 - (BOOL)isAnimating;
    148 
    149 // Returns the maximum height of the client area of the notifications tray.
    150 + (CGFloat)maxTrayClientHeight;
    151 
    152 // Returns the width of the notifications tray.
    153 + (CGFloat)trayWidth;
    154 
    155 @end
    156 
    157 // Testing API /////////////////////////////////////////////////////////////////
    158 
    159 @interface MCTrayViewController (TestingAPI)
    160 - (NSScrollView*)scrollView;
    161 - (HoverImageButton*)pauseButton;
    162 - (HoverImageButton*)clearAllButton;
    163 
    164 // Setter for changing the animation duration. The testing code could set it
    165 // to a very small value to expedite the test running.
    166 - (void)setAnimationDuration:(NSTimeInterval)duration;
    167 
    168 // Setter for changing the clear-all animation delay. The testing code could set
    169 // it to a very small value to expedite the test running.
    170 - (void)setAnimateClearingNextNotificationDelay:(NSTimeInterval)delay;
    171 
    172 // Setter for testingAnimationEndedCallback_. The testing code could set it
    173 // to get called back when the animation ends.
    174 - (void)setAnimationEndedCallback:
    175     (message_center::TrayAnimationEndedCallback)callback;
    176 @end
    177 
    178 #endif  // UI_MESSAGE_CENTER_COCOA_TRAY_VIEW_CONTROLLER_H_
    179