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

CrOS Status area: Let the status widget calculate its own bounds

This is a step in the direction of better compartmentalizing each
shelf component and better coordinate animations. It also aims at making
the shelf layout manager not so huge.

Change-Id: I7369e00f87bda1fac0956e119d60f34d9716a651
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2033567
Commit-Queue: Manu Cornet <manucornet@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737572}
parent 02185a07
...@@ -615,7 +615,6 @@ component("ash") { ...@@ -615,7 +615,6 @@ component("ash") {
"shelf/shelf_button_delegate.h", "shelf/shelf_button_delegate.h",
"shelf/shelf_button_pressed_metric_tracker.cc", "shelf/shelf_button_pressed_metric_tracker.cc",
"shelf/shelf_button_pressed_metric_tracker.h", "shelf/shelf_button_pressed_metric_tracker.h",
"shelf/shelf_component.cc",
"shelf/shelf_component.h", "shelf/shelf_component.h",
"shelf/shelf_config.cc", "shelf/shelf_config.cc",
"shelf/shelf_container_view.cc", "shelf/shelf_container_view.cc",
......
...@@ -1366,16 +1366,14 @@ gfx::Insets ScrollableShelfView::CalculateEdgePadding( ...@@ -1366,16 +1366,14 @@ gfx::Insets ScrollableShelfView::CalculateEdgePadding(
int ScrollableShelfView::GetStatusWidgetSizeOnPrimaryAxis( int ScrollableShelfView::GetStatusWidgetSizeOnPrimaryAxis(
bool use_target_bounds) const { bool use_target_bounds) const {
const gfx::Size status_widget_size = use_target_bounds const gfx::Size status_widget_size =
? GetShelf() use_target_bounds
->shelf_layout_manager() ? GetShelf()->status_area_widget()->GetTargetBounds().size()
->GetStatusAreaBoundsInScreen() : GetShelf()
.size() ->shelf_widget()
: GetShelf() ->status_area_widget()
->shelf_widget() ->GetWindowBoundsInScreen()
->status_area_widget() .size();
->GetWindowBoundsInScreen()
.size();
return GetShelf()->PrimaryAxisValue(status_widget_size.width(), return GetShelf()->PrimaryAxisValue(status_widget_size.width(),
status_widget_size.height()); status_widget_size.height());
} }
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/shelf/shelf_component.h"
namespace ash {
// TODO(manucornet): Make this pure virtual when all subclasses implement it.
gfx::Rect ShelfComponent::GetTargetBounds() const {
return gfx::Rect();
}
} // namespace ash
...@@ -20,7 +20,7 @@ class ASH_EXPORT ShelfComponent { ...@@ -20,7 +20,7 @@ class ASH_EXPORT ShelfComponent {
virtual void CalculateTargetBounds() = 0; virtual void CalculateTargetBounds() = 0;
// Returns this component's current target bounds, in screen coordinates. // Returns this component's current target bounds, in screen coordinates.
virtual gfx::Rect GetTargetBounds() const; virtual gfx::Rect GetTargetBounds() const = 0;
// Updates the component's layout and bounds to match the most recently // Updates the component's layout and bounds to match the most recently
// calculated target bounds. The change should be animated if |animate| is // calculated target bounds. The change should be animated if |animate| is
......
...@@ -1082,10 +1082,6 @@ gfx::Rect ShelfLayoutManager::GetHotseatBounds() const { ...@@ -1082,10 +1082,6 @@ gfx::Rect ShelfLayoutManager::GetHotseatBounds() const {
return hotseat_bounds; return hotseat_bounds;
} }
gfx::Rect ShelfLayoutManager::GetStatusAreaBoundsInScreen() const {
return target_bounds_.status_bounds_in_screen;
}
float ShelfLayoutManager::GetOpacity() const { float ShelfLayoutManager::GetOpacity() const {
return target_bounds_.opacity; return target_bounds_.opacity;
} }
...@@ -1631,26 +1627,11 @@ void ShelfLayoutManager::CalculateTargetBounds( ...@@ -1631,26 +1627,11 @@ void ShelfLayoutManager::CalculateTargetBounds(
gfx::Rect(shelf_origin.x(), shelf_origin.y(), shelf_width, shelf_height), gfx::Rect(shelf_origin.x(), shelf_origin.y(), shelf_width, shelf_height),
shelf_widget_->GetNativeWindow()); shelf_widget_->GetNativeWindow());
gfx::Size status_size( shelf_->status_area_widget()->CalculateTargetBounds();
shelf_widget_->status_area_widget()->GetWindowBoundsInScreen().size());
if (shelf_->IsHorizontalAlignment())
status_size.set_height(shelf_size);
else
status_size.set_width(shelf_size);
gfx::Point status_origin = shelf_->SelectValueForShelfAlignment(
gfx::Point(0, 0),
gfx::Point(shelf_width - status_size.width(),
shelf_height - status_size.height()),
gfx::Point(0, shelf_height - status_size.height()));
if (shelf_->IsHorizontalAlignment() && !base::i18n::IsRTL())
status_origin.set_x(shelf_width - status_size.width());
status_origin.Offset(shelf_origin.x(), shelf_origin.y());
target_bounds_.status_bounds_in_screen =
gfx::Rect(status_origin, status_size);
shelf_->navigation_widget()->CalculateTargetBounds(); shelf_->navigation_widget()->CalculateTargetBounds();
const gfx::Size status_size =
shelf_->status_area_widget()->GetTargetBounds().size();
gfx::Rect nav_bounds_in_shelf = gfx::Rect nav_bounds_in_shelf =
shelf_->navigation_widget()->GetTargetBounds(); shelf_->navigation_widget()->GetTargetBounds();
// Convert back into shelf coordinates. // Convert back into shelf coordinates.
...@@ -1802,11 +1783,10 @@ void ShelfLayoutManager::UpdateTargetBoundsForGesture( ...@@ -1802,11 +1783,10 @@ void ShelfLayoutManager::UpdateTargetBoundsForGesture(
if (horizontal) { if (horizontal) {
if (!IsHotseatEnabled()) { if (!IsHotseatEnabled()) {
const int shelf_y = baseline + translate; target_bounds_.shelf_bounds.set_y(baseline + translate);
target_bounds_.shelf_bounds.set_y(shelf_y);
shelf_->navigation_widget()->UpdateTargetBoundsForGesture(); shelf_->navigation_widget()->UpdateTargetBoundsForGesture();
target_bounds_.hotseat_bounds_in_shelf.set_y(0); target_bounds_.hotseat_bounds_in_shelf.set_y(0);
target_bounds_.status_bounds_in_screen.set_y(shelf_y); shelf_->status_area_widget()->UpdateTargetBoundsForGesture();
return; return;
} }
...@@ -1851,11 +1831,10 @@ void ShelfLayoutManager::UpdateTargetBoundsForGesture( ...@@ -1851,11 +1831,10 @@ void ShelfLayoutManager::UpdateTargetBoundsForGesture(
return; return;
} }
const int shelf_x = baseline + translate;
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_shelf.set_x(0); target_bounds_.hotseat_bounds_in_shelf.set_x(0);
target_bounds_.status_bounds_in_screen.set_x(shelf_x); shelf_->status_area_widget()->UpdateTargetBoundsForGesture();
} }
void ShelfLayoutManager::UpdateAutoHideStateNow() { void ShelfLayoutManager::UpdateAutoHideStateNow() {
......
...@@ -249,10 +249,8 @@ class ASH_EXPORT ShelfLayoutManager ...@@ -249,10 +249,8 @@ class ASH_EXPORT ShelfLayoutManager
// coordinates. // coordinates.
int CalculateHotseatYInShelf(HotseatState hotseat_target_state) const; int CalculateHotseatYInShelf(HotseatState hotseat_target_state) const;
// Getters for bounds and opacity of the various sub-components.
gfx::Rect GetShelfBoundsInScreen() const; gfx::Rect GetShelfBoundsInScreen() const;
gfx::Rect GetHotseatBounds() const; gfx::Rect GetHotseatBounds() const;
gfx::Rect GetStatusAreaBoundsInScreen() const;
float GetOpacity() const; float GetOpacity() const;
bool updating_bounds() const { return updating_bounds_; } bool updating_bounds() const { return updating_bounds_; }
...@@ -287,7 +285,6 @@ class ASH_EXPORT ShelfLayoutManager ...@@ -287,7 +285,6 @@ class ASH_EXPORT ShelfLayoutManager
gfx::Rect shelf_bounds; // Bounds of the shelf within the screen gfx::Rect shelf_bounds; // Bounds of the shelf within the screen
gfx::Rect shelf_bounds_in_shelf; // Bounds of the shelf minus status area gfx::Rect shelf_bounds_in_shelf; // Bounds of the shelf minus status area
gfx::Rect hotseat_bounds_in_shelf; // Bounds of the hotseat within shelf gfx::Rect hotseat_bounds_in_shelf; // Bounds of the hotseat within shelf
gfx::Rect status_bounds_in_screen; // Bounds of status area within screen
gfx::Insets shelf_insets; // Shelf insets within the screen gfx::Insets shelf_insets; // Shelf insets within the screen
}; };
......
...@@ -186,8 +186,29 @@ void StatusAreaWidget::UpdateCollapseState() { ...@@ -186,8 +186,29 @@ void StatusAreaWidget::UpdateCollapseState() {
} }
void StatusAreaWidget::CalculateTargetBounds() { void StatusAreaWidget::CalculateTargetBounds() {
// TODO(manucornet): Move target bounds calculations from the shelf layout gfx::Size status_size(status_area_widget_delegate_->size());
// manager. const gfx::Size shelf_size = shelf_->shelf_widget()->GetTargetBounds().size();
const gfx::Point shelf_origin =
shelf_->shelf_widget()->GetTargetBounds().origin();
if (shelf_->IsHorizontalAlignment())
status_size.set_height(shelf_size.height());
else
status_size.set_width(shelf_size.width());
gfx::Point status_origin = shelf_->SelectValueForShelfAlignment(
gfx::Point(0, 0),
gfx::Point(shelf_size.width() - status_size.width(),
shelf_size.height() - status_size.height()),
gfx::Point(0, shelf_size.height() - status_size.height()));
if (shelf_->IsHorizontalAlignment() && !base::i18n::IsRTL())
status_origin.set_x(shelf_size.width() - status_size.width());
status_origin.Offset(shelf_origin.x(), shelf_origin.y());
target_bounds_ = gfx::Rect(status_origin, status_size);
}
gfx::Rect StatusAreaWidget::GetTargetBounds() const {
return target_bounds_;
} }
void StatusAreaWidget::UpdateLayout(bool animate) { void StatusAreaWidget::UpdateLayout(bool animate) {
...@@ -202,7 +223,22 @@ void StatusAreaWidget::UpdateLayout(bool animate) { ...@@ -202,7 +223,22 @@ void StatusAreaWidget::UpdateLayout(bool animate) {
animation_setter.SetTweenType(gfx::Tween::EASE_OUT); animation_setter.SetTweenType(gfx::Tween::EASE_OUT);
animation_setter.SetPreemptionStrategy( animation_setter.SetPreemptionStrategy(
ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
SetBounds(layout_manager->GetStatusAreaBoundsInScreen()); SetBounds(target_bounds_);
}
void StatusAreaWidget::UpdateTargetBoundsForGesture() {
const gfx::Point shelf_origin =
shelf_->shelf_widget()->GetTargetBounds().origin();
if (shelf_->IsHorizontalAlignment()) {
const bool tablet_mode =
Shell::Get()->tablet_mode_controller() &&
Shell::Get()->tablet_mode_controller()->InTabletMode();
if (!tablet_mode || !chromeos::switches::ShouldShowShelfHotseat()) {
target_bounds_.set_y(shelf_origin.y());
}
} else {
target_bounds_.set_x(shelf_origin.x());
}
} }
void StatusAreaWidget::CalculateButtonVisibilityForCollapsedState() { void StatusAreaWidget::CalculateButtonVisibilityForCollapsedState() {
......
...@@ -65,8 +65,11 @@ class ASH_EXPORT StatusAreaWidget : public ShelfComponent, ...@@ -65,8 +65,11 @@ class ASH_EXPORT StatusAreaWidget : public ShelfComponent,
// ShelfComponent: // ShelfComponent:
void CalculateTargetBounds() override; void CalculateTargetBounds() override;
gfx::Rect GetTargetBounds() const override;
void UpdateLayout(bool animate) override; void UpdateLayout(bool animate) override;
void UpdateTargetBoundsForGesture();
// Sets system tray visibility. Shows or hides widget if needed. // Sets system tray visibility. Shows or hides widget if needed.
void SetSystemTrayVisibility(bool visible); void SetSystemTrayVisibility(bool visible);
...@@ -165,6 +168,8 @@ class ASH_EXPORT StatusAreaWidget : public ShelfComponent, ...@@ -165,6 +168,8 @@ class ASH_EXPORT StatusAreaWidget : public ShelfComponent,
CollapseState collapse_state_ = CollapseState::NOT_COLLAPSIBLE; CollapseState collapse_state_ = CollapseState::NOT_COLLAPSIBLE;
gfx::Rect target_bounds_;
Shelf* shelf_; Shelf* shelf_;
bool initialized_ = false; bool initialized_ = false;
......
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