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

CrOS Shelf: Add a target bounds getter method for the shelf component

This is a step in the direction of letting each shelf component
calculate and store its target bounds instead of having everything in
the shelf layout manager.

This change doesn't modify any of the actual semantics of bound
calculation yet.

Change-Id: Ibf08b425e9799d97f93fc9a4b17156ed15ae34d8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2032566Reviewed-by: default avatarMatthew Mourgos <mmourgos@chromium.org>
Commit-Queue: Manu Cornet <manucornet@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737168}
parent 57ccdd9c
...@@ -615,6 +615,7 @@ component("ash") { ...@@ -615,6 +615,7 @@ 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",
......
...@@ -244,6 +244,7 @@ bool HotseatWidget::ShouldShowHotseatBackground() { ...@@ -244,6 +244,7 @@ bool HotseatWidget::ShouldShowHotseatBackground() {
void HotseatWidget::Initialize(aura::Window* container, Shelf* shelf) { void HotseatWidget::Initialize(aura::Window* container, Shelf* shelf) {
DCHECK(container); DCHECK(container);
DCHECK(shelf); DCHECK(shelf);
shelf_ = shelf;
views::Widget::InitParams params( views::Widget::InitParams params(
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
params.name = "HotseatWidget"; params.name = "HotseatWidget";
...@@ -354,6 +355,12 @@ void HotseatWidget::CalculateTargetBounds() { ...@@ -354,6 +355,12 @@ void HotseatWidget::CalculateTargetBounds() {
// manager. // manager.
} }
gfx::Rect HotseatWidget::GetTargetBounds() const {
// TODO(manucornet): Store these locally and do not depend on the layout
// manager.
return shelf_->shelf_layout_manager()->GetHotseatBounds();
}
void HotseatWidget::UpdateLayout(bool animate) { void HotseatWidget::UpdateLayout(bool animate) {
const LayoutInputs new_layout_inputs = GetLayoutInputs(); const LayoutInputs new_layout_inputs = GetLayoutInputs();
if (layout_inputs_.has_value() && *layout_inputs_ == new_layout_inputs) if (layout_inputs_.has_value() && *layout_inputs_ == new_layout_inputs)
......
...@@ -69,6 +69,7 @@ class ASH_EXPORT HotseatWidget : public ShelfComponent, ...@@ -69,6 +69,7 @@ class ASH_EXPORT HotseatWidget : 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;
gfx::Size GetTranslucentBackgroundSize() const; gfx::Size GetTranslucentBackgroundSize() const;
...@@ -122,6 +123,8 @@ class ASH_EXPORT HotseatWidget : public ShelfComponent, ...@@ -122,6 +123,8 @@ class ASH_EXPORT HotseatWidget : public ShelfComponent,
HotseatState state_ = HotseatState::kShown; HotseatState state_ = HotseatState::kShown;
Shelf* shelf_ = nullptr;
// View containing the shelf items within an active user session. Owned by // View containing the shelf items within an active user session. Owned by
// the views hierarchy. // the views hierarchy.
ShelfView* shelf_view_ = nullptr; ShelfView* shelf_view_ = nullptr;
......
// 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
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
#define ASH_SHELF_SHELF_COMPONENT_H_ #define ASH_SHELF_SHELF_COMPONENT_H_
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "ui/gfx/geometry/rect.h"
namespace ash {
// An interface describing any shelf component such as the navigation widget, // An interface describing any shelf component such as the navigation widget,
// the hotseat widget or the status area widget, to make it easier to // the hotseat widget or the status area widget, to make it easier to
...@@ -16,10 +19,15 @@ class ASH_EXPORT ShelfComponent { ...@@ -16,10 +19,15 @@ class ASH_EXPORT ShelfComponent {
// calculated bounds. // calculated bounds.
virtual void CalculateTargetBounds() = 0; virtual void CalculateTargetBounds() = 0;
// Returns this component's current target bounds, in screen coordinates.
virtual gfx::Rect GetTargetBounds() const;
// 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
// true. // true.
virtual void UpdateLayout(bool animate) = 0; virtual void UpdateLayout(bool animate) = 0;
}; };
} // namespace ash
#endif // ASH_SHELF_SHELF_COMPONENT_H_ #endif // ASH_SHELF_SHELF_COMPONENT_H_
...@@ -409,6 +409,12 @@ void ShelfNavigationWidget::CalculateTargetBounds() { ...@@ -409,6 +409,12 @@ void ShelfNavigationWidget::CalculateTargetBounds() {
// manager. // manager.
} }
gfx::Rect ShelfNavigationWidget::GetTargetBounds() const {
// TODO(manucornet): Store these locally and do not depend on the layout
// manager.
return shelf_->shelf_layout_manager()->GetNavigationBounds();
}
void ShelfNavigationWidget::UpdateLayout(bool animate) { void ShelfNavigationWidget::UpdateLayout(bool animate) {
const bool back_button_shown = IsBackButtonShown(); const bool back_button_shown = IsBackButtonShown();
const bool home_button_shown = IsHomeButtonShown(); const bool home_button_shown = IsHomeButtonShown();
......
...@@ -93,6 +93,7 @@ class ASH_EXPORT ShelfNavigationWidget : public TabletModeObserver, ...@@ -93,6 +93,7 @@ class ASH_EXPORT ShelfNavigationWidget : public TabletModeObserver,
// ShelfComponent: // ShelfComponent:
void CalculateTargetBounds() override; void CalculateTargetBounds() override;
gfx::Rect GetTargetBounds() const override;
void UpdateLayout(bool animate) override; void UpdateLayout(bool animate) override;
private: private:
......
...@@ -711,6 +711,12 @@ void ShelfWidget::UpdateLayout(bool animate) { ...@@ -711,6 +711,12 @@ void ShelfWidget::UpdateLayout(bool animate) {
// TODO(manucornet): Refactor layout update logic into this method. // TODO(manucornet): Refactor layout update logic into this method.
} }
gfx::Rect ShelfWidget::GetTargetBounds() const {
// TODO(manucornet): Store these locally and do not depend on the layout
// manager.
return shelf_->shelf_layout_manager()->GetShelfBoundsInScreen();
}
void ShelfWidget::OnSessionStateChanged(session_manager::SessionState state) { void ShelfWidget::OnSessionStateChanged(session_manager::SessionState state) {
// Do not show shelf widget: // Do not show shelf widget:
// * when views based shelf is disabled // * when views based shelf is disabled
......
...@@ -110,6 +110,7 @@ class ASH_EXPORT ShelfWidget : public AccessibilityObserver, ...@@ -110,6 +110,7 @@ class ASH_EXPORT ShelfWidget : public AccessibilityObserver,
// ShelfComponent: // ShelfComponent:
void CalculateTargetBounds() override; void CalculateTargetBounds() override;
gfx::Rect GetTargetBounds() const override;
void UpdateLayout(bool animate) override; void UpdateLayout(bool animate) override;
// ShelfLayoutManagerObserver: // ShelfLayoutManagerObserver:
......
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