Commit 17143592 authored by Manu Cornet's avatar Manu Cornet Committed by Commit Bot

CrOS shelf: conditionally blur the shelf background

Delegate the decision to blur the shelf to the shelf layout manager,
and do not blur it unless there is an active session (e.g. login
screen).

Cache whether the background is currently blurred to avoid unnecessary
updates.

Bug: 883558
Change-Id: I6bc881f8133a0363260f88efd4225fb072009fc0
Reviewed-on: https://chromium-review.googlesource.com/1227813Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Manu Cornet <manucornet@chromium.org>
Cr-Commit-Position: refs/heads/master@{#592978}
parent 1eee7cc0
......@@ -1179,6 +1179,14 @@ bool ShelfLayoutManager::IsShelfAutoHideForFullscreenMaximized() const {
active_window->autohide_shelf_when_maximized_or_fullscreen();
}
bool ShelfLayoutManager::ShouldBlurShelfBackground() {
if (!IsBackgroundBlurEnabled())
return false;
if (!chromeos::switches::ShouldUseShelfNewUi())
return false;
return state_.session_state == session_manager::SessionState::ACTIVE;
}
////////////////////////////////////////////////////////////////////////////////
// ShelfLayoutManager, Gesture functions:
......
......@@ -148,6 +148,11 @@ class ASH_EXPORT ShelfLayoutManager
// Returns whether background blur is enabled.
bool IsBackgroundBlurEnabled() { return is_background_blur_enabled_; }
// Returns whether the shelf should show a blurred background. This may
// return false even if background blur is enabled depending on the session
// state.
bool ShouldBlurShelfBackground();
// Overridden from wm::WmSnapToPixelLayoutManager:
void OnWindowResized() override;
void SetChildBounds(aura::Window* child,
......
......@@ -93,6 +93,7 @@ class ShelfWidget::DelegateView : public views::WidgetDelegate,
bool CanActivate() const override;
void ReorderChildLayers(ui::Layer* parent_layer) override;
void UpdateBackgroundBlur();
void UpdateOpaqueBackground();
// This will be called when the parent local bounds change.
void OnBoundsChanged(const gfx::Rect& old_bounds) override;
......@@ -116,6 +117,10 @@ class ShelfWidget::DelegateView : public views::WidgetDelegate,
// When true, the default focus of the shelf is the last focusable child.
bool default_last_focusable_child_ = false;
// Cache the state of the background blur so that it can be updated only
// when necessary.
bool background_is_currently_blurred_ = false;
DISALLOW_COPY_AND_ASSIGN(DelegateView);
};
......@@ -129,8 +134,6 @@ ShelfWidget::DelegateView::DelegateView(ShelfWidget* shelf_widget)
SetLayoutManager(std::make_unique<views::FillLayout>());
set_allow_deactivate_on_esc(true);
if (shelf_widget_->shelf_layout_manager()->IsBackgroundBlurEnabled())
opaque_background_.SetBackgroundBlur(kShelfBlurRadius);
UpdateOpaqueBackground();
}
......@@ -185,6 +188,18 @@ void ShelfWidget::DelegateView::ReorderChildLayers(ui::Layer* parent_layer) {
parent_layer->StackAtBottom(&opaque_background_);
}
void ShelfWidget::DelegateView::UpdateBackgroundBlur() {
const bool should_blur_background =
shelf_widget_->shelf_layout_manager()->ShouldBlurShelfBackground();
if (should_blur_background == background_is_currently_blurred_)
return;
opaque_background_.SetBackgroundBlur(should_blur_background ? kShelfBlurRadius
: 0);
background_is_currently_blurred_ = should_blur_background;
}
void ShelfWidget::DelegateView::UpdateOpaqueBackground() {
const gfx::Rect local_bounds = GetLocalBounds();
gfx::Rect opaque_background_bounds = local_bounds;
......@@ -222,6 +237,7 @@ void ShelfWidget::DelegateView::UpdateOpaqueBackground() {
}
}
opaque_background_.SetBounds(opaque_background_bounds);
UpdateBackgroundBlur();
SchedulePaint();
}
......
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