split_view_drag_indicators.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // Copyright 2017 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_SPLITVIEW_SPLIT_VIEW_DRAG_INDICATORS_H_
  5. #define ASH_WM_SPLITVIEW_SPLIT_VIEW_DRAG_INDICATORS_H_
  6. #include <memory>
  7. #include "ash/ash_export.h"
  8. #include "ash/wm/splitview/split_view_controller.h"
  9. #include "base/gtest_prod_util.h"
  10. #include "ui/gfx/geometry/point.h"
  11. #include "ui/gfx/geometry/rect.h"
  12. namespace aura {
  13. class Window;
  14. } // namespace aura
  15. namespace views {
  16. class Widget;
  17. } // namespace views
  18. namespace ash {
  19. // Enum which contains the indicators that SplitViewDragIndicators can display.
  20. // Converted to a bitmask to make testing easier.
  21. enum class IndicatorType {
  22. kLeftHighlight = 1,
  23. kLeftText = 2,
  24. kRightHighlight = 4,
  25. kRightText = 8
  26. };
  27. // An overlay in which guides users while they are attempting to enter
  28. // splitview. Displays text and highlights when dragging an overview window.
  29. // Displays a highlight of where the window will end up when a window has
  30. // entered a snap region. Shown when the user is dragging an overview window,
  31. // dragging a floated window, or dragging a window from the shelf.
  32. class ASH_EXPORT SplitViewDragIndicators {
  33. public:
  34. // Enum for purposes of providing |SplitViewDragIndicators| with information
  35. // about window dragging.
  36. enum class WindowDraggingState {
  37. // Not dragging, or split view is unsupported (see |ShouldAllowSplitView|).
  38. kNoDrag,
  39. // Dragging is in another display. Split view is supported.
  40. // Note: The distinction between |kNoDrag| and |kOtherDisplay| affects
  41. // animation when the previous state is |kToSnapLeft| or |kToSnapRight|.
  42. kOtherDisplay,
  43. // Started dragging from overview or from the shelf. Split view is
  44. // supported. Not currently dragging in a snap area, or the dragged window
  45. // is not eligible to be snapped in split view.
  46. kFromOverview,
  47. // Started dragging from the top. Split view is supported. Not currently
  48. // dragging in a snap area, or the dragged window is not eligible to be
  49. // snapped in split view.
  50. kFromTop,
  51. // Started dragging from the shelf. Split view is supported. Not currently
  52. // dragging in a snap area, or the dragged window is not eligible to be
  53. // snapped in split view.
  54. kFromShelf,
  55. // Started dragging from the float window state via the caption. Split view
  56. // is supported. If this is the state, the window will not be snapped when
  57. // released; it will either not be in the snapping region, or in the
  58. // snapping region but not snappable.
  59. kFromFloat,
  60. // Currently dragging in the |SplitViewController::LEFT| snap area, and the
  61. // dragged window is eligible to be snapped in split view.
  62. kToSnapLeft,
  63. // Currently dragging in the |SplitViewController::RIGHT| snap area, and the
  64. // dragged window is eligible to be snapped in split view.
  65. kToSnapRight
  66. };
  67. // |SplitViewController::LEFT|, if |window_dragging_state| is |kToSnapLeft|
  68. // |SplitViewController::RIGHT|, if |window_dragging_state| is |kToSnapRight|
  69. // |SplitViewController::NONE| otherwise
  70. static SplitViewController::SnapPosition GetSnapPosition(
  71. WindowDraggingState window_dragging_state);
  72. // |kNoDrag| if |is_dragging| is false or split view is unsupported. If
  73. // |is_dragging| is true and split view is supported, then:
  74. // |non_snap_state|, if |snap_position| is |SplitViewController::NONE|
  75. // |kToSnapLeft|, if |snap_position| is |SplitViewController::LEFT|
  76. // |kToSnapRight|, if |snap_position| is |SplitViewController::RIGHT|
  77. static WindowDraggingState ComputeWindowDraggingState(
  78. bool is_dragging,
  79. WindowDraggingState non_snap_state,
  80. SplitViewController::SnapPosition snap_position);
  81. explicit SplitViewDragIndicators(aura::Window* root_window);
  82. SplitViewDragIndicators(const SplitViewDragIndicators&) = delete;
  83. SplitViewDragIndicators& operator=(const SplitViewDragIndicators&) = delete;
  84. ~SplitViewDragIndicators();
  85. void SetDraggedWindow(aura::Window* dragged_window);
  86. void SetWindowDraggingState(WindowDraggingState window_dragging_state);
  87. void OnDisplayBoundsChanged();
  88. bool GetIndicatorTypeVisibilityForTesting(IndicatorType type) const;
  89. gfx::Rect GetLeftHighlightViewBounds() const;
  90. WindowDraggingState current_window_dragging_state() const {
  91. return current_window_dragging_state_;
  92. }
  93. private:
  94. FRIEND_TEST_ALL_PREFIXES(SplitViewDragIndicatorsTest,
  95. SplitViewDragIndicatorsWidgetReparenting);
  96. class RotatedImageLabelView;
  97. class SplitViewDragIndicatorsView;
  98. // The root content view of |widget_|.
  99. SplitViewDragIndicatorsView* indicators_view_ = nullptr;
  100. WindowDraggingState current_window_dragging_state_ =
  101. WindowDraggingState::kNoDrag;
  102. // The SplitViewDragIndicators widget. It covers the entire root window
  103. // and displays regions and text indicating where users should drag windows
  104. // enter split view.
  105. std::unique_ptr<views::Widget> widget_;
  106. };
  107. } // namespace ash
  108. #endif // ASH_WM_SPLITVIEW_SPLIT_VIEW_DRAG_INDICATORS_H_