summaryrefslogtreecommitdiff
path: root/chromium/ui/message_center/cocoa/tray_view_controller.h
blob: d5f9f1f8876301d9a72e56feeaddafd33960915c (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// Copyright (c) 2013 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.

#ifndef UI_MESSAGE_CENTER_COCOA_TRAY_VIEW_CONTROLLER_H_
#define UI_MESSAGE_CENTER_COCOA_TRAY_VIEW_CONTROLLER_H_

#import <Cocoa/Cocoa.h>

#include <list>
#include <map>
#include <string>

#include "base/mac/scoped_block.h"
#import "base/mac/scoped_nsobject.h"
#include "base/strings/string16.h"
#include "ui/message_center/message_center_export.h"

@class HoverImageButton;
@class MCNotificationController;
@class MCSettingsController;

namespace message_center {
class MessageCenter;
}

@class HoverImageButton;
@class MCClipView;

namespace message_center {
typedef void(^TrayAnimationEndedCallback)();
}

// The view controller responsible for the content of the message center tray
// UI. This hosts a scroll view of all the notifications, as well as buttons
// to enter quiet mode and the settings panel.
MESSAGE_CENTER_EXPORT
@interface MCTrayViewController : NSViewController<NSAnimationDelegate> {
 @private
  // Controller of the notifications, where action messages are forwarded. Weak.
  message_center::MessageCenter* messageCenter_;

  // The back button shown while the settings are open.
  base::scoped_nsobject<HoverImageButton> backButton_;

  // The "Notifications" label at the top.
  base::scoped_nsobject<NSTextField> title_;

  // The scroll view that contains all the notifications in its documentView.
  base::scoped_nsobject<NSScrollView> scrollView_;

  // The clip view that manages how scrollView_'s documentView is clipped.
  base::scoped_nsobject<MCClipView> clipView_;

  // Array of MCNotificationController objects, which the array owns.
  base::scoped_nsobject<NSMutableArray> notifications_;

  // Map of notification IDs to weak pointers of the view controllers in
  // |notifications_|.
  std::map<std::string, MCNotificationController*> notificationsMap_;

  // The pause button that enters quiet mode.
  base::scoped_nsobject<HoverImageButton> pauseButton_;

  // The clear all notifications button. Hidden when there are no notifications.
  base::scoped_nsobject<HoverImageButton> clearAllButton_;

  // The settings button that shows the settings UI.
  base::scoped_nsobject<HoverImageButton> settingsButton_;

  // Array of MCNotificationController objects pending removal by the user.
  // The object is owned by the array.
  base::scoped_nsobject<NSMutableArray> notificationsPendingRemoval_;

  // Used to animate multiple notifications simultaneously when they're being
  // removed or repositioned.
  base::scoped_nsobject<NSViewAnimation> animation_;

  // The controller of the settings view. Only set while the view is open.
  base::scoped_nsobject<MCSettingsController> settingsController_;

  // The flag which is set when the notification removal animation is still
  // in progress and the user clicks "Clear All" button. The clear-all animation
  // will be delayed till the existing animation completes.
  BOOL clearAllDelayed_;

  // The flag which is set when the clear-all animation is in progress.
  BOOL clearAllInProgress_;

  // List of weak pointers of the view controllers that are visible in the
  // scroll view and waiting to slide off one by one when the user clicks
  // "Clear All" button.
  std::list<MCNotificationController*> visibleNotificationsPendingClear_;

  // Array of NSViewAnimation objects, which the array owns.
  base::scoped_nsobject<NSMutableArray> clearAllAnimations_;

  // The duration of the bounds animation, in the number of seconds.
  NSTimeInterval animationDuration_;

  // The delay to start animating clearing next notification, in the number of
  // seconds.
  NSTimeInterval animateClearingNextNotificationDelay_;

  // For testing only. If set, the callback will be called when the animation
  // ends.
  base::mac::ScopedBlock<message_center::TrayAnimationEndedCallback>
      testingAnimationEndedCallback_;
}

// The title that is displayed at the top of the message center tray.
@property(copy, nonatomic) NSString* trayTitle;

// Designated initializer.
- (id)initWithMessageCenter:(message_center::MessageCenter*)messageCenter;

// Called when the window is being closed.
- (void)onWindowClosing;

// Callback for when the MessageCenter model changes.
- (void)onMessageCenterTrayChanged;

// Action for the quiet mode button.
- (void)toggleQuietMode:(id)sender;

// Action for the clear all button.
- (void)clearAllNotifications:(id)sender;

// Action for the settings button.
- (void)showSettings:(id)sender;

// Updates the settings dialog in response to contents change due to something
// like selecting a different profile.
- (void)updateSettings;

// Hides the settings dialog if it's open.
- (void)showMessages:(id)sender;

// Cleans up settings data structures.  Called when messages are shown and when
// closing the center directly from the settings.
- (void)cleanupSettings;

// Scroll to the topmost notification in the tray.
- (void)scrollToTop;

// Returns true if an animation is being played.
- (BOOL)isAnimating;

// Returns the maximum height of the client area of the notifications tray.
+ (CGFloat)maxTrayClientHeight;

// Returns the width of the notifications tray.
+ (CGFloat)trayWidth;

@end

// Testing API /////////////////////////////////////////////////////////////////

@interface MCTrayViewController (TestingAPI)
- (NSScrollView*)scrollView;
- (HoverImageButton*)pauseButton;
- (HoverImageButton*)clearAllButton;

// Setter for changing the animation duration. The testing code could set it
// to a very small value to expedite the test running.
- (void)setAnimationDuration:(NSTimeInterval)duration;

// Setter for changing the clear-all animation delay. The testing code could set
// it to a very small value to expedite the test running.
- (void)setAnimateClearingNextNotificationDelay:(NSTimeInterval)delay;

// Setter for testingAnimationEndedCallback_. The testing code could set it
// to get called back when the animation ends.
- (void)setAnimationEndedCallback:
    (message_center::TrayAnimationEndedCallback)callback;
@end

#endif  // UI_MESSAGE_CENTER_COCOA_TRAY_VIEW_CONTROLLER_H_