Commit 58238c76 authored by Andrew Xu's avatar Andrew Xu Committed by Commit Bot

Implement display centering alignment

Scrollable shelf should place shelf icons in the center of
display when there is sufficient space. That is also the
UI behavior of the current shelf view. This CL achieves the UI
consistency for scrollable shelf.

Bug: 973481
Change-Id: Ifc50e6d62f5508dc84578519c4f6c6522fb845e1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1789677
Commit-Queue: Andrew Xu <andrewxu@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695226}
parent fcc458a8
...@@ -5,8 +5,10 @@ ...@@ -5,8 +5,10 @@
#include "ash/shelf/scrollable_shelf_view.h" #include "ash/shelf/scrollable_shelf_view.h"
#include "ash/public/cpp/shelf_config.h" #include "ash/public/cpp/shelf_config.h"
#include "ash/screen_util.h"
#include "ash/shelf/shelf_focus_cycler.h" #include "ash/shelf/shelf_focus_cycler.h"
#include "ash/shelf/shelf_widget.h" #include "ash/shelf/shelf_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 "base/numerics/ranges.h" #include "base/numerics/ranges.h"
#include "ui/compositor/paint_recorder.h" #include "ui/compositor/paint_recorder.h"
...@@ -382,6 +384,32 @@ bool ScrollableShelfView::ShouldAdaptToRTL() const { ...@@ -382,6 +384,32 @@ bool ScrollableShelfView::ShouldAdaptToRTL() const {
return base::i18n::IsRTL() && GetShelf()->IsHorizontalAlignment(); return base::i18n::IsRTL() && GetShelf()->IsHorizontalAlignment();
} }
bool ScrollableShelfView::ShouldApplyDisplayCentering() const {
if (layout_strategy_ != kNotShowArrowButtons)
return false;
const gfx::Rect display_bounds =
screen_util::GetDisplayBoundsWithShelf(GetWidget()->GetNativeWindow());
const int display_size_primary = GetShelf()->PrimaryAxisValue(
display_bounds.width(), display_bounds.height());
StatusAreaWidget* status_widget =
GetShelf()->shelf_widget()->status_area_widget();
const int status_widget_size = GetShelf()->PrimaryAxisValue(
status_widget->GetWindowBoundsInScreen().width(),
status_widget->GetWindowBoundsInScreen().height());
// An easy way to check whether the apps fit at the exact center of the
// screen is to imagine that we have another status widget on the other
// side (the status widget is always bigger than the home button plus
// the back button if applicable) and see if the apps can fit in the middle
int available_space_for_screen_centering =
display_size_primary -
2 * (status_widget_size + ShelfConfig::Get()->app_icon_group_margin());
return available_space_for_screen_centering >
shelf_view_->GetSizeOfAppIcons(shelf_view_->number_of_visible_apps(),
false);
}
Shelf* ScrollableShelfView::GetShelf() { Shelf* ScrollableShelfView::GetShelf() {
return const_cast<Shelf*>( return const_cast<Shelf*>(
const_cast<const ScrollableShelfView*>(this)->GetShelf()); const_cast<const ScrollableShelfView*>(this)->GetShelf());
...@@ -563,19 +591,25 @@ void ScrollableShelfView::OnShelfAlignmentChanged(aura::Window* root_window) { ...@@ -563,19 +591,25 @@ void ScrollableShelfView::OnShelfAlignmentChanged(aura::Window* root_window) {
} }
gfx::Insets ScrollableShelfView::CalculateEdgePadding() const { gfx::Insets ScrollableShelfView::CalculateEdgePadding() const {
const int available_size_for_app_icons = // Display centering alignment
(GetShelf()->IsHorizontalAlignment() ? width() : height()) - if (ShouldApplyDisplayCentering())
2 * ShelfConfig::Get()->app_icon_group_margin(); return CalculatePaddingForDisplayCentering();
const int icons_size = shelf_view_->GetSizeOfAppIcons( const int icons_size = shelf_view_->GetSizeOfAppIcons(
shelf_view_->number_of_visible_apps(), false); shelf_view_->number_of_visible_apps(), false);
gfx::Insets padding_insets( gfx::Insets padding_insets(
/*vertical= */ 0, /*vertical= */ 0,
/*horizontal= */ ShelfConfig::Get()->app_icon_group_margin()); /*horizontal= */ ShelfConfig::Get()->app_icon_group_margin());
int gap = layout_strategy_ == kNotShowArrowButtons
? available_size_for_app_icons - icons_size - const int available_size_for_app_icons =
2 * GetAppIconEndPadding() (GetShelf()->IsHorizontalAlignment() ? width() : height()) -
: CalculateOverflowPadding(available_size_for_app_icons); 2 * ShelfConfig::Get()->app_icon_group_margin();
int gap =
layout_strategy_ == kNotShowArrowButtons
? available_size_for_app_icons - icons_size // shelf centering
: CalculateOverflowPadding(available_size_for_app_icons); // overflow
padding_insets.set_left(padding_insets.left() + gap / 2); padding_insets.set_left(padding_insets.left() + gap / 2);
padding_insets.set_right(padding_insets.right() + padding_insets.set_right(padding_insets.right() +
(gap % 2 ? gap / 2 + 1 : gap / 2)); (gap % 2 ? gap / 2 + 1 : gap / 2));
...@@ -583,6 +617,28 @@ gfx::Insets ScrollableShelfView::CalculateEdgePadding() const { ...@@ -583,6 +617,28 @@ gfx::Insets ScrollableShelfView::CalculateEdgePadding() const {
return padding_insets; return padding_insets;
} }
gfx::Insets ScrollableShelfView::CalculatePaddingForDisplayCentering() const {
const int icons_size = shelf_view_->GetSizeOfAppIcons(
shelf_view_->number_of_visible_apps(), false);
const gfx::Rect display_bounds =
screen_util::GetDisplayBoundsWithShelf(GetWidget()->GetNativeWindow());
const int display_size_primary = GetShelf()->PrimaryAxisValue(
display_bounds.width(), display_bounds.height());
const int gap = (display_size_primary - icons_size) / 2;
// Calculates paddings in view coordinates.
const gfx::Rect screen_bounds = GetBoundsInScreen();
const int left_padding = gap - GetShelf()->PrimaryAxisValue(
screen_bounds.x() - display_bounds.x(),
screen_bounds.y() - display_bounds.y());
const int right_padding =
gap - GetShelf()->PrimaryAxisValue(
display_bounds.right() - screen_bounds.right(),
display_bounds.bottom() - screen_bounds.bottom());
return gfx::Insets(0, left_padding, 0, right_padding);
}
bool ScrollableShelfView::ShouldHandleGestures(const ui::GestureEvent& event) { bool ScrollableShelfView::ShouldHandleGestures(const ui::GestureEvent& event) {
// ScrollableShelfView only handles the gesture scrolling along the main axis. // ScrollableShelfView only handles the gesture scrolling along the main axis.
// For other gesture events, including the scrolling across the main axis, // For other gesture events, including the scrolling across the main axis,
......
...@@ -112,6 +112,9 @@ class ASH_EXPORT ScrollableShelfView : public views::AccessiblePaneView, ...@@ -112,6 +112,9 @@ class ASH_EXPORT ScrollableShelfView : public views::AccessiblePaneView,
// Returns whether the view should adapt to RTL. // Returns whether the view should adapt to RTL.
bool ShouldAdaptToRTL() const; bool ShouldAdaptToRTL() const;
// Returns whether the app icon layout should be centering alignment.
bool ShouldApplyDisplayCentering() const;
Shelf* GetShelf(); Shelf* GetShelf();
const Shelf* GetShelf() const; const Shelf* GetShelf() const;
...@@ -133,12 +136,15 @@ class ASH_EXPORT ScrollableShelfView : public views::AccessiblePaneView, ...@@ -133,12 +136,15 @@ class ASH_EXPORT ScrollableShelfView : public views::AccessiblePaneView,
// Overridden from ShellObserver: // Overridden from ShellObserver:
void OnShelfAlignmentChanged(aura::Window* root_window) override; void OnShelfAlignmentChanged(aura::Window* root_window) override;
// Returns the padding inset. Padding for two scenarios: if there is // Returns the padding inset. Different Padding strategies for three scenarios
// sufficient space to accommodate all of shelf icons, add padding to show // (1) display centering alignment
// ScrollableShelfView in centering alignment; otherwise, add padding to fully // (2) scrollable shelf centering alignment
// show all of visible shelf icons. // (3) overflow mode
gfx::Insets CalculateEdgePadding() const; gfx::Insets CalculateEdgePadding() const;
// Calculates padding for display centering alignment.
gfx::Insets CalculatePaddingForDisplayCentering() const;
// Returns whether the received gesture event should be handled here. // Returns whether the received gesture event should be handled here.
bool ShouldHandleGestures(const ui::GestureEvent& event); bool ShouldHandleGestures(const ui::GestureEvent& event);
......
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