ash_notification_input_container.cc 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // Copyright 2021 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/message_center/ash_notification_input_container.h"
  5. #include "ash/public/cpp/style/color_provider.h"
  6. #include "ash/resources/vector_icons/vector_icons.h"
  7. #include "ash/strings/grit/ash_strings.h"
  8. #include "ash/style/ash_color_provider.h"
  9. #include "ash/system/message_center/message_center_constants.h"
  10. #include "ui/color/color_id.h"
  11. #include "ui/gfx/font_list.h"
  12. #include "ui/gfx/geometry/rrect_f.h"
  13. #include "ui/gfx/paint_vector_icon.h"
  14. #include "ui/views/background.h"
  15. #include "ui/views/controls/button/image_button.h"
  16. #include "ui/views/controls/focus_ring.h"
  17. #include "ui/views/controls/highlight_path_generator.h"
  18. #include "ui/views/controls/textfield/textfield.h"
  19. namespace ash {
  20. namespace {
  21. // Padding between children, currently only between the textfield and the
  22. // ImageButton.
  23. constexpr int kBetweenChildSpacing = 12;
  24. // Insets for inside the border.
  25. constexpr auto kInsideBorderInsets = gfx::Insets::TLBR(6, 16, 14, 6);
  26. // The icon size of inline reply input field.
  27. constexpr int kInputReplyButtonSize = 20;
  28. // Padding on the input reply button.
  29. constexpr auto kInputReplyButtonPadding = gfx::Insets::TLBR(0, 6, 0, 6);
  30. // Radius of the circular input reply button highlight.
  31. constexpr int kInputReplyHighlightRadius =
  32. (kInputReplyButtonPadding.width() + kInputReplyButtonSize) / 2;
  33. // Padding of the textfield, inside the rounded background.
  34. constexpr auto kInputTextfieldPaddingCrOS = gfx::Insets::TLBR(6, 12, 6, 12);
  35. // Corner radius of the grey background of the textfield.
  36. constexpr int kTextfieldBackgroundCornerRadius = 24;
  37. } // namespace
  38. AshNotificationInputContainer::AshNotificationInputContainer(
  39. message_center::NotificationInputDelegate* delegate)
  40. : message_center::NotificationInputContainer(delegate) {}
  41. AshNotificationInputContainer::~AshNotificationInputContainer() {}
  42. views::BoxLayout* AshNotificationInputContainer::InstallLayoutManager() {
  43. return SetLayoutManager(std::make_unique<views::BoxLayout>(
  44. views::BoxLayout::Orientation::kHorizontal, kInsideBorderInsets,
  45. kBetweenChildSpacing));
  46. }
  47. views::InkDropContainerView* AshNotificationInputContainer::InstallInkDrop() {
  48. // Do not install an inkdrop.
  49. return nullptr;
  50. }
  51. gfx::Insets AshNotificationInputContainer::GetTextfieldPadding() const {
  52. return kInputTextfieldPaddingCrOS;
  53. }
  54. int AshNotificationInputContainer::GetDefaultPlaceholderStringId() const {
  55. return IDS_ASH_NOTIFICATION_INLINE_REPLY_PLACEHOLDER;
  56. }
  57. void AshNotificationInputContainer::StyleTextfield() {
  58. textfield()->SetFontList(gfx::FontList({kGoogleSansFont}, gfx::Font::NORMAL,
  59. kNotificationBodyFontWeight,
  60. gfx::Font::Weight::MEDIUM));
  61. auto* color_provider = ash::AshColorProvider::Get();
  62. textfield()->SetBackground(views::CreateRoundedRectBackground(
  63. color_provider->GetControlsLayerColor(
  64. ash::AshColorProvider::ControlsLayerType::
  65. kControlBackgroundColorInactive),
  66. kTextfieldBackgroundCornerRadius));
  67. views::FocusRing::Install(textfield());
  68. views::InstallRoundRectHighlightPathGenerator(
  69. textfield(), gfx::Insets(), kTextfieldBackgroundCornerRadius);
  70. views::FocusRing::Get(textfield())->SetColorId(ui::kColorAshFocusRing);
  71. }
  72. gfx::Insets AshNotificationInputContainer::GetSendButtonPadding() const {
  73. return kInputReplyButtonPadding;
  74. }
  75. void AshNotificationInputContainer::SetSendButtonHighlightPath() {
  76. views::FocusRing::Install(textfield());
  77. views::InstallRoundRectHighlightPathGenerator(button(), gfx::Insets(),
  78. kInputReplyHighlightRadius);
  79. views::FocusRing::Get(button())->SetColorId(ui::kColorAshFocusRing);
  80. }
  81. void AshNotificationInputContainer::UpdateButtonImage() {
  82. if (!GetWidget())
  83. return;
  84. button()->SetImage(
  85. views::Button::STATE_NORMAL,
  86. gfx::CreateVectorIcon(kSendIcon, kInputReplyButtonSize,
  87. ash::AshColorProvider::Get()->GetControlsLayerColor(
  88. ash::AshColorProvider::ControlsLayerType::
  89. kControlBackgroundColorActive)));
  90. }
  91. void AshNotificationInputContainer::OnThemeChanged() {
  92. message_center::NotificationInputContainer::OnThemeChanged();
  93. UpdateButtonImage();
  94. SetSendButtonHighlightPath();
  95. StyleTextfield();
  96. }
  97. } // namespace ash