Commit bd65dcb0 authored by Andrew Xu's avatar Andrew Xu Committed by Commit Bot

[ScrollableShelf] Enable gestures to trigger context menu

This CL enables the scrollable shelf to show context menu for proper
gestures (like long-time tapping). It helps to keep the UI consistency
with the shelf view.

Bug: 1003584
Change-Id: I74b69ffea84fedc6c780cacc01b6eea680b6875b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1801320Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Andrew Xu <andrewxu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697036}
parent b77b4169
...@@ -257,6 +257,8 @@ void ScrollableShelfView::Init() { ...@@ -257,6 +257,8 @@ void ScrollableShelfView::Init() {
focus_search_ = std::make_unique<ScrollableShelfFocusSearch>(this); focus_search_ = std::make_unique<ScrollableShelfFocusSearch>(this);
GetShelf()->tooltip()->set_shelf_tooltip_delegate(this); GetShelf()->tooltip()->set_shelf_tooltip_delegate(this);
set_context_menu_controller(this);
} }
void ScrollableShelfView::OnFocusRingActivationChanged(bool activated) { void ScrollableShelfView::OnFocusRingActivationChanged(bool activated) {
...@@ -580,6 +582,14 @@ void ScrollableShelfView::OnShelfButtonAboutToRequestFocusFromTabTraversal( ...@@ -580,6 +582,14 @@ void ScrollableShelfView::OnShelfButtonAboutToRequestFocusFromTabTraversal(
ShelfButton* button, ShelfButton* button,
bool reverse) {} bool reverse) {}
void ScrollableShelfView::ShowContextMenuForViewImpl(
views::View* source,
const gfx::Point& point,
ui::MenuSourceType source_type) {
// |point| is in screen coordinates. So it does not need to transform.
shelf_view_->ShowContextMenuForViewImpl(shelf_view_, point, source_type);
}
void ScrollableShelfView::ButtonPressed(views::Button* sender, void ScrollableShelfView::ButtonPressed(views::Button* sender,
const ui::Event& event, const ui::Event& event,
views::InkDrop* ink_drop) { views::InkDrop* ink_drop) {
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "ash/shelf/shelf_tooltip_delegate.h" #include "ash/shelf/shelf_tooltip_delegate.h"
#include "ash/shelf/shelf_view.h" #include "ash/shelf/shelf_view.h"
#include "ui/views/animation/ink_drop_host_view.h" #include "ui/views/animation/ink_drop_host_view.h"
#include "ui/views/context_menu_controller.h"
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
namespace views { namespace views {
...@@ -25,7 +26,8 @@ namespace ash { ...@@ -25,7 +26,8 @@ namespace ash {
class ASH_EXPORT ScrollableShelfView : public views::AccessiblePaneView, class ASH_EXPORT ScrollableShelfView : public views::AccessiblePaneView,
public ShellObserver, public ShellObserver,
public ShelfButtonDelegate, public ShelfButtonDelegate,
public ShelfTooltipDelegate { public ShelfTooltipDelegate,
public views::ContextMenuController {
public: public:
enum LayoutStrategy { enum LayoutStrategy {
// The arrow buttons are not shown. It means that there is enough space to // The arrow buttons are not shown. It means that there is enough space to
...@@ -131,6 +133,12 @@ class ASH_EXPORT ScrollableShelfView : public views::AccessiblePaneView, ...@@ -131,6 +133,12 @@ class ASH_EXPORT ScrollableShelfView : public views::AccessiblePaneView,
// ShelfButtonDelegate: // ShelfButtonDelegate:
void OnShelfButtonAboutToRequestFocusFromTabTraversal(ShelfButton* button, void OnShelfButtonAboutToRequestFocusFromTabTraversal(ShelfButton* button,
bool reverse) override; bool reverse) override;
// ContextMenuController:
void ShowContextMenuForViewImpl(views::View* source,
const gfx::Point& point,
ui::MenuSourceType source_type) override;
void ButtonPressed(views::Button* sender, void ButtonPressed(views::Button* sender,
const ui::Event& event, const ui::Event& event,
views::InkDrop* ink_drop) override; views::InkDrop* ink_drop) override;
......
...@@ -822,6 +822,32 @@ void ShelfView::CreateDragIconProxy( ...@@ -822,6 +822,32 @@ void ShelfView::CreateDragIconProxy(
drag_image_->SetWidgetVisible(true); drag_image_->SetWidgetVisible(true);
} }
void ShelfView::ShowContextMenuForViewImpl(views::View* source,
const gfx::Point& point,
ui::MenuSourceType source_type) {
// Prevent concurrent requests that may show application or context menus.
const ShelfItem* item = ShelfItemForView(source);
if (!item_awaiting_response_.IsNull()) {
if (item && item->id != item_awaiting_response_) {
static_cast<views::Button*>(source)->AnimateInkDrop(
views::InkDropState::DEACTIVATED, nullptr);
}
return;
}
last_pressed_index_ = -1;
if (!item || !model_->GetShelfItemDelegate(item->id)) {
ShowShelfContextMenu(ShelfID(), point, source, source_type, nullptr);
return;
}
item_awaiting_response_ = item->id;
const int64_t display_id = GetDisplayIdForView(this);
model_->GetShelfItemDelegate(item->id)->GetContextMenu(
display_id, base::BindOnce(&ShelfView::ShowShelfContextMenu,
weak_factory_.GetWeakPtr(), item->id, point,
source, source_type));
}
void ShelfView::OnTabletModeStarted() { void ShelfView::OnTabletModeStarted() {
// Close all menus when tablet mode starts to ensure that the clamshell only // Close all menus when tablet mode starts to ensure that the clamshell only
// context menu options are not available in tablet mode. // context menu options are not available in tablet mode.
...@@ -2311,32 +2337,6 @@ void ShelfView::ShowShelfContextMenu( ...@@ -2311,32 +2337,6 @@ void ShelfView::ShowShelfContextMenu(
ShowMenu(std::move(model), source, point, /*context_menu=*/true, source_type); ShowMenu(std::move(model), source, point, /*context_menu=*/true, source_type);
} }
void ShelfView::ShowContextMenuForViewImpl(views::View* source,
const gfx::Point& point,
ui::MenuSourceType source_type) {
// Prevent concurrent requests that may show application or context menus.
const ShelfItem* item = ShelfItemForView(source);
if (!item_awaiting_response_.IsNull()) {
if (item && item->id != item_awaiting_response_) {
static_cast<views::Button*>(source)->AnimateInkDrop(
views::InkDropState::DEACTIVATED, nullptr);
}
return;
}
last_pressed_index_ = -1;
if (!item || !model_->GetShelfItemDelegate(item->id)) {
ShowShelfContextMenu(ShelfID(), point, source, source_type, nullptr);
return;
}
item_awaiting_response_ = item->id;
const int64_t display_id = GetDisplayIdForView(this);
model_->GetShelfItemDelegate(item->id)->GetContextMenu(
display_id, base::BindOnce(&ShelfView::ShowShelfContextMenu,
weak_factory_.GetWeakPtr(), item->id, point,
source, source_type));
}
void ShelfView::ShowMenu(std::unique_ptr<ui::SimpleMenuModel> menu_model, void ShelfView::ShowMenu(std::unique_ptr<ui::SimpleMenuModel> menu_model,
views::View* source, views::View* source,
const gfx::Point& click_point, const gfx::Point& click_point,
......
...@@ -207,6 +207,11 @@ class ASH_EXPORT ShelfView : public views::AccessiblePaneView, ...@@ -207,6 +207,11 @@ class ASH_EXPORT ShelfView : public views::AccessiblePaneView,
const gfx::Vector2d& cursor_offset_from_center, const gfx::Vector2d& cursor_offset_from_center,
float scale_factor) override; float scale_factor) override;
// Overridden from views::ContextMenuController:
void ShowContextMenuForViewImpl(views::View* source,
const gfx::Point& point,
ui::MenuSourceType source_type) override;
// ash::TabletModeObserver: // ash::TabletModeObserver:
void OnTabletModeStarted() override; void OnTabletModeStarted() override;
void OnTabletModeEnded() override; void OnTabletModeEnded() override;
...@@ -510,11 +515,6 @@ class ASH_EXPORT ShelfView : public views::AccessiblePaneView, ...@@ -510,11 +515,6 @@ class ASH_EXPORT ShelfView : public views::AccessiblePaneView,
ShelfAction action, ShelfAction action,
ShelfItemDelegate::AppMenuItems menu_items); ShelfItemDelegate::AppMenuItems menu_items);
// Overridden from views::ContextMenuController:
void ShowContextMenuForViewImpl(views::View* source,
const gfx::Point& point,
ui::MenuSourceType source_type) override;
// Show either a context or normal click menu of given |menu_model|. // Show either a context or normal click menu of given |menu_model|.
// If |context_menu| is set, the displayed menu is a context menu and not // If |context_menu| is set, the displayed menu is a context menu and not
// a menu listing one or more running applications. // a menu listing one or more running applications.
......
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