Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Unified Diff: content/browser/web_contents/web_contents_drag_win.cc

Issue 14122008: Enable touch-initiated drag-drop work on Windows (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: hot fixing Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..7513c4e8d5f6b9cc648e839b580bda8954eb199c 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,8 @@ bool run_do_drag_drop = true;
HHOOK msg_hook = NULL;
DWORD drag_out_thread_id = 0;
bool mouse_up_received = false;
+// True if the drag-drop is initiated by touch event.
+bool touch_initiated_drag_drop = false;
LRESULT CALLBACK MsgFilterProc(int code, WPARAM wparam, LPARAM lparam) {
if (code == base::MessagePumpForUI::kMessageFilterCode &&
@@ -66,11 +69,25 @@ LRESULT CALLBACK MsgFilterProc(int code, WPARAM wparam, LPARAM lparam) {
msg->wParam,
msg->lParam);
- // If the left button is up, we do not need to forward the message any
- // more.
+ // If the left 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 (touch_initiated_drag_drop) {
+ // In case of touch-initiated drag, we need to take care of right
+ // mouse up event since a mouse right button down event is triggered
+ // programmatically for DoDragDrop running.
+ if (msg->message == WM_RBUTTONUP)
dcheng 2013/05/28 20:34:02 Nit: I think you can just fold this into line 64-6
Hongbo Min 2013/05/29 06:08:04 Done.
girard 2013/05/29 18:57:52 Is this code even reachable given the test in line
Hongbo Min 2013/05/30 01:36:03 Fixed.
+ PostThreadMessage(drag_out_thread_id,
+ msg->message,
+ msg->wParam,
+ msg->lParam);
+
+ if (msg->message == WM_RBUTTONUP || !(GetKeyState(VK_RBUTTON) & 0x8000))
+ mouse_up_received = true;
+ }
+
return TRUE;
}
}
@@ -161,7 +178,21 @@ void WebContentsDragWin::StartDragging(const WebDropData& drop_data,
const gfx::Vector2d& image_offset) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- drag_source_ = new WebDragSource(source_window_, web_contents_);
+ RenderWidgetHostViewWin* rwhv =
+ static_cast<RenderWidgetHostViewWin*>
+ (web_contents_->GetRenderWidgetHostView());
dcheng 2013/05/28 20:34:02 Nit: ( on previous line.
Hongbo Min 2013/05/29 06:08:04 Done.
+
+ ui::DragDropTypes::DragEventSource event_source;
+ if (rwhv->in_long_press_gesture()) {
+ event_source = ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH;
+ touch_initiated_drag_drop = true;
+ }
+ else {
+ event_source = ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE;
+ touch_initiated_drag_drop = false;
+ }
+
+ drag_source_ = new WebDragSource(source_window_, web_contents_, event_source);
const GURL& page_url = web_contents_->GetURL();
const std::string& page_encoding = web_contents_->GetEncoding();
@@ -315,6 +346,16 @@ bool WebContentsDragWin::DoDragging(const WebDropData& drop_data,
const gfx::Vector2d& image_offset) {
ui::OSExchangeData data;
+ RenderWidgetHostViewWin* rwhv =
+ static_cast<RenderWidgetHostViewWin*>(
+ web_contents_->GetRenderWidgetHostView());
+ // 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 (!drop_data.download_metadata.empty()) {
PrepareDragForDownload(drop_data, &data, page_url, page_encoding);
@@ -412,6 +453,44 @@ void WebContentsDragWin::CloseThread() {
drag_drop_thread_.reset();
}
+void WebContentsDragWin::SendMouseEventForTouchDnD() {
+ static const int kMaxAbsoluteCoordinate = 65535;
+
+ RenderWidgetHostViewWin* rwhv =
+ static_cast<RenderWidgetHostViewWin*>(
+ web_contents_->GetRenderWidgetHostView());
+
+ if (!rwhv)
+ return;
+
+ int screen_width = ::GetSystemMetrics(SM_CXSCREEN);
+ int screen_height = ::GetSystemMetrics(SM_CYSCREEN);
dcheng 2013/05/28 20:34:02 Nit: extra space.
Hongbo Min 2013/05/29 06:08:04 Use gfx::Screen and gfx::Display API instead now.
+ 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 input = { 0 };
+ input.type = INPUT_MOUSE;
+ input.mi.dwFlags = MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_ABSOLUTE;
+ input.mi.dx = absolute_x;
+ input.mi.dy = absolute_y;
+ ::SendInput(1, &input, sizeof(input));
+
+ // Send MOUSEEVENTF_MOVE input event to set cursor to the right position.
+ input.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;
+ ::SendInput(1, &input, sizeof(input));
+}
+
void WebContentsDragWin::OnWaitForData() {
DCHECK(drag_drop_thread_id_ == base::PlatformThread::CurrentId());

Powered by Google App Engine
This is Rietveld 408576698