tab_drag_drop_delegate.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // Copyright 2020 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_TAB_DRAG_DROP_DELEGATE_H_
  5. #define ASH_DRAG_DROP_TAB_DRAG_DROP_DELEGATE_H_
  6. #include <memory>
  7. #include "ash/ash_export.h"
  8. #include "ash/drag_drop/drag_drop_capture_delegate.h"
  9. #include "ash/wm/splitview/split_view_controller.h"
  10. #include "ui/gfx/geometry/point.h"
  11. namespace aura {
  12. class Window;
  13. }
  14. namespace ui {
  15. class OSExchangeData;
  16. class PresentationTimeRecorder;
  17. }
  18. namespace ash {
  19. class SplitViewDragIndicators;
  20. class TabletModeBrowserWindowDragSessionWindowsHider;
  21. // Provides special handling for Chrome tab drags on behalf of
  22. // DragDropController. This must be created at the beginning of a tab drag and
  23. // destroyed at the end.
  24. class ASH_EXPORT TabDragDropDelegate : public DragDropCaptureDelegate {
  25. public:
  26. // Determines whether |drag_data| indicates a tab drag from a WebUI tab strip
  27. // (or simply returns false if the integration is disabled).
  28. static bool IsChromeTabDrag(const ui::OSExchangeData& drag_data);
  29. // Returns whether a tab from |window| is actively being dragged.
  30. static bool IsSourceWindowForDrag(const aura::Window* window);
  31. // |root_window| is the root window from which the drag originated. The drag
  32. // is expected to stay in |root_window|. |source_window| is the Chrome window
  33. // the tab was dragged from. |start_location_in_screen| is the location of
  34. // the touch or click that started the drag.
  35. TabDragDropDelegate(aura::Window* root_window,
  36. aura::Window* source_window,
  37. const gfx::Point& start_location_in_screen);
  38. ~TabDragDropDelegate() override;
  39. TabDragDropDelegate(const TabDragDropDelegate&) = delete;
  40. TabDragDropDelegate& operator=(const TabDragDropDelegate&) = delete;
  41. const aura::Window* root_window() const { return root_window_; }
  42. // Must be called on every drag update.
  43. void DragUpdate(const gfx::Point& location_in_screen);
  44. // Must be called on drop if it was not accepted by the drop target. After
  45. // calling this, this delegate must not be used.
  46. void DropAndDeleteSelf(const gfx::Point& location_in_screen,
  47. const ui::OSExchangeData& drop_data);
  48. private:
  49. FRIEND_TEST_ALL_PREFIXES(TabDragDropDelegateTest, DropWithoutNewWindow);
  50. // Scales or transforms the source window if appropriate for this drag.
  51. // |candidate_snap_position| is where the dragged tab will be snapped
  52. // if dropped immediately.
  53. void UpdateSourceWindowBoundsIfNecessary(
  54. SplitViewController::SnapPosition candidate_snap_position,
  55. const gfx::Point& location_in_screen);
  56. // Puts the source window back into its original position.
  57. void RestoreSourceWindowBounds();
  58. // Effectively handles the new window creation in DropAndDeleteSelf(). This
  59. // method can be called asynchronously in case of Lacros.
  60. void OnNewBrowserWindowCreated(const gfx::Point& location_in_screen,
  61. aura::Window* new_window);
  62. // This method returns true when all of the conditions below are met
  63. //
  64. // - Not in split view mode
  65. // - In landscape mode
  66. // - The current drag location is inside the WebUI tab strip
  67. //
  68. // When it returns true, we don't allow to enter split view because
  69. // it hinders dragging tabs within the tab strip to trigger auto-scroll.
  70. // This restriction does not apply to split screen mode because either
  71. // the left/right could be non browser window, which may lead to
  72. // confusing behavior.
  73. // It also does not apply to portrait mode because dragging up/down to
  74. // enter split screen does not hinder dragging left/right to move tabs.
  75. //
  76. // https://crbug.com/1316070
  77. bool ShouldPreventSnapToTheEdge(const gfx::Point& location_in_screen);
  78. aura::Window* const root_window_;
  79. aura::Window* const source_window_;
  80. const gfx::Point start_location_in_screen_;
  81. std::unique_ptr<SplitViewDragIndicators> split_view_drag_indicators_;
  82. std::unique_ptr<TabletModeBrowserWindowDragSessionWindowsHider>
  83. windows_hider_;
  84. // Presentation time recorder for tab dragging in tablet mode with webui
  85. // tab strip enable.
  86. std::unique_ptr<ui::PresentationTimeRecorder> tab_dragging_recorder_;
  87. };
  88. } // namespace ash
  89. #endif // ASH_DRAG_DROP_TAB_DRAG_DROP_DELEGATE_H_