andrewxu | 81f2520 | 2023-02-28 20:21:34 | [diff] [blame] | 1 | // Copyright 2023 The Chromium Authors |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "ash/drag_drop/draggable_test_view.h" |
| 6 | |
| 7 | #include "base/files/file_path.h" |
| 8 | #include "third_party/skia/include/core/SkBitmap.h" |
| 9 | #include "ui/base/dragdrop/drag_drop_types.h" |
| 10 | #include "ui/base/dragdrop/os_exchange_data.h" |
| 11 | #include "ui/base/dragdrop/os_exchange_data_provider.h" |
| 12 | |
| 13 | namespace ash { |
| 14 | |
| 15 | DraggableTestView::DraggableTestView(bool set_drag_image, bool set_file_name) |
| 16 | : set_drag_image_(set_drag_image), set_file_name_(set_file_name) { |
| 17 | // The drag operation is `DRAG_COPY` by default. `DraggableTestView` users |
| 18 | // can use `WillOnce()` or `WillRepeatedly()` to customize the return. |
| 19 | ON_CALL(*this, GetDragOperations) |
| 20 | .WillByDefault(testing::Return(ui::DragDropTypes::DRAG_COPY)); |
| 21 | } |
| 22 | |
| 23 | DraggableTestView::~DraggableTestView() = default; |
| 24 | |
| 25 | void DraggableTestView::WriteDragData(const gfx::Point& press_pt, |
| 26 | ui::OSExchangeData* data) { |
| 27 | data->SetString(u"test"); |
| 28 | |
| 29 | if (set_file_name_) { |
| 30 | data->SetFilename(base::FilePath("dummy_path")); |
| 31 | } |
| 32 | |
| 33 | if (set_drag_image_) { |
| 34 | SkBitmap bitmap; |
| 35 | bitmap.allocN32Pixels(/*width=*/10, /*height=*/10); |
| 36 | data->provider().SetDragImage(gfx::ImageSkia::CreateFrom1xBitmap(bitmap), |
| 37 | gfx::Vector2d()); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | } // namespace ash |