| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/views/tab_contents/tab_contents_drag_win.h" | 5 #include "chrome/browser/views/tab_contents/tab_contents_drag_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/task.h" | 11 #include "base/task.h" |
| 12 #include "base/thread.h" | 12 #include "base/thread.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "base/win_util.h" | 14 #include "base/win_util.h" |
| 15 #include "chrome/browser/bookmarks/bookmark_drag_data.h" | 15 #include "chrome/browser/bookmarks/bookmark_drag_data.h" |
| 16 #include "chrome/browser/chrome_thread.h" | 16 #include "chrome/browser/chrome_thread.h" |
| 17 #include "chrome/browser/download/drag_download_file.h" | 17 #include "chrome/browser/download/drag_download_file.h" |
| 18 #include "chrome/browser/download/drag_download_util.h" | 18 #include "chrome/browser/download/drag_download_util.h" |
| 19 #include "chrome/browser/profile.h" | 19 #include "chrome/browser/profile.h" |
| 20 #include "chrome/browser/tab_contents/tab_contents.h" | 20 #include "chrome/browser/tab_contents/tab_contents.h" |
| 21 #include "chrome/browser/tab_contents/web_drag_source_win.h" | 21 #include "chrome/browser/tab_contents/web_drag_source_win.h" |
| 22 #include "chrome/browser/tab_contents/web_drop_target_win.h" | 22 #include "chrome/browser/tab_contents/web_drop_target_win.h" |
| 23 #include "chrome/browser/views/tab_contents/tab_contents_view_win.h" | 23 #include "chrome/browser/views/tab_contents/tab_contents_view_win.h" |
| 24 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
| 25 #include "net/base/net_util.h" | 25 #include "net/base/net_util.h" |
| 26 #include "webkit/glue/webdropdata.h" | 26 #include "webkit/glue/webdropdata.h" |
| 27 | 27 |
| 28 using WebKit::WebDragOperationsMask; | 28 using WebKit::WebDragOperationsMask; |
| 29 using WebKit::WebDragOperationCopy; |
| 30 using WebKit::WebDragOperationLink; |
| 31 using WebKit::WebDragOperationMove; |
| 29 | 32 |
| 30 namespace { | 33 namespace { |
| 31 | 34 |
| 32 HHOOK msg_hook = NULL; | 35 HHOOK msg_hook = NULL; |
| 33 DWORD drag_out_thread_id = 0; | 36 DWORD drag_out_thread_id = 0; |
| 34 bool mouse_up_received = false; | 37 bool mouse_up_received = false; |
| 35 | 38 |
| 36 LRESULT CALLBACK MsgFilterProc(int code, WPARAM wparam, LPARAM lparam) { | 39 LRESULT CALLBACK MsgFilterProc(int code, WPARAM wparam, LPARAM lparam) { |
| 37 if (code == base::MessagePumpForUI::kMessageFilterCode && | 40 if (code == base::MessagePumpForUI::kMessageFilterCode && |
| 38 !mouse_up_received) { | 41 !mouse_up_received) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 51 // more. | 54 // more. |
| 52 if (msg->message == WM_LBUTTONUP || !(GetKeyState(VK_LBUTTON) & 0x8000)) | 55 if (msg->message == WM_LBUTTONUP || !(GetKeyState(VK_LBUTTON) & 0x8000)) |
| 53 mouse_up_received = true; | 56 mouse_up_received = true; |
| 54 | 57 |
| 55 return TRUE; | 58 return TRUE; |
| 56 } | 59 } |
| 57 } | 60 } |
| 58 return CallNextHookEx(msg_hook, code, wparam, lparam); | 61 return CallNextHookEx(msg_hook, code, wparam, lparam); |
| 59 } | 62 } |
| 60 | 63 |
| 64 DWORD WebDragOpToWinDragOp(WebDragOperationsMask op) { |
| 65 DWORD win_op = DROPEFFECT_NONE; |
| 66 if (op & WebDragOperationCopy) |
| 67 win_op |= DROPEFFECT_COPY; |
| 68 if (op & WebDragOperationLink) |
| 69 win_op |= DROPEFFECT_LINK; |
| 70 if (op & WebDragOperationMove) |
| 71 win_op |= DROPEFFECT_MOVE; |
| 72 return win_op; |
| 73 } |
| 74 |
| 61 } // namespace | 75 } // namespace |
| 62 | 76 |
| 63 class DragDropThread : public base::Thread { | 77 class DragDropThread : public base::Thread { |
| 64 public: | 78 public: |
| 65 explicit DragDropThread(TabContentsDragWin* drag_handler) | 79 explicit DragDropThread(TabContentsDragWin* drag_handler) |
| 66 : base::Thread("Chrome_DragDropThread"), | 80 : base::Thread("Chrome_DragDropThread"), |
| 67 drag_handler_(drag_handler) { | 81 drag_handler_(drag_handler) { |
| 68 } | 82 } |
| 69 | 83 |
| 70 virtual ~DragDropThread() { | 84 virtual ~DragDropThread() { |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 data.SetString(drop_data.plain_text); | 294 data.SetString(drop_data.plain_text); |
| 281 } | 295 } |
| 282 | 296 |
| 283 DWORD effects = 0; | 297 DWORD effects = 0; |
| 284 | 298 |
| 285 // We need to enable recursive tasks on the message loop so we can get | 299 // We need to enable recursive tasks on the message loop so we can get |
| 286 // updates while in the system DoDragDrop loop. | 300 // updates while in the system DoDragDrop loop. |
| 287 bool old_state = MessageLoop::current()->NestableTasksAllowed(); | 301 bool old_state = MessageLoop::current()->NestableTasksAllowed(); |
| 288 MessageLoop::current()->SetNestableTasksAllowed(true); | 302 MessageLoop::current()->SetNestableTasksAllowed(true); |
| 289 DoDragDrop(OSExchangeDataProviderWin::GetIDataObject(data), drag_source_, | 303 DoDragDrop(OSExchangeDataProviderWin::GetIDataObject(data), drag_source_, |
| 290 DROPEFFECT_COPY | DROPEFFECT_LINK, &effects); | 304 WebDragOpToWinDragOp(ops), &effects); |
| 291 // TODO(snej): Use 'ops' param instead of hardcoding dropeffects | |
| 292 MessageLoop::current()->SetNestableTasksAllowed(old_state); | 305 MessageLoop::current()->SetNestableTasksAllowed(old_state); |
| 293 } | 306 } |
| 294 | 307 |
| 295 void TabContentsDragWin::EndDragging(bool restore_suspended_state) { | 308 void TabContentsDragWin::EndDragging(bool restore_suspended_state) { |
| 296 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 309 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 297 | 310 |
| 298 if (drag_ended_) | 311 if (drag_ended_) |
| 299 return; | 312 return; |
| 300 drag_ended_ = true; | 313 drag_ended_ = true; |
| 301 | 314 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 | 351 |
| 339 void TabContentsDragWin::OnDataObjectDisposed() { | 352 void TabContentsDragWin::OnDataObjectDisposed() { |
| 340 DCHECK(drag_drop_thread_id_ == PlatformThread::CurrentId()); | 353 DCHECK(drag_drop_thread_id_ == PlatformThread::CurrentId()); |
| 341 | 354 |
| 342 // The drag-and-drop thread is only closed after OLE is done with | 355 // The drag-and-drop thread is only closed after OLE is done with |
| 343 // DataObjectImpl. | 356 // DataObjectImpl. |
| 344 ChromeThread::PostTask( | 357 ChromeThread::PostTask( |
| 345 ChromeThread::UI, FROM_HERE, | 358 ChromeThread::UI, FROM_HERE, |
| 346 NewRunnableMethod(this, &TabContentsDragWin::CloseThread)); | 359 NewRunnableMethod(this, &TabContentsDragWin::CloseThread)); |
| 347 } | 360 } |
| OLD | NEW |