| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef ASH_WM_SPLITSVIEW_SPLIT_VIEW_CONTROLLER_H_ | 5 #ifndef ASH_WM_SPLITSVIEW_SPLIT_VIEW_CONTROLLER_H_ |
| 6 #define ASH_WM_SPLITSVIEW_SPLIT_VIEW_CONTROLLER_H_ | 6 #define ASH_WM_SPLITSVIEW_SPLIT_VIEW_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
| 9 #include "ash/shell_observer.h" | 9 #include "ash/shell_observer.h" |
| 10 #include "ash/wm/window_state_observer.h" | 10 #include "ash/wm/window_state_observer.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
| 13 #include "ui/aura/window_observer.h" | 13 #include "ui/aura/window_observer.h" |
| 14 #include "ui/wm/public/activation_change_observer.h" | 14 #include "ui/wm/public/activation_change_observer.h" |
| 15 | 15 |
| 16 namespace ash { | 16 namespace ash { |
| 17 | 17 |
| 18 class SplitViewControllerTest; | 18 class SplitViewControllerTest; |
| 19 | 19 |
| 20 // The controller for the split view. It snaps a window to left/right side of | 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 | 21 // the screen. It also observes the two snapped windows and decides when to exit |
| 22 // the split view mode. | 22 // the split view mode. |
| 23 class ASH_EXPORT SplitViewController : public aura::WindowObserver, | 23 class ASH_EXPORT SplitViewController : public aura::WindowObserver, |
| 24 public ash::wm::WindowStateObserver, | 24 public ash::wm::WindowStateObserver, |
| 25 public ::wm::ActivationChangeObserver, | 25 public ::wm::ActivationChangeObserver, |
| 26 public ShellObserver { | 26 public ShellObserver { |
| 27 public: | 27 public: |
| 28 enum State { NO_SNAP, LEFT_SNAPPED, RIGHT_SNAPPED, BOTH_SNAPPED }; | 28 enum State { NO_SNAP, LEFT_SNAPPED, RIGHT_SNAPPED, BOTH_SNAPPED }; |
| 29 enum SnapPosition { LEFT, RIGHT }; | 29 enum SnapPosition { NONE, LEFT, RIGHT }; |
| 30 | 30 |
| 31 class Observer { | 31 class Observer { |
| 32 public: | 32 public: |
| 33 // Called when split view state changed from |previous_state| to |state|. | 33 // Called when split view state changed from |previous_state| to |state|. |
| 34 virtual void OnSplitViewStateChanged( | 34 virtual void OnSplitViewStateChanged( |
| 35 SplitViewController::State previous_state, | 35 SplitViewController::State previous_state, |
| 36 SplitViewController::State state) {} | 36 SplitViewController::State state) {} |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 SplitViewController(); | 39 SplitViewController(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 51 | 51 |
| 52 // Returns the default snapped window. It's the window that remains open until | 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 | 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 | 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. | 55 // |left_window_|. All the other window will open on the right side. |
| 56 aura::Window* GetDefaultSnappedWindow(); | 56 aura::Window* GetDefaultSnappedWindow(); |
| 57 | 57 |
| 58 // Gets the window bounds according to the snap state |snap_state| and the | 58 // Gets the window bounds according to the snap state |snap_state| and the |
| 59 // separator position |separator_position_|. | 59 // separator position |separator_position_|. |
| 60 gfx::Rect GetSnappedWindowBoundsInParent(aura::Window* window, | 60 gfx::Rect GetSnappedWindowBoundsInParent(aura::Window* window, |
| 61 State snap_state); | 61 SnapPosition snap_position); |
| 62 gfx::Rect GetSnappedWindowBoundsInScreen(aura::Window* window, | 62 gfx::Rect GetSnappedWindowBoundsInScreen(aura::Window* window, |
| 63 State snap_state); | 63 SnapPosition snap_position); |
| 64 gfx::Rect GetDisplayWorkAreaBoundsInParent(aura::Window* window); | 64 gfx::Rect GetDisplayWorkAreaBoundsInParent(aura::Window* window); |
| 65 gfx::Rect GetDisplayWorkAreaBoundsInScreen(aura::Window* window); | 65 gfx::Rect GetDisplayWorkAreaBoundsInScreen(aura::Window* window); |
| 66 | 66 |
| 67 void AddObserver(Observer* observer); | 67 void AddObserver(Observer* observer); |
| 68 void RemoveObserver(Observer* observer); | 68 void RemoveObserver(Observer* observer); |
| 69 | 69 |
| 70 // aura::WindowObserver: | 70 // aura::WindowObserver: |
| 71 void OnWindowDestroying(aura::Window* window) override; | 71 void OnWindowDestroying(aura::Window* window) override; |
| 72 | 72 |
| 73 // ash::wm::WindowStateObserver: | 73 // ash::wm::WindowStateObserver: |
| 74 void OnPostWindowStateTypeChange(ash::wm::WindowState* window_state, | 74 void OnPostWindowStateTypeChange(ash::wm::WindowState* window_state, |
| 75 ash::wm::WindowStateType old_type) override; | 75 ash::wm::WindowStateType old_type) override; |
| 76 | 76 |
| 77 // wm::ActivationChangeObserver: | 77 // wm::ActivationChangeObserver: |
| 78 void OnWindowActivated(ActivationReason reason, | 78 void OnWindowActivated(ActivationReason reason, |
| 79 aura::Window* gained_active, | 79 aura::Window* gained_active, |
| 80 aura::Window* lost_active) override; | 80 aura::Window* lost_active) override; |
| 81 | 81 |
| 82 // ShellObserver: | 82 // ShellObserver: |
| 83 void OnOverviewModeStarting() override; | 83 void OnOverviewModeStarting() override; |
| 84 void OnOverviewModeEnded() override; | 84 void OnOverviewModeEnded() override; |
| 85 | 85 |
| 86 aura::Window* left_window() { return left_window_; } | 86 aura::Window* left_window() { return left_window_; } |
| 87 aura::Window* right_window() { return right_window_; } | 87 aura::Window* right_window() { return right_window_; } |
| 88 int divider_position() const { return divider_position_; } | 88 int divider_position() const { return divider_position_; } |
| 89 State state() const { return state_; } | 89 State state() const { return state_; } |
| 90 SnapPosition default_snap_position() const { return default_snap_position_; } |
| 90 | 91 |
| 91 private: | 92 private: |
| 92 friend class SplitViewControllerTest; | 93 friend class SplitViewControllerTest; |
| 93 | 94 |
| 94 // Ends the split view mode. | 95 // Ends the split view mode. |
| 95 void EndSplitView(); | 96 void EndSplitView(); |
| 96 | 97 |
| 97 // Starts/Stops observing |window|. | 98 // Starts/Stops observing |window|. |
| 98 void StartObserving(aura::Window* window); | 99 void StartObserving(aura::Window* window); |
| 99 void StopObserving(aura::Window* window); | 100 void StopObserving(aura::Window* window); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 115 // screen coordinates. | 116 // screen coordinates. |
| 116 int divider_position_ = -1; | 117 int divider_position_ = -1; |
| 117 | 118 |
| 118 // Current snap state. | 119 // Current snap state. |
| 119 State state_ = NO_SNAP; | 120 State state_ = NO_SNAP; |
| 120 | 121 |
| 121 // The default snap position. It's decided by the first snapped window. If the | 122 // 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 // 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 // i.e., all the other windows will open snapped on the right side - and vice |
| 124 // versa. | 125 // versa. |
| 125 SnapPosition default_snap_position_ = LEFT; | 126 SnapPosition default_snap_position_ = NONE; |
| 126 | 127 |
| 127 base::ObserverList<Observer> observers_; | 128 base::ObserverList<Observer> observers_; |
| 128 | 129 |
| 129 DISALLOW_COPY_AND_ASSIGN(SplitViewController); | 130 DISALLOW_COPY_AND_ASSIGN(SplitViewController); |
| 130 }; | 131 }; |
| 131 | 132 |
| 132 } // namespace ash | 133 } // namespace ash |
| 133 | 134 |
| 134 #endif // ASH_WM_SPLITSVIEW_SPLIT_VIEW_CONTROLLER_H_ | 135 #endif // ASH_WM_SPLITSVIEW_SPLIT_VIEW_CONTROLLER_H_ |
| OLD | NEW |