summaryrefslogtreecommitdiffstats
path: root/ash/drag_drop
diff options
context:
space:
mode:
authorvarunjain@chromium.org <varunjain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-09 17:31:13 +0000
committervarunjain@chromium.org <varunjain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-09 17:31:13 +0000
commitbb612dbae46c38ff616c3c65a246b9b8f4f4dab8 (patch)
treeb660d2b6af1b6b7f1d0034629eaae49fef44bbbe /ash/drag_drop
parent75209fd0aec385d547e12a4c8338f181faa3f0df (diff)
downloadchromium_src-bb612dbae46c38ff616c3c65a246b9b8f4f4dab8.zip
chromium_src-bb612dbae46c38ff616c3c65a246b9b8f4f4dab8.tar.gz
chromium_src-bb612dbae46c38ff616c3c65a246b9b8f4f4dab8.tar.bz2
aura: animate drag widget at the end of a drag-drop session.
BUG=97845 TEST=manual Review URL: http://codereview.chromium.org/9123019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116872 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/drag_drop')
-rw-r--r--ash/drag_drop/drag_drop_controller.cc42
-rw-r--r--ash/drag_drop/drag_drop_controller.h22
2 files changed, 59 insertions, 5 deletions
diff --git a/ash/drag_drop/drag_drop_controller.cc b/ash/drag_drop/drag_drop_controller.cc
index c1539b6..c983a43 100644
--- a/ash/drag_drop/drag_drop_controller.cc
+++ b/ash/drag_drop/drag_drop_controller.cc
@@ -12,6 +12,7 @@
#include "ui/aura/window.h"
#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/dragdrop/os_exchange_data_provider_aura.h"
+#include "ui/gfx/compositor/layer_animator.h"
#include "ui/gfx/point.h"
#include "ui/gfx/rect.h"
#include "ui/views/views_delegate.h"
@@ -24,6 +25,8 @@ using aura::RootWindow;
namespace {
const gfx::Point kDragDropWidgetOffset(0, 0);
+const base::TimeDelta kDragDropAnimationDuration =
+ base::TimeDelta::FromMilliseconds(250);
}
////////////////////////////////////////////////////////////////////////////////
@@ -44,6 +47,11 @@ DragDropController::DragDropController()
DragDropController::~DragDropController() {
Shell::GetInstance()->RemoveRootWindowEventFilter(this);
Cleanup();
+ if (drag_image_.get()) {
+ aura::Window* window = drag_image_->GetWidget()->GetNativeView();
+ window->layer()->GetAnimator()->RemoveObserver(this);
+ drag_image_.reset();
+ }
}
int DragDropController::StartDragAndDrop(const ui::OSExchangeData& data,
@@ -69,6 +77,7 @@ int DragDropController::StartDragAndDrop(const ui::OSExchangeData& data,
drag_image_->SetWidgetVisible(true);
dragged_window_ = NULL;
+ drag_start_location_ = RootWindow::GetInstance()->last_mouse_location();
if (should_block_during_drag_drop_) {
MessageLoopForUI::current()->RunWithDispatcher(
@@ -114,7 +123,12 @@ void DragDropController::Drop(aura::Window* target,
if ((delegate = aura::client::GetDragDropDelegate(dragged_window_))) {
aura::DropTargetEvent e(*drag_data_, event.location(), drag_operation_);
drag_operation_ = delegate->OnPerformDrop(e);
- // TODO(varunjain): if drag_op is 0, do drag widget flying back animation
+ if (drag_operation_ == 0)
+ StartCanceledAnimation();
+ else
+ drag_image_.reset();
+ } else {
+ drag_image_.reset();
}
Cleanup();
@@ -123,9 +137,9 @@ void DragDropController::Drop(aura::Window* target,
}
void DragDropController::DragCancel() {
- // TODO(varunjain): Do drag widget flying back animation
Cleanup();
drag_operation_ = 0;
+ StartCanceledAnimation();
if (should_block_during_drag_drop_)
MessageLoop::current()->Quit();
}
@@ -169,8 +183,30 @@ ui::TouchStatus DragDropController::PreHandleTouchEvent(
////////////////////////////////////////////////////////////////////////////////
// DragDropController, private:
-void DragDropController::Cleanup() {
+void DragDropController::OnLayerAnimationEnded(
+ const ui::LayerAnimationSequence* sequence) {
+ DCHECK(drag_image_.get());
drag_image_.reset();
+}
+
+void DragDropController::OnLayerAnimationAborted(
+ const ui::LayerAnimationSequence* sequence) {
+ DCHECK(drag_image_.get());
+ drag_image_.reset();
+}
+
+void DragDropController::StartCanceledAnimation() {
+ aura::Window* window = drag_image_->GetWidget()->GetNativeView();
+ ui::LayerAnimator* animator = window->layer()->GetAnimator();
+ animator->set_preemption_strategy(
+ ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
+ animator->AddObserver(this);
+ ui::LayerAnimator::ScopedSettings animation_setter(animator);
+ animation_setter.SetTransitionDuration(kDragDropAnimationDuration);
+ window->SetBounds(gfx::Rect(drag_start_location_, window->bounds().size()));
+}
+
+void DragDropController::Cleanup() {
drag_data_ = NULL;
drag_drop_in_progress_ = false;
}
diff --git a/ash/drag_drop/drag_drop_controller.h b/ash/drag_drop/drag_drop_controller.h
index 1d895d6..dd3b028 100644
--- a/ash/drag_drop/drag_drop_controller.h
+++ b/ash/drag_drop/drag_drop_controller.h
@@ -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.
@@ -12,12 +12,17 @@
#include "ui/aura/event_filter.h"
#include "ui/base/dragdrop/os_exchange_data.h"
#include "ui/base/events.h"
+#include "ui/gfx/compositor/layer_animation_observer.h"
#include "ui/gfx/point.h"
namespace aura {
class Window;
}
+namespace ui {
+class LayerAnimationSequence;
+}
+
namespace ash {
namespace test {
@@ -30,7 +35,8 @@ class DragImageView;
class ASH_EXPORT DragDropController
: public aura::client::DragDropClient,
- public aura::EventFilter {
+ public aura::EventFilter,
+ public ui::LayerAnimationObserver {
public:
DragDropController();
virtual ~DragDropController();
@@ -60,6 +66,17 @@ class ASH_EXPORT DragDropController
private:
friend class ash::test::DragDropControllerTest;
+ // Overridden from ui::LayerAnimationObserver:
+ void OnLayerAnimationEnded(
+ const ui::LayerAnimationSequence* sequence) OVERRIDE;
+ void OnLayerAnimationAborted(
+ const ui::LayerAnimationSequence* sequence) OVERRIDE;
+ void OnLayerAnimationScheduled(
+ const ui::LayerAnimationSequence* sequence) OVERRIDE {}
+
+ // Helper method to start drag widget flying back animation.
+ void StartCanceledAnimation();
+
// Helper method to reset everything.
void Cleanup();
@@ -67,6 +84,7 @@ class ASH_EXPORT DragDropController
const ui::OSExchangeData* drag_data_;
int drag_operation_;
aura::Window* dragged_window_;
+ gfx::Point drag_start_location_;
bool drag_drop_in_progress_;