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 "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 |
| 34 // A helper method for getting the preferred drop effect. | 35 // A helper method for getting the preferred drop effect. |
| 35 DWORD GetPreferredDropEffect(DWORD effect) { | 36 DWORD GetPreferredDropEffect(DWORD effect) { |
| 36 if (effect & DROPEFFECT_COPY) | 37 if (effect & DROPEFFECT_COPY) |
| 37 return DROPEFFECT_COPY; | 38 return DROPEFFECT_COPY; |
| 38 if (effect & DROPEFFECT_LINK) | 39 if (effect & DROPEFFECT_LINK) |
| 39 return DROPEFFECT_LINK; | 40 return DROPEFFECT_LINK; |
| 40 if (effect & DROPEFFECT_MOVE) | 41 if (effect & DROPEFFECT_MOVE) |
| 41 return DROPEFFECT_MOVE; | 42 return DROPEFFECT_MOVE; |
| 42 return DROPEFFECT_NONE; | 43 return DROPEFFECT_NONE; |
| 43 } | 44 } |
| 44 | 45 |
| 46 int GetModifierFlags() { | |
| 47 int modifier_state = 0; | |
| 48 if (::GetKeyState(VK_SHIFT) & HIGH_BIT_MASK_SHORT) | |
|
tony
2012/05/15 23:17:05
Nit: Can you use the HIBYTE macro?
varunjain
2012/05/16 01:30:23
HIBYTE returns the whole byte afaik while we just
| |
| 49 modifier_state |= WebKit::WebInputEvent::ShiftKey; | |
| 50 if (::GetKeyState(VK_CONTROL) & HIGH_BIT_MASK_SHORT) | |
| 51 modifier_state |= WebKit::WebInputEvent::ControlKey; | |
| 52 if (::GetKeyState(VK_MENU) & HIGH_BIT_MASK_SHORT) | |
| 53 modifier_state |= WebKit::WebInputEvent::AltKey; | |
| 54 if (::GetKeyState(VK_LWIN) & HIGH_BIT_MASK_SHORT) | |
| 55 modifier_state |= WebKit::WebInputEvent::MetaKey; | |
| 56 if (::GetKeyState(VK_RWIN) & HIGH_BIT_MASK_SHORT) | |
| 57 modifier_state |= WebKit::WebInputEvent::MetaKey; | |
| 58 return modifier_state; | |
| 59 } | |
| 60 | |
| 45 } // namespace | 61 } // namespace |
| 46 | 62 |
| 47 // InterstitialDropTarget is like a ui::DropTarget implementation that | 63 // InterstitialDropTarget is like a ui::DropTarget implementation that |
| 48 // WebDragDest passes through to if an interstitial is showing. Rather than | 64 // 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 | 65 // 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. | 66 // in the drop data and handle links as navigations. |
| 51 class InterstitialDropTarget { | 67 class InterstitialDropTarget { |
| 52 public: | 68 public: |
| 53 explicit InterstitialDropTarget(WebContents* web_contents) | 69 explicit InterstitialDropTarget(WebContents* web_contents) |
| 54 : web_contents_(web_contents) {} | 70 : web_contents_(web_contents) {} |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 ui::OSExchangeDataProviderWin::GetPlainTextURL(data_object, | 138 ui::OSExchangeDataProviderWin::GetPlainTextURL(data_object, |
| 123 &drop_data_->url); | 139 &drop_data_->url); |
| 124 | 140 |
| 125 drag_cursor_ = WebDragOperationNone; | 141 drag_cursor_ = WebDragOperationNone; |
| 126 | 142 |
| 127 POINT client_pt = cursor_position; | 143 POINT client_pt = cursor_position; |
| 128 ScreenToClient(GetHWND(), &client_pt); | 144 ScreenToClient(GetHWND(), &client_pt); |
| 129 web_contents_->GetRenderViewHost()->DragTargetDragEnter(*drop_data_, | 145 web_contents_->GetRenderViewHost()->DragTargetDragEnter(*drop_data_, |
| 130 gfx::Point(client_pt.x, client_pt.y), | 146 gfx::Point(client_pt.x, client_pt.y), |
| 131 gfx::Point(cursor_position.x, cursor_position.y), | 147 gfx::Point(cursor_position.x, cursor_position.y), |
| 132 web_drag_utils_win::WinDragOpMaskToWebDragOpMask(effects)); | 148 web_drag_utils_win::WinDragOpMaskToWebDragOpMask(effects), |
| 149 GetModifierFlags()); | |
| 133 | 150 |
| 134 if (delegate_) | 151 if (delegate_) |
| 135 delegate_->OnDragEnter(data_object); | 152 delegate_->OnDragEnter(data_object); |
| 136 | 153 |
| 137 // 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 |
| 138 // wait for the IPC call to return. | 155 // wait for the IPC call to return. |
| 139 return web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_); | 156 return web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_); |
| 140 } | 157 } |
| 141 | 158 |
| 142 DWORD WebDragDest::OnDragOver(IDataObject* data_object, | 159 DWORD WebDragDest::OnDragOver(IDataObject* data_object, |
| 143 DWORD key_state, | 160 DWORD key_state, |
| 144 POINT cursor_position, | 161 POINT cursor_position, |
| 145 DWORD effects) { | 162 DWORD effects) { |
| 146 DCHECK(current_rvh_); | 163 DCHECK(current_rvh_); |
| 147 if (current_rvh_ != web_contents_->GetRenderViewHost()) | 164 if (current_rvh_ != web_contents_->GetRenderViewHost()) |
| 148 OnDragEnter(data_object, key_state, cursor_position, effects); | 165 OnDragEnter(data_object, key_state, cursor_position, effects); |
| 149 | 166 |
| 150 if (web_contents_->ShowingInterstitialPage()) | 167 if (web_contents_->ShowingInterstitialPage()) |
| 151 return interstitial_drop_target_->OnDragOver(data_object, effects); | 168 return interstitial_drop_target_->OnDragOver(data_object, effects); |
| 152 | 169 |
| 153 POINT client_pt = cursor_position; | 170 POINT client_pt = cursor_position; |
| 154 ScreenToClient(GetHWND(), &client_pt); | 171 ScreenToClient(GetHWND(), &client_pt); |
| 155 web_contents_->GetRenderViewHost()->DragTargetDragOver( | 172 web_contents_->GetRenderViewHost()->DragTargetDragOver( |
| 156 gfx::Point(client_pt.x, client_pt.y), | 173 gfx::Point(client_pt.x, client_pt.y), |
| 157 gfx::Point(cursor_position.x, cursor_position.y), | 174 gfx::Point(cursor_position.x, cursor_position.y), |
| 158 web_drag_utils_win::WinDragOpMaskToWebDragOpMask(effects)); | 175 web_drag_utils_win::WinDragOpMaskToWebDragOpMask(effects), |
| 176 GetModifierFlags()); | |
| 159 | 177 |
| 160 if (delegate_) | 178 if (delegate_) |
| 161 delegate_->OnDragOver(data_object); | 179 delegate_->OnDragOver(data_object); |
| 162 | 180 |
| 163 return web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_); | 181 return web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_); |
| 164 } | 182 } |
| 165 | 183 |
| 166 void WebDragDest::OnDragLeave(IDataObject* data_object) { | 184 void WebDragDest::OnDragLeave(IDataObject* data_object) { |
| 167 DCHECK(current_rvh_); | 185 DCHECK(current_rvh_); |
| 168 if (current_rvh_ != web_contents_->GetRenderViewHost()) | 186 if (current_rvh_ != web_contents_->GetRenderViewHost()) |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 191 if (web_contents_->ShowingInterstitialPage()) | 209 if (web_contents_->ShowingInterstitialPage()) |
| 192 interstitial_drop_target_->OnDragOver(data_object, effect); | 210 interstitial_drop_target_->OnDragOver(data_object, effect); |
| 193 | 211 |
| 194 if (web_contents_->ShowingInterstitialPage()) | 212 if (web_contents_->ShowingInterstitialPage()) |
| 195 return interstitial_drop_target_->OnDrop(data_object, effect); | 213 return interstitial_drop_target_->OnDrop(data_object, effect); |
| 196 | 214 |
| 197 POINT client_pt = cursor_position; | 215 POINT client_pt = cursor_position; |
| 198 ScreenToClient(GetHWND(), &client_pt); | 216 ScreenToClient(GetHWND(), &client_pt); |
| 199 web_contents_->GetRenderViewHost()->DragTargetDrop( | 217 web_contents_->GetRenderViewHost()->DragTargetDrop( |
| 200 gfx::Point(client_pt.x, client_pt.y), | 218 gfx::Point(client_pt.x, client_pt.y), |
| 201 gfx::Point(cursor_position.x, cursor_position.y)); | 219 gfx::Point(cursor_position.x, cursor_position.y), |
| 220 GetModifierFlags()); | |
| 202 | 221 |
| 203 if (delegate_) | 222 if (delegate_) |
| 204 delegate_->OnDrop(data_object); | 223 delegate_->OnDrop(data_object); |
| 205 | 224 |
| 206 current_rvh_ = NULL; | 225 current_rvh_ = NULL; |
| 207 | 226 |
| 208 // 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. |
| 209 // 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. |
| 210 DWORD drop_effect = web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_); | 229 DWORD drop_effect = web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_); |
| 211 DWORD result = drop_effect != DROPEFFECT_MOVE ? | 230 DWORD result = drop_effect != DROPEFFECT_MOVE ? |
| 212 drop_effect : DROPEFFECT_COPY; | 231 drop_effect : DROPEFFECT_COPY; |
| 213 | 232 |
| 214 drop_data_.reset(); | 233 drop_data_.reset(); |
| 215 return result; | 234 return result; |
| 216 } | 235 } |
| OLD | NEW |