ambient_info_view.cc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // Copyright 2020 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/ambient/ui/ambient_info_view.h"
  5. #include <memory>
  6. #include "ash/ambient/ui/ambient_view_delegate.h"
  7. #include "ash/ambient/ui/ambient_view_ids.h"
  8. #include "ash/ambient/ui/glanceable_info_view.h"
  9. #include "ash/ambient/util/ambient_util.h"
  10. #include "ui/base/metadata/metadata_impl_macros.h"
  11. #include "ui/compositor/layer.h"
  12. #include "ui/gfx/geometry/insets.h"
  13. #include "ui/views/controls/label.h"
  14. #include "ui/views/layout/box_layout.h"
  15. #include "ui/views/view_class_properties.h"
  16. namespace ash {
  17. namespace {
  18. // Appearance
  19. constexpr int kMarginDip = 16;
  20. constexpr int kSpacingDip = 8;
  21. // Typography
  22. constexpr int kDefaultFontSizeDip = 64;
  23. constexpr int kDetailsFontSizeDip = 13;
  24. constexpr int kTimeFontSizeDip = 64;
  25. views::Label* AddLabel(views::View* parent) {
  26. auto* label = parent->AddChildView(std::make_unique<views::Label>());
  27. label->SetAutoColorReadabilityEnabled(false);
  28. label->SetEnabledColor(ambient::util::GetContentLayerColor(
  29. AshColorProvider::ContentLayerType::kTextColorSecondary));
  30. label->SetFontList(ambient::util::GetDefaultFontlist().DeriveWithSizeDelta(
  31. kDetailsFontSizeDip - kDefaultFontSizeDip));
  32. label->SetPaintToLayer();
  33. label->layer()->SetFillsBoundsOpaquely(false);
  34. return label;
  35. }
  36. } // namespace
  37. AmbientInfoView::AmbientInfoView(AmbientViewDelegate* delegate)
  38. : delegate_(delegate) {
  39. DCHECK(delegate_);
  40. SetID(AmbientViewID::kAmbientInfoView);
  41. InitLayout();
  42. }
  43. AmbientInfoView::~AmbientInfoView() = default;
  44. void AmbientInfoView::OnThemeChanged() {
  45. views::View::OnThemeChanged();
  46. const auto* color_provider = GetColorProvider();
  47. details_label_->SetShadows(
  48. ambient::util::GetTextShadowValues(color_provider));
  49. related_details_label_->SetShadows(
  50. ambient::util::GetTextShadowValues(color_provider));
  51. }
  52. void AmbientInfoView::UpdateImageDetails(
  53. const std::u16string& details,
  54. const std::u16string& related_details) {
  55. details_label_->SetText(details);
  56. related_details_label_->SetText(related_details);
  57. related_details_label_->SetVisible(!related_details.empty() &&
  58. details != related_details);
  59. }
  60. void AmbientInfoView::SetTextTransform(const gfx::Transform& transform) {
  61. details_label_->layer()->SetTransform(transform);
  62. related_details_label_->layer()->SetTransform(transform);
  63. glanceable_info_view_->layer()->SetTransform(transform);
  64. }
  65. void AmbientInfoView::InitLayout() {
  66. gfx::Insets shadow_insets =
  67. gfx::ShadowValue::GetMargin(ambient::util::GetTextShadowValues(nullptr));
  68. // Full screen view with the glanceable info view and details label in the
  69. // lower left.
  70. views::BoxLayout* layout =
  71. SetLayoutManager(std::make_unique<views::BoxLayout>(
  72. views::BoxLayout::Orientation::kVertical));
  73. layout->set_main_axis_alignment(views::BoxLayout::MainAxisAlignment::kEnd);
  74. layout->set_cross_axis_alignment(
  75. views::BoxLayout::CrossAxisAlignment::kStart);
  76. layout->set_inside_border_insets(
  77. gfx::Insets::TLBR(0, kMarginDip + shadow_insets.left(),
  78. kMarginDip + shadow_insets.bottom(), 0));
  79. layout->set_between_child_spacing(kSpacingDip + shadow_insets.top() +
  80. shadow_insets.bottom());
  81. glanceable_info_view_ = AddChildView(std::make_unique<GlanceableInfoView>(
  82. delegate_, kTimeFontSizeDip, /*time_temperature_font_color=*/
  83. ambient::util::GetContentLayerColor(
  84. AshColorProvider::ContentLayerType::kTextColorPrimary)));
  85. glanceable_info_view_->SetPaintToLayer();
  86. details_label_ = AddLabel(this);
  87. related_details_label_ = AddLabel(this);
  88. }
  89. BEGIN_METADATA(AmbientInfoView, views::View)
  90. END_METADATA
  91. } // namespace ash