Commit c140d46f authored by Ahmed Fakhry's avatar Ahmed Fakhry Committed by Commit Bot

Virtual Desks: Suppress DesksBar in tablet mode when there's only one desk

This effectively disables the feature in tablet mode if entered before
creating more than one desk.

BUG=976442
TEST=Manual, added a new test.

Change-Id: I38966dd59cf0eb76873958ca0fb4472c9bf5a53f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1666548
Commit-Queue: Ahmed Fakhry <afakhry@chromium.org>
Reviewed-by: default avatarSammie Quon <sammiequon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#670347}
parent 1dd50619
...@@ -1213,6 +1213,48 @@ TEST_F(DesksTest, TabletModeBackdrops) { ...@@ -1213,6 +1213,48 @@ TEST_F(DesksTest, TabletModeBackdrops) {
EXPECT_FALSE(desk_2_backdrop_controller->backdrop_window()); EXPECT_FALSE(desk_2_backdrop_controller->backdrop_window());
} }
TEST_F(DesksTest, NoDesksBarInTabletModeWithOneDesk) {
// Initially there's only one desk.
auto* controller = DesksController::Get();
ASSERT_EQ(1u, controller->desks().size());
auto window = CreateTestWindow(gfx::Rect(0, 0, 250, 100));
wm::ActivateWindow(window.get());
EXPECT_EQ(window.get(), wm::GetActiveWindow());
// Enter tablet mode and expect that the DesksBar widget won't be created.
// Avoid TabletModeController::OnGetSwitchStates() from disabling tablet mode.
base::RunLoop().RunUntilIdle();
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
auto* overview_controller = Shell::Get()->overview_controller();
overview_controller->StartOverview();
EXPECT_TRUE(overview_controller->InOverviewSession());
const auto* overview_grid =
GetOverviewGridForRoot(Shell::GetPrimaryRootWindow());
const auto* desks_bar_view = overview_grid->GetDesksBarViewForTesting();
ASSERT_FALSE(desks_bar_view);
// It's possible to drag the window without any crashes.
auto* overview_session = overview_controller->overview_session();
auto* overview_item =
overview_session->GetOverviewItemForWindow(window.get());
DragItemToPoint(overview_item, window->GetBoundsInScreen().CenterPoint(),
GetEventGenerator(), /*drop=*/true);
// Exit overview and add a new desk, then re-enter overview. Expect that now
// the desks bar is visible.
overview_controller->EndOverview();
EXPECT_FALSE(overview_controller->InOverviewSession());
controller->NewDesk();
overview_controller->StartOverview();
EXPECT_TRUE(overview_controller->InOverviewSession());
overview_grid = GetOverviewGridForRoot(Shell::GetPrimaryRootWindow());
desks_bar_view = overview_grid->GetDesksBarViewForTesting();
ASSERT_TRUE(desks_bar_view);
ASSERT_EQ(2u, desks_bar_view->mini_views().size());
}
TEST_F(DesksTest, TabletModeDesksCreationRemovalCycle) { TEST_F(DesksTest, TabletModeDesksCreationRemovalCycle) {
auto window = CreateTestWindow(gfx::Rect(0, 0, 250, 100)); auto window = CreateTestWindow(gfx::Rect(0, 0, 250, 100));
wm::ActivateWindow(window.get()); wm::ActivateWindow(window.get());
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "ash/public/cpp/ash_features.h" #include "ash/public/cpp/ash_features.h"
#include "ash/public/cpp/shell_window_ids.h" #include "ash/public/cpp/shell_window_ids.h"
#include "ash/public/cpp/tablet_mode.h"
#include "ash/wm/desks/desk.h" #include "ash/wm/desks/desk.h"
#include "ash/wm/desks/desks_controller.h" #include "ash/wm/desks/desks_controller.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
...@@ -122,6 +123,12 @@ aura::Window* GetDeskContainerForContext(aura::Window* context) { ...@@ -122,6 +123,12 @@ aura::Window* GetDeskContainerForContext(aura::Window* context) {
return nullptr; return nullptr;
} }
bool ShouldDesksBarBeCreated() {
return features::IsVirtualDesksEnabled() &&
(!TabletMode::Get()->IsEnabled() ||
DesksController::Get()->desks().size() > 1);
}
} // namespace desks_util } // namespace desks_util
} // namespace ash } // namespace ash
...@@ -42,6 +42,9 @@ ASH_EXPORT bool BelongsToActiveDesk(aura::Window* window); ...@@ -42,6 +42,9 @@ ASH_EXPORT bool BelongsToActiveDesk(aura::Window* window);
// container, otherwise return nullptr. // container, otherwise return nullptr.
ASH_EXPORT aura::Window* GetDeskContainerForContext(aura::Window* context); ASH_EXPORT aura::Window* GetDeskContainerForContext(aura::Window* context);
// Returns true if the DesksBar widget should be created in overview mode.
ASH_EXPORT bool ShouldDesksBarBeCreated();
} // namespace desks_util } // namespace desks_util
} // namespace ash } // namespace ash
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/wm/desks/desk_mini_view.h" #include "ash/wm/desks/desk_mini_view.h"
#include "ash/wm/desks/desks_bar_view.h" #include "ash/wm/desks/desks_bar_view.h"
#include "ash/wm/desks/desks_util.h"
#include "ash/wm/overview/cleanup_animation_observer.h" #include "ash/wm/overview/cleanup_animation_observer.h"
#include "ash/wm/overview/drop_target_view.h" #include "ash/wm/overview/drop_target_view.h"
#include "ash/wm/overview/overview_constants.h" #include "ash/wm/overview/overview_constants.h"
...@@ -1319,7 +1320,7 @@ aura::Window* OverviewGrid::GetTargetWindowOnLocation( ...@@ -1319,7 +1320,7 @@ aura::Window* OverviewGrid::GetTargetWindowOnLocation(
} }
bool OverviewGrid::IsDesksBarViewActive() const { bool OverviewGrid::IsDesksBarViewActive() const {
DCHECK(features::IsVirtualDesksEnabled()); DCHECK(desks_util::ShouldDesksBarBeCreated());
// The desk bar view is not active if there is only a single desk when // The desk bar view is not active if there is only a single desk when
// overview is started. Once there are more than one desk, it should stay // overview is started. Once there are more than one desk, it should stay
...@@ -1329,7 +1330,7 @@ bool OverviewGrid::IsDesksBarViewActive() const { ...@@ -1329,7 +1330,7 @@ bool OverviewGrid::IsDesksBarViewActive() const {
} }
gfx::Rect OverviewGrid::GetGridEffectiveBounds() const { gfx::Rect OverviewGrid::GetGridEffectiveBounds() const {
if (!features::IsVirtualDesksEnabled() || !IsDesksBarViewActive()) if (!desks_util::ShouldDesksBarBeCreated() || !IsDesksBarViewActive())
return bounds_; return bounds_;
gfx::Rect effective_bounds = bounds_; gfx::Rect effective_bounds = bounds_;
...@@ -1339,7 +1340,7 @@ gfx::Rect OverviewGrid::GetGridEffectiveBounds() const { ...@@ -1339,7 +1340,7 @@ gfx::Rect OverviewGrid::GetGridEffectiveBounds() const {
bool OverviewGrid::UpdateDesksBarDragDetails( bool OverviewGrid::UpdateDesksBarDragDetails(
const gfx::Point& screen_location) { const gfx::Point& screen_location) {
DCHECK(features::IsVirtualDesksEnabled()); DCHECK(desks_util::ShouldDesksBarBeCreated());
const bool dragged_item_over_bar = const bool dragged_item_over_bar =
desks_widget_->GetWindowBoundsInScreen().Contains(screen_location); desks_widget_->GetWindowBoundsInScreen().Contains(screen_location);
...@@ -1350,7 +1351,7 @@ bool OverviewGrid::UpdateDesksBarDragDetails( ...@@ -1350,7 +1351,7 @@ bool OverviewGrid::UpdateDesksBarDragDetails(
bool OverviewGrid::MaybeDropItemOnDeskMiniView( bool OverviewGrid::MaybeDropItemOnDeskMiniView(
const gfx::Point& screen_location, const gfx::Point& screen_location,
OverviewItem* drag_item) { OverviewItem* drag_item) {
DCHECK(features::IsVirtualDesksEnabled()); DCHECK(desks_util::ShouldDesksBarBeCreated());
// End the drag for the DesksBarView. // End the drag for the DesksBarView.
desks_bar_view_->SetDragDetails(screen_location, desks_bar_view_->SetDragDetails(screen_location,
...@@ -1386,7 +1387,7 @@ bool OverviewGrid::MaybeDropItemOnDeskMiniView( ...@@ -1386,7 +1387,7 @@ bool OverviewGrid::MaybeDropItemOnDeskMiniView(
} }
void OverviewGrid::MaybeInitDesksWidget() { void OverviewGrid::MaybeInitDesksWidget() {
if (!features::IsVirtualDesksEnabled() || desks_widget_) if (!desks_util::ShouldDesksBarBeCreated() || desks_widget_)
return; return;
desks_widget_ = DesksBarView::CreateDesksWidget( desks_widget_ = DesksBarView::CreateDesksWidget(
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "ash/scoped_animation_disabler.h" #include "ash/scoped_animation_disabler.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h" #include "ash/strings/grit/ash_strings.h"
#include "ash/wm/desks/desks_util.h"
#include "ash/wm/drag_window_controller.h" #include "ash/wm/drag_window_controller.h"
#include "ash/wm/overview/delayed_animation_observer_impl.h" #include "ash/wm/overview/delayed_animation_observer_impl.h"
#include "ash/wm/overview/overview_animation_type.h" #include "ash/wm/overview/overview_animation_type.h"
...@@ -764,7 +765,7 @@ void OverviewItem::UpdateMaskAndShadow() { ...@@ -764,7 +765,7 @@ void OverviewItem::UpdateMaskAndShadow() {
OverviewController* overview_controller = Shell::Get()->overview_controller(); OverviewController* overview_controller = Shell::Get()->overview_controller();
if (disable_mask_ || !overview_controller || if (disable_mask_ || !overview_controller ||
!overview_controller->InOverviewSession() || !overview_controller->InOverviewSession() ||
(!ash::features::ShouldUseShaderRoundedCorner() && (!features::ShouldUseShaderRoundedCorner() &&
overview_grid_->window_list().size() > 10) || overview_grid_->window_list().size() > 10) ||
overview_controller->IsInStartAnimation() || is_being_dragged_ || overview_controller->IsInStartAnimation() || is_being_dragged_ ||
overview_grid_->IsDropTargetWindow(GetWindow()) || overview_grid_->IsDropTargetWindow(GetWindow()) ||
...@@ -864,7 +865,7 @@ void OverviewItem::HandleDragEvent(const gfx::PointF& location_in_screen) { ...@@ -864,7 +865,7 @@ void OverviewItem::HandleDragEvent(const gfx::PointF& location_in_screen) {
} }
void OverviewItem::HandleLongPressEvent(const gfx::PointF& location_in_screen) { void OverviewItem::HandleLongPressEvent(const gfx::PointF& location_in_screen) {
if (ShouldAllowSplitView() || features::IsVirtualDesksEnabled()) if (ShouldAllowSplitView() || desks_util::ShouldDesksBarBeCreated())
overview_session_->StartNormalDragMode(location_in_screen); overview_session_->StartNormalDragMode(location_in_screen);
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "ash/screen_util.h" #include "ash/screen_util.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/wm/desks/desk_preview_view.h" #include "ash/wm/desks/desk_preview_view.h"
#include "ash/wm/desks/desks_util.h"
#include "ash/wm/overview/overview_constants.h" #include "ash/wm/overview/overview_constants.h"
#include "ash/wm/overview/overview_controller.h" #include "ash/wm/overview/overview_controller.h"
#include "ash/wm/overview/overview_grid.h" #include "ash/wm/overview/overview_grid.h"
...@@ -95,7 +96,7 @@ OverviewWindowDragController::OverviewWindowDragController( ...@@ -95,7 +96,7 @@ OverviewWindowDragController::OverviewWindowDragController(
item_(item), item_(item),
on_desks_bar_item_size_(GetItemSizeWhenOnDesksBar(item)), on_desks_bar_item_size_(GetItemSizeWhenOnDesksBar(item)),
should_allow_split_view_(ShouldAllowSplitView()), should_allow_split_view_(ShouldAllowSplitView()),
virtual_desks_enabled_(features::IsVirtualDesksEnabled()) {} virtual_desks_bar_enabled_(desks_util::ShouldDesksBarBeCreated()) {}
OverviewWindowDragController::~OverviewWindowDragController() = default; OverviewWindowDragController::~OverviewWindowDragController() = default;
...@@ -132,7 +133,7 @@ void OverviewWindowDragController::Drag(const gfx::PointF& location_in_screen) { ...@@ -132,7 +133,7 @@ void OverviewWindowDragController::Drag(const gfx::PointF& location_in_screen) {
overview_session_->GetGridWithRootWindow(item_->root_window()) overview_session_->GetGridWithRootWindow(item_->root_window())
->StartNudge(item_); ->StartNudge(item_);
did_move_ = true; did_move_ = true;
} else if (should_allow_split_view_ || virtual_desks_enabled_) { } else if (should_allow_split_view_ || virtual_desks_bar_enabled_) {
StartNormalDragMode(location_in_screen); StartNormalDragMode(location_in_screen);
} }
} }
...@@ -183,7 +184,7 @@ OverviewWindowDragController::CompleteDrag( ...@@ -183,7 +184,7 @@ OverviewWindowDragController::CompleteDrag(
void OverviewWindowDragController::StartNormalDragMode( void OverviewWindowDragController::StartNormalDragMode(
const gfx::PointF& location_in_screen) { const gfx::PointF& location_in_screen) {
DCHECK(should_allow_split_view_ || virtual_desks_enabled_); DCHECK(should_allow_split_view_ || virtual_desks_bar_enabled_);
did_move_ = true; did_move_ = true;
current_drag_behavior_ = DragBehavior::kNormalDrag; current_drag_behavior_ = DragBehavior::kNormalDrag;
...@@ -334,7 +335,7 @@ gfx::RectF OverviewWindowDragController::ContinueNormalDrag( ...@@ -334,7 +335,7 @@ gfx::RectF OverviewWindowDragController::ContinueNormalDrag(
gfx::PointF centerpoint = gfx::PointF centerpoint =
location_in_screen - (initial_event_location_ - initial_centerpoint_); location_in_screen - (initial_event_location_ - initial_centerpoint_);
if (virtual_desks_enabled_) { if (virtual_desks_bar_enabled_) {
if (item_->overview_grid()->UpdateDesksBarDragDetails( if (item_->overview_grid()->UpdateDesksBarDragDetails(
gfx::ToRoundedPoint(location_in_screen))) { gfx::ToRoundedPoint(location_in_screen))) {
// The drag location intersects the bounds of the DesksBarView, in this // The drag location intersects the bounds of the DesksBarView, in this
...@@ -391,7 +392,7 @@ OverviewWindowDragController::CompleteNormalDrag( ...@@ -391,7 +392,7 @@ OverviewWindowDragController::CompleteNormalDrag(
} }
// Attempt to move a window to a different desk. // Attempt to move a window to a different desk.
if (virtual_desks_enabled_) { if (virtual_desks_bar_enabled_) {
item_->SetOpacity(original_opacity_); item_->SetOpacity(original_opacity_);
if (item_->overview_grid()->MaybeDropItemOnDeskMiniView( if (item_->overview_grid()->MaybeDropItemOnDeskMiniView(
......
...@@ -142,8 +142,8 @@ class ASH_EXPORT OverviewWindowDragController { ...@@ -142,8 +142,8 @@ class ASH_EXPORT OverviewWindowDragController {
// True if SplitView is enabled. // True if SplitView is enabled.
const bool should_allow_split_view_; const bool should_allow_split_view_;
// True if the Virtual Desks feature is enabled. // True if the Virtual Desks bar is created and dragging to desks is enabled.
const bool virtual_desks_enabled_; const bool virtual_desks_bar_enabled_;
// False if the initial drag location was not a snap region, or if it was in // False if the initial drag location was not a snap region, or if it was in
// a snap region but the drag has since moved out. // a snap region but the drag has since moved out.
......
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