| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <windows.h> | 5 #include <windows.h> |
| 6 #include <shlobj.h> | 6 #include <shlobj.h> |
| 7 | 7 |
| 8 #include "chrome/browser/tab_contents/web_drop_target_win.h" | 8 #include "chrome/browser/tab_contents/web_drop_target_win.h" |
| 9 | 9 |
| 10 #include "app/clipboard/clipboard_util_win.h" | 10 #include "app/clipboard/clipboard_util_win.h" |
| 11 #include "app/os_exchange_data.h" | 11 #include "app/os_exchange_data.h" |
| 12 #include "app/os_exchange_data_provider_win.h" | 12 #include "app/os_exchange_data_provider_win.h" |
| 13 #include "chrome/browser/bookmarks/bookmark_drag_data.h" | 13 #include "chrome/browser/bookmarks/bookmark_drag_data.h" |
| 14 #include "chrome/browser/renderer_host/render_view_host.h" | 14 #include "chrome/browser/renderer_host/render_view_host.h" |
| 15 #include "chrome/browser/tab_contents/tab_contents.h" | 15 #include "chrome/browser/tab_contents/tab_contents.h" |
| 16 #include "chrome/browser/tab_contents/web_drag_utils_win.h" | 16 #include "chrome/browser/tab_contents/web_drag_utils_win.h" |
| 17 #include "gfx/point.h" | 17 #include "gfx/point.h" |
| 18 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
| 19 #include "net/base/net_util.h" | 19 #include "net/base/net_util.h" |
| 20 #include "webkit/glue/webdropdata.h" | 20 #include "webkit/glue/webdropdata.h" |
| 21 #include "webkit/glue/window_open_disposition.h" | 21 #include "webkit/glue/window_open_disposition.h" |
| 22 | 22 |
| 23 using WebKit::WebDragOperationsMask; | |
| 24 using WebKit::WebDragOperationNone; | 23 using WebKit::WebDragOperationNone; |
| 25 using WebKit::WebDragOperationCopy; | 24 using WebKit::WebDragOperationCopy; |
| 26 using WebKit::WebDragOperationLink; | 25 using WebKit::WebDragOperationLink; |
| 27 using WebKit::WebDragOperationMove; | 26 using WebKit::WebDragOperationMove; |
| 27 using WebKit::WebDragOperationGeneric; |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 // A helper method for getting the preferred drop effect. | 31 // A helper method for getting the preferred drop effect. |
| 32 DWORD GetPreferredDropEffect(DWORD effect) { | 32 DWORD GetPreferredDropEffect(DWORD effect) { |
| 33 if (effect & DROPEFFECT_COPY) | 33 if (effect & DROPEFFECT_COPY) |
| 34 return DROPEFFECT_COPY; | 34 return DROPEFFECT_COPY; |
| 35 if (effect & DROPEFFECT_LINK) | 35 if (effect & DROPEFFECT_LINK) |
| 36 return DROPEFFECT_LINK; | 36 return DROPEFFECT_LINK; |
| 37 if (effect & DROPEFFECT_MOVE) | 37 if (effect & DROPEFFECT_MOVE) |
| 38 return DROPEFFECT_MOVE; | 38 return DROPEFFECT_MOVE; |
| 39 return DROPEFFECT_NONE; | 39 return DROPEFFECT_NONE; |
| 40 } | 40 } |
| 41 | 41 |
| 42 DWORD GetPreferredDragCursor(WebDragOperationsMask op) { | |
| 43 if (op & WebDragOperationCopy) | |
| 44 return DROPEFFECT_COPY; | |
| 45 if (op & WebDragOperationLink) | |
| 46 return DROPEFFECT_LINK; | |
| 47 if (op & WebDragOperationMove) | |
| 48 return DROPEFFECT_MOVE; | |
| 49 return DROPEFFECT_NONE; | |
| 50 } | |
| 51 | |
| 52 } // anonymous namespace | 42 } // anonymous namespace |
| 53 | 43 |
| 54 // InterstitialDropTarget is like a BaseDropTarget implementation that | 44 // InterstitialDropTarget is like a BaseDropTarget implementation that |
| 55 // WebDropTarget passes through to if an interstitial is showing. Rather than | 45 // WebDropTarget passes through to if an interstitial is showing. Rather than |
| 56 // passing messages on to the renderer, we just check to see if there's a link | 46 // passing messages on to the renderer, we just check to see if there's a link |
| 57 // in the drop data and handle links as navigations. | 47 // in the drop data and handle links as navigations. |
| 58 class InterstitialDropTarget { | 48 class InterstitialDropTarget { |
| 59 public: | 49 public: |
| 60 explicit InterstitialDropTarget(TabContents* tab_contents) | 50 explicit InterstitialDropTarget(TabContents* tab_contents) |
| 61 : tab_contents_(tab_contents) {} | 51 : tab_contents_(tab_contents) {} |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 // support for (at the moment experimental) drag and drop extensions. | 128 // support for (at the moment experimental) drag and drop extensions. |
| 139 if (tab_contents_->GetBookmarkDragDelegate()) { | 129 if (tab_contents_->GetBookmarkDragDelegate()) { |
| 140 OSExchangeData os_exchange_data(new OSExchangeDataProviderWin(data_object)); | 130 OSExchangeData os_exchange_data(new OSExchangeDataProviderWin(data_object)); |
| 141 BookmarkDragData bookmark_drag_data; | 131 BookmarkDragData bookmark_drag_data; |
| 142 if (bookmark_drag_data.Read(os_exchange_data)) | 132 if (bookmark_drag_data.Read(os_exchange_data)) |
| 143 tab_contents_->GetBookmarkDragDelegate()->OnDragEnter(bookmark_drag_data); | 133 tab_contents_->GetBookmarkDragDelegate()->OnDragEnter(bookmark_drag_data); |
| 144 } | 134 } |
| 145 | 135 |
| 146 // 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 |
| 147 // wait for the IPC call to return. | 137 // wait for the IPC call to return. |
| 148 return GetPreferredDragCursor(drag_cursor_); | 138 DCHECK(drag_cursor_ == WebDragOperationNone || |
| 139 drag_cursor_ == WebDragOperationCopy || |
| 140 drag_cursor_ == WebDragOperationLink || |
| 141 drag_cursor_ == (WebDragOperationMove | WebDragOperationGeneric)); |
| 142 return web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_); |
| 149 } | 143 } |
| 150 | 144 |
| 151 DWORD WebDropTarget::OnDragOver(IDataObject* data_object, | 145 DWORD WebDropTarget::OnDragOver(IDataObject* data_object, |
| 152 DWORD key_state, | 146 DWORD key_state, |
| 153 POINT cursor_position, | 147 POINT cursor_position, |
| 154 DWORD effect) { | 148 DWORD effect) { |
| 155 DCHECK(current_rvh_); | 149 DCHECK(current_rvh_); |
| 156 if (current_rvh_ != tab_contents_->render_view_host()) | 150 if (current_rvh_ != tab_contents_->render_view_host()) |
| 157 OnDragEnter(data_object, key_state, cursor_position, effect); | 151 OnDragEnter(data_object, key_state, cursor_position, effect); |
| 158 | 152 |
| 159 if (tab_contents_->showing_interstitial_page()) | 153 if (tab_contents_->showing_interstitial_page()) |
| 160 return interstitial_drop_target_->OnDragOver(data_object, effect); | 154 return interstitial_drop_target_->OnDragOver(data_object, effect); |
| 161 | 155 |
| 162 POINT client_pt = cursor_position; | 156 POINT client_pt = cursor_position; |
| 163 ScreenToClient(GetHWND(), &client_pt); | 157 ScreenToClient(GetHWND(), &client_pt); |
| 164 tab_contents_->render_view_host()->DragTargetDragOver( | 158 tab_contents_->render_view_host()->DragTargetDragOver( |
| 165 gfx::Point(client_pt.x, client_pt.y), | 159 gfx::Point(client_pt.x, client_pt.y), |
| 166 gfx::Point(cursor_position.x, cursor_position.y), | 160 gfx::Point(cursor_position.x, cursor_position.y), |
| 167 web_drag_utils_win::WinDragOpToWebDragOp(effect)); | 161 web_drag_utils_win::WinDragOpToWebDragOp(effect)); |
| 168 | 162 |
| 169 if (tab_contents_->GetBookmarkDragDelegate()) { | 163 if (tab_contents_->GetBookmarkDragDelegate()) { |
| 170 OSExchangeData os_exchange_data(new OSExchangeDataProviderWin(data_object)); | 164 OSExchangeData os_exchange_data(new OSExchangeDataProviderWin(data_object)); |
| 171 BookmarkDragData bookmark_drag_data; | 165 BookmarkDragData bookmark_drag_data; |
| 172 if (bookmark_drag_data.Read(os_exchange_data)) | 166 if (bookmark_drag_data.Read(os_exchange_data)) |
| 173 tab_contents_->GetBookmarkDragDelegate()->OnDragOver(bookmark_drag_data); | 167 tab_contents_->GetBookmarkDragDelegate()->OnDragOver(bookmark_drag_data); |
| 174 } | 168 } |
| 175 | 169 |
| 176 return GetPreferredDragCursor(drag_cursor_); | 170 DCHECK(drag_cursor_ == WebDragOperationNone || |
| 171 drag_cursor_ == WebDragOperationCopy || |
| 172 drag_cursor_ == WebDragOperationLink || |
| 173 drag_cursor_ == (WebDragOperationMove | WebDragOperationGeneric)); |
| 174 return web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_); |
| 177 } | 175 } |
| 178 | 176 |
| 179 void WebDropTarget::OnDragLeave(IDataObject* data_object) { | 177 void WebDropTarget::OnDragLeave(IDataObject* data_object) { |
| 180 DCHECK(current_rvh_); | 178 DCHECK(current_rvh_); |
| 181 if (current_rvh_ != tab_contents_->render_view_host()) | 179 if (current_rvh_ != tab_contents_->render_view_host()) |
| 182 return; | 180 return; |
| 183 | 181 |
| 184 if (tab_contents_->showing_interstitial_page()) { | 182 if (tab_contents_->showing_interstitial_page()) { |
| 185 interstitial_drop_target_->OnDragLeave(data_object); | 183 interstitial_drop_target_->OnDragLeave(data_object); |
| 186 } else { | 184 } else { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 217 | 215 |
| 218 if (tab_contents_->GetBookmarkDragDelegate()) { | 216 if (tab_contents_->GetBookmarkDragDelegate()) { |
| 219 OSExchangeData os_exchange_data(new OSExchangeDataProviderWin(data_object)); | 217 OSExchangeData os_exchange_data(new OSExchangeDataProviderWin(data_object)); |
| 220 BookmarkDragData bookmark_drag_data; | 218 BookmarkDragData bookmark_drag_data; |
| 221 if (bookmark_drag_data.Read(os_exchange_data)) | 219 if (bookmark_drag_data.Read(os_exchange_data)) |
| 222 tab_contents_->GetBookmarkDragDelegate()->OnDrop(bookmark_drag_data); | 220 tab_contents_->GetBookmarkDragDelegate()->OnDrop(bookmark_drag_data); |
| 223 } | 221 } |
| 224 | 222 |
| 225 current_rvh_ = NULL; | 223 current_rvh_ = NULL; |
| 226 | 224 |
| 227 // We lie and always claim that the drop operation didn't happen because we | 225 // This isn't always correct, but at least it's a close approximation. |
| 228 // don't want to wait for the renderer to respond. | 226 // For now, we always map a move to a copy to prevent potential data loss. |
| 229 return DROPEFFECT_NONE; | 227 DWORD drop_effect = web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_); |
| 228 return drop_effect != DROPEFFECT_MOVE ? drop_effect : DROPEFFECT_COPY; |
| 230 } | 229 } |
| OLD | NEW |