Commit 5b65a4f3 authored by Manu Cornet's avatar Manu Cornet Committed by Commit Bot

CrOS Shelf: Mark manual pin/unpin changes as user-triggered

This particular change should not cause any behaviour change.

This new distinction will be used for at least two purposes in the
near future:

1) provide accessibility feedback (alert) when an item has been
   pinned to, or unpinned from, the shelf

2) provide visual feedback when an item has been pinned to the
   "scrollable" shelf (for instance scroll the scroll view to have
   the new item within the viewport).

Neither of these interactions should happen when the pinning/unpinning
is not a result of a user-initiated action, such as in callbacks to
sync events.

Bug: 1012772, 1010697
Change-Id: Ib581aa05841826b78a7ba8cfe5d2b0a52f367810
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1925439
Commit-Queue: Manu Cornet <manucornet@chromium.org>
Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#717748}
parent 12266bcc
......@@ -59,7 +59,7 @@ class ASH_PUBLIC_EXPORT ShelfModel {
// If there is no running instance, a new shelf item is created and pinned.
void PinAppWithID(const std::string& app_id);
// Check if the app with |app_id_| is pinned to the shelf.
// Checks if the app with |app_id_| is pinned to the shelf.
bool IsAppPinned(const std::string& app_id);
// Unpins app item with |app_id|.
......
......@@ -1287,6 +1287,7 @@ bool ShelfView::StartDrag(const std::string& app_id,
// When an item is dragged from overflow to shelf, IsShowingOverflowBubble()
// returns true. At this time, we don't need to pin the item.
if (!IsShowingOverflowBubble() && !model_->IsAppPinned(app_id)) {
ShelfModel::ScopedUserTriggeredMutation user_triggered(model_);
model_->PinAppWithID(app_id);
drag_and_drop_item_pinned_ = true;
}
......@@ -1349,6 +1350,7 @@ void ShelfView::EndDrag(bool cancel) {
// Either destroy the temporarily created item - or - make the item visible.
if (drag_and_drop_item_pinned_ && cancel) {
ShelfModel::ScopedUserTriggeredMutation user_triggered(model_);
model_->UnpinAppWithID(drag_and_drop_shelf_id_.app_id);
} else if (drag_and_drop_view) {
std::unique_ptr<gfx::AnimationDelegate> animation_delegate;
......@@ -1922,6 +1924,7 @@ void ShelfView::FinalizeRipOffDrag(bool cancel) {
} else {
// Make sure the item stays invisible upon removal.
drag_view_->SetVisible(false);
ShelfModel::ScopedUserTriggeredMutation user_triggered(model_);
model_->UnpinAppWithID(model_->items()[current_index].id.app_id);
}
}
......
......@@ -4,6 +4,7 @@
#include "chrome/browser/ui/app_list/app_context_menu.h"
#include "ash/public/cpp/shelf_model.h"
#include "chrome/browser/ui/app_list/app_context_menu_delegate.h"
#include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
#include "chrome/grit/generated_resources.h"
......@@ -70,6 +71,8 @@ bool AppContextMenu::IsCommandIdEnabled(int command_id) const {
void AppContextMenu::TogglePin(const std::string& shelf_app_id) {
DCHECK_EQ(AppListControllerDelegate::PIN_EDITABLE,
controller_->GetPinnable(shelf_app_id));
ash::ShelfModel::ScopedUserTriggeredMutation user_triggered(
ash::ShelfModel::Get());
if (controller_->IsAppPinned(shelf_app_id))
controller_->UnpinApp(shelf_app_id);
else
......
......@@ -104,6 +104,8 @@ bool LauncherContextMenu::IsCommandIdEnabled(int command_id) const {
}
void LauncherContextMenu::ExecuteCommand(int command_id, int event_flags) {
ash::ShelfModel::ScopedUserTriggeredMutation user_triggered(
controller_->shelf_model());
switch (static_cast<ash::CommandId>(command_id)) {
case ash::MENU_OPEN_NEW:
// Use a copy of the id to avoid crashes, as this menu's owner will be
......
......@@ -156,6 +156,7 @@ void AppInfoFooterPanel::SetPinnedToShelf(bool value) {
ash::ShelfModel* shelf_model =
ChromeLauncherController::instance()->shelf_model();
DCHECK(shelf_model);
ash::ShelfModel::ScopedUserTriggeredMutation user_triggered(shelf_model);
if (value)
shelf_model->PinAppWithID(app_->id());
else
......
......@@ -20,6 +20,7 @@
#include "chrome/browser/web_applications/web_app_provider.h"
#if defined(OS_CHROMEOS)
#include "ash/public/cpp/shelf_model.h"
#include "chrome/browser/ui/app_list/app_list_syncable_service.h"
#include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
......
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