Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: athena/wm/window_overview_mode.cc

Issue 420603011: Split Screen mode implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@split_view
Patch Set: Fixing a rebase glitch Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/window_overview_mode.h" 5 #include "athena/wm/window_overview_mode.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <vector> 9 #include <vector>
10 10
11 #include "athena/wm/public/window_list_provider.h"
11 #include "base/bind.h" 12 #include "base/bind.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "ui/aura/scoped_window_targeter.h" 14 #include "ui/aura/scoped_window_targeter.h"
14 #include "ui/aura/window.h" 15 #include "ui/aura/window.h"
15 #include "ui/aura/window_delegate.h" 16 #include "ui/aura/window_delegate.h"
16 #include "ui/aura/window_property.h" 17 #include "ui/aura/window_property.h"
17 #include "ui/aura/window_targeter.h" 18 #include "ui/aura/window_targeter.h"
18 #include "ui/aura/window_tree_host.h" 19 #include "ui/aura/window_tree_host.h"
19 #include "ui/compositor/compositor.h" 20 #include "ui/compositor/compositor.h"
20 #include "ui/compositor/compositor_animation_observer.h" 21 #include "ui/compositor/compositor_animation_observer.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 } // namespace 68 } // namespace
68 69
69 DECLARE_WINDOW_PROPERTY_TYPE(WindowOverviewState*) 70 DECLARE_WINDOW_PROPERTY_TYPE(WindowOverviewState*)
70 DEFINE_OWNED_WINDOW_PROPERTY_KEY(WindowOverviewState, 71 DEFINE_OWNED_WINDOW_PROPERTY_KEY(WindowOverviewState,
71 kWindowOverviewState, 72 kWindowOverviewState,
72 NULL) 73 NULL)
73 namespace athena { 74 namespace athena {
74 75
75 namespace { 76 namespace {
76 77
77 bool ShouldShowWindowInOverviewMode(aura::Window* window) {
78 return window->type() == ui::wm::WINDOW_TYPE_NORMAL;
79 }
80
81 // Gets the transform for the window in its current state. 78 // Gets the transform for the window in its current state.
82 gfx::Transform GetTransformForState(WindowOverviewState* state) { 79 gfx::Transform GetTransformForState(WindowOverviewState* state) {
83 return gfx::Tween::TransformValueBetween(state->progress, 80 return gfx::Tween::TransformValueBetween(state->progress,
84 state->top, 81 state->top,
85 state->bottom); 82 state->bottom);
86 } 83 }
87
sadrul 2014/08/09 13:32:40 Keep the blank line between the functions here.
mfomitchev 2014/08/09 18:29:56 Done.
88 // Sets the progress-state for the window in the overview mode. 84 // Sets the progress-state for the window in the overview mode.
89 void SetWindowProgress(aura::Window* window, float progress) { 85 void SetWindowProgress(aura::Window* window, float progress) {
90 WindowOverviewState* state = window->GetProperty(kWindowOverviewState); 86 WindowOverviewState* state = window->GetProperty(kWindowOverviewState);
91 state->progress = progress; 87 state->progress = progress;
92 window->SetTransform(GetTransformForState(state)); 88 window->SetTransform(GetTransformForState(state));
93 } 89 }
94 90
95 // Resets the overview-related state for |window|. 91 // Resets the overview-related state for |window|.
96 void RestoreWindowState(aura::Window* window) { 92 void RestoreWindowState(aura::Window* window) {
97 window->ClearProperty(kWindowOverviewState); 93 window->ClearProperty(kWindowOverviewState);
(...skipping 26 matching lines...) Expand all
124 120
125 aura::Window* target_; 121 aura::Window* target_;
126 DISALLOW_COPY_AND_ASSIGN(StaticWindowTargeter); 122 DISALLOW_COPY_AND_ASSIGN(StaticWindowTargeter);
127 }; 123 };
128 124
129 class WindowOverviewModeImpl : public WindowOverviewMode, 125 class WindowOverviewModeImpl : public WindowOverviewMode,
130 public ui::EventHandler, 126 public ui::EventHandler,
131 public ui::CompositorAnimationObserver { 127 public ui::CompositorAnimationObserver {
132 public: 128 public:
133 WindowOverviewModeImpl(aura::Window* container, 129 WindowOverviewModeImpl(aura::Window* container,
130 const WindowListProvider* window_list_provider,
134 WindowOverviewModeDelegate* delegate) 131 WindowOverviewModeDelegate* delegate)
135 : container_(container), 132 : container_(container),
133 window_list_provider_(window_list_provider),
136 delegate_(delegate), 134 delegate_(delegate),
137 scoped_targeter_(new aura::ScopedWindowTargeter( 135 scoped_targeter_(new aura::ScopedWindowTargeter(
138 container, 136 container,
139 scoped_ptr<ui::EventTargeter>( 137 scoped_ptr<ui::EventTargeter>(
140 new StaticWindowTargeter(container)))), 138 new StaticWindowTargeter(container)))),
141 dragged_window_(NULL) { 139 dragged_window_(NULL) {
142 container_->set_target_handler(this); 140 container_->set_target_handler(this);
143 141
144 // Prepare the desired transforms for all the windows, and set the initial 142 // Prepare the desired transforms for all the windows, and set the initial
145 // state on the windows. 143 // state on the windows.
146 ComputeTerminalStatesForAllWindows(); 144 ComputeTerminalStatesForAllWindows();
147 SetInitialWindowStates(); 145 SetInitialWindowStates();
148 } 146 }
149 147
150 virtual ~WindowOverviewModeImpl() { 148 virtual ~WindowOverviewModeImpl() {
151 container_->set_target_handler(container_->delegate()); 149 container_->set_target_handler(container_->delegate());
152 RemoveAnimationObserver(); 150 RemoveAnimationObserver();
153 const aura::Window::Windows& windows = container_->children(); 151 aura::Window::Windows windows = window_list_provider_->GetWindowList();
154 for (aura::Window::Windows::const_iterator iter = windows.begin(); 152 if (windows.empty())
155 iter != windows.end(); 153 return;
156 ++iter) { 154 std::for_each(windows.begin(), windows.end(), &RestoreWindowState);
157 if ((*iter)->GetProperty(kWindowOverviewState))
158 RestoreWindowState(*iter);
159 }
160 } 155 }
161 156
162 private: 157 private:
163 // Computes the transforms for all windows in both the topmost and bottom-most 158 // Computes the transforms for all windows in both the topmost and bottom-most
164 // positions. The transforms are set in the |kWindowOverviewState| property of 159 // positions. The transforms are set in the |kWindowOverviewState| property of
165 // the windows. 160 // the windows.
166 void ComputeTerminalStatesForAllWindows() { 161 void ComputeTerminalStatesForAllWindows() {
167 const aura::Window::Windows& windows = container_->children(); 162 aura::Window::Windows windows = window_list_provider_->GetWindowList();
168 size_t window_count = std::count_if(windows.begin(), windows.end(), 163 size_t window_count = windows.size();
169 ShouldShowWindowInOverviewMode);
170
171 size_t index = 0; 164 size_t index = 0;
172 const gfx::Size container_size = container_->bounds().size(); 165 const gfx::Size container_size = container_->bounds().size();
173 166
174 const int kGapBetweenWindowsBottom = 10; 167 const int kGapBetweenWindowsBottom = 10;
175 const int kGapBetweenWindowsTop = 5; 168 const int kGapBetweenWindowsTop = 5;
176 169
177 for (aura::Window::Windows::const_reverse_iterator iter = windows.rbegin(); 170 for (aura::Window::Windows::const_reverse_iterator iter = windows.rbegin();
178 iter != windows.rend(); 171 iter != windows.rend();
179 ++iter) { 172 ++iter, ++index) {
180 aura::Window* window = (*iter); 173 aura::Window* window = (*iter);
181 if (!ShouldShowWindowInOverviewMode(window))
182 continue;
183 174
184 gfx::Transform top_transform; 175 gfx::Transform top_transform;
185 int top = (window_count - index - 1) * kGapBetweenWindowsTop; 176 int top = (window_count - index - 1) * kGapBetweenWindowsTop;
186 float x_translate = container_size.width() * (1 - kMinScale) / 2.; 177 float x_translate = container_size.width() * (1 - kMinScale) / 2.;
187 top_transform.Translate(x_translate, top); 178 top_transform.Translate(x_translate, top);
188 top_transform.Scale(kMinScale, kMinScale); 179 top_transform.Scale(kMinScale, kMinScale);
189 180
190 gfx::Transform bottom_transform; 181 gfx::Transform bottom_transform;
191 int bottom = GetScrollableHeight() - (index * kGapBetweenWindowsBottom); 182 int bottom = GetScrollableHeight() - (index * kGapBetweenWindowsBottom);
192 x_translate = container_size.width() * (1 - kMaxScale) / 2.; 183 x_translate = container_size.width() * (1 - kMaxScale) / 2.;
193 bottom_transform.Translate(x_translate, bottom - window->bounds().y()); 184 bottom_transform.Translate(x_translate, bottom - window->bounds().y());
194 bottom_transform.Scale(kMaxScale, kMaxScale); 185 bottom_transform.Scale(kMaxScale, kMaxScale);
195 186
196 WindowOverviewState* state = new WindowOverviewState; 187 WindowOverviewState* state = new WindowOverviewState;
197 state->top = top_transform; 188 state->top = top_transform;
198 state->bottom = bottom_transform; 189 state->bottom = bottom_transform;
199 state->progress = 0.f; 190 state->progress = 0.f;
200 state->shadow = CreateShadowForWindow(window); 191 state->shadow = CreateShadowForWindow(window);
201 window->SetProperty(kWindowOverviewState, state); 192 window->SetProperty(kWindowOverviewState, state);
202
203 index++;
204 } 193 }
205 } 194 }
206 195
207 // Sets the initial position for the windows for the overview mode. 196 // Sets the initial position for the windows for the overview mode.
208 void SetInitialWindowStates() { 197 void SetInitialWindowStates() {
198 aura::Window::Windows windows = window_list_provider_->GetWindowList();
199 size_t window_count = windows.size();
209 // The initial overview state of the topmost three windows. 200 // The initial overview state of the topmost three windows.
210 const float kInitialProgress[] = { 0.5f, 0.05f, 0.01f }; 201 const float kInitialProgress[] = { 0.5f, 0.05f, 0.01f };
211 size_t index = 0; 202 for (size_t i = 0; i < window_count; ++i) {
212 const aura::Window::Windows& windows = container_->children();
213 for (aura::Window::Windows::const_reverse_iterator iter = windows.rbegin();
214 iter != windows.rend();
215 ++iter) {
216 aura::Window* window = (*iter);
217 if (!window->GetProperty(kWindowOverviewState))
218 continue;
219
220 float progress = 0.f; 203 float progress = 0.f;
221 if (index < arraysize(kInitialProgress)) 204 aura::Window* window = windows[window_count - 1 - i];
222 progress = kInitialProgress[index]; 205 if (i < arraysize(kInitialProgress))
206 progress = kInitialProgress[i];
223 207
224 scoped_refptr<ui::LayerAnimator> animator = 208 scoped_refptr<ui::LayerAnimator> animator =
225 window->layer()->GetAnimator(); 209 window->layer()->GetAnimator();
226 210
227 // Unset any in-progress animation. 211 // Unset any in-progress animation.
228 { 212 {
229 ui::ScopedLayerAnimationSettings settings(animator); 213 ui::ScopedLayerAnimationSettings settings(animator);
230 settings.SetPreemptionStrategy( 214 settings.SetPreemptionStrategy(
231 ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET); 215 ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET);
232 window->Show(); 216 window->Show();
233 window->SetTransform(gfx::Transform()); 217 window->SetTransform(gfx::Transform());
234 } 218 }
235 // Setup the animation. 219 // Setup the animation.
236 { 220 {
237 ui::ScopedLayerAnimationSettings settings(animator); 221 ui::ScopedLayerAnimationSettings settings(animator);
238 settings.SetPreemptionStrategy( 222 settings.SetPreemptionStrategy(
239 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 223 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
240 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(250)); 224 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(250));
241 SetWindowProgress(window, progress); 225 SetWindowProgress(window, progress);
242 } 226 }
243 index++;
244 } 227 }
245 } 228 }
246 229
247 scoped_ptr<wm::Shadow> CreateShadowForWindow(aura::Window* window) { 230 scoped_ptr<wm::Shadow> CreateShadowForWindow(aura::Window* window) {
248 scoped_ptr<wm::Shadow> shadow(new wm::Shadow()); 231 scoped_ptr<wm::Shadow> shadow(new wm::Shadow());
249 shadow->Init(wm::Shadow::STYLE_ACTIVE); 232 shadow->Init(wm::Shadow::STYLE_ACTIVE);
250 shadow->SetContentBounds(gfx::Rect(window->bounds().size())); 233 shadow->SetContentBounds(gfx::Rect(container_->bounds().size()));
251 shadow->layer()->SetVisible(true); 234 shadow->layer()->SetVisible(true);
252 window->layer()->Add(shadow->layer()); 235 window->layer()->Add(shadow->layer());
253 return shadow.Pass(); 236 return shadow.Pass();
254 } 237 }
255 238
256 aura::Window* SelectWindowAt(ui::LocatedEvent* event) { 239 aura::Window* SelectWindowAt(ui::LocatedEvent* event) {
257 CHECK_EQ(container_, event->target()); 240 CHECK_EQ(container_, event->target());
258 // Find the old targeter to find the target of the event. 241 // Find the old targeter to find the target of the event.
259 ui::EventTarget* window = container_; 242 ui::EventTarget* window = container_;
260 ui::EventTargeter* targeter = scoped_targeter_->old_targeter(); 243 ui::EventTargeter* targeter = scoped_targeter_->old_targeter();
261 while (!targeter && window->GetParentTarget()) { 244 while (!targeter && window->GetParentTarget()) {
262 window = window->GetParentTarget(); 245 window = window->GetParentTarget();
263 targeter = window->GetEventTargeter(); 246 targeter = window->GetEventTargeter();
264 } 247 }
265 if (!targeter) 248 if (!targeter)
266 return NULL; 249 return NULL;
267 aura::Window* target = static_cast<aura::Window*>( 250 aura::Window* target = static_cast<aura::Window*>(
268 targeter->FindTargetForLocatedEvent(container_, event)); 251 targeter->FindTargetForLocatedEvent(container_, event));
269 while (target && target->parent() != container_) 252 while (target && target->parent() != container_)
270 target = target->parent(); 253 target = target->parent();
271 return target; 254 return target;
272 } 255 }
273 256
274 // Scroll the window list by |delta_y| amount. |delta_y| is negative when 257 // Scroll the window list by |delta_y| amount. |delta_y| is negative when
275 // scrolling up; and positive when scrolling down. 258 // scrolling up; and positive when scrolling down.
276 void DoScroll(float delta_y) { 259 void DoScroll(float delta_y) {
277 const float kEpsilon = 1e-3f; 260 const float kEpsilon = 1e-3f;
278 float delta_y_p = std::abs(delta_y) / GetScrollableHeight(); 261 float delta_y_p = std::abs(delta_y) / GetScrollableHeight();
279 const aura::Window::Windows& windows = container_->children(); 262 aura::Window::Windows windows = window_list_provider_->GetWindowList();
280 if (delta_y < 0) { 263 if (delta_y < 0) {
281 // Scroll up. Start with the top-most (i.e. behind-most in terms of 264 // Scroll up. Start with the top-most (i.e. behind-most in terms of
282 // z-index) window, and try to scroll them up. 265 // z-index) window, and try to scroll them up.
283 for (aura::Window::Windows::const_iterator iter = windows.begin(); 266 for (aura::Window::Windows::const_iterator iter = windows.begin();
284 delta_y_p > kEpsilon && iter != windows.end(); 267 delta_y_p > kEpsilon && iter != windows.end();
285 ++iter) { 268 ++iter) {
286 aura::Window* window = (*iter); 269 aura::Window* window = (*iter);
287 WindowOverviewState* state = window->GetProperty(kWindowOverviewState); 270 WindowOverviewState* state = window->GetProperty(kWindowOverviewState);
288 if (!state)
289 continue;
290 if (state->progress > kEpsilon) { 271 if (state->progress > kEpsilon) {
291 // It is possible to scroll |window| up. Scroll it up, and update 272 // It is possible to scroll |window| up. Scroll it up, and update
292 // |delta_y_p| for the next window. 273 // |delta_y_p| for the next window.
293 float apply = delta_y_p * state->progress; 274 float apply = delta_y_p * state->progress;
294 SetWindowProgress(window, std::max(0.f, state->progress - apply * 3)); 275 SetWindowProgress(window, std::max(0.f, state->progress - apply * 3));
295 delta_y_p -= apply; 276 delta_y_p -= apply;
296 } 277 }
297 } 278 }
298 } else { 279 } else {
299 // Scroll down. Start with the bottom-most (i.e. front-most in terms of 280 // Scroll down. Start with the bottom-most (i.e. front-most in terms of
300 // z-index) window, and try to scroll them down. 281 // z-index) window, and try to scroll them down.
301 for (aura::Window::Windows::const_reverse_iterator iter = 282 aura::Window::Windows::const_reverse_iterator iter;
302 windows.rbegin(); 283 for (iter = windows.rbegin();
303 delta_y_p > kEpsilon && iter != windows.rend(); 284 delta_y_p > kEpsilon && iter != windows.rend();
304 ++iter) { 285 ++iter) {
305 aura::Window* window = (*iter); 286 aura::Window* window = (*iter);
306 WindowOverviewState* state = window->GetProperty(kWindowOverviewState); 287 WindowOverviewState* state = window->GetProperty(kWindowOverviewState);
307 if (!state)
308 continue;
309 if (1.f - state->progress > kEpsilon) { 288 if (1.f - state->progress > kEpsilon) {
310 // It is possible to scroll |window| down. Scroll it down, and update 289 // It is possible to scroll |window| down. Scroll it down, and update
311 // |delta_y_p| for the next window. 290 // |delta_y_p| for the next window.
312 SetWindowProgress(window, std::min(1.f, state->progress + delta_y_p)); 291 SetWindowProgress(window, std::min(1.f, state->progress + delta_y_p));
313 delta_y_p /= 2.f; 292 delta_y_p /= 2.f;
314 } 293 }
315 } 294 }
316 } 295 }
317 } 296 }
318 297
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 } 493 }
515 } 494 }
516 495
517 const int kMinDistanceForDismissal = 300; 496 const int kMinDistanceForDismissal = 300;
518 const float kMinScale = 0.6f; 497 const float kMinScale = 0.6f;
519 const float kMaxScale = 0.95f; 498 const float kMaxScale = 0.95f;
520 const float kMaxOpacity = 1.0f; 499 const float kMaxOpacity = 1.0f;
521 const float kMinOpacity = 0.2f; 500 const float kMinOpacity = 0.2f;
522 501
523 aura::Window* container_; 502 aura::Window* container_;
503 // Provider of the stack of windows to show in the overview mode. Not owned.
504 const WindowListProvider* window_list_provider_;
524 WindowOverviewModeDelegate* delegate_; 505 WindowOverviewModeDelegate* delegate_;
525 scoped_ptr<aura::ScopedWindowTargeter> scoped_targeter_; 506 scoped_ptr<aura::ScopedWindowTargeter> scoped_targeter_;
526 scoped_ptr<ui::FlingCurve> fling_; 507 scoped_ptr<ui::FlingCurve> fling_;
527 508
528 aura::Window* dragged_window_; 509 aura::Window* dragged_window_;
529 gfx::Point dragged_start_location_; 510 gfx::Point dragged_start_location_;
530 511
531 DISALLOW_COPY_AND_ASSIGN(WindowOverviewModeImpl); 512 DISALLOW_COPY_AND_ASSIGN(WindowOverviewModeImpl);
532 }; 513 };
533 514
534 } // namespace 515 } // namespace
535 516
536 // static 517 // static
537 scoped_ptr<WindowOverviewMode> WindowOverviewMode::Create( 518 scoped_ptr<WindowOverviewMode> WindowOverviewMode::Create(
538 aura::Window* container, 519 aura::Window* container,
520 const WindowListProvider* window_list_provider,
539 WindowOverviewModeDelegate* delegate) { 521 WindowOverviewModeDelegate* delegate) {
540 return scoped_ptr<WindowOverviewMode>( 522 return scoped_ptr<WindowOverviewMode>(
541 new WindowOverviewModeImpl(container, delegate)); 523 new WindowOverviewModeImpl(container, window_list_provider, delegate));
542 } 524 }
543 525
544 } // namespace athena 526 } // namespace athena
OLDNEW
« athena/wm/window_manager_impl.cc ('K') | « athena/wm/window_overview_mode.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698