Commit 1c90fe14 authored by Manu Cornet's avatar Manu Cornet

CrOS Shelf: Let the nav widget calculate & keep track of its own bounds

Also remove |TargetBounds| comparison logic in the shelf layout manager
that isn't used any more, and access some of the shelf components
directly from |Shelf| instead of going through |ShelfWidget|.

This is a step in the direction of better compartmentalizing each
shelf component and better coordinate animations.

Change-Id: If9e4b6dcb17c40988e54db2395271b84922a6167
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2032073
Commit-Queue: Manu Cornet <manucornet@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737415}
parent 1f509735
...@@ -1075,13 +1075,6 @@ gfx::Rect ShelfLayoutManager::GetShelfBoundsInScreen() const { ...@@ -1075,13 +1075,6 @@ gfx::Rect ShelfLayoutManager::GetShelfBoundsInScreen() const {
return target_bounds_.shelf_bounds; return target_bounds_.shelf_bounds;
} }
gfx::Rect ShelfLayoutManager::GetNavigationBounds() const {
gfx::Vector2d nav_offset = target_bounds_.shelf_bounds.OffsetFromOrigin();
gfx::Rect nav_bounds = target_bounds_.nav_bounds_in_shelf;
nav_bounds.Offset(nav_offset);
return nav_bounds;
}
gfx::Rect ShelfLayoutManager::GetHotseatBounds() const { gfx::Rect ShelfLayoutManager::GetHotseatBounds() const {
gfx::Vector2d offset = target_bounds_.shelf_bounds.OffsetFromOrigin(); gfx::Vector2d offset = target_bounds_.shelf_bounds.OffsetFromOrigin();
gfx::Rect hotseat_bounds = target_bounds_.hotseat_bounds_in_shelf; gfx::Rect hotseat_bounds = target_bounds_.hotseat_bounds_in_shelf;
...@@ -1427,7 +1420,7 @@ void ShelfLayoutManager::SetDimmed(bool dimmed) { ...@@ -1427,7 +1420,7 @@ void ShelfLayoutManager::SetDimmed(bool dimmed) {
dimmed_for_inactivity_ = dimmed; dimmed_for_inactivity_ = dimmed;
CalculateTargetBoundsAndUpdateWorkArea(); CalculateTargetBoundsAndUpdateWorkArea();
AnimateOpacity(shelf_widget_->navigation_widget(), target_bounds_.opacity, AnimateOpacity(shelf_->navigation_widget(), target_bounds_.opacity,
kDimAnimationDuration, gfx::Tween::LINEAR); kDimAnimationDuration, gfx::Tween::LINEAR);
AnimateOpacity(shelf_widget_->hotseat_widget(), AnimateOpacity(shelf_widget_->hotseat_widget(),
...@@ -1452,7 +1445,7 @@ void ShelfLayoutManager::UpdateBoundsAndOpacity(bool animate) { ...@@ -1452,7 +1445,7 @@ void ShelfLayoutManager::UpdateBoundsAndOpacity(bool animate) {
} }
} }
ShelfNavigationWidget* nav_widget = shelf_widget_->navigation_widget(); ShelfNavigationWidget* nav_widget = shelf_->navigation_widget();
HotseatWidget* hotseat_widget = shelf_widget_->hotseat_widget(); HotseatWidget* hotseat_widget = shelf_widget_->hotseat_widget();
StatusAreaWidget* status_widget = shelf_widget_->status_area_widget(); StatusAreaWidget* status_widget = shelf_widget_->status_area_widget();
base::AutoReset<bool> auto_reset_updating_bounds(&updating_bounds_, true); base::AutoReset<bool> auto_reset_updating_bounds(&updating_bounds_, true);
...@@ -1652,31 +1645,24 @@ void ShelfLayoutManager::CalculateTargetBounds( ...@@ -1652,31 +1645,24 @@ void ShelfLayoutManager::CalculateTargetBounds(
target_bounds_.status_bounds_in_screen = target_bounds_.status_bounds_in_screen =
gfx::Rect(status_origin, status_size); gfx::Rect(status_origin, status_size);
gfx::Point nav_origin = gfx::Point(); shelf_->navigation_widget()->CalculateTargetBounds();
gfx::Size nav_size = shelf_widget_->navigation_widget()->GetIdealSize();
// Enlarge the widget to take up available space, this ensures events which
// are outside of the HomeButton bounds can be received.
if (!nav_size.IsEmpty())
nav_size.Enlarge(home_button_edge_spacing, home_button_edge_spacing);
if (shelf_->IsHorizontalAlignment() && base::i18n::IsRTL())
nav_origin.set_x(shelf_width - nav_size.width());
target_bounds_.nav_bounds_in_shelf = gfx::Rect(nav_origin, nav_size);
gfx::Rect nav_bounds_in_shelf =
shelf_->navigation_widget()->GetTargetBounds();
// Convert back into shelf coordinates.
nav_bounds_in_shelf.Offset(-shelf_origin.x(), -shelf_origin.y());
gfx::Point hotseat_origin; gfx::Point hotseat_origin;
int hotseat_width; int hotseat_width;
int hotseat_height; int hotseat_height;
if (shelf_->IsHorizontalAlignment()) { if (shelf_->IsHorizontalAlignment()) {
hotseat_width = hotseat_width = shelf_width - nav_bounds_in_shelf.size().width() -
shelf_width - target_bounds_.nav_bounds_in_shelf.size().width() - home_button_edge_spacing -
home_button_edge_spacing - ShelfConfig::Get()->app_icon_group_margin() - ShelfConfig::Get()->app_icon_group_margin() -
status_size.width(); status_size.width();
int hotseat_x = base::i18n::IsRTL() int hotseat_x =
? target_bounds_.nav_bounds_in_shelf.x() - base::i18n::IsRTL()
home_button_edge_spacing - hotseat_width ? nav_bounds_in_shelf.x() - home_button_edge_spacing - hotseat_width
: target_bounds_.nav_bounds_in_shelf.right() + : nav_bounds_in_shelf.right() + home_button_edge_spacing;
home_button_edge_spacing;
if (hotseat_target_state != HotseatState::kShown) { if (hotseat_target_state != HotseatState::kShown) {
// Give the hotseat more space if it is shown outside of the shelf. // Give the hotseat more space if it is shown outside of the shelf.
hotseat_width = available_bounds.width(); hotseat_width = available_bounds.width();
...@@ -1686,13 +1672,13 @@ void ShelfLayoutManager::CalculateTargetBounds( ...@@ -1686,13 +1672,13 @@ void ShelfLayoutManager::CalculateTargetBounds(
gfx::Point(hotseat_x, CalculateHotseatYInShelf(hotseat_target_state)); gfx::Point(hotseat_x, CalculateHotseatYInShelf(hotseat_target_state));
hotseat_height = ShelfConfig::Get()->hotseat_size(); hotseat_height = ShelfConfig::Get()->hotseat_size();
} else { } else {
hotseat_origin = gfx::Point(0, target_bounds_.nav_bounds_in_shelf.bottom() + hotseat_origin =
home_button_edge_spacing); gfx::Point(0, nav_bounds_in_shelf.bottom() + home_button_edge_spacing);
hotseat_width = shelf_width; hotseat_width = shelf_width;
hotseat_height = hotseat_height = shelf_height - nav_bounds_in_shelf.size().height() -
shelf_height - target_bounds_.nav_bounds_in_shelf.size().height() - home_button_edge_spacing -
home_button_edge_spacing - ShelfConfig::Get()->app_icon_group_margin() - ShelfConfig::Get()->app_icon_group_margin() -
status_size.height(); status_size.height();
} }
target_bounds_.hotseat_bounds_in_shelf = target_bounds_.hotseat_bounds_in_shelf =
gfx::Rect(hotseat_origin, gfx::Size(hotseat_width, hotseat_height)); gfx::Rect(hotseat_origin, gfx::Size(hotseat_width, hotseat_height));
...@@ -1717,21 +1703,18 @@ void ShelfLayoutManager::CalculateTargetBounds( ...@@ -1717,21 +1703,18 @@ void ShelfLayoutManager::CalculateTargetBounds(
const bool showing_login_shelf = !state.IsActiveSessionState(); const bool showing_login_shelf = !state.IsActiveSessionState();
if (chromeos::switches::ShouldShowScrollableShelf() && !showing_login_shelf) { if (chromeos::switches::ShouldShowScrollableShelf() && !showing_login_shelf) {
target_bounds_.shelf_bounds_in_shelf = shelf_->SelectValueForShelfAlignment( target_bounds_.shelf_bounds_in_shelf = shelf_->SelectValueForShelfAlignment(
gfx::Rect(target_bounds_.nav_bounds_in_shelf.right(), 0, gfx::Rect(nav_bounds_in_shelf.right(), 0,
shelf_width - status_size.width() - shelf_width - status_size.width() -
target_bounds_.nav_bounds_in_shelf.width() - nav_bounds_in_shelf.width() - home_button_edge_spacing,
home_button_edge_spacing,
target_bounds_.shelf_bounds.height()), target_bounds_.shelf_bounds.height()),
gfx::Rect(0, target_bounds_.nav_bounds_in_shelf.height(), gfx::Rect(0, nav_bounds_in_shelf.height(),
target_bounds_.shelf_bounds.width(), target_bounds_.shelf_bounds.width(),
shelf_height - status_size.height() - shelf_height - status_size.height() -
target_bounds_.nav_bounds_in_shelf.height() - nav_bounds_in_shelf.height() - home_button_edge_spacing),
home_button_edge_spacing), gfx::Rect(0, nav_bounds_in_shelf.height(),
gfx::Rect(0, target_bounds_.nav_bounds_in_shelf.height(),
target_bounds_.shelf_bounds.width(), target_bounds_.shelf_bounds.width(),
shelf_height - status_size.height() - shelf_height - status_size.height() -
target_bounds_.nav_bounds_in_shelf.height() - nav_bounds_in_shelf.height() - home_button_edge_spacing));
home_button_edge_spacing));
} else { } else {
target_bounds_.shelf_bounds_in_shelf = shelf_->SelectValueForShelfAlignment( target_bounds_.shelf_bounds_in_shelf = shelf_->SelectValueForShelfAlignment(
gfx::Rect(0, 0, shelf_width - status_size.width(), gfx::Rect(0, 0, shelf_width - status_size.width(),
...@@ -1817,8 +1800,7 @@ void ShelfLayoutManager::UpdateTargetBoundsForGesture( ...@@ -1817,8 +1800,7 @@ void ShelfLayoutManager::UpdateTargetBoundsForGesture(
if (!IsHotseatEnabled()) { if (!IsHotseatEnabled()) {
const int shelf_y = baseline + translate; const int shelf_y = baseline + translate;
target_bounds_.shelf_bounds.set_y(shelf_y); target_bounds_.shelf_bounds.set_y(shelf_y);
target_bounds_.nav_bounds_in_shelf.set_y( shelf_->navigation_widget()->UpdateTargetBoundsForGesture();
ShelfConfig::Get()->button_spacing());
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); target_bounds_.status_bounds_in_screen.set_y(shelf_y);
return; return;
...@@ -1867,8 +1849,7 @@ void ShelfLayoutManager::UpdateTargetBoundsForGesture( ...@@ -1867,8 +1849,7 @@ void ShelfLayoutManager::UpdateTargetBoundsForGesture(
const int shelf_x = baseline + translate; const int shelf_x = baseline + translate;
target_bounds_.shelf_bounds.set_x(baseline + translate); target_bounds_.shelf_bounds.set_x(baseline + translate);
target_bounds_.nav_bounds_in_shelf.set_x( shelf_->navigation_widget()->UpdateTargetBoundsForGesture();
ShelfConfig::Get()->button_spacing());
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); target_bounds_.status_bounds_in_screen.set_x(shelf_x);
} }
...@@ -1958,8 +1939,7 @@ ShelfAutoHideState ShelfLayoutManager::CalculateAutoHideState( ...@@ -1958,8 +1939,7 @@ ShelfAutoHideState ShelfLayoutManager::CalculateAutoHideState(
if (shelf_widget_->hotseat_widget()->IsShowingOverflowBubble()) if (shelf_widget_->hotseat_widget()->IsShowingOverflowBubble())
return SHELF_AUTO_HIDE_SHOWN; return SHELF_AUTO_HIDE_SHOWN;
if (shelf_widget_->IsActive() || if (shelf_widget_->IsActive() || shelf_->navigation_widget()->IsActive() ||
shelf_widget_->navigation_widget()->IsActive() ||
shelf_widget_->hotseat_widget()->IsActive() || shelf_widget_->hotseat_widget()->IsActive() ||
(shelf_widget_->status_area_widget() && (shelf_widget_->status_area_widget() &&
shelf_widget_->status_area_widget()->IsActive())) { shelf_widget_->status_area_widget()->IsActive())) {
...@@ -2069,7 +2049,7 @@ bool ShelfLayoutManager::IsShelfWindow(aura::Window* window) { ...@@ -2069,7 +2049,7 @@ bool ShelfLayoutManager::IsShelfWindow(aura::Window* window) {
return false; return false;
const aura::Window* shelf_window = shelf_widget_->GetNativeWindow(); const aura::Window* shelf_window = shelf_widget_->GetNativeWindow();
const aura::Window* navigation_window = const aura::Window* navigation_window =
shelf_widget_->navigation_widget()->GetNativeWindow(); shelf_->navigation_widget()->GetNativeWindow();
const aura::Window* hotseat_window = const aura::Window* hotseat_window =
shelf_widget_->hotseat_widget()->GetNativeWindow(); shelf_widget_->hotseat_widget()->GetNativeWindow();
const aura::Window* status_area_window = const aura::Window* status_area_window =
......
...@@ -251,7 +251,6 @@ class ASH_EXPORT ShelfLayoutManager ...@@ -251,7 +251,6 @@ class ASH_EXPORT ShelfLayoutManager
// Getters for bounds and opacity of the various sub-components. // Getters for bounds and opacity of the various sub-components.
gfx::Rect GetShelfBoundsInScreen() const; gfx::Rect GetShelfBoundsInScreen() const;
gfx::Rect GetNavigationBounds() const;
gfx::Rect GetHotseatBounds() const; gfx::Rect GetHotseatBounds() const;
gfx::Rect GetStatusAreaBoundsInScreen() const; gfx::Rect GetStatusAreaBoundsInScreen() const;
float GetOpacity() const; float GetOpacity() const;
...@@ -287,56 +286,9 @@ class ASH_EXPORT ShelfLayoutManager ...@@ -287,56 +286,9 @@ 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 nav_bounds_in_shelf; // Bounds of nav widget within shelf
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::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
bool operator==(const TargetBounds& other) {
return opacity == other.opacity && shelf_bounds == other.shelf_bounds &&
shelf_bounds_in_shelf == other.shelf_bounds_in_shelf &&
nav_bounds_in_shelf == other.nav_bounds_in_shelf &&
hotseat_bounds_in_shelf == other.hotseat_bounds_in_shelf &&
status_bounds_in_screen == other.status_bounds_in_screen &&
shelf_insets == other.shelf_insets;
}
std::string diff_for_debug(const TargetBounds& other) {
std::string diff = "";
if (*this == other)
return diff;
if (opacity != other.opacity) {
diff += " opacity " + base::NumberToString(opacity) + " vs " +
base::NumberToString(other.opacity);
}
if (shelf_bounds != other.shelf_bounds) {
diff += " shelf_bounds " + shelf_bounds.ToString() + " vs " +
other.shelf_bounds.ToString();
}
if (shelf_bounds_in_shelf != other.shelf_bounds_in_shelf) {
diff += " shelf_bounds_in_shelf " + shelf_bounds_in_shelf.ToString() +
" vs " + other.shelf_bounds_in_shelf.ToString();
}
if (nav_bounds_in_shelf != other.nav_bounds_in_shelf) {
diff += " nav_bounds_in_shelf " + nav_bounds_in_shelf.ToString() +
" vs " + other.nav_bounds_in_shelf.ToString();
}
if (hotseat_bounds_in_shelf != other.hotseat_bounds_in_shelf) {
diff += " hotseat_bounds_in_shelf " +
hotseat_bounds_in_shelf.ToString() + " vs " +
other.hotseat_bounds_in_shelf.ToString();
}
if (status_bounds_in_screen != other.status_bounds_in_screen) {
diff += " status_bounds_in_screen " +
status_bounds_in_screen.ToString() + " vs " +
other.status_bounds_in_screen.ToString();
}
if (shelf_insets != other.shelf_insets) {
diff += " shelf_insets " + shelf_insets.ToString() + " vs " +
other.shelf_insets.ToString();
}
return diff;
}
}; };
struct State { struct State {
......
...@@ -411,14 +411,28 @@ void ShelfNavigationWidget::OnShelfConfigUpdated() { ...@@ -411,14 +411,28 @@ void ShelfNavigationWidget::OnShelfConfigUpdated() {
} }
void ShelfNavigationWidget::CalculateTargetBounds() { void ShelfNavigationWidget::CalculateTargetBounds() {
// TODO(manucornet): Move target bounds calculations from the shelf layout const int home_button_edge_spacing =
// manager. ShelfConfig::Get()->home_button_edge_spacing();
const gfx::Point shelf_origin =
shelf_->shelf_widget()->GetTargetBounds().origin();
gfx::Point nav_origin = gfx::Point(shelf_origin.x(), shelf_origin.y());
gfx::Size nav_size = GetIdealSize();
// Enlarge the widget to take up available space, this ensures events which
// are outside of the HomeButton bounds can be received.
if (!nav_size.IsEmpty())
nav_size.Enlarge(home_button_edge_spacing, home_button_edge_spacing);
if (shelf_->IsHorizontalAlignment() && base::i18n::IsRTL()) {
nav_origin.set_x(shelf_->shelf_widget()->GetTargetBounds().size().width() -
nav_size.width());
}
target_bounds_ = gfx::Rect(nav_origin, nav_size);
} }
gfx::Rect ShelfNavigationWidget::GetTargetBounds() const { gfx::Rect ShelfNavigationWidget::GetTargetBounds() const {
// TODO(manucornet): Store these locally and do not depend on the layout return target_bounds_;
// manager.
return shelf_->shelf_layout_manager()->GetNavigationBounds();
} }
void ShelfNavigationWidget::UpdateLayout(bool animate) { void ShelfNavigationWidget::UpdateLayout(bool animate) {
...@@ -449,7 +463,7 @@ void ShelfNavigationWidget::UpdateLayout(bool animate) { ...@@ -449,7 +463,7 @@ void ShelfNavigationWidget::UpdateLayout(bool animate) {
nav_animation_setter.SetPreemptionStrategy( nav_animation_setter.SetPreemptionStrategy(
ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
SetBounds(shelf_->shelf_layout_manager()->GetNavigationBounds()); SetBounds(target_bounds_);
views::View* const back_button = delegate_->back_button(); views::View* const back_button = delegate_->back_button();
UpdateButtonVisibility(back_button, back_button_shown, animate); UpdateButtonVisibility(back_button, back_button_shown, animate);
...@@ -469,6 +483,20 @@ void ShelfNavigationWidget::UpdateLayout(bool animate) { ...@@ -469,6 +483,20 @@ void ShelfNavigationWidget::UpdateLayout(bool animate) {
delegate_->UpdateOpaqueBackground(); delegate_->UpdateOpaqueBackground();
} }
void ShelfNavigationWidget::UpdateTargetBoundsForGesture() {
const gfx::Point shelf_origin =
shelf_->shelf_widget()->GetTargetBounds().origin();
if (shelf_->IsHorizontalAlignment()) {
if (!IsTabletMode() || !chromeos::switches::ShouldShowShelfHotseat()) {
target_bounds_.set_y(shelf_origin.y() +
ShelfConfig::Get()->button_spacing());
}
} else {
target_bounds_.set_x(shelf_origin.x() +
ShelfConfig::Get()->button_spacing());
}
}
void ShelfNavigationWidget::UpdateButtonVisibility(views::View* button, void ShelfNavigationWidget::UpdateButtonVisibility(views::View* button,
bool visible, bool visible,
bool animate) { bool animate) {
......
...@@ -96,6 +96,8 @@ class ASH_EXPORT ShelfNavigationWidget : public TabletModeObserver, ...@@ -96,6 +96,8 @@ class ASH_EXPORT ShelfNavigationWidget : public TabletModeObserver,
gfx::Rect GetTargetBounds() const override; gfx::Rect GetTargetBounds() const override;
void UpdateLayout(bool animate) override; void UpdateLayout(bool animate) override;
void UpdateTargetBoundsForGesture();
private: private:
class Delegate; class Delegate;
...@@ -103,6 +105,7 @@ class ASH_EXPORT ShelfNavigationWidget : public TabletModeObserver, ...@@ -103,6 +105,7 @@ class ASH_EXPORT ShelfNavigationWidget : public TabletModeObserver,
Shelf* shelf_ = nullptr; Shelf* shelf_ = nullptr;
Delegate* delegate_ = nullptr; Delegate* delegate_ = nullptr;
gfx::Rect target_bounds_;
std::unique_ptr<views::BoundsAnimator> bounds_animator_; std::unique_ptr<views::BoundsAnimator> bounds_animator_;
DISALLOW_COPY_AND_ASSIGN(ShelfNavigationWidget); DISALLOW_COPY_AND_ASSIGN(ShelfNavigationWidget);
......
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