drag_window_controller.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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_WM_DRAG_WINDOW_CONTROLLER_H_
  5. #define ASH_WM_DRAG_WINDOW_CONTROLLER_H_
  6. #include <memory>
  7. #include <vector>
  8. #include "ash/ash_export.h"
  9. #include "base/gtest_prod_util.h"
  10. #include "third_party/abseil-cpp/absl/types/optional.h"
  11. #include "ui/gfx/geometry/rect.h"
  12. namespace aura {
  13. class Window;
  14. }
  15. namespace ui {
  16. class Shadow;
  17. }
  18. namespace ash {
  19. // Handles visuals for window dragging as it relates to multi-display support.
  20. // Phantom windows called "drag windows" represent the window on other displays.
  21. class ASH_EXPORT DragWindowController {
  22. public:
  23. DragWindowController(
  24. aura::Window* window,
  25. bool is_touch_dragging,
  26. const absl::optional<gfx::Rect>& shadow_bounds = absl::nullopt);
  27. DragWindowController(const DragWindowController&) = delete;
  28. DragWindowController& operator=(const DragWindowController&) = delete;
  29. virtual ~DragWindowController();
  30. // Updates bounds and opacity for the drag windows, and creates/destroys each
  31. // drag window so that it only exists when it would have nonzero opacity. Also
  32. // updates the opacity of the original window.
  33. void Update();
  34. private:
  35. class DragWindowDetails;
  36. FRIEND_TEST_ALL_PREFIXES(DragWindowResizerTest, DragWindowController);
  37. FRIEND_TEST_ALL_PREFIXES(DragWindowResizerTest,
  38. DragWindowControllerAcrossThreeDisplays);
  39. FRIEND_TEST_ALL_PREFIXES(DragWindowResizerTest,
  40. DragWindowControllerWithCustomShadowBounds);
  41. // Returns the currently active drag windows.
  42. int GetDragWindowsCountForTest() const;
  43. // Returns the drag window/layer owner for given index of the
  44. // currently active drag windows list.
  45. const aura::Window* GetDragWindowForTest(size_t index) const;
  46. const ui::Shadow* GetDragWindowShadowForTest(size_t index) const;
  47. // Call Layer::OnPaintLayer on all layers under the drag_windows_.
  48. void RequestLayerPaintForTest();
  49. // The original window.
  50. aura::Window* window_;
  51. // Indicates touch dragging, as opposed to mouse dragging.
  52. const bool is_touch_dragging_;
  53. // Used if the drag windows may need their shadows adjusted.
  54. const absl::optional<gfx::Rect> shadow_bounds_;
  55. // |window_|'s opacity before the drag. Used to revert opacity after the drag.
  56. const float old_opacity_;
  57. // Phantom windows to visually represent |window_| on other displays.
  58. std::vector<std::unique_ptr<DragWindowDetails>> drag_windows_;
  59. };
  60. } // namespace ash
  61. #endif // ASH_WM_DRAG_WINDOW_CONTROLLER_H_