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 separator position. | |
57 gfx::Rect GetLeftWindowBoundsInParent(aura::Window* window); | |
58 gfx::Rect GetRightWindowBoundsInParent(aura::Window* window); | |
59 gfx::Rect GetLeftWindowBoundsInScreen(aura::Window* window); | |
60 gfx::Rect GetRightWindowBoundsInScreen(aura::Window* window); | |
61 | |
62 void AddObserver(Observer* observer); | |
63 void RemoveObserver(Observer* observer); | |
64 | |
65 // aura::WindowObserver overrides: | |
66 void OnWindowDestroying(aura::Window* window) override; | |
67 | |
68 // ash::wm::WindowStateObserver overrides: | |
69 void OnPostWindowStateTypeChange(ash::wm::WindowState* window_state, | |
70 ash::wm::WindowStateType old_type) override; | |
71 | |
72 // wm::ActivationChangeObserver: | |
73 void OnWindowActivated(ActivationReason reason, | |
74 aura::Window* gained_active, | |
75 aura::Window* lost_active) override; | |
76 | |
77 // ShellObserver overrides: | |
78 void OnOverviewModeStarting() override; | |
79 void OnOverviewModeEnded() override; | |
80 | |
81 aura::Window* left_window() { return left_window_; } | |
82 aura::Window* right_window() { return right_window_; } | |
83 int separator_position() { return separator_position_; } | |
oshima
2017/06/14 05:45:47
const
xdai1
2017/06/15 22:11:42
Done.
| |
84 State state() { return state_; } | |
oshima
2017/06/14 05:45:47
const
xdai1
2017/06/15 22:11:42
Done.
| |
85 | |
86 private: | |
87 enum DefaultSnapPosition { LEFT, RIGHT }; | |
88 | |
89 // Ends the split view mode. | |
90 void EndSplitView(); | |
91 | |
92 // Stops observing |window| and restore its bounds. | |
93 void StopObservingAndRestore(aura::Window* window); | |
94 | |
95 // Notify observers that the split view state has been changed. | |
96 void NotifySplitViewStateChanged(State previous_state, State state); | |
97 | |
98 // The current left/right snapped window. | |
99 aura::Window* left_window_ = nullptr; | |
100 aura::Window* right_window_ = nullptr; | |
101 | |
102 // The x position of the separator between |left_window_| and |right_window_|. | |
103 int separator_position_ = -1; | |
104 | |
105 // Current snap state. | |
106 State state_ = NOSNAP; | |
107 | |
108 // The default snap position. It's decided by the first snapped window. If the | |
109 // first window was snapped left, then |default_snap_position_| equals LEFT, | |
110 // i.e., all the other windows will open snapped on the right side - And vice | |
111 // versa. | |
112 DefaultSnapPosition default_snap_position_ = LEFT; | |
113 | |
114 base::ObserverList<Observer> observers_; | |
115 | |
116 DISALLOW_COPY_AND_ASSIGN(SplitViewController); | |
117 }; | |
118 | |
119 } // namespace ash | |
120 | |
121 #endif // ASH_WM_SPLITSVIEW_SPLIT_VIEW_CONTROLLER_H_ | |
OLD | NEW |