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

Side by Side Diff: content/browser/tab_contents/web_drag_dest_win.cc

Issue 9562049: Move the core drag&drop code for Windows to content\browser to match Mac/GTK. I've had to add tempo… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/tab_contents/web_drop_target_win.h" 5 #include "content/browser/tab_contents/web_drag_dest_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <shlobj.h> 8 #include <shlobj.h>
9 9
10 #include "chrome/browser/tab_contents/web_drag_bookmark_handler_win.h"
11 #include "chrome/browser/tab_contents/web_drag_utils_win.h"
12 #include "content/browser/renderer_host/render_view_host.h" 10 #include "content/browser/renderer_host/render_view_host.h"
13 #include "content/browser/tab_contents/web_drag_dest_delegate.h" 11 #include "content/browser/tab_contents/web_drag_dest_delegate.h"
12 #include "content/browser/tab_contents/web_drag_utils_win.h"
14 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
15 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
16 #include "net/base/net_util.h" 15 #include "net/base/net_util.h"
17 #include "ui/base/clipboard/clipboard_util_win.h" 16 #include "ui/base/clipboard/clipboard_util_win.h"
18 #include "ui/base/dragdrop/os_exchange_data.h" 17 #include "ui/base/dragdrop/os_exchange_data.h"
19 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" 18 #include "ui/base/dragdrop/os_exchange_data_provider_win.h"
20 #include "ui/gfx/point.h" 19 #include "ui/gfx/point.h"
21 #include "webkit/glue/webdropdata.h" 20 #include "webkit/glue/webdropdata.h"
22 #include "webkit/glue/window_open_disposition.h" 21 #include "webkit/glue/window_open_disposition.h"
23 22
(...skipping 15 matching lines...) Expand all
39 if (effect & DROPEFFECT_LINK) 38 if (effect & DROPEFFECT_LINK)
40 return DROPEFFECT_LINK; 39 return DROPEFFECT_LINK;
41 if (effect & DROPEFFECT_MOVE) 40 if (effect & DROPEFFECT_MOVE)
42 return DROPEFFECT_MOVE; 41 return DROPEFFECT_MOVE;
43 return DROPEFFECT_NONE; 42 return DROPEFFECT_NONE;
44 } 43 }
45 44
46 } // namespace 45 } // namespace
47 46
48 // InterstitialDropTarget is like a ui::DropTarget implementation that 47 // InterstitialDropTarget is like a ui::DropTarget implementation that
49 // WebDropTarget passes through to if an interstitial is showing. Rather than 48 // WebDragDest passes through to if an interstitial is showing. Rather than
50 // passing messages on to the renderer, we just check to see if there's a link 49 // passing messages on to the renderer, we just check to see if there's a link
51 // in the drop data and handle links as navigations. 50 // in the drop data and handle links as navigations.
52 class InterstitialDropTarget { 51 class InterstitialDropTarget {
53 public: 52 public:
54 explicit InterstitialDropTarget(WebContents* web_contents) 53 explicit InterstitialDropTarget(WebContents* web_contents)
55 : web_contents_(web_contents) {} 54 : web_contents_(web_contents) {}
56 55
57 DWORD OnDragEnter(IDataObject* data_object, DWORD effect) { 56 DWORD OnDragEnter(IDataObject* data_object, DWORD effect) {
58 return ui::ClipboardUtil::HasUrl(data_object) ? 57 return ui::ClipboardUtil::HasUrl(data_object) ?
59 GetPreferredDropEffect(effect) : DROPEFFECT_NONE; 58 GetPreferredDropEffect(effect) : DROPEFFECT_NONE;
(...skipping 20 matching lines...) Expand all
80 web_contents_->OpenURL(params); 79 web_contents_->OpenURL(params);
81 return GetPreferredDropEffect(effect); 80 return GetPreferredDropEffect(effect);
82 } 81 }
83 82
84 private: 83 private:
85 WebContents* web_contents_; 84 WebContents* web_contents_;
86 85
87 DISALLOW_COPY_AND_ASSIGN(InterstitialDropTarget); 86 DISALLOW_COPY_AND_ASSIGN(InterstitialDropTarget);
88 }; 87 };
89 88
90 WebDropTarget::WebDropTarget(HWND source_hwnd, WebContents* web_contents) 89 WebDragDest::WebDragDest(HWND source_hwnd, WebContents* web_contents)
91 : ui::DropTarget(source_hwnd), 90 : ui::DropTarget(source_hwnd),
92 web_contents_(web_contents), 91 web_contents_(web_contents),
93 current_rvh_(NULL), 92 current_rvh_(NULL),
94 drag_cursor_(WebDragOperationNone), 93 drag_cursor_(WebDragOperationNone),
95 interstitial_drop_target_(new InterstitialDropTarget(web_contents)), 94 interstitial_drop_target_(new InterstitialDropTarget(web_contents)),
96 delegate_(new WebDragBookmarkHandlerWin()) { 95 delegate_(NULL) {
97 } 96 }
98 97
99 WebDropTarget::~WebDropTarget() { 98 WebDragDest::~WebDragDest() {
100 // TODO(jam): this will be owned by chrome when it moves, so no scoped
101 // pointer.
102 if (delegate_)
103 delete delegate_;
104 } 99 }
105 100
106 DWORD WebDropTarget::OnDragEnter(IDataObject* data_object, 101 DWORD WebDragDest::OnDragEnter(IDataObject* data_object,
107 DWORD key_state, 102 DWORD key_state,
108 POINT cursor_position, 103 POINT cursor_position,
109 DWORD effects) { 104 DWORD effects) {
110 current_rvh_ = web_contents_->GetRenderViewHost(); 105 current_rvh_ = web_contents_->GetRenderViewHost();
111 106
112 if (delegate_) 107 if (delegate_)
113 delegate_->DragInitialize(web_contents_); 108 delegate_->DragInitialize(web_contents_);
114 109
115 // Don't pass messages to the renderer if an interstitial page is showing 110 // Don't pass messages to the renderer if an interstitial page is showing
116 // because we don't want the interstitial page to navigate. Instead, 111 // because we don't want the interstitial page to navigate. Instead,
117 // pass the messages on to a separate interstitial DropTarget handler. 112 // pass the messages on to a separate interstitial DropTarget handler.
118 if (web_contents_->ShowingInterstitialPage()) 113 if (web_contents_->ShowingInterstitialPage())
119 return interstitial_drop_target_->OnDragEnter(data_object, effects); 114 return interstitial_drop_target_->OnDragEnter(data_object, effects);
(...skipping 16 matching lines...) Expand all
136 web_drag_utils_win::WinDragOpMaskToWebDragOpMask(effects)); 131 web_drag_utils_win::WinDragOpMaskToWebDragOpMask(effects));
137 132
138 if (delegate_) 133 if (delegate_)
139 delegate_->OnDragEnter(data_object); 134 delegate_->OnDragEnter(data_object);
140 135
141 // We lie here and always return a DROPEFFECT because we don't want to 136 // We lie here and always return a DROPEFFECT because we don't want to
142 // wait for the IPC call to return. 137 // wait for the IPC call to return.
143 return web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_); 138 return web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_);
144 } 139 }
145 140
146 DWORD WebDropTarget::OnDragOver(IDataObject* data_object, 141 DWORD WebDragDest::OnDragOver(IDataObject* data_object,
147 DWORD key_state, 142 DWORD key_state,
148 POINT cursor_position, 143 POINT cursor_position,
149 DWORD effects) { 144 DWORD effects) {
150 DCHECK(current_rvh_); 145 DCHECK(current_rvh_);
151 if (current_rvh_ != web_contents_->GetRenderViewHost()) 146 if (current_rvh_ != web_contents_->GetRenderViewHost())
152 OnDragEnter(data_object, key_state, cursor_position, effects); 147 OnDragEnter(data_object, key_state, cursor_position, effects);
153 148
154 if (web_contents_->ShowingInterstitialPage()) 149 if (web_contents_->ShowingInterstitialPage())
155 return interstitial_drop_target_->OnDragOver(data_object, effects); 150 return interstitial_drop_target_->OnDragOver(data_object, effects);
156 151
157 POINT client_pt = cursor_position; 152 POINT client_pt = cursor_position;
158 ScreenToClient(GetHWND(), &client_pt); 153 ScreenToClient(GetHWND(), &client_pt);
159 web_contents_->GetRenderViewHost()->DragTargetDragOver( 154 web_contents_->GetRenderViewHost()->DragTargetDragOver(
160 gfx::Point(client_pt.x, client_pt.y), 155 gfx::Point(client_pt.x, client_pt.y),
161 gfx::Point(cursor_position.x, cursor_position.y), 156 gfx::Point(cursor_position.x, cursor_position.y),
162 web_drag_utils_win::WinDragOpMaskToWebDragOpMask(effects)); 157 web_drag_utils_win::WinDragOpMaskToWebDragOpMask(effects));
163 158
164 if (delegate_) 159 if (delegate_)
165 delegate_->OnDragOver(data_object); 160 delegate_->OnDragOver(data_object);
166 161
167 return web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_); 162 return web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_);
168 } 163 }
169 164
170 void WebDropTarget::OnDragLeave(IDataObject* data_object) { 165 void WebDragDest::OnDragLeave(IDataObject* data_object) {
171 DCHECK(current_rvh_); 166 DCHECK(current_rvh_);
172 if (current_rvh_ != web_contents_->GetRenderViewHost()) 167 if (current_rvh_ != web_contents_->GetRenderViewHost())
173 return; 168 return;
174 169
175 if (web_contents_->ShowingInterstitialPage()) { 170 if (web_contents_->ShowingInterstitialPage()) {
176 interstitial_drop_target_->OnDragLeave(data_object); 171 interstitial_drop_target_->OnDragLeave(data_object);
177 } else { 172 } else {
178 web_contents_->GetRenderViewHost()->DragTargetDragLeave(); 173 web_contents_->GetRenderViewHost()->DragTargetDragLeave();
179 } 174 }
180 175
181 if (delegate_) 176 if (delegate_)
182 delegate_->OnDragLeave(data_object); 177 delegate_->OnDragLeave(data_object);
183 } 178 }
184 179
185 DWORD WebDropTarget::OnDrop(IDataObject* data_object, 180 DWORD WebDragDest::OnDrop(IDataObject* data_object,
186 DWORD key_state, 181 DWORD key_state,
187 POINT cursor_position, 182 POINT cursor_position,
188 DWORD effect) { 183 DWORD effect) {
189 DCHECK(current_rvh_); 184 DCHECK(current_rvh_);
190 if (current_rvh_ != web_contents_->GetRenderViewHost()) 185 if (current_rvh_ != web_contents_->GetRenderViewHost())
191 OnDragEnter(data_object, key_state, cursor_position, effect); 186 OnDragEnter(data_object, key_state, cursor_position, effect);
192 187
193 if (web_contents_->ShowingInterstitialPage()) 188 if (web_contents_->ShowingInterstitialPage())
194 interstitial_drop_target_->OnDragOver(data_object, effect); 189 interstitial_drop_target_->OnDragOver(data_object, effect);
195 190
196 if (web_contents_->ShowingInterstitialPage()) 191 if (web_contents_->ShowingInterstitialPage())
197 return interstitial_drop_target_->OnDrop(data_object, effect); 192 return interstitial_drop_target_->OnDrop(data_object, effect);
198 193
199 POINT client_pt = cursor_position; 194 POINT client_pt = cursor_position;
200 ScreenToClient(GetHWND(), &client_pt); 195 ScreenToClient(GetHWND(), &client_pt);
201 web_contents_->GetRenderViewHost()->DragTargetDrop( 196 web_contents_->GetRenderViewHost()->DragTargetDrop(
202 gfx::Point(client_pt.x, client_pt.y), 197 gfx::Point(client_pt.x, client_pt.y),
203 gfx::Point(cursor_position.x, cursor_position.y)); 198 gfx::Point(cursor_position.x, cursor_position.y));
204 199
205 if (delegate_) 200 if (delegate_)
206 delegate_->OnDrop(data_object); 201 delegate_->OnDrop(data_object);
207 202
208 current_rvh_ = NULL; 203 current_rvh_ = NULL;
209 204
210 // This isn't always correct, but at least it's a close approximation. 205 // This isn't always correct, but at least it's a close approximation.
211 // For now, we always map a move to a copy to prevent potential data loss. 206 // For now, we always map a move to a copy to prevent potential data loss.
212 DWORD drop_effect = web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_); 207 DWORD drop_effect = web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_);
213 return drop_effect != DROPEFFECT_MOVE ? drop_effect : DROPEFFECT_COPY; 208 return drop_effect != DROPEFFECT_MOVE ? drop_effect : DROPEFFECT_COPY;
214 } 209 }
OLDNEW
« no previous file with comments | « content/browser/tab_contents/web_drag_dest_win.h ('k') | content/browser/tab_contents/web_drag_source_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698