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

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

Powered by Google App Engine
This is Rietveld 408576698