Commit 74f837ef authored by David Black's avatar David Black Committed by Commit Bot

Add initial drag image for holding space item views.

This CL adds the initial drag image that is displayed when dragging
items out of Holding Space UI. Follow up CLs will:

- Render screenshot items differently
- Render at most two items with an overflow badge if necessary

Note that this CL does not use ui::Layer's to accomplish the desired
drop shadow effect because a solution could not be identified to paint
a view hierarchy with its layer tree to an SkBitmap.

Demo: http://shortn/_mWLGXsTcTY
Note that the screen recorder did not capture the cursor moving with
the drag image but it actually does so on device.

Bug: 1139113
Change-Id: I569bf42b31beb19459f85a80bfc1c3f673a40b1a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2476728
Commit-Queue: David Black <dmblack@google.com>
Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818024}
parent 1079fd94
...@@ -946,6 +946,8 @@ component("ash") { ...@@ -946,6 +946,8 @@ component("ash") {
"system/gesture_education/gesture_education_notification_controller.h", "system/gesture_education/gesture_education_notification_controller.h",
"system/holding_space/holding_space_color_provider_impl.cc", "system/holding_space/holding_space_color_provider_impl.cc",
"system/holding_space/holding_space_color_provider_impl.h", "system/holding_space/holding_space_color_provider_impl.h",
"system/holding_space/holding_space_drag_util.cc",
"system/holding_space/holding_space_drag_util.h",
"system/holding_space/holding_space_item_chip_view.cc", "system/holding_space/holding_space_item_chip_view.cc",
"system/holding_space/holding_space_item_chip_view.h", "system/holding_space/holding_space_item_chip_view.h",
"system/holding_space/holding_space_item_chips_container.cc", "system/holding_space/holding_space_item_chips_container.cc",
......
This diff is collapsed.
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_HOLDING_SPACE_HOLDING_SPACE_DRAG_UTIL_H_
#define ASH_SYSTEM_HOLDING_SPACE_HOLDING_SPACE_DRAG_UTIL_H_
#include <vector>
namespace gfx {
class ImageSkia;
} // namespace gfx
namespace ash {
class HoldingSpaceItemView;
namespace holding_space_util {
// Returns a drag image for the specified holding space item `views`. The drag
// image consists of a stacked representation of the dragged items with the
// first item being stacked on top. Note that the drag image will paint at most
// two items with an overflow badge to represent the presence of additional drag
// items if necessary.
gfx::ImageSkia CreateDragImage(
const std::vector<const HoldingSpaceItemView*>& views);
} // namespace holding_space_util
} // namespace ash
#endif // ASH_SYSTEM_HOLDING_SPACE_HOLDING_SPACE_DRAG_UTIL_H_
...@@ -12,12 +12,15 @@ ...@@ -12,12 +12,15 @@
#include "ash/public/cpp/holding_space/holding_space_model.h" #include "ash/public/cpp/holding_space/holding_space_model.h"
#include "ash/resources/vector_icons/vector_icons.h" #include "ash/resources/vector_icons/vector_icons.h"
#include "ash/strings/grit/ash_strings.h" #include "ash/strings/grit/ash_strings.h"
#include "ash/system/holding_space/holding_space_drag_util.h"
#include "ash/system/holding_space/holding_space_item_view.h" #include "ash/system/holding_space/holding_space_item_view.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/i18n/rtl.h"
#include "net/base/mime_util.h" #include "net/base/mime_util.h"
#include "ui/accessibility/ax_action_data.h" #include "ui/accessibility/ax_action_data.h"
#include "ui/accessibility/ax_enums.mojom.h" #include "ui/accessibility/ax_enums.mojom.h"
#include "ui/base/dragdrop/drag_drop_types.h" #include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/dragdrop/os_exchange_data_provider.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/models/simple_menu_model.h" #include "ui/base/models/simple_menu_model.h"
#include "ui/views/controls/menu/menu_runner.h" #include "ui/views/controls/menu/menu_runner.h"
...@@ -234,10 +237,18 @@ void HoldingSpaceItemViewDelegate::WriteDragDataForView( ...@@ -234,10 +237,18 @@ void HoldingSpaceItemViewDelegate::WriteDragDataForView(
holding_space_metrics::RecordItemAction( holding_space_metrics::RecordItemAction(
GetItems(selection), holding_space_metrics::ItemAction::kDrag); GetItems(selection), holding_space_metrics::ItemAction::kDrag);
// Drag image.
gfx::ImageSkia drag_image = holding_space_util::CreateDragImage(selection);
data->provider().SetDragImage(std::move(drag_image),
/*image_offset=*/base::i18n::IsRTL()
? gfx::Vector2d(drag_image.width(), 0)
: gfx::Vector2d());
// Payload.
std::vector<ui::FileInfo> filenames; std::vector<ui::FileInfo> filenames;
for (const HoldingSpaceItemView* view : selection) { for (const HoldingSpaceItemView* view : selection) {
filenames.push_back(ui::FileInfo(view->item()->file_path(), const base::FilePath& file_path = view->item()->file_path();
view->item()->file_path().BaseName())); filenames.push_back(ui::FileInfo(file_path, file_path.BaseName()));
} }
data->SetFilenames(filenames); data->SetFilenames(filenames);
} }
......
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