Commit 9fa04fb8 authored by Tetsui Ohkubo's avatar Tetsui Ohkubo Committed by Commit Bot

Unified: keep notification position on collapse

According to UX spec, UnifiedSystemTray should keep the position of the
notification list from the bottom of the notification. Notifications
should be pushed up when UST is expanded, and the notification right
under the expand button should be the same one.

TEST=manual
BUG=856060

Change-Id: I0393dadca02a2e1d633a5a7e3fa165b7c4e3ba82
Reviewed-on: https://chromium-review.googlesource.com/1164807
Commit-Queue: Tetsui Ohkubo <tetsui@chromium.org>
Reviewed-by: default avatarYoshiki Iguchi <yoshiki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#581172}
parent fe8ec7a6
......@@ -6,7 +6,6 @@
#include "ash/message_center/message_center_scroll_bar.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/unified/sign_out_button.h"
#include "ash/system/unified/unified_system_tray_controller.h"
#include "ash/system/unified/unified_system_tray_view.h"
......@@ -101,6 +100,8 @@ void UnifiedMessageCenterView::Init() {
focus_manager_ = GetFocusManager();
if (focus_manager_)
focus_manager_->AddFocusChangeListener(this);
ScrollToPositionFromBottom();
NotifyHeightBelowScroll();
}
void UnifiedMessageCenterView::SetMaxHeight(int max_height) {
......@@ -132,8 +133,8 @@ void UnifiedMessageCenterView::SetNotifications(
void UnifiedMessageCenterView::Layout() {
scroller_->SetBounds(0, 0, width(), height());
ScrollToBottom();
OnMessageCenterScrolled();
ScrollToPositionFromBottom();
NotifyHeightBelowScroll();
}
gfx::Size UnifiedMessageCenterView::CalculatePreferredSize() const {
......@@ -158,7 +159,6 @@ void UnifiedMessageCenterView::OnNotificationAdded(const std::string& id) {
}
}
Update();
ScrollToBottom();
}
void UnifiedMessageCenterView::OnNotificationRemoved(const std::string& id,
......@@ -217,6 +217,15 @@ void UnifiedMessageCenterView::OnAllNotificationsCleared() {
}
void UnifiedMessageCenterView::OnMessageCenterScrolled() {
// Notification list is scrolled manually e.g. by mouse or gesture.
auto* scroll_bar = scroller_->vertical_scroll_bar();
// Save the distance from the bottom when manually scrolled.
position_from_bottom_ =
scroll_bar->GetMaxPosition() - scroller_->GetVisibleRect().y();
NotifyHeightBelowScroll();
}
void UnifiedMessageCenterView::NotifyHeightBelowScroll() {
parent_->SetNotificationHeightBelowScroll(
message_list_view_->GetHeightBelowVisibleRect());
}
......@@ -239,8 +248,9 @@ void UnifiedMessageCenterView::Update() {
}
scroller_->Layout();
PreferredSizeChanged();
OnMessageCenterScrolled();
NotifyHeightBelowScroll();
}
void UnifiedMessageCenterView::AddNotificationAt(
......@@ -272,14 +282,11 @@ void UnifiedMessageCenterView::UpdateNotification(const std::string& id) {
}
}
void UnifiedMessageCenterView::ScrollToBottom() {
// Hide Clear All button at the buttom from initial viewport.
int max_position_without_button =
scroller_->vertical_scroll_bar()->GetMaxPosition() -
3 * kUnifiedNotificationCenterSpacing;
void UnifiedMessageCenterView::ScrollToPositionFromBottom() {
scroller_->ScrollToPosition(
const_cast<views::ScrollBar*>(scroller_->vertical_scroll_bar()),
max_position_without_button);
std::max(0, scroller_->vertical_scroll_bar()->GetMaxPosition() -
position_from_bottom_));
}
} // namespace ash
......@@ -10,6 +10,7 @@
#include "ash/ash_export.h"
#include "ash/message_center/message_center_scroll_bar.h"
#include "ash/message_center/message_list_view.h"
#include "ash/system/tray/tray_constants.h"
#include "base/macros.h"
#include "ui/message_center/message_center_observer.h"
#include "ui/message_center/notification_list.h"
......@@ -90,14 +91,18 @@ class ASH_EXPORT UnifiedMessageCenterView
// MessageCenterScrollBar::Observer:
void OnMessageCenterScrolled() override;
// Notify the height below scroll to UnifiedSystemTrayView in order to imitate
// notification list scrolling under SystemTray.
void NotifyHeightBelowScroll();
private:
void Update();
void AddNotificationAt(const message_center::Notification& notification,
int index);
void UpdateNotification(const std::string& notification_id);
// Scroll the notification list to the bottom.
void ScrollToBottom();
// Scroll the notification list to |position_from_bottom_|.
void ScrollToPositionFromBottom();
UnifiedSystemTrayController* const tray_controller_;
UnifiedSystemTrayView* const parent_;
......@@ -106,6 +111,10 @@ class ASH_EXPORT UnifiedMessageCenterView
views::ScrollView* const scroller_;
MessageListView* const message_list_view_;
// Position from the bottom of scroll contents in dip. Hide Clear All button
// at the buttom from initial viewport.
int position_from_bottom_ = 3 * kUnifiedNotificationCenterSpacing;
views::FocusManager* focus_manager_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(UnifiedMessageCenterView);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment