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

CrOS Shelf: Start moving some hotseat logic into the hotseat widget

The general idea here is to encapsulate more of the hotseat's behavior
into its own class rather than have it all over the shelf layout
manager. Eventually, I hope to get rid of the huge
"CalculateHotseatState" method by setting the hotseat state to the
appropriate values from the relevant places.

Change-Id: I03bf50bc9f6fb68f7f22f1b6ec966f08f48220da
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1893997
Commit-Queue: Manu Cornet <manucornet@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711796}
parent a72a5f6b
......@@ -186,6 +186,14 @@ void HotseatWidget::Initialize(aura::Window* container, Shelf* shelf) {
delegate_view_->Init(scrollable_shelf_view(), GetLayer());
}
void HotseatWidget::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
}
void HotseatWidget::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}
void HotseatWidget::OnMouseEvent(ui::MouseEvent* event) {
if (event->type() == ui::ET_MOUSE_PRESSED)
keyboard::KeyboardUIController::Get()->HideKeyboardImplicitlyByUser();
......@@ -231,6 +239,15 @@ const ShelfView* HotseatWidget::GetShelfView() const {
const_cast<HotseatWidget*>(this)->GetShelfView());
}
void HotseatWidget::SetState(HotseatState state) {
if (state_ == state)
return;
state_ = state;
for (auto& observer : observers_)
observer.OnHotseatStateChanged();
}
bool HotseatWidget::IsShowingOverflowBubble() const {
return GetShelfView()->IsShowingOverflowBubble();
}
......
......@@ -7,6 +7,9 @@
#include "ash/ash_export.h"
#include "ash/public/cpp/shelf_config.h"
#include "ash/public/cpp/shelf_types.h"
#include "base/observer_list.h"
#include "base/observer_list_types.h"
#include "ui/views/widget/widget.h"
namespace ash {
......@@ -19,12 +22,19 @@ class ShelfView;
class ASH_EXPORT HotseatWidget : public views::Widget,
public ShelfConfig::Observer {
public:
class Observer : public base::CheckedObserver {
public:
virtual void OnHotseatStateChanged() = 0;
};
HotseatWidget();
~HotseatWidget() override;
// Initializes the widget, sets its contents view and basic properties.
void Initialize(aura::Window* container, Shelf* shelf);
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
// views::Widget:
void OnMouseEvent(ui::MouseEvent* event) override;
void OnGestureEvent(ui::GestureEvent* event) override;
......@@ -58,6 +68,9 @@ class ASH_EXPORT HotseatWidget : public views::Widget,
ShelfView* GetShelfView();
const ShelfView* GetShelfView() const;
void SetState(HotseatState state);
HotseatState state() const { return state_; }
ScrollableShelfView* scrollable_shelf_view() {
return scrollable_shelf_view_;
}
......@@ -82,6 +95,10 @@ class ASH_EXPORT HotseatWidget : public views::Widget,
// of the hotseat.
DelegateView* delegate_view_ = nullptr;
HotseatState state_ = HotseatState::kShown;
base::ObserverList<Observer> observers_;
// Whether the widget is currently extended because the user has manually
// dragged it. This will be reset with any visible shelf configuration change.
bool is_manually_extended_ = false;
......
This diff is collapsed.
......@@ -14,6 +14,7 @@
#include "ash/public/cpp/wallpaper_controller_observer.h"
#include "ash/session/session_observer.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shell_observer.h"
#include "ash/system/locale/locale_update_controller_impl.h"
#include "ash/wm/desks/desks_controller.h"
......@@ -64,6 +65,7 @@ class ASH_EXPORT ShelfLayoutManager : public AppListControllerObserver,
public ShellObserver,
public SplitViewObserver,
public OverviewObserver,
public HotseatWidget::Observer,
public ::wm::ActivationChangeObserver,
public LockStateObserver,
public WmDefaultLayoutManager,
......@@ -119,7 +121,7 @@ class ASH_EXPORT ShelfLayoutManager : public AppListControllerObserver,
void ProcessGestureEventOfAutoHideShelf(ui::GestureEvent* event,
aura::Window* target);
// Handles events that are detected while the hotseat is kExtended in in-app
// Handles events that are detected while the hotseat is extended in in-app
// shelf.
void ProcessGestureEventOfInAppHotseat(ui::GestureEvent* event,
aura::Window* target);
......@@ -187,6 +189,9 @@ class ASH_EXPORT ShelfLayoutManager : public AppListControllerObserver,
void OnOverviewModeEndingAnimationComplete(bool canceled) override;
void OnOverviewModeEnded() override;
// HotseatWidget::Observer:
void OnHotseatStateChanged() override;
// AppListControllerObserver:
void OnAppListVisibilityWillChange(bool shown, int64_t display_id) override;
void OnAppListVisibilityChanged(bool shown, int64_t display_id) override;
......@@ -232,7 +237,9 @@ class ASH_EXPORT ShelfLayoutManager : public AppListControllerObserver,
bool updating_bounds() const { return updating_bounds_; }
ShelfAutoHideState auto_hide_state() const { return state_.auto_hide_state; }
HotseatState hotseat_state() const { return state_.hotseat_state; }
HotseatState hotseat_state() const {
return shelf_widget_->hotseat_widget()->state();
}
DragWindowFromShelfController* window_drag_controller_for_testing() {
return window_drag_controller_.get();
......
......@@ -30,9 +30,6 @@ class ASH_EXPORT ShelfLayoutManagerObserver {
virtual void OnBackgroundUpdated(ShelfBackgroundType background_type,
AnimationChangeType change_type) {}
// Called when the hotseat state changes.
virtual void OnHotseatStateChanged(HotseatState state) {}
// Called when ShelfLayoutManager has updated Shelf insets in work area
// insets.
virtual void OnWorkAreaInsetsChanged() {}
......
......@@ -3219,19 +3219,16 @@ class HotseatShelfLayoutManagerTest
};
// Records HotseatState transitions.
class HotseatStateWatcher : public ShelfLayoutManagerObserver {
class HotseatStateWatcher : public HotseatWidget::Observer {
public:
HotseatStateWatcher(ShelfLayoutManager* shelf_layout_manager)
: shelf_layout_manager_(shelf_layout_manager) {
shelf_layout_manager_->AddObserver(this);
}
~HotseatStateWatcher() override {
shelf_layout_manager_->RemoveObserver(this);
explicit HotseatStateWatcher(HotseatWidget* widget) : widget_(widget) {
widget_->AddObserver(this);
}
~HotseatStateWatcher() override { widget_->RemoveObserver(this); }
void OnHotseatStateChanged(HotseatState state) override {
void OnHotseatStateChanged() override {
run_loop_.QuitWhenIdle();
state_changes_.push_back(state);
state_changes_.push_back(widget_->state());
}
void CheckEqual(std::vector<HotseatState> state_changes) {
......@@ -3241,7 +3238,7 @@ class HotseatStateWatcher : public ShelfLayoutManagerObserver {
void WaitUntilStateChanged() { run_loop_.Run(); }
private:
ShelfLayoutManager* shelf_layout_manager_;
HotseatWidget* const widget_;
std::vector<HotseatState> state_changes_;
base::RunLoop run_loop_;
DISALLOW_COPY_AND_ASSIGN(HotseatStateWatcher);
......@@ -3539,8 +3536,8 @@ TEST_F(HotseatShelfLayoutManagerTest, ReleasingSlowDragBelowThreshold) {
EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
}
// Tests that releasing the hotseat gesture above the threshold results in a
// kExtended hotseat.
// Tests that releasing the hotseat gesture above the threshold results in an
// extended hotseat.
TEST_P(HotseatShelfLayoutManagerTest, ReleasingSlowDragAboveThreshold) {
GetPrimaryShelf()->SetAutoHideBehavior(GetParam());
TabletModeControllerTestApi().EnterTabletMode();
......@@ -3577,7 +3574,8 @@ TEST_P(HotseatShelfLayoutManagerTest, ShowingOverviewFromShownAnimatesOnce) {
wm::ActivateWindow(window.get());
std::unique_ptr<HotseatStateWatcher> state_watcher_ =
std::make_unique<HotseatStateWatcher>(GetShelfLayoutManager());
std::make_unique<HotseatStateWatcher>(
GetPrimaryShelf()->shelf_widget()->hotseat_widget());
SwipeUpOnShelf();
ASSERT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
......@@ -3781,7 +3779,8 @@ TEST_P(HotseatShelfLayoutManagerTest, HomeToOverviewChangesStateOnce) {
.CenterPoint();
{
HotseatStateWatcher watcher(GetShelfLayoutManager());
HotseatStateWatcher watcher(
GetPrimaryShelf()->shelf_widget()->hotseat_widget());
OverviewAnimationWaiter waiter;
GetEventGenerator()->GestureTapAt(overview_button_center);
waiter.Wait();
......@@ -3800,7 +3799,8 @@ TEST_P(HotseatShelfLayoutManagerTest, HomeToOverviewChangesStateOnce) {
GetAppListTestHelper()->CheckVisibility(true);
// Activate overview and expect the hotseat only changes state to extended.
{
HotseatStateWatcher watcher(GetShelfLayoutManager());
HotseatStateWatcher watcher(
GetPrimaryShelf()->shelf_widget()->hotseat_widget());
OverviewAnimationWaiter waiter;
GetEventGenerator()->GestureTapAt(overview_button_center);
waiter.Wait();
......@@ -3815,7 +3815,8 @@ TEST_P(HotseatShelfLayoutManagerTest, HomeToInAppChangesStateOnce) {
TabletModeControllerTestApi().EnterTabletMode();
// Go to in-app, the hotseat should hide.
HotseatStateWatcher watcher(GetShelfLayoutManager());
HotseatStateWatcher watcher(
GetPrimaryShelf()->shelf_widget()->hotseat_widget());
std::unique_ptr<aura::Window> window =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
wm::ActivateWindow(window.get());
......@@ -3839,7 +3840,8 @@ TEST_P(HotseatShelfLayoutManagerTest, InAppToHomeChangesStateOnce) {
// Press the HomeLauncher button, the hotseat should transition directly to
// kShown.
{
HotseatStateWatcher watcher(GetShelfLayoutManager());
HotseatStateWatcher watcher(
GetPrimaryShelf()->shelf_widget()->hotseat_widget());
views::View* home_button =
GetPrimaryShelf()->shelf_widget()->GetHomeButton();
GetEventGenerator()->GestureTapAt(
......@@ -3857,7 +3859,8 @@ TEST_P(HotseatShelfLayoutManagerTest, InAppToHomeChangesStateOnce) {
{
ui::ScopedAnimationDurationScaleMode regular_animations(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
HotseatStateWatcher watcher(GetShelfLayoutManager());
HotseatStateWatcher watcher(
GetPrimaryShelf()->shelf_widget()->hotseat_widget());
FlingUpOnShelf();
watcher.WaitUntilStateChanged();
watcher.CheckEqual({HotseatState::kShown});
......@@ -3874,7 +3877,8 @@ TEST_P(HotseatShelfLayoutManagerTest, InAppToHomeChangesStateOnce) {
// Press the HomeLauncher button, the hotseat should transition directly to
// kShown.
{
HotseatStateWatcher watcher(GetShelfLayoutManager());
HotseatStateWatcher watcher(
GetPrimaryShelf()->shelf_widget()->hotseat_widget());
views::View* home_button =
GetPrimaryShelf()->shelf_widget()->GetHomeButton();
GetEventGenerator()->GestureTapAt(
......@@ -3897,7 +3901,8 @@ TEST_F(HotseatShelfLayoutManagerTest,
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
wm::ActivateWindow(window.get());
{
HotseatStateWatcher watcher(GetShelfLayoutManager());
HotseatStateWatcher watcher(
GetPrimaryShelf()->shelf_widget()->hotseat_widget());
// Enter overview by using the controller.
OverviewAnimationWaiter waiter;
Shell::Get()->overview_controller()->StartOverview();
......@@ -3917,7 +3922,8 @@ TEST_F(HotseatShelfLayoutManagerTest,
GetShelfLayoutManager()->auto_hide_state());
SwipeUpOnShelf();
{
HotseatStateWatcher watcher(GetShelfLayoutManager());
HotseatStateWatcher watcher(
GetPrimaryShelf()->shelf_widget()->hotseat_widget());
// Enter overview by using the controller.
OverviewAnimationWaiter waiter;
Shell::Get()->overview_controller()->StartOverview();
......
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