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

Side by Side Diff: ash/wm/overview/scoped_transform_overview_window.cc

Issue 690103008: Implemented swipe to close in overview mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed ET_SCROLL_FLING_CANCEL handling from TransparentButton and removed WindowSelector.MultiWind… Created 5 years, 11 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "ash/wm/overview/scoped_transform_overview_window.h" 5 #include "ash/wm/overview/scoped_transform_overview_window.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/screen_util.h" 10 #include "ash/screen_util.h"
11 #include "ash/shell.h"
11 #include "ash/shell_window_ids.h" 12 #include "ash/shell_window_ids.h"
12 #include "ash/wm/overview/scoped_overview_animation_settings.h" 13 #include "ash/wm/overview/scoped_overview_animation_settings.h"
13 #include "ash/wm/overview/scoped_window_copy.h" 14 #include "ash/wm/overview/scoped_window_copy.h"
15 #include "ash/wm/overview/window_selector_controller.h"
14 #include "ash/wm/overview/window_selector_item.h" 16 #include "ash/wm/overview/window_selector_item.h"
15 #include "ash/wm/window_state.h" 17 #include "ash/wm/window_state.h"
16 #include "ash/wm/window_util.h" 18 #include "ash/wm/window_util.h"
17 #include "base/macros.h" 19 #include "base/macros.h"
18 #include "ui/aura/client/aura_constants.h" 20 #include "ui/aura/client/aura_constants.h"
19 #include "ui/aura/client/screen_position_client.h" 21 #include "ui/aura/client/screen_position_client.h"
20 #include "ui/aura/window.h" 22 #include "ui/aura/window.h"
21 #include "ui/compositor/scoped_layer_animation_settings.h" 23 #include "ui/compositor/scoped_layer_animation_settings.h"
22 #include "ui/gfx/animation/tween.h" 24 #include "ui/gfx/animation/tween.h"
23 #include "ui/gfx/transform_util.h" 25 #include "ui/gfx/transform_util.h"
24 #include "ui/views/widget/widget.h" 26 #include "ui/views/widget/widget.h"
25 #include "ui/wm/core/window_animations.h" 27 #include "ui/wm/core/window_animations.h"
26 #include "ui/wm/core/window_util.h" 28 #include "ui/wm/core/window_util.h"
27 29
28 namespace ash { 30 namespace ash {
29 31
30 namespace { 32 namespace {
31 33
32 // The opacity level that windows will be set to when they are restored. 34 // The opacity level that windows will be set to when they are restored.
33 const float kRestoreWindowOpacity = 1.0f; 35 const float kRestoreWindowOpacity = 1.0f;
34 36
37 // The minimum opacity used during touch scroll gestures.
38 const float kMinimumOpacity = 0.2f;
39
40 // The distance at which the minimum opacity should take effect.
41 const float kMinimumOpacityDistance = 200.0f;
42
35 aura::Window* GetTransientRoot(aura::Window* window) { 43 aura::Window* GetTransientRoot(aura::Window* window) {
36 while (::wm::GetTransientParent(window)) 44 while (::wm::GetTransientParent(window))
37 window = ::wm::GetTransientParent(window); 45 window = ::wm::GetTransientParent(window);
38 return window; 46 return window;
39 } 47 }
40 48
49 // Calculates the window opacity from the given scroll |distance|.
50 float CalculateOpacityFromScrollDistance(int distance) {
51 float opacity =
52 1.0 - static_cast<float>(abs(distance)) / kMinimumOpacityDistance;
53 return std::min(1.0f, std::max(kMinimumOpacity, opacity));
54 }
55
41 // An iterator class that traverses an aura::Window and all of it's transient 56 // An iterator class that traverses an aura::Window and all of it's transient
42 // descendants. 57 // descendants.
43 class TransientDescendantIterator { 58 class TransientDescendantIterator {
44 public: 59 public:
45 // Creates an empty iterator. 60 // Creates an empty iterator.
46 TransientDescendantIterator(); 61 TransientDescendantIterator();
47 62
48 // Copy constructor required for iterator purposes. 63 // Copy constructor required for iterator purposes.
49 TransientDescendantIterator( 64 TransientDescendantIterator(
50 const TransientDescendantIterator& other) = default; 65 const TransientDescendantIterator& other) = default;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 173
159 TransientDescendantIteratorRange GetTransientTreeIterator( 174 TransientDescendantIteratorRange GetTransientTreeIterator(
160 aura::Window* window) { 175 aura::Window* window) {
161 return TransientDescendantIteratorRange( 176 return TransientDescendantIteratorRange(
162 TransientDescendantIterator(GetTransientRoot(window))); 177 TransientDescendantIterator(GetTransientRoot(window)));
163 } 178 }
164 179
165 } // namespace 180 } // namespace
166 181
167 ScopedTransformOverviewWindow::ScopedTransformOverviewWindow( 182 ScopedTransformOverviewWindow::ScopedTransformOverviewWindow(
168 aura::Window* window) 183 aura::Window* window)
169 : window_(window), 184 : window_(window),
170 activate_button_(new TransparentActivateWindowButton( 185 activate_button_(new TransparentActivateWindowButton(
171 window_->GetRootWindow(), this)), 186 window_->GetRootWindow(), this)),
172 minimized_(window->GetProperty(aura::client::kShowStateKey) == 187 minimized_(window->GetProperty(aura::client::kShowStateKey) ==
173 ui::SHOW_STATE_MINIMIZED), 188 ui::SHOW_STATE_MINIMIZED),
174 ignored_by_shelf_(wm::GetWindowState(window)->ignored_by_shelf()), 189 ignored_by_shelf_(wm::GetWindowState(window)->ignored_by_shelf()),
175 overview_started_(false), 190 overview_started_(false),
176 original_transform_(window->layer()->GetTargetTransform()), 191 original_transform_(window->layer()->GetTargetTransform()),
177 original_opacity_(window->layer()->GetTargetOpacity()) { 192 original_opacity_(window->layer()->GetTargetOpacity()) {
178 } 193 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 window->SetTransform(new_transform); 310 window->SetTransform(new_transform);
296 } 311 }
297 } 312 }
298 313
299 void ScopedTransformOverviewWindow::SetOpacity(float opacity) { 314 void ScopedTransformOverviewWindow::SetOpacity(float opacity) {
300 for (const auto& window : GetTransientTreeIterator(window_)) { 315 for (const auto& window : GetTransientTreeIterator(window_)) {
301 window->layer()->SetOpacity(opacity); 316 window->layer()->SetOpacity(opacity);
302 } 317 }
303 } 318 }
304 319
320 void ScopedTransformOverviewWindow::Scroll(int delta_x) {
321 const float opacity = CalculateOpacityFromScrollDistance(delta_x);
322
323 ScopedOverviewAnimationSettings animation_settings(
324 OverviewAnimationType::SELECTOR_ITEM_SCROLL,
325 window());
326 gfx::Transform new_transform;
327 new_transform.Translate(delta_x, 0);
328 new_transform.PreconcatTransform(get_overview_transform());
329 SetTransform(window()->GetRootWindow(), new_transform);
330
331 SetOpacity(opacity);
332 }
333
334 void ScopedTransformOverviewWindow::CancelScroll() {
335 ScopedOverviewAnimationSettings animation_settings(
336 OverviewAnimationType::SELECTOR_ITEM_SCROLL_CANCEL,
337 window());
338
339 // The target opacity is set before the transform so that the
340 // WindowSelectorItem::OnWindowTransformed handler can properly
341 // update the opacity of the close button to the window's target
342 // opacity.
343 SetOpacity(1.0);
344 SetTransform(window()->GetRootWindow(),
345 get_overview_transform());
346 }
347
305 void ScopedTransformOverviewWindow::Select() { 348 void ScopedTransformOverviewWindow::Select() {
306 wm::GetWindowState(window_)->Activate(); 349 wm::GetWindowState(window_)->Activate();
307 } 350 }
308 351
309 void ScopedTransformOverviewWindow::Close() { 352 void ScopedTransformOverviewWindow::Close() {
310 aura::Window* window = GetTransientRoot(window_); 353 aura::Window* window = GetTransientRoot(window_);
311 views::Widget::GetWidgetForNativeView(window)->Close(); 354 views::Widget::GetWidgetForNativeView(window)->Close();
312 } 355 }
313 356
314 void ScopedTransformOverviewWindow::PrepareForOverview() { 357 void ScopedTransformOverviewWindow::PrepareForOverview() {
315 DCHECK(!overview_started_); 358 DCHECK(!overview_started_);
316 overview_started_ = true; 359 overview_started_ = true;
317 wm::GetWindowState(window_)->set_ignored_by_shelf(true); 360 wm::GetWindowState(window_)->set_ignored_by_shelf(true);
318 RestoreWindow(); 361 RestoreWindow();
319 } 362 }
320 363
321 } // namespace ash 364 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698