blob: b662e072808e0161807a3396651242c0cecba04d [file] [log] [blame]
andrewxu81f25202023-02-28 20:21:341// 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
13namespace ash {
14
15DraggableTestView::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
23DraggableTestView::~DraggableTestView() = default;
24
25void 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