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()); |
| 122 window->Hide(); |
123 } | 123 } |
124 | 124 |
125 void SplitViewController::DeactivateSplitMode() { | 125 void SplitViewController::DeactivateSplitMode() { |
126 CHECK_NE(SCROLLING, state_); | 126 CHECK_EQ(ACTIVE, state_); |
127 state_ = INACTIVE; | 127 state_ = INACTIVE; |
| 128 UpdateLayout(false); |
128 left_window_ = right_window_ = NULL; | 129 left_window_ = right_window_ = NULL; |
129 } | 130 } |
130 | 131 |
131 gfx::Rect SplitViewController::GetLeftTargetBounds() { | 132 gfx::Rect SplitViewController::GetLeftTargetBounds() { |
132 gfx::Rect work_area = | 133 gfx::Rect work_area = |
133 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area(); | 134 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area(); |
134 return gfx::Rect(0, 0, container_->bounds().width() / 2, work_area.height()); | 135 return gfx::Rect(0, 0, container_->bounds().width() / 2, work_area.height()); |
135 } | 136 } |
136 | 137 |
137 gfx::Rect SplitViewController::GetRightTargetBounds() { | 138 gfx::Rect SplitViewController::GetRightTargetBounds() { |
138 gfx::Rect work_area = | 139 gfx::Rect work_area = |
139 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area(); | 140 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area(); |
140 int container_width = container_->bounds().width(); | 141 int container_width = container_->bounds().width(); |
141 return gfx::Rect( | 142 return gfx::Rect( |
142 container_width / 2, 0, container_width / 2, work_area.height()); | 143 container_width / 2, 0, container_width / 2, work_area.height()); |
143 } | 144 } |
144 | 145 |
145 void SplitViewController::UpdateLayout(bool animate) { | 146 void SplitViewController::UpdateLayout(bool animate) { |
146 if (!left_window_) | 147 CHECK(left_window_); |
| 148 CHECK(right_window_); |
| 149 |
| 150 if (state_ == INACTIVE && !animate) { |
| 151 if (!wm::IsActiveWindow(left_window_)) |
| 152 left_window_->Hide(); |
| 153 if (!wm::IsActiveWindow(right_window_)) |
| 154 right_window_->Hide(); |
| 155 SetWindowTransforms(gfx::Transform(), gfx::Transform(), false); |
147 return; | 156 return; |
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) { | |
153 // Windows should be resized via an animation when entering the ACTIVE | |
154 // state. | |
155 CHECK(animate); | |
156 // We scale the windows here, but when the animation finishes, we reset | |
157 // the scaling and update the window bounds to the proper size - see | |
158 // OnAnimationCompleted(). | |
159 left_transform = GetTargetTransformForBoundsAnimation( | |
160 left_window_->bounds(), GetLeftTargetBounds()); | |
161 right_transform = GetTargetTransformForBoundsAnimation( | |
162 right_window_->bounds(), GetRightTargetBounds()); | |
163 } else { | |
164 left_transform.Translate(separator_position_ - container_width, 0); | |
165 right_transform.Translate(separator_position_, 0); | |
166 } | 157 } |
| 158 |
167 left_window_->Show(); | 159 left_window_->Show(); |
168 right_window_->Show(); | 160 right_window_->Show(); |
169 SetWindowTransform(left_window_, left_transform, animate); | 161 if (state_ == ACTIVE) { |
170 SetWindowTransform(right_window_, right_transform, animate); | 162 if (animate) { |
| 163 gfx::Transform left_transform = GetTargetTransformForBoundsAnimation( |
| 164 left_window_->bounds(), GetLeftTargetBounds()); |
| 165 gfx::Transform right_transform = GetTargetTransformForBoundsAnimation( |
| 166 right_window_->bounds(), GetRightTargetBounds()); |
| 167 SetWindowTransforms(left_transform, right_transform, true); |
| 168 } else { |
| 169 left_window_->SetBounds(GetLeftTargetBounds()); |
| 170 right_window_->SetBounds(GetRightTargetBounds()); |
| 171 SetWindowTransforms(gfx::Transform(), gfx::Transform(), false); |
| 172 } |
| 173 } else { |
| 174 gfx::Transform left_transform; |
| 175 left_transform.Translate(separator_position_ - container_->bounds().width(), |
| 176 0); |
| 177 gfx::Transform right_transform; |
| 178 right_transform.Translate(separator_position_, 0); |
| 179 SetWindowTransforms(left_transform, right_transform, animate); |
| 180 } |
| 181 // Note: |left_window_| and |right_window_| may be NULL if calling |
| 182 // SetWindowTransforms(): |
| 183 // - caused the in-progress animation to abort. |
| 184 // - started a zero duration animation. |
171 } | 185 } |
172 | 186 |
173 void SplitViewController::SetWindowTransform(aura::Window* window, | 187 void SplitViewController::SetWindowTransforms( |
174 const gfx::Transform& transform, | 188 const gfx::Transform& left_transform, |
175 bool animate) { | 189 const gfx::Transform& right_transform, |
| 190 bool animate) { |
176 if (animate) { | 191 if (animate) { |
177 scoped_refptr<ui::LayerAnimator> animator = window->layer()->GetAnimator(); | 192 ui::ScopedLayerAnimationSettings left_settings( |
178 ui::ScopedLayerAnimationSettings settings(animator); | 193 left_window_->layer()->GetAnimator()); |
179 settings.SetPreemptionStrategy( | 194 left_settings.SetPreemptionStrategy( |
180 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 195 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
181 settings.AddObserver(new ui::ClosureAnimationObserver( | 196 left_window_->SetTransform(left_transform); |
| 197 |
| 198 ui::ScopedLayerAnimationSettings right_settings( |
| 199 right_window_->layer()->GetAnimator()); |
| 200 right_settings.SetPreemptionStrategy( |
| 201 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 202 right_settings.AddObserver(new ui::ClosureAnimationObserver( |
182 base::Bind(&SplitViewController::OnAnimationCompleted, | 203 base::Bind(&SplitViewController::OnAnimationCompleted, |
183 weak_factory_.GetWeakPtr(), | 204 weak_factory_.GetWeakPtr()))); |
184 window))); | 205 right_window_->SetTransform(right_transform); |
185 window->SetTransform(transform); | |
186 } else { | 206 } else { |
187 window->SetTransform(transform); | 207 left_window_->SetTransform(left_transform); |
| 208 right_window_->SetTransform(right_transform); |
188 } | 209 } |
189 } | 210 } |
190 | 211 |
191 void SplitViewController::OnAnimationCompleted(aura::Window* window) { | 212 void SplitViewController::OnAnimationCompleted() { |
192 // Animation can be cancelled when deactivated. | 213 // Animation can be cancelled when deactivated. |
193 if (left_window_ == NULL) | 214 if (left_window_ == NULL) |
194 return; | 215 return; |
195 DCHECK(window == left_window_ || window == right_window_); | 216 UpdateLayout(false); |
196 if (state_ == ACTIVE) { | 217 |
197 window->SetTransform(gfx::Transform()); | 218 if (state_ == INACTIVE) { |
198 if (window == left_window_) | 219 left_window_ = NULL; |
199 left_window_->SetBounds(GetLeftTargetBounds()); | 220 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(); | |
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 } | 221 } |
217 } | 222 } |
218 | 223 |
219 void SplitViewController::UpdateSeparatorPositionFromScrollDelta(float delta) { | 224 void SplitViewController::UpdateSeparatorPositionFromScrollDelta(float delta) { |
220 gfx::Screen* screen = gfx::Screen::GetScreenFor(container_); | 225 gfx::Screen* screen = gfx::Screen::GetScreenFor(container_); |
221 const gfx::Rect& display_bounds = | 226 const gfx::Rect& display_bounds = |
222 screen->GetDisplayNearestWindow(container_).bounds(); | 227 screen->GetDisplayNearestWindow(container_).bounds(); |
223 gfx::Rect container_bounds = container_->GetBoundsInScreen(); | 228 gfx::Rect container_bounds = container_->GetBoundsInScreen(); |
224 separator_position_ = | 229 separator_position_ = |
225 delta > 0 ? ((int)delta) + display_bounds.x() - container_bounds.x() | 230 delta > 0 ? ((int)delta) + display_bounds.x() - container_bounds.x() |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 } | 293 } |
289 | 294 |
290 bool SplitViewController::CanScroll() { | 295 bool SplitViewController::CanScroll() { |
291 // TODO(mfomitchev): return false in vertical orientation, in full screen. | 296 // TODO(mfomitchev): return false in vertical orientation, in full screen. |
292 bool result = (!IsSplitViewModeActive() && | 297 bool result = (!IsSplitViewModeActive() && |
293 window_list_provider_->GetWindowList().size() >= 2); | 298 window_list_provider_->GetWindowList().size() >= 2); |
294 return result; | 299 return result; |
295 } | 300 } |
296 | 301 |
297 } // namespace athena | 302 } // namespace athena |
OLD | NEW |