Commit b1065a61 authored by Matthew Mourgos's avatar Matthew Mourgos Committed by Commit Bot

cros: Add blur to hotseat and shelf widgets in tablet mode

The added blur will only be visible when the "shelf-hotseat" flag
is enabled.

Bug: 1006965
Change-Id: I58d27a7701b22de83590fdc7ce27f402c95baf71
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1834762
Commit-Queue: Matthew Mourgos <mmourgos@chromium.org>
Reviewed-by: default avatarManu Cornet <manucornet@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#703885}
parent da6832a5
...@@ -137,6 +137,7 @@ class ASH_EXPORT ShelfConfig : public TabletModeObserver, ...@@ -137,6 +137,7 @@ class ASH_EXPORT ShelfConfig : public TabletModeObserver,
float shelf_tooltip_preview_min_ratio() const { float shelf_tooltip_preview_min_ratio() const {
return shelf_tooltip_preview_min_ratio_; return shelf_tooltip_preview_min_ratio_;
} }
int shelf_blur_radius() const { return shelf_blur_radius_; }
// Gets the current color for the shelf control buttons. // Gets the current color for the shelf control buttons.
SkColor GetShelfControlButtonColor() const; SkColor GetShelfControlButtonColor() const;
...@@ -151,6 +152,9 @@ class ASH_EXPORT ShelfConfig : public TabletModeObserver, ...@@ -151,6 +152,9 @@ class ASH_EXPORT ShelfConfig : public TabletModeObserver,
// available. // available.
SkColor GetDefaultShelfColor() const; SkColor GetDefaultShelfColor() const;
// Returns the current blur radius to use for the control buttons.
int GetShelfControlButtonBlurRadius() const;
private: private:
friend class ShelfConfigTest; friend class ShelfConfigTest;
...@@ -220,6 +224,9 @@ class ASH_EXPORT ShelfConfig : public TabletModeObserver, ...@@ -220,6 +224,9 @@ class ASH_EXPORT ShelfConfig : public TabletModeObserver,
const float shelf_tooltip_preview_max_ratio_; const float shelf_tooltip_preview_max_ratio_;
const float shelf_tooltip_preview_min_ratio_; const float shelf_tooltip_preview_min_ratio_;
// The blur radius used for the shelf.
const int shelf_blur_radius_;
base::ObserverList<Observer> observers_; base::ObserverList<Observer> observers_;
DISALLOW_COPY_AND_ASSIGN(ShelfConfig); DISALLOW_COPY_AND_ASSIGN(ShelfConfig);
......
...@@ -117,6 +117,8 @@ void HotseatWidget::DelegateView::UpdateOpaqueBackground() { ...@@ -117,6 +117,8 @@ void HotseatWidget::DelegateView::UpdateOpaqueBackground() {
scrollable_shelf_view_->GetHotseatBackgroundBounds(); scrollable_shelf_view_->GetHotseatBackgroundBounds();
if (opaque_background_.bounds() != background_bounds) if (opaque_background_.bounds() != background_bounds)
opaque_background_.SetBounds(background_bounds); opaque_background_.SetBounds(background_bounds);
opaque_background_.SetBackgroundBlur(ShelfConfig::Get()->shelf_blur_radius());
} }
void HotseatWidget::DelegateView::OnTabletModeChanged() { void HotseatWidget::DelegateView::OnTabletModeChanged() {
......
...@@ -55,8 +55,9 @@ ShelfConfig::ShelfConfig() ...@@ -55,8 +55,9 @@ ShelfConfig::ShelfConfig()
status_indicator_offset_from_shelf_edge_(1), status_indicator_offset_from_shelf_edge_(1),
shelf_tooltip_preview_height_(128), shelf_tooltip_preview_height_(128),
shelf_tooltip_preview_max_width_(192), shelf_tooltip_preview_max_width_(192),
shelf_tooltip_preview_max_ratio_(1.5), // = 3/2 shelf_tooltip_preview_max_ratio_(1.5), // = 3/2
shelf_tooltip_preview_min_ratio_(0.666) { // = 2/3 shelf_tooltip_preview_min_ratio_(0.666), // = 2/3
shelf_blur_radius_(30) {
UpdateIsDense(); UpdateIsDense();
} }
...@@ -250,8 +251,7 @@ SkColor ShelfConfig::GetMaximizedShelfColor() const { ...@@ -250,8 +251,7 @@ SkColor ShelfConfig::GetMaximizedShelfColor() const {
} }
SkColor ShelfConfig::GetDefaultShelfColor() const { SkColor ShelfConfig::GetDefaultShelfColor() const {
if (!features::IsBackgroundBlurEnabled() || if (!features::IsBackgroundBlurEnabled()) {
chromeos::switches::ShouldShowShelfHotseat()) {
return AshColorProvider::Get()->GetBaseLayerColor( return AshColorProvider::Get()->GetBaseLayerColor(
AshColorProvider::BaseLayerType::kTransparentWithoutBlur, AshColorProvider::BaseLayerType::kTransparentWithoutBlur,
AshColorProvider::AshColorMode::kDark); AshColorProvider::AshColorMode::kDark);
...@@ -279,6 +279,15 @@ SkColor ShelfConfig::GetDefaultShelfColor() const { ...@@ -279,6 +279,15 @@ SkColor ShelfConfig::GetDefaultShelfColor() const {
return SkColorSetA(final_color, 189); // 74% opacity return SkColorSetA(final_color, 189); // 74% opacity
} }
int ShelfConfig::GetShelfControlButtonBlurRadius() const {
if (features::IsBackgroundBlurEnabled() &&
chromeos::switches::ShouldShowShelfHotseat() && IsTabletMode() &&
!is_in_app()) {
return shelf_blur_radius_;
}
return 0;
}
void ShelfConfig::OnShelfConfigUpdated() { void ShelfConfig::OnShelfConfigUpdated() {
for (auto& observer : observers_) for (auto& observer : observers_)
observer.OnShelfConfigUpdated(); observer.OnShelfConfigUpdated();
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "ash/strings/grit/ash_strings.h" #include "ash/strings/grit/ash_strings.h"
#include "ash/system/status_area_widget.h" #include "ash/system/status_area_widget.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h" #include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "chromeos/constants/chromeos_switches.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/compositor/scoped_layer_animation_settings.h" #include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/views/animation/bounds_animator.h" #include "ui/views/animation/bounds_animator.h"
...@@ -57,9 +58,16 @@ class ShelfNavigationWidget::Delegate : public views::AccessiblePaneView, ...@@ -57,9 +58,16 @@ class ShelfNavigationWidget::Delegate : public views::AccessiblePaneView,
Delegate(Shelf* shelf, ShelfView* shelf_view); Delegate(Shelf* shelf, ShelfView* shelf_view);
~Delegate() override; ~Delegate() override;
// Initializes the view.
void Init(ui::Layer* parent_layer);
void UpdateOpaqueBackground();
// views::View: // views::View:
FocusTraversable* GetPaneFocusTraversable() override; FocusTraversable* GetPaneFocusTraversable() override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override; void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
void ReorderChildLayers(ui::Layer* parent_layer) override;
void OnBoundsChanged(const gfx::Rect& old_bounds) override;
// views::AccessiblePaneView: // views::AccessiblePaneView:
View* GetDefaultFocusableChild() override; View* GetDefaultFocusableChild() override;
...@@ -77,16 +85,22 @@ class ShelfNavigationWidget::Delegate : public views::AccessiblePaneView, ...@@ -77,16 +85,22 @@ class ShelfNavigationWidget::Delegate : public views::AccessiblePaneView,
} }
private: private:
void SetParentLayer(ui::Layer* layer);
BackButton* back_button_ = nullptr; BackButton* back_button_ = nullptr;
HomeButton* home_button_ = nullptr; HomeButton* home_button_ = nullptr;
// When true, the default focus of the navigation widget is the last // When true, the default focus of the navigation widget is the last
// focusable child. // focusable child.
bool default_last_focusable_child_ = false; bool default_last_focusable_child_ = false;
// A background layer that may be visible depending on shelf state.
ui::Layer opaque_background_;
DISALLOW_COPY_AND_ASSIGN(Delegate); DISALLOW_COPY_AND_ASSIGN(Delegate);
}; };
ShelfNavigationWidget::Delegate::Delegate(Shelf* shelf, ShelfView* shelf_view) { ShelfNavigationWidget::Delegate::Delegate(Shelf* shelf, ShelfView* shelf_view)
: opaque_background_(ui::LAYER_SOLID_COLOR) {
set_allow_deactivate_on_esc(true); set_allow_deactivate_on_esc(true);
const int control_size = ShelfConfig::Get()->control_size(); const int control_size = ShelfConfig::Get()->control_size();
...@@ -108,6 +122,31 @@ ShelfNavigationWidget::Delegate::Delegate(Shelf* shelf, ShelfView* shelf_view) { ...@@ -108,6 +122,31 @@ ShelfNavigationWidget::Delegate::Delegate(Shelf* shelf, ShelfView* shelf_view) {
ShelfNavigationWidget::Delegate::~Delegate() = default; ShelfNavigationWidget::Delegate::~Delegate() = default;
void ShelfNavigationWidget::Delegate::Init(ui::Layer* parent_layer) {
SetParentLayer(parent_layer);
UpdateOpaqueBackground();
}
void ShelfNavigationWidget::Delegate::UpdateOpaqueBackground() {
opaque_background_.SetColor(ShelfConfig::Get()->GetShelfControlButtonColor());
if (chromeos::switches::ShouldShowShelfHotseat() && IsTabletMode() &&
ShelfConfig::Get()->is_in_app()) {
opaque_background_.SetVisible(false);
return;
}
opaque_background_.SetVisible(true);
int radius = ShelfConfig::Get()->control_border_radius();
gfx::RoundedCornersF rounded_corners = {radius, radius, radius, radius};
if (opaque_background_.rounded_corner_radii() != rounded_corners)
opaque_background_.SetRoundedCornerRadius(rounded_corners);
opaque_background_.SetBounds(GetLocalBounds());
opaque_background_.SetBackgroundBlur(
ShelfConfig::Get()->GetShelfControlButtonBlurRadius());
}
bool ShelfNavigationWidget::Delegate::CanActivate() const { bool ShelfNavigationWidget::Delegate::CanActivate() const {
// We don't want mouse clicks to activate us, but we need to allow // We don't want mouse clicks to activate us, but we need to allow
// activation when the user is using the keyboard (FocusCycler). // activation when the user is using the keyboard (FocusCycler).
...@@ -125,11 +164,27 @@ void ShelfNavigationWidget::Delegate::GetAccessibleNodeData( ...@@ -125,11 +164,27 @@ void ShelfNavigationWidget::Delegate::GetAccessibleNodeData(
node_data->SetName(l10n_util::GetStringUTF8(IDS_ASH_SHELF_ACCESSIBLE_NAME)); node_data->SetName(l10n_util::GetStringUTF8(IDS_ASH_SHELF_ACCESSIBLE_NAME));
} }
void ShelfNavigationWidget::Delegate::ReorderChildLayers(
ui::Layer* parent_layer) {
views::View::ReorderChildLayers(parent_layer);
parent_layer->StackAtBottom(&opaque_background_);
}
void ShelfNavigationWidget::Delegate::OnBoundsChanged(
const gfx::Rect& old_bounds) {
UpdateOpaqueBackground();
}
views::View* ShelfNavigationWidget::Delegate::GetDefaultFocusableChild() { views::View* ShelfNavigationWidget::Delegate::GetDefaultFocusableChild() {
return default_last_focusable_child_ ? GetLastFocusableChild() return default_last_focusable_child_ ? GetLastFocusableChild()
: GetFirstFocusableChild(); : GetFirstFocusableChild();
} }
void ShelfNavigationWidget::Delegate::SetParentLayer(ui::Layer* layer) {
layer->Add(&opaque_background_);
ReorderLayers();
}
ShelfNavigationWidget::ShelfNavigationWidget(Shelf* shelf, ShelfNavigationWidget::ShelfNavigationWidget(Shelf* shelf,
ShelfView* shelf_view) ShelfView* shelf_view)
: shelf_(shelf), : shelf_(shelf),
...@@ -160,6 +215,7 @@ void ShelfNavigationWidget::Initialize(aura::Window* container) { ...@@ -160,6 +215,7 @@ void ShelfNavigationWidget::Initialize(aura::Window* container) {
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.parent = container; params.parent = container;
Init(std::move(params)); Init(std::move(params));
delegate_->Init(GetLayer());
set_focus_on_creation(false); set_focus_on_creation(false);
GetFocusManager()->set_arrow_key_traversal_enabled_for_widget(true); GetFocusManager()->set_arrow_key_traversal_enabled_for_widget(true);
SetContentsView(delegate_); SetContentsView(delegate_);
...@@ -247,9 +303,7 @@ void ShelfNavigationWidget::UpdateLayout() { ...@@ -247,9 +303,7 @@ void ShelfNavigationWidget::UpdateLayout() {
tablet_mode ? GetSecondButtonBounds() : GetFirstButtonBounds()); tablet_mode ? GetSecondButtonBounds() : GetFirstButtonBounds());
GetBackButton()->SetBoundsRect(GetFirstButtonBounds()); GetBackButton()->SetBoundsRect(GetFirstButtonBounds());
delegate_->SetBackground(views::CreateRoundedRectBackground( delegate_->UpdateOpaqueBackground();
ShelfConfig::Get()->GetShelfControlButtonColor(),
ShelfConfig::Get()->control_border_radius()));
} }
} // namespace ash } // namespace ash
...@@ -115,34 +115,6 @@ class TrayBackgroundView::TrayWidgetObserver : public views::WidgetObserver { ...@@ -115,34 +115,6 @@ class TrayBackgroundView::TrayWidgetObserver : public views::WidgetObserver {
DISALLOW_COPY_AND_ASSIGN(TrayWidgetObserver); DISALLOW_COPY_AND_ASSIGN(TrayWidgetObserver);
}; };
class TrayBackground : public views::Background {
public:
explicit TrayBackground(TrayBackgroundView* tray_background_view)
: tray_background_view_(tray_background_view) {}
~TrayBackground() override = default;
private:
// Overridden from views::Background.
void Paint(gfx::Canvas* canvas, views::View* view) const override {
gfx::ScopedCanvas scoped_canvas(canvas);
cc::PaintFlags background_flags;
background_flags.setAntiAlias(true);
background_flags.setColor(ShelfConfig::Get()->GetShelfControlButtonColor());
gfx::Rect bounds = tray_background_view_->GetBackgroundBounds();
const float dsf = canvas->UndoDeviceScaleFactor();
canvas->DrawRoundRect(gfx::ScaleToRoundedRect(bounds, dsf),
ShelfConfig::Get()->control_border_radius() * dsf,
background_flags);
}
// Reference to the TrayBackgroundView for which this is a background.
TrayBackgroundView* tray_background_view_;
DISALLOW_COPY_AND_ASSIGN(TrayBackground);
};
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// TrayBackgroundView // TrayBackgroundView
...@@ -151,7 +123,6 @@ TrayBackgroundView::TrayBackgroundView(Shelf* shelf) ...@@ -151,7 +123,6 @@ TrayBackgroundView::TrayBackgroundView(Shelf* shelf)
: ActionableView(TrayPopupInkDropStyle::FILL_BOUNDS), : ActionableView(TrayPopupInkDropStyle::FILL_BOUNDS),
shelf_(shelf), shelf_(shelf),
tray_container_(new TrayContainer(shelf)), tray_container_(new TrayContainer(shelf)),
background_(new TrayBackground(this)),
is_active_(false), is_active_(false),
separator_visible_(true), separator_visible_(true),
visible_preferred_(false), visible_preferred_(false),
...@@ -164,7 +135,6 @@ TrayBackgroundView::TrayBackgroundView(Shelf* shelf) ...@@ -164,7 +135,6 @@ TrayBackgroundView::TrayBackgroundView(Shelf* shelf)
ShelfConfig::Get()->shelf_ink_drop_visible_opacity()); ShelfConfig::Get()->shelf_ink_drop_visible_opacity());
SetLayoutManager(std::make_unique<views::FillLayout>()); SetLayoutManager(std::make_unique<views::FillLayout>());
SetBackground(std::unique_ptr<views::Background>(background_));
SetInstallFocusRingOnFocus(true); SetInstallFocusRingOnFocus(true);
focus_ring()->SetColor(ShelfConfig::Get()->shelf_focus_border_color()); focus_ring()->SetColor(ShelfConfig::Get()->shelf_focus_border_color());
SetFocusPainter(nullptr); SetFocusPainter(nullptr);
...@@ -173,8 +143,13 @@ TrayBackgroundView::TrayBackgroundView(Shelf* shelf) ...@@ -173,8 +143,13 @@ TrayBackgroundView::TrayBackgroundView(Shelf* shelf)
tray_event_filter_.reset(new TrayEventFilter); tray_event_filter_.reset(new TrayEventFilter);
SetPaintToLayer(); // Use layer color to provide background color. Note that children views
// need to have their own layers to be visible.
SetPaintToLayer(ui::LAYER_SOLID_COLOR);
layer()->SetFillsBoundsOpaquely(false); layer()->SetFillsBoundsOpaquely(false);
UpdateBackground();
// Start the tray items not visible, because visibility changes are animated. // Start the tray items not visible, because visibility changes are animated.
views::View::SetVisible(false); views::View::SetVisible(false);
} }
...@@ -444,6 +419,9 @@ void TrayBackgroundView::OnBoundsChanged(const gfx::Rect& previous_bounds) { ...@@ -444,6 +419,9 @@ void TrayBackgroundView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
path->addRoundRect(gfx::RectToSkRect(GetBackgroundBounds()), border_radius, path->addRoundRect(gfx::RectToSkRect(GetBackgroundBounds()), border_radius,
border_radius); border_radius);
SetProperty(views::kHighlightPathKey, path.release()); SetProperty(views::kHighlightPathKey, path.release());
UpdateBackground();
// Bypass ActionableView::OnBoundsChanged which sets its own highlight path. // Bypass ActionableView::OnBoundsChanged which sets its own highlight path.
Button::OnBoundsChanged(previous_bounds); Button::OnBoundsChanged(previous_bounds);
} }
...@@ -485,4 +463,14 @@ gfx::Insets TrayBackgroundView::GetBackgroundInsets() const { ...@@ -485,4 +463,14 @@ gfx::Insets TrayBackgroundView::GetBackgroundInsets() const {
return insets; return insets;
} }
void TrayBackgroundView::UpdateBackground() {
const int radius = ShelfConfig::Get()->control_border_radius();
gfx::RoundedCornersF rounded_corners = {radius, radius, radius, radius};
layer()->SetRoundedCornerRadius(rounded_corners);
layer()->SetBackgroundBlur(
ShelfConfig::Get()->GetShelfControlButtonBlurRadius());
layer()->SetColor(ShelfConfig::Get()->GetShelfControlButtonColor());
layer()->SetClipRect(GetBackgroundBounds());
}
} // namespace ash } // namespace ash
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
namespace ash { namespace ash {
class Shelf; class Shelf;
class TrayBackground;
class TrayContainer; class TrayContainer;
class TrayEventFilter; class TrayEventFilter;
...@@ -148,6 +147,8 @@ class ASH_EXPORT TrayBackgroundView : public ActionableView, ...@@ -148,6 +147,8 @@ class ASH_EXPORT TrayBackgroundView : public ActionableView,
// Helper function that calculates background insets relative to local bounds. // Helper function that calculates background insets relative to local bounds.
gfx::Insets GetBackgroundInsets() const; gfx::Insets GetBackgroundInsets() const;
// Updates the background layer.
void UpdateBackground();
// The shelf containing the system tray for this view. // The shelf containing the system tray for this view.
Shelf* shelf_; Shelf* shelf_;
...@@ -155,9 +156,6 @@ class ASH_EXPORT TrayBackgroundView : public ActionableView, ...@@ -155,9 +156,6 @@ class ASH_EXPORT TrayBackgroundView : public ActionableView,
// Convenience pointer to the contents view. // Convenience pointer to the contents view.
TrayContainer* tray_container_; TrayContainer* tray_container_;
// Owned by the view passed to SetContents().
TrayBackground* background_;
// Determines if the view is active. This changes how the ink drop ripples // Determines if the view is active. This changes how the ink drop ripples
// behave. // behave.
bool is_active_; bool is_active_;
......
...@@ -20,6 +20,8 @@ TrayContainer::TrayContainer(Shelf* shelf) : shelf_(shelf) { ...@@ -20,6 +20,8 @@ TrayContainer::TrayContainer(Shelf* shelf) : shelf_(shelf) {
ShelfConfig::Get()->AddObserver(this); ShelfConfig::Get()->AddObserver(this);
SetPaintToLayer();
layer()->SetFillsBoundsOpaquely(false);
UpdateLayout(); UpdateLayout();
} }
......
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