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" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
13 #include "ui/compositor/closure_animation_observer.h" | 13 #include "ui/compositor/closure_animation_observer.h" |
14 #include "ui/compositor/layer_animation_observer.h" | 14 #include "ui/compositor/layer_animation_observer.h" |
15 #include "ui/compositor/scoped_layer_animation_settings.h" | 15 #include "ui/compositor/scoped_layer_animation_settings.h" |
16 #include "ui/events/event_handler.h" | 16 #include "ui/events/event_handler.h" |
17 #include "ui/gfx/display.h" | 17 #include "ui/gfx/display.h" |
18 #include "ui/gfx/screen.h" | 18 #include "ui/gfx/screen.h" |
19 #include "ui/wm/core/window_util.h" | 19 #include "ui/wm/core/window_util.h" |
20 | 20 |
21 namespace athena { | 21 namespace athena { |
22 | 22 |
| 23 namespace { |
| 24 |
| 25 // Returns a target transform which is suitable for animating a windows's |
| 26 // bounds. |
| 27 gfx::Transform GetTargetTransformForBoundsAnimation(const gfx::Rect& from, |
| 28 const gfx::Rect& to) { |
| 29 gfx::Transform transform; |
| 30 transform.Translate(to.x() - from.x(), to.y() - from.y()); |
| 31 transform.Scale(to.width() / static_cast<float>(from.width()), |
| 32 to.height() / static_cast<float>(from.height())); |
| 33 return transform; |
| 34 } |
| 35 |
| 36 } // namespace |
| 37 |
23 SplitViewController::SplitViewController( | 38 SplitViewController::SplitViewController( |
24 aura::Window* container, | 39 aura::Window* container, |
25 WindowListProvider* window_list_provider) | 40 WindowListProvider* window_list_provider) |
26 : state_(INACTIVE), | 41 : state_(INACTIVE), |
27 container_(container), | 42 container_(container), |
28 window_list_provider_(window_list_provider), | 43 window_list_provider_(window_list_provider), |
29 left_window_(NULL), | 44 left_window_(NULL), |
30 right_window_(NULL), | 45 right_window_(NULL), |
31 separator_position_(0), | 46 separator_position_(0), |
32 weak_factory_(this) { | 47 weak_factory_(this) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 wm::ActivateWindow(replace_with); | 121 wm::ActivateWindow(replace_with); |
107 window->SetTransform(gfx::Transform()); | 122 window->SetTransform(gfx::Transform()); |
108 } | 123 } |
109 | 124 |
110 void SplitViewController::DeactivateSplitMode() { | 125 void SplitViewController::DeactivateSplitMode() { |
111 CHECK_NE(SCROLLING, state_); | 126 CHECK_NE(SCROLLING, state_); |
112 state_ = INACTIVE; | 127 state_ = INACTIVE; |
113 left_window_ = right_window_ = NULL; | 128 left_window_ = right_window_ = NULL; |
114 } | 129 } |
115 | 130 |
| 131 gfx::Rect SplitViewController::GetLeftTargetBounds() { |
| 132 gfx::Rect work_area = |
| 133 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area(); |
| 134 return gfx::Rect(0, 0, container_->bounds().width() / 2, work_area.height()); |
| 135 } |
| 136 |
| 137 gfx::Rect SplitViewController::GetRightTargetBounds() { |
| 138 gfx::Rect work_area = |
| 139 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area(); |
| 140 int container_width = container_->bounds().width(); |
| 141 return gfx::Rect( |
| 142 container_width / 2, 0, container_width / 2, work_area.height()); |
| 143 } |
| 144 |
116 void SplitViewController::UpdateLayout(bool animate) { | 145 void SplitViewController::UpdateLayout(bool animate) { |
117 if (!left_window_) | 146 if (!left_window_) |
118 return; | 147 return; |
119 CHECK(right_window_); | 148 CHECK(right_window_); |
120 gfx::Transform left_transform; | 149 gfx::Transform left_transform; |
121 gfx::Transform right_transform; | 150 gfx::Transform right_transform; |
122 int container_width = container_->GetBoundsInScreen().width(); | 151 int container_width = container_->GetBoundsInScreen().width(); |
123 if (state_ == ACTIVE) { | 152 if (state_ == ACTIVE) { |
124 // This method should only be called once in ACTIVE state when | |
125 // the left and rightwindows are still full screen and need to be resized. | |
126 CHECK_EQ(left_window_->bounds().width(), container_width); | |
127 CHECK_EQ(right_window_->bounds().width(), container_width); | |
128 // Windows should be resized via an animation when entering the ACTIVE | 153 // Windows should be resized via an animation when entering the ACTIVE |
129 // state. | 154 // state. |
130 CHECK(animate); | 155 CHECK(animate); |
131 // We scale the windows here, but when the animation finishes, we reset | 156 // We scale the windows here, but when the animation finishes, we reset |
132 // the scaling and update the window bounds to the proper size - see | 157 // the scaling and update the window bounds to the proper size - see |
133 // OnAnimationCompleted(). | 158 // OnAnimationCompleted(). |
134 left_transform.Scale(.5, 1); | 159 left_transform = GetTargetTransformForBoundsAnimation( |
135 right_transform.Scale(.5, 1); | 160 left_window_->bounds(), GetLeftTargetBounds()); |
136 right_transform.Translate(container_width, 0); | 161 right_transform = GetTargetTransformForBoundsAnimation( |
| 162 right_window_->bounds(), GetRightTargetBounds()); |
137 } else { | 163 } else { |
138 left_transform.Translate(separator_position_ - container_width, 0); | 164 left_transform.Translate(separator_position_ - container_width, 0); |
139 right_transform.Translate(separator_position_, 0); | 165 right_transform.Translate(separator_position_, 0); |
140 } | 166 } |
141 left_window_->Show(); | 167 left_window_->Show(); |
142 right_window_->Show(); | 168 right_window_->Show(); |
143 SetWindowTransform(left_window_, left_transform, animate); | 169 SetWindowTransform(left_window_, left_transform, animate); |
144 SetWindowTransform(right_window_, right_transform, animate); | 170 SetWindowTransform(right_window_, right_transform, animate); |
145 } | 171 } |
146 | 172 |
(...skipping 14 matching lines...) Expand all Loading... |
161 window->SetTransform(transform); | 187 window->SetTransform(transform); |
162 } | 188 } |
163 } | 189 } |
164 | 190 |
165 void SplitViewController::OnAnimationCompleted(aura::Window* window) { | 191 void SplitViewController::OnAnimationCompleted(aura::Window* window) { |
166 // Animation can be cancelled when deactivated. | 192 // Animation can be cancelled when deactivated. |
167 if (left_window_ == NULL) | 193 if (left_window_ == NULL) |
168 return; | 194 return; |
169 DCHECK(window == left_window_ || window == right_window_); | 195 DCHECK(window == left_window_ || window == right_window_); |
170 if (state_ == ACTIVE) { | 196 if (state_ == ACTIVE) { |
171 int container_width = container_->bounds().width(); | |
172 gfx::Display display = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | |
173 gfx::Rect window_bounds(container_width / 2, display.work_area().height()); | |
174 window->SetTransform(gfx::Transform()); | 197 window->SetTransform(gfx::Transform()); |
175 if (window == left_window_) { | 198 if (window == left_window_) |
176 left_window_->SetBounds(window_bounds); | 199 left_window_->SetBounds(GetLeftTargetBounds()); |
177 } else { | 200 else |
178 window_bounds.set_x(container_width / 2); | 201 right_window_->SetBounds(GetRightTargetBounds()); |
179 right_window_->SetBounds(window_bounds); | |
180 } | |
181 } else { | 202 } else { |
182 int container_width = container_->bounds().width(); | 203 int container_width = container_->bounds().width(); |
183 window->SetTransform(gfx::Transform()); | 204 window->SetTransform(gfx::Transform()); |
184 if (window == left_window_) { | 205 if (window == left_window_) { |
185 if (separator_position_ == 0) | 206 if (separator_position_ == 0) |
186 left_window_->Hide(); | 207 left_window_->Hide(); |
187 if (state_ == INACTIVE) | 208 if (state_ == INACTIVE) |
188 left_window_ = NULL; | 209 left_window_ = NULL; |
189 } else { | 210 } else { |
190 if (separator_position_ == container_width) | 211 if (separator_position_ == container_width) |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 } | 288 } |
268 | 289 |
269 bool SplitViewController::CanScroll() { | 290 bool SplitViewController::CanScroll() { |
270 // TODO(mfomitchev): return false in vertical orientation, in full screen. | 291 // TODO(mfomitchev): return false in vertical orientation, in full screen. |
271 bool result = (!IsSplitViewModeActive() && | 292 bool result = (!IsSplitViewModeActive() && |
272 window_list_provider_->GetWindowList().size() >= 2); | 293 window_list_provider_->GetWindowList().size() >= 2); |
273 return result; | 294 return result; |
274 } | 295 } |
275 | 296 |
276 } // namespace athena | 297 } // namespace athena |
OLD | NEW |