Commit 7c172c14 authored by Jeffrey Young's avatar Jeffrey Young Committed by Chromium LUCI CQ

ambient: refactor ambient_background_image_view

Split informational text view out from main ambient image view.
Create new class AmbientInfoView.

BUG=none

Cq-Include-Trybots: luci.chrome.try:linux-chromeos-chrome
Change-Id: I55e96ae26093568cd3bbe4bfb238da2272a217b4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2566632
Commit-Queue: Jeffrey Young <cowmoo@chromium.org>
Reviewed-by: default avatarTao Wu <wutao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833420}
parent 2481bb1c
......@@ -203,6 +203,8 @@ component("ash") {
"ambient/ui/ambient_background_image_view.h",
"ambient/ui/ambient_container_view.cc",
"ambient/ui/ambient_container_view.h",
"ambient/ui/ambient_info_view.cc",
"ambient/ui/ambient_info_view.h",
"ambient/ui/ambient_view_delegate.h",
"ambient/ui/ambient_view_ids.h",
"ambient/ui/assistant_response_container_view.cc",
......
......@@ -7,8 +7,8 @@
#include <memory>
#include "ash/ambient/ambient_constants.h"
#include "ash/ambient/ui/ambient_info_view.h"
#include "ash/ambient/ui/ambient_view_ids.h"
#include "ash/ambient/ui/glanceable_info_view.h"
#include "ash/ambient/ui/media_string_view.h"
#include "ash/ambient/util/ambient_util.h"
#include "base/rand_util.h"
......@@ -16,7 +16,6 @@
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/layout/flex_layout.h"
......@@ -29,15 +28,8 @@ namespace ash {
namespace {
// Appearance.
constexpr int kMarginDip = 16;
constexpr int kSpacingDip = 8;
constexpr int kMediaStringMarginDip = 32;
// Typography.
constexpr SkColor kTextColor = SK_ColorWHITE;
constexpr int kDefaultFontSizeDip = 64;
constexpr int kDetailsFontSizeDip = 13;
// The dicretion to translate glanceable info views in the x/y coordinates. `1`
// means positive translate, `-1` negative.
int translate_x_direction = 1;
......@@ -126,7 +118,7 @@ void AmbientBackgroundImageView::UpdateImage(
void AmbientBackgroundImageView::UpdateImageDetails(
const base::string16& details) {
details_label_->SetText(details);
ambient_info_view_->UpdateImageDetails(details);
}
const gfx::ImageSkia& AmbientBackgroundImageView::GetCurrentImage() {
......@@ -181,42 +173,12 @@ void AmbientBackgroundImageView::InitLayout() {
related_image_view_->SetProperty(
views::kMarginsKey, gfx::Insets(0, kMarginLeftOfRelatedImageDip, 0, 0));
ambient_info_view_ =
AddChildView(std::make_unique<AmbientInfoView>(delegate_));
gfx::Insets shadow_insets =
gfx::ShadowValue::GetMargin(ambient::util::GetTextShadowValues());
// Inits the attribution view. It also has a full-screen size and is
// responsible for layout the details label at its bottom left corner.
views::View* attribution_view = AddChildView(std::make_unique<views::View>());
views::BoxLayout* attribution_layout =
attribution_view->SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical));
attribution_layout->set_main_axis_alignment(
views::BoxLayout::MainAxisAlignment::kEnd);
attribution_layout->set_cross_axis_alignment(
views::BoxLayout::CrossAxisAlignment::kStart);
attribution_layout->set_inside_border_insets(
gfx::Insets(0, kMarginDip + shadow_insets.left(),
kMarginDip + shadow_insets.bottom(), 0));
attribution_layout->set_between_child_spacing(
kSpacingDip + shadow_insets.top() + shadow_insets.bottom());
glanceable_info_view_ = attribution_view->AddChildView(
std::make_unique<GlanceableInfoView>(delegate_));
glanceable_info_view_->SetPaintToLayer();
// Inits the details label.
details_label_ =
attribution_view->AddChildView(std::make_unique<views::Label>());
details_label_->SetAutoColorReadabilityEnabled(false);
details_label_->SetEnabledColor(kTextColor);
details_label_->SetFontList(
ambient::util::GetDefaultFontlist().DeriveWithSizeDelta(
kDetailsFontSizeDip - kDefaultFontSizeDip));
details_label_->SetShadows(ambient::util::GetTextShadowValues());
details_label_->SetPaintToLayer();
details_label_->layer()->SetFillsBoundsOpaquely(false);
// Inits the media string view. The media string view is positioned on the
// right-top corner of the container.
views::View* media_string_view_container_ =
......@@ -267,8 +229,7 @@ void AmbientBackgroundImageView::UpdateGlanceableInfoPosition() {
gfx::Transform transform;
transform.Translate(current_x_translation, current_y_translation);
glanceable_info_view_->layer()->SetTransform(transform);
details_label_->layer()->SetTransform(transform);
ambient_info_view_->SetTextTransform(transform);
if (media_string_view_->GetVisible()) {
gfx::Transform media_string_transform;
......
......@@ -15,13 +15,9 @@
#include "ui/views/view.h"
#include "ui/views/view_observer.h"
namespace views {
class Label;
} // namespace views
namespace ash {
class GlanceableInfoView;
class AmbientInfoView;
class MediaStringView;
// AmbientBackgroundImageView--------------------------------------------------
......@@ -83,11 +79,7 @@ class ASH_EXPORT AmbientBackgroundImageView : public views::View,
gfx::ImageSkia image_unscaled_;
gfx::ImageSkia related_image_unscaled_;
GlanceableInfoView* glanceable_info_view_ = nullptr;
// Label to show details text, i.e. attribution, to be displayed for the
// current image. Owned by the view hierarchy.
views::Label* details_label_ = nullptr;
AmbientInfoView* ambient_info_view_ = nullptr;
MediaStringView* media_string_view_ = nullptr;
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/ambient/ui/ambient_info_view.h"
#include <memory>
#include "ash/ambient/ui/ambient_view_delegate.h"
#include "ash/ambient/ui/ambient_view_ids.h"
#include "ash/ambient/ui/glanceable_info_view.h"
#include "ash/ambient/util/ambient_util.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/metadata/metadata_impl_macros.h"
#include "ui/views/view_class_properties.h"
namespace ash {
namespace {
// Appearance
constexpr int kMarginDip = 16;
constexpr int kSpacingDip = 8;
// Typography
constexpr SkColor kTextColor = SK_ColorWHITE;
constexpr int kDefaultFontSizeDip = 64;
constexpr int kDetailsFontSizeDip = 13;
} // namespace
AmbientInfoView::AmbientInfoView(AmbientViewDelegate* delegate)
: delegate_(delegate) {
DCHECK(delegate_);
SetID(AmbientViewID::kAmbientInfoView);
InitLayout();
}
AmbientInfoView::~AmbientInfoView() = default;
void AmbientInfoView::UpdateImageDetails(const base::string16& details) {
details_label_->SetText(details);
}
void AmbientInfoView::SetTextTransform(const gfx::Transform& transform) {
details_label_->layer()->SetTransform(transform);
glanceable_info_view_->layer()->SetTransform(transform);
}
void AmbientInfoView::InitLayout() {
gfx::Insets shadow_insets =
gfx::ShadowValue::GetMargin(ambient::util::GetTextShadowValues());
// Full screen view with the glanceable info view and details label in the
// lower left.
views::BoxLayout* layout =
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical));
layout->set_main_axis_alignment(views::BoxLayout::MainAxisAlignment::kEnd);
layout->set_cross_axis_alignment(
views::BoxLayout::CrossAxisAlignment::kStart);
layout->set_inside_border_insets(
gfx::Insets(0, kMarginDip + shadow_insets.left(),
kMarginDip + shadow_insets.bottom(), 0));
layout->set_between_child_spacing(kSpacingDip + shadow_insets.top() +
shadow_insets.bottom());
glanceable_info_view_ =
AddChildView(std::make_unique<GlanceableInfoView>(delegate_));
glanceable_info_view_->SetPaintToLayer();
details_label_ = AddChildView(std::make_unique<views::Label>());
details_label_->SetAutoColorReadabilityEnabled(false);
details_label_->SetEnabledColor(kTextColor);
details_label_->SetFontList(
ambient::util::GetDefaultFontlist().DeriveWithSizeDelta(
kDetailsFontSizeDip - kDefaultFontSizeDip));
details_label_->SetShadows(ambient::util::GetTextShadowValues());
details_label_->SetPaintToLayer();
details_label_->layer()->SetFillsBoundsOpaquely(false);
}
BEGIN_METADATA(AmbientInfoView, views::View)
END_METADATA
} // namespace ash
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_AMBIENT_UI_AMBIENT_INFO_VIEW_H_
#define ASH_AMBIENT_UI_AMBIENT_INFO_VIEW_H_
#include "ash/ambient/ui/ambient_view_delegate.h"
#include "ash/ash_export.h"
#include "ui/views/metadata/metadata_header_macros.h"
#include "ui/views/view.h"
namespace gfx {
class Transform;
}
namespace views {
class Label;
} // namespace views
namespace ash {
class GlanceableInfoView;
class ASH_EXPORT AmbientInfoView : public views::View {
public:
METADATA_HEADER(AmbientInfoView);
explicit AmbientInfoView(AmbientViewDelegate* delegate);
AmbientInfoView(const AmbientInfoView&) = delete;
AmbientInfoView& operator=(AmbientInfoView&) = delete;
~AmbientInfoView() override;
void UpdateImageDetails(const base::string16& details);
void SetTextTransform(const gfx::Transform& transform);
private:
void InitLayout();
// Owned by |AmbientController| and should always outlive |this|.
AmbientViewDelegate* delegate_ = nullptr;
GlanceableInfoView* glanceable_info_view_ = nullptr;
views::Label* details_label_ = nullptr;
};
} // namespace ash
#endif // ASH_AMBIENT_UI_AMBIENT_INFO_VIEW_H_
......@@ -21,6 +21,7 @@ enum AmbientViewID {
kAmbientGlanceableInfoView,
kAmbientAssistantDialogPlate,
kAmbientMediaStringView,
kAmbientInfoView,
};
} // namespace ash
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment