blob: 51312516c67f5f5719698bd9cdd4ce88ef566c7b [file] [log] [blame]
Avi Drissman3a215d1e2022-09-07 19:43:091// Copyright 2012 The Chromium Authors
James Cookb0bf8e82017-04-09 17:01:442// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef ASH_DRAG_DROP_DRAG_IMAGE_VIEW_H_
6#define ASH_DRAG_DROP_DRAG_IMAGE_VIEW_H_
7
James Cookb0bf8e82017-04-09 17:01:448#include "ash/ash_export.h"
James Cookb0bf8e82017-04-09 17:01:449#include "ui/base/dragdrop/drag_drop_types.h"
Henrique Ferreiro1748fd12020-08-04 12:51:4610#include "ui/base/dragdrop/mojom/drag_drop_types.mojom-forward.h"
James Cookb0bf8e82017-04-09 17:01:4411#include "ui/gfx/geometry/point.h"
12#include "ui/gfx/geometry/size.h"
13#include "ui/views/controls/image_view.h"
14
skyf14333c92017-04-18 22:21:0115namespace aura {
16class Window;
17}
18
James Cookb0bf8e82017-04-09 17:01:4419namespace gfx {
20class Image;
21}
22
James Cookb0bf8e82017-04-09 17:01:4423namespace ash {
24
James Cookb0bf8e82017-04-09 17:01:4425// This class allows to show a (native) view always on top of everything. It
26// does this by creating a widget and setting the content as the given view. The
27// caller can then use this object to freely move / drag it around on the
28// desktop in screen coordinates.
29class ASH_EXPORT DragImageView : public views::ImageView {
30 public:
Peter Boströmec31a042021-09-16 23:37:3431 DragImageView(const DragImageView&) = delete;
32 DragImageView& operator=(const DragImageView&) = delete;
33
Allen Bauer35d4e722020-06-16 22:47:5634 ~DragImageView() override;
35
James Cookb0bf8e82017-04-09 17:01:4436 // |root_window| is the root window on which to create the drag image widget.
37 // |source| is the event source that started this drag drop operation (touch
38 // or mouse). It is used to determine attributes of the drag image such as
39 // whether to show drag operation hint on top of the image.
Ana Salazar40d497c2023-02-23 22:47:0740 static std::unique_ptr<views::Widget> Create(
41 aura::Window* root_window,
42 ui::mojom::DragEventSource source);
James Cookb0bf8e82017-04-09 17:01:4443
44 // Sets the bounds of the native widget in screen
45 // coordinates.
46 // TODO(oshima): Looks like this is root window's
47 // coordinate. Change this to screen's coordinate.
48 void SetBoundsInScreen(const gfx::Rect& bounds);
49
50 // Sets the position of the native widget.
51 void SetScreenPosition(const gfx::Point& position);
52
53 // Gets the image position in screen coordinates.
54 gfx::Rect GetBoundsInScreen() const;
55
56 // Sets the visibility of the native widget.
57 void SetWidgetVisible(bool visible);
58
59 // For touch drag drop, we show a hint corresponding to the drag operation
60 // (since no mouse cursor is visible). These functions set the hint
61 // parameters.
62 void SetTouchDragOperationHintOff();
63
64 // |operation| is a bit field indicating allowable drag operations from
65 // ui::DragDropTypes::DragOperation.
66 void SetTouchDragOperation(int operation);
67 void SetTouchDragOperationHintPosition(const gfx::Point& position);
68
69 // Sets the |opacity| of the image view between 0.0 and 1.0.
70 void SetOpacity(float opacity);
71
72 gfx::Size GetMinimumSize() const override;
73
74 private:
Lei Zhang020052d42021-11-05 17:23:0275 explicit DragImageView(ui::mojom::DragEventSource source);
Allen Bauer35d4e722020-06-16 22:47:5676
James Cookb0bf8e82017-04-09 17:01:4477 gfx::Image* DragHint() const;
78 // Drag hint images are only drawn when the input source is touch.
79 bool ShouldDrawDragHint() const;
80
81 // Overridden from views::ImageView.
82 void OnPaint(gfx::Canvas* canvas) override;
83
84 // Overridden from views::view
Peter Kasting1e3a1e992024-02-01 18:10:4185 void Layout(PassKey) override;
James Cookb0bf8e82017-04-09 17:01:4486
James Cookb0bf8e82017-04-09 17:01:4487 // Save the requested drag image size. We may need to display a drag hint
88 // image, which potentially expands |widget_|'s size. That drag hint image
89 // may be disabled (e.g. during the drag cancel animation). In that case,
90 // we need to know the originally requested size to render the drag image.
91 gfx::Size drag_image_size_;
92
Henrique Ferreiro1748fd12020-08-04 12:51:4693 ui::mojom::DragEventSource drag_event_source_;
James Cookb0bf8e82017-04-09 17:01:4494
95 // Bitmask of ui::DragDropTypes::DragOperation values.
Allen Bauer35d4e722020-06-16 22:47:5696 int touch_drag_operation_ = ui::DragDropTypes::DRAG_NONE;
James Cookb0bf8e82017-04-09 17:01:4497 gfx::Point touch_drag_operation_indicator_position_;
James Cookb0bf8e82017-04-09 17:01:4498};
99
100} // namespace ash
101
102#endif // ASH_DRAG_DROP_DRAG_IMAGE_VIEW_H_