Commit b2ef1382 authored by Tetsui Ohkubo's avatar Tetsui Ohkubo Committed by Commit Bot

Add empty notifier settings view to message center.

As a part of message center restyling, this CL adds a new view for
message center when there are no notifier sources.

Previously, there was no such view and the layout was broken when
there were no notifier sources.

TEST=ash_unittests
BUG=726246

Change-Id: I51c6b6b074995003c622e4bd4e1de19d2db5f56b
Reviewed-on: https://chromium-review.googlesource.com/708106
Commit-Queue: Tetsui Ohkubo <tetsui@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarYoshiki Iguchi <yoshiki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#509688}
parent 5c161d39
......@@ -1188,6 +1188,9 @@ Subsequent notifications, windows and dialogs may be split between desktops.
<message name="IDS_ASH_MESSAGE_CENTER_NO_MESSAGES" desc="The message displayed in the message center when there are no notifications.">
All done
</message>
<message name="IDS_ASH_MESSAGE_CENTER_NO_NOTIFIERS" desc="The message displayed in the message center when there are no notification sources.">
Nothing to see just yet
</message>
</messages>
</release>
</grit>
......
......@@ -85,7 +85,7 @@ void SetDefaultButtonStyle(views::Button* button) {
button->SetFocusPainter(views::Painter::CreateSolidFocusPainter(
message_center::kFocusBorderColor, gfx::Insets(1, 2, 2, 2)));
button->SetBorder(
views::CreateEmptyBorder(message_center_style::kVectorIconPadding));
views::CreateEmptyBorder(message_center_style::kActionIconPadding));
// TODO(tetsui): Add ripple effect to the buttons.
}
......@@ -145,12 +145,12 @@ MessageCenterButtonBar::MessageCenterButtonBar(
close_all_button_->SetImage(
views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(kNotificationCenterClearAllIcon,
message_center_style::kVectorIconSize,
message_center_style::kActionIconSize,
kActiveButtonColor));
close_all_button_->SetImage(
views::Button::STATE_DISABLED,
gfx::CreateVectorIcon(kNotificationCenterClearAllIcon,
message_center_style::kVectorIconSize,
message_center_style::kActionIconSize,
kInactiveButtonColor));
close_all_button_->SetTooltipText(l10n_util::GetStringUTF16(
IDS_ASH_MESSAGE_CENTER_CLEAR_ALL_BUTTON_TOOLTIP));
......@@ -162,11 +162,11 @@ MessageCenterButtonBar::MessageCenterButtonBar(
quiet_mode_button_->SetImage(
views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(kNotificationCenterDoNotDisturbOffIcon,
message_center_style::kVectorIconSize,
message_center_style::kActionIconSize,
kInactiveButtonColor));
gfx::ImageSkia quiet_mode_toggle_icon = gfx::CreateVectorIcon(
kNotificationCenterDoNotDisturbOnIcon,
message_center_style::kVectorIconSize, kActiveButtonColor);
message_center_style::kActionIconSize, kActiveButtonColor);
quiet_mode_button_->SetToggledImage(views::Button::STATE_NORMAL,
&quiet_mode_toggle_icon);
quiet_mode_button_->SetTooltipText(l10n_util::GetStringUTF16(
......@@ -180,7 +180,7 @@ MessageCenterButtonBar::MessageCenterButtonBar(
settings_button_->SetImage(
views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(kNotificationCenterSettingsIcon,
message_center_style::kVectorIconSize,
message_center_style::kActionIconSize,
kActiveButtonColor));
settings_button_->SetTooltipText(l10n_util::GetStringUTF16(
IDS_ASH_MESSAGE_CENTER_SETTINGS_BUTTON_TOOLTIP));
......
......@@ -14,9 +14,13 @@ namespace ash {
namespace message_center_style {
constexpr SkColor kBackgroundColor = SkColorSetRGB(0xFF, 0xFF, 0xFF);
constexpr SkColor kEmptyViewColor = SkColorSetARGB(0x8A, 0x0, 0x0, 0x0);
constexpr int kVectorIconSize = 20;
constexpr gfx::Insets kVectorIconPadding(14);
constexpr int kActionIconSize = 20;
constexpr int kEmptyIconSize = 24;
constexpr int kEmptyLabelSize = 12;
constexpr gfx::Insets kActionIconPadding(14);
constexpr gfx::Insets kEmptyIconPadding(0, 0, 4, 0);
constexpr int kMarginBetweenItems = 8;
......
......@@ -65,10 +65,6 @@ constexpr int kDefaultFrameRateHz = 60;
constexpr int kMinScrollViewHeight = 77;
constexpr int kEmptyViewHeight = 96;
constexpr gfx::Insets kEmptyViewPadding(0, 0, 24, 0);
constexpr SkColor kEmptyViewColor = SkColorSetARGB(0x8A, 0x0, 0x0, 0x0);
constexpr gfx::Insets kAllDoneIconPadding(0, 0, 4, 0);
constexpr int kAllDoneIconSize = 24;
constexpr int kEmptyLabelSize = 12;
void SetViewHierarchyEnabled(views::View* view, bool enabled) {
for (int i = 0; i < view->child_count(); i++)
......@@ -88,17 +84,19 @@ class EmptyNotificationView : public views::View {
SetLayoutManager(layout);
views::ImageView* icon = new views::ImageView();
icon->SetImage(gfx::CreateVectorIcon(kNotificationCenterAllDoneIcon,
kAllDoneIconSize, kEmptyViewColor));
icon->SetBorder(views::CreateEmptyBorder(kAllDoneIconPadding));
icon->SetImage(gfx::CreateVectorIcon(
kNotificationCenterAllDoneIcon, message_center_style::kEmptyIconSize,
message_center_style::kEmptyViewColor));
icon->SetBorder(
views::CreateEmptyBorder(message_center_style::kEmptyIconPadding));
AddChildView(icon);
views::Label* label = new views::Label(
l10n_util::GetStringUTF16(IDS_ASH_MESSAGE_CENTER_NO_MESSAGES));
label->SetEnabledColor(kEmptyViewColor);
label->SetEnabledColor(message_center_style::kEmptyViewColor);
// "Roboto-Medium, 12sp" is specified in the mock.
label->SetFontList(message_center_style::GetFontListForSizeAndWeight(
kEmptyLabelSize, gfx::Font::Weight::MEDIUM));
message_center_style::kEmptyLabelSize, gfx::Font::Weight::MEDIUM));
label->SetHorizontalAlignment(gfx::ALIGN_CENTER);
AddChildView(label);
}
......
......@@ -182,6 +182,40 @@ void EntryView::OnBlur() {
SchedulePaint();
}
// EmptyNotifierView -----------------------------------------------------------
class EmptyNotifierView : public views::View {
public:
EmptyNotifierView() {
views::BoxLayout* layout =
new views::BoxLayout(views::BoxLayout::kVertical, gfx::Insets(), 0);
layout->set_main_axis_alignment(
views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER);
layout->set_cross_axis_alignment(
views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
SetLayoutManager(layout);
views::ImageView* icon = new views::ImageView();
icon->SetImage(gfx::CreateVectorIcon(
kNotificationCenterEmptyIcon, message_center_style::kEmptyIconSize,
message_center_style::kEmptyViewColor));
icon->SetBorder(
views::CreateEmptyBorder(message_center_style::kEmptyIconPadding));
AddChildView(icon);
views::Label* label = new views::Label(
l10n_util::GetStringUTF16(IDS_ASH_MESSAGE_CENTER_NO_NOTIFIERS));
label->SetEnabledColor(message_center_style::kEmptyViewColor);
// "Roboto-Medium, 12sp" is specified in the mock.
label->SetFontList(message_center_style::GetFontListForSizeAndWeight(
message_center_style::kEmptyLabelSize, gfx::Font::Weight::MEDIUM));
AddChildView(label);
}
private:
DISALLOW_COPY_AND_ASSIGN(EmptyNotifierView);
};
} // namespace
// NotifierSettingsView::NotifierButton ---------------------------------------
......@@ -361,7 +395,9 @@ void NotifierSettingsView::NotifierButton::GridChanged(bool has_learn_more) {
NotifierSettingsView::NotifierSettingsView(NotifierSettingsProvider* provider)
: title_arrow_(nullptr),
header_view_(nullptr),
top_label_(nullptr),
scroller_(nullptr),
no_notifiers_view_(nullptr),
provider_(provider) {
// |provider_| may be null in tests.
if (provider_)
......@@ -386,7 +422,7 @@ NotifierSettingsView::NotifierSettingsView(NotifierSettingsProvider* provider)
views::ImageView* quiet_mode_icon = new views::ImageView();
quiet_mode_icon->SetImage(gfx::CreateVectorIcon(
kNotificationCenterDoNotDisturbOffIcon,
message_center_style::kVectorIconSize, kQuietModeIconColor));
message_center_style::kActionIconSize, kQuietModeIconColor));
quiet_mode_view->AddChildView(quiet_mode_icon);
views::Label* quiet_mode_label = new views::Label(l10n_util::GetStringUTF16(
......@@ -406,17 +442,17 @@ NotifierSettingsView::NotifierSettingsView(NotifierSettingsProvider* provider)
quiet_mode_view->AddChildView(quiet_mode_toggle_);
header_view_->AddChildView(quiet_mode_view);
views::Label* top_label = new views::Label(l10n_util::GetStringUTF16(
top_label_ = new views::Label(l10n_util::GetStringUTF16(
IDS_ASH_MESSAGE_CENTER_SETTINGS_DIALOG_DESCRIPTION));
top_label->SetBorder(views::CreateEmptyBorder(kTopLabelPadding));
top_label_->SetBorder(views::CreateEmptyBorder(kTopLabelPadding));
// "Roboto-Medium, 13sp" is specified in the mock.
top_label->SetFontList(message_center_style::GetFontListForSizeAndWeight(
top_label_->SetFontList(message_center_style::GetFontListForSizeAndWeight(
kLabelFontSize, gfx::Font::Weight::MEDIUM));
top_label->SetAutoColorReadabilityEnabled(false);
top_label->SetEnabledColor(kTopLabelColor);
top_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
top_label->SetMultiLine(true);
header_view_->AddChildView(top_label);
top_label_->SetAutoColorReadabilityEnabled(false);
top_label_->SetEnabledColor(kTopLabelColor);
top_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
top_label_->SetMultiLine(true);
header_view_->AddChildView(top_label_);
AddChildView(header_view_);
......@@ -426,6 +462,9 @@ NotifierSettingsView::NotifierSettingsView(NotifierSettingsProvider* provider)
scroller_->SetHorizontalScrollBar(new views::OverlayScrollBar(true));
AddChildView(scroller_);
no_notifiers_view_ = new EmptyNotifierView();
AddChildView(no_notifiers_view_);
std::vector<std::unique_ptr<Notifier>> notifiers;
if (provider_)
provider_->GetNotifierList(&notifiers);
......@@ -488,6 +527,9 @@ void NotifierSettingsView::UpdateContentsView(
buttons_.insert(button);
}
top_label_->SetVisible(notifier_count > 0);
no_notifiers_view_->SetVisible(notifier_count == 0);
scroller_->SetContents(contents_view);
contents_view->SetBoundsRect(gfx::Rect(contents_view->GetPreferredSize()));
......@@ -507,6 +549,8 @@ void NotifierSettingsView::Layout() {
}
contents_view->SetBounds(0, 0, content_width, content_height);
scroller_->SetBounds(0, header_height, width(), height() - header_height);
no_notifiers_view_->SetBounds(0, header_height, width(),
height() - header_height);
}
gfx::Size NotifierSettingsView::GetMinimumSize() const {
......@@ -522,8 +566,13 @@ gfx::Size NotifierSettingsView::CalculatePreferredSize() const {
gfx::Size preferred_size;
gfx::Size header_size = header_view_->GetPreferredSize();
gfx::Size content_size = scroller_->contents()->GetPreferredSize();
return gfx::Size(std::max(header_size.width(), content_size.width()),
header_size.height() + content_size.height());
int no_notifiers_height = 0;
if (no_notifiers_view_->visible())
no_notifiers_height = no_notifiers_view_->GetPreferredSize().height();
return gfx::Size(
std::max(header_size.width(), content_size.width()),
std::max(kMinimumHeight, header_size.height() + content_size.height() +
no_notifiers_height));
}
bool NotifierSettingsView::OnKeyPressed(const ui::KeyEvent& event) {
......
......@@ -52,6 +52,7 @@ class ASH_EXPORT NotifierSettingsView
private:
FRIEND_TEST_ALL_PREFIXES(NotifierSettingsViewTest, TestLearnMoreButton);
FRIEND_TEST_ALL_PREFIXES(NotifierSettingsViewTest, TestEmptyNotifierView);
class ASH_EXPORT NotifierButton : public views::Button,
public views::ButtonListener {
......@@ -109,7 +110,9 @@ class ASH_EXPORT NotifierSettingsView
views::ImageButton* title_arrow_;
views::ToggleButton* quiet_mode_toggle_;
views::View* header_view_;
views::Label* top_label_;
views::ScrollView* scroller_;
views::View* no_notifiers_view_;
message_center::NotifierSettingsProvider* provider_;
std::set<NotifierButton*> buttons_;
......
......@@ -11,6 +11,7 @@
#include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/message_center/notifier_settings.h"
#include "ui/views/controls/scroll_view.h"
using message_center::Notifier;
using message_center::NotifierGroup;
......@@ -61,8 +62,11 @@ class TestingNotifierSettingsProvider : public NotifierSettingsProvider {
void GetNotifierList(
std::vector<std::unique_ptr<Notifier>>* notifiers) override {
notifiers->clear();
notifiers->push_back(NewNotifier("id", "title", /*enabled=*/true));
notifiers->push_back(NewNotifier("id2", "other title", /*enabled=*/false));
if (!no_notifiers_) {
notifiers->push_back(NewNotifier("id", "title", true /* enabled */));
notifiers->push_back(
NewNotifier("id2", "other title", false /* enabled */));
}
}
void SetNotifierEnabled(const NotifierId& notifier_id,
......@@ -83,6 +87,8 @@ class TestingNotifierSettingsProvider : public NotifierSettingsProvider {
last_notifier_id_settings_requested_.reset(new NotifierId(notifier_id));
}
void set_no_notifiers(bool no_notifiers) { no_notifiers_ = no_notifiers; }
private:
std::unique_ptr<Notifier> NewNotifier(const std::string& id,
const std::string& title,
......@@ -94,6 +100,7 @@ class TestingNotifierSettingsProvider : public NotifierSettingsProvider {
size_t request_count_ = 0u;
std::unique_ptr<NotifierId> last_notifier_id_settings_requested_;
bool no_notifiers_ = false;
};
} // namespace
......@@ -106,10 +113,14 @@ class NotifierSettingsViewTest : public AshTestBase {
void SetUp() override;
void TearDown() override;
void InitView();
NotifierSettingsView* GetView() const;
const TestingNotifierSettingsProvider* settings_provider() const {
return &settings_provider_;
}
void SetNoNotifiers(bool no_notifiers) {
settings_provider_.set_no_notifiers(no_notifiers);
}
private:
TestingNotifierSettingsProvider settings_provider_;
......@@ -124,8 +135,7 @@ NotifierSettingsViewTest::~NotifierSettingsViewTest() = default;
void NotifierSettingsViewTest::SetUp() {
AshTestBase::SetUp();
notifier_settings_view_ =
std::make_unique<NotifierSettingsView>(&settings_provider_);
SetNoNotifiers(false);
}
void NotifierSettingsViewTest::TearDown() {
......@@ -133,11 +143,17 @@ void NotifierSettingsViewTest::TearDown() {
AshTestBase::TearDown();
}
void NotifierSettingsViewTest::InitView() {
notifier_settings_view_ =
std::make_unique<NotifierSettingsView>(&settings_provider_);
}
NotifierSettingsView* NotifierSettingsViewTest::GetView() const {
return notifier_settings_view_.get();
}
TEST_F(NotifierSettingsViewTest, TestLearnMoreButton) {
InitView();
const std::set<NotifierSettingsView::NotifierButton*>& buttons =
GetView()->buttons_;
EXPECT_EQ(2u, buttons.size());
......@@ -158,4 +174,15 @@ TEST_F(NotifierSettingsViewTest, TestLearnMoreButton) {
*last_settings_button_id);
}
TEST_F(NotifierSettingsViewTest, TestEmptyNotifierView) {
InitView();
EXPECT_FALSE(GetView()->no_notifiers_view_->visible());
EXPECT_TRUE(GetView()->top_label_->visible());
SetNoNotifiers(true);
InitView();
EXPECT_TRUE(GetView()->no_notifiers_view_->visible());
EXPECT_FALSE(GetView()->top_label_->visible());
}
} // namespace ash
......@@ -80,6 +80,7 @@ aggregate_vector_icons("ash_vector_icons") {
"notification_center_clear_all.icon",
"notification_center_do_not_disturb_off.icon",
"notification_center_do_not_disturb_on.icon",
"notification_center_empty.icon",
"notification_center_settings.icon",
"notification_charging_usb_c.icon",
"notification_chromevox.icon",
......
// Copyright 2017 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.
CANVAS_DIMENSIONS, 48,
MOVE_TO, 12, 20,
R_CUBIC_TO, -2.21f, 0, -4, 1.79f, -4, 4,
R_CUBIC_TO, 0, 2.21f, 1.79f, 4, 4, 4,
R_CUBIC_TO, 2.21f, 0, 4, -1.79f, 4, -4,
R_CUBIC_TO, 0, -2.21f, -1.79f, -4, -4, -4,
CLOSE,
R_MOVE_TO, 24, 0,
R_CUBIC_TO, -2.21f, 0, -4, 1.79f, -4, 4,
R_CUBIC_TO, 0, 2.21f, 1.79f, 4, 4, 4,
R_CUBIC_TO, 2.21f, 0, 4, -1.79f, 4, -4,
R_CUBIC_TO, 0, -2.21f, -1.79f, -4, -4, -4,
CLOSE,
R_MOVE_TO, -12, 0,
R_CUBIC_TO, -2.21f, 0, -4, 1.79f, -4, 4,
R_CUBIC_TO, 0, 2.21f, 1.79f, 4, 4, 4,
R_CUBIC_TO, 2.21f, 0, 4, -1.79f, 4, -4,
R_CUBIC_TO, 0, -2.21f, -1.79f, -4, -4, -4,
CLOSE,
END
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