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 @@ ...@@ -11,6 +11,7 @@
#include "ash/public/cpp/assistant/proactive_suggestions.h" #include "ash/public/cpp/assistant/proactive_suggestions.h"
#include "ash/resources/vector_icons/vector_icons.h" #include "ash/resources/vector_icons/vector_icons.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "ui/display/screen.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/color_palette.h" #include "ui/gfx/color_palette.h"
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
...@@ -20,6 +21,7 @@ ...@@ -20,6 +21,7 @@
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
#include "ui/views/vector_icons.h" #include "ui/views/vector_icons.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
#include "ui/wm/core/window_animations.h"
namespace ash { namespace ash {
...@@ -40,11 +42,18 @@ ProactiveSuggestionsView::ProactiveSuggestionsView( ...@@ -40,11 +42,18 @@ ProactiveSuggestionsView::ProactiveSuggestionsView(
InitLayout(); InitLayout();
InitWidget(); 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); delegate_->AddUiModelObserver(this);
} }
ProactiveSuggestionsView::~ProactiveSuggestionsView() { ProactiveSuggestionsView::~ProactiveSuggestionsView() {
delegate_->RemoveUiModelObserver(this); delegate_->RemoveUiModelObserver(this);
if (GetWidget() && GetWidget()->GetNativeWindow())
GetWidget()->GetNativeWindow()->RemoveObserver(this);
} }
const char* ProactiveSuggestionsView::GetClassName() const { const char* ProactiveSuggestionsView::GetClassName() const {
...@@ -90,6 +99,36 @@ void ProactiveSuggestionsView::OnUsableWorkAreaChanged( ...@@ -90,6 +99,36 @@ void ProactiveSuggestionsView::OnUsableWorkAreaChanged(
UpdateBounds(); 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() { void ProactiveSuggestionsView::InitLayout() {
views::BoxLayout* layout_manager = views::BoxLayout* layout_manager =
SetLayoutManager(std::make_unique<views::BoxLayout>( SetLayoutManager(std::make_unique<views::BoxLayout>(
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define ASH_ASSISTANT_UI_PROACTIVE_SUGGESTIONS_VIEW_H_ #define ASH_ASSISTANT_UI_PROACTIVE_SUGGESTIONS_VIEW_H_
#include "ash/assistant/model/assistant_ui_model_observer.h" #include "ash/assistant/model/assistant_ui_model_observer.h"
#include "ui/aura/window_observer.h"
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
namespace views { namespace views {
...@@ -20,7 +21,8 @@ class AssistantViewDelegate; ...@@ -20,7 +21,8 @@ class AssistantViewDelegate;
class COMPONENT_EXPORT(ASSISTANT_UI) ProactiveSuggestionsView class COMPONENT_EXPORT(ASSISTANT_UI) ProactiveSuggestionsView
: public views::Button, : public views::Button,
public views::ButtonListener, public views::ButtonListener,
public AssistantUiModelObserver { public AssistantUiModelObserver,
public aura::WindowObserver {
public: public:
explicit ProactiveSuggestionsView(AssistantViewDelegate* delegate); explicit ProactiveSuggestionsView(AssistantViewDelegate* delegate);
~ProactiveSuggestionsView() override; ~ProactiveSuggestionsView() override;
...@@ -37,6 +39,10 @@ class COMPONENT_EXPORT(ASSISTANT_UI) ProactiveSuggestionsView ...@@ -37,6 +39,10 @@ class COMPONENT_EXPORT(ASSISTANT_UI) ProactiveSuggestionsView
// AssistantUiModelObserver: // AssistantUiModelObserver:
void OnUsableWorkAreaChanged(const gfx::Rect& usable_work_area) override; 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: private:
void InitLayout(); void InitLayout();
void InitWidget(); 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