Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(422)

Side by Side Diff: ash/wm/splitview/split_view_controller.h

Issue 2960843004: CrOS Tablet Window management - Split Screen part I (Closed)
Patch Set: nit. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
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:
varkha 2017/06/30 14:29:35 nit: feel free to ignore here and below - I think
xdai1 2017/07/05 20:18:23 Done.
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_| in
116 // screen coordinates.
117 int divider_position_ = -1;
118
119 // Current snap state.
120 State state_ = NO_SNAP;
121
122 // The default snap position. It's decided by the first snapped window. If the
123 // first window was snapped left, then |default_snap_position_| equals LEFT,
124 // i.e., all the other windows will open snapped on the right side - And vice
varkha 2017/06/30 14:29:35 nit: And -> and
xdai1 2017/07/05 20:18:23 Done.
125 // versa.
126 DefaultSnapPosition default_snap_position_ = LEFT;
127
128 base::ObserverList<Observer> observers_;
129
130 DISALLOW_COPY_AND_ASSIGN(SplitViewController);
131 };
132
133 } // namespace ash
134
135 #endif // ASH_WM_SPLITSVIEW_SPLIT_VIEW_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698