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; | 149 |
150 gfx::Transform right_transform; | |
151 int container_width = container_->GetBoundsInScreen().width(); | |
152 if (state_ == ACTIVE) { | 150 if (state_ == ACTIVE) { |
153 // Windows should be resized via an animation when entering the ACTIVE | 151 if (animate) { |
154 // state. | 152 gfx::Transform left_transform = GetTargetTransformForBoundsAnimation( |
155 CHECK(animate); | 153 left_window_->bounds(), GetLeftTargetBounds()); |
156 // We scale the windows here, but when the animation finishes, we reset | 154 gfx::Transform right_transform = GetTargetTransformForBoundsAnimation( |
157 // the scaling and update the window bounds to the proper size - see | 155 right_window_->bounds(), GetRightTargetBounds()); |
158 // OnAnimationCompleted(). | 156 SetWindowTransforms(left_transform, right_transform, true); |
159 left_transform = GetTargetTransformForBoundsAnimation( | 157 } else { |
160 left_window_->bounds(), GetLeftTargetBounds()); | 158 left_window_->SetBounds(GetLeftTargetBounds()); |
161 right_transform = GetTargetTransformForBoundsAnimation( | 159 right_window_->SetBounds(GetRightTargetBounds()); |
162 right_window_->bounds(), GetRightTargetBounds()); | 160 SetWindowTransforms(gfx::Transform(), gfx::Transform(), false); |
161 } | |
162 } else if (state_ == INACTIVE && !animate) { | |
163 SetWindowTransforms(gfx::Transform(), gfx::Transform(), false); | |
163 } else { | 164 } else { |
164 left_transform.Translate(separator_position_ - container_width, 0); | 165 gfx::Transform left_transform; |
166 left_transform.Translate(separator_position_ - container_->bounds().width(), | |
167 0); | |
168 gfx::Transform right_transform; | |
165 right_transform.Translate(separator_position_, 0); | 169 right_transform.Translate(separator_position_, 0); |
170 SetWindowTransforms(left_transform, right_transform, animate); | |
166 } | 171 } |
167 left_window_->Show(); | |
168 right_window_->Show(); | |
169 SetWindowTransform(left_window_, left_transform, animate); | |
170 SetWindowTransform(right_window_, right_transform, animate); | |
171 } | |
172 | 172 |
173 void SplitViewController::SetWindowTransform(aura::Window* window, | 173 if (state_ == INACTIVE && !animate) { |
174 const gfx::Transform& transform, | 174 if (!wm::IsActiveWindow(left_window_)) |
175 bool animate) { | 175 left_window_->Hide(); |
176 if (animate) { | 176 if (!wm::IsActiveWindow(right_window_)) |
177 scoped_refptr<ui::LayerAnimator> animator = window->layer()->GetAnimator(); | 177 right_window_->Hide(); |
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 { | 178 } else { |
187 window->SetTransform(transform); | 179 left_window_->Show(); |
180 right_window_->Show(); | |
188 } | 181 } |
189 } | 182 } |
190 | 183 |
191 void SplitViewController::OnAnimationCompleted(aura::Window* window) { | 184 void SplitViewController::SetWindowTransforms( |
185 const gfx::Transform& left_transform, | |
186 const gfx::Transform& right_transform, | |
187 bool animate) { | |
188 if (animate) { | |
189 ui::ScopedLayerAnimationSettings left_settings( | |
190 left_window_->layer()->GetAnimator()); | |
191 left_settings.SetPreemptionStrategy( | |
192 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
193 left_window_->SetTransform(left_transform); | |
194 | |
195 ui::ScopedLayerAnimationSettings right_settings( | |
196 right_window_->layer()->GetAnimator()); | |
197 right_settings.SetPreemptionStrategy( | |
198 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
199 right_settings.AddObserver(new ui::ClosureAnimationObserver( | |
200 base::Bind(&SplitViewController::OnAnimationCompleted, | |
201 weak_factory_.GetWeakPtr()))); | |
202 right_window_->SetTransform(right_transform); | |
203 } else { | |
204 left_window_->SetTransform(left_transform); | |
205 right_window_->SetTransform(right_transform); | |
206 } | |
207 } | |
208 | |
209 void SplitViewController::OnAnimationCompleted() { | |
192 // Animation can be cancelled when deactivated. | 210 // Animation can be cancelled when deactivated. |
193 if (left_window_ == NULL) | 211 if (left_window_ == NULL) |
194 return; | 212 return; |
195 DCHECK(window == left_window_ || window == right_window_); | 213 UpdateLayout(false); |
sadrul
2014/08/29 15:06:02
Do we not want to reset left_window_ and right_win
pkotwicz
2014/08/29 18:07:42
Yes we do. I need to be more careful...
| |
196 if (state_ == ACTIVE) { | |
197 window->SetTransform(gfx::Transform()); | |
198 if (window == left_window_) | |
199 left_window_->SetBounds(GetLeftTargetBounds()); | |
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 } | |
217 } | 214 } |
218 | 215 |
219 void SplitViewController::UpdateSeparatorPositionFromScrollDelta(float delta) { | 216 void SplitViewController::UpdateSeparatorPositionFromScrollDelta(float delta) { |
220 gfx::Screen* screen = gfx::Screen::GetScreenFor(container_); | 217 gfx::Screen* screen = gfx::Screen::GetScreenFor(container_); |
221 const gfx::Rect& display_bounds = | 218 const gfx::Rect& display_bounds = |
222 screen->GetDisplayNearestWindow(container_).bounds(); | 219 screen->GetDisplayNearestWindow(container_).bounds(); |
223 gfx::Rect container_bounds = container_->GetBoundsInScreen(); | 220 gfx::Rect container_bounds = container_->GetBoundsInScreen(); |
224 separator_position_ = | 221 separator_position_ = |
225 delta > 0 ? ((int)delta) + display_bounds.x() - container_bounds.x() | 222 delta > 0 ? ((int)delta) + display_bounds.x() - container_bounds.x() |
226 : display_bounds.right() - container_bounds.x() + delta; | 223 : display_bounds.right() - container_bounds.x() + delta; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 } | 285 } |
289 | 286 |
290 bool SplitViewController::CanScroll() { | 287 bool SplitViewController::CanScroll() { |
291 // TODO(mfomitchev): return false in vertical orientation, in full screen. | 288 // TODO(mfomitchev): return false in vertical orientation, in full screen. |
292 bool result = (!IsSplitViewModeActive() && | 289 bool result = (!IsSplitViewModeActive() && |
293 window_list_provider_->GetWindowList().size() >= 2); | 290 window_list_provider_->GetWindowList().size() >= 2); |
294 return result; | 291 return result; |
295 } | 292 } |
296 | 293 |
297 } // namespace athena | 294 } // namespace athena |
OLD | NEW |