| 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 | 14 |
| 15 using WebKit::WebDragOperationNone; | 15 using WebKit::WebDragOperationNone; |
| 16 using content::BrowserThread; | |
| 17 using content::WebContents; | |
| 18 | 16 |
| 17 namespace content { |
| 19 namespace { | 18 namespace { |
| 20 | 19 |
| 21 static void GetCursorPositions(gfx::NativeWindow wnd, gfx::Point* client, | 20 static void GetCursorPositions(gfx::NativeWindow wnd, gfx::Point* client, |
| 22 gfx::Point* screen) { | 21 gfx::Point* screen) { |
| 23 POINT cursor_pos; | 22 POINT cursor_pos; |
| 24 GetCursorPos(&cursor_pos); | 23 GetCursorPos(&cursor_pos); |
| 25 screen->SetPoint(cursor_pos.x, cursor_pos.y); | 24 screen->SetPoint(cursor_pos.x, cursor_pos.y); |
| 26 ScreenToClient(wnd, &cursor_pos); | 25 ScreenToClient(wnd, &cursor_pos); |
| 27 client->SetPoint(cursor_pos.x, cursor_pos.y); | 26 client->SetPoint(cursor_pos.x, cursor_pos.y); |
| 28 } | 27 } |
| 29 | 28 |
| 30 } // namespace | 29 } // namespace |
| 31 | 30 |
| 32 /////////////////////////////////////////////////////////////////////////////// | 31 /////////////////////////////////////////////////////////////////////////////// |
| 33 // WebDragSource, public: | 32 // WebDragSource, public: |
| 34 | 33 |
| 35 WebDragSource::WebDragSource(gfx::NativeWindow source_wnd, | 34 WebDragSource::WebDragSource(gfx::NativeWindow source_wnd, |
| 36 WebContents* web_contents) | 35 WebContents* web_contents) |
| 37 : ui::DragSource(), | 36 : ui::DragSource(), |
| 38 source_wnd_(source_wnd), | 37 source_wnd_(source_wnd), |
| 39 render_view_host_(web_contents->GetRenderViewHost()), | 38 render_view_host_(web_contents->GetRenderViewHost()), |
| 40 effect_(DROPEFFECT_NONE) { | 39 effect_(DROPEFFECT_NONE) { |
| 41 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_SWAPPED, | 40 registrar_.Add(this, NOTIFICATION_WEB_CONTENTS_SWAPPED, |
| 42 content::Source<WebContents>(web_contents)); | 41 Source<WebContents>(web_contents)); |
| 43 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, | 42 registrar_.Add(this, NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
| 44 content::Source<WebContents>(web_contents)); | 43 Source<WebContents>(web_contents)); |
| 45 } | 44 } |
| 46 | 45 |
| 47 WebDragSource::~WebDragSource() { | 46 WebDragSource::~WebDragSource() { |
| 48 } | 47 } |
| 49 | 48 |
| 50 void WebDragSource::OnDragSourceCancel() { | 49 void WebDragSource::OnDragSourceCancel() { |
| 51 // Delegate to the UI thread if we do drag-and-drop in the background thread. | 50 // Delegate to the UI thread if we do drag-and-drop in the background thread. |
| 52 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 51 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 53 BrowserThread::PostTask( | 52 BrowserThread::PostTask( |
| 54 BrowserThread::UI, FROM_HERE, | 53 BrowserThread::UI, FROM_HERE, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 80 | 79 |
| 81 void WebDragSource::DelayedOnDragSourceDrop() { | 80 void WebDragSource::DelayedOnDragSourceDrop() { |
| 82 if (!render_view_host_) | 81 if (!render_view_host_) |
| 83 return; | 82 return; |
| 84 | 83 |
| 85 gfx::Point client; | 84 gfx::Point client; |
| 86 gfx::Point screen; | 85 gfx::Point screen; |
| 87 GetCursorPositions(source_wnd_, &client, &screen); | 86 GetCursorPositions(source_wnd_, &client, &screen); |
| 88 render_view_host_->DragSourceEndedAt( | 87 render_view_host_->DragSourceEndedAt( |
| 89 client.x(), client.y(), screen.x(), screen.y(), | 88 client.x(), client.y(), screen.x(), screen.y(), |
| 90 web_drag_utils_win::WinDragOpToWebDragOp(effect_)); | 89 WinDragOpToWebDragOp(effect_)); |
| 91 } | 90 } |
| 92 | 91 |
| 93 void WebDragSource::OnDragSourceMove() { | 92 void WebDragSource::OnDragSourceMove() { |
| 94 // Delegate to the UI thread if we do drag-and-drop in the background thread. | 93 // Delegate to the UI thread if we do drag-and-drop in the background thread. |
| 95 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 94 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 96 BrowserThread::PostTask( | 95 BrowserThread::PostTask( |
| 97 BrowserThread::UI, FROM_HERE, | 96 BrowserThread::UI, FROM_HERE, |
| 98 base::Bind(&WebDragSource::OnDragSourceMove, this)); | 97 base::Bind(&WebDragSource::OnDragSourceMove, this)); |
| 99 return; | 98 return; |
| 100 } | 99 } |
| 101 | 100 |
| 102 if (!render_view_host_) | 101 if (!render_view_host_) |
| 103 return; | 102 return; |
| 104 | 103 |
| 105 gfx::Point client; | 104 gfx::Point client; |
| 106 gfx::Point screen; | 105 gfx::Point screen; |
| 107 GetCursorPositions(source_wnd_, &client, &screen); | 106 GetCursorPositions(source_wnd_, &client, &screen); |
| 108 render_view_host_->DragSourceMovedTo(client.x(), client.y(), | 107 render_view_host_->DragSourceMovedTo(client.x(), client.y(), |
| 109 screen.x(), screen.y()); | 108 screen.x(), screen.y()); |
| 110 } | 109 } |
| 111 | 110 |
| 112 void WebDragSource::Observe(int type, | 111 void WebDragSource::Observe(int type, |
| 113 const content::NotificationSource& source, | 112 const NotificationSource& source, |
| 114 const content::NotificationDetails& details) { | 113 const NotificationDetails& details) { |
| 115 if (content::NOTIFICATION_WEB_CONTENTS_SWAPPED == type) { | 114 if (type == NOTIFICATION_WEB_CONTENTS_SWAPPED) { |
| 116 // When the WebContents get swapped, our render view host goes away. | 115 // When the WebContents get swapped, our render view host goes away. |
| 117 // That's OK, we can continue the drag, we just can't send messages back to | 116 // That's OK, we can continue the drag, we just can't send messages back to |
| 118 // our drag source. | 117 // our drag source. |
| 119 render_view_host_ = NULL; | 118 render_view_host_ = NULL; |
| 120 } else if (content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED == type) { | 119 } else if (type == NOTIFICATION_WEB_CONTENTS_DISCONNECTED) { |
| 121 // This could be possible when we close the tab and the source is still | 120 // This could be possible when we close the tab and the source is still |
| 122 // being used in DoDragDrop at the time that the virtual file is being | 121 // being used in DoDragDrop at the time that the virtual file is being |
| 123 // downloaded. | 122 // downloaded. |
| 124 render_view_host_ = NULL; | 123 render_view_host_ = NULL; |
| 125 } | 124 } |
| 126 } | 125 } |
| 126 |
| 127 } // namespace content |
| OLD | NEW |