| 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_drag_utils_win.h" |
| 22 #include "chrome/browser/tab_contents/web_drop_target_win.h" | 23 #include "chrome/browser/tab_contents/web_drop_target_win.h" |
| 23 #include "chrome/browser/views/tab_contents/tab_contents_view_win.h" | 24 #include "chrome/browser/views/tab_contents/tab_contents_view_win.h" |
| 24 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
| 25 #include "net/base/net_util.h" | 26 #include "net/base/net_util.h" |
| 26 #include "webkit/glue/webdropdata.h" | 27 #include "webkit/glue/webdropdata.h" |
| 27 | 28 |
| 28 using WebKit::WebDragOperationsMask; | 29 using WebKit::WebDragOperationsMask; |
| 29 using WebKit::WebDragOperationCopy; | 30 using WebKit::WebDragOperationCopy; |
| 30 using WebKit::WebDragOperationLink; | 31 using WebKit::WebDragOperationLink; |
| 31 using WebKit::WebDragOperationMove; | 32 using WebKit::WebDragOperationMove; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 54 // more. | 55 // more. |
| 55 if (msg->message == WM_LBUTTONUP || !(GetKeyState(VK_LBUTTON) & 0x8000)) | 56 if (msg->message == WM_LBUTTONUP || !(GetKeyState(VK_LBUTTON) & 0x8000)) |
| 56 mouse_up_received = true; | 57 mouse_up_received = true; |
| 57 | 58 |
| 58 return TRUE; | 59 return TRUE; |
| 59 } | 60 } |
| 60 } | 61 } |
| 61 return CallNextHookEx(msg_hook, code, wparam, lparam); | 62 return CallNextHookEx(msg_hook, code, wparam, lparam); |
| 62 } | 63 } |
| 63 | 64 |
| 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 | |
| 75 } // namespace | 65 } // namespace |
| 76 | 66 |
| 77 class DragDropThread : public base::Thread { | 67 class DragDropThread : public base::Thread { |
| 78 public: | 68 public: |
| 79 explicit DragDropThread(TabContentsDragWin* drag_handler) | 69 explicit DragDropThread(TabContentsDragWin* drag_handler) |
| 80 : base::Thread("Chrome_DragDropThread"), | 70 : base::Thread("Chrome_DragDropThread"), |
| 81 drag_handler_(drag_handler) { | 71 drag_handler_(drag_handler) { |
| 82 } | 72 } |
| 83 | 73 |
| 84 virtual ~DragDropThread() { | 74 virtual ~DragDropThread() { |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 if (!drop_data.plain_text.empty()) | 283 if (!drop_data.plain_text.empty()) |
| 294 data.SetString(drop_data.plain_text); | 284 data.SetString(drop_data.plain_text); |
| 295 } | 285 } |
| 296 | 286 |
| 297 // We need to enable recursive tasks on the message loop so we can get | 287 // We need to enable recursive tasks on the message loop so we can get |
| 298 // updates while in the system DoDragDrop loop. | 288 // updates while in the system DoDragDrop loop. |
| 299 bool old_state = MessageLoop::current()->NestableTasksAllowed(); | 289 bool old_state = MessageLoop::current()->NestableTasksAllowed(); |
| 300 DWORD effect; | 290 DWORD effect; |
| 301 MessageLoop::current()->SetNestableTasksAllowed(true); | 291 MessageLoop::current()->SetNestableTasksAllowed(true); |
| 302 DoDragDrop(OSExchangeDataProviderWin::GetIDataObject(data), drag_source_, | 292 DoDragDrop(OSExchangeDataProviderWin::GetIDataObject(data), drag_source_, |
| 303 WebDragOpToWinDragOp(ops), &effect); | 293 web_drag_utils_win::WebDragOpToWinDragOp(ops), &effect); |
| 304 // This works because WebDragSource::OnDragSourceDrop uses PostTask to | 294 // This works because WebDragSource::OnDragSourceDrop uses PostTask to |
| 305 // dispatch the actual event. | 295 // dispatch the actual event. |
| 306 drag_source_->set_effect(effect); | 296 drag_source_->set_effect(effect); |
| 307 MessageLoop::current()->SetNestableTasksAllowed(old_state); | 297 MessageLoop::current()->SetNestableTasksAllowed(old_state); |
| 308 } | 298 } |
| 309 | 299 |
| 310 void TabContentsDragWin::EndDragging(bool restore_suspended_state) { | 300 void TabContentsDragWin::EndDragging(bool restore_suspended_state) { |
| 311 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 301 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 312 | 302 |
| 313 if (drag_ended_) | 303 if (drag_ended_) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 | 343 |
| 354 void TabContentsDragWin::OnDataObjectDisposed() { | 344 void TabContentsDragWin::OnDataObjectDisposed() { |
| 355 DCHECK(drag_drop_thread_id_ == PlatformThread::CurrentId()); | 345 DCHECK(drag_drop_thread_id_ == PlatformThread::CurrentId()); |
| 356 | 346 |
| 357 // The drag-and-drop thread is only closed after OLE is done with | 347 // The drag-and-drop thread is only closed after OLE is done with |
| 358 // DataObjectImpl. | 348 // DataObjectImpl. |
| 359 ChromeThread::PostTask( | 349 ChromeThread::PostTask( |
| 360 ChromeThread::UI, FROM_HERE, | 350 ChromeThread::UI, FROM_HERE, |
| 361 NewRunnableMethod(this, &TabContentsDragWin::CloseThread)); | 351 NewRunnableMethod(this, &TabContentsDragWin::CloseThread)); |
| 362 } | 352 } |
| OLD | NEW |