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

Add notification counter icon in UnifiedSystemTray

As described in the design doc, old SystemTray class is going to be
replaced by UnifiedSystemTray class. Tray icons will be implemented in
UnifiedSystemTray.

This CL adds notification counter and do-not-disturb icon to
UnifiedSystemTray button.

Screenshot:
  * Counter: http://screen/cgktiihNYDo
  * Mute icon: http://screen/613vrQB3suz
UX spec: http://shortn/_4BzEvhLxJ5
Design doc: go/cros-qs-restyling

TEST=manual
BUG=836134

Change-Id: Ia8c75290afe6c63a70125808d6ebd9bc7b0c37b9
Reviewed-on: https://chromium-review.googlesource.com/1060779Reviewed-by: default avatarYoshiki Iguchi <yoshiki@chromium.org>
Commit-Queue: Tetsui Ohkubo <tetsui@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560267}
parent 11cab2b7
...@@ -886,6 +886,8 @@ component("ash") { ...@@ -886,6 +886,8 @@ component("ash") {
"system/unified/feature_pod_controller_base.h", "system/unified/feature_pod_controller_base.h",
"system/unified/feature_pods_container_view.cc", "system/unified/feature_pods_container_view.cc",
"system/unified/feature_pods_container_view.h", "system/unified/feature_pods_container_view.h",
"system/unified/notification_counter_view.cc",
"system/unified/notification_counter_view.h",
"system/unified/quiet_mode_feature_pod_controller.cc", "system/unified/quiet_mode_feature_pod_controller.cc",
"system/unified/quiet_mode_feature_pod_controller.h", "system/unified/quiet_mode_feature_pod_controller.h",
"system/unified/sign_out_button.cc", "system/unified/sign_out_button.cc",
......
...@@ -85,7 +85,7 @@ gfx::Size TrayItemView::CalculatePreferredSize() const { ...@@ -85,7 +85,7 @@ gfx::Size TrayItemView::CalculatePreferredSize() const {
gfx::Size size = rect.size(); gfx::Size size = rect.size();
if (!animation_.get() || !animation_->is_animating()) if (!animation_.get() || !animation_->is_animating())
return size; return size;
if (owner() && owner()->system_tray()->shelf()->IsHorizontalAlignment()) { if (!owner() || owner()->system_tray()->shelf()->IsHorizontalAlignment()) {
size.set_width(std::max( size.set_width(std::max(
1, static_cast<int>(size.width() * animation_->GetCurrentValue()))); 1, static_cast<int>(size.width() * animation_->GetCurrentValue())));
} else { } else {
...@@ -105,7 +105,7 @@ void TrayItemView::ChildPreferredSizeChanged(views::View* child) { ...@@ -105,7 +105,7 @@ void TrayItemView::ChildPreferredSizeChanged(views::View* child) {
void TrayItemView::AnimationProgressed(const gfx::Animation* animation) { void TrayItemView::AnimationProgressed(const gfx::Animation* animation) {
gfx::Transform transform; gfx::Transform transform;
if (owner() && owner()->system_tray()->shelf()->IsHorizontalAlignment()) { if (!owner() || owner()->system_tray()->shelf()->IsHorizontalAlignment()) {
transform.Translate(0, animation->CurrentValueBetween( transform.Translate(0, animation->CurrentValueBetween(
static_cast<double>(height()) / 2, 0.)); static_cast<double>(height()) / 2, 0.));
} else { } else {
......
// Copyright 2018 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.
#include "ash/system/unified/notification_counter_view.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_utils.h"
#include "base/i18n/number_formatting.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/message_center/message_center.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
namespace ash {
NotificationCounterView::NotificationCounterView() : TrayItemView(nullptr) {
CreateLabel();
Update();
}
NotificationCounterView::~NotificationCounterView() = default;
void NotificationCounterView::Update() {
size_t notification_count =
message_center::MessageCenter::Get()->NotificationCount();
SetupLabelForTray(label());
label()->SetText(base::FormatNumber(notification_count));
SetVisible(notification_count > 0 &&
!message_center::MessageCenter::Get()->IsQuietMode());
}
QuietModeView::QuietModeView() : TrayItemView(nullptr) {
CreateImageView();
image_view()->SetImage(gfx::CreateVectorIcon(
kNotificationCenterDoNotDisturbOnIcon, kTrayIconSize, kTrayIconColor));
Update();
}
QuietModeView::~QuietModeView() = default;
void QuietModeView::Update() {
SetVisible(message_center::MessageCenter::Get()->IsQuietMode());
}
} // namespace ash
// Copyright 2018 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_UNIFIED_NOTIFICATION_COUNTER_VIEW_H_
#define ASH_SYSTEM_UNIFIED_NOTIFICATION_COUNTER_VIEW_H_
#include "ash/system/tray/tray_item_view.h"
#include "base/macros.h"
namespace ash {
// A notification counter view in UnifiedSystemTray button.
class NotificationCounterView : public TrayItemView {
public:
NotificationCounterView();
~NotificationCounterView() override;
void Update();
private:
DISALLOW_COPY_AND_ASSIGN(NotificationCounterView);
};
// A do-not-distrub icon view in UnifiedSystemTray button.
class QuietModeView : public TrayItemView {
public:
QuietModeView();
~QuietModeView() override;
void Update();
private:
DISALLOW_COPY_AND_ASSIGN(QuietModeView);
};
} // namespace ash
#endif // ASH_SYSTEM_UNIFIED_NOTIFICATION_COUNTER_VIEW_H_
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "ash/system/status_area_widget.h" #include "ash/system/status_area_widget.h"
#include "ash/system/tray/system_tray.h" #include "ash/system/tray/system_tray.h"
#include "ash/system/tray/tray_container.h" #include "ash/system/tray/tray_container.h"
#include "ash/system/unified/notification_counter_view.h"
#include "ash/system/unified/unified_system_tray_bubble.h" #include "ash/system/unified/unified_system_tray_bubble.h"
#include "ash/system/unified/unified_system_tray_model.h" #include "ash/system/unified/unified_system_tray_model.h"
#include "chromeos/network/network_handler.h" #include "chromeos/network/network_handler.h"
...@@ -31,7 +32,7 @@ namespace ash { ...@@ -31,7 +32,7 @@ namespace ash {
class UnifiedSystemTray::UiDelegate : public message_center::UiDelegate { class UnifiedSystemTray::UiDelegate : public message_center::UiDelegate {
public: public:
explicit UiDelegate(UnifiedSystemTray* owner); UiDelegate(UnifiedSystemTray* owner);
~UiDelegate() override; ~UiDelegate() override;
// message_center::UiDelegate: // message_center::UiDelegate:
...@@ -73,7 +74,7 @@ UnifiedSystemTray::UiDelegate::UiDelegate(UnifiedSystemTray* owner) ...@@ -73,7 +74,7 @@ UnifiedSystemTray::UiDelegate::UiDelegate(UnifiedSystemTray* owner)
UnifiedSystemTray::UiDelegate::~UiDelegate() = default; UnifiedSystemTray::UiDelegate::~UiDelegate() = default;
void UnifiedSystemTray::UiDelegate::OnMessageCenterContentsChanged() { void UnifiedSystemTray::UiDelegate::OnMessageCenterContentsChanged() {
// TODO(tetsui): Implement. owner_->UpdateNotificationInternal();
} }
bool UnifiedSystemTray::UiDelegate::ShowPopups() { bool UnifiedSystemTray::UiDelegate::ShowPopups() {
...@@ -136,7 +137,12 @@ void UnifiedSystemTray::NetworkStateDelegate::NetworkStateChanged( ...@@ -136,7 +137,12 @@ void UnifiedSystemTray::NetworkStateDelegate::NetworkStateChanged(
UnifiedSystemTray::UnifiedSystemTray(Shelf* shelf) UnifiedSystemTray::UnifiedSystemTray(Shelf* shelf)
: TrayBackgroundView(shelf), : TrayBackgroundView(shelf),
ui_delegate_(std::make_unique<UiDelegate>(this)), ui_delegate_(std::make_unique<UiDelegate>(this)),
model_(std::make_unique<UnifiedSystemTrayModel>()) { model_(std::make_unique<UnifiedSystemTrayModel>()),
notification_counter_item_(new NotificationCounterView()),
quiet_mode_view_(new QuietModeView()) {
tray_container()->AddChildView(notification_counter_item_);
tray_container()->AddChildView(quiet_mode_view_);
// It is possible in unit tests that it's missing. // It is possible in unit tests that it's missing.
if (chromeos::NetworkHandler::IsInitialized()) { if (chromeos::NetworkHandler::IsInitialized()) {
tray::NetworkTrayView* network_item = new tray::NetworkTrayView(nullptr); tray::NetworkTrayView* network_item = new tray::NetworkTrayView(nullptr);
...@@ -213,4 +219,9 @@ void UnifiedSystemTray::HideBubbleInternal() { ...@@ -213,4 +219,9 @@ void UnifiedSystemTray::HideBubbleInternal() {
SetIsActive(false); SetIsActive(false);
} }
void UnifiedSystemTray::UpdateNotificationInternal() {
notification_counter_item_->Update();
quiet_mode_view_->Update();
}
} // namespace ash } // namespace ash
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
namespace ash { namespace ash {
class NotificationCounterView;
class QuietModeView;
class UnifiedSystemTrayBubble; class UnifiedSystemTrayBubble;
class UnifiedSystemTrayModel; class UnifiedSystemTrayModel;
...@@ -59,15 +61,19 @@ class UnifiedSystemTray : public TrayBackgroundView { ...@@ -59,15 +61,19 @@ class UnifiedSystemTray : public TrayBackgroundView {
// Forwarded from UiDelegate. // Forwarded from UiDelegate.
void ShowBubbleInternal(bool show_by_click); void ShowBubbleInternal(bool show_by_click);
void HideBubbleInternal(); void HideBubbleInternal();
void UpdateNotificationInternal();
std::unique_ptr<UiDelegate> ui_delegate_; const std::unique_ptr<UiDelegate> ui_delegate_;
std::unique_ptr<NetworkStateDelegate> network_state_delegate_; std::unique_ptr<NetworkStateDelegate> network_state_delegate_;
std::unique_ptr<UnifiedSystemTrayBubble> bubble_; std::unique_ptr<UnifiedSystemTrayBubble> bubble_;
// Model class that stores UnifiedSystemTray's UI specific variables. // Model class that stores UnifiedSystemTray's UI specific variables.
std::unique_ptr<UnifiedSystemTrayModel> model_; const std::unique_ptr<UnifiedSystemTrayModel> model_;
NotificationCounterView* const notification_counter_item_;
QuietModeView* const quiet_mode_view_;
DISALLOW_COPY_AND_ASSIGN(UnifiedSystemTray); DISALLOW_COPY_AND_ASSIGN(UnifiedSystemTray);
}; };
......
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