OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 ATHENA_WM_SPLIT_VIEW_CONTROLLER_H_ | 5 #ifndef ATHENA_WM_SPLIT_VIEW_CONTROLLER_H_ |
6 #define ATHENA_WM_SPLIT_VIEW_CONTROLLER_H_ | 6 #define ATHENA_WM_SPLIT_VIEW_CONTROLLER_H_ |
7 | 7 |
8 #include "athena/athena_export.h" | 8 #include "athena/athena_export.h" |
| 9 #include "athena/util/drag_handle.h" |
9 #include "athena/wm/bezel_controller.h" | 10 #include "athena/wm/bezel_controller.h" |
| 11 #include "athena/wm/public/window_manager_observer.h" |
10 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
11 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
12 | 14 |
13 namespace gfx { | 15 namespace gfx { |
14 class Rect; | 16 class Rect; |
15 class Transform; | 17 class Transform; |
16 } | 18 } |
17 | 19 |
| 20 namespace aura { |
| 21 class ScopedWindowTargeter; |
| 22 class Window; |
| 23 class WindowTargeter; |
| 24 } |
| 25 |
| 26 namespace views { |
| 27 class ViewTargeterDelegate; |
| 28 class Widget; |
| 29 } |
| 30 |
18 namespace athena { | 31 namespace athena { |
19 class WindowListProvider; | 32 class WindowListProvider; |
20 class SplitViewControllerTest; | 33 class SplitViewControllerTest; |
21 | 34 |
22 // Responsible for entering split view mode, exiting from split view mode, and | 35 // Responsible for entering split view mode, exiting from split view mode, and |
23 // laying out the windows in split view mode. | 36 // laying out the windows in split view mode. |
24 class ATHENA_EXPORT SplitViewController | 37 class ATHENA_EXPORT SplitViewController |
25 : public BezelController::ScrollDelegate { | 38 : public BezelController::ScrollDelegate, |
| 39 public DragHandleScrollDelegate, |
| 40 public WindowManagerObserver { |
26 public: | 41 public: |
27 SplitViewController(aura::Window* container, | 42 SplitViewController(aura::Window* container, |
28 WindowListProvider* window_list_provider); | 43 WindowListProvider* window_list_provider); |
29 | 44 |
30 virtual ~SplitViewController(); | 45 virtual ~SplitViewController(); |
31 | 46 |
32 bool IsSplitViewModeActive() const; | 47 bool IsSplitViewModeActive() const; |
33 | 48 |
34 // Activates split-view mode with |left| and |right| windows. If |left| and/or | 49 // Activates split-view mode with |left| and |right| windows. If |left| and/or |
35 // |right| is NULL, then the first window in the window-list (which is neither | 50 // |right| is NULL, then the first window in the window-list (which is neither |
36 // |left| nor |right|) is selected instead. | 51 // |left| nor |right|) is selected instead. |
37 void ActivateSplitMode(aura::Window* left, aura::Window* right); | 52 void ActivateSplitMode(aura::Window* left, aura::Window* right); |
38 | 53 |
39 // Resets the internal state to an inactive state. | 54 // Resets the internal state to an inactive state. |
40 void DeactivateSplitMode(); | 55 void DeactivateSplitMode(); |
41 | 56 |
42 // Replaces |window| in split-view mode with |replace_with|. Adjusts | 57 // Replaces |window| in split-view mode with |replace_with|. Adjusts |
43 // |replace_with|'s visibility, transform and bounds. Resets |window|'s | 58 // |replace_with|'s visibility, transform and bounds. Resets |window|'s |
44 // visibility and transform but does not change its bounds. | 59 // visibility and transform but does not change its bounds. |
45 void ReplaceWindow(aura::Window* window, | 60 void ReplaceWindow(aura::Window* window, |
46 aura::Window* replace_with); | 61 aura::Window* replace_with); |
47 | 62 |
48 // Returns the bounds that the left and right windows will have once split | 63 // Returns the bounds of the left and right parts of the |container_| based |
49 // view is active and they are done animating. If |left_window_| and | 64 // on the current value of |divider_position_|. |
50 // |right_window_| are still animating this may be different than their | 65 gfx::Rect GetLeftAreaBounds(); |
51 // current bounds. | 66 gfx::Rect GetRightAreaBounds(); |
52 gfx::Rect GetLeftTargetBounds(); | |
53 gfx::Rect GetRightTargetBounds(); | |
54 | 67 |
55 aura::Window* left_window() { return left_window_; } | 68 aura::Window* left_window() { return left_window_; } |
56 aura::Window* right_window() { return right_window_; } | 69 aura::Window* right_window() { return right_window_; } |
57 | 70 |
58 private: | 71 private: |
59 friend class SplitViewControllerTest; | 72 friend class SplitViewControllerTest; |
60 | 73 |
61 enum State { | 74 enum State { |
62 // Split View mode is not active. |left_window_| and |right_window| are | 75 // Split View mode is not active. |left_window_| and |right_window| are |
63 // NULL. | 76 // NULL. |
64 INACTIVE, | 77 INACTIVE, |
65 // Two windows |left_window_| and |right_window| are shown side by side and | 78 // Two windows |left_window_| and |right_window| are shown side by side and |
66 // there is a horizontal scroll in progress which is dragging the separator | 79 // there is a horizontal scroll in progress which is dragging the divider |
67 // between the two windows. | 80 // between the two windows. |
68 SCROLLING, | 81 SCROLLING, |
69 // Split View mode is active with |left_window_| and |right_window| showing | 82 // Split View mode is active with |left_window_| and |right_window| showing |
70 // side by side each occupying half the screen. No scroll in progress. | 83 // side by side each occupying half the screen. No scroll in progress. |
71 ACTIVE | 84 ACTIVE |
72 }; | 85 }; |
73 | 86 |
74 void SetState(State state); | 87 void SetState(State state); |
| 88 |
| 89 void InitializeDivider(); |
| 90 void HideDivider(); |
| 91 void ShowDivider(); |
| 92 |
75 void UpdateLayout(bool animate); | 93 void UpdateLayout(bool animate); |
76 | 94 |
77 void SetWindowTransforms(const gfx::Transform& left_transform, | 95 void SetWindowTransforms(const gfx::Transform& left_transform, |
78 const gfx::Transform& right_transform, | 96 const gfx::Transform& right_transform, |
| 97 const gfx::Transform& divider_transform, |
79 bool animate); | 98 bool animate); |
80 | 99 |
81 // Called when the animation initiated by SetWindowTransforms() completes. | 100 // Called when the animation initiated by SetWindowTransforms() completes. |
82 void OnAnimationCompleted(); | 101 void OnAnimationCompleted(); |
83 | 102 |
84 void UpdateSeparatorPositionFromScrollDelta(float delta); | 103 // Returns the default divider position for when the split view mode is |
| 104 // active and the divider is not being dragged. |
| 105 int GetDefaultDividerPosition(); |
85 | 106 |
86 // BezelController::ScrollDelegate: | 107 // BezelController::ScrollDelegate: |
87 virtual void ScrollBegin(BezelController::Bezel bezel, float delta) OVERRIDE; | 108 virtual void BezelScrollBegin(BezelController::Bezel bezel, |
88 virtual void ScrollEnd() OVERRIDE; | 109 float delta) OVERRIDE; |
89 virtual void ScrollUpdate(float delta) OVERRIDE; | 110 virtual void BezelScrollEnd() OVERRIDE; |
90 virtual bool CanScroll() OVERRIDE; | 111 virtual void BezelScrollUpdate(float delta) OVERRIDE; |
| 112 virtual bool BezelCanScroll() OVERRIDE; |
| 113 |
| 114 // DragHandleScrollDelegate: |
| 115 virtual void HandleScrollBegin(float delta) OVERRIDE; |
| 116 virtual void HandleScrollEnd() OVERRIDE; |
| 117 virtual void HandleScrollUpdate(float delta) OVERRIDE; |
| 118 virtual bool HandleCanScroll() OVERRIDE; |
| 119 |
| 120 // WindowManagerObserver: |
| 121 virtual void OnOverviewModeEnter() OVERRIDE; |
| 122 virtual void OnOverviewModeExit() OVERRIDE; |
| 123 virtual void OnSplitViewModeEnter() OVERRIDE; |
| 124 virtual void OnSplitViewModeExit() OVERRIDE; |
91 | 125 |
92 State state_; | 126 State state_; |
93 | 127 |
94 aura::Window* container_; | 128 aura::Window* container_; |
95 | 129 |
96 // Provider of the list of windows to cycle through. Not owned. | 130 // Provider of the list of windows to cycle through. Not owned. |
97 WindowListProvider* window_list_provider_; | 131 WindowListProvider* window_list_provider_; |
98 | 132 |
99 // Windows for the left and right activities shown in SCROLLING and ACTIVE | 133 // Windows for the left and right activities shown in SCROLLING and ACTIVE |
100 // states. In INACTIVE state these are NULL. | 134 // states. In INACTIVE state these are NULL. |
101 aura::Window* left_window_; | 135 aura::Window* left_window_; |
102 aura::Window* right_window_; | 136 aura::Window* right_window_; |
103 | 137 |
104 // Position of the separator between left_window_ and right_window_ in | 138 // X-Coordinate of the (center of the) divider between left_window_ and |
105 // container_ coordinates (along the x axis). | 139 // right_window_ in |container_| coordinates. |
106 int separator_position_; | 140 int divider_position_; |
| 141 |
| 142 // Meaningful only when state_ is SCROLLING. |
| 143 // X-Coordinate of the divider when the scroll started. |
| 144 int divider_scroll_start_position_; |
| 145 |
| 146 // Visually separates the windows and contains the drag handle. |
| 147 views::Widget* divider_widget_; |
| 148 |
| 149 // The drag handle which can be used when split view is active to exit the |
| 150 // split view mode. |
| 151 views::View* drag_handle_; |
| 152 |
| 153 scoped_ptr<aura::ScopedWindowTargeter> window_targeter_; |
| 154 scoped_ptr<views::ViewTargeterDelegate> view_targeter_delegate_; |
107 | 155 |
108 base::WeakPtrFactory<SplitViewController> weak_factory_; | 156 base::WeakPtrFactory<SplitViewController> weak_factory_; |
109 | 157 |
110 DISALLOW_COPY_AND_ASSIGN(SplitViewController); | 158 DISALLOW_COPY_AND_ASSIGN(SplitViewController); |
111 }; | 159 }; |
112 | 160 |
113 } // namespace athena | 161 } // namespace athena |
114 | 162 |
115 #endif // ATHENA_WM_SPLIT_VIEW_CONTROLLER_H_ | 163 #endif // ATHENA_WM_SPLIT_VIEW_CONTROLLER_H_ |
OLD | NEW |