Commit 672d71b4 authored by Alan Cutter's avatar Alan Cutter Committed by Commit Bot

Add menu button highlight animation to origin title animation for hosted apps

This CL adds a menu button highlight animation to run along side the origin
title bar text animation for hosted apps added in:
https://chromium-review.googlesource.com/c/chromium/src/+/942722

Screencast: https://bugs.chromium.org/p/chromium/issues/attachment?aid=327708&signed_aid=U4VyDkrKmEzMN56O5woqsw==&inline=1

Bug: 809794
Change-Id: I7ed8a7c9ccbf2c020bd9c76fb04f2a3123f265de
Reviewed-on: https://chromium-review.googlesource.com/958899Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarMohsen Izadi <mohsen@chromium.org>
Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Commit-Queue: Alan Cutter <alancutter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543569}
parent b9c7a7e3
...@@ -2228,6 +2228,15 @@ class InkDropSpy : public views::InkDrop { ...@@ -2228,6 +2228,15 @@ class InkDropSpy : public views::InkDrop {
requested_states_.push_back(ink_drop_state); requested_states_.push_back(ink_drop_state);
ink_drop_->AnimateToState(ink_drop_state); ink_drop_->AnimateToState(ink_drop_state);
} }
void SetHoverHighlightFadeDurationMs(int duration_ms) override {
ink_drop_->SetHoverHighlightFadeDurationMs(duration_ms);
}
void UseDefaultHoverHighlightFadeDuration() override {
ink_drop_->UseDefaultHoverHighlightFadeDuration();
}
void SnapToActivated() override { ink_drop_->SnapToActivated(); } void SnapToActivated() override { ink_drop_->SnapToActivated(); }
void SnapToHidden() override { ink_drop_->SnapToHidden(); } void SnapToHidden() override { ink_drop_->SnapToHidden(); }
void SetHovered(bool is_hovered) override { void SetHovered(bool is_hovered) override {
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "ui/gfx/color_palette.h" #include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h" #include "ui/gfx/color_utils.h"
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
#include "ui/views/animation/ink_drop.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
#include "ui/views/widget/native_widget_aura.h" #include "ui/views/widget/native_widget_aura.h"
...@@ -33,6 +34,8 @@ namespace { ...@@ -33,6 +34,8 @@ namespace {
// Padding around content setting icons. // Padding around content setting icons.
constexpr int kContentSettingIconInteriorPadding = 4; constexpr int kContentSettingIconInteriorPadding = 4;
constexpr int kMenuHighlightFadeDurationMs = 800;
constexpr base::TimeDelta kContentSettingsFadeInDuration = constexpr base::TimeDelta kContentSettingsFadeInDuration =
base::TimeDelta::FromMilliseconds(500); base::TimeDelta::FromMilliseconds(500);
...@@ -183,11 +186,34 @@ void HostedAppButtonContainer::AppMenuButton::OnMenuButtonClicked( ...@@ -183,11 +186,34 @@ void HostedAppButtonContainer::AppMenuButton::OnMenuButtonClicked(
void HostedAppButtonContainer::StartTitlebarAnimation( void HostedAppButtonContainer::StartTitlebarAnimation(
base::TimeDelta origin_text_slide_duration) { base::TimeDelta origin_text_slide_duration) {
app_menu_button_->StartHighlightAnimation(origin_text_slide_duration);
fade_in_content_setting_buttons_timer_.Start( fade_in_content_setting_buttons_timer_.Start(
FROM_HERE, origin_text_slide_duration, content_settings_container_, FROM_HERE, origin_text_slide_duration, content_settings_container_,
&ContentSettingsContainer::FadeIn); &ContentSettingsContainer::FadeIn);
} }
void HostedAppButtonContainer::AppMenuButton::StartHighlightAnimation(
base::TimeDelta duration) {
GetInkDrop()->SetHoverHighlightFadeDurationMs(kMenuHighlightFadeDurationMs);
GetInkDrop()->SetHovered(true);
GetInkDrop()->UseDefaultHoverHighlightFadeDuration();
highlight_off_timer_.Start(
FROM_HERE,
duration -
base::TimeDelta::FromMilliseconds(kMenuHighlightFadeDurationMs),
this, &HostedAppButtonContainer::AppMenuButton::FadeHighlightOff);
}
void HostedAppButtonContainer::AppMenuButton::FadeHighlightOff() {
if (!ShouldEnterHoveredState()) {
GetInkDrop()->SetHoverHighlightFadeDurationMs(kMenuHighlightFadeDurationMs);
GetInkDrop()->SetHovered(false);
GetInkDrop()->UseDefaultHoverHighlightFadeDuration();
}
}
HostedAppButtonContainer::HostedAppButtonContainer(BrowserView* browser_view, HostedAppButtonContainer::HostedAppButtonContainer(BrowserView* browser_view,
SkColor active_icon_color, SkColor active_icon_color,
SkColor inactive_icon_color) SkColor inactive_icon_color)
......
...@@ -66,7 +66,12 @@ class HostedAppButtonContainer : public views::View, ...@@ -66,7 +66,12 @@ class HostedAppButtonContainer : public views::View,
AppMenu* menu() { return menu_.get(); } AppMenu* menu() { return menu_.get(); }
// Fades the menu button highlight on and off.
void StartHighlightAnimation(base::TimeDelta duration);
private: private:
void FadeHighlightOff();
// The containing browser view. // The containing browser view.
BrowserView* browser_view_; BrowserView* browser_view_;
...@@ -76,6 +81,8 @@ class HostedAppButtonContainer : public views::View, ...@@ -76,6 +81,8 @@ class HostedAppButtonContainer : public views::View,
std::unique_ptr<HostedAppMenuModel> menu_model_; std::unique_ptr<HostedAppMenuModel> menu_model_;
std::unique_ptr<AppMenu> menu_; std::unique_ptr<AppMenu> menu_;
base::OneShotTimer highlight_off_timer_;
DISALLOW_COPY_AND_ASSIGN(AppMenuButton); DISALLOW_COPY_AND_ASSIGN(AppMenuButton);
}; };
......
...@@ -36,6 +36,14 @@ class VIEWS_EXPORT InkDrop { ...@@ -36,6 +36,14 @@ class VIEWS_EXPORT InkDrop {
// Animates from the current InkDropState to |ink_drop_state|. // Animates from the current InkDropState to |ink_drop_state|.
virtual void AnimateToState(InkDropState ink_drop_state) = 0; virtual void AnimateToState(InkDropState ink_drop_state) = 0;
// Sets hover highlight fade animations to last for |duration_ms|
// milliseconds.
virtual void SetHoverHighlightFadeDurationMs(int duration_ms) = 0;
// Clears any set hover highlight fade durations and uses the default
// durations instead.
virtual void UseDefaultHoverHighlightFadeDuration() = 0;
// Immediately snaps the InkDropState to ACTIVATED and HIDDEN specifically. // Immediately snaps the InkDropState to ACTIVATED and HIDDEN specifically.
// These are more specific implementations of the non-existent // These are more specific implementations of the non-existent
// SnapToState(InkDropState) function are the only ones available because they // SnapToState(InkDropState) function are the only ones available because they
......
...@@ -171,11 +171,15 @@ void InkDropImpl::NoAutoHighlightHiddenState::Enter() { ...@@ -171,11 +171,15 @@ void InkDropImpl::NoAutoHighlightHiddenState::Enter() {
} }
void InkDropImpl::NoAutoHighlightHiddenState::ShowOnHoverChanged() { void InkDropImpl::NoAutoHighlightHiddenState::ShowOnHoverChanged() {
HandleHoverAndFocusChangeChanges(kHighlightFadeInOnHoverChangeDurationMs); HandleHoverAndFocusChangeChanges(
GetInkDrop()->hover_highlight_fade_duration_ms().value_or(
kHighlightFadeInOnHoverChangeDurationMs));
} }
void InkDropImpl::NoAutoHighlightHiddenState::OnHoverChanged() { void InkDropImpl::NoAutoHighlightHiddenState::OnHoverChanged() {
HandleHoverAndFocusChangeChanges(kHighlightFadeInOnHoverChangeDurationMs); HandleHoverAndFocusChangeChanges(
GetInkDrop()->hover_highlight_fade_duration_ms().value_or(
kHighlightFadeInOnHoverChangeDurationMs));
} }
void InkDropImpl::NoAutoHighlightHiddenState::ShowOnFocusChanged() { void InkDropImpl::NoAutoHighlightHiddenState::ShowOnFocusChanged() {
...@@ -216,11 +220,15 @@ void InkDropImpl::NoAutoHighlightVisibleState::Enter() { ...@@ -216,11 +220,15 @@ void InkDropImpl::NoAutoHighlightVisibleState::Enter() {
} }
void InkDropImpl::NoAutoHighlightVisibleState::ShowOnHoverChanged() { void InkDropImpl::NoAutoHighlightVisibleState::ShowOnHoverChanged() {
HandleHoverAndFocusChangeChanges(kHighlightFadeOutOnHoverChangeDurationMs); HandleHoverAndFocusChangeChanges(
GetInkDrop()->hover_highlight_fade_duration_ms().value_or(
kHighlightFadeOutOnHoverChangeDurationMs));
} }
void InkDropImpl::NoAutoHighlightVisibleState::OnHoverChanged() { void InkDropImpl::NoAutoHighlightVisibleState::OnHoverChanged() {
HandleHoverAndFocusChangeChanges(kHighlightFadeOutOnHoverChangeDurationMs); HandleHoverAndFocusChangeChanges(
GetInkDrop()->hover_highlight_fade_duration_ms().value_or(
kHighlightFadeOutOnHoverChangeDurationMs));
} }
void InkDropImpl::NoAutoHighlightVisibleState::ShowOnFocusChanged() { void InkDropImpl::NoAutoHighlightVisibleState::ShowOnFocusChanged() {
...@@ -647,6 +655,14 @@ void InkDropImpl::AnimateToState(InkDropState ink_drop_state) { ...@@ -647,6 +655,14 @@ void InkDropImpl::AnimateToState(InkDropState ink_drop_state) {
ink_drop_ripple_->AnimateToState(ink_drop_state); ink_drop_ripple_->AnimateToState(ink_drop_state);
} }
void InkDropImpl::SetHoverHighlightFadeDurationMs(int duration_ms) {
hover_highlight_fade_duration_ms_ = duration_ms;
}
void InkDropImpl::UseDefaultHoverHighlightFadeDuration() {
hover_highlight_fade_duration_ms_.reset();
}
void InkDropImpl::SnapToActivated() { void InkDropImpl::SnapToActivated() {
DestroyHiddenTargetedAnimations(); DestroyHiddenTargetedAnimations();
if (!ink_drop_ripple_) if (!ink_drop_ripple_)
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <memory> #include <memory>
#include "base/macros.h" #include "base/macros.h"
#include "base/optional.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#include "ui/views/animation/ink_drop.h" #include "ui/views/animation/ink_drop.h"
...@@ -66,10 +67,16 @@ class VIEWS_EXPORT InkDropImpl : public InkDrop, ...@@ -66,10 +67,16 @@ class VIEWS_EXPORT InkDropImpl : public InkDrop,
// set to SHOW_ON_RIPPLE highlight behavior. // set to SHOW_ON_RIPPLE highlight behavior.
void SetAutoHighlightModeForPlatform(); void SetAutoHighlightModeForPlatform();
const base::Optional<int>& hover_highlight_fade_duration_ms() const {
return hover_highlight_fade_duration_ms_;
}
// InkDrop: // InkDrop:
void HostSizeChanged(const gfx::Size& new_size) override; void HostSizeChanged(const gfx::Size& new_size) override;
InkDropState GetTargetInkDropState() const override; InkDropState GetTargetInkDropState() const override;
void AnimateToState(InkDropState ink_drop_state) override; void AnimateToState(InkDropState ink_drop_state) override;
void SetHoverHighlightFadeDurationMs(int duration_ms) override;
void UseDefaultHoverHighlightFadeDuration() override;
void SnapToActivated() override; void SnapToActivated() override;
void SnapToHidden() override; void SnapToHidden() override;
void SetHovered(bool is_hovered) override; void SetHovered(bool is_hovered) override;
...@@ -306,6 +313,9 @@ class VIEWS_EXPORT InkDropImpl : public InkDrop, ...@@ -306,6 +313,9 @@ class VIEWS_EXPORT InkDropImpl : public InkDrop,
// of the |highlight_|. // of the |highlight_|.
std::unique_ptr<HighlightState> highlight_state_; std::unique_ptr<HighlightState> highlight_state_;
// Overrides the default hover highlight fade durations when set.
base::Optional<int> hover_highlight_fade_duration_ms_;
// Used to ensure highlight state transitions are not triggered when exiting // Used to ensure highlight state transitions are not triggered when exiting
// the current state. // the current state.
bool exiting_highlight_state_; bool exiting_highlight_state_;
......
...@@ -18,6 +18,10 @@ InkDropState InkDropStub::GetTargetInkDropState() const { ...@@ -18,6 +18,10 @@ InkDropState InkDropStub::GetTargetInkDropState() const {
void InkDropStub::AnimateToState(InkDropState state) {} void InkDropStub::AnimateToState(InkDropState state) {}
void InkDropStub::SetHoverHighlightFadeDurationMs(int duration_ms) {}
void InkDropStub::UseDefaultHoverHighlightFadeDuration() {}
void InkDropStub::SnapToActivated() {} void InkDropStub::SnapToActivated() {}
void InkDropStub::SnapToHidden() {} void InkDropStub::SnapToHidden() {}
......
...@@ -22,6 +22,8 @@ class VIEWS_EXPORT InkDropStub : public InkDrop { ...@@ -22,6 +22,8 @@ class VIEWS_EXPORT InkDropStub : public InkDrop {
void HostSizeChanged(const gfx::Size& new_size) override; void HostSizeChanged(const gfx::Size& new_size) override;
InkDropState GetTargetInkDropState() const override; InkDropState GetTargetInkDropState() const override;
void AnimateToState(InkDropState state) override; void AnimateToState(InkDropState state) override;
void SetHoverHighlightFadeDurationMs(int duration_ms) override;
void UseDefaultHoverHighlightFadeDuration() override;
void SnapToActivated() override; void SnapToActivated() override;
void SnapToHidden() override; void SnapToHidden() override;
void SetHovered(bool is_hovered) override; void SetHovered(bool is_hovered) override;
......
...@@ -20,6 +20,10 @@ void TestInkDrop::AnimateToState(InkDropState ink_drop_state) { ...@@ -20,6 +20,10 @@ void TestInkDrop::AnimateToState(InkDropState ink_drop_state) {
state_ = ink_drop_state; state_ = ink_drop_state;
} }
void TestInkDrop::SetHoverHighlightFadeDurationMs(int duration_ms) {}
void TestInkDrop::UseDefaultHoverHighlightFadeDuration() {}
void TestInkDrop::SnapToActivated() { void TestInkDrop::SnapToActivated() {
state_ = InkDropState::ACTIVATED; state_ = InkDropState::ACTIVATED;
} }
......
...@@ -24,6 +24,8 @@ class TestInkDrop : public InkDrop { ...@@ -24,6 +24,8 @@ class TestInkDrop : public InkDrop {
void HostSizeChanged(const gfx::Size& new_size) override; void HostSizeChanged(const gfx::Size& new_size) override;
InkDropState GetTargetInkDropState() const override; InkDropState GetTargetInkDropState() const override;
void AnimateToState(InkDropState ink_drop_state) override; void AnimateToState(InkDropState ink_drop_state) override;
void SetHoverHighlightFadeDurationMs(int duration_ms) override;
void UseDefaultHoverHighlightFadeDuration() override;
void SnapToActivated() override; void SnapToActivated() override;
void SnapToHidden() override; void SnapToHidden() override;
void SetHovered(bool is_hovered) override; void SetHovered(bool is_hovered) override;
......
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