| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <map> | 5 #include <map> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 // Include views_test_base.h first because the definition of None in X.h | 8 // Include views_test_base.h first because the definition of None in X.h |
| 9 // conflicts with the definition of None in gtest-type-util.h | 9 // conflicts with the definition of None in gtest-type-util.h |
| 10 #include "ui/views/test/views_test_base.h" | 10 #include "ui/views/test/views_test_base.h" |
| 11 | 11 |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/run_loop.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 15 #include "ui/aura/window_tree_host.h" | 16 #include "ui/aura/window_tree_host.h" |
| 16 #include "ui/base/dragdrop/os_exchange_data.h" | 17 #include "ui/base/dragdrop/os_exchange_data.h" |
| 17 #include "ui/base/x/x11_util.h" | 18 #include "ui/base/x/x11_util.h" |
| 18 #include "ui/gfx/x/x11_atom_cache.h" | 19 #include "ui/gfx/x/x11_atom_cache.h" |
| 19 #include "ui/gfx/x/x11_types.h" | 20 #include "ui/gfx/x/x11_types.h" |
| 20 #include "ui/views/widget/desktop_aura/desktop_cursor_loader_updater.h" | 21 #include "ui/views/widget/desktop_aura/desktop_cursor_loader_updater.h" |
| 21 #include "ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.h" | 22 #include "ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.h" |
| 22 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h" | 23 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h" |
| 23 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 24 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
| 25 #include "ui/views/widget/desktop_aura/x11_move_loop.h" |
| 24 #include "ui/views/widget/widget.h" | 26 #include "ui/views/widget/widget.h" |
| 25 | 27 |
| 26 #include <X11/Xlib.h> | 28 #include <X11/Xlib.h> |
| 27 | 29 |
| 28 namespace views { | 30 namespace views { |
| 29 | 31 |
| 30 namespace { | 32 namespace { |
| 31 | 33 |
| 32 const char* kAtomsToCache[] = { | 34 const char* kAtomsToCache[] = { |
| 33 "XdndActionCopy", | 35 "XdndActionCopy", |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 ::Window xid_; | 68 ::Window xid_; |
| 67 | 69 |
| 68 // Not owned. | 70 // Not owned. |
| 69 TestDragDropClient* client_; | 71 TestDragDropClient* client_; |
| 70 | 72 |
| 71 std::vector<XClientMessageEvent> events_; | 73 std::vector<XClientMessageEvent> events_; |
| 72 | 74 |
| 73 DISALLOW_COPY_AND_ASSIGN(ClientMessageEventCollector); | 75 DISALLOW_COPY_AND_ASSIGN(ClientMessageEventCollector); |
| 74 }; | 76 }; |
| 75 | 77 |
| 78 // An implementation of X11MoveLoop where RunMoveLoop() always starts the move |
| 79 // loop. |
| 80 class TestMoveLoop : public X11MoveLoop { |
| 81 public: |
| 82 explicit TestMoveLoop(X11MoveLoopDelegate* delegate); |
| 83 virtual ~TestMoveLoop(); |
| 84 |
| 85 // Returns true if the move loop is running. |
| 86 bool IsRunning() const; |
| 87 |
| 88 // X11MoveLoop: |
| 89 virtual bool RunMoveLoop(aura::Window* window, |
| 90 gfx::NativeCursor cursor) OVERRIDE; |
| 91 virtual void UpdateCursor(gfx::NativeCursor cursor) OVERRIDE; |
| 92 virtual void EndMoveLoop() OVERRIDE; |
| 93 virtual void SetDragImage(const gfx::ImageSkia& image, |
| 94 const gfx::Vector2dF& offset) OVERRIDE; |
| 95 |
| 96 private: |
| 97 // Not owned. |
| 98 X11MoveLoopDelegate* delegate_; |
| 99 |
| 100 // Ends the move loop. |
| 101 base::Closure quit_closure_; |
| 102 |
| 103 bool is_running_; |
| 104 }; |
| 105 |
| 76 // Implementation of DesktopDragDropClientAuraX11 which works with a fake | 106 // Implementation of DesktopDragDropClientAuraX11 which works with a fake |
| 77 // |DesktopDragDropClientAuraX11::source_current_window_|. | 107 // |DesktopDragDropClientAuraX11::source_current_window_|. |
| 78 class TestDragDropClient : public DesktopDragDropClientAuraX11 { | 108 class TestDragDropClient : public DesktopDragDropClientAuraX11 { |
| 79 public: | 109 public: |
| 80 // The location in screen coordinates used for the synthetic mouse moves | 110 // The location in screen coordinates used for the synthetic mouse moves |
| 81 // generated in SetTopmostXWindowAndMoveMouse(). | 111 // generated in SetTopmostXWindowAndMoveMouse(). |
| 82 static const int kMouseMoveX; | 112 static const int kMouseMoveX; |
| 83 static const int kMouseMoveY; | 113 static const int kMouseMoveY; |
| 84 | 114 |
| 85 TestDragDropClient(aura::Window* window, | 115 TestDragDropClient(aura::Window* window, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 115 bool accepted_drop, | 145 bool accepted_drop, |
| 116 ::Atom performed_action); | 146 ::Atom performed_action); |
| 117 | 147 |
| 118 // Sets |xid| as the topmost window at the current mouse position and | 148 // Sets |xid| as the topmost window at the current mouse position and |
| 119 // generates a synthetic mouse move. | 149 // generates a synthetic mouse move. |
| 120 void SetTopmostXWindowAndMoveMouse(::Window xid); | 150 void SetTopmostXWindowAndMoveMouse(::Window xid); |
| 121 | 151 |
| 122 // Returns true if the move loop is running. | 152 // Returns true if the move loop is running. |
| 123 bool IsMoveLoopRunning(); | 153 bool IsMoveLoopRunning(); |
| 124 | 154 |
| 125 // DesktopDragDropClientAuraX11: | |
| 126 virtual int StartDragAndDrop( | |
| 127 const ui::OSExchangeData& data, | |
| 128 aura::Window* root_window, | |
| 129 aura::Window* source_window, | |
| 130 const gfx::Point& root_location, | |
| 131 int operation, | |
| 132 ui::DragDropTypes::DragEventSource source) OVERRIDE; | |
| 133 virtual void OnMoveLoopEnded() OVERRIDE; | |
| 134 | |
| 135 private: | 155 private: |
| 136 // DesktopDragDropClientAuraX11: | 156 // DesktopDragDropClientAuraX11: |
| 157 virtual scoped_ptr<X11MoveLoop> CreateMoveLoop( |
| 158 X11MoveLoopDelegate* delegate) OVERRIDE; |
| 137 virtual ::Window FindWindowFor(const gfx::Point& screen_point) OVERRIDE; | 159 virtual ::Window FindWindowFor(const gfx::Point& screen_point) OVERRIDE; |
| 138 virtual void SendXClientEvent(::Window xid, XEvent* event) OVERRIDE; | 160 virtual void SendXClientEvent(::Window xid, XEvent* event) OVERRIDE; |
| 139 | 161 |
| 140 // The XID of the window which initiated the drag. | 162 // The XID of the window which initiated the drag. |
| 141 ::Window source_xid_; | 163 ::Window source_xid_; |
| 142 | 164 |
| 143 // The XID of the window which is simulated to be the topmost window at the | 165 // The XID of the window which is simulated to be the topmost window at the |
| 144 // current mouse position. | 166 // current mouse position. |
| 145 ::Window target_xid_; | 167 ::Window target_xid_; |
| 146 | 168 |
| 147 // Whether the move loop is running. | 169 // The move loop. Not owned. |
| 148 bool move_loop_running_; | 170 TestMoveLoop* loop_; |
| 149 | 171 |
| 150 // Map of ::Windows to the collector which intercepts XClientMessageEvents | 172 // Map of ::Windows to the collector which intercepts XClientMessageEvents |
| 151 // for that window. | 173 // for that window. |
| 152 std::map< ::Window, ClientMessageEventCollector*> collectors_; | 174 std::map< ::Window, ClientMessageEventCollector*> collectors_; |
| 153 | 175 |
| 154 ui::X11AtomCache atom_cache_; | 176 ui::X11AtomCache atom_cache_; |
| 155 | 177 |
| 156 DISALLOW_COPY_AND_ASSIGN(TestDragDropClient); | 178 DISALLOW_COPY_AND_ASSIGN(TestDragDropClient); |
| 157 }; | 179 }; |
| 158 | 180 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 176 to_return.swap(events_); | 198 to_return.swap(events_); |
| 177 return to_return; | 199 return to_return; |
| 178 } | 200 } |
| 179 | 201 |
| 180 void ClientMessageEventCollector::RecordEvent( | 202 void ClientMessageEventCollector::RecordEvent( |
| 181 const XClientMessageEvent& event) { | 203 const XClientMessageEvent& event) { |
| 182 events_.push_back(event); | 204 events_.push_back(event); |
| 183 } | 205 } |
| 184 | 206 |
| 185 /////////////////////////////////////////////////////////////////////////////// | 207 /////////////////////////////////////////////////////////////////////////////// |
| 208 // TestMoveLoop |
| 209 |
| 210 TestMoveLoop::TestMoveLoop(X11MoveLoopDelegate* delegate) |
| 211 : delegate_(delegate), |
| 212 is_running_(false) { |
| 213 } |
| 214 |
| 215 TestMoveLoop::~TestMoveLoop() { |
| 216 } |
| 217 |
| 218 bool TestMoveLoop::IsRunning() const { |
| 219 return is_running_; |
| 220 } |
| 221 |
| 222 bool TestMoveLoop::RunMoveLoop( |
| 223 aura::Window* window, |
| 224 gfx::NativeCursor cursor) { |
| 225 is_running_ = true; |
| 226 base::RunLoop run_loop; |
| 227 quit_closure_ = run_loop.QuitClosure(); |
| 228 run_loop.Run(); |
| 229 return true; |
| 230 } |
| 231 |
| 232 void TestMoveLoop::UpdateCursor(gfx::NativeCursor cursor) { |
| 233 } |
| 234 |
| 235 void TestMoveLoop::EndMoveLoop() { |
| 236 if (is_running_) { |
| 237 delegate_->OnMoveLoopEnded(); |
| 238 is_running_ = false; |
| 239 quit_closure_.Run(); |
| 240 } |
| 241 } |
| 242 |
| 243 void TestMoveLoop::SetDragImage(const gfx::ImageSkia& image, |
| 244 const gfx::Vector2dF& offset) { |
| 245 } |
| 246 |
| 247 /////////////////////////////////////////////////////////////////////////////// |
| 186 // TestDragDropClient | 248 // TestDragDropClient |
| 187 | 249 |
| 188 // static | 250 // static |
| 189 const int TestDragDropClient::kMouseMoveX = 100; | 251 const int TestDragDropClient::kMouseMoveX = 100; |
| 190 | 252 |
| 191 // static | 253 // static |
| 192 const int TestDragDropClient::kMouseMoveY = 200; | 254 const int TestDragDropClient::kMouseMoveY = 200; |
| 193 | 255 |
| 194 TestDragDropClient::TestDragDropClient( | 256 TestDragDropClient::TestDragDropClient( |
| 195 aura::Window* window, | 257 aura::Window* window, |
| 196 DesktopNativeCursorManager* cursor_manager) | 258 DesktopNativeCursorManager* cursor_manager) |
| 197 : DesktopDragDropClientAuraX11(window, | 259 : DesktopDragDropClientAuraX11(window, |
| 198 cursor_manager, | 260 cursor_manager, |
| 199 gfx::GetXDisplay(), | 261 gfx::GetXDisplay(), |
| 200 window->GetHost()->GetAcceleratedWidget()), | 262 window->GetHost()->GetAcceleratedWidget()), |
| 201 source_xid_(window->GetHost()->GetAcceleratedWidget()), | 263 source_xid_(window->GetHost()->GetAcceleratedWidget()), |
| 202 target_xid_(None), | 264 target_xid_(None), |
| 203 move_loop_running_(false), | 265 loop_(NULL), |
| 204 atom_cache_(gfx::GetXDisplay(), kAtomsToCache) { | 266 atom_cache_(gfx::GetXDisplay(), kAtomsToCache) { |
| 205 } | 267 } |
| 206 | 268 |
| 207 TestDragDropClient::~TestDragDropClient() { | 269 TestDragDropClient::~TestDragDropClient() { |
| 208 } | 270 } |
| 209 | 271 |
| 210 Atom TestDragDropClient::GetAtom(const char* name) { | 272 Atom TestDragDropClient::GetAtom(const char* name) { |
| 211 return atom_cache_.GetAtom(name); | 273 return atom_cache_.GetAtom(name); |
| 212 } | 274 } |
| 213 | 275 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 target_xid_ = xid; | 321 target_xid_ = xid; |
| 260 | 322 |
| 261 XMotionEvent event; | 323 XMotionEvent event; |
| 262 event.time = CurrentTime; | 324 event.time = CurrentTime; |
| 263 event.x_root = kMouseMoveX; | 325 event.x_root = kMouseMoveX; |
| 264 event.y_root = kMouseMoveY; | 326 event.y_root = kMouseMoveY; |
| 265 OnMouseMovement(&event); | 327 OnMouseMovement(&event); |
| 266 } | 328 } |
| 267 | 329 |
| 268 bool TestDragDropClient::IsMoveLoopRunning() { | 330 bool TestDragDropClient::IsMoveLoopRunning() { |
| 269 return move_loop_running_; | 331 return loop_->IsRunning(); |
| 270 } | 332 } |
| 271 | 333 |
| 272 int TestDragDropClient::StartDragAndDrop( | 334 scoped_ptr<X11MoveLoop> TestDragDropClient::CreateMoveLoop( |
| 273 const ui::OSExchangeData& data, | 335 X11MoveLoopDelegate* delegate) { |
| 274 aura::Window* root_window, | 336 loop_ = new TestMoveLoop(delegate); |
| 275 aura::Window* source_window, | 337 return scoped_ptr<X11MoveLoop>(loop_); |
| 276 const gfx::Point& root_location, | |
| 277 int operation, | |
| 278 ui::DragDropTypes::DragEventSource source) { | |
| 279 move_loop_running_ = true; | |
| 280 return DesktopDragDropClientAuraX11::StartDragAndDrop(data, root_window, | |
| 281 source_window, root_location, operation, source); | |
| 282 } | |
| 283 | |
| 284 void TestDragDropClient::OnMoveLoopEnded() { | |
| 285 DesktopDragDropClientAuraX11::OnMoveLoopEnded(); | |
| 286 move_loop_running_ = false; | |
| 287 } | 338 } |
| 288 | 339 |
| 289 ::Window TestDragDropClient::FindWindowFor(const gfx::Point& screen_point) { | 340 ::Window TestDragDropClient::FindWindowFor(const gfx::Point& screen_point) { |
| 290 return target_xid_; | 341 return target_xid_; |
| 291 } | 342 } |
| 292 | 343 |
| 293 void TestDragDropClient::SendXClientEvent(::Window xid, XEvent* event) { | 344 void TestDragDropClient::SendXClientEvent(::Window xid, XEvent* event) { |
| 294 std::map< ::Window, ClientMessageEventCollector*>::iterator it = | 345 std::map< ::Window, ClientMessageEventCollector*>::iterator it = |
| 295 collectors_.find(xid); | 346 collectors_.find(xid); |
| 296 if (it != collectors_.end()) | 347 if (it != collectors_.end()) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 params.native_widget = new DesktopNativeWidgetAura(widget_.get()); | 382 params.native_widget = new DesktopNativeWidgetAura(widget_.get()); |
| 332 params.bounds = gfx::Rect(100, 100); | 383 params.bounds = gfx::Rect(100, 100); |
| 333 widget_->Init(params); | 384 widget_->Init(params); |
| 334 widget_->Show(); | 385 widget_->Show(); |
| 335 | 386 |
| 336 cursor_manager_.reset(new DesktopNativeCursorManager( | 387 cursor_manager_.reset(new DesktopNativeCursorManager( |
| 337 DesktopCursorLoaderUpdater::Create())); | 388 DesktopCursorLoaderUpdater::Create())); |
| 338 | 389 |
| 339 client_.reset(new TestDragDropClient(widget_->GetNativeWindow(), | 390 client_.reset(new TestDragDropClient(widget_->GetNativeWindow(), |
| 340 cursor_manager_.get())); | 391 cursor_manager_.get())); |
| 392 client_->Init(); |
| 341 } | 393 } |
| 342 | 394 |
| 343 virtual void TearDown() OVERRIDE { | 395 virtual void TearDown() OVERRIDE { |
| 344 client_.reset(); | 396 client_.reset(); |
| 345 cursor_manager_.reset(); | 397 cursor_manager_.reset(); |
| 346 widget_.reset(); | 398 widget_.reset(); |
| 347 ViewsTestBase::TearDown(); | 399 ViewsTestBase::TearDown(); |
| 348 } | 400 } |
| 349 | 401 |
| 350 TestDragDropClient* client() { | 402 TestDragDropClient* client() { |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 | 722 |
| 671 // Repeat the test but reject the drop in the XdndFinished message instead. | 723 // Repeat the test but reject the drop in the XdndFinished message instead. |
| 672 base::MessageLoop::current()->PostTask( | 724 base::MessageLoop::current()->PostTask( |
| 673 FROM_HERE, | 725 FROM_HERE, |
| 674 base::Bind(&RejectAfterMouseReleaseStep3, client())); | 726 base::Bind(&RejectAfterMouseReleaseStep3, client())); |
| 675 result = StartDragAndDrop(); | 727 result = StartDragAndDrop(); |
| 676 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, result); | 728 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, result); |
| 677 } | 729 } |
| 678 | 730 |
| 679 } // namespace views | 731 } // namespace views |
| OLD | NEW |