notification_hidden_view.cc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/system/unified/notification_hidden_view.h"
  5. #include "ash/bubble/bubble_constants.h"
  6. #include "ash/login/login_screen_controller.h"
  7. #include "ash/shell.h"
  8. #include "ash/strings/grit/ash_strings.h"
  9. #include "ash/style/ash_color_provider.h"
  10. #include "ash/style/pill_button.h"
  11. #include "ash/system/message_center/ash_message_center_lock_screen_controller.h"
  12. #include "ash/system/message_center/message_center_constants.h"
  13. #include "ash/system/tray/tray_constants.h"
  14. #include "base/bind.h"
  15. #include "base/callback_helpers.h"
  16. #include "ui/base/l10n/l10n_util.h"
  17. #include "ui/message_center/lock_screen/lock_screen_controller.h"
  18. #include "ui/message_center/message_center.h"
  19. #include "ui/message_center/message_center_impl.h"
  20. #include "ui/views/background.h"
  21. #include "ui/views/border.h"
  22. #include "ui/views/controls/label.h"
  23. #include "ui/views/layout/box_layout.h"
  24. #include "ui/views/layout/fill_layout.h"
  25. namespace ash {
  26. namespace {
  27. void ShowLockScreenNotificationSettings() {
  28. ash::Shell::Get()
  29. ->login_screen_controller()
  30. ->ShowLockScreenNotificationSettings();
  31. }
  32. SkColor GetBackgroundColor() {
  33. return AshColorProvider::Get()->GetControlsLayerColor(
  34. AshColorProvider::ControlsLayerType::kControlBackgroundColorInactive);
  35. }
  36. } // namespace
  37. NotificationHiddenView::NotificationHiddenView()
  38. : container_(AddChildView(std::make_unique<views::View>())),
  39. label_(container_->AddChildView(std::make_unique<views::Label>())) {
  40. label_->SetAutoColorReadabilityEnabled(false);
  41. label_->SetText(
  42. l10n_util::GetStringUTF16(IDS_ASH_MESSAGE_CENTER_LOCKSCREEN_UNIFIED));
  43. label_->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_LEFT);
  44. label_->SetLineHeight(kUnifiedNotificationHiddenLineHeight);
  45. label_->SetBorder(
  46. views::CreateEmptyBorder(kUnifiedNotificationHiddenPadding));
  47. container_->SetBackground(views::CreateRoundedRectBackground(
  48. GetBackgroundColor(), kBubbleCornerRadius));
  49. auto* layout =
  50. container_->SetLayoutManager(std::make_unique<views::BoxLayout>(
  51. views::BoxLayout::Orientation::kHorizontal));
  52. layout->SetFlexForView(label_, 1);
  53. // Shows the "Change" button, unless the locks screen notification is
  54. // prohibited by policy or flag.
  55. if (AshMessageCenterLockScreenController::IsAllowed()) {
  56. change_button_ = container_->AddChildView(std::make_unique<PillButton>(
  57. base::BindRepeating(&NotificationHiddenView::ChangeButtonPressed,
  58. base::Unretained(this)),
  59. l10n_util::GetStringUTF16(IDS_ASH_MESSAGE_CENTER_LOCKSCREEN_CHANGE),
  60. PillButton::Type::kIconless, /*icon=*/nullptr,
  61. kNotificationPillButtonHorizontalSpacing));
  62. change_button_->SetTooltipText(l10n_util::GetStringUTF16(
  63. IDS_ASH_MESSAGE_CENTER_LOCKSCREEN_CHANGE_TOOLTIP));
  64. }
  65. SetBorder(views::CreateEmptyBorder(kUnifiedNotificationCenterSpacing));
  66. SetLayoutManager(std::make_unique<views::FillLayout>());
  67. }
  68. const char* NotificationHiddenView::GetClassName() const {
  69. return "NotificationHiddenView";
  70. }
  71. void NotificationHiddenView::OnThemeChanged() {
  72. views::View::OnThemeChanged();
  73. label_->SetEnabledColor(AshColorProvider::Get()->GetContentLayerColor(
  74. AshColorProvider::ContentLayerType::kTextColorPrimary));
  75. container_->background()->SetNativeControlColor(GetBackgroundColor());
  76. }
  77. void NotificationHiddenView::ChangeButtonPressed() {
  78. // TODO(yoshiki): Refactor LockScreenController and remove the static cast.
  79. // TODO(yoshiki): Show the setting after unlocking.
  80. static_cast<message_center::MessageCenterImpl*>(
  81. message_center::MessageCenter::Get())
  82. ->lock_screen_controller()
  83. ->DismissLockScreenThenExecute(
  84. base::BindOnce(&ShowLockScreenNotificationSettings),
  85. base::DoNothing(), IDS_ASH_MESSAGE_CENTER_UNLOCK_TO_CHANGE_SETTING);
  86. }
  87. } // namespace ash