Commit 4a279808 authored by Tetsui Ohkubo's avatar Tetsui Ohkubo Committed by Commit Bot

NewMessageListView: Paint corners behind tray.

This CL implements TopCornerBorder hack for NewMessageListView. For the
detail of the hack, please refer https://crrev.com/c/1161710 .

NewUnifiedMessageCenterView will replace UnifiedMessageCenterView.
It's behind a flag: --enable-features=NewMessageListView

TEST=NewUnifiedMessageCenterViewTest
BUG=769219

Change-Id: I24ad795fe118c21ef40be6b4ecc2f8e4a5f85101
Reviewed-on: https://chromium-review.googlesource.com/c/1278068
Commit-Queue: Tetsui Ohkubo <tetsui@chromium.org>
Reviewed-by: default avatarYoshiki Iguchi <yoshiki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#599822}
parent 0cecb6ce
......@@ -12,7 +12,7 @@
#include "ash/system/message_center/unified_message_list_view.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"
#include "base/metrics/user_metrics.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/message_center/message_center.h"
......@@ -68,8 +68,10 @@ class ScrollerContentsView : public views::View {
} // namespace
NewUnifiedMessageCenterView::NewUnifiedMessageCenterView()
: stacking_counter_(new StackingNotificationCounterView()),
NewUnifiedMessageCenterView::NewUnifiedMessageCenterView(
UnifiedSystemTrayView* parent)
: parent_(parent),
stacking_counter_(new StackingNotificationCounterView()),
scroll_bar_(new MessageCenterScrollBar(this)),
scroller_(new views::ScrollView()),
message_list_view_(new UnifiedMessageListView(this)),
......@@ -89,7 +91,9 @@ NewUnifiedMessageCenterView::NewUnifiedMessageCenterView()
UpdateVisibility();
}
NewUnifiedMessageCenterView::~NewUnifiedMessageCenterView() = default;
NewUnifiedMessageCenterView::~NewUnifiedMessageCenterView() {
RemovedFromWidget();
}
void NewUnifiedMessageCenterView::SetMaxHeight(int max_height) {
scroller_->ClipHeightTo(0, max_height);
......@@ -110,6 +114,19 @@ void NewUnifiedMessageCenterView::ConfigureMessageView(
message_view->set_scroller(scroller_);
}
void NewUnifiedMessageCenterView::AddedToWidget() {
focus_manager_ = GetFocusManager();
if (focus_manager_)
focus_manager_->AddFocusChangeListener(this);
}
void NewUnifiedMessageCenterView::RemovedFromWidget() {
if (!focus_manager_)
return;
focus_manager_->RemoveFocusChangeListener(this);
focus_manager_ = nullptr;
}
void NewUnifiedMessageCenterView::Layout() {
stacking_counter_->SetCount(GetStackedNotificationCount());
if (stacking_counter_->visible()) {
......@@ -126,6 +143,7 @@ void NewUnifiedMessageCenterView::Layout() {
}
ScrollToPositionFromBottom();
NotifyHeightBelowScroll();
}
gfx::Size NewUnifiedMessageCenterView::CalculatePreferredSize() const {
......@@ -148,6 +166,8 @@ void NewUnifiedMessageCenterView::OnMessageCenterScrolled() {
// on-screen position of notification list does not change.
scroll_bar_->ScrollByContentsOffset(previous_y - scroller_->y());
}
NotifyHeightBelowScroll();
}
void NewUnifiedMessageCenterView::ButtonPressed(views::Button* sender,
......@@ -160,6 +180,19 @@ void NewUnifiedMessageCenterView::ButtonPressed(views::Button* sender,
message_center::MessageCenter::RemoveType::NON_PINNED);
}
void NewUnifiedMessageCenterView::OnWillChangeFocus(views::View* before,
views::View* now) {}
void NewUnifiedMessageCenterView::OnDidChangeFocus(views::View* before,
views::View* now) {
OnMessageCenterScrolled();
}
void NewUnifiedMessageCenterView::SetNotificationHeightBelowScroll(
int height_below_scroll) {
parent_->SetNotificationHeightBelowScroll(height_below_scroll);
}
void NewUnifiedMessageCenterView::UpdateVisibility() {
SessionController* session_controller = Shell::Get()->session_controller();
SetVisible(message_list_view_->child_count() > 0 &&
......@@ -203,4 +236,9 @@ int NewUnifiedMessageCenterView::GetStackedNotificationCount() const {
return message_list_view_->CountNotificationsAboveY(y_offset);
}
void NewUnifiedMessageCenterView::NotifyHeightBelowScroll() {
SetNotificationHeightBelowScroll(std::max(
0, message_list_view_->height() - scroller_->GetVisibleRect().bottom()));
}
} // namespace ash
......@@ -20,15 +20,17 @@ namespace ash {
class MessageCenterScrollBar;
class StackingNotificationCounterView;
class UnifiedSystemTrayView;
// Manages scrolling of notification list.
// TODO(tetsui): Rename to UnifiedMessageCenterView after old code is removed.
class ASH_EXPORT NewUnifiedMessageCenterView
: public views::View,
public MessageCenterScrollBar::Observer,
public views::ButtonListener {
public views::ButtonListener,
public views::FocusChangeListener {
public:
NewUnifiedMessageCenterView();
explicit NewUnifiedMessageCenterView(UnifiedSystemTrayView* parent);
~NewUnifiedMessageCenterView() override;
// Sets the maximum height that the view can take.
......@@ -42,6 +44,8 @@ class ASH_EXPORT NewUnifiedMessageCenterView
void ConfigureMessageView(message_center::MessageView* message_view);
// views::View:
void AddedToWidget() override;
void RemovedFromWidget() override;
void Layout() override;
gfx::Size CalculatePreferredSize() const override;
......@@ -51,6 +55,14 @@ class ASH_EXPORT NewUnifiedMessageCenterView
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// views::FocusChangeListener:
void OnWillChangeFocus(views::View* before, views::View* now) override;
void OnDidChangeFocus(views::View* before, views::View* now) override;
protected:
// Virtual for testing.
virtual void SetNotificationHeightBelowScroll(int height_below_scroll);
private:
friend class NewUnifiedMessageCenterViewTest;
......@@ -59,9 +71,14 @@ class ASH_EXPORT NewUnifiedMessageCenterView
// Scroll the notification list to |position_from_bottom_|.
void ScrollToPositionFromBottom();
// Notifies height below scroll to |parent_| so that it can update
// TopCornerBorder.
void NotifyHeightBelowScroll();
// Count number of notifications that are above visible area.
int GetStackedNotificationCount() const;
UnifiedSystemTrayView* const parent_;
StackingNotificationCounterView* const stacking_counter_;
MessageCenterScrollBar* const scroll_bar_;
views::ScrollView* const scroller_;
......@@ -70,6 +87,8 @@ class ASH_EXPORT NewUnifiedMessageCenterView
// Position from the bottom of scroll contents in dip.
int position_from_bottom_;
views::FocusManager* focus_manager_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(NewUnifiedMessageCenterView);
};
......
......@@ -32,6 +32,24 @@ class DummyEvent : public ui::Event {
~DummyEvent() override = default;
};
class TestNewUnifiedMessageCenterView : public NewUnifiedMessageCenterView {
public:
TestNewUnifiedMessageCenterView() : NewUnifiedMessageCenterView(nullptr) {}
~TestNewUnifiedMessageCenterView() override = default;
void SetNotificationHeightBelowScroll(int height_below_scroll) override {
height_below_scroll_ = height_below_scroll;
}
int height_below_scroll() const { return height_below_scroll_; }
private:
int height_below_scroll_ = -1;
DISALLOW_COPY_AND_ASSIGN(TestNewUnifiedMessageCenterView);
};
} // namespace
class NewUnifiedMessageCenterViewTest : public AshTestBase,
......@@ -68,7 +86,7 @@ class NewUnifiedMessageCenterViewTest : public AshTestBase,
}
void CreateMessageCenterView(int max_height = kDefaultMaxHeight) {
message_center_view_ = std::make_unique<NewUnifiedMessageCenterView>();
message_center_view_ = std::make_unique<TestNewUnifiedMessageCenterView>();
message_center_view_->AddObserver(this);
message_center_view_->SetMaxHeight(max_height);
OnViewPreferredSizeChanged(message_center_view_.get());
......@@ -100,7 +118,7 @@ class NewUnifiedMessageCenterViewTest : public AshTestBase,
return message_center_view()->stacking_counter_;
}
NewUnifiedMessageCenterView* message_center_view() {
TestNewUnifiedMessageCenterView* message_center_view() {
return message_center_view_.get();
}
......@@ -110,7 +128,7 @@ class NewUnifiedMessageCenterViewTest : public AshTestBase,
int id_ = 0;
int size_changed_count_ = 0;
std::unique_ptr<NewUnifiedMessageCenterView> message_center_view_;
std::unique_ptr<TestNewUnifiedMessageCenterView> message_center_view_;
DISALLOW_COPY_AND_ASSIGN(NewUnifiedMessageCenterViewTest);
};
......@@ -332,4 +350,22 @@ TEST_F(NewUnifiedMessageCenterViewTest,
EXPECT_FALSE(GetStackingCounter()->visible());
}
TEST_F(NewUnifiedMessageCenterViewTest, HeightBelowScroll) {
for (size_t i = 0; i < 6; ++i)
AddNotification();
CreateMessageCenterView();
EXPECT_TRUE(message_center_view()->visible());
// MessageCenterView is maxed out.
EXPECT_GT(GetMessageListView()->bounds().height(),
message_center_view()->bounds().height());
message_center_view()->OnMessageCenterScrolled();
EXPECT_EQ(0, message_center_view()->height_below_scroll());
GetScroller()->ScrollToPosition(GetScrollBar(), 0);
message_center_view()->OnMessageCenterScrolled();
EXPECT_LT(0, message_center_view()->height_below_scroll());
}
} // namespace ash
......@@ -228,7 +228,7 @@ UnifiedSystemTrayView::UnifiedSystemTrayView(
this,
message_center::MessageCenter::Get())),
new_message_center_view_(features::IsNewMessageListViewEnabled()
? new NewUnifiedMessageCenterView()
? new NewUnifiedMessageCenterView(this)
: nullptr),
focus_search_(std::make_unique<FocusSearch>(this)),
interacted_by_tap_recorder_(
......
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