Commit b92b6294 authored by David Black's avatar David Black Committed by Commit Bot

Implemented entry/exit animations for proactive suggestions.

Entry animation: Translate up from offscreen.
Exit animation: Fade out.

See bug for demo.

Bug: b:139199754
Change-Id: Ib32f3bf0eaf19577cd1da2e9e28285a4d96bec53
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1769841Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Commit-Queue: David Black <dmblack@google.com>
Cr-Commit-Position: refs/heads/master@{#690907}
parent 89c6f2bf
......@@ -11,6 +11,7 @@
#include "ash/public/cpp/assistant/proactive_suggestions.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/display/screen.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/paint_vector_icon.h"
......@@ -20,6 +21,7 @@
#include "ui/views/layout/box_layout.h"
#include "ui/views/vector_icons.h"
#include "ui/views/widget/widget.h"
#include "ui/wm/core/window_animations.h"
namespace ash {
......@@ -40,11 +42,18 @@ ProactiveSuggestionsView::ProactiveSuggestionsView(
InitLayout();
InitWidget();
// We observe the proactive suggestions window in order to modify entry/exit
// animation behavior prior to window visibility changes.
GetWidget()->GetNativeWindow()->AddObserver(this);
delegate_->AddUiModelObserver(this);
}
ProactiveSuggestionsView::~ProactiveSuggestionsView() {
delegate_->RemoveUiModelObserver(this);
if (GetWidget() && GetWidget()->GetNativeWindow())
GetWidget()->GetNativeWindow()->RemoveObserver(this);
}
const char* ProactiveSuggestionsView::GetClassName() const {
......@@ -90,6 +99,36 @@ void ProactiveSuggestionsView::OnUsableWorkAreaChanged(
UpdateBounds();
}
void ProactiveSuggestionsView::OnWindowDestroying(aura::Window* window) {
window->RemoveObserver(this);
}
void ProactiveSuggestionsView::OnWindowVisibilityChanging(aura::Window* window,
bool visible) {
if (!visible) {
// When exiting, the proactive suggestions window fades out.
wm::SetWindowVisibilityAnimationType(
window, wm::WindowVisibilityAnimationType::
WINDOW_VISIBILITY_ANIMATION_TYPE_FADE);
return;
}
// When entering, the proactive suggestions window translates in vertically.
wm::SetWindowVisibilityAnimationType(
window, wm::WindowVisibilityAnimationType::
WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL);
// The vertical position is equal to the distance from the top of the
// proactive suggestions view to the bottom of the screen. This gives the
// effect of animating the proactive suggestions window up from offscreen.
wm::SetWindowVisibilityAnimationVerticalPosition(
window, display::Screen::GetScreen()
->GetDisplayNearestWindow(window)
.bounds()
.bottom() -
GetBoundsInScreen().y());
}
void ProactiveSuggestionsView::InitLayout() {
views::BoxLayout* layout_manager =
SetLayoutManager(std::make_unique<views::BoxLayout>(
......
......@@ -6,6 +6,7 @@
#define ASH_ASSISTANT_UI_PROACTIVE_SUGGESTIONS_VIEW_H_
#include "ash/assistant/model/assistant_ui_model_observer.h"
#include "ui/aura/window_observer.h"
#include "ui/views/controls/button/button.h"
namespace views {
......@@ -20,7 +21,8 @@ class AssistantViewDelegate;
class COMPONENT_EXPORT(ASSISTANT_UI) ProactiveSuggestionsView
: public views::Button,
public views::ButtonListener,
public AssistantUiModelObserver {
public AssistantUiModelObserver,
public aura::WindowObserver {
public:
explicit ProactiveSuggestionsView(AssistantViewDelegate* delegate);
~ProactiveSuggestionsView() override;
......@@ -37,6 +39,10 @@ class COMPONENT_EXPORT(ASSISTANT_UI) ProactiveSuggestionsView
// AssistantUiModelObserver:
void OnUsableWorkAreaChanged(const gfx::Rect& usable_work_area) override;
// aura::WindowObserver:
void OnWindowDestroying(aura::Window* window) override;
void OnWindowVisibilityChanging(aura::Window* window, bool visible) override;
private:
void InitLayout();
void InitWidget();
......
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