Chromium Code Reviews| Index: ui/message_center/views/message_center_view.cc |
| diff --git a/ui/message_center/views/message_center_view.cc b/ui/message_center/views/message_center_view.cc |
| index e40718629e8b2044b3ceef155c13ea5e7b04cb97..ed125dcfff0f83f99f84bea3f1e449d042bf7c6f 100644 |
| --- a/ui/message_center/views/message_center_view.cc |
| +++ b/ui/message_center/views/message_center_view.cc |
| @@ -43,11 +43,6 @@ namespace message_center { |
| namespace { |
| -const SkColor kNoNotificationsTextColor = SkColorSetRGB(0xb4, 0xb4, 0xb4); |
| -#if defined(OS_LINUX) && defined(OS_CHROMEOS) |
| -const SkColor kTransparentColor = SkColorSetARGB(0, 0, 0, 0); |
| -#endif |
| - |
| const int kDefaultAnimationDurationMs = 120; |
| const int kDefaultFrameRateHz = 60; |
| @@ -59,52 +54,6 @@ void SetViewHierarchyEnabled(views::View* view, bool enabled) { |
| } // namespace |
| -class NoNotificationMessageView : public views::View { |
| - public: |
| - NoNotificationMessageView(); |
| - ~NoNotificationMessageView() override; |
| - |
| - // Overridden from views::View. |
| - gfx::Size GetPreferredSize() const override; |
| - int GetHeightForWidth(int width) const override; |
| - void Layout() override; |
| - |
| - private: |
| - views::Label* label_; |
| - |
| - DISALLOW_COPY_AND_ASSIGN(NoNotificationMessageView); |
| -}; |
| - |
| -NoNotificationMessageView::NoNotificationMessageView() { |
| - label_ = new views::Label(l10n_util::GetStringUTF16( |
| - IDS_MESSAGE_CENTER_NO_MESSAGES)); |
| - label_->SetAutoColorReadabilityEnabled(false); |
| - label_->SetEnabledColor(kNoNotificationsTextColor); |
| - // Set transparent background to ensure that subpixel rendering |
| - // is disabled. See crbug.com/169056 |
| -#if defined(OS_LINUX) && defined(OS_CHROMEOS) |
| - label_->SetBackgroundColor(kTransparentColor); |
| -#endif |
| - AddChildView(label_); |
| -} |
| - |
| -NoNotificationMessageView::~NoNotificationMessageView() { |
| -} |
| - |
| -gfx::Size NoNotificationMessageView::GetPreferredSize() const { |
| - return gfx::Size(kMinScrollViewHeight, label_->GetPreferredSize().width()); |
| -} |
| - |
| -int NoNotificationMessageView::GetHeightForWidth(int width) const { |
| - return kMinScrollViewHeight; |
| -} |
| - |
| -void NoNotificationMessageView::Layout() { |
| - int text_height = label_->GetHeightForWidth(width()); |
| - int margin = (height() - text_height) / 2; |
| - label_->SetBounds(0, margin, width(), text_height); |
| -} |
| - |
| // MessageCenterView /////////////////////////////////////////////////////////// |
| MessageCenterView::MessageCenterView(MessageCenter* message_center, |
| @@ -125,6 +74,8 @@ MessageCenterView::MessageCenterView(MessageCenter* message_center, |
| target_view_(NULL), |
| target_height_(0), |
| is_closing_(false), |
| + mode_((!initially_settings_visible) ? Mode::BUTTONS_ONLY |
| + : Mode::SETTINGS), |
| context_menu_controller_(new MessageViewContextMenuController(this)) { |
| message_center_->AddObserver(this); |
| set_notify_enter_exit_on_child(true); |
| @@ -138,6 +89,7 @@ MessageCenterView::MessageCenterView(MessageCenter* message_center, |
| notifier_settings_provider, |
| initially_settings_visible, |
| title); |
| + button_bar_->SetCloseAllButtonEnabled(false); |
| const int button_height = button_bar_->GetPreferredSize().height(); |
| @@ -151,8 +103,6 @@ MessageCenterView::MessageCenterView(MessageCenter* message_center, |
| scroller_->layer()->SetFillsBoundsOpaquely(false); |
| scroller_->layer()->SetMasksToBounds(true); |
| - empty_list_view_.reset(new NoNotificationMessageView); |
| - empty_list_view_->set_owned_by_client(); |
| message_list_view_.reset(new MessageListView(this, top_down)); |
| message_list_view_->set_owned_by_client(); |
| @@ -164,15 +114,13 @@ MessageCenterView::MessageCenterView(MessageCenter* message_center, |
| // out. |
| views::View* scroller_contents = new views::View(); |
| scroller_contents->SetLayoutManager(new views::FillLayout()); |
| - scroller_contents->AddChildView(empty_list_view_.get()); |
| + scroller_contents->AddChildView(message_list_view_.get()); |
| scroller_->SetContents(scroller_contents); |
| settings_view_ = new NotifierSettingsView(notifier_settings_provider); |
| - if (initially_settings_visible) |
| - scroller_->SetVisible(false); |
| - else |
| - settings_view_->SetVisible(false); |
| + scroller_->SetVisible(false); // Because it has no notifications at first. |
| + settings_view_->SetVisible(mode_ == Mode::SETTINGS); |
| AddChildView(scroller_); |
| AddChildView(settings_view_); |
| @@ -202,74 +150,33 @@ void MessageCenterView::SetNotifications( |
| break; |
| } |
| - NotificationsChanged(); |
| + Update(false /* animate */); |
| scroller_->RequestFocus(); |
| } |
| void MessageCenterView::SetSettingsVisible(bool visible) { |
| - if (is_closing_) |
| - return; |
| - |
| - if (visible == settings_visible_) |
| - return; |
| - |
| settings_visible_ = visible; |
| - |
| - if (visible) { |
| - source_view_ = scroller_; |
| - target_view_ = settings_view_; |
| - } else { |
| - source_view_ = settings_view_; |
| - target_view_ = scroller_; |
| - } |
| - source_height_ = source_view_->GetHeightForWidth(width()); |
| - target_height_ = target_view_->GetHeightForWidth(width()); |
| - |
| - gfx::MultiAnimation::Parts parts; |
| - // First part: slide resize animation. |
| - parts.push_back(gfx::MultiAnimation::Part( |
| - (source_height_ == target_height_) ? 0 : kDefaultAnimationDurationMs, |
| - gfx::Tween::EASE_OUT)); |
| - // Second part: fade-out the source_view. |
| - if (source_view_->layer()) { |
| - parts.push_back(gfx::MultiAnimation::Part( |
| - kDefaultAnimationDurationMs, gfx::Tween::LINEAR)); |
| - } else { |
| - parts.push_back(gfx::MultiAnimation::Part()); |
| - } |
| - // Third part: fade-in the target_view. |
| - if (target_view_->layer()) { |
| - parts.push_back(gfx::MultiAnimation::Part( |
| - kDefaultAnimationDurationMs, gfx::Tween::LINEAR)); |
| - target_view_->layer()->SetOpacity(0); |
| - target_view_->SetVisible(true); |
| - } else { |
| - parts.push_back(gfx::MultiAnimation::Part()); |
| - } |
| - settings_transition_animation_.reset(new gfx::MultiAnimation( |
| - parts, base::TimeDelta::FromMicroseconds(1000000 / kDefaultFrameRateHz))); |
| - settings_transition_animation_->set_delegate(this); |
| - settings_transition_animation_->set_continuous(false); |
| - settings_transition_animation_->Start(); |
| - |
| - button_bar_->SetBackArrowVisible(visible); |
| + Update(true /* animate */); |
| } |
| void MessageCenterView::ClearAllClosableNotifications() { |
| if (is_closing_) |
| return; |
| + is_clearing_ = true; |
| + UpdateButtonsStatus(); |
| SetViewHierarchyEnabled(scroller_, false); |
| - button_bar_->SetAllButtonsEnabled(false); |
| message_list_view_->ClearAllClosableNotifications( |
| scroller_->GetVisibleRect()); |
| } |
| void MessageCenterView::OnAllNotificationsCleared() { |
| + is_clearing_ = false; |
| SetViewHierarchyEnabled(scroller_, true); |
| - button_bar_->SetAllButtonsEnabled(true); |
| button_bar_->SetCloseAllButtonEnabled(false); |
| + // The status of buttons will be updated after removing all notifications. |
| + |
| // Action by user. |
| message_center_->RemoveAllNotifications( |
| true /* by_user */, |
| @@ -323,7 +230,7 @@ void MessageCenterView::Layout() { |
| bool is_scrollable = false; |
| if (scroller_->visible()) |
| is_scrollable = scroller_->height() < message_list_view_->height(); |
| - else |
| + else if (settings_view_->visible()) |
| is_scrollable = settings_view_->IsScrollable(); |
| if (!animating) { |
| @@ -349,8 +256,9 @@ void MessageCenterView::Layout() { |
| gfx::Size MessageCenterView::GetPreferredSize() const { |
| if (settings_transition_animation_ && |
| settings_transition_animation_->is_animating()) { |
| - int content_width = std::max(source_view_->GetPreferredSize().width(), |
| - target_view_->GetPreferredSize().width()); |
| + int content_width = |
| + std::max(source_view_ ? source_view_->GetPreferredSize().width() : 0, |
| + target_view_ ? target_view_->GetPreferredSize().width() : 0); |
| int width = std::max(content_width, |
| button_bar_->GetPreferredSize().width()); |
| return gfx::Size(width, GetHeightForWidth(width)); |
| @@ -366,6 +274,7 @@ gfx::Size MessageCenterView::GetPreferredSize() const { |
| } |
| int MessageCenterView::GetHeightForWidth(int width) const { |
| + views::Border* button_border = button_bar_->border(); |
| if (settings_transition_animation_ && |
| settings_transition_animation_->is_animating()) { |
| int content_height = target_height_; |
| @@ -373,16 +282,17 @@ int MessageCenterView::GetHeightForWidth(int width) const { |
| content_height = settings_transition_animation_->CurrentValueBetween( |
| source_height_, target_height_); |
| } |
| - return button_bar_->GetHeightForWidth(width) + content_height; |
| + return button_bar_->GetHeightForWidth(width) + content_height + |
| + (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.
|
| } |
| int content_height = 0; |
| if (scroller_->visible()) |
| content_height += scroller_->GetHeightForWidth(width); |
| - else |
| + else if (settings_view_->visible()) |
| content_height += settings_view_->GetHeightForWidth(width); |
| - return button_bar_->GetHeightForWidth(width) + |
| - button_bar_->GetInsets().height() + content_height; |
| + return button_bar_->GetHeightForWidth(width) + content_height + |
| + (button_border ? button_border->GetInsets().height() : 0); |
| } |
| bool MessageCenterView::OnMouseWheel(const ui::MouseWheelEvent& event) { |
| @@ -400,7 +310,7 @@ void MessageCenterView::OnMouseExited(const ui::MouseEvent& event) { |
| return; |
| message_list_view_->ResetRepositionSession(); |
| - NotificationsChanged(); |
| + Update(true /* animate */); |
| } |
| void MessageCenterView::OnNotificationAdded(const std::string& id) { |
| @@ -417,7 +327,7 @@ void MessageCenterView::OnNotificationAdded(const std::string& id) { |
| if (notification_views_.size() >= kMaxVisibleMessageCenterNotifications) |
| break; |
| } |
| - NotificationsChanged(); |
| + Update(true /* animate */); |
| } |
| void MessageCenterView::OnNotificationRemoved(const std::string& id, |
| @@ -454,7 +364,7 @@ void MessageCenterView::OnNotificationRemoved(const std::string& id, |
| } |
| message_list_view_->RemoveNotification(view); |
| notification_views_.erase(view_iter); |
| - NotificationsChanged(); |
| + Update(true /* animate */); |
| } |
| void MessageCenterView::OnNotificationUpdated(const std::string& id) { |
| @@ -489,7 +399,7 @@ void MessageCenterView::OnNotificationUpdated(const std::string& id) { |
| int old_height = view->GetHeightForWidth(old_width); |
| message_list_view_->UpdateNotification(view, **iter); |
| if (view->GetHeightForWidth(old_width) != old_height) |
| - NotificationsChanged(); |
| + Update(true /* animate */); |
| break; |
| } |
| } |
| @@ -529,16 +439,18 @@ void MessageCenterView::ClickOnSettingsButton( |
| void MessageCenterView::AnimationEnded(const gfx::Animation* animation) { |
| DCHECK_EQ(animation, settings_transition_animation_.get()); |
| - Visibility visibility = target_view_ == settings_view_ |
| - ? VISIBILITY_SETTINGS |
| - : VISIBILITY_MESSAGE_CENTER; |
| + Visibility visibility = |
| + mode_ == Mode::SETTINGS ? VISIBILITY_SETTINGS : VISIBILITY_MESSAGE_CENTER; |
| message_center_->SetVisibility(visibility); |
| - source_view_->SetVisible(false); |
| - target_view_->SetVisible(true); |
| - if (source_view_->layer()) |
| + if (source_view_) { |
| + source_view_->SetVisible(false); |
| + } |
| + if (target_view_) |
| + target_view_->SetVisible(true); |
| + if (source_view_ && source_view_->layer()) |
| source_view_->layer()->SetOpacity(1.0); |
| - if (target_view_->layer()) |
| + if (target_view_ && target_view_->layer()) |
| target_view_->layer()->SetOpacity(1.0); |
| settings_transition_animation_.reset(); |
| PreferredSizeChanged(); |
| @@ -548,16 +460,18 @@ void MessageCenterView::AnimationEnded(const gfx::Animation* animation) { |
| void MessageCenterView::AnimationProgressed(const gfx::Animation* animation) { |
| DCHECK_EQ(animation, settings_transition_animation_.get()); |
| PreferredSizeChanged(); |
| - if (settings_transition_animation_->current_part_index() == 1 && |
| - source_view_->layer()) { |
| - source_view_->layer()->SetOpacity( |
| - 1.0 - settings_transition_animation_->GetCurrentValue()); |
| - SchedulePaint(); |
| - } else if (settings_transition_animation_->current_part_index() == 2 && |
| - target_view_->layer()) { |
| - target_view_->layer()->SetOpacity( |
| - settings_transition_animation_->GetCurrentValue()); |
| - SchedulePaint(); |
| + if (settings_transition_animation_->current_part_index() == 1) { |
| + if (source_view_ && source_view_->layer()) { |
| + source_view_->layer()->SetOpacity( |
| + 1.0 - settings_transition_animation_->GetCurrentValue()); |
| + SchedulePaint(); |
| + } |
| + } else if (settings_transition_animation_->current_part_index() == 2) { |
| + if (target_view_ && target_view_->layer()) { |
| + target_view_->layer()->SetOpacity( |
| + settings_transition_animation_->GetCurrentValue()); |
| + SchedulePaint(); |
| + } |
| } |
| } |
| @@ -576,7 +490,7 @@ void MessageCenterView::AddNotificationAt(const Notification& notification, |
| message_list_view_->AddNotificationAt(view, index); |
| } |
| -void MessageCenterView::NotificationsChanged() { |
| +void MessageCenterView::Update(bool animate) { |
| bool no_message_views = notification_views_.empty(); |
| // When the child view is removed from the hierarchy, its focus is cleared. |
| @@ -588,19 +502,12 @@ void MessageCenterView::NotificationsChanged() { |
| if (focus_manager) |
| focused_view = focus_manager->GetFocusedView(); |
| - // All the children of this view are owned by |this|. |
| - scroller_->contents()->RemoveAllChildViews(/*delete_children=*/false); |
| - scroller_->contents()->AddChildView( |
| - no_message_views ? empty_list_view_.get() : message_list_view_.get()); |
| - |
| - bool no_closable_views = true; |
| - for (const auto& view : notification_views_) { |
| - if (!view.second->IsPinned()) { |
| - no_closable_views = false; |
| - break; |
| - } |
| - } |
| - button_bar_->SetCloseAllButtonEnabled(!no_closable_views); |
| + if (settings_visible_) |
| + SetVisibilityMode(Mode::SETTINGS, animate); |
| + else if (no_message_views) |
| + SetVisibilityMode(Mode::BUTTONS_ONLY, animate); |
| + else |
| + SetVisibilityMode(Mode::NOTIFICATIONS, animate); |
| if (no_message_views) { |
| scroller_->SetFocusBehavior(FocusBehavior::NEVER); |
| @@ -612,14 +519,102 @@ void MessageCenterView::NotificationsChanged() { |
| #endif |
| } |
| + UpdateButtonsStatus(); |
| + |
| if (focus_manager && focused_view) |
| focus_manager->SetFocusedView(focused_view); |
| - scroller_->InvalidateLayout(); |
| + if (scroller_->visible()) |
| + scroller_->InvalidateLayout(); |
| PreferredSizeChanged(); |
| Layout(); |
| } |
| +void MessageCenterView::SetVisibilityMode(Mode mode, bool animate) { |
| + if (is_closing_) |
| + return; |
| + |
| + if (mode == mode_) |
| + return; |
| + |
| + if (mode_ == Mode::NOTIFICATIONS) |
| + source_view_ = scroller_; |
| + else if (mode_ == Mode::SETTINGS) |
| + source_view_ = settings_view_; |
| + else |
| + source_view_ = NULL; |
| + |
| + if (mode == Mode::NOTIFICATIONS) |
| + target_view_ = scroller_; |
| + else if (mode == Mode::SETTINGS) |
| + target_view_ = settings_view_; |
| + else |
| + target_view_ = NULL; |
| + |
| + mode_ = mode; |
| + |
| + source_height_ = source_view_ ? source_view_->GetHeightForWidth(width()) : 0; |
| + target_height_ = target_view_ ? target_view_->GetHeightForWidth(width()) : 0; |
| + |
| + button_bar_->SetBackArrowVisible(mode == Mode::SETTINGS); |
| + if (!animate) { |
| + AnimationEnded(NULL); |
| + return; |
| + } |
| + |
| + gfx::MultiAnimation::Parts parts; |
| + // First part: slide resize animation. |
| + parts.push_back(gfx::MultiAnimation::Part( |
| + (source_height_ == target_height_) ? 0 : kDefaultAnimationDurationMs, |
| + gfx::Tween::EASE_OUT)); |
| + // Second part: fade-out the source_view. |
| + if (source_view_ && source_view_->layer()) { |
| + parts.push_back(gfx::MultiAnimation::Part( |
| + kDefaultAnimationDurationMs, gfx::Tween::LINEAR)); |
| + } else { |
| + parts.push_back(gfx::MultiAnimation::Part()); |
| + } |
| + // Third part: fade-in the target_view. |
| + if (target_view_ && target_view_->layer()) { |
| + parts.push_back(gfx::MultiAnimation::Part( |
| + kDefaultAnimationDurationMs, gfx::Tween::LINEAR)); |
| + target_view_->layer()->SetOpacity(0); |
| + target_view_->SetVisible(true); |
| + } else { |
| + parts.push_back(gfx::MultiAnimation::Part()); |
| + } |
| + settings_transition_animation_.reset(new gfx::MultiAnimation( |
| + parts, base::TimeDelta::FromMicroseconds(1000000 / kDefaultFrameRateHz))); |
| + settings_transition_animation_->set_delegate(this); |
| + settings_transition_animation_->set_continuous(false); |
| + settings_transition_animation_->Start(); |
| +} |
| + |
| +void MessageCenterView::UpdateButtonsStatus() { |
| + // Disables all buttons during animation of cleaning of all notifications. |
| + if (is_clearing_) { |
| + button_bar_->SetSettingsAndQuietModeButtonsEnabled(false); |
| + button_bar_->SetCloseAllButtonEnabled(false); |
| + return; |
| + } |
| + |
| + button_bar_->SetSettingsAndQuietModeButtonsEnabled(true); |
| + |
| + if (mode_ == Mode::NOTIFICATIONS) { |
| + bool no_closable_views = true; |
| + for (const auto& view : notification_views_) { |
| + if (!view.second->IsPinned()) { |
| + no_closable_views = false; |
| + break; |
| + } |
| + } |
| + button_bar_->SetCloseAllButtonEnabled(!no_closable_views); |
| + } else { |
| + // Disable the close-all button since no notification is visible. |
| + button_bar_->SetCloseAllButtonEnabled(false); |
| + } |
| +} |
| + |
| void MessageCenterView::SetNotificationViewForTest(MessageView* view) { |
| message_list_view_->AddNotificationAt(view, 0); |
| } |