| 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 "content/browser/web_contents/web_drag_source_win.h" | 5 #include "content/browser/web_contents/web_drag_source_win.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "content/browser/renderer_host/render_view_host_impl.h" | 8 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 9 #include "content/browser/web_contents/web_drag_utils_win.h" | 9 #include "content/browser/web_contents/web_drag_utils_win.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 11 #include "content/public/browser/notification_source.h" | 11 #include "content/public/browser/notification_source.h" |
| 12 #include "content/public/browser/notification_types.h" | 12 #include "content/public/browser/notification_types.h" |
| 13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 14 #include "ui/base/dragdrop/os_exchange_data.h" |
| 14 | 15 |
| 15 using WebKit::WebDragOperationNone; | 16 using WebKit::WebDragOperationNone; |
| 16 | 17 |
| 17 namespace content { | 18 namespace content { |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 static void GetCursorPositions(gfx::NativeWindow wnd, gfx::Point* client, | 21 static void GetCursorPositions(gfx::NativeWindow wnd, gfx::Point* client, |
| 21 gfx::Point* screen) { | 22 gfx::Point* screen) { |
| 22 POINT cursor_pos; | 23 POINT cursor_pos; |
| 23 GetCursorPos(&cursor_pos); | 24 GetCursorPos(&cursor_pos); |
| 24 screen->SetPoint(cursor_pos.x, cursor_pos.y); | 25 screen->SetPoint(cursor_pos.x, cursor_pos.y); |
| 25 ScreenToClient(wnd, &cursor_pos); | 26 ScreenToClient(wnd, &cursor_pos); |
| 26 client->SetPoint(cursor_pos.x, cursor_pos.y); | 27 client->SetPoint(cursor_pos.x, cursor_pos.y); |
| 27 } | 28 } |
| 28 | 29 |
| 29 } // namespace | 30 } // namespace |
| 30 | 31 |
| 31 /////////////////////////////////////////////////////////////////////////////// | 32 /////////////////////////////////////////////////////////////////////////////// |
| 32 // WebDragSource, public: | 33 // WebDragSource, public: |
| 33 | 34 |
| 34 WebDragSource::WebDragSource(gfx::NativeWindow source_wnd, | 35 WebDragSource::WebDragSource(gfx::NativeWindow source_wnd, |
| 35 WebContents* web_contents) | 36 WebContents* web_contents) |
| 36 : ui::DragSourceWin(), | 37 : ui::DragSourceWin(), |
| 37 source_wnd_(source_wnd), | 38 source_wnd_(source_wnd), |
| 38 render_view_host_(web_contents->GetRenderViewHost()), | 39 render_view_host_(web_contents->GetRenderViewHost()), |
| 39 effect_(DROPEFFECT_NONE) { | 40 effect_(DROPEFFECT_NONE), |
| 41 data_(NULL) { |
| 40 registrar_.Add(this, NOTIFICATION_WEB_CONTENTS_SWAPPED, | 42 registrar_.Add(this, NOTIFICATION_WEB_CONTENTS_SWAPPED, |
| 41 Source<WebContents>(web_contents)); | 43 Source<WebContents>(web_contents)); |
| 42 registrar_.Add(this, NOTIFICATION_WEB_CONTENTS_DISCONNECTED, | 44 registrar_.Add(this, NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
| 43 Source<WebContents>(web_contents)); | 45 Source<WebContents>(web_contents)); |
| 44 } | 46 } |
| 45 | 47 |
| 46 WebDragSource::~WebDragSource() { | 48 WebDragSource::~WebDragSource() { |
| 47 } | 49 } |
| 48 | 50 |
| 49 void WebDragSource::OnDragSourceCancel() { | 51 void WebDragSource::OnDragSourceCancel() { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 60 | 62 |
| 61 gfx::Point client; | 63 gfx::Point client; |
| 62 gfx::Point screen; | 64 gfx::Point screen; |
| 63 GetCursorPositions(source_wnd_, &client, &screen); | 65 GetCursorPositions(source_wnd_, &client, &screen); |
| 64 render_view_host_->DragSourceEndedAt(client.x(), client.y(), | 66 render_view_host_->DragSourceEndedAt(client.x(), client.y(), |
| 65 screen.x(), screen.y(), | 67 screen.x(), screen.y(), |
| 66 WebDragOperationNone); | 68 WebDragOperationNone); |
| 67 } | 69 } |
| 68 | 70 |
| 69 void WebDragSource::OnDragSourceDrop() { | 71 void WebDragSource::OnDragSourceDrop() { |
| 72 DCHECK(data_); |
| 73 data_->SetInDragLoop(false); |
| 70 // On Windows, we check for drag end in IDropSource::QueryContinueDrag which | 74 // On Windows, we check for drag end in IDropSource::QueryContinueDrag which |
| 71 // happens before IDropTarget::Drop is called. HTML5 requires the "dragend" | 75 // happens before IDropTarget::Drop is called. HTML5 requires the "dragend" |
| 72 // event to happen after the "drop" event. Since Windows calls these two | 76 // event to happen after the "drop" event. Since Windows calls these two |
| 73 // directly after each other we can just post a task to handle the | 77 // directly after each other we can just post a task to handle the |
| 74 // OnDragSourceDrop after the current task. | 78 // OnDragSourceDrop after the current task. |
| 75 BrowserThread::PostTask( | 79 BrowserThread::PostTask( |
| 76 BrowserThread::UI, FROM_HERE, | 80 BrowserThread::UI, FROM_HERE, |
| 77 base::Bind(&WebDragSource::DelayedOnDragSourceDrop, this)); | 81 base::Bind(&WebDragSource::DelayedOnDragSourceDrop, this)); |
| 78 } | 82 } |
| 79 | 83 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 render_view_host_ = NULL; | 122 render_view_host_ = NULL; |
| 119 } else if (type == NOTIFICATION_WEB_CONTENTS_DISCONNECTED) { | 123 } else if (type == NOTIFICATION_WEB_CONTENTS_DISCONNECTED) { |
| 120 // This could be possible when we close the tab and the source is still | 124 // This could be possible when we close the tab and the source is still |
| 121 // being used in DoDragDrop at the time that the virtual file is being | 125 // being used in DoDragDrop at the time that the virtual file is being |
| 122 // downloaded. | 126 // downloaded. |
| 123 render_view_host_ = NULL; | 127 render_view_host_ = NULL; |
| 124 } | 128 } |
| 125 } | 129 } |
| 126 | 130 |
| 127 } // namespace content | 131 } // namespace content |
| OLD | NEW |