Chromium Code Reviews| 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 { NOSNAP, LEFT_SNAPPED, RIGHT_SNAPPED, BOTH_SNAPPED }; | |
|
oshima
2017/06/28 17:36:36
nit: NO_SNAP
xdai1
2017/06/28 18:48:16
Done.
| |
| 29 | |
| 30 class Observer { | |
| 31 public: | |
| 32 // Called when split view state changed from |previous_state| to |state|. | |
| 33 virtual void OnSplitViewStateChanged( | |
| 34 SplitViewController::State previous_state, | |
| 35 SplitViewController::State state) {} | |
| 36 }; | |
| 37 | |
| 38 SplitViewController(); | |
| 39 ~SplitViewController() override; | |
| 40 | |
| 41 // Returns true if split view mode is supported. Currently the split view | |
| 42 // mode is only supported in maximized mode (tablet mode). | |
| 43 static bool ShouldAllowSplitView(); | |
| 44 | |
| 45 // Returns true if split view mode is active. | |
| 46 bool IsSplitViewModeActive() const; | |
| 47 | |
| 48 // Snaps window to left/right. | |
| 49 void SetLeftWindow(aura::Window* left_window); | |
| 50 void SetRightWindow(aura::Window* right_window); | |
| 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 overrides: | |
| 71 void OnWindowDestroying(aura::Window* window) override; | |
| 72 | |
| 73 // ash::wm::WindowStateObserver overrides: | |
| 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 overrides: | |
| 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 enum DefaultSnapPosition { LEFT, RIGHT }; | |
| 95 | |
| 96 // Ends the split view mode. | |
| 97 void EndSplitView(); | |
| 98 | |
| 99 // Stops observing |window|. | |
| 100 void StopObserving(aura::Window* window); | |
| 101 | |
| 102 // Notify observers that the split view state has been changed. | |
| 103 void NotifySplitViewStateChanged(State previous_state, State state); | |
| 104 | |
| 105 // Gets the window bounds according to the separator position. | |
| 106 gfx::Rect GetLeftWindowBoundsInParent(aura::Window* window); | |
| 107 gfx::Rect GetRightWindowBoundsInParent(aura::Window* window); | |
| 108 gfx::Rect GetLeftWindowBoundsInScreen(aura::Window* window); | |
| 109 gfx::Rect GetRightWindowBoundsInScreen(aura::Window* window); | |
| 110 | |
| 111 // The current left/right snapped window. | |
| 112 aura::Window* left_window_ = nullptr; | |
| 113 aura::Window* right_window_ = nullptr; | |
| 114 | |
| 115 // The x position of the divider between |left_window_| and |right_window_|. | |
|
oshima
2017/06/28 17:36:36
in the root window coordinates?
xdai1
2017/06/28 18:48:16
in screen coordinates. Added it here.
| |
| 116 int divider_position_ = -1; | |
| 117 | |
| 118 // Current snap state. | |
| 119 State state_ = NOSNAP; | |
| 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 DefaultSnapPosition 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 |