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

Slight refactor of the shelf view positioning code

* Make it a little easier to understand
* Remove some panel-related code (a lot more of that in a separate CL)

No change in behavior.

Bug: 805612
Bug: 788033
Change-Id: I70225cc90cba940a8e2cb148be4aa887ebaa01ce
Reviewed-on: https://chromium-review.googlesource.com/1150776
Commit-Queue: Manu Cornet <manucornet@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579869}
parent 67d437dd
This diff is collapsed.
......@@ -74,7 +74,7 @@ enum ShelfAlignmentUmaEnumValue {
// ^ ^
// | |
// first_visible_index = 0 last_visible_index = 13
// (back button = 0 is hidden) last_hidden_index = 13
// (back button = 0 is hidden)
//
// Where:
// 0 = back button (only shown in tablet mode)
......@@ -83,7 +83,7 @@ enum ShelfAlignmentUmaEnumValue {
// If screen space is more constrained, some icons are placed in an overflow
// menu (which holds its own instance of ShelfView):
//
// first_visible_index = 10 last_hidden_index = 13
// first_visible_index = 10
// (for the overflow) last_visible_index = 13 (for overflow)
// | |
// v v
......@@ -285,11 +285,7 @@ class ASH_EXPORT ShelfView : public views::View,
// Returns the index of the last view whose max primary axis coordinate is
// less than |max_value|. Returns -1 if nothing fits, or there are no views.
int DetermineLastVisibleIndex(int max_value) const;
// Returns the index of the first panel whose min primary axis coordinate is
// at least |min_value|. Returns the index past the last panel if none fit.
int DetermineFirstVisiblePanelIndex(int min_value) const;
int IndexOfLastItemThatFitsSize(int max_value) const;
// Animates the bounds of each view to its ideal bounds.
void AnimateToIdealBounds();
......@@ -515,10 +511,6 @@ class ASH_EXPORT ShelfView : public views::View,
// True when an item being inserted or removed in the model cancels a drag.
bool cancelling_drag_model_changed_ = false;
// Index of the last hidden launcher item. If there are no hidden items this
// will be equal to last_visible_index_ + 1.
mutable int last_hidden_index_ = 0;
// The timestamp of the event which closed the last menu - or 0.
base::TimeTicks closing_event_time_;
......
......@@ -288,7 +288,7 @@ class ShelfViewTest : public AshTestBase {
ShelfID AddItem(ShelfItemType type, bool wait_for_animations) {
ShelfItem item;
item.type = type;
if (type == TYPE_APP || type == TYPE_APP_PANEL)
if (type == TYPE_APP)
item.status = STATUS_RUNNING;
item.id = ShelfID(base::IntToString(id_++));
......@@ -301,7 +301,6 @@ class ShelfViewTest : public AshTestBase {
return item.id;
}
ShelfID AddAppShortcut() { return AddItem(TYPE_PINNED_APP, true); }
ShelfID AddPanel() { return AddItem(TYPE_APP_PANEL, true); }
ShelfID AddAppNoWait() { return AddItem(TYPE_APP, false); }
ShelfID AddApp() { return AddItem(TYPE_APP, true); }
......@@ -715,22 +714,16 @@ TEST_F(ShelfViewTest, EnforceDragType) {
EXPECT_FALSE(test_api_->SameDragType(TYPE_APP, TYPE_PINNED_APP));
EXPECT_FALSE(test_api_->SameDragType(TYPE_APP, TYPE_BROWSER_SHORTCUT));
EXPECT_FALSE(test_api_->SameDragType(TYPE_APP, TYPE_APP_LIST));
EXPECT_FALSE(test_api_->SameDragType(TYPE_APP, TYPE_APP_PANEL));
EXPECT_TRUE(test_api_->SameDragType(TYPE_PINNED_APP, TYPE_PINNED_APP));
EXPECT_TRUE(test_api_->SameDragType(TYPE_PINNED_APP, TYPE_BROWSER_SHORTCUT));
EXPECT_FALSE(test_api_->SameDragType(TYPE_PINNED_APP, TYPE_APP_LIST));
EXPECT_FALSE(test_api_->SameDragType(TYPE_PINNED_APP, TYPE_APP_PANEL));
EXPECT_TRUE(
test_api_->SameDragType(TYPE_BROWSER_SHORTCUT, TYPE_BROWSER_SHORTCUT));
EXPECT_FALSE(test_api_->SameDragType(TYPE_BROWSER_SHORTCUT, TYPE_APP_LIST));
EXPECT_FALSE(test_api_->SameDragType(TYPE_BROWSER_SHORTCUT, TYPE_APP_PANEL));
EXPECT_TRUE(test_api_->SameDragType(TYPE_APP_LIST, TYPE_APP_LIST));
EXPECT_FALSE(test_api_->SameDragType(TYPE_APP_LIST, TYPE_APP_PANEL));
EXPECT_TRUE(test_api_->SameDragType(TYPE_APP_PANEL, TYPE_APP_PANEL));
}
// Adds platform app button until overflow and verifies that the last added
......@@ -780,74 +773,6 @@ TEST_F(ShelfViewTest, AddAppShortcutWithBrowserButtonUntilOverflow) {
EXPECT_FALSE(GetButtonByID(browser_button_id)->visible());
}
TEST_F(ShelfViewTest, AddPanelHidesPlatformAppButton) {
// All buttons should be visible.
ASSERT_EQ(test_api_->GetButtonCount(), test_api_->GetLastVisibleIndex() + 1);
// Add platform app button until overflow, remember last visible platform app
// button.
int items_added = 0;
ShelfID first_added = AddApp();
EXPECT_TRUE(GetButtonByID(first_added)->visible());
while (true) {
ShelfID added = AddApp();
if (test_api_->IsOverflowButtonVisible()) {
EXPECT_FALSE(GetButtonByID(added)->visible());
RemoveByID(added);
break;
}
++items_added;
ASSERT_LT(items_added, 10000);
}
ShelfID panel = AddPanel();
EXPECT_TRUE(test_api_->IsOverflowButtonVisible());
RemoveByID(panel);
EXPECT_FALSE(test_api_->IsOverflowButtonVisible());
}
// When there are more panels then platform app buttons we should hide panels
// rather than platform apps.
TEST_F(ShelfViewTest, PlatformAppHidesExcessPanels) {
// All buttons should be visible.
ASSERT_EQ(test_api_->GetButtonCount(), test_api_->GetLastVisibleIndex() + 1);
// Add platform app button.
ShelfID platform_app = AddApp();
ShelfID first_panel = AddPanel();
EXPECT_TRUE(GetButtonByID(platform_app)->visible());
EXPECT_TRUE(GetButtonByID(first_panel)->visible());
// Add panels until there is an overflow.
ShelfID last_panel = first_panel;
int items_added = 0;
while (!test_api_->IsOverflowButtonVisible()) {
last_panel = AddPanel();
++items_added;
ASSERT_LT(items_added, 10000);
}
// The first panel should now be hidden by the new platform apps needing
// space.
EXPECT_FALSE(GetButtonByID(first_panel)->visible());
EXPECT_TRUE(GetButtonByID(last_panel)->visible());
EXPECT_TRUE(GetButtonByID(platform_app)->visible());
// Adding platform apps should eventually begin to hide platform apps. We will
// add platform apps until either the last panel or platform app is hidden.
items_added = 0;
while (GetButtonByID(platform_app)->visible() &&
GetButtonByID(last_panel)->visible()) {
platform_app = AddApp();
++items_added;
ASSERT_LT(items_added, 10000);
}
EXPECT_TRUE(GetButtonByID(last_panel)->visible());
EXPECT_FALSE(GetButtonByID(platform_app)->visible());
}
// Making sure that no buttons on the shelf will ever overlap after adding many
// of them.
TEST_F(ShelfViewTest, AssertNoButtonsOverlap) {
......@@ -860,8 +785,7 @@ TEST_F(ShelfViewTest, AssertNoButtonsOverlap) {
ASSERT_LT(button_ids.size(), 10000U);
ASSERT_GT(button_ids.size(), 2U);
// Remove 2 icons to make more room for panel icons, the overflow button
// should go away.
// Remove 2 icons to make more room, the overflow button should go away.
for (int i = 0; i < 2; ++i) {
ShelfID id = button_ids.back();
RemoveByID(id);
......@@ -870,9 +794,9 @@ TEST_F(ShelfViewTest, AssertNoButtonsOverlap) {
EXPECT_FALSE(test_api_->IsOverflowButtonVisible());
EXPECT_TRUE(GetButtonByID(button_ids.back())->visible());
// Add 20 panel icons, and expect to have overflow.
// Add 20 app icons, and expect to have overflow.
for (int i = 0; i < 20; ++i) {
ShelfID id = AddPanel();
ShelfID id = AddAppShortcut();
button_ids.push_back(id);
}
ASSERT_LT(button_ids.size(), 10000U);
......@@ -1064,15 +988,6 @@ TEST_F(ShelfViewTest, ModelChangesWhileDragging) {
std::make_pair(new_id, GetButtonByID(new_id)));
ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
shelf_view_->PointerReleasedOnButton(dragged_button, ShelfView::MOUSE, false);
// Adding a shelf item at the end (i.e. a panel) canels drag and respects
// the order.
dragged_button = SimulateDrag(ShelfView::MOUSE, 2, 4, false);
new_id = AddPanel();
id_map.insert(id_map.begin() + 8,
std::make_pair(new_id, GetButtonByID(new_id)));
ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
shelf_view_->PointerReleasedOnButton(dragged_button, ShelfView::MOUSE, false);
}
// Check that 2nd drag from the other pointer would be ignored.
......
......@@ -783,107 +783,6 @@ TEST_F(PanelLayoutManagerTest, AlignmentRight) {
IsCalloutAboveLauncherIcon(w.get());
}
// Tests that panels will hide and restore their state with the shelf visibility
// state. This ensures that entering full-screen mode will hide your panels
// until you leave it.
TEST_F(PanelLayoutManagerTest, PanelsHideAndRestoreWithShelf) {
gfx::Rect bounds(0, 0, 201, 201);
std::unique_ptr<aura::Window> w1(CreatePanelWindow(bounds));
std::unique_ptr<aura::Window> w2(CreatePanelWindow(bounds));
std::unique_ptr<aura::Window> w3;
// Minimize w2.
wm::GetWindowState(w2.get())->Minimize();
RunAllPendingInMessageLoop();
EXPECT_TRUE(w1->IsVisible());
EXPECT_FALSE(w2->IsVisible());
SetShelfVisibilityState(Shell::GetPrimaryRootWindow(), SHELF_HIDDEN);
RunAllPendingInMessageLoop();
// w3 is created while in full-screen mode, should only become visible when
// we exit fullscreen mode.
w3.reset(CreatePanelWindow(bounds));
EXPECT_FALSE(w1->IsVisible());
EXPECT_FALSE(w2->IsVisible());
EXPECT_FALSE(w3->IsVisible());
// While in full-screen mode, the panel windows should still be in the
// switchable window list - http://crbug.com/313919.
aura::Window::Windows switchable_window_list =
Shell::Get()->mru_window_tracker()->BuildMruWindowList();
EXPECT_EQ(3u, switchable_window_list.size());
EXPECT_TRUE(base::ContainsValue(switchable_window_list, w1.get()));
EXPECT_TRUE(base::ContainsValue(switchable_window_list, w2.get()));
EXPECT_TRUE(base::ContainsValue(switchable_window_list, w3.get()));
SetShelfVisibilityState(Shell::GetPrimaryRootWindow(), SHELF_VISIBLE);
RunAllPendingInMessageLoop();
// Windows should be restored to their prior state.
EXPECT_TRUE(w1->IsVisible());
EXPECT_FALSE(w2->IsVisible());
EXPECT_TRUE(w3->IsVisible());
}
// Verifies that touches along the attached edge of a panel do not
// target the panel itself.
TEST_F(PanelLayoutManagerTest, TouchHitTestPanel) {
aura::test::TestWindowDelegate delegate;
std::unique_ptr<aura::Window> w(
CreatePanelWindowWithDelegate(&delegate, gfx::Rect(0, 0, 200, 200)));
aura::Window* root = w->GetRootWindow();
ui::EventTargeter* targeter =
root->GetHost()->dispatcher()->GetDefaultEventTargeter();
// Note that the constants used in the touch locations below are
// arbitrarily-selected small numbers which will ensure the point is
// within the default extended region surrounding the panel. This value
// is calculated as
// kResizeOutsideBoundsSize * kResizeOutsideBoundsScaleForTouch
// in src/ash/root_window_controller.cc.
// Hit test outside the right edge with a bottom-aligned shelf.
SetAlignment(Shell::GetPrimaryRootWindow(), SHELF_ALIGNMENT_BOTTOM);
gfx::Rect bounds(w->bounds());
ui::TouchEvent touch(
ui::ET_TOUCH_PRESSED, gfx::Point(bounds.right() + 3, bounds.y() + 2),
ui::EventTimeForNow(),
ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0));
ui::EventTarget* target = targeter->FindTargetForEvent(root, &touch);
EXPECT_EQ(w.get(), target);
// Hit test outside the bottom edge with a bottom-aligned shelf.
touch.set_location(gfx::Point(bounds.x() + 6, bounds.bottom() + 5));
target = targeter->FindTargetForEvent(root, &touch);
EXPECT_NE(w.get(), target);
// Hit test outside the bottom edge with a right-aligned shelf.
SetAlignment(Shell::GetPrimaryRootWindow(), SHELF_ALIGNMENT_RIGHT);
bounds = w->bounds();
touch.set_location(gfx::Point(bounds.x() + 6, bounds.bottom() + 5));
target = targeter->FindTargetForEvent(root, &touch);
EXPECT_EQ(w.get(), target);
// Hit test outside the right edge with a right-aligned shelf.
touch.set_location(gfx::Point(bounds.right() + 3, bounds.y() + 2));
target = targeter->FindTargetForEvent(root, &touch);
EXPECT_NE(w.get(), target);
// Hit test outside the top edge with a left-aligned shelf.
SetAlignment(Shell::GetPrimaryRootWindow(), SHELF_ALIGNMENT_LEFT);
bounds = w->bounds();
touch.set_location(gfx::Point(bounds.x() + 4, bounds.y() - 6));
target = targeter->FindTargetForEvent(root, &touch);
EXPECT_EQ(w.get(), target);
// Hit test outside the left edge with a left-aligned shelf.
touch.set_location(gfx::Point(bounds.x() - 1, bounds.y() + 5));
target = targeter->FindTargetForEvent(root, &touch);
EXPECT_NE(w.get(), target);
}
INSTANTIATE_TEST_CASE_P(LtrRtl,
PanelLayoutManagerTextDirectionTest,
testing::Bool());
......
......@@ -273,98 +273,6 @@ TEST_F(PanelWindowResizerTest, PanelDetachReattachMultipleDisplays) {
DetachReattachTest(window.get(), 0, -1);
}
TEST_F(PanelWindowResizerTest, DetachThenDragAcrossDisplays) {
UpdateDisplay("600x400,600x400");
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
std::unique_ptr<aura::Window> window(CreatePanelWindow(gfx::Point()));
gfx::Rect initial_bounds = window->GetBoundsInScreen();
EXPECT_EQ(root_windows[0], window->GetRootWindow());
DragStart(window.get());
DragMove(0, -100);
DragEnd();
EXPECT_EQ(root_windows[0], window->GetRootWindow());
EXPECT_EQ(initial_bounds.x(), window->GetBoundsInScreen().x());
EXPECT_EQ(initial_bounds.y() - 100, window->GetBoundsInScreen().y());
EXPECT_FALSE(window->GetProperty(kPanelAttachedKey));
EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
DragStart(window.get());
DragMove(500, 0);
DragEnd();
EXPECT_EQ(root_windows[1], window->GetRootWindow());
EXPECT_EQ(initial_bounds.x() + 500, window->GetBoundsInScreen().x());
EXPECT_EQ(initial_bounds.y() - 100, window->GetBoundsInScreen().y());
EXPECT_FALSE(window->GetProperty(kPanelAttachedKey));
EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
}
TEST_F(PanelWindowResizerTest, DetachAcrossDisplays) {
UpdateDisplay("600x400,600x400");
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
std::unique_ptr<aura::Window> window(CreatePanelWindow(gfx::Point()));
gfx::Rect initial_bounds = window->GetBoundsInScreen();
EXPECT_EQ(root_windows[0], window->GetRootWindow());
DragStart(window.get());
DragMove(500, -100);
DragEnd();
EXPECT_EQ(root_windows[1], window->GetRootWindow());
EXPECT_EQ(initial_bounds.x() + 500, window->GetBoundsInScreen().x());
EXPECT_EQ(initial_bounds.y() - 100, window->GetBoundsInScreen().y());
EXPECT_FALSE(window->GetProperty(kPanelAttachedKey));
EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
}
TEST_F(PanelWindowResizerTest, DetachThenAttachToSecondDisplay) {
UpdateDisplay("600x400,600x600");
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
std::unique_ptr<aura::Window> window(CreatePanelWindow(gfx::Point()));
gfx::Rect initial_bounds = window->GetBoundsInScreen();
EXPECT_EQ(root_windows[0], window->GetRootWindow());
// Detach the window.
DragStart(window.get());
DragMove(0, -100);
DragEnd();
EXPECT_EQ(root_windows[0], window->GetRootWindow());
EXPECT_FALSE(window->GetProperty(kPanelAttachedKey));
// Drag the window just above the other display's launcher.
DragStart(window.get());
DragMove(500, 295);
EXPECT_EQ(initial_bounds.x() + 500, window->GetBoundsInScreen().x());
// Should stick to other launcher.
EXPECT_EQ(initial_bounds.y() + 200, window->GetBoundsInScreen().y());
DragEnd();
// When dropped should move to second display's panel container.
EXPECT_EQ(root_windows[1], window->GetRootWindow());
EXPECT_TRUE(window->GetProperty(kPanelAttachedKey));
EXPECT_EQ(kShellWindowId_PanelContainer, window->parent()->id());
}
TEST_F(PanelWindowResizerTest, AttachToSecondDisplay) {
UpdateDisplay("600x400,600x600");
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
std::unique_ptr<aura::Window> window(CreatePanelWindow(gfx::Point()));
gfx::Rect initial_bounds = window->GetBoundsInScreen();
EXPECT_EQ(root_windows[0], window->GetRootWindow());
// Drag the window just above the other display's launcher.
DragStart(window.get());
DragMove(500, 195);
EXPECT_EQ(initial_bounds.x() + 500, window->GetBoundsInScreen().x());
// Should stick to other launcher.
EXPECT_EQ(initial_bounds.y() + 200, window->GetBoundsInScreen().y());
DragEnd();
// When dropped should move to second display's panel container.
EXPECT_EQ(root_windows[1], window->GetRootWindow());
EXPECT_TRUE(window->GetProperty(kPanelAttachedKey));
EXPECT_EQ(kShellWindowId_PanelContainer, window->parent()->id());
}
TEST_F(PanelWindowResizerTest, AttachToSecondFullscreenDisplay) {
UpdateDisplay("600x400,600x600");
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
......@@ -440,15 +348,6 @@ TEST_F(PanelWindowResizerTest, DragMovesToPanelLayer) {
EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
}
TEST_P(PanelWindowResizerTextDirectionTest, DragReordersPanelsHorizontal) {
DragAlongShelfReorder(base::i18n::IsRTL() ? 1 : -1, 0);
}
TEST_F(PanelWindowResizerTest, DragReordersPanelsVertical) {
GetPrimaryShelf()->SetAlignment(SHELF_ALIGNMENT_LEFT);
DragAlongShelfReorder(0, -1);
}
// Tests that panels can have transient children of different types.
// The transient children should be reparented in sync with the panel.
TEST_P(PanelWindowResizerTransientTest, PanelWithTransientChild) {
......
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