Commit 5743dbdd authored by David Black's avatar David Black Committed by Commit Bot

Animate Assistant container growth/shrink.

Motion spec still being delivered by UX but this should be a step in
the right direction and removes a lot of our existing jank.

Note: We still have yet to crossfade between mini/main/web states.

Also revised some AssistantMiniView metrics per the spec.

See bug for demo.

Bug: b:112487675
Change-Id: I9cecb3afdd7d5e85e04d8ef95a25e5dfdd263c91
Reviewed-on: https://chromium-review.googlesource.com/1171952
Commit-Queue: David Black <dmblack@google.com>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582624}
parent 7400e88b
......@@ -11,11 +11,14 @@
#include "ash/assistant/model/assistant_ui_model.h"
#include "ash/assistant/ui/assistant_main_view.h"
#include "ash/assistant/ui/assistant_mini_view.h"
#include "ash/assistant/ui/assistant_ui_constants.h"
#include "ash/assistant/ui/assistant_web_view.h"
#include "ash/shell.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/gfx/animation/slide_animation.h"
#include "ui/gfx/animation/tween.h"
#include "ui/views/bubble/bubble_dialog_delegate.h"
#include "ui/views/bubble/bubble_frame_view.h"
#include "ui/views/layout/layout_manager.h"
......@@ -31,6 +34,9 @@ constexpr SkColor kBackgroundColor = SK_ColorWHITE;
constexpr int kCornerRadiusDip = 20;
constexpr int kMarginDip = 8;
// Animation.
constexpr int kResizeAnimationDurationMs = 250;
// AssistantContainerLayout ----------------------------------------------------
// The AssistantContainerLayout calculates preferred size to fit the largest
......@@ -137,10 +143,30 @@ void AssistantContainerView::ChildPreferredSizeChanged(views::View* child) {
}
void AssistantContainerView::PreferredSizeChanged() {
views::View::PreferredSizeChanged();
if (!GetWidget())
return;
const bool visible =
assistant_controller_->ui_controller()->model()->visible();
// When visible with the motion spec enabled, size changes are animated.
if (visible && assistant::ui::kIsMotionSpecEnabled) {
resize_animation_ = std::make_unique<gfx::SlideAnimation>(this);
resize_animation_->SetSlideDuration(kResizeAnimationDurationMs);
// Cache start and end animation values.
resize_start_ = gfx::SizeF(size());
resize_end_ = gfx::SizeF(GetPreferredSize());
if (GetWidget())
SizeToContents();
// Start animation.
resize_animation_->Show();
return;
}
// Clear any existing animation.
resize_animation_.reset();
SizeToContents();
}
int AssistantContainerView::GetDialogButtons() const {
......@@ -170,6 +196,11 @@ void AssistantContainerView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
void AssistantContainerView::Init() {
SetLayoutManager(std::make_unique<AssistantContainerLayout>());
// We need to paint to our own layer so we can clip child layers.
SetPaintToLayer();
layer()->SetFillsBoundsOpaquely(false);
layer()->SetMasksToBounds(true);
// Main view.
assistant_main_view_ = new AssistantMainView(assistant_controller_);
AddChildView(assistant_main_view_);
......@@ -242,4 +273,33 @@ void AssistantContainerView::OnUiModeChanged(AssistantUiMode ui_mode) {
RequestFocus();
}
// TODO(dmblack): Improve performance of this animation using transformations
// for GPU acceleration. Lower spec hardware may struggle with numerous layouts.
void AssistantContainerView::AnimationProgressed(
const gfx::Animation* animation) {
if (!GetWidget())
return;
// Retrieve current bounds.
gfx::Rect bounds = GetWidget()->GetWindowBoundsInScreen();
// Our view is horizontally centered and bottom aligned. As such, we should
// retain the same |bottom| and |center_x| position after resizing.
const int bottom = bounds.bottom();
const int center_x = bounds.CenterPoint().x();
// Interpolate size at our current animation value.
const gfx::SizeF size = gfx::Tween::SizeValueBetween(
animation->GetCurrentValue(), resize_start_, resize_end_);
// Use our interpolated size.
bounds.set_size(gfx::Size(size.width(), size.height()));
// Maintain our original |bottom| and |center_x| positions.
bounds.set_x(center_x - (bounds.width() / 2));
bounds.set_y(bottom - bounds.height());
GetWidget()->SetBounds(bounds);
}
} // namespace ash
......@@ -7,8 +7,13 @@
#include "ash/assistant/model/assistant_ui_model_observer.h"
#include "base/macros.h"
#include "ui/gfx/animation/animation_delegate.h"
#include "ui/views/bubble/bubble_dialog_delegate.h"
namespace gfx {
class SlideAnimation;
} // namespace gfx
namespace ash {
class AssistantController;
......@@ -17,7 +22,8 @@ class AssistantMiniView;
class AssistantWebView;
class AssistantContainerView : public views::BubbleDialogDelegateView,
public AssistantUiModelObserver {
public AssistantUiModelObserver,
public gfx::AnimationDelegate {
public:
explicit AssistantContainerView(AssistantController* assistant_controller);
~AssistantContainerView() override;
......@@ -35,6 +41,9 @@ class AssistantContainerView : public views::BubbleDialogDelegateView,
// AssistantUiModelObserver:
void OnUiModeChanged(AssistantUiMode ui_mode) override;
// gfx::AnimationDelegate:
void AnimationProgressed(const gfx::Animation* animation) override;
private:
void SetAnchor();
......@@ -44,6 +53,10 @@ class AssistantContainerView : public views::BubbleDialogDelegateView,
AssistantMiniView* assistant_mini_view_; // Owned by view hierarchy.
AssistantWebView* assistant_web_view_; // Owned by view hierarchy.
std::unique_ptr<gfx::SlideAnimation> resize_animation_;
gfx::SizeF resize_start_;
gfx::SizeF resize_end_;
DISALLOW_COPY_AND_ASSIGN(AssistantContainerView);
};
......
......@@ -25,10 +25,10 @@ namespace ash {
namespace {
// Appearance.
constexpr int kIconSizeDip = 20;
constexpr int kLineHeightDip = 20;
constexpr int kIconSizeDip = 24;
constexpr int kLineHeightDip = 24;
constexpr int kMaxWidthDip = 512;
constexpr int kPaddingLeftDip = 14;
constexpr int kPaddingLeftDip = 12;
constexpr int kPaddingRightDip = 24;
constexpr int kPreferredHeightDip = 48;
......@@ -85,8 +85,9 @@ void AssistantMiniView::InitLayout() {
// Label.
label_->SetAutoColorReadabilityEnabled(false);
label_->SetEnabledColor(kTextColorPrimary);
label_->SetFontList(
assistant::ui::GetDefaultFontList().DeriveWithSizeDelta(1));
label_->SetFontList(assistant::ui::GetDefaultFontList()
.DeriveWithSizeDelta(1)
.DeriveWithWeight(gfx::Font::Weight::MEDIUM));
label_->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_LEFT);
label_->SetLineHeight(kLineHeightDip);
AddChildView(label_);
......
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