Commit 71358f40 authored by Manu Cornet's avatar Manu Cornet Committed by Commit Bot

CrOS Shelf: Move shelf widget bound calculation to that class

Change-Id: Idae5f3fec0e8fbcbf1dbff9a3982e0a90b64d900
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2053249
Commit-Queue: Manu Cornet <manucornet@chromium.org>
Reviewed-by: default avatarAndrew Xu <andrewxu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#741144}
parent 8b8f74cf
......@@ -361,7 +361,7 @@ ShelfVisibilityState Shelf::GetVisibilityState() const {
}
gfx::Rect Shelf::GetShelfBoundsInScreen() const {
return shelf_layout_manager_->GetShelfBoundsInScreen();
return shelf_widget()->GetTargetBounds();
}
gfx::Rect Shelf::GetIdealBounds() const {
......
......@@ -1084,10 +1084,6 @@ void ShelfLayoutManager::OnDeskSwitchAnimationFinished() {
UpdateVisibilityState();
}
gfx::Rect ShelfLayoutManager::GetShelfBoundsInScreen() const {
return target_bounds_.shelf_bounds;
}
float ShelfLayoutManager::GetOpacity() const {
return target_bounds_.opacity;
}
......@@ -1118,10 +1114,12 @@ int ShelfLayoutManager::CalculateHotseatYInScreen(
ShelfConfig::Get()->hotseat_bottom_padding() + hotseat_size;
break;
}
const int current_shelf_size = target_bounds_.shelf_bounds.size().height();
const int current_shelf_size =
shelf_->shelf_widget()->GetTargetBounds().size().height();
const int hotseat_y_in_shelf =
-(hotseat_distance_from_bottom_of_display - current_shelf_size);
return hotseat_y_in_shelf + target_bounds_.shelf_bounds.y();
const int shelf_y = shelf_->shelf_widget()->GetTargetBounds().y();
return hotseat_y_in_shelf + shelf_y;
}
void ShelfLayoutManager::OnShelfConfigUpdated() {
......@@ -1488,9 +1486,10 @@ void ShelfLayoutManager::UpdateBoundsAndOpacity(bool animate) {
gfx::Transform shelf_widget_target_transform;
shelf_widget_target_transform.Translate(
current_shelf_bounds.origin() - target_bounds_.shelf_bounds.origin());
current_shelf_bounds.origin() -
shelf_->shelf_widget()->GetTargetBounds().origin());
shelf_widget_->GetLayer()->SetTransform(shelf_widget_target_transform);
shelf_widget_->SetBounds(target_bounds_.shelf_bounds);
shelf_widget_->SetBounds(shelf_->shelf_widget()->GetTargetBounds());
ui::ScopedLayerAnimationSettings shelf_animation_setter(
GetLayer(shelf_widget_)->GetAnimator());
......@@ -1605,45 +1604,7 @@ void ShelfLayoutManager::StopAnimating() {
void ShelfLayoutManager::CalculateTargetBounds(
const State& state,
HotseatState hotseat_target_state) {
const int shelf_size = ShelfConfig::Get()->shelf_size();
// By default, show the whole shelf on the screen.
int shelf_in_screen_portion = shelf_size;
const WorkAreaInsets* const work_area =
WorkAreaInsets::ForWindow(shelf_widget_->GetNativeWindow());
if (state.IsShelfAutoHidden()) {
shelf_in_screen_portion =
Shell::Get()->app_list_controller()->home_launcher_transition_state() ==
AppListControllerImpl::HomeLauncherTransitionState::kMostlyShown
? shelf_size
: ShelfConfig::Get()->hidden_shelf_in_screen_portion();
} else if (state.visibility_state == SHELF_HIDDEN ||
work_area->IsKeyboardShown()) {
shelf_in_screen_portion = 0;
}
gfx::Rect available_bounds =
screen_util::GetDisplayBoundsWithShelf(shelf_widget_->GetNativeWindow());
available_bounds.Inset(work_area->GetAccessibilityInsets());
int shelf_width =
shelf_->PrimaryAxisValue(available_bounds.width(), shelf_size);
int shelf_height =
shelf_->PrimaryAxisValue(shelf_size, available_bounds.height());
const int shelf_primary_position = shelf_->SelectValueForShelfAlignment(
available_bounds.bottom() - shelf_in_screen_portion,
available_bounds.x() - shelf_size + shelf_in_screen_portion,
available_bounds.right() - shelf_in_screen_portion);
gfx::Point shelf_origin = shelf_->SelectValueForShelfAlignment(
gfx::Point(available_bounds.x(), shelf_primary_position),
gfx::Point(shelf_primary_position, available_bounds.y()),
gfx::Point(shelf_primary_position, available_bounds.y()));
target_bounds_.shelf_bounds = screen_util::SnapBoundsToDisplayEdge(
gfx::Rect(shelf_origin.x(), shelf_origin.y(), shelf_width, shelf_height),
shelf_widget_->GetNativeWindow());
shelf_->shelf_widget()->CalculateTargetBounds();
shelf_->status_area_widget()->CalculateTargetBounds();
shelf_->navigation_widget()->CalculateTargetBounds();
shelf_->hotseat_widget()->CalculateTargetBounds();
......@@ -1653,22 +1614,31 @@ void ShelfLayoutManager::CalculateTargetBounds(
if (drag_status_ == kDragInProgress)
UpdateTargetBoundsForGesture(hotseat_target_state);
const gfx::Rect shelf_bounds = shelf_->shelf_widget()->GetTargetBounds();
gfx::Rect snapped_shelf_bounds(shelf_bounds);
screen_util::SnapBoundsToDisplayEdge(
snapped_shelf_bounds, shelf_->shelf_widget()->GetNativeWindow());
shelf_->shelf_widget()->set_target_bounds(snapped_shelf_bounds);
target_bounds_.shelf_insets = shelf_->SelectValueForShelfAlignment(
gfx::Insets(0, 0,
GetShelfInset(state.visibility_state,
IsHotseatEnabled()
? ShelfConfig::Get()->in_app_shelf_size()
: shelf_height),
: shelf_bounds.height()),
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, GetShelfInset(state.visibility_state, shelf_bounds.width()), 0, 0),
gfx::Insets(0, 0, 0,
GetShelfInset(state.visibility_state, shelf_bounds.width())));
}
void ShelfLayoutManager::CalculateTargetBoundsAndUpdateWorkArea() {
HotseatState hotseat_target_state =
CalculateHotseatState(visibility_state(), auto_hide_state());
CalculateTargetBounds(state_, hotseat_target_state);
gfx::Rect shelf_bounds_for_workarea_calculation = target_bounds_.shelf_bounds;
gfx::Rect shelf_bounds_for_workarea_calculation =
shelf_->shelf_widget()->GetTargetBounds();
// When the hotseat is enabled, only use the in-app shelf bounds when
// calculating the work area. This prevents windows resizing unnecessarily.
if (IsHotseatEnabled()) {
......@@ -1736,7 +1706,8 @@ void ShelfLayoutManager::UpdateTargetBoundsForGesture(
if (horizontal) {
if (!IsHotseatEnabled()) {
target_bounds_.shelf_bounds.set_y(baseline + translate);
shelf_->shelf_widget()->UpdateTargetBoundsForGesture(baseline +
translate);
shelf_->navigation_widget()->UpdateTargetBoundsForGesture();
gfx::Rect hotseat_bounds = shelf_->hotseat_widget()->GetTargetBounds();
hotseat_bounds.set_y(baseline + translate);
......@@ -1758,7 +1729,10 @@ void ShelfLayoutManager::UpdateTargetBoundsForGesture(
// move the hotseat down.
if (IsWindowDragInProgress())
shelf_y = available_bounds.bottom() - shelf_size;
target_bounds_.shelf_bounds.set_y(shelf_y);
gfx::Rect updated_target_bounds =
shelf_->shelf_widget()->GetTargetBounds();
updated_target_bounds.set_y(shelf_y);
shelf_->shelf_widget()->set_target_bounds(updated_target_bounds);
}
int hotseat_y = 0;
......@@ -1782,13 +1756,14 @@ void ShelfLayoutManager::UpdateTargetBoundsForGesture(
// the hotseat down.
if (IsWindowDragInProgress())
hotseat_y = -hotseat_extended_y;
gfx::Rect shelf_bounds = shelf_->shelf_widget()->GetTargetBounds();
gfx::Rect hotseat_bounds = shelf_->hotseat_widget()->GetTargetBounds();
hotseat_bounds.set_y(hotseat_y + target_bounds_.shelf_bounds.y());
hotseat_bounds.set_y(hotseat_y + shelf_bounds.y());
shelf_->hotseat_widget()->set_target_bounds(hotseat_bounds);
return;
}
target_bounds_.shelf_bounds.set_x(baseline + translate);
shelf_->shelf_widget()->UpdateTargetBoundsForGesture(baseline + translate);
shelf_->navigation_widget()->UpdateTargetBoundsForGesture();
gfx::Rect hotseat_bounds = shelf_->hotseat_widget()->GetTargetBounds();
hotseat_bounds.set_x(baseline + translate);
......
......@@ -250,6 +250,8 @@ class ASH_EXPORT ShelfLayoutManager
return state_.visibility_state;
}
bool is_shelf_auto_hidden() const { return state_.IsShelfAutoHidden(); }
void LockAutoHideState(bool lock_auto_hide_state) {
is_auto_hide_state_locked_ = lock_auto_hide_state;
}
......@@ -265,7 +267,6 @@ class ASH_EXPORT ShelfLayoutManager
void OnTabletModeStarted() override;
void OnTabletModeEnded() override;
gfx::Rect GetShelfBoundsInScreen() const;
float GetOpacity() const;
bool updating_bounds() const { return updating_bounds_; }
......@@ -303,7 +304,6 @@ class ASH_EXPORT ShelfLayoutManager
float opacity;
gfx::Rect shelf_bounds; // Bounds of the shelf within the screen
gfx::Insets shelf_insets; // Shelf insets within the screen
};
......
......@@ -8,6 +8,7 @@
#include "ash/accessibility/accessibility_controller_impl.h"
#include "ash/animation/animation_change_type.h"
#include "ash/app_list/app_list_controller_impl.h"
#include "ash/focus_cycler.h"
#include "ash/keyboard/ui/keyboard_ui_controller.h"
#include "ash/public/cpp/ash_features.h"
......@@ -16,6 +17,7 @@
#include "ash/public/cpp/shelf_model.h"
#include "ash/public/cpp/window_properties.h"
#include "ash/root_window_controller.h"
#include "ash/screen_util.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shelf/drag_handle.h"
#include "ash/shelf/home_button.h"
......@@ -33,6 +35,7 @@
#include "ash/style/ash_color_provider.h"
#include "ash/system/status_area_widget.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "ash/wm/work_area_insets.h"
#include "base/command_line.h"
#include "chromeos/constants/chromeos_switches.h"
#include "ui/compositor/layer.h"
......@@ -74,6 +77,11 @@ views::View* FindFirstOrLastFocusableChild(views::View* root,
&dummy_focus_traversable, &dummy_focus_traversable_view);
}
bool IsHotseatEnabled() {
return Shell::Get()->IsInTabletMode() &&
chromeos::switches::ShouldShowShelfHotseat();
}
} // namespace
// The contents view of the Shelf. In an active session, this is used to
......@@ -678,8 +686,44 @@ void ShelfWidget::OnBackgroundTypeChanged(ShelfBackgroundType background_type,
}
void ShelfWidget::CalculateTargetBounds() {
// TODO(manucornet): Move target bounds calculations from the shelf layout
// manager.
const ShelfLayoutManager* layout_manager = shelf_->shelf_layout_manager();
const int shelf_size = ShelfConfig::Get()->shelf_size();
// By default, show the whole shelf on the screen.
int shelf_in_screen_portion = shelf_size;
const WorkAreaInsets* const work_area =
WorkAreaInsets::ForWindow(GetNativeWindow());
if (layout_manager->is_shelf_auto_hidden()) {
shelf_in_screen_portion =
Shell::Get()->app_list_controller()->home_launcher_transition_state() ==
AppListControllerImpl::HomeLauncherTransitionState::kMostlyShown
? shelf_size
: ShelfConfig::Get()->hidden_shelf_in_screen_portion();
} else if (layout_manager->visibility_state() == SHELF_HIDDEN ||
work_area->IsKeyboardShown()) {
shelf_in_screen_portion = 0;
}
gfx::Rect available_bounds =
screen_util::GetDisplayBoundsWithShelf(GetNativeWindow());
available_bounds.Inset(work_area->GetAccessibilityInsets());
int shelf_width =
shelf_->PrimaryAxisValue(available_bounds.width(), shelf_size);
int shelf_height =
shelf_->PrimaryAxisValue(shelf_size, available_bounds.height());
const int shelf_primary_position = shelf_->SelectValueForShelfAlignment(
available_bounds.bottom() - shelf_in_screen_portion,
available_bounds.x() - shelf_size + shelf_in_screen_portion,
available_bounds.right() - shelf_in_screen_portion);
gfx::Point shelf_origin = shelf_->SelectValueForShelfAlignment(
gfx::Point(available_bounds.x(), shelf_primary_position),
gfx::Point(shelf_primary_position, available_bounds.y()),
gfx::Point(shelf_primary_position, available_bounds.y()));
target_bounds_ =
gfx::Rect(shelf_origin.x(), shelf_origin.y(), shelf_width, shelf_height);
}
void ShelfWidget::UpdateLayout(bool animate) {
......@@ -687,10 +731,17 @@ void ShelfWidget::UpdateLayout(bool animate) {
delegate_view_->UpdateOpaqueBackground();
}
void ShelfWidget::UpdateTargetBoundsForGesture(int new_position) {
if (shelf_->IsHorizontalAlignment()) {
if (!IsHotseatEnabled())
target_bounds_.set_y(new_position);
} else {
target_bounds_.set_x(new_position);
}
}
gfx::Rect ShelfWidget::GetTargetBounds() const {
// TODO(manucornet): Store these locally and do not depend on the layout
// manager.
return shelf_->shelf_layout_manager()->GetShelfBoundsInScreen();
return target_bounds_;
}
void ShelfWidget::OnSessionStateChanged(session_manager::SessionState state) {
......
......@@ -109,6 +109,14 @@ class ASH_EXPORT ShelfWidget : public AccessibilityObserver,
gfx::Rect GetTargetBounds() const override;
void UpdateLayout(bool animate) override;
// TODO(manucornet): Remove this method when all this widget's layout
// logic is part of this class.
void set_target_bounds(gfx::Rect target_bounds) {
target_bounds_ = target_bounds;
}
void UpdateTargetBoundsForGesture(int new_position);
// ShelfLayoutManagerObserver:
void WillDeleteShelfLayoutManager() override;
void OnHotseatStateChanged(HotseatState old_state,
......@@ -179,7 +187,7 @@ class ASH_EXPORT ShelfWidget : public AccessibilityObserver,
const ShelfView* GetShelfView() const;
Shelf* shelf_;
gfx::Rect target_bounds_;
ShelfBackgroundAnimator background_animator_;
// Owned by the shelf container's window.
......
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