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

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: fixings in drag_source_win Created 7 years, 6 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
« no previous file with comments | « content/browser/web_contents/web_drag_source_win.h ('k') | ui/base/dragdrop/drag_source_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_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"
15 #include "ui/base/dragdrop/drag_drop_types.h"
14 #include "ui/base/dragdrop/os_exchange_data.h" 16 #include "ui/base/dragdrop/os_exchange_data.h"
15 17
16 using WebKit::WebDragOperationNone; 18 using WebKit::WebDragOperationNone;
17 19
18 namespace content { 20 namespace content {
19 namespace { 21 namespace {
20 22
21 static void GetCursorPositions(gfx::NativeWindow wnd, gfx::Point* client, 23 static void GetCursorPositions(gfx::NativeWindow wnd, gfx::Point* client,
22 gfx::Point* screen) { 24 gfx::Point* screen) {
23 POINT cursor_pos; 25 POINT cursor_pos;
24 GetCursorPos(&cursor_pos); 26 GetCursorPos(&cursor_pos);
25 screen->SetPoint(cursor_pos.x, cursor_pos.y); 27 screen->SetPoint(cursor_pos.x, cursor_pos.y);
26 ScreenToClient(wnd, &cursor_pos); 28 ScreenToClient(wnd, &cursor_pos);
27 client->SetPoint(cursor_pos.x, cursor_pos.y); 29 client->SetPoint(cursor_pos.x, cursor_pos.y);
28 } 30 }
29 31
30 } // namespace 32 } // namespace
31 33
32 /////////////////////////////////////////////////////////////////////////////// 34 ///////////////////////////////////////////////////////////////////////////////
33 // WebDragSource, public: 35 // WebDragSource, public:
34 36
35 WebDragSource::WebDragSource(gfx::NativeWindow source_wnd, 37 WebDragSource::WebDragSource(gfx::NativeWindow source_wnd,
36 WebContents* web_contents) 38 WebContents* web_contents,
37 : ui::DragSourceWin(), 39 ui::DragDropTypes::DragEventSource event_source)
40 : ui::DragSourceWin(event_source),
38 source_wnd_(source_wnd), 41 source_wnd_(source_wnd),
39 web_contents_(static_cast<WebContentsImpl*>(web_contents)), 42 web_contents_(static_cast<WebContentsImpl*>(web_contents)),
40 effect_(DROPEFFECT_NONE), 43 effect_(DROPEFFECT_NONE),
41 data_(NULL) { 44 data_(NULL) {
42 registrar_.Add(this, NOTIFICATION_WEB_CONTENTS_SWAPPED, 45 registrar_.Add(this, NOTIFICATION_WEB_CONTENTS_SWAPPED,
43 Source<WebContents>(web_contents)); 46 Source<WebContents>(web_contents));
44 registrar_.Add(this, NOTIFICATION_WEB_CONTENTS_DISCONNECTED, 47 registrar_.Add(this, NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
45 Source<WebContents>(web_contents)); 48 Source<WebContents>(web_contents));
46 } 49 }
47 50
(...skipping 11 matching lines...) Expand all
59 62
60 if (!web_contents_) 63 if (!web_contents_)
61 return; 64 return;
62 65
63 gfx::Point client; 66 gfx::Point client;
64 gfx::Point screen; 67 gfx::Point screen;
65 GetCursorPositions(source_wnd_, &client, &screen); 68 GetCursorPositions(source_wnd_, &client, &screen);
66 web_contents_->DragSourceEndedAt(client.x(), client.y(), 69 web_contents_->DragSourceEndedAt(client.x(), client.y(),
67 screen.x(), screen.y(), 70 screen.x(), screen.y(),
68 WebDragOperationNone); 71 WebDragOperationNone);
72 CancelLongPressGestureIfNeeded();
69 } 73 }
70 74
71 void WebDragSource::OnDragSourceDrop() { 75 void WebDragSource::OnDragSourceDrop() {
72 DCHECK(data_); 76 DCHECK(data_);
73 data_->SetInDragLoop(false); 77 data_->SetInDragLoop(false);
74 // On Windows, we check for drag end in IDropSource::QueryContinueDrag which 78 // On Windows, we check for drag end in IDropSource::QueryContinueDrag which
75 // happens before IDropTarget::Drop is called. HTML5 requires the "dragend" 79 // happens before IDropTarget::Drop is called. HTML5 requires the "dragend"
76 // event to happen after the "drop" event. Since Windows calls these two 80 // 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 81 // directly after each other we can just post a task to handle the
78 // OnDragSourceDrop after the current task. 82 // OnDragSourceDrop after the current task.
79 BrowserThread::PostTask( 83 BrowserThread::PostTask(
80 BrowserThread::UI, FROM_HERE, 84 BrowserThread::UI, FROM_HERE,
81 base::Bind(&WebDragSource::DelayedOnDragSourceDrop, this)); 85 base::Bind(&WebDragSource::DelayedOnDragSourceDrop, this));
82 } 86 }
83 87
84 void WebDragSource::DelayedOnDragSourceDrop() { 88 void WebDragSource::DelayedOnDragSourceDrop() {
85 if (!web_contents_) 89 if (!web_contents_)
86 return; 90 return;
87
88 gfx::Point client; 91 gfx::Point client;
89 gfx::Point screen; 92 gfx::Point screen;
90 GetCursorPositions(source_wnd_, &client, &screen); 93 GetCursorPositions(source_wnd_, &client, &screen);
91 web_contents_->DragSourceEndedAt(client.x(), client.y(), screen.x(), 94 web_contents_->DragSourceEndedAt(client.x(), client.y(), screen.x(),
92 screen.y(), WinDragOpToWebDragOp(effect_)); 95 screen.y(), WinDragOpToWebDragOp(effect_));
96 CancelLongPressGestureIfNeeded();
97 }
98
99 void WebDragSource::CancelLongPressGestureIfNeeded() {
100 RenderWidgetHostViewWin* rwhv =
101 static_cast<RenderWidgetHostViewWin*>(
102 web_contents_->GetRenderWidgetHostView());
103 if (rwhv->in_long_press_gesture())
104 rwhv->CancelLongPressGesture();
93 } 105 }
94 106
95 void WebDragSource::OnDragSourceMove() { 107 void WebDragSource::OnDragSourceMove() {
96 // Delegate to the UI thread if we do drag-and-drop in the background thread. 108 // Delegate to the UI thread if we do drag-and-drop in the background thread.
97 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 109 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
98 BrowserThread::PostTask( 110 BrowserThread::PostTask(
99 BrowserThread::UI, FROM_HERE, 111 BrowserThread::UI, FROM_HERE,
100 base::Bind(&WebDragSource::OnDragSourceMove, this)); 112 base::Bind(&WebDragSource::OnDragSourceMove, this));
101 return; 113 return;
102 } 114 }
(...skipping 18 matching lines...) Expand all
121 web_contents_ = NULL; 133 web_contents_ = NULL;
122 } else if (type == NOTIFICATION_WEB_CONTENTS_DISCONNECTED) { 134 } else if (type == NOTIFICATION_WEB_CONTENTS_DISCONNECTED) {
123 // This could be possible when we close the tab and the source is still 135 // 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 136 // being used in DoDragDrop at the time that the virtual file is being
125 // downloaded. 137 // downloaded.
126 web_contents_ = NULL; 138 web_contents_ = NULL;
127 } 139 }
128 } 140 }
129 141
130 } // namespace content 142 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_drag_source_win.h ('k') | ui/base/dragdrop/drag_source_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698