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