Commit ee08e49a authored by Toni Barzic's avatar Toni Barzic Committed by Commit Bot

Do not restart shelf nav widget animations with same target values

Shelf navigation widget layout may get updated while the previous
animation is still in progress. Do not restart the animation if the
target opacity or bounds do not change.

While here, do not update shelf navigation layout from shelf config
observer. Shelf layout manager handles shelf config changes, and will
call UpdateLayout as necessary (so calls from the shelf navigation
widget would be duplicative).

BUG=1101084

Change-Id: I3a89847ebfe63e69fe869623e58c58b35c38d966
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2276654Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Toni Baržić <tbarzic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#784194}
parent 9f839b30
......@@ -450,12 +450,9 @@ ShelfNavigationWidget::ShelfNavigationWidget(Shelf* shelf,
NavigationButtonAnimationMetricsReporter::NavigationButtonType::
kHomeButton)) {
DCHECK(shelf_);
ShelfConfig::Get()->AddObserver(this);
}
ShelfNavigationWidget::~ShelfNavigationWidget() {
ShelfConfig::Get()->RemoveObserver(this);
// Cancel animations now so the BoundsAnimator doesn't outlive the metrics
// reporter associated to it.
bounds_animator_->Cancel();
......@@ -561,10 +558,6 @@ void ShelfNavigationWidget::SetDefaultLastFocusableChild(
delegate_->set_default_last_focusable_child(default_last_focusable_child);
}
void ShelfNavigationWidget::OnShelfConfigUpdated() {
UpdateLayout(/*animate=*/true);
}
void ShelfNavigationWidget::CalculateTargetBounds() {
const gfx::Point shelf_origin =
shelf_->shelf_widget()->GetTargetBounds().origin();
......@@ -609,25 +602,34 @@ void ShelfNavigationWidget::UpdateLayout(bool animate) {
}
// Use the same duration for all parts of the upcoming animation.
const auto animation_duration =
const base::TimeDelta animation_duration =
animate ? ShelfConfig::Get()->shelf_animation_duration()
: base::TimeDelta::FromMilliseconds(0);
ui::ScopedLayerAnimationSettings nav_animation_setter(
GetNativeView()->layer()->GetAnimator());
nav_animation_setter.SetTransitionDuration(animation_duration);
nav_animation_setter.SetTweenType(gfx::Tween::EASE_OUT);
nav_animation_setter.SetPreemptionStrategy(
ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
base::Optional<ui::AnimationThroughputReporter> reporter;
if (animate) {
reporter.emplace(nav_animation_setter.GetAnimator(),
shelf_->GetNavigationWidgetAnimationReportCallback());
const bool update_opacity = !animate || GetLayer()->GetTargetOpacity() !=
layout_manager->GetOpacity();
const bool update_bounds =
!animate || GetLayer()->GetTargetBounds() != target_bounds_;
if (update_opacity || update_bounds) {
ui::ScopedLayerAnimationSettings nav_animation_setter(
GetNativeView()->layer()->GetAnimator());
nav_animation_setter.SetTransitionDuration(animation_duration);
nav_animation_setter.SetTweenType(gfx::Tween::EASE_OUT);
nav_animation_setter.SetPreemptionStrategy(
ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
base::Optional<ui::AnimationThroughputReporter> reporter;
if (animate) {
reporter.emplace(nav_animation_setter.GetAnimator(),
shelf_->GetNavigationWidgetAnimationReportCallback());
}
if (update_opacity)
GetLayer()->SetOpacity(layout_manager->GetOpacity());
if (update_bounds)
SetBounds(target_bounds_);
}
GetLayer()->SetOpacity(layout_manager->GetOpacity());
SetBounds(target_bounds_);
views::View* const back_button = delegate_->back_button();
UpdateButtonVisibility(back_button, back_button_shown, animate,
back_button_metrics_reporter_.get());
......
......@@ -8,7 +8,6 @@
#include <memory>
#include "ash/ash_export.h"
#include "ash/public/cpp/shelf_config.h"
#include "ash/shelf/shelf_component.h"
#include "ui/views/accessible_pane_view.h"
#include "ui/views/widget/widget.h"
......@@ -32,7 +31,6 @@ class ShelfView;
// The shelf navigation widget holds the home button and (when in tablet mode)
// the back button.
class ASH_EXPORT ShelfNavigationWidget : public ShelfComponent,
public ShelfConfig::Observer,
public views::Widget {
public:
class TestApi {
......@@ -80,9 +78,6 @@ class ASH_EXPORT ShelfNavigationWidget : public ShelfComponent,
// focused when activating this widget.
void SetDefaultLastFocusableChild(bool default_last_focusable_child);
// ShelfConfig::Observer:
void OnShelfConfigUpdated() override;
// ShelfComponent:
void CalculateTargetBounds() override;
gfx::Rect GetTargetBounds() const 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