Commit 8292d610 authored by Min Chen's avatar Min Chen Committed by Commit Bot

Items in AUTO_HIDE_SHOWN shelf should can be dragged after context menu is shown.

Changes in this cl:
- Make sure ShelfLayoutManager doesn't handle the following gesture events after
  ET_GESTURE_SCROLL_BEGIN for auto_hide shelf. Then they can still be propagated
  to ShelfButton to process the drag and drop.

- Start the gesture drag and ink drop timer of the shelf item only if the shelf
  is visible. Then gesture drag on the item in AUTO_HIDE_HIDDEN shelf will not
  activate the ink drop of the shelf item.

- Update the shelf visibility in ShelfView::OnMenuClosed only if there is no
  shelf item in drag. Since shelf should be kept as visible during drag even the
  menu is closed.

Bug: 905847
Change-Id: I384b4c4b3bc2d240820cea338c4ddc59d8cc517a
Reviewed-on: https://chromium-review.googlesource.com/c/1340952
Commit-Queue: Min Chen <minch@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609842}
parent f3666376
...@@ -95,6 +95,10 @@ void Shelf::DestroyShelfWidget() { ...@@ -95,6 +95,10 @@ void Shelf::DestroyShelfWidget() {
shelf_widget_.reset(); shelf_widget_.reset();
} }
bool Shelf::IsVisible() const {
return shelf_layout_manager_->IsVisible();
}
aura::Window* Shelf::GetWindow() { aura::Window* Shelf::GetWindow() {
return shelf_widget_->GetNativeWindow(); return shelf_widget_->GetNativeWindow();
} }
......
...@@ -59,6 +59,11 @@ class ASH_EXPORT Shelf : public ShelfLayoutManagerObserver { ...@@ -59,6 +59,11 @@ class ASH_EXPORT Shelf : public ShelfLayoutManagerObserver {
return shelf_layout_manager_; return shelf_layout_manager_;
} }
// Returns true if the shelf is visible. Shelf can be visible in 1)
// SHELF_VISIBLE or 2) SHELF_AUTO_HIDE but in SHELF_AUTO_HIDE_SHOWN. See
// details in ShelfLayoutManager::IsVisible.
bool IsVisible() const;
ShelfWidget* shelf_widget() { return shelf_widget_.get(); } ShelfWidget* shelf_widget() { return shelf_widget_.get(); }
// Returns the window showing the shelf. // Returns the window showing the shelf.
......
...@@ -605,16 +605,20 @@ void ShelfButton::ChildPreferredSizeChanged(views::View* child) { ...@@ -605,16 +605,20 @@ void ShelfButton::ChildPreferredSizeChanged(views::View* child) {
void ShelfButton::OnGestureEvent(ui::GestureEvent* event) { void ShelfButton::OnGestureEvent(ui::GestureEvent* event) {
switch (event->type()) { switch (event->type()) {
case ui::ET_GESTURE_TAP_DOWN: case ui::ET_GESTURE_TAP_DOWN:
AddState(STATE_HOVERED); if (shelf_view_->shelf()->IsVisible()) {
drag_timer_.Start( AddState(STATE_HOVERED);
FROM_HERE, base::TimeDelta::FromMilliseconds(kDragTimeThresholdMs), drag_timer_.Start(
base::Bind(&ShelfButton::OnTouchDragTimer, base::Unretained(this))); FROM_HERE, base::TimeDelta::FromMilliseconds(kDragTimeThresholdMs),
ripple_activation_timer_.Start( base::BindRepeating(&ShelfButton::OnTouchDragTimer,
FROM_HERE, base::Unretained(this)));
base::TimeDelta::FromMilliseconds(kInkDropRippleActivationTimeMs), ripple_activation_timer_.Start(
base::Bind(&ShelfButton::OnRippleTimer, base::Unretained(this))); FROM_HERE,
GetInkDrop()->AnimateToState(views::InkDropState::ACTION_PENDING); base::TimeDelta::FromMilliseconds(kInkDropRippleActivationTimeMs),
event->SetHandled(); base::BindRepeating(&ShelfButton::OnRippleTimer,
base::Unretained(this)));
GetInkDrop()->AnimateToState(views::InkDropState::ACTION_PENDING);
event->SetHandled();
}
break; break;
case ui::ET_GESTURE_END: case ui::ET_GESTURE_END:
drag_timer_.Stop(); drag_timer_.Stop();
......
...@@ -394,13 +394,6 @@ bool ShelfLayoutManager::ProcessGestureEvent( ...@@ -394,13 +394,6 @@ bool ShelfLayoutManager::ProcessGestureEvent(
if (gesture_drag_status_ != GESTURE_DRAG_IN_PROGRESS && if (gesture_drag_status_ != GESTURE_DRAG_IN_PROGRESS &&
gesture_drag_status_ != GESTURE_DRAG_APPLIST_IN_PROGRESS) { gesture_drag_status_ != GESTURE_DRAG_APPLIST_IN_PROGRESS) {
if ((shelf_->GetVisibilityState() == SHELF_AUTO_HIDE &&
shelf_->GetAutoHideState() == SHELF_AUTO_HIDE_HIDDEN) ||
shelf_->GetVisibilityState() == SHELF_HIDDEN) {
// Do not allow children to handle events while the shelf is hidden.
return true;
}
return false; return false;
} }
......
...@@ -2130,8 +2130,12 @@ void ShelfView::OnMenuClosed(views::View* source) { ...@@ -2130,8 +2130,12 @@ void ShelfView::OnMenuClosed(views::View* source) {
shelf_menu_model_adapter_.reset(); shelf_menu_model_adapter_.reset();
// Auto-hide or alignment might have changed, but only for this shelf. const bool is_in_drag = item && ShelfButtonIsInDrag(item->type, source);
shelf_->UpdateVisibilityState(); // Update the shelf visibility since auto-hide or alignment might have
// changes, but don't update if shelf item is being dragged. Since shelf
// should be kept as visible during shelf item drag even menu is closed.
if (!is_in_drag)
shelf_->UpdateVisibilityState();
} }
void ShelfView::OnBoundsAnimatorProgressed(views::BoundsAnimator* animator) { void ShelfView::OnBoundsAnimatorProgressed(views::BoundsAnimator* animator) {
......
...@@ -2085,6 +2085,64 @@ TEST_F(ShelfViewTest, ShelfDragViewAndContextMenu) { ...@@ -2085,6 +2085,64 @@ TEST_F(ShelfViewTest, ShelfDragViewAndContextMenu) {
EXPECT_FALSE(shelf_view_->drag_view()); EXPECT_FALSE(shelf_view_->drag_view());
} }
// Tests that shelf items in always shown shelf can be dragged through gesture
// events after context menu is shown.
TEST_F(ShelfViewTest, DragAppAfterContextMenuIsShownInAlwaysShownShelf) {
ASSERT_EQ(SHELF_VISIBLE, GetPrimaryShelf()->GetVisibilityState());
ui::test::EventGenerator* generator = GetEventGenerator();
const ShelfID first_app_id = AddAppShortcut();
const ShelfID second_app_id = AddAppShortcut();
const int last_index = model_->items().size() - 1;
ASSERT_TRUE(last_index >= 0);
const gfx::Point start = GetButtonCenter(first_app_id);
// Drag the app long enough to ensure the drag can be triggered.
const gfx::Point end(start.x() + 100, start.y());
generator->set_current_location(start);
// Add |STATE_DRAGGING| state to emulate the gesture drag after context menu
// is shown.
GetButtonByID(first_app_id)->AddState(ShelfButton::STATE_DRAGGING);
generator->GestureScrollSequence(start, end,
base::TimeDelta::FromMilliseconds(100), 3);
// |first_add_id| has been moved to the end of the items in the shelf.
EXPECT_EQ(first_app_id, model_->items()[last_index].id);
}
// Tests that shelf items in AUTO_HIDE_SHOWN shelf can be dragged through
// gesture events after context menu is shown.
TEST_F(ShelfViewTest, DragAppAfterContextMenuIsShownInAutoHideShelf) {
ui::test::EventGenerator* generator = GetEventGenerator();
const ShelfID first_app_id = AddAppShortcut();
const ShelfID second_app_id = AddAppShortcut();
const int last_index = model_->items().size() - 1;
Shelf* shelf = GetPrimaryShelf();
std::unique_ptr<views::Widget> widget = CreateTestWidget();
widget->Show();
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
shelf->shelf_widget()->GetFocusCycler()->RotateFocus(FocusCycler::FORWARD);
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
const gfx::Point start = GetButtonCenter(first_app_id);
// Drag the app long enough to ensure the drag can be triggered.
const gfx::Point end = gfx::Point(start.x() + 100, start.y());
generator->set_current_location(start);
// Add |STATE_DRAGGING| state to emulate the gesture drag after context menu
// is shown.
GetButtonByID(first_app_id)->AddState(ShelfButton::STATE_DRAGGING);
generator->GestureScrollSequence(start, end,
base::TimeDelta::FromMilliseconds(100), 3);
// |first_add_id| has been moved to the end of the items in the shelf.
EXPECT_EQ(first_app_id, model_->items()[last_index].id);
}
struct TouchableAppContextMenuTestParams { struct TouchableAppContextMenuTestParams {
TouchableAppContextMenuTestParams(bool enable_touchable_app_context_menu, TouchableAppContextMenuTestParams(bool enable_touchable_app_context_menu,
bool context_menu) bool context_menu)
......
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