Commit e6ee7ea5 authored by Ahmed Mehfooz's avatar Ahmed Mehfooz Committed by Commit Bot

Add notification icons in the message center stacking bar

With this change each notification that is in the message center
but not visible will have an icon representing it in the stacking bar.
The icons are removed as we scroll up through the message center.
If there is not enough space to show all icons there will be a
"+ x" appended after the icons to signify remaining notifications.

Bug: 1002714
Change-Id: I2e7737a4cf0dd145e0868e7fbf11a15be897d51d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1803731
Commit-Queue: Ahmed Mehfooz <amehfooz@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarTim Song <tengs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#702203}
parent 0eb8a0a8
......@@ -753,6 +753,8 @@ component("ash") {
"system/message_center/notifier_settings_view.h",
"system/message_center/session_state_notification_blocker.cc",
"system/message_center/session_state_notification_blocker.h",
"system/message_center/stacked_notification_bar.cc",
"system/message_center/stacked_notification_bar.h",
"system/message_center/unified_message_center_bubble.cc",
"system/message_center/unified_message_center_bubble.h",
"system/message_center/unified_message_center_view.cc",
......
This diff is collapsed.
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_MESSAGE_CENTER_STACKED_NOTIFICATION_BAR_H_
#define ASH_SYSTEM_MESSAGE_CENTER_STACKED_NOTIFICATION_BAR_H_
#include "ash/ash_export.h"
#include "ash/system/message_center/message_center_scroll_bar.h"
#include "ash/system/message_center/unified_message_center_view.h"
#include "ash/system/message_center/unified_message_list_view.h"
#include "ui/gfx/animation/animation_delegate.h"
#include "ui/views/background.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/focus/focus_manager.h"
#include "ui/views/view.h"
namespace message_center {
class Notification;
} // namespace message_center
namespace ash {
// The header shown above the notification list displaying the number of hidden
// notifications. There are currently two UI implementations toggled by the
// NotificationStackedBarRedesign feature flag.
class StackedNotificationBar : public views::View {
public:
explicit StackedNotificationBar(views::ButtonListener* listener);
~StackedNotificationBar() override;
// Sets the icons and overflow count for hidden notifications as well as the
// total notifications count. Returns true if the state of the bar has
// changed.
bool Update(int total_notification_count,
std::vector<message_center::Notification*> stacked_notifications);
// Sets the current animation state.
void SetAnimationState(UnifiedMessageCenterAnimationState animation_state);
// views::View:
void OnPaint(gfx::Canvas* canvas) override;
const char* GetClassName() const override;
private:
friend class UnifiedMessageCenterViewTest;
// Set visibility based on number of stacked notifications or animation state.
void UpdateVisibility();
// Add a stacked notification icon to the front or back of the row.
void AddNotificationIcon(message_center::Notification* notification,
bool at_front);
// Move all icons left when notifications are scrolled up.
void ShiftIconsLeft(
std::vector<message_center::Notification*> stacked_notifications);
// Move icons right to make space for additional icons when notifications are
// scrolled down.
void ShiftIconsRight(
std::vector<message_center::Notification*> stacked_notifications);
// Update state for stacked notification icons and move them as necessary.
void UpdateStackedNotifications(
std::vector<message_center::Notification*> stacked_notifications);
int total_notification_count_ = 0;
int stacked_notification_count_ = 0;
UnifiedMessageCenterAnimationState animation_state_ =
UnifiedMessageCenterAnimationState::IDLE;
views::View* notification_icons_container_;
views::Label* const count_label_;
views::Button* const clear_all_button_;
DISALLOW_COPY_AND_ASSIGN(StackedNotificationBar);
};
} // namespace ash
#endif // ASH_SYSTEM_MESSAGE_CENTER_STACKED_NOTIFICATION_BAR_H_
......@@ -19,6 +19,10 @@ namespace gfx {
class LinearAnimation;
} // namespace gfx
namespace message_center {
class Notification;
} // namespace message_center
namespace views {
class ScrollView;
} // namespace views
......@@ -26,6 +30,7 @@ class ScrollView;
namespace ash {
class MessageCenterScrollBar;
class StackedNotificationBar;
class UnifiedMessageCenterBubble;
class UnifiedSystemTrayModel;
class UnifiedSystemTrayView;
......@@ -49,41 +54,6 @@ enum class UnifiedMessageCenterAnimationState {
COLLAPSE,
};
// The header shown above the notification list displaying the number of hidden
// notifications. There are currently two UI implementations toggled by the
// NotificationStackingBarRedesign feature flag.
class StackingNotificationCounterView : public views::View {
public:
explicit StackingNotificationCounterView(views::ButtonListener* listener);
~StackingNotificationCounterView() override;
// Sets the number of total notifications and hidden notifications. Returns
// true if the count was updated from the previous SetCount() call.
bool SetCount(int total_notification_count, int stacked_notification_count);
// Sets the current animation state.
void SetAnimationState(UnifiedMessageCenterAnimationState animation_state);
// views::View:
void OnPaint(gfx::Canvas* canvas) override;
const char* GetClassName() const override;
private:
friend class UnifiedMessageCenterViewTest;
void UpdateVisibility();
int total_notification_count_ = 0;
int stacked_notification_count_ = 0;
UnifiedMessageCenterAnimationState animation_state_ =
UnifiedMessageCenterAnimationState::IDLE;
views::Label* const count_label_;
views::Button* const clear_all_button_;
DISALLOW_COPY_AND_ASSIGN(StackingNotificationCounterView);
};
// Manages scrolling of notification list.
class ASH_EXPORT UnifiedMessageCenterView
: public views::View,
......@@ -119,7 +89,7 @@ class ASH_EXPORT UnifiedMessageCenterView
void ConfigureMessageView(message_center::MessageView* message_view);
// Count number of notifications that are above visible area.
int GetStackedNotificationCount() const;
std::vector<message_center::Notification*> GetStackedNotifications() const;
// Set the first child view to be focused when focus is acquired.
// This is the first visible child unless reverse is true, in which case
......@@ -186,7 +156,7 @@ class ASH_EXPORT UnifiedMessageCenterView
UnifiedSystemTrayView* const parent_;
UnifiedSystemTrayModel* const model_;
UnifiedMessageCenterBubble* const message_center_bubble_;
StackingNotificationCounterView* const stacking_counter_;
StackedNotificationBar* const notification_bar_;
MessageCenterScrollBar* const scroll_bar_;
views::ScrollView* const scroller_;
UnifiedMessageListView* const message_list_view_;
......
......@@ -10,6 +10,7 @@
#include "ash/shell.h"
#include "ash/system/message_center/ash_message_center_lock_screen_controller.h"
#include "ash/system/message_center/message_center_scroll_bar.h"
#include "ash/system/message_center/stacked_notification_bar.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/unified/unified_system_tray_controller.h"
#include "ash/system/unified/unified_system_tray_model.h"
......@@ -163,15 +164,15 @@ class UnifiedMessageCenterViewTest : public AshTestBase,
}
views::View* GetStackingCounter() {
return message_center_view()->stacking_counter_;
return message_center_view()->notification_bar_;
}
views::View* GetStackingCounterLabel() {
return message_center_view()->stacking_counter_->count_label_;
return message_center_view()->notification_bar_->count_label_;
}
views::View* GetStackingCounterClearAllButton() {
return message_center_view()->stacking_counter_->clear_all_button_;
return message_center_view()->notification_bar_->clear_all_button_;
}
message_center::MessageView* ToggleFocusToMessageView(size_t index,
......
......@@ -283,12 +283,19 @@ void UnifiedMessageListView::ClearAllWithAnimation() {
StartAnimation();
}
int UnifiedMessageListView::CountNotificationsAboveY(int y_offset) const {
const auto it = std::find_if(children().cbegin(), children().cend(),
[y_offset](const views::View* v) {
return v->bounds().bottom() > y_offset;
});
return std::distance(children().cbegin(), it);
std::vector<Notification*> UnifiedMessageListView::GetNotificationsAboveY(
int y_offset) const {
std::vector<Notification*> notifications;
for (views::View* view : children()) {
if (view->bounds().bottom() < y_offset) {
Notification* notification =
MessageCenter::Get()->FindVisibleNotificationById(
AsMVC(view)->GetNotificationId());
if (notification)
notifications.insert(notifications.begin(), notification);
}
}
return notifications;
}
int UnifiedMessageListView::GetTotalNotificationCount() const {
......@@ -486,8 +493,9 @@ MessageView* UnifiedMessageListView::CreateMessageView(
return view;
}
int UnifiedMessageListView::GetStackedNotificationCount() const {
return message_center_view_->GetStackedNotificationCount();
std::vector<message_center::Notification*>
UnifiedMessageListView::GetStackedNotifications() const {
return message_center_view_->GetStackedNotifications();
}
// static
......@@ -623,7 +631,7 @@ void UnifiedMessageListView::UpdateClearAllAnimation() {
view->set_is_removed();
if (state_ == State::CLEAR_ALL_STACKED) {
if (view && GetStackedNotificationCount() > 0) {
if (view && GetStackedNotifications().size() > 0) {
DeleteRemovedNotifications();
UpdateBounds();
start_height_ = ideal_height_;
......
......@@ -60,7 +60,8 @@ class ASH_EXPORT UnifiedMessageListView
// Count the number of notifications whose bottom position is above
// |y_offset|. O(n) where n is number of notifications.
int CountNotificationsAboveY(int y_offset) const;
std::vector<message_center::Notification*> GetNotificationsAboveY(
int y_offset) const;
// Returns the total number of notifications in the list.
int GetTotalNotificationCount() const;
......@@ -102,7 +103,8 @@ class ASH_EXPORT UnifiedMessageListView
const message_center::Notification& notification);
// Virtual for testing.
virtual int GetStackedNotificationCount() const;
virtual std::vector<message_center::Notification*> GetStackedNotifications()
const;
private:
friend class UnifiedMessageCenterViewTest;
......
......@@ -61,7 +61,18 @@ class TestUnifiedMessageListView : public UnifiedMessageListView {
~TestUnifiedMessageListView() override = default;
void set_stacked_notification_count(int stacked_notification_count) {
stacked_notification_count_ = stacked_notification_count;
stacked_notifications_.clear();
for (int i = 0; i < stacked_notification_count; i++) {
std::string id = base::NumberToString(0);
auto notification = std::make_unique<Notification>(
message_center::NOTIFICATION_TYPE_BASE_FORMAT, id,
base::UTF8ToUTF16("test title"), base::UTF8ToUTF16("test message"),
gfx::Image(), base::string16() /* display_source */, GURL(),
message_center::NotifierId(), message_center::RichNotificationData(),
new message_center::NotificationDelegate());
stacked_notifications_.push_back(notification.get());
}
}
// UnifiedMessageListView:
......@@ -72,12 +83,13 @@ class TestUnifiedMessageListView : public UnifiedMessageListView {
return view;
}
int GetStackedNotificationCount() const override {
return stacked_notification_count_;
std::vector<message_center::Notification*> GetStackedNotifications()
const override {
return stacked_notifications_;
}
private:
int stacked_notification_count_ = 0;
std::vector<message_center::Notification*> stacked_notifications_;
DISALLOW_COPY_AND_ASSIGN(TestUnifiedMessageListView);
};
......
......@@ -126,6 +126,12 @@ constexpr int kUnifiedSystemInfoHeight = 16;
constexpr int kUnifiedSystemInfoSpacing = 8;
constexpr gfx::Insets kUnifiedSystemInfoDateViewPadding(3);
// Constants used in StackedNotificationBar located on top of the message
// center.
constexpr gfx::Insets kStackedNotificationIconsContainerPadding(2, 0, 0, 6);
constexpr int kStackedNotificationBarMaxIcons = 5;
constexpr int kStackedNotificationIconSize = 15;
// Constants used in FeaturePodsView of UnifiedSystemTray.
constexpr gfx::Size kUnifiedFeaturePodIconSize(48, 48);
constexpr gfx::Size kUnifiedFeaturePodSize(112, 88);
......
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