| 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 "ui/base/clipboard/clipboard_util_win.h" | 17 #include "ui/base/clipboard/clipboard_util_win.h" |
| 17 #include "ui/base/dragdrop/os_exchange_data.h" | 18 #include "ui/base/dragdrop/os_exchange_data.h" |
| 18 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" | 19 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" |
| 19 #include "ui/gfx/point.h" | 20 #include "ui/gfx/point.h" |
| 20 #include "webkit/glue/webdropdata.h" | 21 #include "webkit/glue/webdropdata.h" |
| 21 #include "webkit/glue/window_open_disposition.h" | 22 #include "webkit/glue/window_open_disposition.h" |
| 22 | 23 |
| 23 using WebKit::WebDragOperationNone; | 24 using WebKit::WebDragOperationNone; |
| 24 using WebKit::WebDragOperationCopy; | 25 using WebKit::WebDragOperationCopy; |
| 25 using WebKit::WebDragOperationLink; | 26 using WebKit::WebDragOperationLink; |
| 26 using WebKit::WebDragOperationMove; | 27 using WebKit::WebDragOperationMove; |
| 27 using WebKit::WebDragOperationGeneric; | 28 using WebKit::WebDragOperationGeneric; |
| 28 using content::OpenURLParams; | 29 using content::OpenURLParams; |
| 29 using content::Referrer; | 30 using content::Referrer; |
| 30 using content::WebContents; | 31 using content::WebContents; |
| 31 | 32 |
| 32 namespace { | 33 namespace { |
| 33 | 34 |
| 35 const unsigned short kHighBitMaskShort = 0x8000; |
| 36 |
| 34 // A helper method for getting the preferred drop effect. | 37 // A helper method for getting the preferred drop effect. |
| 35 DWORD GetPreferredDropEffect(DWORD effect) { | 38 DWORD GetPreferredDropEffect(DWORD effect) { |
| 36 if (effect & DROPEFFECT_COPY) | 39 if (effect & DROPEFFECT_COPY) |
| 37 return DROPEFFECT_COPY; | 40 return DROPEFFECT_COPY; |
| 38 if (effect & DROPEFFECT_LINK) | 41 if (effect & DROPEFFECT_LINK) |
| 39 return DROPEFFECT_LINK; | 42 return DROPEFFECT_LINK; |
| 40 if (effect & DROPEFFECT_MOVE) | 43 if (effect & DROPEFFECT_MOVE) |
| 41 return DROPEFFECT_MOVE; | 44 return DROPEFFECT_MOVE; |
| 42 return DROPEFFECT_NONE; | 45 return DROPEFFECT_NONE; |
| 43 } | 46 } |
| 44 | 47 |
| 48 int GetModifierFlags() { |
| 49 int modifier_state = 0; |
| 50 if (::GetKeyState(VK_SHIFT) & kHighBitMaskShort) |
| 51 modifier_state |= WebKit::WebInputEvent::ShiftKey; |
| 52 if (::GetKeyState(VK_CONTROL) & kHighBitMaskShort) |
| 53 modifier_state |= WebKit::WebInputEvent::ControlKey; |
| 54 if (::GetKeyState(VK_MENU) & kHighBitMaskShort) |
| 55 modifier_state |= WebKit::WebInputEvent::AltKey; |
| 56 if (::GetKeyState(VK_LWIN) & kHighBitMaskShort) |
| 57 modifier_state |= WebKit::WebInputEvent::MetaKey; |
| 58 if (::GetKeyState(VK_RWIN) & kHighBitMaskShort) |
| 59 modifier_state |= WebKit::WebInputEvent::MetaKey; |
| 60 return modifier_state; |
| 61 } |
| 62 |
| 45 } // namespace | 63 } // namespace |
| 46 | 64 |
| 47 // InterstitialDropTarget is like a ui::DropTarget implementation that | 65 // InterstitialDropTarget is like a ui::DropTarget implementation that |
| 48 // WebDragDest passes through to if an interstitial is showing. Rather than | 66 // WebDragDest passes through to if an interstitial is showing. Rather than |
| 49 // passing messages on to the renderer, we just check to see if there's a link | 67 // passing messages on to the renderer, we just check to see if there's a link |
| 50 // in the drop data and handle links as navigations. | 68 // in the drop data and handle links as navigations. |
| 51 class InterstitialDropTarget { | 69 class InterstitialDropTarget { |
| 52 public: | 70 public: |
| 53 explicit InterstitialDropTarget(WebContents* web_contents) | 71 explicit InterstitialDropTarget(WebContents* web_contents) |
| 54 : web_contents_(web_contents) {} | 72 : web_contents_(web_contents) {} |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 ui::OSExchangeDataProviderWin::GetPlainTextURL(data_object, | 140 ui::OSExchangeDataProviderWin::GetPlainTextURL(data_object, |
| 123 &drop_data_->url); | 141 &drop_data_->url); |
| 124 | 142 |
| 125 drag_cursor_ = WebDragOperationNone; | 143 drag_cursor_ = WebDragOperationNone; |
| 126 | 144 |
| 127 POINT client_pt = cursor_position; | 145 POINT client_pt = cursor_position; |
| 128 ScreenToClient(GetHWND(), &client_pt); | 146 ScreenToClient(GetHWND(), &client_pt); |
| 129 web_contents_->GetRenderViewHost()->DragTargetDragEnter(*drop_data_, | 147 web_contents_->GetRenderViewHost()->DragTargetDragEnter(*drop_data_, |
| 130 gfx::Point(client_pt.x, client_pt.y), | 148 gfx::Point(client_pt.x, client_pt.y), |
| 131 gfx::Point(cursor_position.x, cursor_position.y), | 149 gfx::Point(cursor_position.x, cursor_position.y), |
| 132 web_drag_utils_win::WinDragOpMaskToWebDragOpMask(effects)); | 150 web_drag_utils_win::WinDragOpMaskToWebDragOpMask(effects), |
| 151 GetModifierFlags()); |
| 133 | 152 |
| 134 if (delegate_) | 153 if (delegate_) |
| 135 delegate_->OnDragEnter(data_object); | 154 delegate_->OnDragEnter(data_object); |
| 136 | 155 |
| 137 // We lie here and always return a DROPEFFECT because we don't want to | 156 // We lie here and always return a DROPEFFECT because we don't want to |
| 138 // wait for the IPC call to return. | 157 // wait for the IPC call to return. |
| 139 return web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_); | 158 return web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_); |
| 140 } | 159 } |
| 141 | 160 |
| 142 DWORD WebDragDest::OnDragOver(IDataObject* data_object, | 161 DWORD WebDragDest::OnDragOver(IDataObject* data_object, |
| 143 DWORD key_state, | 162 DWORD key_state, |
| 144 POINT cursor_position, | 163 POINT cursor_position, |
| 145 DWORD effects) { | 164 DWORD effects) { |
| 146 DCHECK(current_rvh_); | 165 DCHECK(current_rvh_); |
| 147 if (current_rvh_ != web_contents_->GetRenderViewHost()) | 166 if (current_rvh_ != web_contents_->GetRenderViewHost()) |
| 148 OnDragEnter(data_object, key_state, cursor_position, effects); | 167 OnDragEnter(data_object, key_state, cursor_position, effects); |
| 149 | 168 |
| 150 if (web_contents_->ShowingInterstitialPage()) | 169 if (web_contents_->ShowingInterstitialPage()) |
| 151 return interstitial_drop_target_->OnDragOver(data_object, effects); | 170 return interstitial_drop_target_->OnDragOver(data_object, effects); |
| 152 | 171 |
| 153 POINT client_pt = cursor_position; | 172 POINT client_pt = cursor_position; |
| 154 ScreenToClient(GetHWND(), &client_pt); | 173 ScreenToClient(GetHWND(), &client_pt); |
| 155 web_contents_->GetRenderViewHost()->DragTargetDragOver( | 174 web_contents_->GetRenderViewHost()->DragTargetDragOver( |
| 156 gfx::Point(client_pt.x, client_pt.y), | 175 gfx::Point(client_pt.x, client_pt.y), |
| 157 gfx::Point(cursor_position.x, cursor_position.y), | 176 gfx::Point(cursor_position.x, cursor_position.y), |
| 158 web_drag_utils_win::WinDragOpMaskToWebDragOpMask(effects)); | 177 web_drag_utils_win::WinDragOpMaskToWebDragOpMask(effects), |
| 178 GetModifierFlags()); |
| 159 | 179 |
| 160 if (delegate_) | 180 if (delegate_) |
| 161 delegate_->OnDragOver(data_object); | 181 delegate_->OnDragOver(data_object); |
| 162 | 182 |
| 163 return web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_); | 183 return web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_); |
| 164 } | 184 } |
| 165 | 185 |
| 166 void WebDragDest::OnDragLeave(IDataObject* data_object) { | 186 void WebDragDest::OnDragLeave(IDataObject* data_object) { |
| 167 DCHECK(current_rvh_); | 187 DCHECK(current_rvh_); |
| 168 if (current_rvh_ != web_contents_->GetRenderViewHost()) | 188 if (current_rvh_ != web_contents_->GetRenderViewHost()) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 191 if (web_contents_->ShowingInterstitialPage()) | 211 if (web_contents_->ShowingInterstitialPage()) |
| 192 interstitial_drop_target_->OnDragOver(data_object, effect); | 212 interstitial_drop_target_->OnDragOver(data_object, effect); |
| 193 | 213 |
| 194 if (web_contents_->ShowingInterstitialPage()) | 214 if (web_contents_->ShowingInterstitialPage()) |
| 195 return interstitial_drop_target_->OnDrop(data_object, effect); | 215 return interstitial_drop_target_->OnDrop(data_object, effect); |
| 196 | 216 |
| 197 POINT client_pt = cursor_position; | 217 POINT client_pt = cursor_position; |
| 198 ScreenToClient(GetHWND(), &client_pt); | 218 ScreenToClient(GetHWND(), &client_pt); |
| 199 web_contents_->GetRenderViewHost()->DragTargetDrop( | 219 web_contents_->GetRenderViewHost()->DragTargetDrop( |
| 200 gfx::Point(client_pt.x, client_pt.y), | 220 gfx::Point(client_pt.x, client_pt.y), |
| 201 gfx::Point(cursor_position.x, cursor_position.y)); | 221 gfx::Point(cursor_position.x, cursor_position.y), |
| 222 GetModifierFlags()); |
| 202 | 223 |
| 203 if (delegate_) | 224 if (delegate_) |
| 204 delegate_->OnDrop(data_object); | 225 delegate_->OnDrop(data_object); |
| 205 | 226 |
| 206 current_rvh_ = NULL; | 227 current_rvh_ = NULL; |
| 207 | 228 |
| 208 // This isn't always correct, but at least it's a close approximation. | 229 // This isn't always correct, but at least it's a close approximation. |
| 209 // For now, we always map a move to a copy to prevent potential data loss. | 230 // For now, we always map a move to a copy to prevent potential data loss. |
| 210 DWORD drop_effect = web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_); | 231 DWORD drop_effect = web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_); |
| 211 DWORD result = drop_effect != DROPEFFECT_MOVE ? | 232 DWORD result = drop_effect != DROPEFFECT_MOVE ? |
| 212 drop_effect : DROPEFFECT_COPY; | 233 drop_effect : DROPEFFECT_COPY; |
| 213 | 234 |
| 214 drop_data_.reset(); | 235 drop_data_.reset(); |
| 215 return result; | 236 return result; |
| 216 } | 237 } |
| OLD | NEW |