Commit 4497e01a authored by Tetsui Ohkubo's avatar Tetsui Ohkubo Committed by Commit Bot

Collapse older notification popups.

According to UX, in addition to expanding the latest notification,
older notification popups should be collapsed.

See the screencast:
- Without this CL:
  http://go/scrcast/NTY3OTAwNjEyOTA2MTg4OHxjMjY3MGMxMS0xNw
- With this CL: http://go/scrcast/NTY0MjAyMzc3NjI4ODc2OHxhYjBmNWQ4Yy02NA

TEST=NotificationViewMDTest.ExpandLongMessage
BUG=792582

Change-Id: Ie6693386acda5a47405350822a48b4b0a279029f
Reviewed-on: https://chromium-review.googlesource.com/830998Reviewed-by: default avatarYoshiki Iguchi <yoshiki@chromium.org>
Commit-Queue: Tetsui Ohkubo <tetsui@chromium.org>
Cr-Commit-Position: refs/heads/master@{#525034}
parent 65fe00d5
...@@ -127,6 +127,26 @@ void MessagePopupCollection::UpdateWidgets() { ...@@ -127,6 +127,26 @@ void MessagePopupCollection::UpdateWidgets() {
alignment_delegate_->IsPrimaryDisplayForNotification(); alignment_delegate_->IsPrimaryDisplayForNotification();
#endif #endif
// Check if the popups contain a new notification.
bool has_new_toasts = false;
for (auto* popup : popups) {
if (!FindToast(popup->id())) {
has_new_toasts = true;
break;
}
}
// If a new notification is found, collapse all existing notifications
// beforehand.
if (has_new_toasts) {
for (auto* toast : toasts_) {
if (toast->message_view()->IsMouseHovered() ||
toast->message_view()->manually_expanded_or_collapsed())
continue;
toast->message_view()->SetExpanded(false);
}
}
// Iterate in the reverse order to keep the oldest toasts on screen. Newer // Iterate in the reverse order to keep the oldest toasts on screen. Newer
// items may be ignored if there are no room to place them. // items may be ignored if there are no room to place them.
for (NotificationList::PopupNotifications::const_reverse_iterator iter = for (NotificationList::PopupNotifications::const_reverse_iterator iter =
......
...@@ -99,6 +99,10 @@ class MESSAGE_CENTER_EXPORT MessageView ...@@ -99,6 +99,10 @@ class MESSAGE_CENTER_EXPORT MessageView
void set_force_disable_pinned() { force_disable_pinned_ = true; } void set_force_disable_pinned() { force_disable_pinned_ = true; }
#endif #endif
bool manually_expanded_or_collapsed() const {
return manually_expanded_or_collapsed_;
}
protected: protected:
// Creates and add close button to view hierarchy when necessary. Derived // Creates and add close button to view hierarchy when necessary. Derived
// classes should call this after its view hierarchy is populated to ensure // classes should call this after its view hierarchy is populated to ensure
...@@ -112,6 +116,10 @@ class MESSAGE_CENTER_EXPORT MessageView ...@@ -112,6 +116,10 @@ class MESSAGE_CENTER_EXPORT MessageView
views::View* background_view() { return background_view_; } views::View* background_view() { return background_view_; }
views::ScrollView* scroller() { return scroller_; } views::ScrollView* scroller() { return scroller_; }
void set_manually_expanded_or_collapsed() {
manually_expanded_or_collapsed_ = true;
}
private: private:
std::string notification_id_; std::string notification_id_;
views::View* background_view_ = nullptr; // Owned by views hierarchy. views::View* background_view_ = nullptr; // Owned by views hierarchy.
...@@ -125,6 +133,10 @@ class MESSAGE_CENTER_EXPORT MessageView ...@@ -125,6 +133,10 @@ class MESSAGE_CENTER_EXPORT MessageView
// pinned regardless of the value of |pinned_|. // pinned regardless of the value of |pinned_|.
bool force_disable_pinned_ = false; bool force_disable_pinned_ = false;
// True if the notification is expanded/collapsed by user interaction.
// If true, MessagePopupCollection will not auto-collapse the notification.
bool manually_expanded_or_collapsed_ = false;
std::unique_ptr<views::Painter> focus_painter_; std::unique_ptr<views::Painter> focus_painter_;
views::SlideOutController slide_out_controller_; views::SlideOutController slide_out_controller_;
......
...@@ -655,6 +655,7 @@ void NotificationViewMD::ButtonPressed(views::Button* sender, ...@@ -655,6 +655,7 @@ void NotificationViewMD::ButtonPressed(views::Button* sender,
// |expand_button| can be focused by TAB. // |expand_button| can be focused by TAB.
if (sender == header_row_) { if (sender == header_row_) {
if (IsExpandable()) { if (IsExpandable()) {
set_manually_expanded_or_collapsed();
ToggleExpanded(); ToggleExpanded();
Layout(); Layout();
SchedulePaint(); SchedulePaint();
......
...@@ -637,6 +637,20 @@ TEST_F(NotificationViewMDTest, ExpandLongMessage) { ...@@ -637,6 +637,20 @@ TEST_F(NotificationViewMDTest, ExpandLongMessage) {
EXPECT_EQ(collapsed_height, notification_view()->message_view_->height()); EXPECT_EQ(collapsed_height, notification_view()->message_view_->height());
EXPECT_EQ(collapsed_preferred_height, EXPECT_EQ(collapsed_preferred_height,
notification_view()->GetPreferredSize().height()); notification_view()->GetPreferredSize().height());
// Test |manually_expanded_or_collapsed| being set when the toggle is done by
// user interaction.
EXPECT_FALSE(notification_view()->manually_expanded_or_collapsed());
// Construct a mouse click event 1 pixel inside the header.
gfx::Point done_cursor_location(1, 1);
views::View::ConvertPointToScreen(notification_view()->header_row_,
&done_cursor_location);
ui::test::EventGenerator generator(widget()->GetNativeWindow());
generator.MoveMouseTo(done_cursor_location);
generator.ClickLeftButton();
EXPECT_TRUE(notification_view()->manually_expanded_or_collapsed());
} }
TEST_F(NotificationViewMDTest, TestAccentColor) { TEST_F(NotificationViewMDTest, TestAccentColor) {
......
...@@ -83,6 +83,7 @@ ToastContentsView::~ToastContentsView() { ...@@ -83,6 +83,7 @@ ToastContentsView::~ToastContentsView() {
void ToastContentsView::SetContents(MessageView* view, void ToastContentsView::SetContents(MessageView* view,
bool a11y_feedback_for_updates) { bool a11y_feedback_for_updates) {
message_view_ = view;
bool already_has_contents = child_count() > 0; bool already_has_contents = child_count() > 0;
RemoveAllChildViews(true); RemoveAllChildViews(true);
AddChildView(view); AddChildView(view);
......
...@@ -80,6 +80,8 @@ class MESSAGE_CENTER_EXPORT ToastContentsView ...@@ -80,6 +80,8 @@ class MESSAGE_CENTER_EXPORT ToastContentsView
const std::string& id() const { return id_; } const std::string& id() const { return id_; }
MessageView* message_view() { return message_view_; }
// Overridden from views::View: // Overridden from views::View:
void OnMouseEntered(const ui::MouseEvent& event) override; void OnMouseEntered(const ui::MouseEvent& event) override;
void OnMouseExited(const ui::MouseEvent& event) override; void OnMouseExited(const ui::MouseEvent& event) override;
...@@ -141,6 +143,9 @@ class MESSAGE_CENTER_EXPORT ToastContentsView ...@@ -141,6 +143,9 @@ class MESSAGE_CENTER_EXPORT ToastContentsView
gfx::Point origin_; gfx::Point origin_;
gfx::Size preferred_size_; gfx::Size preferred_size_;
// Weak reference to the MessageView.
MessageView* message_view_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(ToastContentsView); DISALLOW_COPY_AND_ASSIGN(ToastContentsView);
}; };
......
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