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