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

CrOS Shelf: Trim some more fat from the shelf layout manager

Distribute a little more logic from the shelf layout manager to
individual shelf components where it belongs. Now that most coordinates
are calculated within the screen, moving this logic around is a lot
easier.

Change-Id: Ib682350c7bcea935ddea21918b8ba09e3903a367
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2066107
Commit-Queue: Manu Cornet <manucornet@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#743135}
parent 8ddc6d4a
...@@ -397,6 +397,42 @@ void HotseatWidget::SetTranslucentBackground( ...@@ -397,6 +397,42 @@ void HotseatWidget::SetTranslucentBackground(
delegate_view_->SetTranslucentBackground(translucent_background_bounds); delegate_view_->SetTranslucentBackground(translucent_background_bounds);
} }
int HotseatWidget::CalculateHotseatYInScreen(
HotseatState hotseat_target_state) const {
DCHECK(shelf_->IsHorizontalAlignment());
const bool is_hotseat_enabled = Shell::Get()->IsInTabletMode() &&
chromeos::switches::ShouldShowShelfHotseat();
int hotseat_distance_from_bottom_of_display;
const int hotseat_size = ShelfConfig::Get()->hotseat_size();
switch (hotseat_target_state) {
case HotseatState::kShown: {
// When the hotseat state is HotseatState::kShown in tablet mode, the
// home launcher is showing. Elevate the hotseat a few px to match the
// navigation and status area.
const bool use_padding = is_hotseat_enabled;
hotseat_distance_from_bottom_of_display =
hotseat_size +
(use_padding ? ShelfConfig::Get()->hotseat_bottom_padding() : 0);
} break;
case HotseatState::kHidden:
// Show the hotseat offscreen.
hotseat_distance_from_bottom_of_display = 0;
break;
case HotseatState::kExtended:
// Show the hotseat at its extended position.
hotseat_distance_from_bottom_of_display =
ShelfConfig::Get()->in_app_shelf_size() +
ShelfConfig::Get()->hotseat_bottom_padding() + hotseat_size;
break;
}
const int target_shelf_size =
shelf_->shelf_widget()->GetTargetBounds().size().height();
const int hotseat_y_in_shelf =
-(hotseat_distance_from_bottom_of_display - target_shelf_size);
const int shelf_y = shelf_->shelf_widget()->GetTargetBounds().y();
return hotseat_y_in_shelf + shelf_y;
}
void HotseatWidget::CalculateTargetBounds() { void HotseatWidget::CalculateTargetBounds() {
ShelfLayoutManager* layout_manager = shelf_->shelf_layout_manager(); ShelfLayoutManager* layout_manager = shelf_->shelf_layout_manager();
const HotseatState hotseat_target_state = const HotseatState hotseat_target_state =
...@@ -429,9 +465,8 @@ void HotseatWidget::CalculateTargetBounds() { ...@@ -429,9 +465,8 @@ void HotseatWidget::CalculateTargetBounds() {
hotseat_width = shelf_bounds.width(); hotseat_width = shelf_bounds.width();
hotseat_x = shelf_bounds.x(); hotseat_x = shelf_bounds.x();
} }
hotseat_origin = gfx::Point( hotseat_origin =
hotseat_x, gfx::Point(hotseat_x, CalculateHotseatYInScreen(hotseat_target_state));
layout_manager->CalculateHotseatYInScreen(hotseat_target_state));
hotseat_height = ShelfConfig::Get()->hotseat_size(); hotseat_height = ShelfConfig::Get()->hotseat_size();
} else { } else {
hotseat_origin = gfx::Point(shelf_bounds.x(), hotseat_origin = gfx::Point(shelf_bounds.x(),
......
...@@ -74,6 +74,10 @@ class ASH_EXPORT HotseatWidget : public ShelfComponent, ...@@ -74,6 +74,10 @@ class ASH_EXPORT HotseatWidget : public ShelfComponent,
// hotseat background. // hotseat background.
void SetTranslucentBackground(const gfx::Rect& background_bounds); void SetTranslucentBackground(const gfx::Rect& background_bounds);
// Calculates the hotseat y position for |hotseat_target_state| in screen
// coordinates.
int CalculateHotseatYInScreen(HotseatState hotseat_target_state) const;
// ShelfComponent: // ShelfComponent:
void CalculateTargetBounds() override; void CalculateTargetBounds() override;
gfx::Rect GetTargetBounds() const override; gfx::Rect GetTargetBounds() const override;
......
...@@ -565,7 +565,7 @@ void ShelfLayoutManager::UpdateAutoHideForMouseEvent(ui::MouseEvent* event, ...@@ -565,7 +565,7 @@ void ShelfLayoutManager::UpdateAutoHideForMouseEvent(ui::MouseEvent* event,
if (event->type() == ui::ET_MOUSE_PRESSED || if (event->type() == ui::ET_MOUSE_PRESSED ||
event->type() == ui::ET_MOUSE_MOVED) { event->type() == ui::ET_MOUSE_MOVED) {
if (GetVisibleShelfBounds().Contains( if (shelf_->shelf_widget()->GetVisibleShelfBounds().Contains(
display::Screen::GetScreen()->GetCursorScreenPoint())) { display::Screen::GetScreen()->GetCursorScreenPoint())) {
UpdateAutoHideState(); UpdateAutoHideState();
last_seen_mouse_position_was_over_shelf_ = true; last_seen_mouse_position_was_over_shelf_ = true;
...@@ -1070,40 +1070,6 @@ float ShelfLayoutManager::GetOpacity() const { ...@@ -1070,40 +1070,6 @@ float ShelfLayoutManager::GetOpacity() const {
return target_opacity_; return target_opacity_;
} }
int ShelfLayoutManager::CalculateHotseatYInScreen(
HotseatState hotseat_target_state) const {
DCHECK(shelf_->IsHorizontalAlignment());
int hotseat_distance_from_bottom_of_display;
const int hotseat_size = ShelfConfig::Get()->hotseat_size();
switch (hotseat_target_state) {
case HotseatState::kShown: {
// When the hotseat state is HotseatState::kShown in tablet mode, the
// home launcher is showing. Elevate the hotseat a few px to match the
// navigation and status area.
const bool use_padding = IsHotseatEnabled();
hotseat_distance_from_bottom_of_display =
hotseat_size +
(use_padding ? ShelfConfig::Get()->hotseat_bottom_padding() : 0);
} break;
case HotseatState::kHidden:
// Show the hotseat offscreen.
hotseat_distance_from_bottom_of_display = 0;
break;
case HotseatState::kExtended:
// Show the hotseat at its extended position.
hotseat_distance_from_bottom_of_display =
ShelfConfig::Get()->in_app_shelf_size() +
ShelfConfig::Get()->hotseat_bottom_padding() + hotseat_size;
break;
}
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);
const int shelf_y = shelf_->shelf_widget()->GetTargetBounds().y();
return hotseat_y_in_shelf + shelf_y;
}
void ShelfLayoutManager::OnShelfConfigUpdated() { void ShelfLayoutManager::OnShelfConfigUpdated() {
LayoutShelf(/*animate=*/true); LayoutShelf(/*animate=*/true);
} }
...@@ -1510,6 +1476,8 @@ gfx::Insets ShelfLayoutManager::CalculateTargetBounds( ...@@ -1510,6 +1476,8 @@ gfx::Insets ShelfLayoutManager::CalculateTargetBounds(
if (drag_status_ == kDragInProgress) if (drag_status_ == kDragInProgress)
UpdateTargetBoundsForGesture(hotseat_target_state); UpdateTargetBoundsForGesture(hotseat_target_state);
// TODO(manucornet): Snap bounds in the shelf widget directly, and adjust
// tests that don't expect snapped bounds.
const gfx::Rect shelf_bounds = shelf_->shelf_widget()->GetTargetBounds(); const gfx::Rect shelf_bounds = shelf_->shelf_widget()->GetTargetBounds();
gfx::Rect snapped_shelf_bounds(shelf_bounds); gfx::Rect snapped_shelf_bounds(shelf_bounds);
screen_util::SnapBoundsToDisplayEdge( screen_util::SnapBoundsToDisplayEdge(
...@@ -1686,16 +1654,9 @@ void ShelfLayoutManager::StopAutoHideTimer() { ...@@ -1686,16 +1654,9 @@ void ShelfLayoutManager::StopAutoHideTimer() {
mouse_over_shelf_when_auto_hide_timer_started_ = false; mouse_over_shelf_when_auto_hide_timer_started_ = false;
} }
gfx::Rect ShelfLayoutManager::GetVisibleShelfBounds() const {
gfx::Rect shelf_region = shelf_widget_->GetWindowBoundsInScreen();
DCHECK(!display_.bounds().IsEmpty());
shelf_region.Intersect(display_.bounds());
return screen_util::SnapBoundsToDisplayEdge(shelf_region,
shelf_widget_->GetNativeWindow());
}
gfx::Rect ShelfLayoutManager::GetAutoHideShowShelfRegionInScreen() const { gfx::Rect ShelfLayoutManager::GetAutoHideShowShelfRegionInScreen() const {
gfx::Rect shelf_bounds_in_screen = GetVisibleShelfBounds(); gfx::Rect shelf_bounds_in_screen =
shelf_->shelf_widget()->GetVisibleShelfBounds();
gfx::Vector2d offset = shelf_->SelectValueForShelfAlignment( gfx::Vector2d offset = shelf_->SelectValueForShelfAlignment(
gfx::Vector2d(0, shelf_bounds_in_screen.height()), gfx::Vector2d(0, shelf_bounds_in_screen.height()),
gfx::Vector2d(-kMaxAutoHideShowShelfRegionSize, 0), gfx::Vector2d(-kMaxAutoHideShowShelfRegionSize, 0),
...@@ -1813,7 +1774,7 @@ ShelfLayoutManager::CalculateAutoHideStateBasedOnCursorLocation() const { ...@@ -1813,7 +1774,7 @@ ShelfLayoutManager::CalculateAutoHideStateBasedOnCursorLocation() const {
if (!shelf_widget_->IsMouseEventsEnabled()) if (!shelf_widget_->IsMouseEventsEnabled())
return SHELF_AUTO_HIDE_HIDDEN; return SHELF_AUTO_HIDE_HIDDEN;
gfx::Rect shelf_region = GetVisibleShelfBounds(); gfx::Rect shelf_region = shelf_->shelf_widget()->GetVisibleShelfBounds();
if (shelf_widget_->status_area_widget() && if (shelf_widget_->status_area_widget() &&
shelf_widget_->status_area_widget()->IsMessageBubbleShown() && shelf_widget_->status_area_widget()->IsMessageBubbleShown() &&
IsVisible()) { IsVisible()) {
...@@ -2209,7 +2170,8 @@ bool ShelfLayoutManager::StartShelfDrag(const ui::LocatedEvent& event_in_screen, ...@@ -2209,7 +2170,8 @@ bool ShelfLayoutManager::StartShelfDrag(const ui::LocatedEvent& event_in_screen,
// If the start location is above the shelf (e.g., on the extended hotseat), // If the start location is above the shelf (e.g., on the extended hotseat),
// do not allow window drag when the hotseat is extended. // do not allow window drag when the hotseat is extended.
const gfx::Rect shelf_bounds = GetVisibleShelfBounds(); const gfx::Rect shelf_bounds =
shelf_->shelf_widget()->GetVisibleShelfBounds();
allow_window_drag_on_extended_hotseat_ = allow_window_drag_on_extended_hotseat_ =
event_in_screen.location_f().y() >= shelf_bounds.y(); event_in_screen.location_f().y() >= shelf_bounds.y();
......
...@@ -257,10 +257,6 @@ class ASH_EXPORT ShelfLayoutManager ...@@ -257,10 +257,6 @@ class ASH_EXPORT ShelfLayoutManager
is_auto_hide_state_locked_ = lock_auto_hide_state; is_auto_hide_state_locked_ = lock_auto_hide_state;
} }
// Calculates the hotseat y position for |hotseat_target_state| in screen
// coordinates.
int CalculateHotseatYInScreen(HotseatState hotseat_target_state) const;
// ShelfConfig::Observer: // ShelfConfig::Observer:
void OnShelfConfigUpdated() override; void OnShelfConfigUpdated() override;
...@@ -383,11 +379,6 @@ class ASH_EXPORT ShelfLayoutManager ...@@ -383,11 +379,6 @@ class ASH_EXPORT ShelfLayoutManager
// |mouse_over_shelf_when_auto_hide_timer_started_|. // |mouse_over_shelf_when_auto_hide_timer_started_|.
void StopAutoHideTimer(); void StopAutoHideTimer();
// Returns the bounds of the shelf on the screen. The returned rect does
// not include portions of the shelf that extend beyond its own display,
// as those are not visible to the user.
gfx::Rect GetVisibleShelfBounds() const;
// Returns the bounds of an additional region which can trigger showing the // Returns the bounds of an additional region which can trigger showing the
// shelf. This region exists to make it easier to trigger showing the shelf // shelf. This region exists to make it easier to trigger showing the shelf
// when the shelf is auto hidden and the shelf is on the boundary between // when the shelf is auto hidden and the shelf is on the boundary between
......
...@@ -661,6 +661,15 @@ gfx::Rect ShelfWidget::GetScreenBoundsOfItemIconForWindow( ...@@ -661,6 +661,15 @@ gfx::Rect ShelfWidget::GetScreenBoundsOfItemIconForWindow(
bounds.height()); bounds.height());
} }
gfx::Rect ShelfWidget::GetVisibleShelfBounds() const {
gfx::Rect shelf_region = GetWindowBoundsInScreen();
const display::Display display =
display::Screen::GetScreen()->GetDisplayNearestWindow(GetNativeWindow());
DCHECK(!display.bounds().IsEmpty());
shelf_region.Intersect(display.bounds());
return screen_util::SnapBoundsToDisplayEdge(shelf_region, GetNativeWindow());
}
ApplicationDragAndDropHost* ShelfWidget::GetDragAndDropHostForAppList() { ApplicationDragAndDropHost* ShelfWidget::GetDragAndDropHostForAppList() {
return hotseat_widget()->GetShelfView(); return hotseat_widget()->GetShelfView();
} }
......
...@@ -90,6 +90,11 @@ class ASH_EXPORT ShelfWidget : public AccessibilityObserver, ...@@ -90,6 +90,11 @@ class ASH_EXPORT ShelfWidget : public AccessibilityObserver,
// See Shelf::GetScreenBoundsOfItemIconForWindow(). // See Shelf::GetScreenBoundsOfItemIconForWindow().
gfx::Rect GetScreenBoundsOfItemIconForWindow(aura::Window* window); gfx::Rect GetScreenBoundsOfItemIconForWindow(aura::Window* window);
// Returns the bounds of the shelf on the screen. The returned rect does
// not include portions of the shelf that extend beyond its own display,
// as those are not visible to the user.
gfx::Rect GetVisibleShelfBounds() const;
// Returns the ApplicationDragAndDropHost for this shelf. // Returns the ApplicationDragAndDropHost for this shelf.
ApplicationDragAndDropHost* GetDragAndDropHostForAppList(); ApplicationDragAndDropHost* GetDragAndDropHostForAppList();
......
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