OLD | NEW |
(Empty) | |
| 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 |
| 5 #ifndef ASH_WM_SPLITSVIEW_SPLIT_VIEW_CONTROLLER_H_ |
| 6 #define ASH_WM_SPLITSVIEW_SPLIT_VIEW_CONTROLLER_H_ |
| 7 |
| 8 #include "ash/ash_export.h" |
| 9 #include "ash/shell_observer.h" |
| 10 #include "ash/wm/window_state_observer.h" |
| 11 #include "base/macros.h" |
| 12 #include "base/observer_list.h" |
| 13 #include "ui/aura/window_observer.h" |
| 14 #include "ui/wm/public/activation_change_observer.h" |
| 15 |
| 16 namespace ash { |
| 17 |
| 18 class SplitViewControllerTest; |
| 19 |
| 20 // The controller for the split view. It snaps a window to left/right side of |
| 21 // the screen. It also observes the two snapped windows and decides when to exit |
| 22 // the split view mode. |
| 23 class ASH_EXPORT SplitViewController : public aura::WindowObserver, |
| 24 public ash::wm::WindowStateObserver, |
| 25 public ::wm::ActivationChangeObserver, |
| 26 public ShellObserver { |
| 27 public: |
| 28 enum State { NO_SNAP, LEFT_SNAPPED, RIGHT_SNAPPED, BOTH_SNAPPED }; |
| 29 enum SnapPosition { LEFT, RIGHT }; |
| 30 |
| 31 class Observer { |
| 32 public: |
| 33 // Called when split view state changed from |previous_state| to |state|. |
| 34 virtual void OnSplitViewStateChanged( |
| 35 SplitViewController::State previous_state, |
| 36 SplitViewController::State state) {} |
| 37 }; |
| 38 |
| 39 SplitViewController(); |
| 40 ~SplitViewController() override; |
| 41 |
| 42 // Returns true if split view mode is supported. Currently the split view |
| 43 // mode is only supported in maximized mode (tablet mode). |
| 44 static bool ShouldAllowSplitView(); |
| 45 |
| 46 // Returns true if split view mode is active. |
| 47 bool IsSplitViewModeActive() const; |
| 48 |
| 49 // Snaps window to left/right. |
| 50 void SnapWindow(aura::Window* window, SnapPosition snap_position); |
| 51 |
| 52 // Returns the default snapped window. It's the window that remains open until |
| 53 // the split mode ends. It's decided by |default_snap_position_|. E.g., If |
| 54 // |default_snap_position_| equals LEFT, then the default snapped window is |
| 55 // |left_window_|. All the other window will open on the right side. |
| 56 aura::Window* GetDefaultSnappedWindow(); |
| 57 |
| 58 // Gets the window bounds according to the snap state |snap_state| and the |
| 59 // separator position |separator_position_|. |
| 60 gfx::Rect GetSnappedWindowBoundsInParent(aura::Window* window, |
| 61 State snap_state); |
| 62 gfx::Rect GetSnappedWindowBoundsInScreen(aura::Window* window, |
| 63 State snap_state); |
| 64 gfx::Rect GetDisplayWorkAreaBoundsInParent(aura::Window* window); |
| 65 gfx::Rect GetDisplayWorkAreaBoundsInScreen(aura::Window* window); |
| 66 |
| 67 void AddObserver(Observer* observer); |
| 68 void RemoveObserver(Observer* observer); |
| 69 |
| 70 // aura::WindowObserver: |
| 71 void OnWindowDestroying(aura::Window* window) override; |
| 72 |
| 73 // ash::wm::WindowStateObserver: |
| 74 void OnPostWindowStateTypeChange(ash::wm::WindowState* window_state, |
| 75 ash::wm::WindowStateType old_type) override; |
| 76 |
| 77 // wm::ActivationChangeObserver: |
| 78 void OnWindowActivated(ActivationReason reason, |
| 79 aura::Window* gained_active, |
| 80 aura::Window* lost_active) override; |
| 81 |
| 82 // ShellObserver: |
| 83 void OnOverviewModeStarting() override; |
| 84 void OnOverviewModeEnded() override; |
| 85 |
| 86 aura::Window* left_window() { return left_window_; } |
| 87 aura::Window* right_window() { return right_window_; } |
| 88 int divider_position() const { return divider_position_; } |
| 89 State state() const { return state_; } |
| 90 |
| 91 private: |
| 92 friend class SplitViewControllerTest; |
| 93 |
| 94 // Ends the split view mode. |
| 95 void EndSplitView(); |
| 96 |
| 97 // Starts/Stops observing |window|. |
| 98 void StartObserving(aura::Window* window); |
| 99 void StopObserving(aura::Window* window); |
| 100 |
| 101 // Notify observers that the split view state has been changed. |
| 102 void NotifySplitViewStateChanged(State previous_state, State state); |
| 103 |
| 104 // Gets the window bounds according to the separator position. |
| 105 gfx::Rect GetLeftWindowBoundsInParent(aura::Window* window); |
| 106 gfx::Rect GetRightWindowBoundsInParent(aura::Window* window); |
| 107 gfx::Rect GetLeftWindowBoundsInScreen(aura::Window* window); |
| 108 gfx::Rect GetRightWindowBoundsInScreen(aura::Window* window); |
| 109 |
| 110 // The current left/right snapped window. |
| 111 aura::Window* left_window_ = nullptr; |
| 112 aura::Window* right_window_ = nullptr; |
| 113 |
| 114 // The x position of the divider between |left_window_| and |right_window_| in |
| 115 // screen coordinates. |
| 116 int divider_position_ = -1; |
| 117 |
| 118 // Current snap state. |
| 119 State state_ = NO_SNAP; |
| 120 |
| 121 // The default snap position. It's decided by the first snapped window. If the |
| 122 // first window was snapped left, then |default_snap_position_| equals LEFT, |
| 123 // i.e., all the other windows will open snapped on the right side - and vice |
| 124 // versa. |
| 125 SnapPosition default_snap_position_ = LEFT; |
| 126 |
| 127 base::ObserverList<Observer> observers_; |
| 128 |
| 129 DISALLOW_COPY_AND_ASSIGN(SplitViewController); |
| 130 }; |
| 131 |
| 132 } // namespace ash |
| 133 |
| 134 #endif // ASH_WM_SPLITSVIEW_SPLIT_VIEW_CONTROLLER_H_ |
OLD | NEW |