Commit 3b14f137 authored by Manu Cornet's avatar Manu Cornet Committed by Commit Bot

CrOS Shelf: Move hotseat layout logic to the hotseat class

Change-Id: I5bf1f77fc99deb35dfd473aa03689ab023b419eb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2052221Reviewed-by: default avatarAlex Newcomer <newcomer@chromium.org>
Commit-Queue: Manu Cornet <manucornet@chromium.org>
Cr-Commit-Position: refs/heads/master@{#740805}
parent fd582981
...@@ -404,14 +404,56 @@ void HotseatWidget::SetTranslucentBackground( ...@@ -404,14 +404,56 @@ void HotseatWidget::SetTranslucentBackground(
} }
void HotseatWidget::CalculateTargetBounds() { void HotseatWidget::CalculateTargetBounds() {
// TODO(manucornet): Move target bounds calculations from the shelf layout ShelfLayoutManager* layout_manager = shelf_->shelf_layout_manager();
// manager. const HotseatState hotseat_target_state =
layout_manager->CalculateHotseatState(layout_manager->visibility_state(),
layout_manager->auto_hide_state());
const gfx::Size status_size =
shelf_->status_area_widget()->GetTargetBounds().size();
const gfx::Rect shelf_bounds = shelf_->shelf_widget()->GetTargetBounds();
const int horizontal_edge_spacing =
ShelfConfig::Get()->control_button_edge_spacing(
shelf_->IsHorizontalAlignment());
const int vertical_edge_spacing =
ShelfConfig::Get()->control_button_edge_spacing(
!shelf_->IsHorizontalAlignment());
gfx::Rect nav_bounds = shelf_->navigation_widget()->GetTargetBounds();
gfx::Point hotseat_origin;
int hotseat_width;
int hotseat_height;
if (shelf_->IsHorizontalAlignment()) {
hotseat_width = shelf_bounds.width() - nav_bounds.size().width() -
horizontal_edge_spacing -
ShelfConfig::Get()->app_icon_group_margin() -
status_size.width();
int hotseat_x =
base::i18n::IsRTL()
? nav_bounds.x() - horizontal_edge_spacing - hotseat_width
: nav_bounds.right() + horizontal_edge_spacing;
if (hotseat_target_state != HotseatState::kShown) {
// Give the hotseat more space if it is shown outside of the shelf.
hotseat_width = shelf_bounds.width();
hotseat_x = shelf_bounds.x();
}
hotseat_origin = gfx::Point(
hotseat_x,
layout_manager->CalculateHotseatYInScreen(hotseat_target_state));
hotseat_height = ShelfConfig::Get()->hotseat_size();
} else {
hotseat_origin = gfx::Point(shelf_bounds.x(),
nav_bounds.bottom() + vertical_edge_spacing);
hotseat_width = shelf_bounds.width();
hotseat_height = shelf_bounds.height() - nav_bounds.size().height() -
vertical_edge_spacing -
ShelfConfig::Get()->app_icon_group_margin() -
status_size.height();
}
target_bounds_ =
gfx::Rect(hotseat_origin, gfx::Size(hotseat_width, hotseat_height));
} }
gfx::Rect HotseatWidget::GetTargetBounds() const { gfx::Rect HotseatWidget::GetTargetBounds() const {
// TODO(manucornet): Store these locally and do not depend on the layout return target_bounds_;
// manager.
return shelf_->shelf_layout_manager()->GetHotseatBoundsInScreen();
} }
void HotseatWidget::UpdateLayout(bool animate) { void HotseatWidget::UpdateLayout(bool animate) {
...@@ -486,8 +528,7 @@ void HotseatWidget::SetState(HotseatState state) { ...@@ -486,8 +528,7 @@ void HotseatWidget::SetState(HotseatState state) {
} }
HotseatWidget::LayoutInputs HotseatWidget::GetLayoutInputs() const { HotseatWidget::LayoutInputs HotseatWidget::GetLayoutInputs() const {
return {shelf_->shelf_layout_manager()->GetHotseatBoundsInScreen(), return {target_bounds_, CalculateOpacity()};
CalculateOpacity()};
} }
} // namespace ash } // namespace ash
...@@ -78,6 +78,12 @@ class ASH_EXPORT HotseatWidget : public ShelfComponent, ...@@ -78,6 +78,12 @@ class ASH_EXPORT HotseatWidget : public ShelfComponent,
gfx::Rect GetTargetBounds() const override; gfx::Rect GetTargetBounds() const override;
void UpdateLayout(bool animate) override; void UpdateLayout(bool animate) override;
// TODO(manucornet): Remove this method once all the hotseat layout
// code has moved to this class.
void set_target_bounds(gfx::Rect target_bounds) {
target_bounds_ = target_bounds;
}
gfx::Size GetTranslucentBackgroundSize() const; gfx::Size GetTranslucentBackgroundSize() const;
// Sets the focus cycler and adds the hotseat to the cycle. // Sets the focus cycler and adds the hotseat to the cycle.
...@@ -130,6 +136,7 @@ class ASH_EXPORT HotseatWidget : public ShelfComponent, ...@@ -130,6 +136,7 @@ class ASH_EXPORT HotseatWidget : public ShelfComponent,
// changed. // changed.
base::Optional<LayoutInputs> layout_inputs_; base::Optional<LayoutInputs> layout_inputs_;
gfx::Rect target_bounds_;
HotseatState state_ = HotseatState::kShown; HotseatState state_ = HotseatState::kShown;
Shelf* shelf_ = nullptr; Shelf* shelf_ = nullptr;
......
...@@ -643,7 +643,7 @@ gfx::Rect ScrollableShelfView::GetTargetScreenBoundsOfItemIcon( ...@@ -643,7 +643,7 @@ gfx::Rect ScrollableShelfView::GetTargetScreenBoundsOfItemIcon(
// Notes that the target bounds stored in shelf layout manager are adapted to // Notes that the target bounds stored in shelf layout manager are adapted to
// RTL already while |icon_bounds| are not adjusted to RTL yet. // RTL already while |icon_bounds| are not adjusted to RTL yet.
gfx::Rect hotseat_bounds_in_screen = gfx::Rect hotseat_bounds_in_screen =
GetShelf()->shelf_layout_manager()->GetHotseatBoundsInScreen(); GetShelf()->hotseat_widget()->GetTargetBounds();
if (ShouldAdaptToRTL()) { if (ShouldAdaptToRTL()) {
// One simple way for transformation under RTL is: (1) Transforms hotseat // One simple way for transformation under RTL is: (1) Transforms hotseat
// target bounds from RTL to LTR. (2) Calculates the icon's bounds in screen // target bounds from RTL to LTR. (2) Calculates the icon's bounds in screen
...@@ -1390,11 +1390,9 @@ int ScrollableShelfView::GetStatusWidgetSizeOnPrimaryAxis( ...@@ -1390,11 +1390,9 @@ int ScrollableShelfView::GetStatusWidgetSizeOnPrimaryAxis(
gfx::Rect ScrollableShelfView::GetAvailableLocalBounds( gfx::Rect ScrollableShelfView::GetAvailableLocalBounds(
bool use_target_bounds) const { bool use_target_bounds) const {
return use_target_bounds ? gfx::Rect(GetShelf() return use_target_bounds
->shelf_layout_manager() ? gfx::Rect(GetShelf()->hotseat_widget()->GetTargetBounds().size())
->GetHotseatBoundsInScreen() : GetLocalBounds();
.size())
: GetLocalBounds();
} }
gfx::Insets ScrollableShelfView::CalculatePaddingForDisplayCentering( gfx::Insets ScrollableShelfView::CalculatePaddingForDisplayCentering(
...@@ -1410,9 +1408,8 @@ gfx::Insets ScrollableShelfView::CalculatePaddingForDisplayCentering( ...@@ -1410,9 +1408,8 @@ gfx::Insets ScrollableShelfView::CalculatePaddingForDisplayCentering(
// Calculates paddings in view coordinates. // Calculates paddings in view coordinates.
const gfx::Rect screen_bounds = const gfx::Rect screen_bounds =
use_target_bounds use_target_bounds ? GetShelf()->hotseat_widget()->GetTargetBounds()
? GetShelf()->shelf_layout_manager()->GetHotseatBoundsInScreen() : GetBoundsInScreen();
: GetBoundsInScreen();
const int before_padding = gap - GetShelf()->PrimaryAxisValue( const int before_padding = gap - GetShelf()->PrimaryAxisValue(
screen_bounds.x() - display_bounds.x(), screen_bounds.x() - display_bounds.x(),
screen_bounds.y() - display_bounds.y()); screen_bounds.y() - display_bounds.y());
......
...@@ -1093,10 +1093,6 @@ gfx::Rect ShelfLayoutManager::GetShelfBoundsInScreen() const { ...@@ -1093,10 +1093,6 @@ gfx::Rect ShelfLayoutManager::GetShelfBoundsInScreen() const {
return target_bounds_.shelf_bounds; return target_bounds_.shelf_bounds;
} }
gfx::Rect ShelfLayoutManager::GetHotseatBoundsInScreen() const {
return target_bounds_.hotseat_bounds_in_screen;
}
float ShelfLayoutManager::GetOpacity() const { float ShelfLayoutManager::GetOpacity() const {
return target_bounds_.opacity; return target_bounds_.opacity;
} }
...@@ -1615,12 +1611,6 @@ void ShelfLayoutManager::CalculateTargetBounds( ...@@ -1615,12 +1611,6 @@ void ShelfLayoutManager::CalculateTargetBounds(
const State& state, const State& state,
HotseatState hotseat_target_state) { HotseatState hotseat_target_state) {
const int shelf_size = ShelfConfig::Get()->shelf_size(); const int shelf_size = ShelfConfig::Get()->shelf_size();
const int horizontal_edge_spacing =
ShelfConfig::Get()->control_button_edge_spacing(
shelf_->IsHorizontalAlignment());
const int vertical_edge_spacing =
ShelfConfig::Get()->control_button_edge_spacing(
!shelf_->IsHorizontalAlignment());
// By default, show the whole shelf on the screen. // By default, show the whole shelf on the screen.
int shelf_in_screen_portion = shelf_size; int shelf_in_screen_portion = shelf_size;
...@@ -1661,39 +1651,7 @@ void ShelfLayoutManager::CalculateTargetBounds( ...@@ -1661,39 +1651,7 @@ void ShelfLayoutManager::CalculateTargetBounds(
shelf_->status_area_widget()->CalculateTargetBounds(); shelf_->status_area_widget()->CalculateTargetBounds();
shelf_->navigation_widget()->CalculateTargetBounds(); shelf_->navigation_widget()->CalculateTargetBounds();
shelf_->hotseat_widget()->CalculateTargetBounds();
const gfx::Size status_size =
shelf_->status_area_widget()->GetTargetBounds().size();
gfx::Rect nav_bounds = shelf_->navigation_widget()->GetTargetBounds();
gfx::Point hotseat_origin;
int hotseat_width;
int hotseat_height;
if (shelf_->IsHorizontalAlignment()) {
hotseat_width =
shelf_width - nav_bounds.size().width() - horizontal_edge_spacing -
ShelfConfig::Get()->app_icon_group_margin() - status_size.width();
int hotseat_x =
base::i18n::IsRTL()
? nav_bounds.x() - horizontal_edge_spacing - hotseat_width
: nav_bounds.right() + horizontal_edge_spacing;
if (hotseat_target_state != HotseatState::kShown) {
// Give the hotseat more space if it is shown outside of the shelf.
hotseat_width = available_bounds.width();
hotseat_x = target_bounds_.shelf_bounds.x();
}
hotseat_origin =
gfx::Point(hotseat_x, CalculateHotseatYInScreen(hotseat_target_state));
hotseat_height = ShelfConfig::Get()->hotseat_size();
} else {
hotseat_origin = gfx::Point(target_bounds_.shelf_bounds.x(),
nav_bounds.bottom() + vertical_edge_spacing);
hotseat_width = shelf_width;
hotseat_height =
shelf_height - nav_bounds.size().height() - vertical_edge_spacing -
ShelfConfig::Get()->app_icon_group_margin() - status_size.height();
}
target_bounds_.hotseat_bounds_in_screen =
gfx::Rect(hotseat_origin, gfx::Size(hotseat_width, hotseat_height));
target_bounds_.opacity = ComputeTargetOpacity(state); target_bounds_.opacity = ComputeTargetOpacity(state);
...@@ -1709,12 +1667,6 @@ void ShelfLayoutManager::CalculateTargetBounds( ...@@ -1709,12 +1667,6 @@ void ShelfLayoutManager::CalculateTargetBounds(
0), 0),
gfx::Insets(0, GetShelfInset(state.visibility_state, shelf_width), 0, 0), gfx::Insets(0, GetShelfInset(state.visibility_state, shelf_width), 0, 0),
gfx::Insets(0, 0, 0, GetShelfInset(state.visibility_state, shelf_width))); gfx::Insets(0, 0, 0, GetShelfInset(state.visibility_state, shelf_width)));
// This needs to happen after calling UpdateTargetBoundsForGesture(), because
// that can change the size of the shelf.
gfx::Rect nav_bounds_in_shelf = nav_bounds;
// Convert back into shelf coordinates.
nav_bounds_in_shelf.Offset(-shelf_origin.x(), -shelf_origin.y());
} }
void ShelfLayoutManager::CalculateTargetBoundsAndUpdateWorkArea() { void ShelfLayoutManager::CalculateTargetBoundsAndUpdateWorkArea() {
...@@ -1723,7 +1675,7 @@ void ShelfLayoutManager::CalculateTargetBoundsAndUpdateWorkArea() { ...@@ -1723,7 +1675,7 @@ void ShelfLayoutManager::CalculateTargetBoundsAndUpdateWorkArea() {
CalculateTargetBounds(state_, hotseat_target_state); CalculateTargetBounds(state_, hotseat_target_state);
gfx::Rect shelf_bounds_for_workarea_calculation = target_bounds_.shelf_bounds; gfx::Rect shelf_bounds_for_workarea_calculation = target_bounds_.shelf_bounds;
// When the hotseat is enabled, only use the in-app shelf bounds when // When the hotseat is enabled, only use the in-app shelf bounds when
// calculating the work area. This prevents windows resizing unnecesarily. // calculating the work area. This prevents windows resizing unnecessarily.
if (IsHotseatEnabled()) { if (IsHotseatEnabled()) {
shelf_bounds_for_workarea_calculation = shelf_bounds_for_workarea_calculation =
GetIdealBoundsForWorkAreaCalculation(); GetIdealBoundsForWorkAreaCalculation();
...@@ -1791,7 +1743,9 @@ void ShelfLayoutManager::UpdateTargetBoundsForGesture( ...@@ -1791,7 +1743,9 @@ void ShelfLayoutManager::UpdateTargetBoundsForGesture(
if (!IsHotseatEnabled()) { if (!IsHotseatEnabled()) {
target_bounds_.shelf_bounds.set_y(baseline + translate); target_bounds_.shelf_bounds.set_y(baseline + translate);
shelf_->navigation_widget()->UpdateTargetBoundsForGesture(); shelf_->navigation_widget()->UpdateTargetBoundsForGesture();
target_bounds_.hotseat_bounds_in_screen.set_y(baseline + translate); gfx::Rect hotseat_bounds = shelf_->hotseat_widget()->GetTargetBounds();
hotseat_bounds.set_y(baseline + translate);
shelf_->hotseat_widget()->set_target_bounds(hotseat_bounds);
shelf_->status_area_widget()->UpdateTargetBoundsForGesture(); shelf_->status_area_widget()->UpdateTargetBoundsForGesture();
return; return;
} }
...@@ -1833,14 +1787,17 @@ void ShelfLayoutManager::UpdateTargetBoundsForGesture( ...@@ -1833,14 +1787,17 @@ void ShelfLayoutManager::UpdateTargetBoundsForGesture(
// the hotseat down. // the hotseat down.
if (IsWindowDragInProgress()) if (IsWindowDragInProgress())
hotseat_y = -hotseat_extended_y; hotseat_y = -hotseat_extended_y;
target_bounds_.hotseat_bounds_in_screen.set_y( gfx::Rect hotseat_bounds = shelf_->hotseat_widget()->GetTargetBounds();
hotseat_y + target_bounds_.shelf_bounds.y()); hotseat_bounds.set_y(hotseat_y + target_bounds_.shelf_bounds.y());
shelf_->hotseat_widget()->set_target_bounds(hotseat_bounds);
return; return;
} }
target_bounds_.shelf_bounds.set_x(baseline + translate); target_bounds_.shelf_bounds.set_x(baseline + translate);
shelf_->navigation_widget()->UpdateTargetBoundsForGesture(); shelf_->navigation_widget()->UpdateTargetBoundsForGesture();
target_bounds_.hotseat_bounds_in_screen.set_x(baseline + translate); gfx::Rect hotseat_bounds = shelf_->hotseat_widget()->GetTargetBounds();
hotseat_bounds.set_x(baseline + translate);
shelf_->hotseat_widget()->set_target_bounds(hotseat_bounds);
shelf_->status_area_widget()->UpdateTargetBoundsForGesture(); shelf_->status_area_widget()->UpdateTargetBoundsForGesture();
} }
......
...@@ -266,7 +266,6 @@ class ASH_EXPORT ShelfLayoutManager ...@@ -266,7 +266,6 @@ class ASH_EXPORT ShelfLayoutManager
void OnTabletModeEnded() override; void OnTabletModeEnded() override;
gfx::Rect GetShelfBoundsInScreen() const; gfx::Rect GetShelfBoundsInScreen() const;
gfx::Rect GetHotseatBoundsInScreen() const;
float GetOpacity() const; float GetOpacity() const;
bool updating_bounds() const { return updating_bounds_; } bool updating_bounds() const { return updating_bounds_; }
...@@ -283,6 +282,12 @@ class ASH_EXPORT ShelfLayoutManager ...@@ -283,6 +282,12 @@ class ASH_EXPORT ShelfLayoutManager
return drag_status_ == kDragAppListInProgress; return drag_status_ == kDragAppListInProgress;
} }
// Gets the target HotseatState based on the current state of HomeLauncher,
// Overview, Shelf, and any active gestures.
// TODO(manucornet): Move this to the hotseat class.
HotseatState CalculateHotseatState(ShelfVisibilityState visibility_state,
ShelfAutoHideState auto_hide_state);
private: private:
class UpdateShelfObserver; class UpdateShelfObserver;
friend class DimShelfLayoutManagerTestBase; friend class DimShelfLayoutManagerTestBase;
...@@ -299,7 +304,6 @@ class ASH_EXPORT ShelfLayoutManager ...@@ -299,7 +304,6 @@ class ASH_EXPORT ShelfLayoutManager
float opacity; float opacity;
gfx::Rect shelf_bounds; // Bounds of the shelf within the screen gfx::Rect shelf_bounds; // Bounds of the shelf within the screen
gfx::Rect hotseat_bounds_in_screen; // Bounds of the hotseat within screen
gfx::Insets shelf_insets; // Shelf insets within the screen gfx::Insets shelf_insets; // Shelf insets within the screen
}; };
...@@ -347,11 +351,6 @@ class ASH_EXPORT ShelfLayoutManager ...@@ -347,11 +351,6 @@ class ASH_EXPORT ShelfLayoutManager
// Sets the visibility of the shelf to |state|. // Sets the visibility of the shelf to |state|.
void SetState(ShelfVisibilityState visibility_state); void SetState(ShelfVisibilityState visibility_state);
// Gets the target HotseatState based on the current state of HomeLauncher,
// Overview, Shelf, and any active gestures.
HotseatState CalculateHotseatState(ShelfVisibilityState visibility_state,
ShelfAutoHideState auto_hide_state);
// Returns shelf visibility state based on current value of auto hide // Returns shelf visibility state based on current value of auto hide
// behavior setting. // behavior setting.
ShelfVisibilityState CalculateShelfVisibility(); ShelfVisibilityState CalculateShelfVisibility();
......
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