Commit 10e6e8eb authored by Toni Barzic's avatar Toni Barzic Committed by Commit Bot

Disable suggestion chips blur during home animations in tablet mode

BUG=1031673

Change-Id: I5286a06cb913568b50a5321ebeb92bf298566ea4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1966430Reviewed-by: default avatarAlex Newcomer <newcomer@chromium.org>
Commit-Queue: Toni Baržić <tbarzic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#724772}
parent 7f798464
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "ash/app_list/app_list_metrics.h" #include "ash/app_list/app_list_metrics.h"
#include "ash/app_list/app_list_view_delegate.h" #include "ash/app_list/app_list_view_delegate.h"
#include "ash/app_list/views/app_list_main_view.h" #include "ash/app_list/views/app_list_main_view.h"
#include "ash/app_list/views/apps_container_view.h"
#include "ash/app_list/views/contents_view.h" #include "ash/app_list/views/contents_view.h"
#include "ash/public/cpp/app_list/app_list_features.h" #include "ash/public/cpp/app_list/app_list_features.h"
#include "ash/public/cpp/app_list/app_list_switches.h" #include "ash/public/cpp/app_list/app_list_switches.h"
...@@ -65,6 +66,26 @@ void DidPresentCompositorFrame(base::TimeTicks event_time_stamp, ...@@ -65,6 +66,26 @@ void DidPresentCompositorFrame(base::TimeTicks event_time_stamp,
} }
} }
// Implicit animation observer that runs a scoped closure runner, and deletes
// itself when the observed implicit animations complete.
class CallbackRunnerLayerAnimationObserver
: public ui::ImplicitAnimationObserver {
public:
explicit CallbackRunnerLayerAnimationObserver(
base::ScopedClosureRunner closure_runner)
: closure_runner_(std::move(closure_runner)) {}
~CallbackRunnerLayerAnimationObserver() override = default;
// ui::ImplicitAnimationObserver:
void OnImplicitAnimationsCompleted() override {
closure_runner_.RunAndReset();
delete this;
}
private:
base::ScopedClosureRunner closure_runner_;
};
} // namespace } // namespace
AppListPresenterImpl::AppListPresenterImpl( AppListPresenterImpl::AppListPresenterImpl(
...@@ -266,6 +287,16 @@ void AppListPresenterImpl::UpdateYPositionAndOpacityForHomeLauncher( ...@@ -266,6 +287,16 @@ void AppListPresenterImpl::UpdateYPositionAndOpacityForHomeLauncher(
if (!callback.is_null()) { if (!callback.is_null()) {
settings.emplace(layer->GetAnimator()); settings.emplace(layer->GetAnimator());
callback.Run(&settings.value()); callback.Run(&settings.value());
// Disable suggestion chips blur during animations to improve performance.
base::ScopedClosureRunner blur_disabler =
view_->app_list_main_view()
->contents_view()
->GetAppsContainerView()
->DisableSuggestionChipsBlur();
// The observer will delete itself when the animations are completed.
settings->AddObserver(
new CallbackRunnerLayerAnimationObserver(std::move(blur_disabler)));
} }
// The animation metrics reporter will run for opacity and transform // The animation metrics reporter will run for opacity and transform
...@@ -313,6 +344,16 @@ void AppListPresenterImpl::UpdateScaleAndOpacityForHomeLauncher( ...@@ -313,6 +344,16 @@ void AppListPresenterImpl::UpdateScaleAndOpacityForHomeLauncher(
if (!callback.is_null()) { if (!callback.is_null()) {
settings.emplace(layer->GetAnimator()); settings.emplace(layer->GetAnimator());
callback.Run(&settings.value()); callback.Run(&settings.value());
// Disable suggestion chips blur during animations to improve performance.
base::ScopedClosureRunner blur_disabler =
view_->app_list_main_view()
->contents_view()
->GetAppsContainerView()
->DisableSuggestionChipsBlur();
// The observer will delete itself when the animations are completed.
settings->AddObserver(
new CallbackRunnerLayerAnimationObserver(std::move(blur_disabler)));
} }
// The animation metrics reporter will run for opacity and transform // The animation metrics reporter will run for opacity and transform
......
...@@ -522,6 +522,17 @@ void AppsContainerView::UpdateSuggestionChips() { ...@@ -522,6 +522,17 @@ void AppsContainerView::UpdateSuggestionChips() {
->results()); ->results());
} }
base::ScopedClosureRunner AppsContainerView::DisableSuggestionChipsBlur() {
++suggestion_chips_blur_disabler_count_;
if (suggestion_chips_blur_disabler_count_ == 1)
suggestion_chip_container_view_->SetBlurDisabled(true);
return base::ScopedClosureRunner(
base::BindOnce(&AppsContainerView::OnSuggestionChipsBlurDisablerReleased,
weak_ptr_factory_.GetWeakPtr()));
}
const AppListConfig& AppsContainerView::GetAppListConfig() const { const AppListConfig& AppsContainerView::GetAppListConfig() const {
return contents_view_->app_list_view()->GetAppListConfig(); return contents_view_->app_list_view()->GetAppListConfig();
} }
...@@ -616,4 +627,12 @@ AppsContainerView::GridLayout AppsContainerView::CalculateGridLayout() const { ...@@ -616,4 +627,12 @@ AppsContainerView::GridLayout AppsContainerView::CalculateGridLayout() const {
return result; return result;
} }
void AppsContainerView::OnSuggestionChipsBlurDisablerReleased() {
DCHECK_GT(suggestion_chips_blur_disabler_count_, 0u);
--suggestion_chips_blur_disabler_count_;
if (suggestion_chips_blur_disabler_count_ == 0)
suggestion_chip_container_view_->SetBlurDisabled(false);
}
} // namespace ash } // namespace ash
...@@ -11,7 +11,9 @@ ...@@ -11,7 +11,9 @@
#include "ash/app_list/model/app_list_folder_item.h" #include "ash/app_list/model/app_list_folder_item.h"
#include "ash/app_list/views/horizontal_page.h" #include "ash/app_list/views/horizontal_page.h"
#include "base/callback_helpers.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h"
namespace ash { namespace ash {
...@@ -137,6 +139,10 @@ class APP_LIST_EXPORT AppsContainerView : public HorizontalPage { ...@@ -137,6 +139,10 @@ class APP_LIST_EXPORT AppsContainerView : public HorizontalPage {
// Updates suggestion chips from app list model. // Updates suggestion chips from app list model.
void UpdateSuggestionChips(); void UpdateSuggestionChips();
// Temporarily disables blur on suggestion chips view background. The blur
// will remained disabled until the returned closure runner goes out of scope.
base::ScopedClosureRunner DisableSuggestionChipsBlur();
private: private:
enum ShowState { enum ShowState {
SHOW_NONE, // initial state SHOW_NONE, // initial state
...@@ -171,6 +177,12 @@ class APP_LIST_EXPORT AppsContainerView : public HorizontalPage { ...@@ -171,6 +177,12 @@ class APP_LIST_EXPORT AppsContainerView : public HorizontalPage {
// depending on the current display work area size. // depending on the current display work area size.
GridLayout CalculateGridLayout() const; GridLayout CalculateGridLayout() const;
// Callback returned by DisableBlur().
void OnSuggestionChipsBlurDisablerReleased();
// The number of active requests to disable blur.
size_t suggestion_chips_blur_disabler_count_ = 0;
ContentsView* contents_view_; // Not owned. ContentsView* contents_view_; // Not owned.
// The views below are owned by views hierarchy. // The views below are owned by views hierarchy.
...@@ -198,6 +210,8 @@ class APP_LIST_EXPORT AppsContainerView : public HorizontalPage { ...@@ -198,6 +210,8 @@ class APP_LIST_EXPORT AppsContainerView : public HorizontalPage {
// arguments (otherwise the margins will be recalculated). // arguments (otherwise the margins will be recalculated).
CachedContainerMargins cached_container_margins_; CachedContainerMargins cached_container_margins_;
base::WeakPtrFactory<AppsContainerView> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(AppsContainerView); DISALLOW_COPY_AND_ASSIGN(AppsContainerView);
}; };
......
...@@ -274,9 +274,23 @@ void SuggestionChipContainerView::DisableFocusForShowingActiveFolder( ...@@ -274,9 +274,23 @@ void SuggestionChipContainerView::DisableFocusForShowingActiveFolder(
} }
void SuggestionChipContainerView::OnTabletModeChanged(bool started) { void SuggestionChipContainerView::OnTabletModeChanged(bool started) {
// Enable/Disable chips' background blur based on tablet mode. in_tablet_mode_ = started;
UpdateBlurState();
}
void SuggestionChipContainerView::SetBlurDisabled(bool blur_disabled) {
if (blur_disabled_ == blur_disabled)
return;
blur_disabled_ = blur_disabled;
UpdateBlurState();
}
void SuggestionChipContainerView::UpdateBlurState() {
// Enable/Disable chips' background blur based on tablet mode, and whether
// blur has been explicitly disabled.
for (auto* chip : suggestion_chip_views_) for (auto* chip : suggestion_chip_views_)
chip->SetBackgroundBlurEnabled(started); chip->SetBackgroundBlurEnabled(in_tablet_mode_ && !blur_disabled_);
} }
} // namespace ash } // namespace ash
...@@ -37,10 +37,22 @@ class SuggestionChipContainerView : public SearchResultContainerView { ...@@ -37,10 +37,22 @@ class SuggestionChipContainerView : public SearchResultContainerView {
// Called when tablet mode starts and ends. // Called when tablet mode starts and ends.
void OnTabletModeChanged(bool started); void OnTabletModeChanged(bool started);
// Sets whether blur is disabled on suggestion chip views.
void SetBlurDisabled(bool blur_disabled);
private: private:
// Enables or disables suggestion chips blur depending on the container state.
void UpdateBlurState();
ContentsView* contents_view_ = nullptr; // Not owned ContentsView* contents_view_ = nullptr; // Not owned
views::BoxLayout* layout_manager_ = nullptr; // Not owned views::BoxLayout* layout_manager_ = nullptr; // Not owned
// Whether tablet mode is active - tracked by OnTabletModeChanged().
bool in_tablet_mode_ = false;
// Whether suggestion chip blur has been explicitly disabled.
bool blur_disabled_ = false;
std::vector<SearchResultSuggestionChipView*> suggestion_chip_views_; // Owned std::vector<SearchResultSuggestionChipView*> suggestion_chip_views_; // Owned
DISALLOW_COPY_AND_ASSIGN(SuggestionChipContainerView); DISALLOW_COPY_AND_ASSIGN(SuggestionChipContainerView);
......
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