diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-12 20:22:08 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-12 20:22:08 +0000 |
commit | f7ed9ab9a9cd0403bef9cb0174ed7cb7437e2daf (patch) | |
tree | 0477a569672f2e19fddd075b78d56a4b9a8c5637 | |
parent | 378f29cc2d3f381a0304bfe176c007a40454a491 (diff) | |
download | chromium_src-f7ed9ab9a9cd0403bef9cb0174ed7cb7437e2daf.zip chromium_src-f7ed9ab9a9cd0403bef9cb0174ed7cb7437e2daf.tar.gz chromium_src-f7ed9ab9a9cd0403bef9cb0174ed7cb7437e2daf.tar.bz2 |
ash: Add some experimental support for gesture-fling to snap/minimize/maximize windows.
BUG=121140
TEST=none
Review URL: https://chromiumcodereview.appspot.com/10067011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132042 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ash/wm/default_window_resizer.h | 15 | ||||
-rw-r--r-- | ash/wm/toplevel_window_event_filter.cc | 43 | ||||
-rw-r--r-- | ui/base/animation/tween.cc | 4 |
3 files changed, 49 insertions, 13 deletions
diff --git a/ash/wm/default_window_resizer.h b/ash/wm/default_window_resizer.h index 0f6494b..ea7d114 100644 --- a/ash/wm/default_window_resizer.h +++ b/ash/wm/default_window_resizer.h @@ -20,16 +20,6 @@ class RootWindowEventFilter; // windows coordiantes. class ASH_EXPORT DefaultWindowResizer : public WindowResizer { public: - // Constants to identify the type of resize. - static const int kBoundsChange_None; - static const int kBoundsChange_Repositions; - static const int kBoundsChange_Resizes; - - // Used to indicate which direction the resize occurs in. - static const int kBoundsChangeDirection_None; - static const int kBoundsChangeDirection_Horizontal; - static const int kBoundsChangeDirection_Vertical; - virtual ~DefaultWindowResizer(); // Creates a new DefaultWindowResizer. The caller takes ownership of the @@ -42,6 +32,11 @@ class ASH_EXPORT DefaultWindowResizer : public WindowResizer { // Returns true if the drag will result in changing the window in anyway. bool is_resizable() const { return details_.is_resizable; } + bool changed_size() const { + return !(details_.bounds_change & kBoundsChange_Repositions); + } + aura::Window* target_window() const { return details_.window; } + // WindowResizer overides: virtual void Drag(const gfx::Point& location) OVERRIDE; virtual void CompleteDrag() OVERRIDE; diff --git a/ash/wm/toplevel_window_event_filter.cc b/ash/wm/toplevel_window_event_filter.cc index 962698ff..53e388f 100644 --- a/ash/wm/toplevel_window_event_filter.cc +++ b/ash/wm/toplevel_window_event_filter.cc @@ -10,6 +10,7 @@ #include "ash/wm/resize_shadow_controller.h" #include "ash/wm/window_resizer.h" #include "ash/wm/window_util.h" +#include "ash/wm/workspace/snap_sizer.h" #include "base/message_loop.h" #include "ui/aura/client/aura_constants.h" #include "ui/aura/env.h" @@ -20,8 +21,15 @@ #include "ui/base/cursor/cursor.h" #include "ui/base/hit_test.h" #include "ui/base/ui_base_types.h" +#include "ui/gfx/compositor/layer.h" +#include "ui/gfx/compositor/scoped_layer_animation_settings.h" #include "ui/gfx/screen.h" +namespace { +const double kMinHorizVelocityForWindowSwipe = 1100; +const double kMinVertVelocityForWindowMinimize = 1000; +} + namespace ash { namespace { @@ -142,7 +150,40 @@ ui::GestureStatus ToplevelWindowEventFilter::PreHandleGestureEvent( case ui::ET_GESTURE_SCROLL_END: { if (!in_gesture_resize_) return ui::GESTURE_STATUS_UNKNOWN; - CompleteDrag(DRAG_COMPLETE); + DefaultWindowResizer* default_resizer = + static_cast<DefaultWindowResizer*>(window_resizer_.get()); + bool changed_size = + default_resizer ? default_resizer->changed_size() : false; + aura::Window* window = + default_resizer ? default_resizer->target_window() : NULL; + bool drag_done = false; + + if (window && !changed_size) { + if (fabs(event->delta_y()) > kMinVertVelocityForWindowMinimize) { + // Minimize/maximize. + window->SetProperty(aura::client::kShowStateKey, + event->delta_y() > 0 ? ui::SHOW_STATE_MINIMIZED : + ui::SHOW_STATE_MAXIMIZED); + drag_done = true; + } else if (fabs(event->delta_x()) > kMinHorizVelocityForWindowSwipe) { + // Snap left/right. + internal::SnapSizer sizer(window, + gfx::Point(), + event->delta_x() < 0 ? internal::SnapSizer::LEFT_EDGE : + internal::SnapSizer::RIGHT_EDGE, + Shell::GetInstance()->GetGridSize()); + + ui::ScopedLayerAnimationSettings scoped_setter( + window->layer()->GetAnimator()); + scoped_setter.SetPreemptionStrategy( + ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); + window->SetBounds(sizer.target_bounds()); + drag_done = true; + } + } + + if (!drag_done) + CompleteDrag(DRAG_COMPLETE); in_gesture_resize_ = false; break; } diff --git a/ui/base/animation/tween.cc b/ui/base/animation/tween.cc index b8f4385..c1e4a47 100644 --- a/ui/base/animation/tween.cc +++ b/ui/base/animation/tween.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -37,7 +37,7 @@ double Tween::CalculateValue(Tween::Type type, double state) { case EASE_OUT_SNAP: state = 0.95 * (1.0 - pow(1.0 - state, 2)); - break; + return state; case EASE_OUT: return 1.0 - pow(1.0 - state, 2); |