app_drag_icon_proxy.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Copyright 2021 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_APP_LIST_VIEWS_APP_DRAG_ICON_PROXY_H_
  5. #define ASH_APP_LIST_VIEWS_APP_DRAG_ICON_PROXY_H_
  6. #include <memory>
  7. #include "base/callback.h"
  8. #include "ui/compositor/layer_animation_observer.h"
  9. #include "ui/gfx/geometry/vector2d.h"
  10. #include "ui/views/widget/unique_widget_ptr.h"
  11. namespace aura {
  12. class Window;
  13. } // namespace aura
  14. namespace gfx {
  15. class ImageSkia;
  16. class Point;
  17. class Rect;
  18. } // namespace gfx
  19. namespace ui {
  20. class Layer;
  21. } // namespace ui
  22. namespace ash {
  23. class SystemShadow;
  24. // Manages the drag image shown while an app is being dragged in app list or
  25. // shelf. It creates a DragImageView widget in a window container used for
  26. // drag images, so the app icon can escape the views container that owns the
  27. // dragged app view. The widget is destroyed when this goes out of scope.
  28. class AppDragIconProxy : public ui::ImplicitAnimationObserver {
  29. public:
  30. // `root_window` - The root window to which the proxy should be added.
  31. // `icon` - The icon to be used for the app icon.
  32. // `pointer_location_in_screen` - The initial pointer location.
  33. // `pointer_offset_from_center` - The pointer offset from the center of the
  34. // drag image. The drag icon position will be offset from the pointer
  35. // location to maintain pointer offset from the drag image center.
  36. // `scale_factor` - The scale factor by which the `icon` should be scaled when
  37. // shown as a drag image.
  38. // `use_blurred_background` - whether the drag image should have blurred
  39. // background.
  40. AppDragIconProxy(aura::Window* root_window,
  41. const gfx::ImageSkia& icon,
  42. const gfx::Point& pointer_location_in_screen,
  43. const gfx::Vector2d& pointer_offset_from_center,
  44. float scale_factor,
  45. bool use_blurred_background);
  46. AppDragIconProxy(const AppDragIconProxy&) = delete;
  47. AppDragIconProxy& operator=(const AppDragIconProxy&) = delete;
  48. ~AppDragIconProxy() override;
  49. // ui::ImplicitAnimationObserver:
  50. void OnImplicitAnimationsCompleted() override;
  51. // Updates drag icon position to match the new pointer location.
  52. void UpdatePosition(const gfx::Point& pointer_location_in_screen);
  53. // Animates the drag image to the provided bounds, and closes the widget once
  54. // the animation completes. Expected to be called at most once.
  55. // `animation_completion_callback` - Called when the animation completes, or
  56. // when the `AppDragIconProxy` gets deleted.
  57. void AnimateToBoundsAndCloseWidget(
  58. const gfx::Rect& bounds_in_screen,
  59. base::OnceClosure animation_completion_callback);
  60. // Sets the drag image opacity.
  61. void SetOpacity(float opacity);
  62. // Returns the current drag image bounds in screen.
  63. gfx::Rect GetBoundsInScreen() const;
  64. // Returns the drag image view's layer.
  65. ui::Layer* GetImageLayerForTesting();
  66. // Returns the drag image widget.
  67. views::Widget* GetWidgetForTesting();
  68. private:
  69. // Whether close animation (see `AnimateToBoundsAndCloseWidget()`) is in
  70. // progress.
  71. bool closing_widget_ = false;
  72. std::unique_ptr<SystemShadow> shadow_;
  73. // The widget used to display the drag image.
  74. views::UniqueWidgetPtr drag_image_widget_;
  75. // The cursor offset to the center of the dragged item.
  76. gfx::Vector2d drag_image_offset_;
  77. base::OnceClosure animation_completion_callback_;
  78. };
  79. } // namespace ash
  80. #endif // ASH_APP_LIST_VIEWS_APP_DRAG_ICON_PROXY_H_