Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_dest_win.h" | 5 #include "content/browser/web_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 "content/browser/renderer_host/render_view_host_impl.h" | 10 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 11 #include "content/browser/web_contents/web_drag_utils_win.h" | 11 #include "content/browser/web_contents/web_drag_utils_win.h" |
| 12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 13 #include "content/public/browser/web_drag_dest_delegate.h" | 13 #include "content/public/browser/web_drag_dest_delegate.h" |
| 14 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
| 15 #include "net/base/net_util.h" | 15 #include "net/base/net_util.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 17 #include "ui/base/clipboard/clipboard_util_win.h" | 17 #include "ui/base/clipboard/clipboard_util_win.h" |
| 18 #include "ui/base/dragdrop/os_exchange_data.h" | 18 #include "ui/base/dragdrop/os_exchange_data.h" |
| 19 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" | 19 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" |
| 20 #include "ui/gfx/point.h" | 20 #include "ui/gfx/point.h" |
| 21 #include "webkit/glue/webdropdata.h" | 21 #include "webkit/glue/webdropdata.h" |
| 22 #include "webkit/glue/window_open_disposition.h" | 22 #include "webkit/glue/window_open_disposition.h" |
| 23 | 23 |
| 24 using WebKit::WebDragOperationNone; | 24 using WebKit::WebDragOperationNone; |
| 25 using WebKit::WebDragOperationCopy; | 25 using WebKit::WebDragOperationCopy; |
| 26 using WebKit::WebDragOperationLink; | 26 using WebKit::WebDragOperationLink; |
| 27 using WebKit::WebDragOperationMove; | 27 using WebKit::WebDragOperationMove; |
| 28 using WebKit::WebDragOperationGeneric; | 28 using WebKit::WebDragOperationGeneric; |
| 29 using content::OpenURLParams; | |
| 30 using content::Referrer; | |
| 31 using content::WebContents; | |
| 32 | 29 |
| 30 namespace content { | |
| 33 namespace { | 31 namespace { |
| 34 | 32 |
| 35 const unsigned short kHighBitMaskShort = 0x8000; | 33 const unsigned short kHighBitMaskShort = 0x8000; |
| 36 | 34 |
| 37 // A helper method for getting the preferred drop effect. | 35 // A helper method for getting the preferred drop effect. |
| 38 DWORD GetPreferredDropEffect(DWORD effect) { | 36 DWORD GetPreferredDropEffect(DWORD effect) { |
| 39 if (effect & DROPEFFECT_COPY) | 37 if (effect & DROPEFFECT_COPY) |
| 40 return DROPEFFECT_COPY; | 38 return DROPEFFECT_COPY; |
| 41 if (effect & DROPEFFECT_LINK) | 39 if (effect & DROPEFFECT_LINK) |
| 42 return DROPEFFECT_LINK; | 40 return DROPEFFECT_LINK; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 void OnDragLeave(IDataObject* data_object) { | 82 void OnDragLeave(IDataObject* data_object) { |
| 85 } | 83 } |
| 86 | 84 |
| 87 DWORD OnDrop(IDataObject* data_object, DWORD effect) { | 85 DWORD OnDrop(IDataObject* data_object, DWORD effect) { |
| 88 if (!ui::ClipboardUtil::HasUrl(data_object)) | 86 if (!ui::ClipboardUtil::HasUrl(data_object)) |
| 89 return DROPEFFECT_NONE; | 87 return DROPEFFECT_NONE; |
| 90 | 88 |
| 91 std::wstring url; | 89 std::wstring url; |
| 92 std::wstring title; | 90 std::wstring title; |
| 93 ui::ClipboardUtil::GetUrl(data_object, &url, &title, true); | 91 ui::ClipboardUtil::GetUrl(data_object, &url, &title, true); |
| 94 OpenURLParams params( | 92 OpenURLParams params( |
|
tfarina
2012/10/29 19:37:19
OpenURLParams params(GURL(url), Referrer(), CURREN
jam
2012/10/29 20:01:51
Done.
| |
| 95 GURL(url), Referrer(), CURRENT_TAB, | 93 GURL(url), Referrer(), CURRENT_TAB, |
| 96 content::PAGE_TRANSITION_AUTO_BOOKMARK, false); | 94 PAGE_TRANSITION_AUTO_BOOKMARK, false); |
| 97 web_contents_->OpenURL(params); | 95 web_contents_->OpenURL(params); |
| 98 return GetPreferredDropEffect(effect); | 96 return GetPreferredDropEffect(effect); |
| 99 } | 97 } |
| 100 | 98 |
| 101 private: | 99 private: |
| 102 WebContents* web_contents_; | 100 WebContents* web_contents_; |
| 103 | 101 |
| 104 DISALLOW_COPY_AND_ASSIGN(InterstitialDropTarget); | 102 DISALLOW_COPY_AND_ASSIGN(InterstitialDropTarget); |
| 105 }; | 103 }; |
| 106 | 104 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 ui::OSExchangeDataProviderWin::GetPlainTextURL(data_object, | 138 ui::OSExchangeDataProviderWin::GetPlainTextURL(data_object, |
| 141 &drop_data_->url); | 139 &drop_data_->url); |
| 142 | 140 |
| 143 drag_cursor_ = WebDragOperationNone; | 141 drag_cursor_ = WebDragOperationNone; |
| 144 | 142 |
| 145 POINT client_pt = cursor_position; | 143 POINT client_pt = cursor_position; |
| 146 ScreenToClient(GetHWND(), &client_pt); | 144 ScreenToClient(GetHWND(), &client_pt); |
| 147 web_contents_->GetRenderViewHost()->DragTargetDragEnter(*drop_data_, | 145 web_contents_->GetRenderViewHost()->DragTargetDragEnter(*drop_data_, |
| 148 gfx::Point(client_pt.x, client_pt.y), | 146 gfx::Point(client_pt.x, client_pt.y), |
| 149 gfx::Point(cursor_position.x, cursor_position.y), | 147 gfx::Point(cursor_position.x, cursor_position.y), |
| 150 web_drag_utils_win::WinDragOpMaskToWebDragOpMask(effects), | 148 WinDragOpMaskToWebDragOpMask(effects), |
| 151 GetModifierFlags()); | 149 GetModifierFlags()); |
| 152 | 150 |
| 153 if (delegate_) | 151 if (delegate_) |
| 154 delegate_->OnDragEnter(data_object); | 152 delegate_->OnDragEnter(data_object); |
| 155 | 153 |
| 156 // We lie here and always return a DROPEFFECT because we don't want to | 154 // We lie here and always return a DROPEFFECT because we don't want to |
| 157 // wait for the IPC call to return. | 155 // wait for the IPC call to return. |
| 158 return web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_); | 156 return WebDragOpToWinDragOp(drag_cursor_); |
| 159 } | 157 } |
| 160 | 158 |
| 161 DWORD WebDragDest::OnDragOver(IDataObject* data_object, | 159 DWORD WebDragDest::OnDragOver(IDataObject* data_object, |
| 162 DWORD key_state, | 160 DWORD key_state, |
| 163 POINT cursor_position, | 161 POINT cursor_position, |
| 164 DWORD effects) { | 162 DWORD effects) { |
| 165 DCHECK(current_rvh_); | 163 DCHECK(current_rvh_); |
| 166 if (current_rvh_ != web_contents_->GetRenderViewHost()) | 164 if (current_rvh_ != web_contents_->GetRenderViewHost()) |
| 167 OnDragEnter(data_object, key_state, cursor_position, effects); | 165 OnDragEnter(data_object, key_state, cursor_position, effects); |
| 168 | 166 |
| 169 if (web_contents_->ShowingInterstitialPage()) | 167 if (web_contents_->ShowingInterstitialPage()) |
| 170 return interstitial_drop_target_->OnDragOver(data_object, effects); | 168 return interstitial_drop_target_->OnDragOver(data_object, effects); |
| 171 | 169 |
| 172 POINT client_pt = cursor_position; | 170 POINT client_pt = cursor_position; |
| 173 ScreenToClient(GetHWND(), &client_pt); | 171 ScreenToClient(GetHWND(), &client_pt); |
| 174 web_contents_->GetRenderViewHost()->DragTargetDragOver( | 172 web_contents_->GetRenderViewHost()->DragTargetDragOver( |
| 175 gfx::Point(client_pt.x, client_pt.y), | 173 gfx::Point(client_pt.x, client_pt.y), |
| 176 gfx::Point(cursor_position.x, cursor_position.y), | 174 gfx::Point(cursor_position.x, cursor_position.y), |
| 177 web_drag_utils_win::WinDragOpMaskToWebDragOpMask(effects), | 175 WinDragOpMaskToWebDragOpMask(effects), |
| 178 GetModifierFlags()); | 176 GetModifierFlags()); |
| 179 | 177 |
| 180 if (delegate_) | 178 if (delegate_) |
| 181 delegate_->OnDragOver(data_object); | 179 delegate_->OnDragOver(data_object); |
| 182 | 180 |
| 183 return web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_); | 181 return WebDragOpToWinDragOp(drag_cursor_); |
| 184 } | 182 } |
| 185 | 183 |
| 186 void WebDragDest::OnDragLeave(IDataObject* data_object) { | 184 void WebDragDest::OnDragLeave(IDataObject* data_object) { |
| 187 DCHECK(current_rvh_); | 185 DCHECK(current_rvh_); |
| 188 if (current_rvh_ != web_contents_->GetRenderViewHost()) | 186 if (current_rvh_ != web_contents_->GetRenderViewHost()) |
| 189 return; | 187 return; |
| 190 | 188 |
| 191 if (web_contents_->ShowingInterstitialPage()) { | 189 if (web_contents_->ShowingInterstitialPage()) { |
| 192 interstitial_drop_target_->OnDragLeave(data_object); | 190 interstitial_drop_target_->OnDragLeave(data_object); |
| 193 } else { | 191 } else { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 221 gfx::Point(cursor_position.x, cursor_position.y), | 219 gfx::Point(cursor_position.x, cursor_position.y), |
| 222 GetModifierFlags()); | 220 GetModifierFlags()); |
| 223 | 221 |
| 224 if (delegate_) | 222 if (delegate_) |
| 225 delegate_->OnDrop(data_object); | 223 delegate_->OnDrop(data_object); |
| 226 | 224 |
| 227 current_rvh_ = NULL; | 225 current_rvh_ = NULL; |
| 228 | 226 |
| 229 // This isn't always correct, but at least it's a close approximation. | 227 // This isn't always correct, but at least it's a close approximation. |
| 230 // For now, we always map a move to a copy to prevent potential data loss. | 228 // For now, we always map a move to a copy to prevent potential data loss. |
| 231 DWORD drop_effect = web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_); | 229 DWORD drop_effect = WebDragOpToWinDragOp(drag_cursor_); |
| 232 DWORD result = drop_effect != DROPEFFECT_MOVE ? | 230 DWORD result = drop_effect != DROPEFFECT_MOVE ? |
| 233 drop_effect : DROPEFFECT_COPY; | 231 drop_effect : DROPEFFECT_COPY; |
|
tfarina
2012/10/29 19:37:19
this does fits above.
jam
2012/10/29 20:01:51
Done.
| |
| 234 | 232 |
| 235 drop_data_.reset(); | 233 drop_data_.reset(); |
| 236 return result; | 234 return result; |
| 237 } | 235 } |
| 236 | |
| 237 } // namespace content | |
| OLD | NEW |