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 #include "athena/wm/split_view_controller.h" | 5 #include "athena/wm/split_view_controller.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "athena/wm/public/window_list_provider.h" | 9 #include "athena/wm/public/window_list_provider.h" |
10 #include "athena/wm/public/window_manager.h" | 10 #include "athena/wm/public/window_manager.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 CHECK(IsSplitViewModeActive()); | 105 CHECK(IsSplitViewModeActive()); |
106 CHECK(replace_with); | 106 CHECK(replace_with); |
107 CHECK(window == left_window_ || window == right_window_); | 107 CHECK(window == left_window_ || window == right_window_); |
108 CHECK(replace_with != left_window_ && replace_with != right_window_); | 108 CHECK(replace_with != left_window_ && replace_with != right_window_); |
109 #if !defined(NDEBUG) | 109 #if !defined(NDEBUG) |
110 aura::Window::Windows windows = window_list_provider_->GetWindowList(); | 110 aura::Window::Windows windows = window_list_provider_->GetWindowList(); |
111 DCHECK(std::find(windows.begin(), windows.end(), replace_with) != | 111 DCHECK(std::find(windows.begin(), windows.end(), replace_with) != |
112 windows.end()); | 112 windows.end()); |
113 #endif | 113 #endif |
114 | 114 |
115 replace_with->SetBounds(window->bounds()); | |
116 replace_with->SetTransform(gfx::Transform()); | |
117 if (window == left_window_) | 115 if (window == left_window_) |
118 left_window_ = replace_with; | 116 left_window_ = replace_with; |
119 else | 117 else |
120 right_window_ = replace_with; | 118 right_window_ = replace_with; |
121 wm::ActivateWindow(replace_with); | 119 wm::ActivateWindow(replace_with); |
120 UpdateLayout(false); | |
122 window->SetTransform(gfx::Transform()); | 121 window->SetTransform(gfx::Transform()); |
123 } | 122 } |
124 | 123 |
125 void SplitViewController::DeactivateSplitMode() { | 124 void SplitViewController::DeactivateSplitMode() { |
126 CHECK_NE(SCROLLING, state_); | 125 CHECK_NE(SCROLLING, state_); |
127 state_ = INACTIVE; | 126 state_ = INACTIVE; |
127 UpdateLayout(false); | |
128 left_window_ = right_window_ = NULL; | 128 left_window_ = right_window_ = NULL; |
129 } | 129 } |
130 | 130 |
131 gfx::Rect SplitViewController::GetLeftTargetBounds() { | 131 gfx::Rect SplitViewController::GetLeftTargetBounds() { |
132 gfx::Rect work_area = | 132 gfx::Rect work_area = |
133 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area(); | 133 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area(); |
134 return gfx::Rect(0, 0, container_->bounds().width() / 2, work_area.height()); | 134 return gfx::Rect(0, 0, container_->bounds().width() / 2, work_area.height()); |
135 } | 135 } |
136 | 136 |
137 gfx::Rect SplitViewController::GetRightTargetBounds() { | 137 gfx::Rect SplitViewController::GetRightTargetBounds() { |
138 gfx::Rect work_area = | 138 gfx::Rect work_area = |
139 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area(); | 139 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area(); |
140 int container_width = container_->bounds().width(); | 140 int container_width = container_->bounds().width(); |
141 return gfx::Rect( | 141 return gfx::Rect( |
142 container_width / 2, 0, container_width / 2, work_area.height()); | 142 container_width / 2, 0, container_width / 2, work_area.height()); |
143 } | 143 } |
144 | 144 |
145 void SplitViewController::UpdateLayout(bool animate) { | 145 void SplitViewController::UpdateLayout(bool animate) { |
146 if (!left_window_) | 146 if (!left_window_) |
147 return; | 147 return; |
148 CHECK(right_window_); | 148 CHECK(right_window_); |
149 gfx::Transform left_transform; | |
150 gfx::Transform right_transform; | |
151 int container_width = container_->GetBoundsInScreen().width(); | |
152 if (state_ == ACTIVE) { | 149 if (state_ == ACTIVE) { |
153 // Windows should be resized via an animation when entering the ACTIVE | 150 if (animate) { |
154 // state. | 151 gfx::Transform left_transform = GetTargetTransformForBoundsAnimation( |
155 CHECK(animate); | 152 left_window_->bounds(), GetLeftTargetBounds()); |
156 // We scale the windows here, but when the animation finishes, we reset | 153 gfx::Transform right_transform = GetTargetTransformForBoundsAnimation( |
157 // the scaling and update the window bounds to the proper size - see | 154 right_window_->bounds(), GetRightTargetBounds()); |
158 // OnAnimationCompleted(). | 155 SetWindowTransforms(left_transform, right_transform, true); |
159 left_transform = GetTargetTransformForBoundsAnimation( | 156 } else { |
160 left_window_->bounds(), GetLeftTargetBounds()); | 157 left_window_->SetBounds(GetLeftTargetBounds()); |
161 right_transform = GetTargetTransformForBoundsAnimation( | 158 right_window_->SetBounds(GetRightTargetBounds()); |
162 right_window_->bounds(), GetRightTargetBounds()); | 159 SetWindowTransforms(gfx::Transform(), gfx::Transform(), false); |
160 } | |
161 } else if (state_ == INACTIVE && !animate) { | |
162 SetWindowTransforms(gfx::Transform(), gfx::Transform(), false); | |
163 } else { | 163 } else { |
164 left_transform.Translate(separator_position_ - container_width, 0); | 164 gfx::Transform left_transform; |
165 left_transform.Translate(separator_position_ - container_->bounds().width(), | |
166 0); | |
167 gfx::Transform right_transform; | |
165 right_transform.Translate(separator_position_, 0); | 168 right_transform.Translate(separator_position_, 0); |
166 } | 169 SetWindowTransforms(left_transform, right_transform, animate); |
167 left_window_->Show(); | |
168 right_window_->Show(); | |
169 SetWindowTransform(left_window_, left_transform, animate); | |
170 SetWindowTransform(right_window_, right_transform, animate); | |
171 } | |
172 | |
173 void SplitViewController::SetWindowTransform(aura::Window* window, | |
174 const gfx::Transform& transform, | |
175 bool animate) { | |
176 if (animate) { | |
177 scoped_refptr<ui::LayerAnimator> animator = window->layer()->GetAnimator(); | |
178 ui::ScopedLayerAnimationSettings settings(animator); | |
179 settings.SetPreemptionStrategy( | |
180 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
181 settings.AddObserver(new ui::ClosureAnimationObserver( | |
182 base::Bind(&SplitViewController::OnAnimationCompleted, | |
183 weak_factory_.GetWeakPtr(), | |
184 window))); | |
185 window->SetTransform(transform); | |
186 } else { | |
187 window->SetTransform(transform); | |
188 } | 170 } |
189 } | 171 } |
190 | 172 |
191 void SplitViewController::OnAnimationCompleted(aura::Window* window) { | 173 void SplitViewController::SetWindowTransforms( |
174 const gfx::Transform& left_transform, | |
175 const gfx::Transform& right_transform, | |
176 bool animate) { | |
177 if (animate) { | |
178 ui::ScopedLayerAnimationSettings left_settings( | |
179 left_window_->layer()->GetAnimator()); | |
180 left_settings.SetPreemptionStrategy( | |
181 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
182 left_window_->SetTransform(left_transform); | |
183 | |
184 ui::ScopedLayerAnimationSettings right_settings( | |
185 right_window_->layer()->GetAnimator()); | |
186 right_settings.SetPreemptionStrategy( | |
187 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
188 right_settings.AddObserver(new ui::ClosureAnimationObserver( | |
189 base::Bind(&SplitViewController::OnAnimationCompleted, | |
190 weak_factory_.GetWeakPtr()))); | |
191 right_window_->SetTransform(right_transform); | |
192 } else { | |
193 left_window_->SetTransform(left_transform); | |
194 right_window_->SetTransform(right_transform); | |
195 } | |
196 } | |
197 | |
198 void SplitViewController::OnAnimationCompleted() { | |
192 // Animation can be cancelled when deactivated. | 199 // Animation can be cancelled when deactivated. |
193 if (left_window_ == NULL) | 200 if (left_window_ == NULL) |
194 return; | 201 return; |
195 DCHECK(window == left_window_ || window == right_window_); | 202 UpdateLayout(false); |
196 if (state_ == ACTIVE) { | 203 |
197 window->SetTransform(gfx::Transform()); | 204 if (state_ == INACTIVE) { |
198 if (window == left_window_) | 205 left_window_ = NULL; |
199 left_window_->SetBounds(GetLeftTargetBounds()); | 206 right_window_ = NULL; |
200 else | |
201 right_window_->SetBounds(GetRightTargetBounds()); | |
202 } else { | |
203 int container_width = container_->bounds().width(); | |
204 window->SetTransform(gfx::Transform()); | |
205 if (window == left_window_) { | |
206 if (separator_position_ == 0) | |
207 left_window_->Hide(); | |
pkotwicz
2014/08/28 22:03:45
I couldn't figure out why the window is hidden. Ac
sadrul
2014/08/29 13:31:30
I believe the idea here is to hide the window that
pkotwicz
2014/08/29 14:44:45
I have brought back the 'hide window' functionalit
sadrul
2014/08/29 15:06:02
We do hide non-visible windows in some cases (e.g.
pkotwicz
2014/08/29 18:07:42
I have modified the unit test as requested
| |
208 if (state_ == INACTIVE) | |
209 left_window_ = NULL; | |
210 } else { | |
211 if (separator_position_ == container_width) | |
212 right_window_->Hide(); | |
213 if (state_ == INACTIVE) | |
214 right_window_ = NULL; | |
215 } | |
216 } | 207 } |
217 } | 208 } |
218 | 209 |
219 void SplitViewController::UpdateSeparatorPositionFromScrollDelta(float delta) { | 210 void SplitViewController::UpdateSeparatorPositionFromScrollDelta(float delta) { |
220 gfx::Screen* screen = gfx::Screen::GetScreenFor(container_); | 211 gfx::Screen* screen = gfx::Screen::GetScreenFor(container_); |
221 const gfx::Rect& display_bounds = | 212 const gfx::Rect& display_bounds = |
222 screen->GetDisplayNearestWindow(container_).bounds(); | 213 screen->GetDisplayNearestWindow(container_).bounds(); |
223 gfx::Rect container_bounds = container_->GetBoundsInScreen(); | 214 gfx::Rect container_bounds = container_->GetBoundsInScreen(); |
224 separator_position_ = | 215 separator_position_ = |
225 delta > 0 ? ((int)delta) + display_bounds.x() - container_bounds.x() | 216 delta > 0 ? ((int)delta) + display_bounds.x() - container_bounds.x() |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 } | 279 } |
289 | 280 |
290 bool SplitViewController::CanScroll() { | 281 bool SplitViewController::CanScroll() { |
291 // TODO(mfomitchev): return false in vertical orientation, in full screen. | 282 // TODO(mfomitchev): return false in vertical orientation, in full screen. |
292 bool result = (!IsSplitViewModeActive() && | 283 bool result = (!IsSplitViewModeActive() && |
293 window_list_provider_->GetWindowList().size() >= 2); | 284 window_list_provider_->GetWindowList().size() >= 2); |
294 return result; | 285 return result; |
295 } | 286 } |
296 | 287 |
297 } // namespace athena | 288 } // namespace athena |
OLD | NEW |