Commit 0f441d76 authored by Ana Salazar's avatar Ana Salazar Committed by Chromium LUCI CQ

Click/Tap tote bubble background to deselect items

For tote, users should be able to clear the selection by clicking or
tapping on the bubble background.

Bug: 1146145
Change-Id: Ibaabe09ae6f6b5dfb73581e1169d0a2d46651ee3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2628075
Commit-Queue: Ana Salazar <anasalazar@chromium.org>
Reviewed-by: default avatarDavid Black <dmblack@google.com>
Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843692}
parent 9c611482
......@@ -239,6 +239,19 @@ bool HoldingSpaceItemViewDelegate::OnHoldingSpaceTrayKeyPressed(
return false;
}
void HoldingSpaceItemViewDelegate::OnHoldingSpaceItemViewsSectionMousePressed(
const ui::MouseEvent& event) {
SetSelection({});
}
void HoldingSpaceItemViewDelegate::OnHoldingSpaceItemViewsSectionGestureEvent(
const ui::GestureEvent& event) {
if (event.type() != ui::ET_GESTURE_TAP)
return;
SetSelection({});
}
void HoldingSpaceItemViewDelegate::ShowContextMenuForViewImpl(
views::View* source,
const gfx::Point& point,
......
......@@ -89,6 +89,14 @@ class ASH_EXPORT HoldingSpaceItemViewDelegate
// Invoked when the tray receives the specified key pressed `event`.
bool OnHoldingSpaceTrayKeyPressed(const ui::KeyEvent& event);
// Invoked when the item views section receives the specified mouse pressed
// `event`.
void OnHoldingSpaceItemViewsSectionMousePressed(const ui::MouseEvent& event);
// Invoked when the item views section receives the specified gesture `event`.
void OnHoldingSpaceItemViewsSectionGestureEvent(
const ui::GestureEvent& event);
private:
// views::ContextMenuController:
void ShowContextMenuForViewImpl(views::View* source,
......
......@@ -252,6 +252,16 @@ void HoldingSpaceItemViewsSection::ViewHierarchyChanged(
PreferredSizeChanged();
}
bool HoldingSpaceItemViewsSection::OnMousePressed(const ui::MouseEvent& event) {
delegate_->OnHoldingSpaceItemViewsSectionMousePressed(event);
return true;
}
void HoldingSpaceItemViewsSection::OnGestureEvent(ui::GestureEvent* event) {
delegate_->OnHoldingSpaceItemViewsSectionGestureEvent(*event);
views::View::OnGestureEvent(event);
}
void HoldingSpaceItemViewsSection::OnHoldingSpaceItemsAdded(
const std::vector<const HoldingSpaceItem*>& items) {
const bool needs_update = std::any_of(
......
......@@ -53,6 +53,8 @@ class HoldingSpaceItemViewsSection : public views::View {
void ChildVisibilityChanged(views::View* child) override;
void PreferredSizeChanged() override;
void ViewHierarchyChanged(const views::ViewHierarchyChangedDetails&) override;
void OnGestureEvent(ui::GestureEvent* event) override;
bool OnMousePressed(const ui::MouseEvent& event) override;
// `HoldingSpaceModelObserver` events forwarded from the parent
// `HoldingSpaceTrayChildBubble`. Note that events may be withheld from this
......
......@@ -1669,6 +1669,46 @@ TEST_P(HoldingSpaceTrayTest, EnterKeyOpensSelectedFiles) {
PressKey(download_chips[0], ui::KeyboardCode::VKEY_RETURN, 0);
}
// Clicking on tote buble background should deselect any selected items.
TEST_P(HoldingSpaceTrayTest, ClickBackgroundToDeselectItems) {
StartSession();
// Add two items.
AddItem(HoldingSpaceItem::Type::kDownload, base::FilePath("/tmp/fake1"));
AddItem(HoldingSpaceItem::Type::kDownload, base::FilePath("/tmp/fake2"));
EXPECT_TRUE(test_api()->IsShowingInShelf());
// Show the bubble.
test_api()->Show();
std::vector<views::View*> download_chips = test_api()->GetDownloadChips();
HoldingSpaceItemView* holding_space_item =
HoldingSpaceItemView::Cast(download_chips[0]);
// Click an item chip. The view should be selected.
Click(download_chips[0], 0);
ASSERT_TRUE(holding_space_item->selected());
// Clicking on the parent view should deselect item.
Click(download_chips[0]->parent(), 0);
ASSERT_FALSE(holding_space_item->selected());
test_api()->Show();
download_chips = test_api()->GetDownloadChips();
holding_space_item = HoldingSpaceItemView::Cast(download_chips[0]);
HoldingSpaceItemView* holding_space_item_2 =
HoldingSpaceItemView::Cast(download_chips[1]);
// Click on both items to select them both.
Click(download_chips[0], ui::EF_SHIFT_DOWN);
Click(download_chips[1], ui::EF_SHIFT_DOWN);
ASSERT_TRUE(holding_space_item->selected());
ASSERT_TRUE(holding_space_item_2->selected());
// Clicking on the parent view should deselect both items.
Click(download_chips[0]->parent(), 0);
ASSERT_FALSE(holding_space_item->selected());
ASSERT_FALSE(holding_space_item_2->selected());
}
INSTANTIATE_TEST_SUITE_P(All, HoldingSpaceTrayTest, testing::Bool());
} // namespace ash
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