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

Side by Side Diff: content/browser/web_contents/web_drag_source_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: Created 7 years, 8 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 unified diff | Download patch
OLDNEW
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_drag_utils_win.h" 10 #include "content/browser/web_contents/web_drag_utils_win.h"
10 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
11 #include "content/public/browser/notification_source.h" 12 #include "content/public/browser/notification_source.h"
12 #include "content/public/browser/notification_types.h" 13 #include "content/public/browser/notification_types.h"
13 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
14 15
15 using WebKit::WebDragOperationNone; 16 using WebKit::WebDragOperationNone;
16 17
17 namespace content { 18 namespace content {
18 namespace { 19 namespace {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 58
58 if (!render_view_host_) 59 if (!render_view_host_)
59 return; 60 return;
60 61
61 gfx::Point client; 62 gfx::Point client;
62 gfx::Point screen; 63 gfx::Point screen;
63 GetCursorPositions(source_wnd_, &client, &screen); 64 GetCursorPositions(source_wnd_, &client, &screen);
64 render_view_host_->DragSourceEndedAt(client.x(), client.y(), 65 render_view_host_->DragSourceEndedAt(client.x(), client.y(),
65 screen.x(), screen.y(), 66 screen.x(), screen.y(),
66 WebDragOperationNone); 67 WebDragOperationNone);
68 OnDragSourceEnded();
67 } 69 }
68 70
69 void WebDragSource::OnDragSourceDrop() { 71 void WebDragSource::OnDragSourceDrop() {
70 // On Windows, we check for drag end in IDropSource::QueryContinueDrag which 72 // On Windows, we check for drag end in IDropSource::QueryContinueDrag which
71 // happens before IDropTarget::Drop is called. HTML5 requires the "dragend" 73 // happens before IDropTarget::Drop is called. HTML5 requires the "dragend"
72 // event to happen after the "drop" event. Since Windows calls these two 74 // 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 75 // directly after each other we can just post a task to handle the
74 // OnDragSourceDrop after the current task. 76 // OnDragSourceDrop after the current task.
75 BrowserThread::PostTask( 77 BrowserThread::PostTask(
76 BrowserThread::UI, FROM_HERE, 78 BrowserThread::UI, FROM_HERE,
77 base::Bind(&WebDragSource::DelayedOnDragSourceDrop, this)); 79 base::Bind(&WebDragSource::DelayedOnDragSourceDrop, this));
78 } 80 }
79 81
80 void WebDragSource::DelayedOnDragSourceDrop() { 82 void WebDragSource::DelayedOnDragSourceDrop() {
81 if (!render_view_host_) 83 if (!render_view_host_)
82 return; 84 return;
83
84 gfx::Point client; 85 gfx::Point client;
85 gfx::Point screen; 86 gfx::Point screen;
86 GetCursorPositions(source_wnd_, &client, &screen); 87 GetCursorPositions(source_wnd_, &client, &screen);
87 render_view_host_->DragSourceEndedAt( 88 render_view_host_->DragSourceEndedAt(
88 client.x(), client.y(), screen.x(), screen.y(), 89 client.x(), client.y(), screen.x(), screen.y(),
89 WinDragOpToWebDragOp(effect_)); 90 WinDragOpToWebDragOp(effect_));
91 OnDragSourceEnded();
92 }
93
94 void WebDragSource::OnDragSourceEnded() {
95 if (!render_view_host_)
96 return;
97
98 RenderWidgetHostViewWin* rwhv =
99 static_cast<RenderWidgetHostViewWin*>(render_view_host_->GetView());
100 if (rwhv->has_valid_long_press_gesture())
101 rwhv->CancelLongPressGesture();
90 } 102 }
91 103
92 void WebDragSource::OnDragSourceMove() { 104 void WebDragSource::OnDragSourceMove() {
93 // Delegate to the UI thread if we do drag-and-drop in the background thread. 105 // Delegate to the UI thread if we do drag-and-drop in the background thread.
94 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 106 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
95 BrowserThread::PostTask( 107 BrowserThread::PostTask(
96 BrowserThread::UI, FROM_HERE, 108 BrowserThread::UI, FROM_HERE,
97 base::Bind(&WebDragSource::OnDragSourceMove, this)); 109 base::Bind(&WebDragSource::OnDragSourceMove, this));
98 return; 110 return;
99 } 111 }
100 112
101 if (!render_view_host_) 113 if (!render_view_host_)
102 return; 114 return;
103
104 gfx::Point client; 115 gfx::Point client;
105 gfx::Point screen; 116 gfx::Point screen;
106 GetCursorPositions(source_wnd_, &client, &screen); 117 GetCursorPositions(source_wnd_, &client, &screen);
107 render_view_host_->DragSourceMovedTo(client.x(), client.y(), 118 render_view_host_->DragSourceMovedTo(client.x(), client.y(),
108 screen.x(), screen.y()); 119 screen.x(), screen.y());
109 } 120 }
110 121
122 bool WebDragSource::ShouldDropDragSource(
123 BOOL escape_pressed, DWORD key_state) {
124 // We also care about right mouse button state since long press gesture is
125 // simulated as right mouse button down/up.
126 return !(key_state & MK_LBUTTON) && !(key_state & MK_RBUTTON);
127 }
128
111 void WebDragSource::Observe(int type, 129 void WebDragSource::Observe(int type,
112 const NotificationSource& source, 130 const NotificationSource& source,
113 const NotificationDetails& details) { 131 const NotificationDetails& details) {
114 if (type == NOTIFICATION_WEB_CONTENTS_SWAPPED) { 132 if (type == NOTIFICATION_WEB_CONTENTS_SWAPPED) {
115 // When the WebContents get swapped, our render view host goes away. 133 // When the WebContents get swapped, our render view host goes away.
116 // That's OK, we can continue the drag, we just can't send messages back to 134 // That's OK, we can continue the drag, we just can't send messages back to
117 // our drag source. 135 // our drag source.
118 render_view_host_ = NULL; 136 render_view_host_ = NULL;
119 } else if (type == NOTIFICATION_WEB_CONTENTS_DISCONNECTED) { 137 } else if (type == NOTIFICATION_WEB_CONTENTS_DISCONNECTED) {
120 // This could be possible when we close the tab and the source is still 138 // 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 139 // being used in DoDragDrop at the time that the virtual file is being
122 // downloaded. 140 // downloaded.
123 render_view_host_ = NULL; 141 render_view_host_ = NULL;
124 } 142 }
125 } 143 }
126 144
127 } // namespace content 145 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698