Index: content/browser/web_contents/web_contents_drag_win.cc |
diff --git a/content/browser/web_contents/web_contents_drag_win.cc b/content/browser/web_contents/web_contents_drag_win.cc |
index 9153808d985b3d45cf5d630bc5d0f7d18e38d87d..5ff55d138b37c08a38ae6891d2886f51c104d15c 100644 |
--- a/content/browser/web_contents/web_contents_drag_win.cc |
+++ b/content/browser/web_contents/web_contents_drag_win.cc |
@@ -18,6 +18,7 @@ |
#include "base/utf_string_conversions.h" |
#include "content/browser/download/drag_download_file.h" |
#include "content/browser/download/drag_download_util.h" |
+#include "content/browser/renderer_host/render_widget_host_view_win.h" |
#include "content/browser/web_contents/web_drag_dest_win.h" |
#include "content/browser/web_contents/web_drag_source_win.h" |
#include "content/browser/web_contents/web_drag_utils_win.h" |
@@ -51,6 +52,7 @@ bool run_do_drag_drop = true; |
HHOOK msg_hook = NULL; |
DWORD drag_out_thread_id = 0; |
bool mouse_up_received = false; |
+const int kMaxAbsoluteCoordinate = 65535; |
LRESULT CALLBACK MsgFilterProc(int code, WPARAM wparam, LPARAM lparam) { |
if (code == base::MessagePumpForUI::kMessageFilterCode && |
@@ -59,18 +61,22 @@ LRESULT CALLBACK MsgFilterProc(int code, WPARAM wparam, LPARAM lparam) { |
// We do not care about WM_SYSKEYDOWN and WM_SYSKEYUP because when ALT key |
// is pressed down on drag-and-drop, it means to create a link. |
if (msg->message == WM_MOUSEMOVE || msg->message == WM_LBUTTONUP || |
- msg->message == WM_KEYDOWN || msg->message == WM_KEYUP) { |
+ msg->message == WM_KEYDOWN || msg->message == WM_KEYUP || |
+ msg->message == WM_RBUTTONUP) { |
// Forward the message from the UI thread to the drag-and-drop thread. |
PostThreadMessage(drag_out_thread_id, |
msg->message, |
msg->wParam, |
msg->lParam); |
- // If the left button is up, we do not need to forward the message any |
- // more. |
+ // If the left/right button is up, we do not need to forward the message |
+ // any more. |
if (msg->message == WM_LBUTTONUP || !(GetKeyState(VK_LBUTTON) & 0x8000)) |
mouse_up_received = true; |
+ if (msg->message == WM_RBUTTONUP || !(GetKeyState(VK_RBUTTON) & 0x8000)) |
+ mouse_up_received = true; |
+ |
return TRUE; |
} |
} |
@@ -166,8 +172,18 @@ void WebContentsDragWin::StartDragging(const WebDropData& drop_data, |
const GURL& page_url = web_contents_->GetURL(); |
const std::string& page_encoding = web_contents_->GetEncoding(); |
+ RenderWidgetHostViewWin* rwhv = |
+ static_cast<RenderWidgetHostViewWin*> |
+ (web_contents_->GetRenderWidgetHostView()); |
// If it is not drag-out, do the drag-and-drop in the current UI thread. |
if (drop_data.download_metadata.empty()) { |
+ // If RWHV has a valid long press gesture, since DoDragDrop will run into |
+ // itself loop and start a dragging session if and only if a mouse button |
+ // is down and then moves, so we need to programmatically send out |
+ // mouse down event and adjust the cursor position for DoDragDrop. |
+ if (rwhv->in_long_press_gesture()) |
+ SendMouseEventForTouchDnD(); |
+ |
if (DoDragging(drop_data, ops, page_url, page_encoding, |
image, image_offset)) |
EndDragging(); |
@@ -188,6 +204,8 @@ void WebContentsDragWin::StartDragging(const WebDropData& drop_data, |
} |
EnableBackgroundDraggingSupport(drag_drop_thread_->thread_id()); |
+ if (rwhv->in_long_press_gesture()) |
+ SendMouseEventForTouchDnD(); |
} |
void WebContentsDragWin::StartBackgroundDragging( |
@@ -412,9 +430,49 @@ void WebContentsDragWin::CloseThread() { |
drag_drop_thread_.reset(); |
} |
+void WebContentsDragWin::SendMouseEventForTouchDnD() { |
+ RenderWidgetHostViewWin* rwhv = |
+ static_cast<RenderWidgetHostViewWin*> |
+ (web_contents_->GetRenderWidgetHostView()); |
+ |
+ if (!rwhv) |
+ return; |
+ |
+ RECT screen_rect; |
+ ::GetWindowRect(::GetDesktopWindow(), &screen_rect); |
+ int screen_width = screen_rect.right - screen_rect.left; |
+ int screen_height = screen_rect.bottom - screen_rect.top; |
+ gfx::Point last_touch_position = rwhv->GetLastTouchEventLocation(); |
+ |
+ // Map the screen coordinate to the normalized absolute coordinate. |
+ int absolute_x = |
+ last_touch_position.x() * kMaxAbsoluteCoordinate / screen_width; |
+ int absolute_y = |
+ last_touch_position.y() * kMaxAbsoluteCoordinate / screen_height; |
+ |
+ // Send MOUSEEVENTF_RIGHTDOWN event followed by MOUSEEVENTF_MOVE event. |
+ // The reason why not to merge these 2 mouse events into one is, we don't |
+ // want DoDragDrop to get mouse event firstly which lead to drop the drag |
+ // source. Once a touch point is removed from screen after long press, |
+ // a MOUSEEVENTF_RIGHTUP event will be sent out, so we send the down event |
+ // paired with it to complete DoDragDrop session. |
+ INPUT ip = { 0 }; |
+ ip.type = INPUT_MOUSE; |
+ ip.mi.dwFlags = MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_ABSOLUTE; |
+ ip.mi.dx = absolute_x; |
+ ip.mi.dy = absolute_y; |
+ ::SendInput(1, &ip, sizeof(INPUT)); |
+ |
+ // Send MOUSEEVENTF_MOVE input event to set cursor to the right position. |
+ ip.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE; |
+ ::SendInput(1, &ip, sizeof(INPUT)); |
+} |
+ |
void WebContentsDragWin::OnWaitForData() { |
DCHECK(drag_drop_thread_id_ == base::PlatformThread::CurrentId()); |
+ LOG(INFO) << "call WebContentsDragWin::OnWaitForData"; |
+ |
// When the left button is release and we start to wait for the data, end |
// the dragging before DoDragDrop returns. This makes the page leave the drag |
// mode so that it can start to process the normal input events. |