Chromium Code Reviews| 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/renderer_host/render_widget_host_view_win.h" | |
| 9 #include "content/browser/web_contents/web_contents_impl.h" | 10 #include "content/browser/web_contents/web_contents_impl.h" |
| 10 #include "content/browser/web_contents/web_drag_utils_win.h" | 11 #include "content/browser/web_contents/web_drag_utils_win.h" |
| 11 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/browser/notification_source.h" | 13 #include "content/public/browser/notification_source.h" |
| 13 #include "content/public/browser/notification_types.h" | 14 #include "content/public/browser/notification_types.h" |
| 14 #include "ui/base/dragdrop/os_exchange_data.h" | 15 #include "ui/base/dragdrop/os_exchange_data.h" |
| 15 | 16 |
| 16 using WebKit::WebDragOperationNone; | 17 using WebKit::WebDragOperationNone; |
| 17 | 18 |
| 18 namespace content { | 19 namespace content { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 | 60 |
| 60 if (!web_contents_) | 61 if (!web_contents_) |
| 61 return; | 62 return; |
| 62 | 63 |
| 63 gfx::Point client; | 64 gfx::Point client; |
| 64 gfx::Point screen; | 65 gfx::Point screen; |
| 65 GetCursorPositions(source_wnd_, &client, &screen); | 66 GetCursorPositions(source_wnd_, &client, &screen); |
| 66 web_contents_->DragSourceEndedAt(client.x(), client.y(), | 67 web_contents_->DragSourceEndedAt(client.x(), client.y(), |
| 67 screen.x(), screen.y(), | 68 screen.x(), screen.y(), |
| 68 WebDragOperationNone); | 69 WebDragOperationNone); |
| 70 OnDragSourceEnded(); | |
| 69 } | 71 } |
| 70 | 72 |
| 71 void WebDragSource::OnDragSourceDrop() { | 73 void WebDragSource::OnDragSourceDrop() { |
| 72 DCHECK(data_); | 74 DCHECK(data_); |
| 73 data_->SetInDragLoop(false); | 75 data_->SetInDragLoop(false); |
| 74 // On Windows, we check for drag end in IDropSource::QueryContinueDrag which | 76 // On Windows, we check for drag end in IDropSource::QueryContinueDrag which |
| 75 // happens before IDropTarget::Drop is called. HTML5 requires the "dragend" | 77 // happens before IDropTarget::Drop is called. HTML5 requires the "dragend" |
| 76 // event to happen after the "drop" event. Since Windows calls these two | 78 // event to happen after the "drop" event. Since Windows calls these two |
| 77 // directly after each other we can just post a task to handle the | 79 // directly after each other we can just post a task to handle the |
| 78 // OnDragSourceDrop after the current task. | 80 // OnDragSourceDrop after the current task. |
| 79 BrowserThread::PostTask( | 81 BrowserThread::PostTask( |
| 80 BrowserThread::UI, FROM_HERE, | 82 BrowserThread::UI, FROM_HERE, |
| 81 base::Bind(&WebDragSource::DelayedOnDragSourceDrop, this)); | 83 base::Bind(&WebDragSource::DelayedOnDragSourceDrop, this)); |
| 82 } | 84 } |
| 83 | 85 |
| 84 void WebDragSource::DelayedOnDragSourceDrop() { | 86 void WebDragSource::DelayedOnDragSourceDrop() { |
| 85 if (!web_contents_) | 87 if (!web_contents_) |
| 86 return; | 88 return; |
| 87 | |
| 88 gfx::Point client; | 89 gfx::Point client; |
| 89 gfx::Point screen; | 90 gfx::Point screen; |
| 90 GetCursorPositions(source_wnd_, &client, &screen); | 91 GetCursorPositions(source_wnd_, &client, &screen); |
| 91 web_contents_->DragSourceEndedAt(client.x(), client.y(), screen.x(), | 92 web_contents_->DragSourceEndedAt(client.x(), client.y(), screen.x(), |
| 92 screen.y(), WinDragOpToWebDragOp(effect_)); | 93 screen.y(), WinDragOpToWebDragOp(effect_)); |
| 94 OnDragSourceEnded(); | |
| 95 } | |
| 96 | |
| 97 void WebDragSource::OnDragSourceEnded() { | |
| 98 RenderViewHost* render_view_host = web_contents_->GetRenderViewHost(); | |
|
dcheng
2013/05/24 01:10:37
Why not just GetRenderWidgetHostView() directly?
Hongbo Min
2013/05/27 14:51:41
Done.
| |
| 99 if (!render_view_host) | |
| 100 return; | |
| 101 | |
| 102 RenderWidgetHostViewWin* rwhv = | |
| 103 static_cast<RenderWidgetHostViewWin*>(render_view_host->GetView()); | |
| 104 if (rwhv->in_long_press_gesture()) | |
| 105 rwhv->CancelLongPressGesture(); | |
| 93 } | 106 } |
| 94 | 107 |
| 95 void WebDragSource::OnDragSourceMove() { | 108 void WebDragSource::OnDragSourceMove() { |
| 96 // Delegate to the UI thread if we do drag-and-drop in the background thread. | 109 // Delegate to the UI thread if we do drag-and-drop in the background thread. |
| 97 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 110 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 98 BrowserThread::PostTask( | 111 BrowserThread::PostTask( |
| 99 BrowserThread::UI, FROM_HERE, | 112 BrowserThread::UI, FROM_HERE, |
| 100 base::Bind(&WebDragSource::OnDragSourceMove, this)); | 113 base::Bind(&WebDragSource::OnDragSourceMove, this)); |
| 101 return; | 114 return; |
| 102 } | 115 } |
| 103 | 116 |
| 104 if (!web_contents_) | 117 if (!web_contents_) |
| 105 return; | 118 return; |
| 106 | 119 |
| 107 gfx::Point client; | 120 gfx::Point client; |
| 108 gfx::Point screen; | 121 gfx::Point screen; |
| 109 GetCursorPositions(source_wnd_, &client, &screen); | 122 GetCursorPositions(source_wnd_, &client, &screen); |
| 110 web_contents_->DragSourceMovedTo(client.x(), client.y(), | 123 web_contents_->DragSourceMovedTo(client.x(), client.y(), |
| 111 screen.x(), screen.y()); | 124 screen.x(), screen.y()); |
| 112 } | 125 } |
| 113 | 126 |
| 127 bool WebDragSource::ShouldDropDragSource( | |
| 128 BOOL escape_pressed, DWORD key_state) { | |
| 129 // We also care about right mouse button state since long press gesture is | |
| 130 // simulated as right mouse button down/up. | |
| 131 LOG(INFO) << "call WebDragSource::ShouldDropDragSource: key_state: " | |
| 132 << key_state; | |
| 133 | |
| 134 return !(key_state & MK_LBUTTON) && !(key_state & MK_RBUTTON); | |
|
dcheng
2013/05/24 01:10:37
I would prefer to see the right-mouse button check
Hongbo Min
2013/05/27 14:51:41
Good suggestion, thanks. Done!
| |
| 135 } | |
| 136 | |
| 114 void WebDragSource::Observe(int type, | 137 void WebDragSource::Observe(int type, |
| 115 const NotificationSource& source, | 138 const NotificationSource& source, |
| 116 const NotificationDetails& details) { | 139 const NotificationDetails& details) { |
| 117 if (type == NOTIFICATION_WEB_CONTENTS_SWAPPED) { | 140 if (type == NOTIFICATION_WEB_CONTENTS_SWAPPED) { |
| 118 // When the WebContents get swapped, our render view host goes away. | 141 // When the WebContents get swapped, our render view host goes away. |
| 119 // That's OK, we can continue the drag, we just can't send messages back to | 142 // That's OK, we can continue the drag, we just can't send messages back to |
| 120 // our drag source. | 143 // our drag source. |
| 121 web_contents_ = NULL; | 144 web_contents_ = NULL; |
| 122 } else if (type == NOTIFICATION_WEB_CONTENTS_DISCONNECTED) { | 145 } else if (type == NOTIFICATION_WEB_CONTENTS_DISCONNECTED) { |
| 123 // This could be possible when we close the tab and the source is still | 146 // This could be possible when we close the tab and the source is still |
| 124 // being used in DoDragDrop at the time that the virtual file is being | 147 // being used in DoDragDrop at the time that the virtual file is being |
| 125 // downloaded. | 148 // downloaded. |
| 126 web_contents_ = NULL; | 149 web_contents_ = NULL; |
| 127 } | 150 } |
| 128 } | 151 } |
| 129 | 152 |
| 130 } // namespace content | 153 } // namespace content |
| OLD | NEW |