drag_image_view.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef ASH_DRAG_DROP_DRAG_IMAGE_VIEW_H_
  5. #define ASH_DRAG_DROP_DRAG_IMAGE_VIEW_H_
  6. #include "ash/ash_export.h"
  7. #include "ui/base/dragdrop/drag_drop_types.h"
  8. #include "ui/base/dragdrop/mojom/drag_drop_types.mojom-forward.h"
  9. #include "ui/gfx/geometry/point.h"
  10. #include "ui/gfx/geometry/size.h"
  11. #include "ui/views/controls/image_view.h"
  12. #include "ui/views/widget/unique_widget_ptr.h"
  13. namespace aura {
  14. class Window;
  15. }
  16. namespace gfx {
  17. class Image;
  18. }
  19. namespace ash {
  20. // This class allows to show a (native) view always on top of everything. It
  21. // does this by creating a widget and setting the content as the given view. The
  22. // caller can then use this object to freely move / drag it around on the
  23. // desktop in screen coordinates.
  24. class ASH_EXPORT DragImageView : public views::ImageView {
  25. public:
  26. DragImageView(const DragImageView&) = delete;
  27. DragImageView& operator=(const DragImageView&) = delete;
  28. ~DragImageView() override;
  29. // |root_window| is the root window on which to create the drag image widget.
  30. // |source| is the event source that started this drag drop operation (touch
  31. // or mouse). It is used to determine attributes of the drag image such as
  32. // whether to show drag operation hint on top of the image.
  33. static views::UniqueWidgetPtr Create(aura::Window* root_window,
  34. ui::mojom::DragEventSource source);
  35. // Sets the bounds of the native widget in screen
  36. // coordinates.
  37. // TODO(oshima): Looks like this is root window's
  38. // coordinate. Change this to screen's coordinate.
  39. void SetBoundsInScreen(const gfx::Rect& bounds);
  40. // Sets the position of the native widget.
  41. void SetScreenPosition(const gfx::Point& position);
  42. // Gets the image position in screen coordinates.
  43. gfx::Rect GetBoundsInScreen() const;
  44. // Sets the visibility of the native widget.
  45. void SetWidgetVisible(bool visible);
  46. // For touch drag drop, we show a hint corresponding to the drag operation
  47. // (since no mouse cursor is visible). These functions set the hint
  48. // parameters.
  49. void SetTouchDragOperationHintOff();
  50. // |operation| is a bit field indicating allowable drag operations from
  51. // ui::DragDropTypes::DragOperation.
  52. void SetTouchDragOperation(int operation);
  53. void SetTouchDragOperationHintPosition(const gfx::Point& position);
  54. // Sets the |opacity| of the image view between 0.0 and 1.0.
  55. void SetOpacity(float opacity);
  56. gfx::Size GetMinimumSize() const override;
  57. private:
  58. explicit DragImageView(ui::mojom::DragEventSource source);
  59. gfx::Image* DragHint() const;
  60. // Drag hint images are only drawn when the input source is touch.
  61. bool ShouldDrawDragHint() const;
  62. // Overridden from views::ImageView.
  63. void OnPaint(gfx::Canvas* canvas) override;
  64. // Overridden from views::view
  65. void Layout() override;
  66. // Save the requested drag image size. We may need to display a drag hint
  67. // image, which potentially expands |widget_|'s size. That drag hint image
  68. // may be disabled (e.g. during the drag cancel animation). In that case,
  69. // we need to know the originally requested size to render the drag image.
  70. gfx::Size drag_image_size_;
  71. ui::mojom::DragEventSource drag_event_source_;
  72. // Bitmask of ui::DragDropTypes::DragOperation values.
  73. int touch_drag_operation_ = ui::DragDropTypes::DRAG_NONE;
  74. gfx::Point touch_drag_operation_indicator_position_;
  75. };
  76. } // namespace ash
  77. #endif // ASH_DRAG_DROP_DRAG_IMAGE_VIEW_H_