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

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

// Copyright 2024 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/conversation_item_view.h"

#include <memory>

#include "ash/public/cpp/rounded_image_view.h"
#include "ash/system/notification_center/message_center_constants.h"
#include "ash/system/notification_center/notification_style_utils.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/text_constants.h"
#include "ui/message_center/public/cpp/notification.h"
#include "ui/message_center/vector_icons.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/flex_layout_view.h"
#include "ui/views/layout/layout_types.h"
#include "ui/views/style/typography.h"
#include "ui/views/view_class_properties.h"

namespace {

constexpr auto kConversationItemViewDefaultMargins =
    gfx::Insets::TLBR(0, 0, 12, 14);
constexpr int kIconSize = 24;

}  // namespace

namespace ash {

ConversationItemView::ConversationItemView(
    const message_center::NotificationItem& notification_item) {
  SetOrientation(views::LayoutOrientation::kHorizontal);
  SetDefault(views::kMarginsKey, kConversationItemViewDefaultMargins);
  auto icon_view = std::make_unique<RoundedImageView>();
  icon_view->SetCornerRadius(kIconSize / 2);
  icon_view->SetImage(
      notification_style_utils::CreateNotificationItemIcon(¬ification_item));
  AddChildView(std::move(icon_view));

  auto title = std::make_unique<views::Label>();
  title->SetText(notification_item.title());
  title->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_LEFT);
  notification_style_utils::ConfigureLabelStyle(
      title.get(), kNotificationTitleLabelSize,
      /*is_color_primary=*/true, gfx::Font::Weight::MEDIUM);

  auto message = std::make_unique<views::Label>();
  message->SetText(notification_item.message());
  message->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_LEFT);
  message->SetTextContext(views::style::CONTEXT_DIALOG_BODY_TEXT);
  message->SetTextStyle(views::style::STYLE_SECONDARY);
  message->SetFontList(gfx::FontList({kGoogleSansFont}, gfx::Font::NORMAL,
                                     kNotificationMessageLabelSize,
                                     gfx::Font::Weight::MEDIUM));
  notification_style_utils::ConfigureLabelStyle(message.get(),
                                                kNotificationMessageLabelSize,
                                                /*is_color_primary=*/false);

  auto label_container = std::make_unique<views::FlexLayoutView>();
  label_container->SetOrientation(views::LayoutOrientation::kVertical);
  label_container->SetMainAxisAlignment(views::LayoutAlignment::kStart);
  label_container->AddChildView(std::move(title));
  label_container->AddChildView(std::move(message));
  AddChildView(std::move(label_container));
}

ConversationItemView::~ConversationItemView() = default;

BEGIN_METADATA(ConversationItemView)
END_METADATA

}  // namespace ash