OLD | NEW |
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/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 | 64 |
65 int num_drag_enters_; | 65 int num_drag_enters_; |
66 int num_drag_exits_; | 66 int num_drag_exits_; |
67 int num_drag_updates_; | 67 int num_drag_updates_; |
68 int num_drops_; | 68 int num_drops_; |
69 bool drag_done_received_; | 69 bool drag_done_received_; |
70 bool long_tap_received_; | 70 bool long_tap_received_; |
71 | 71 |
72 private: | 72 private: |
73 // View overrides: | 73 // View overrides: |
74 virtual int GetDragOperations(const gfx::Point& press_pt) OVERRIDE { | 74 virtual int GetDragOperations(const gfx::Point& press_pt) override { |
75 return ui::DragDropTypes::DRAG_COPY; | 75 return ui::DragDropTypes::DRAG_COPY; |
76 } | 76 } |
77 | 77 |
78 virtual void WriteDragData(const gfx::Point& p, | 78 virtual void WriteDragData(const gfx::Point& p, |
79 OSExchangeData* data) OVERRIDE { | 79 OSExchangeData* data) override { |
80 data->SetString(base::UTF8ToUTF16("I am being dragged")); | 80 data->SetString(base::UTF8ToUTF16("I am being dragged")); |
81 gfx::ImageSkiaRep image_rep(gfx::Size(10, 20), 1.0f); | 81 gfx::ImageSkiaRep image_rep(gfx::Size(10, 20), 1.0f); |
82 gfx::ImageSkia image_skia(image_rep); | 82 gfx::ImageSkia image_skia(image_rep); |
83 | 83 |
84 drag_utils::SetDragImageOnDataObject(image_skia, gfx::Vector2d(), data); | 84 drag_utils::SetDragImageOnDataObject(image_skia, gfx::Vector2d(), data); |
85 } | 85 } |
86 | 86 |
87 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE { | 87 virtual bool OnMousePressed(const ui::MouseEvent& event) override { |
88 return true; | 88 return true; |
89 } | 89 } |
90 | 90 |
91 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { | 91 virtual void OnGestureEvent(ui::GestureEvent* event) override { |
92 if (event->type() == ui::ET_GESTURE_LONG_TAP) | 92 if (event->type() == ui::ET_GESTURE_LONG_TAP) |
93 long_tap_received_ = true; | 93 long_tap_received_ = true; |
94 return; | 94 return; |
95 } | 95 } |
96 | 96 |
97 virtual bool GetDropFormats( | 97 virtual bool GetDropFormats( |
98 int* formats, | 98 int* formats, |
99 std::set<OSExchangeData::CustomFormat>* custom_formats) OVERRIDE { | 99 std::set<OSExchangeData::CustomFormat>* custom_formats) override { |
100 *formats = ui::OSExchangeData::STRING; | 100 *formats = ui::OSExchangeData::STRING; |
101 return true; | 101 return true; |
102 } | 102 } |
103 | 103 |
104 virtual bool CanDrop(const OSExchangeData& data) OVERRIDE { | 104 virtual bool CanDrop(const OSExchangeData& data) override { |
105 return true; | 105 return true; |
106 } | 106 } |
107 | 107 |
108 virtual void OnDragEntered(const ui::DropTargetEvent& event) OVERRIDE { | 108 virtual void OnDragEntered(const ui::DropTargetEvent& event) override { |
109 num_drag_enters_++; | 109 num_drag_enters_++; |
110 } | 110 } |
111 | 111 |
112 virtual int OnDragUpdated(const ui::DropTargetEvent& event) OVERRIDE { | 112 virtual int OnDragUpdated(const ui::DropTargetEvent& event) override { |
113 num_drag_updates_++; | 113 num_drag_updates_++; |
114 return ui::DragDropTypes::DRAG_COPY; | 114 return ui::DragDropTypes::DRAG_COPY; |
115 } | 115 } |
116 | 116 |
117 virtual void OnDragExited() OVERRIDE { | 117 virtual void OnDragExited() override { |
118 num_drag_exits_++; | 118 num_drag_exits_++; |
119 } | 119 } |
120 | 120 |
121 virtual int OnPerformDrop(const ui::DropTargetEvent& event) OVERRIDE { | 121 virtual int OnPerformDrop(const ui::DropTargetEvent& event) override { |
122 num_drops_++; | 122 num_drops_++; |
123 return ui::DragDropTypes::DRAG_COPY; | 123 return ui::DragDropTypes::DRAG_COPY; |
124 } | 124 } |
125 | 125 |
126 virtual void OnDragDone() OVERRIDE { | 126 virtual void OnDragDone() override { |
127 drag_done_received_ = true; | 127 drag_done_received_ = true; |
128 } | 128 } |
129 | 129 |
130 DISALLOW_COPY_AND_ASSIGN(DragTestView); | 130 DISALLOW_COPY_AND_ASSIGN(DragTestView); |
131 }; | 131 }; |
132 | 132 |
133 class CompletableLinearAnimation : public gfx::LinearAnimation { | 133 class CompletableLinearAnimation : public gfx::LinearAnimation { |
134 public: | 134 public: |
135 CompletableLinearAnimation(int duration, | 135 CompletableLinearAnimation(int duration, |
136 int frame_rate, | 136 int frame_rate, |
(...skipping 21 matching lines...) Expand all Loading... |
158 drag_canceled_ = false; | 158 drag_canceled_ = false; |
159 drag_string_.clear(); | 159 drag_string_.clear(); |
160 } | 160 } |
161 | 161 |
162 virtual int StartDragAndDrop( | 162 virtual int StartDragAndDrop( |
163 const ui::OSExchangeData& data, | 163 const ui::OSExchangeData& data, |
164 aura::Window* root_window, | 164 aura::Window* root_window, |
165 aura::Window* source_window, | 165 aura::Window* source_window, |
166 const gfx::Point& location, | 166 const gfx::Point& location, |
167 int operation, | 167 int operation, |
168 ui::DragDropTypes::DragEventSource source) OVERRIDE { | 168 ui::DragDropTypes::DragEventSource source) override { |
169 drag_start_received_ = true; | 169 drag_start_received_ = true; |
170 data.GetString(&drag_string_); | 170 data.GetString(&drag_string_); |
171 return DragDropController::StartDragAndDrop( | 171 return DragDropController::StartDragAndDrop( |
172 data, root_window, source_window, location, operation, source); | 172 data, root_window, source_window, location, operation, source); |
173 } | 173 } |
174 | 174 |
175 virtual void DragUpdate(aura::Window* target, | 175 virtual void DragUpdate(aura::Window* target, |
176 const ui::LocatedEvent& event) OVERRIDE { | 176 const ui::LocatedEvent& event) override { |
177 DragDropController::DragUpdate(target, event); | 177 DragDropController::DragUpdate(target, event); |
178 num_drag_updates_++; | 178 num_drag_updates_++; |
179 } | 179 } |
180 | 180 |
181 virtual void Drop(aura::Window* target, | 181 virtual void Drop(aura::Window* target, |
182 const ui::LocatedEvent& event) OVERRIDE { | 182 const ui::LocatedEvent& event) override { |
183 DragDropController::Drop(target, event); | 183 DragDropController::Drop(target, event); |
184 drop_received_ = true; | 184 drop_received_ = true; |
185 } | 185 } |
186 | 186 |
187 virtual void DragCancel() OVERRIDE { | 187 virtual void DragCancel() override { |
188 DragDropController::DragCancel(); | 188 DragDropController::DragCancel(); |
189 drag_canceled_ = true; | 189 drag_canceled_ = true; |
190 } | 190 } |
191 | 191 |
192 virtual gfx::LinearAnimation* CreateCancelAnimation( | 192 virtual gfx::LinearAnimation* CreateCancelAnimation( |
193 int duration, | 193 int duration, |
194 int frame_rate, | 194 int frame_rate, |
195 gfx::AnimationDelegate* delegate) OVERRIDE { | 195 gfx::AnimationDelegate* delegate) override { |
196 return new CompletableLinearAnimation(duration, frame_rate, delegate); | 196 return new CompletableLinearAnimation(duration, frame_rate, delegate); |
197 } | 197 } |
198 | 198 |
199 virtual void DoDragCancel(int animation_duration_ms) OVERRIDE { | 199 virtual void DoDragCancel(int animation_duration_ms) override { |
200 DragDropController::DoDragCancel(animation_duration_ms); | 200 DragDropController::DoDragCancel(animation_duration_ms); |
201 drag_canceled_ = true; | 201 drag_canceled_ = true; |
202 } | 202 } |
203 | 203 |
204 bool drag_start_received_; | 204 bool drag_start_received_; |
205 int num_drag_updates_; | 205 int num_drag_updates_; |
206 bool drop_received_; | 206 bool drop_received_; |
207 bool drag_canceled_; | 207 bool drag_canceled_; |
208 base::string16 drag_string_; | 208 base::string16 drag_string_; |
209 | 209 |
210 private: | 210 private: |
211 DISALLOW_COPY_AND_ASSIGN(TestDragDropController); | 211 DISALLOW_COPY_AND_ASSIGN(TestDragDropController); |
212 }; | 212 }; |
213 | 213 |
214 class TestNativeWidgetAura : public views::NativeWidgetAura { | 214 class TestNativeWidgetAura : public views::NativeWidgetAura { |
215 public: | 215 public: |
216 explicit TestNativeWidgetAura(views::internal::NativeWidgetDelegate* delegate) | 216 explicit TestNativeWidgetAura(views::internal::NativeWidgetDelegate* delegate) |
217 : NativeWidgetAura(delegate), | 217 : NativeWidgetAura(delegate), |
218 check_if_capture_lost_(false) { | 218 check_if_capture_lost_(false) { |
219 } | 219 } |
220 | 220 |
221 void set_check_if_capture_lost(bool value) { | 221 void set_check_if_capture_lost(bool value) { |
222 check_if_capture_lost_ = value; | 222 check_if_capture_lost_ = value; |
223 } | 223 } |
224 | 224 |
225 virtual void OnCaptureLost() OVERRIDE { | 225 virtual void OnCaptureLost() override { |
226 DCHECK(!check_if_capture_lost_); | 226 DCHECK(!check_if_capture_lost_); |
227 views::NativeWidgetAura::OnCaptureLost(); | 227 views::NativeWidgetAura::OnCaptureLost(); |
228 } | 228 } |
229 | 229 |
230 private: | 230 private: |
231 bool check_if_capture_lost_; | 231 bool check_if_capture_lost_; |
232 | 232 |
233 DISALLOW_COPY_AND_ASSIGN(TestNativeWidgetAura); | 233 DISALLOW_COPY_AND_ASSIGN(TestNativeWidgetAura); |
234 }; | 234 }; |
235 | 235 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 CHECK(!details.dispatcher_destroyed); | 285 CHECK(!details.dispatcher_destroyed); |
286 } | 286 } |
287 | 287 |
288 } // namespace | 288 } // namespace |
289 | 289 |
290 class DragDropControllerTest : public AshTestBase { | 290 class DragDropControllerTest : public AshTestBase { |
291 public: | 291 public: |
292 DragDropControllerTest() : AshTestBase() {} | 292 DragDropControllerTest() : AshTestBase() {} |
293 virtual ~DragDropControllerTest() {} | 293 virtual ~DragDropControllerTest() {} |
294 | 294 |
295 virtual void SetUp() OVERRIDE { | 295 virtual void SetUp() override { |
296 AshTestBase::SetUp(); | 296 AshTestBase::SetUp(); |
297 drag_drop_controller_.reset(new TestDragDropController); | 297 drag_drop_controller_.reset(new TestDragDropController); |
298 drag_drop_controller_->set_should_block_during_drag_drop(false); | 298 drag_drop_controller_->set_should_block_during_drag_drop(false); |
299 aura::client::SetDragDropClient(Shell::GetPrimaryRootWindow(), | 299 aura::client::SetDragDropClient(Shell::GetPrimaryRootWindow(), |
300 drag_drop_controller_.get()); | 300 drag_drop_controller_.get()); |
301 } | 301 } |
302 | 302 |
303 virtual void TearDown() OVERRIDE { | 303 virtual void TearDown() override { |
304 aura::client::SetDragDropClient(Shell::GetPrimaryRootWindow(), NULL); | 304 aura::client::SetDragDropClient(Shell::GetPrimaryRootWindow(), NULL); |
305 drag_drop_controller_.reset(); | 305 drag_drop_controller_.reset(); |
306 AshTestBase::TearDown(); | 306 AshTestBase::TearDown(); |
307 } | 307 } |
308 | 308 |
309 void UpdateDragData(ui::OSExchangeData* data) { | 309 void UpdateDragData(ui::OSExchangeData* data) { |
310 drag_drop_controller_->drag_data_ = data; | 310 drag_drop_controller_->drag_data_ = data; |
311 } | 311 } |
312 | 312 |
313 aura::Window* GetDragWindow() { | 313 aura::Window* GetDragWindow() { |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 EXPECT_FALSE(drag_view->long_tap_received_); | 963 EXPECT_FALSE(drag_view->long_tap_received_); |
964 DispatchGesture(ui::ET_GESTURE_LONG_TAP, point); | 964 DispatchGesture(ui::ET_GESTURE_LONG_TAP, point); |
965 CompleteCancelAnimation(); | 965 CompleteCancelAnimation(); |
966 EXPECT_TRUE(drag_view->long_tap_received_); | 966 EXPECT_TRUE(drag_view->long_tap_received_); |
967 } | 967 } |
968 | 968 |
969 namespace { | 969 namespace { |
970 | 970 |
971 class DragImageWindowObserver : public aura::WindowObserver { | 971 class DragImageWindowObserver : public aura::WindowObserver { |
972 public: | 972 public: |
973 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { | 973 virtual void OnWindowDestroying(aura::Window* window) override { |
974 window_location_on_destroying_ = window->GetBoundsInScreen().origin(); | 974 window_location_on_destroying_ = window->GetBoundsInScreen().origin(); |
975 } | 975 } |
976 | 976 |
977 gfx::Point window_location_on_destroying() const { | 977 gfx::Point window_location_on_destroying() const { |
978 return window_location_on_destroying_; | 978 return window_location_on_destroying_; |
979 } | 979 } |
980 | 980 |
981 public: | 981 public: |
982 gfx::Point window_location_on_destroying_; | 982 gfx::Point window_location_on_destroying_; |
983 }; | 983 }; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1075 EXPECT_EQ("405,405", observer.window_location_on_destroying().ToString()); | 1075 EXPECT_EQ("405,405", observer.window_location_on_destroying().ToString()); |
1076 } | 1076 } |
1077 for (aura::Window::Windows::iterator iter = root_windows.begin(); | 1077 for (aura::Window::Windows::iterator iter = root_windows.begin(); |
1078 iter != root_windows.end(); ++iter) { | 1078 iter != root_windows.end(); ++iter) { |
1079 aura::client::SetDragDropClient(*iter, NULL); | 1079 aura::client::SetDragDropClient(*iter, NULL); |
1080 } | 1080 } |
1081 } | 1081 } |
1082 | 1082 |
1083 } // namespace test | 1083 } // namespace test |
1084 } // namespace aura | 1084 } // namespace aura |
OLD | NEW |