1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138

ash / system / notification_center / views / ash_notification_input_container.cc [blame]

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/system/notification_center/views/ash_notification_input_container.h"

#include "ash/public/cpp/style/color_provider.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/style/typography.h"
#include "ash/system/notification_center/message_center_constants.h"
#include "components/vector_icons/vector_icons.h"
#include "ui/chromeos/styles/cros_tokens_color_mappings.h"
#include "ui/color/color_id.h"
#include "ui/gfx/font_list.h"
#include "ui/gfx/geometry/rrect_f.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/background.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/focus_ring.h"
#include "ui/views/controls/highlight_path_generator.h"
#include "ui/views/controls/textfield/textfield.h"

namespace ash {

namespace {

// Padding between children, currently only between the textfield and the
// ImageButton.
constexpr int kBetweenChildSpacing = 12;

// Insets for inside the border.
constexpr auto kInsideBorderInsets = gfx::Insets::TLBR(6, 16, 14, 6);

// The icon size of inline reply input field.
constexpr int kInputReplyButtonSize = 20;
// Padding on the input reply button.
constexpr auto kInputReplyButtonPadding = gfx::Insets::TLBR(0, 6, 0, 6);
// Radius of the circular input reply button highlight.
constexpr int kInputReplyHighlightRadius =
    (kInputReplyButtonPadding.width() + kInputReplyButtonSize) / 2;

// Padding of the textfield, inside the rounded background.
constexpr auto kInputTextfieldPaddingCrOS = gfx::Insets::TLBR(6, 12, 6, 12);
// Corner radius of the grey background of the textfield.
constexpr int kTextfieldBackgroundCornerRadius = 24;

}  // namespace

AshNotificationInputContainer::AshNotificationInputContainer(
    message_center::NotificationInputDelegate* delegate)
    : message_center::NotificationInputContainer(delegate) {}

AshNotificationInputContainer::~AshNotificationInputContainer() {}

views::BoxLayout* AshNotificationInputContainer::InstallLayoutManager() {
  return SetLayoutManager(std::make_unique<views::BoxLayout>(
      views::BoxLayout::Orientation::kHorizontal, kInsideBorderInsets,
      kBetweenChildSpacing));
}

views::InkDropContainerView* AshNotificationInputContainer::InstallInkDrop() {
  // Do not install an inkdrop.
  return nullptr;
}

gfx::Insets AshNotificationInputContainer::GetTextfieldPadding() const {
  return kInputTextfieldPaddingCrOS;
}

int AshNotificationInputContainer::GetDefaultPlaceholderStringId() const {
  return IDS_ASH_NOTIFICATION_INLINE_REPLY_PLACEHOLDER;
}

void AshNotificationInputContainer::StyleTextfield() {
  views::FocusRing::Install(textfield());
  views::InstallRoundRectHighlightPathGenerator(
      textfield(), gfx::Insets(), kTextfieldBackgroundCornerRadius);
  views::FocusRing::Get(textfield())->SetColorId(ui::kColorAshFocusRing);
}

gfx::Insets AshNotificationInputContainer::GetSendButtonPadding() const {
  return kInputReplyButtonPadding;
}

void AshNotificationInputContainer::SetSendButtonHighlightPath() {
  views::FocusRing::Install(textfield());
  views::InstallRoundRectHighlightPathGenerator(button(), gfx::Insets(),
                                                kInputReplyHighlightRadius);
  views::FocusRing::Get(button())->SetColorId(ui::kColorAshFocusRing);
}

void AshNotificationInputContainer::UpdateButtonImage() {
  if (!GetWidget())
    return;
  UpdateButtonState();
  button()->SetImageModel(
      views::Button::STATE_NORMAL,
      ui::ImageModel::FromVectorIcon(vector_icons::kSendIcon,
                                     cros_tokens::kColorProminent,
                                     kInputReplyButtonSize));
  button()->SetImageModel(
      views::Button::STATE_DISABLED,
      ui::ImageModel::FromVectorIcon(vector_icons::kSendIcon,
                                     cros_tokens::kColorDisabled,
                                     kInputReplyButtonSize));
}

void AshNotificationInputContainer::UpdateButtonState() {
  button()->SetEnabled(!IsInputEmpty());
}

bool AshNotificationInputContainer::IsInputEmpty() {
  return textfield()->GetText().empty();
}

void AshNotificationInputContainer::OnThemeChanged() {
  message_center::NotificationInputContainer::OnThemeChanged();
  UpdateButtonImage();
  SetSendButtonHighlightPath();
  StyleTextfield();

  textfield()->SetTextColor(
      GetColorProvider()->GetColor(cros_tokens::kCrosSysOnSurface));
  textfield()->SetFontList(
      ash::TypographyProvider::Get()->ResolveTypographyToken(
          ash::TypographyToken::kCrosBody2));
  textfield()->set_placeholder_text_color(
      GetColorProvider()->GetColor(cros_tokens::kCrosSysOnSurfaceVariant));
  textfield()->set_placeholder_font_list(
      ash::TypographyProvider::Get()->ResolveTypographyToken(
          ash::TypographyToken::kCrosBody2));

  textfield()->SetBackground(views::CreateRoundedRectBackground(
      GetColorProvider()->GetColor(cros_tokens::kCrosSysSurface),
      kTextfieldBackgroundCornerRadius));
}

}  // namespace ash