split_view_utils.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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_UTILS_H_
  5. #define ASH_WM_SPLITVIEW_SPLIT_VIEW_UTILS_H_
  6. #include <vector>
  7. #include "ash/ash_export.h"
  8. #include "ash/wm/splitview/split_view_controller.h"
  9. #include "third_party/abseil-cpp/absl/types/optional.h"
  10. #include "ui/aura/window_observer.h"
  11. #include "ui/compositor/layer_animation_observer.h"
  12. #include "ui/gfx/geometry/transform.h"
  13. namespace aura {
  14. class Window;
  15. } // namespace aura
  16. namespace ui {
  17. class Layer;
  18. } // namespace ui
  19. namespace ash {
  20. // Enum of the different splitview mode animations. Sorted by property
  21. // (opacity/transform) and then alphabetically.
  22. enum SplitviewAnimationType {
  23. // Used to fade in and out the highlights on either side which indicate where
  24. // to drag a selector item.
  25. SPLITVIEW_ANIMATION_HIGHLIGHT_FADE_IN,
  26. SPLITVIEW_ANIMATION_HIGHLIGHT_FADE_IN_CANNOT_SNAP,
  27. SPLITVIEW_ANIMATION_HIGHLIGHT_FADE_OUT,
  28. // Used to fade in and out the other highlight. There are normally two
  29. // highlights, one on each side. When entering a state with a preview
  30. // highlight, one highlight is the preview highlight, and the other highlight
  31. // is the other highlight.
  32. SPLITVIEW_ANIMATION_OTHER_HIGHLIGHT_FADE_IN,
  33. SPLITVIEW_ANIMATION_OTHER_HIGHLIGHT_FADE_IN_CANNOT_SNAP,
  34. SPLITVIEW_ANIMATION_OTHER_HIGHLIGHT_FADE_OUT,
  35. // Used to fade in and out the label on the overview item which warns users
  36. // the item cannot be snapped. The label appears on the overview item after
  37. // another window has been snapped.
  38. SPLITVIEW_ANIMATION_OVERVIEW_ITEM_FADE_IN,
  39. SPLITVIEW_ANIMATION_OVERVIEW_ITEM_FADE_OUT,
  40. // Used to fade in and out the preview area highlight which indicates the
  41. // bounds of the window that is about to get snapped.
  42. SPLITVIEW_ANIMATION_PREVIEW_AREA_FADE_IN,
  43. SPLITVIEW_ANIMATION_PREVIEW_AREA_FADE_OUT,
  44. // Used to fade in and out the labels which appear on either side of overview
  45. // mode when a overview item is selected. They indicate where to drag the
  46. // selector item if it is snappable, or if an item cannot be snapped.
  47. SPLITVIEW_ANIMATION_TEXT_FADE_IN,
  48. SPLITVIEW_ANIMATION_TEXT_FADE_OUT,
  49. // Used when the text fades in or out with the highlights, as opposed to
  50. // fading in when the highlights change bounds. Has slightly different
  51. // animation values.
  52. SPLITVIEW_ANIMATION_TEXT_FADE_IN_WITH_HIGHLIGHT,
  53. SPLITVIEW_ANIMATION_TEXT_FADE_OUT_WITH_HIGHLIGHT,
  54. // Used to slide in and out the other highlight.
  55. SPLITVIEW_ANIMATION_OTHER_HIGHLIGHT_SLIDE_IN,
  56. SPLITVIEW_ANIMATION_OTHER_HIGHLIGHT_SLIDE_OUT,
  57. // Used to slide in and out the text label on the other highlight.
  58. SPLITVIEW_ANIMATION_OTHER_HIGHLIGHT_TEXT_SLIDE_IN,
  59. SPLITVIEW_ANIMATION_OTHER_HIGHLIGHT_TEXT_SLIDE_OUT,
  60. // Used to animate the inset of the preview area to nothing.
  61. SPLITVIEW_ANIMATION_PREVIEW_AREA_NIX_INSET,
  62. // Used to slide in and out the preview area highlight.
  63. SPLITVIEW_ANIMATION_PREVIEW_AREA_SLIDE_IN,
  64. SPLITVIEW_ANIMATION_PREVIEW_AREA_SLIDE_OUT,
  65. // Used to slide in and out the text label on the preview area highlight.
  66. SPLITVIEW_ANIMATION_PREVIEW_AREA_TEXT_SLIDE_IN,
  67. SPLITVIEW_ANIMATION_PREVIEW_AREA_TEXT_SLIDE_OUT,
  68. // Used to apply window transform on the selector item after it gets snapped
  69. // or on the dragged window after the drag ends.
  70. SPLITVIEW_ANIMATION_SET_WINDOW_TRANSFORM,
  71. };
  72. // This class observes the window transform animation and relayout the window's
  73. // transient bubble dialogs when animation is completed. This is needed in some
  74. // splitview and overview cases as in splitview or overview, the window can have
  75. // an un-identity transform in place when its bounds changed. And when this
  76. // happens, its transient bubble dialogs won't have the correct bounds as the
  77. // bounds are calculated based on the transformed window bounds. We'll need to
  78. // manually relayout the bubble dialogs after the window's transform reset to
  79. // the identity transform so that the bubble dialogs can have correct bounds.
  80. class ASH_EXPORT WindowTransformAnimationObserver
  81. : public ui::ImplicitAnimationObserver,
  82. public aura::WindowObserver {
  83. public:
  84. explicit WindowTransformAnimationObserver(aura::Window* window);
  85. ~WindowTransformAnimationObserver() override;
  86. // ui::ImplicitAnimationObserver:
  87. void OnImplicitAnimationsCompleted() override;
  88. // aura::WindowObserver:
  89. void OnWindowDestroying(aura::Window* window) override;
  90. private:
  91. aura::Window* const window_;
  92. WindowTransformAnimationObserver(const WindowTransformAnimationObserver&) =
  93. delete;
  94. WindowTransformAnimationObserver& operator=(
  95. const WindowTransformAnimationObserver&) = delete;
  96. };
  97. // Animates |layer|'s opacity based on |type|.
  98. void DoSplitviewOpacityAnimation(ui::Layer* layer, SplitviewAnimationType type);
  99. // Animates |layer|'s transform based on |type|.
  100. void DoSplitviewTransformAnimation(
  101. ui::Layer* layer,
  102. SplitviewAnimationType type,
  103. const gfx::Transform& target_transform,
  104. const std::vector<ui::ImplicitAnimationObserver*>& animation_observers);
  105. // Animates |layer|'s clip rect based on |type|.
  106. void DoSplitviewClipRectAnimation(
  107. ui::Layer* layer,
  108. SplitviewAnimationType type,
  109. const gfx::Rect& target_clip_rect,
  110. std::unique_ptr<ui::ImplicitAnimationObserver> animation_observer);
  111. // Restores split view and overview based on the current split view's state.
  112. // If |refresh_snapped_windows| is true, it will update the left and right
  113. // snapped windows based on the MRU windows snapped states.
  114. void MaybeRestoreSplitView(bool refresh_snapped_windows);
  115. // Returns true if split view mode is supported.
  116. ASH_EXPORT bool ShouldAllowSplitView();
  117. // Displays a toast notifying users the application selected for split view is
  118. // not compatible.
  119. void ShowAppCannotSnapToast();
  120. // Calculates the snap position for a dragged window at |location_in_screen|,
  121. // ignoring any properties of the window itself. The |root_window| is of the
  122. // current screen. |initial_location_in_screen| is the location at drag start if
  123. // the drag began in |root_window|, and is empty otherwise. To be snappable
  124. // (meaning the return value is not |SplitViewController::NONE|),
  125. // |location_in_screen| must be either inside |snap_distance_from_edge| or
  126. // dragged toward the edge for at least |minimum_drag_distance| distance until
  127. // it's dragged into a suitable edge of the work area of |root_window| (i.e.,
  128. // |horizontal_edge_inset| if dragged horizontally to snap, or
  129. // |vertical_edge_inset| if dragged vertically).
  130. SplitViewController::SnapPosition GetSnapPositionForLocation(
  131. aura::Window* root_window,
  132. const gfx::Point& location_in_screen,
  133. const absl::optional<gfx::Point>& initial_location_in_screen,
  134. int snap_distance_from_edge,
  135. int minimum_drag_distance,
  136. int horizontal_edge_inset,
  137. int vertical_edge_inset);
  138. // Returns the desired snap position. To be snappable, |window| must 1)
  139. // satisfy |SplitViewController::CanSnapWindow| for |root_window|, and
  140. // 2) be snappable according to |GetSnapPositionForLocation| above.
  141. // |initial_location_in_screen| is the window location at drag start in
  142. // its initial window. Otherwise, the arguments are the same as above.
  143. ASH_EXPORT SplitViewController::SnapPosition GetSnapPosition(
  144. aura::Window* root_window,
  145. aura::Window* window,
  146. const gfx::Point& location_in_screen,
  147. const gfx::Point& initial_location_in_screen,
  148. int snap_distance_from_edge,
  149. int minimum_drag_distance,
  150. int horizontal_edge_inset,
  151. int vertical_edge_inset);
  152. } // namespace ash
  153. #endif // ASH_WM_SPLITVIEW_SPLIT_VIEW_UTILS_H_