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

Side by Side Diff: ash/drag_drop/drag_drop_controller.cc

Issue 13041002: Cancel drag upon screen lock (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « ash/drag_drop/drag_drop_controller.h ('k') | ash/drag_drop/drag_drop_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/drag_drop/drag_drop_controller.h" 5 #include "ash/drag_drop/drag_drop_controller.h"
6 6
7 #include "ash/drag_drop/drag_drop_tracker.h" 7 #include "ash/drag_drop/drag_drop_tracker.h"
8 #include "ash/drag_drop/drag_image_view.h" 8 #include "ash/drag_drop/drag_image_view.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/wm/coordinate_conversion.h" 10 #include "ash/wm/coordinate_conversion.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "ui/aura/client/capture_client.h" 14 #include "ui/aura/client/capture_client.h"
15 #include "ui/aura/client/drag_drop_delegate.h" 15 #include "ui/aura/client/drag_drop_delegate.h"
16 #include "ui/aura/env.h" 16 #include "ui/aura/env.h"
17 #include "ui/aura/root_window.h" 17 #include "ui/aura/root_window.h"
18 #include "ui/aura/window.h" 18 #include "ui/aura/window.h"
19 #include "ui/aura/window_delegate.h"
19 #include "ui/base/animation/linear_animation.h" 20 #include "ui/base/animation/linear_animation.h"
20 #include "ui/base/dragdrop/drag_drop_types.h" 21 #include "ui/base/dragdrop/drag_drop_types.h"
21 #include "ui/base/dragdrop/os_exchange_data.h" 22 #include "ui/base/dragdrop/os_exchange_data.h"
22 #include "ui/base/events/event.h" 23 #include "ui/base/events/event.h"
23 #include "ui/base/events/event_utils.h" 24 #include "ui/base/events/event_utils.h"
25 #include "ui/base/hit_test.h"
26 #include "ui/gfx/path.h"
24 #include "ui/gfx/point.h" 27 #include "ui/gfx/point.h"
25 #include "ui/gfx/rect.h" 28 #include "ui/gfx/rect.h"
26 #include "ui/gfx/rect_conversions.h" 29 #include "ui/gfx/rect_conversions.h"
27 #include "ui/views/views_delegate.h" 30 #include "ui/views/views_delegate.h"
28 #include "ui/views/widget/native_widget_aura.h" 31 #include "ui/views/widget/native_widget_aura.h"
29 32
30 namespace ash { 33 namespace ash {
31 namespace internal { 34 namespace internal {
32 35
33 using aura::RootWindow; 36 using aura::RootWindow;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 0, 73 0,
71 0, 74 0,
72 ui::EventTimeForNow(), 75 ui::EventTimeForNow(),
73 ui::GestureEventDetails(ui::ET_GESTURE_END, 0, 0), 76 ui::GestureEventDetails(ui::ET_GESTURE_END, 0, 0),
74 0); 77 0);
75 window->delegate()->OnGestureEvent(&gesture_end); 78 window->delegate()->OnGestureEvent(&gesture_end);
76 } 79 }
77 } 80 }
78 } // namespace 81 } // namespace
79 82
83 class DragDropTrackerDelegate : public aura::WindowDelegate {
84 public:
85 explicit DragDropTrackerDelegate(DragDropController* controller)
86 : drag_drop_controller_(controller) {}
87 virtual ~DragDropTrackerDelegate() {}
88
89 // Overridden from WindowDelegate:
90 virtual gfx::Size GetMinimumSize() const OVERRIDE {
91 return gfx::Size();
92 }
93
94 virtual gfx::Size GetMaximumSize() const OVERRIDE {
95 return gfx::Size();
96 }
97
98 virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
99 const gfx::Rect& new_bounds) OVERRIDE {}
100 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE {
101 return gfx::kNullCursor;
102 }
103 virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE {
104 return HTCAPTION;
105 }
106 virtual bool ShouldDescendIntoChildForEventHandling(
107 aura::Window* child,
108 const gfx::Point& location) OVERRIDE {
109 return true;
110 }
111 virtual bool CanFocus() OVERRIDE { return true; }
112 virtual void OnCaptureLost() OVERRIDE {
113 if (drag_drop_controller_->IsDragDropInProgress())
114 drag_drop_controller_->DragCancel();
115 }
116 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
117 }
118 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE {}
119 virtual void OnWindowDestroying() OVERRIDE {}
120 virtual void OnWindowDestroyed() OVERRIDE {}
121 virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE {}
122 virtual bool HasHitTestMask() const OVERRIDE {
123 return true;
124 }
125 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {
126 DCHECK(mask->isEmpty());
127 }
128 virtual scoped_refptr<ui::Texture> CopyTexture() OVERRIDE {
129 return scoped_refptr<ui::Texture>();
130 }
131
132 private:
133 DragDropController* drag_drop_controller_;
134
135 DISALLOW_COPY_AND_ASSIGN(DragDropTrackerDelegate);
136 };
137
80 //////////////////////////////////////////////////////////////////////////////// 138 ////////////////////////////////////////////////////////////////////////////////
81 // DragDropController, public: 139 // DragDropController, public:
82 140
83 DragDropController::DragDropController() 141 DragDropController::DragDropController()
84 : drag_image_(NULL), 142 : drag_image_(NULL),
85 drag_data_(NULL), 143 drag_data_(NULL),
86 drag_operation_(0), 144 drag_operation_(0),
87 drag_window_(NULL), 145 drag_window_(NULL),
88 drag_source_window_(NULL), 146 drag_source_window_(NULL),
89 should_block_during_drag_drop_(true), 147 should_block_during_drag_drop_(true),
148 ALLOW_THIS_IN_INITIALIZER_LIST(
149 drag_drop_window_delegate_(new DragDropTrackerDelegate(this))),
90 current_drag_event_source_(ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE), 150 current_drag_event_source_(ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE),
91 weak_factory_(this) { 151 weak_factory_(this) {
92 Shell::GetInstance()->AddPreTargetHandler(this); 152 Shell::GetInstance()->AddPreTargetHandler(this);
93 } 153 }
94 154
95 DragDropController::~DragDropController() { 155 DragDropController::~DragDropController() {
96 Shell::GetInstance()->RemovePreTargetHandler(this); 156 Shell::GetInstance()->RemovePreTargetHandler(this);
97 Cleanup(); 157 Cleanup();
98 if (cancel_animation_.get()) 158 if (cancel_animation_.get())
99 cancel_animation_->End(); 159 cancel_animation_->End();
(...skipping 11 matching lines...) Expand all
111 if (IsDragDropInProgress()) 171 if (IsDragDropInProgress())
112 return 0; 172 return 0;
113 173
114 const ui::OSExchangeData::Provider* provider = &data.provider(); 174 const ui::OSExchangeData::Provider* provider = &data.provider();
115 // We do not support touch drag/drop without a drag image. 175 // We do not support touch drag/drop without a drag image.
116 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH && 176 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH &&
117 provider->GetDragImage().size().IsEmpty()) 177 provider->GetDragImage().size().IsEmpty())
118 return 0; 178 return 0;
119 179
120 current_drag_event_source_ = source; 180 current_drag_event_source_ = source;
121 DragDropTracker* tracker = new DragDropTracker(root_window); 181 DragDropTracker* tracker =
182 new DragDropTracker(root_window, drag_drop_window_delegate_.get());
122 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH) { 183 if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH) {
123 // We need to transfer the current gesture sequence and the GR's touch event 184 // We need to transfer the current gesture sequence and the GR's touch event
124 // queue to the |drag_drop_tracker_|'s capture window so that when it takes 185 // queue to the |drag_drop_tracker_|'s capture window so that when it takes
125 // capture, it still gets a valid gesture state. 186 // capture, it still gets a valid gesture state.
126 root_window->gesture_recognizer()->TransferEventsTo(source_window, 187 root_window->gesture_recognizer()->TransferEventsTo(source_window,
127 tracker->capture_window()); 188 tracker->capture_window());
128 // We also send a gesture end to the source window so it can clear state. 189 // We also send a gesture end to the source window so it can clear state.
129 // TODO(varunjain): Remove this whole block when gesture sequence 190 // TODO(varunjain): Remove this whole block when gesture sequence
130 // transferring is properly done in the GR (http://crbug.com/160558) 191 // transferring is properly done in the GR (http://crbug.com/160558)
131 DispatchGestureEndToWindow(source_window); 192 DispatchGestureEndToWindow(source_window);
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 drag_window_->RemoveObserver(this); 555 drag_window_->RemoveObserver(this);
495 drag_window_ = NULL; 556 drag_window_ = NULL;
496 drag_data_ = NULL; 557 drag_data_ = NULL;
497 // Cleanup can be called again while deleting DragDropTracker, so use Pass 558 // Cleanup can be called again while deleting DragDropTracker, so use Pass
498 // instead of reset to avoid double free. 559 // instead of reset to avoid double free.
499 drag_drop_tracker_.Pass(); 560 drag_drop_tracker_.Pass();
500 } 561 }
501 562
502 } // namespace internal 563 } // namespace internal
503 } // namespace ash 564 } // namespace ash
OLDNEW
« no previous file with comments | « ash/drag_drop/drag_drop_controller.h ('k') | ash/drag_drop/drag_drop_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698