Skip to content

Commit

Permalink
bento_button: More refactoring of the desk bar
Browse files Browse the repository at this point in the history
This does more refactoring of the desk bar. It migrates all rest code
from the legacy desk bar view to the desk bar view base. Further cleanup
and improvements are needed for the state transition as tracked in
b/277969403.

With this, the following functionalities should be fully or partially
working:
  - click the new desk button
  - click the library button
  - drag to reorder desk
  - click the desk preview to switch desk
  - click the combine/close all button to get rid of a desk
  - rename a desk

This also adds test coverage for the functionalities above.

Bug: b/278946648 && b/278945929
Test: All/DeskButtonTest.*
Change-Id: Ibc7e136f3ed814794810ef530965b748fe7675c9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4551458
Reviewed-by: Daniel Andersson <dandersson@chromium.org>
Commit-Queue: Yongshun Liu <yongshun@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1147528}
  • Loading branch information
Yongshun Liu authored and Chromium LUCI CQ committed May 22, 2023
1 parent ac63240 commit a9ae792
Show file tree
Hide file tree
Showing 12 changed files with 900 additions and 761 deletions.
6 changes: 6 additions & 0 deletions ash/wm/desks/desk_bar_controller.cc
Expand Up @@ -23,14 +23,20 @@ namespace ash {
DeskBarController::DeskBarController() {
Shell::Get()->overview_controller()->AddObserver(this);
Shell::Get()->tablet_mode_controller()->AddObserver(this);
DesksController::Get()->AddObserver(this);
}

DeskBarController::~DeskBarController() {
DestroyAllDeskBars();
DesksController::Get()->RemoveObserver(this);
Shell::Get()->tablet_mode_controller()->RemoveObserver(this);
Shell::Get()->overview_controller()->RemoveObserver(this);
}

void DeskBarController::OnDeskSwitchAnimationLaunching() {
DestroyAllDeskBars();
}

void DeskBarController::OnOverviewModeWillStart() {
DestroyAllDeskBars();
}
Expand Down
7 changes: 6 additions & 1 deletion ash/wm/desks/desk_bar_controller.h
Expand Up @@ -11,6 +11,7 @@
#include "ash/ash_export.h"
#include "ash/public/cpp/tablet_mode_observer.h"
#include "ash/wm/desks/desk_bar_view_base.h"
#include "ash/wm/desks/desks_controller.h"
#include "ash/wm/overview/overview_observer.h"
#include "base/observer_list.h"
#include "ui/gfx/geometry/rect.h"
Expand All @@ -26,7 +27,8 @@ namespace ash {
// and managing all desk bars. At this point, it supports only desk button desk
// bar, but eventually, it will support all bars. Please note this controller is
// owned by `DesksController`.
class ASH_EXPORT DeskBarController : public OverviewObserver,
class ASH_EXPORT DeskBarController : public DesksController::Observer,
public OverviewObserver,
public TabletModeObserver {
public:
DeskBarController();
Expand All @@ -36,6 +38,9 @@ class ASH_EXPORT DeskBarController : public OverviewObserver,

~DeskBarController() override;

// DesksController::Observer:
void OnDeskSwitchAnimationLaunching() override;

// OverviewObserver:
void OnOverviewModeWillStart() override;

Expand Down
32 changes: 0 additions & 32 deletions ash/wm/desks/desk_bar_view.cc
Expand Up @@ -4,9 +4,7 @@

#include "ash/wm/desks/desk_bar_view.h"

#include "ash/wm/desks/desk_mini_view.h"
#include "ui/aura/window.h"
#include "ui/views/widget/widget.h"

namespace ash {

Expand All @@ -16,38 +14,8 @@ namespace ash {
DeskBarView::DeskBarView(aura::Window* root)
: DeskBarViewBase(root, DeskBarViewBase::Type::kDeskButton) {}

DeskBarView::~DeskBarView() = default;

const char* DeskBarView::GetClassName() const {
return "DeskBarView";
}

void DeskBarView::UpdateNewMiniViews(bool initializing_bar_view,
bool expanding_bar_view) {
CHECK(initializing_bar_view);
CHECK(!expanding_bar_view);

// This should not be called when a desk is removed.
const auto& desks = DesksController::Get()->desks();
CHECK_LE(mini_views_.size(), desks.size());

UpdateDeskButtonsVisibility();

// New mini views can be added at any index, so we need to iterate through and
// insert new mini views in a position in `mini_views_` that corresponds to
// their index in the `DeskController`'s list of desks.
int mini_view_index = 0;
for (const auto& desk : desks) {
if (!FindMiniViewForDesk(desk.get())) {
DeskMiniView* mini_view = scroll_view_contents_->AddChildViewAt(
std::make_unique<DeskMiniView>(this, root_, desk.get()),
mini_view_index);
mini_views_.insert(mini_views_.begin() + mini_view_index, mini_view);
}
++mini_view_index;
}

Layout();
}

} // namespace ash
6 changes: 0 additions & 6 deletions ash/wm/desks/desk_bar_view.h
Expand Up @@ -22,14 +22,8 @@ class ASH_EXPORT DeskBarView : public DeskBarViewBase {
DeskBarView(const DeskBarView&) = delete;
DeskBarView& operator=(const DeskBarView&) = delete;

~DeskBarView() override;

// views::View:
const char* GetClassName() const override;

// TODO(b/277969403): Improve and simplify state transition for desk bar view.
void UpdateNewMiniViews(bool initializing_bar_view,
bool expanding_bar_view) override;
};

} // namespace ash
Expand Down

0 comments on commit a9ae792

Please sign in to comment.