Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: ui/message_center/views/message_center_view.cc

Issue 1961803002: Remove NoNotificationMessageView from empty message center (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added tests of "mode". Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/message_center/views/message_center_view.h" 5 #include "ui/message_center/views/message_center_view.h"
6 6
7 #include <list> 7 #include <list>
8 #include <map> 8 #include <map>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 25 matching lines...) Expand all
36 #include "ui/views/controls/label.h" 36 #include "ui/views/controls/label.h"
37 #include "ui/views/controls/scroll_view.h" 37 #include "ui/views/controls/scroll_view.h"
38 #include "ui/views/controls/scrollbar/overlay_scroll_bar.h" 38 #include "ui/views/controls/scrollbar/overlay_scroll_bar.h"
39 #include "ui/views/layout/fill_layout.h" 39 #include "ui/views/layout/fill_layout.h"
40 #include "ui/views/widget/widget.h" 40 #include "ui/views/widget/widget.h"
41 41
42 namespace message_center { 42 namespace message_center {
43 43
44 namespace { 44 namespace {
45 45
46 const SkColor kNoNotificationsTextColor = SkColorSetRGB(0xb4, 0xb4, 0xb4);
47 #if defined(OS_LINUX) && defined(OS_CHROMEOS)
48 const SkColor kTransparentColor = SkColorSetARGB(0, 0, 0, 0);
49 #endif
50
51 const int kDefaultAnimationDurationMs = 120; 46 const int kDefaultAnimationDurationMs = 120;
52 const int kDefaultFrameRateHz = 60; 47 const int kDefaultFrameRateHz = 60;
53 48
54 void SetViewHierarchyEnabled(views::View* view, bool enabled) { 49 void SetViewHierarchyEnabled(views::View* view, bool enabled) {
55 for (int i = 0; i < view->child_count(); i++) 50 for (int i = 0; i < view->child_count(); i++)
56 SetViewHierarchyEnabled(view->child_at(i), enabled); 51 SetViewHierarchyEnabled(view->child_at(i), enabled);
57 view->SetEnabled(enabled); 52 view->SetEnabled(enabled);
58 } 53 }
59 54
60 } // namespace 55 } // namespace
61 56
62 class NoNotificationMessageView : public views::View {
63 public:
64 NoNotificationMessageView();
65 ~NoNotificationMessageView() override;
66
67 // Overridden from views::View.
68 gfx::Size GetPreferredSize() const override;
69 int GetHeightForWidth(int width) const override;
70 void Layout() override;
71
72 private:
73 views::Label* label_;
74
75 DISALLOW_COPY_AND_ASSIGN(NoNotificationMessageView);
76 };
77
78 NoNotificationMessageView::NoNotificationMessageView() {
79 label_ = new views::Label(l10n_util::GetStringUTF16(
80 IDS_MESSAGE_CENTER_NO_MESSAGES));
81 label_->SetAutoColorReadabilityEnabled(false);
82 label_->SetEnabledColor(kNoNotificationsTextColor);
83 // Set transparent background to ensure that subpixel rendering
84 // is disabled. See crbug.com/169056
85 #if defined(OS_LINUX) && defined(OS_CHROMEOS)
86 label_->SetBackgroundColor(kTransparentColor);
87 #endif
88 AddChildView(label_);
89 }
90
91 NoNotificationMessageView::~NoNotificationMessageView() {
92 }
93
94 gfx::Size NoNotificationMessageView::GetPreferredSize() const {
95 return gfx::Size(kMinScrollViewHeight, label_->GetPreferredSize().width());
96 }
97
98 int NoNotificationMessageView::GetHeightForWidth(int width) const {
99 return kMinScrollViewHeight;
100 }
101
102 void NoNotificationMessageView::Layout() {
103 int text_height = label_->GetHeightForWidth(width());
104 int margin = (height() - text_height) / 2;
105 label_->SetBounds(0, margin, width(), text_height);
106 }
107
108 // MessageCenterView /////////////////////////////////////////////////////////// 57 // MessageCenterView ///////////////////////////////////////////////////////////
109 58
110 MessageCenterView::MessageCenterView(MessageCenter* message_center, 59 MessageCenterView::MessageCenterView(MessageCenter* message_center,
111 MessageCenterTray* tray, 60 MessageCenterTray* tray,
112 int max_height, 61 int max_height,
113 bool initially_settings_visible, 62 bool initially_settings_visible,
114 bool top_down, 63 bool top_down,
115 const base::string16& title) 64 const base::string16& title)
116 : message_center_(message_center), 65 : message_center_(message_center),
117 tray_(tray), 66 tray_(tray),
118 scroller_(NULL), 67 scroller_(NULL),
119 settings_view_(NULL), 68 settings_view_(NULL),
120 button_bar_(NULL), 69 button_bar_(NULL),
121 top_down_(top_down), 70 top_down_(top_down),
122 settings_visible_(initially_settings_visible), 71 settings_visible_(initially_settings_visible),
123 source_view_(NULL), 72 source_view_(NULL),
124 source_height_(0), 73 source_height_(0),
125 target_view_(NULL), 74 target_view_(NULL),
126 target_height_(0), 75 target_height_(0),
127 is_closing_(false), 76 is_closing_(false),
77 mode_((!initially_settings_visible) ? Mode::BUTTONS_ONLY
78 : Mode::SETTINGS),
128 context_menu_controller_(new MessageViewContextMenuController(this)) { 79 context_menu_controller_(new MessageViewContextMenuController(this)) {
129 message_center_->AddObserver(this); 80 message_center_->AddObserver(this);
130 set_notify_enter_exit_on_child(true); 81 set_notify_enter_exit_on_child(true);
131 set_background(views::Background::CreateSolidBackground( 82 set_background(views::Background::CreateSolidBackground(
132 kMessageCenterBackgroundColor)); 83 kMessageCenterBackgroundColor));
133 84
134 NotifierSettingsProvider* notifier_settings_provider = 85 NotifierSettingsProvider* notifier_settings_provider =
135 message_center_->GetNotifierSettingsProvider(); 86 message_center_->GetNotifierSettingsProvider();
136 button_bar_ = new MessageCenterButtonBar(this, 87 button_bar_ = new MessageCenterButtonBar(this,
137 message_center, 88 message_center,
138 notifier_settings_provider, 89 notifier_settings_provider,
139 initially_settings_visible, 90 initially_settings_visible,
140 title); 91 title);
92 button_bar_->SetCloseAllButtonEnabled(false);
141 93
142 const int button_height = button_bar_->GetPreferredSize().height(); 94 const int button_height = button_bar_->GetPreferredSize().height();
143 95
144 scroller_ = new views::ScrollView(); 96 scroller_ = new views::ScrollView();
145 scroller_->ClipHeightTo(kMinScrollViewHeight, max_height - button_height); 97 scroller_->ClipHeightTo(kMinScrollViewHeight, max_height - button_height);
146 scroller_->SetVerticalScrollBar(new views::OverlayScrollBar(false)); 98 scroller_->SetVerticalScrollBar(new views::OverlayScrollBar(false));
147 scroller_->set_background( 99 scroller_->set_background(
148 views::Background::CreateSolidBackground(kMessageCenterBackgroundColor)); 100 views::Background::CreateSolidBackground(kMessageCenterBackgroundColor));
149 101
150 scroller_->SetPaintToLayer(true); 102 scroller_->SetPaintToLayer(true);
151 scroller_->layer()->SetFillsBoundsOpaquely(false); 103 scroller_->layer()->SetFillsBoundsOpaquely(false);
152 scroller_->layer()->SetMasksToBounds(true); 104 scroller_->layer()->SetMasksToBounds(true);
153 105
154 empty_list_view_.reset(new NoNotificationMessageView);
155 empty_list_view_->set_owned_by_client();
156 message_list_view_.reset(new MessageListView(this, top_down)); 106 message_list_view_.reset(new MessageListView(this, top_down));
157 message_list_view_->set_owned_by_client(); 107 message_list_view_->set_owned_by_client();
158 108
159 // We want to swap the contents of the scroll view between the empty list 109 // We want to swap the contents of the scroll view between the empty list
160 // view and the message list view, without constructing them afresh each 110 // view and the message list view, without constructing them afresh each
161 // time. So, since the scroll view deletes old contents each time you 111 // time. So, since the scroll view deletes old contents each time you
162 // set the contents (regardless of the |owned_by_client_| setting) we need 112 // set the contents (regardless of the |owned_by_client_| setting) we need
163 // an intermediate view for the contents whose children we can swap in and 113 // an intermediate view for the contents whose children we can swap in and
164 // out. 114 // out.
165 views::View* scroller_contents = new views::View(); 115 views::View* scroller_contents = new views::View();
166 scroller_contents->SetLayoutManager(new views::FillLayout()); 116 scroller_contents->SetLayoutManager(new views::FillLayout());
167 scroller_contents->AddChildView(empty_list_view_.get()); 117 scroller_contents->AddChildView(message_list_view_.get());
168 scroller_->SetContents(scroller_contents); 118 scroller_->SetContents(scroller_contents);
169 119
170 settings_view_ = new NotifierSettingsView(notifier_settings_provider); 120 settings_view_ = new NotifierSettingsView(notifier_settings_provider);
171 121
172 if (initially_settings_visible) 122 scroller_->SetVisible(false); // Because it has no notifications at first.
173 scroller_->SetVisible(false); 123 settings_view_->SetVisible(mode_ == Mode::SETTINGS);
174 else
175 settings_view_->SetVisible(false);
176 124
177 AddChildView(scroller_); 125 AddChildView(scroller_);
178 AddChildView(settings_view_); 126 AddChildView(settings_view_);
179 AddChildView(button_bar_); 127 AddChildView(button_bar_);
180 } 128 }
181 129
182 MessageCenterView::~MessageCenterView() { 130 MessageCenterView::~MessageCenterView() {
183 if (!is_closing_) 131 if (!is_closing_)
184 message_center_->RemoveObserver(this); 132 message_center_->RemoveObserver(this);
185 } 133 }
186 134
187 void MessageCenterView::SetNotifications( 135 void MessageCenterView::SetNotifications(
188 const NotificationList::Notifications& notifications) { 136 const NotificationList::Notifications& notifications) {
189 if (is_closing_) 137 if (is_closing_)
190 return; 138 return;
191 139
192 notification_views_.clear(); 140 notification_views_.clear();
193 141
194 int index = 0; 142 int index = 0;
195 for (NotificationList::Notifications::const_iterator iter = 143 for (NotificationList::Notifications::const_iterator iter =
196 notifications.begin(); iter != notifications.end(); ++iter) { 144 notifications.begin(); iter != notifications.end(); ++iter) {
197 AddNotificationAt(*(*iter), index++); 145 AddNotificationAt(*(*iter), index++);
198 146
199 message_center_->DisplayedNotification( 147 message_center_->DisplayedNotification(
200 (*iter)->id(), message_center::DISPLAY_SOURCE_MESSAGE_CENTER); 148 (*iter)->id(), message_center::DISPLAY_SOURCE_MESSAGE_CENTER);
201 if (notification_views_.size() >= kMaxVisibleMessageCenterNotifications) 149 if (notification_views_.size() >= kMaxVisibleMessageCenterNotifications)
202 break; 150 break;
203 } 151 }
204 152
205 NotificationsChanged(); 153 Update(false /* animate */);
206 scroller_->RequestFocus(); 154 scroller_->RequestFocus();
207 } 155 }
208 156
209 void MessageCenterView::SetSettingsVisible(bool visible) { 157 void MessageCenterView::SetSettingsVisible(bool visible) {
210 if (is_closing_)
211 return;
212
213 if (visible == settings_visible_)
214 return;
215
216 settings_visible_ = visible; 158 settings_visible_ = visible;
217 159 Update(true /* animate */);
218 if (visible) {
219 source_view_ = scroller_;
220 target_view_ = settings_view_;
221 } else {
222 source_view_ = settings_view_;
223 target_view_ = scroller_;
224 }
225 source_height_ = source_view_->GetHeightForWidth(width());
226 target_height_ = target_view_->GetHeightForWidth(width());
227
228 gfx::MultiAnimation::Parts parts;
229 // First part: slide resize animation.
230 parts.push_back(gfx::MultiAnimation::Part(
231 (source_height_ == target_height_) ? 0 : kDefaultAnimationDurationMs,
232 gfx::Tween::EASE_OUT));
233 // Second part: fade-out the source_view.
234 if (source_view_->layer()) {
235 parts.push_back(gfx::MultiAnimation::Part(
236 kDefaultAnimationDurationMs, gfx::Tween::LINEAR));
237 } else {
238 parts.push_back(gfx::MultiAnimation::Part());
239 }
240 // Third part: fade-in the target_view.
241 if (target_view_->layer()) {
242 parts.push_back(gfx::MultiAnimation::Part(
243 kDefaultAnimationDurationMs, gfx::Tween::LINEAR));
244 target_view_->layer()->SetOpacity(0);
245 target_view_->SetVisible(true);
246 } else {
247 parts.push_back(gfx::MultiAnimation::Part());
248 }
249 settings_transition_animation_.reset(new gfx::MultiAnimation(
250 parts, base::TimeDelta::FromMicroseconds(1000000 / kDefaultFrameRateHz)));
251 settings_transition_animation_->set_delegate(this);
252 settings_transition_animation_->set_continuous(false);
253 settings_transition_animation_->Start();
254
255 button_bar_->SetBackArrowVisible(visible);
256 } 160 }
257 161
258 void MessageCenterView::ClearAllClosableNotifications() { 162 void MessageCenterView::ClearAllClosableNotifications() {
259 if (is_closing_) 163 if (is_closing_)
260 return; 164 return;
261 165
166 is_clearing_ = true;
167 UpdateButtonsStatus();
262 SetViewHierarchyEnabled(scroller_, false); 168 SetViewHierarchyEnabled(scroller_, false);
263 button_bar_->SetAllButtonsEnabled(false);
264 message_list_view_->ClearAllClosableNotifications( 169 message_list_view_->ClearAllClosableNotifications(
265 scroller_->GetVisibleRect()); 170 scroller_->GetVisibleRect());
266 } 171 }
267 172
268 void MessageCenterView::OnAllNotificationsCleared() { 173 void MessageCenterView::OnAllNotificationsCleared() {
174 is_clearing_ = false;
269 SetViewHierarchyEnabled(scroller_, true); 175 SetViewHierarchyEnabled(scroller_, true);
270 button_bar_->SetAllButtonsEnabled(true);
271 button_bar_->SetCloseAllButtonEnabled(false); 176 button_bar_->SetCloseAllButtonEnabled(false);
272 177
178 // The status of buttons will be updated after removing all notifications.
179
273 // Action by user. 180 // Action by user.
274 message_center_->RemoveAllNotifications( 181 message_center_->RemoveAllNotifications(
275 true /* by_user */, 182 true /* by_user */,
276 message_center::MessageCenter::RemoveType::NON_PINNED); 183 message_center::MessageCenter::RemoveType::NON_PINNED);
277 } 184 }
278 185
279 size_t MessageCenterView::NumMessageViewsForTest() const { 186 size_t MessageCenterView::NumMessageViewsForTest() const {
280 return message_list_view_->child_count(); 187 return message_list_view_->child_count();
281 } 188 }
282 189
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 width(), 223 width(),
317 height() - button_height); 224 height() - button_height);
318 settings_view_->SetBounds(0, 225 settings_view_->SetBounds(0,
319 top_down_ ? button_height : 0, 226 top_down_ ? button_height : 0,
320 width(), 227 width(),
321 height() - button_height); 228 height() - button_height);
322 229
323 bool is_scrollable = false; 230 bool is_scrollable = false;
324 if (scroller_->visible()) 231 if (scroller_->visible())
325 is_scrollable = scroller_->height() < message_list_view_->height(); 232 is_scrollable = scroller_->height() < message_list_view_->height();
326 else 233 else if (settings_view_->visible())
327 is_scrollable = settings_view_->IsScrollable(); 234 is_scrollable = settings_view_->IsScrollable();
328 235
329 if (!animating) { 236 if (!animating) {
330 if (is_scrollable) { 237 if (is_scrollable) {
331 // Draw separator line on the top of the button bar if it is on the bottom 238 // Draw separator line on the top of the button bar if it is on the bottom
332 // or draw it at the bottom if the bar is on the top. 239 // or draw it at the bottom if the bar is on the top.
333 button_bar_->SetBorder(views::Border::CreateSolidSidedBorder( 240 button_bar_->SetBorder(views::Border::CreateSolidSidedBorder(
334 top_down_ ? 0 : 1, 0, top_down_ ? 1 : 0, 0, kFooterDelimiterColor)); 241 top_down_ ? 0 : 1, 0, top_down_ ? 1 : 0, 0, kFooterDelimiterColor));
335 } else { 242 } else {
336 button_bar_->SetBorder(views::Border::CreateEmptyBorder( 243 button_bar_->SetBorder(views::Border::CreateEmptyBorder(
337 top_down_ ? 0 : 1, 0, top_down_ ? 1 : 0, 0)); 244 top_down_ ? 0 : 1, 0, top_down_ ? 1 : 0, 0));
338 } 245 }
339 button_bar_->SchedulePaint(); 246 button_bar_->SchedulePaint();
340 } 247 }
341 button_bar_->SetBounds(0, 248 button_bar_->SetBounds(0,
342 top_down_ ? 0 : height() - button_height, 249 top_down_ ? 0 : height() - button_height,
343 width(), 250 width(),
344 button_height); 251 button_height);
345 if (GetWidget()) 252 if (GetWidget())
346 GetWidget()->GetRootView()->SchedulePaint(); 253 GetWidget()->GetRootView()->SchedulePaint();
347 } 254 }
348 255
349 gfx::Size MessageCenterView::GetPreferredSize() const { 256 gfx::Size MessageCenterView::GetPreferredSize() const {
350 if (settings_transition_animation_ && 257 if (settings_transition_animation_ &&
351 settings_transition_animation_->is_animating()) { 258 settings_transition_animation_->is_animating()) {
352 int content_width = std::max(source_view_->GetPreferredSize().width(), 259 int content_width =
353 target_view_->GetPreferredSize().width()); 260 std::max(source_view_ ? source_view_->GetPreferredSize().width() : 0,
261 target_view_ ? target_view_->GetPreferredSize().width() : 0);
354 int width = std::max(content_width, 262 int width = std::max(content_width,
355 button_bar_->GetPreferredSize().width()); 263 button_bar_->GetPreferredSize().width());
356 return gfx::Size(width, GetHeightForWidth(width)); 264 return gfx::Size(width, GetHeightForWidth(width));
357 } 265 }
358 266
359 int width = 0; 267 int width = 0;
360 for (int i = 0; i < child_count(); ++i) { 268 for (int i = 0; i < child_count(); ++i) {
361 const views::View* child = child_at(0); 269 const views::View* child = child_at(0);
362 if (child->visible()) 270 if (child->visible())
363 width = std::max(width, child->GetPreferredSize().width()); 271 width = std::max(width, child->GetPreferredSize().width());
364 } 272 }
365 return gfx::Size(width, GetHeightForWidth(width)); 273 return gfx::Size(width, GetHeightForWidth(width));
366 } 274 }
367 275
368 int MessageCenterView::GetHeightForWidth(int width) const { 276 int MessageCenterView::GetHeightForWidth(int width) const {
277 views::Border* button_border = button_bar_->border();
369 if (settings_transition_animation_ && 278 if (settings_transition_animation_ &&
370 settings_transition_animation_->is_animating()) { 279 settings_transition_animation_->is_animating()) {
371 int content_height = target_height_; 280 int content_height = target_height_;
372 if (settings_transition_animation_->current_part_index() == 0) { 281 if (settings_transition_animation_->current_part_index() == 0) {
373 content_height = settings_transition_animation_->CurrentValueBetween( 282 content_height = settings_transition_animation_->CurrentValueBetween(
374 source_height_, target_height_); 283 source_height_, target_height_);
375 } 284 }
376 return button_bar_->GetHeightForWidth(width) + content_height; 285 return button_bar_->GetHeightForWidth(width) + content_height +
286 (button_border ? button_border->GetInsets().height() : 0);
yoshiki 2016/05/13 05:10:48 As you mentioned in comment in crrev.com/192611300
dewittj 2016/05/13 19:54:13 OK, just mention it in the CL comment.
yoshiki 2016/05/16 15:05:53 Done.
377 } 287 }
378 288
379 int content_height = 0; 289 int content_height = 0;
380 if (scroller_->visible()) 290 if (scroller_->visible())
381 content_height += scroller_->GetHeightForWidth(width); 291 content_height += scroller_->GetHeightForWidth(width);
382 else 292 else if (settings_view_->visible())
383 content_height += settings_view_->GetHeightForWidth(width); 293 content_height += settings_view_->GetHeightForWidth(width);
384 return button_bar_->GetHeightForWidth(width) + 294 return button_bar_->GetHeightForWidth(width) + content_height +
385 button_bar_->GetInsets().height() + content_height; 295 (button_border ? button_border->GetInsets().height() : 0);
386 } 296 }
387 297
388 bool MessageCenterView::OnMouseWheel(const ui::MouseWheelEvent& event) { 298 bool MessageCenterView::OnMouseWheel(const ui::MouseWheelEvent& event) {
389 // Do not rely on the default scroll event handler of ScrollView because 299 // Do not rely on the default scroll event handler of ScrollView because
390 // the scroll happens only when the focus is on the ScrollView. The 300 // the scroll happens only when the focus is on the ScrollView. The
391 // notification center will allow the scrolling even when the focus is on 301 // notification center will allow the scrolling even when the focus is on
392 // the buttons. 302 // the buttons.
393 if (scroller_->bounds().Contains(event.location())) 303 if (scroller_->bounds().Contains(event.location()))
394 return scroller_->OnMouseWheel(event); 304 return scroller_->OnMouseWheel(event);
395 return views::View::OnMouseWheel(event); 305 return views::View::OnMouseWheel(event);
396 } 306 }
397 307
398 void MessageCenterView::OnMouseExited(const ui::MouseEvent& event) { 308 void MessageCenterView::OnMouseExited(const ui::MouseEvent& event) {
399 if (is_closing_) 309 if (is_closing_)
400 return; 310 return;
401 311
402 message_list_view_->ResetRepositionSession(); 312 message_list_view_->ResetRepositionSession();
403 NotificationsChanged(); 313 Update(true /* animate */);
404 } 314 }
405 315
406 void MessageCenterView::OnNotificationAdded(const std::string& id) { 316 void MessageCenterView::OnNotificationAdded(const std::string& id) {
407 int index = 0; 317 int index = 0;
408 const NotificationList::Notifications& notifications = 318 const NotificationList::Notifications& notifications =
409 message_center_->GetVisibleNotifications(); 319 message_center_->GetVisibleNotifications();
410 for (NotificationList::Notifications::const_iterator iter = 320 for (NotificationList::Notifications::const_iterator iter =
411 notifications.begin(); iter != notifications.end(); 321 notifications.begin(); iter != notifications.end();
412 ++iter, ++index) { 322 ++iter, ++index) {
413 if ((*iter)->id() == id) { 323 if ((*iter)->id() == id) {
414 AddNotificationAt(*(*iter), index); 324 AddNotificationAt(*(*iter), index);
415 break; 325 break;
416 } 326 }
417 if (notification_views_.size() >= kMaxVisibleMessageCenterNotifications) 327 if (notification_views_.size() >= kMaxVisibleMessageCenterNotifications)
418 break; 328 break;
419 } 329 }
420 NotificationsChanged(); 330 Update(true /* animate */);
421 } 331 }
422 332
423 void MessageCenterView::OnNotificationRemoved(const std::string& id, 333 void MessageCenterView::OnNotificationRemoved(const std::string& id,
424 bool by_user) { 334 bool by_user) {
425 NotificationViewsMap::iterator view_iter = notification_views_.find(id); 335 NotificationViewsMap::iterator view_iter = notification_views_.find(id);
426 if (view_iter == notification_views_.end()) 336 if (view_iter == notification_views_.end())
427 return; 337 return;
428 NotificationView* view = view_iter->second; 338 NotificationView* view = view_iter->second;
429 int index = message_list_view_->GetIndexOf(view); 339 int index = message_list_view_->GetIndexOf(view);
430 DCHECK_LE(0, index); 340 DCHECK_LE(0, index);
(...skipping 16 matching lines...) Expand all
447 static_cast<MessageView*>( 357 static_cast<MessageView*>(
448 next_focused_view)->RequestFocusOnCloseButton(); 358 next_focused_view)->RequestFocusOnCloseButton();
449 } else { 359 } else {
450 next_focused_view->RequestFocus(); 360 next_focused_view->RequestFocus();
451 } 361 }
452 } 362 }
453 } 363 }
454 } 364 }
455 message_list_view_->RemoveNotification(view); 365 message_list_view_->RemoveNotification(view);
456 notification_views_.erase(view_iter); 366 notification_views_.erase(view_iter);
457 NotificationsChanged(); 367 Update(true /* animate */);
458 } 368 }
459 369
460 void MessageCenterView::OnNotificationUpdated(const std::string& id) { 370 void MessageCenterView::OnNotificationUpdated(const std::string& id) {
461 NotificationViewsMap::const_iterator view_iter = notification_views_.find(id); 371 NotificationViewsMap::const_iterator view_iter = notification_views_.find(id);
462 if (view_iter == notification_views_.end()) 372 if (view_iter == notification_views_.end())
463 return; 373 return;
464 374
465 // Set the item on the mouse cursor as the reposition target so that it 375 // Set the item on the mouse cursor as the reposition target so that it
466 // should stick to the current position over the update. 376 // should stick to the current position over the update.
467 bool set = false; 377 bool set = false;
(...skipping 14 matching lines...) Expand all
482 NotificationView* view = view_iter->second; 392 NotificationView* view = view_iter->second;
483 const NotificationList::Notifications& notifications = 393 const NotificationList::Notifications& notifications =
484 message_center_->GetVisibleNotifications(); 394 message_center_->GetVisibleNotifications();
485 for (NotificationList::Notifications::const_iterator iter = 395 for (NotificationList::Notifications::const_iterator iter =
486 notifications.begin(); iter != notifications.end(); ++iter) { 396 notifications.begin(); iter != notifications.end(); ++iter) {
487 if ((*iter)->id() == id) { 397 if ((*iter)->id() == id) {
488 int old_width = view->width(); 398 int old_width = view->width();
489 int old_height = view->GetHeightForWidth(old_width); 399 int old_height = view->GetHeightForWidth(old_width);
490 message_list_view_->UpdateNotification(view, **iter); 400 message_list_view_->UpdateNotification(view, **iter);
491 if (view->GetHeightForWidth(old_width) != old_height) 401 if (view->GetHeightForWidth(old_width) != old_height)
492 NotificationsChanged(); 402 Update(true /* animate */);
493 break; 403 break;
494 } 404 }
495 } 405 }
496 } 406 }
497 407
498 void MessageCenterView::ClickOnNotification( 408 void MessageCenterView::ClickOnNotification(
499 const std::string& notification_id) { 409 const std::string& notification_id) {
500 message_center_->ClickOnNotification(notification_id); 410 message_center_->ClickOnNotification(notification_id);
501 } 411 }
502 412
(...skipping 19 matching lines...) Expand all
522 } 432 }
523 433
524 void MessageCenterView::ClickOnSettingsButton( 434 void MessageCenterView::ClickOnSettingsButton(
525 const std::string& notification_id) { 435 const std::string& notification_id) {
526 message_center_->ClickOnSettingsButton(notification_id); 436 message_center_->ClickOnSettingsButton(notification_id);
527 } 437 }
528 438
529 void MessageCenterView::AnimationEnded(const gfx::Animation* animation) { 439 void MessageCenterView::AnimationEnded(const gfx::Animation* animation) {
530 DCHECK_EQ(animation, settings_transition_animation_.get()); 440 DCHECK_EQ(animation, settings_transition_animation_.get());
531 441
532 Visibility visibility = target_view_ == settings_view_ 442 Visibility visibility =
533 ? VISIBILITY_SETTINGS 443 mode_ == Mode::SETTINGS ? VISIBILITY_SETTINGS : VISIBILITY_MESSAGE_CENTER;
534 : VISIBILITY_MESSAGE_CENTER;
535 message_center_->SetVisibility(visibility); 444 message_center_->SetVisibility(visibility);
536 445
537 source_view_->SetVisible(false); 446 if (source_view_) {
538 target_view_->SetVisible(true); 447 source_view_->SetVisible(false);
539 if (source_view_->layer()) 448 }
449 if (target_view_)
450 target_view_->SetVisible(true);
451 if (source_view_ && source_view_->layer())
540 source_view_->layer()->SetOpacity(1.0); 452 source_view_->layer()->SetOpacity(1.0);
541 if (target_view_->layer()) 453 if (target_view_ && target_view_->layer())
542 target_view_->layer()->SetOpacity(1.0); 454 target_view_->layer()->SetOpacity(1.0);
543 settings_transition_animation_.reset(); 455 settings_transition_animation_.reset();
544 PreferredSizeChanged(); 456 PreferredSizeChanged();
545 Layout(); 457 Layout();
546 } 458 }
547 459
548 void MessageCenterView::AnimationProgressed(const gfx::Animation* animation) { 460 void MessageCenterView::AnimationProgressed(const gfx::Animation* animation) {
549 DCHECK_EQ(animation, settings_transition_animation_.get()); 461 DCHECK_EQ(animation, settings_transition_animation_.get());
550 PreferredSizeChanged(); 462 PreferredSizeChanged();
551 if (settings_transition_animation_->current_part_index() == 1 && 463 if (settings_transition_animation_->current_part_index() == 1) {
552 source_view_->layer()) { 464 if (source_view_ && source_view_->layer()) {
553 source_view_->layer()->SetOpacity( 465 source_view_->layer()->SetOpacity(
554 1.0 - settings_transition_animation_->GetCurrentValue()); 466 1.0 - settings_transition_animation_->GetCurrentValue());
555 SchedulePaint(); 467 SchedulePaint();
556 } else if (settings_transition_animation_->current_part_index() == 2 && 468 }
557 target_view_->layer()) { 469 } else if (settings_transition_animation_->current_part_index() == 2) {
558 target_view_->layer()->SetOpacity( 470 if (target_view_ && target_view_->layer()) {
559 settings_transition_animation_->GetCurrentValue()); 471 target_view_->layer()->SetOpacity(
560 SchedulePaint(); 472 settings_transition_animation_->GetCurrentValue());
473 SchedulePaint();
474 }
561 } 475 }
562 } 476 }
563 477
564 void MessageCenterView::AnimationCanceled(const gfx::Animation* animation) { 478 void MessageCenterView::AnimationCanceled(const gfx::Animation* animation) {
565 DCHECK_EQ(animation, settings_transition_animation_.get()); 479 DCHECK_EQ(animation, settings_transition_animation_.get());
566 AnimationEnded(animation); 480 AnimationEnded(animation);
567 } 481 }
568 482
569 void MessageCenterView::AddNotificationAt(const Notification& notification, 483 void MessageCenterView::AddNotificationAt(const Notification& notification,
570 int index) { 484 int index) {
571 NotificationView* view = 485 NotificationView* view =
572 NotificationView::Create(this, notification, false); // Not top-level. 486 NotificationView::Create(this, notification, false); // Not top-level.
573 view->set_context_menu_controller(context_menu_controller_.get()); 487 view->set_context_menu_controller(context_menu_controller_.get());
574 notification_views_[notification.id()] = view; 488 notification_views_[notification.id()] = view;
575 view->set_scroller(scroller_); 489 view->set_scroller(scroller_);
576 message_list_view_->AddNotificationAt(view, index); 490 message_list_view_->AddNotificationAt(view, index);
577 } 491 }
578 492
579 void MessageCenterView::NotificationsChanged() { 493 void MessageCenterView::Update(bool animate) {
580 bool no_message_views = notification_views_.empty(); 494 bool no_message_views = notification_views_.empty();
581 495
582 // When the child view is removed from the hierarchy, its focus is cleared. 496 // When the child view is removed from the hierarchy, its focus is cleared.
583 // In this case we want to save which view has focus so that the user can 497 // In this case we want to save which view has focus so that the user can
584 // continue to interact with notifications in the order they were expecting. 498 // continue to interact with notifications in the order they were expecting.
585 views::FocusManager* focus_manager = scroller_->GetFocusManager(); 499 views::FocusManager* focus_manager = scroller_->GetFocusManager();
586 View* focused_view = NULL; 500 View* focused_view = NULL;
587 // |focus_manager| can be NULL in tests. 501 // |focus_manager| can be NULL in tests.
588 if (focus_manager) 502 if (focus_manager)
589 focused_view = focus_manager->GetFocusedView(); 503 focused_view = focus_manager->GetFocusedView();
590 504
591 // All the children of this view are owned by |this|. 505 if (settings_visible_)
592 scroller_->contents()->RemoveAllChildViews(/*delete_children=*/false); 506 SetVisibilityMode(Mode::SETTINGS, animate);
593 scroller_->contents()->AddChildView( 507 else if (no_message_views)
594 no_message_views ? empty_list_view_.get() : message_list_view_.get()); 508 SetVisibilityMode(Mode::BUTTONS_ONLY, animate);
595 509 else
596 bool no_closable_views = true; 510 SetVisibilityMode(Mode::NOTIFICATIONS, animate);
597 for (const auto& view : notification_views_) {
598 if (!view.second->IsPinned()) {
599 no_closable_views = false;
600 break;
601 }
602 }
603 button_bar_->SetCloseAllButtonEnabled(!no_closable_views);
604 511
605 if (no_message_views) { 512 if (no_message_views) {
606 scroller_->SetFocusBehavior(FocusBehavior::NEVER); 513 scroller_->SetFocusBehavior(FocusBehavior::NEVER);
607 } else { 514 } else {
608 #if defined(OS_MACOSX) 515 #if defined(OS_MACOSX)
609 scroller_->SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); 516 scroller_->SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY);
610 #else 517 #else
611 scroller_->SetFocusBehavior(FocusBehavior::ALWAYS); 518 scroller_->SetFocusBehavior(FocusBehavior::ALWAYS);
612 #endif 519 #endif
613 } 520 }
614 521
522 UpdateButtonsStatus();
523
615 if (focus_manager && focused_view) 524 if (focus_manager && focused_view)
616 focus_manager->SetFocusedView(focused_view); 525 focus_manager->SetFocusedView(focused_view);
617 526
618 scroller_->InvalidateLayout(); 527 if (scroller_->visible())
528 scroller_->InvalidateLayout();
619 PreferredSizeChanged(); 529 PreferredSizeChanged();
620 Layout(); 530 Layout();
621 } 531 }
622 532
533 void MessageCenterView::SetVisibilityMode(Mode mode, bool animate) {
534 if (is_closing_)
535 return;
536
537 if (mode == mode_)
538 return;
539
540 if (mode_ == Mode::NOTIFICATIONS)
541 source_view_ = scroller_;
542 else if (mode_ == Mode::SETTINGS)
543 source_view_ = settings_view_;
544 else
545 source_view_ = NULL;
546
547 if (mode == Mode::NOTIFICATIONS)
548 target_view_ = scroller_;
549 else if (mode == Mode::SETTINGS)
550 target_view_ = settings_view_;
551 else
552 target_view_ = NULL;
553
554 mode_ = mode;
555
556 source_height_ = source_view_ ? source_view_->GetHeightForWidth(width()) : 0;
557 target_height_ = target_view_ ? target_view_->GetHeightForWidth(width()) : 0;
558
559 button_bar_->SetBackArrowVisible(mode == Mode::SETTINGS);
560 if (!animate) {
561 AnimationEnded(NULL);
562 return;
563 }
564
565 gfx::MultiAnimation::Parts parts;
566 // First part: slide resize animation.
567 parts.push_back(gfx::MultiAnimation::Part(
568 (source_height_ == target_height_) ? 0 : kDefaultAnimationDurationMs,
569 gfx::Tween::EASE_OUT));
570 // Second part: fade-out the source_view.
571 if (source_view_ && source_view_->layer()) {
572 parts.push_back(gfx::MultiAnimation::Part(
573 kDefaultAnimationDurationMs, gfx::Tween::LINEAR));
574 } else {
575 parts.push_back(gfx::MultiAnimation::Part());
576 }
577 // Third part: fade-in the target_view.
578 if (target_view_ && target_view_->layer()) {
579 parts.push_back(gfx::MultiAnimation::Part(
580 kDefaultAnimationDurationMs, gfx::Tween::LINEAR));
581 target_view_->layer()->SetOpacity(0);
582 target_view_->SetVisible(true);
583 } else {
584 parts.push_back(gfx::MultiAnimation::Part());
585 }
586 settings_transition_animation_.reset(new gfx::MultiAnimation(
587 parts, base::TimeDelta::FromMicroseconds(1000000 / kDefaultFrameRateHz)));
588 settings_transition_animation_->set_delegate(this);
589 settings_transition_animation_->set_continuous(false);
590 settings_transition_animation_->Start();
591 }
592
593 void MessageCenterView::UpdateButtonsStatus() {
594 // Disables all buttons during animation of cleaning of all notifications.
595 if (is_clearing_) {
596 button_bar_->SetSettingsAndQuietModeButtonsEnabled(false);
597 button_bar_->SetCloseAllButtonEnabled(false);
598 return;
599 }
600
601 button_bar_->SetSettingsAndQuietModeButtonsEnabled(true);
602
603 if (mode_ == Mode::NOTIFICATIONS) {
604 bool no_closable_views = true;
605 for (const auto& view : notification_views_) {
606 if (!view.second->IsPinned()) {
607 no_closable_views = false;
608 break;
609 }
610 }
611 button_bar_->SetCloseAllButtonEnabled(!no_closable_views);
612 } else {
613 // Disable the close-all button since no notification is visible.
614 button_bar_->SetCloseAllButtonEnabled(false);
615 }
616 }
617
623 void MessageCenterView::SetNotificationViewForTest(MessageView* view) { 618 void MessageCenterView::SetNotificationViewForTest(MessageView* view) {
624 message_list_view_->AddNotificationAt(view, 0); 619 message_list_view_->AddNotificationAt(view, 0);
625 } 620 }
626 621
627 } // namespace message_center 622 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698