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 "base/win/win_util.h" | 10 #include "base/win/win_util.h" |
11 #include "content/browser/renderer_host/render_view_host_impl.h" | 11 #include "content/browser/renderer_host/render_view_host_impl.h" |
12 #include "content/browser/web_contents/web_drag_utils_win.h" | 12 #include "content/browser/web_contents/web_drag_utils_win.h" |
13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
14 #include "content/public/browser/web_contents_delegate.h" | 14 #include "content/public/browser/web_contents_delegate.h" |
15 #include "content/public/browser/web_drag_dest_delegate.h" | 15 #include "content/public/browser/web_drag_dest_delegate.h" |
| 16 #include "content/public/common/drop_data.h" |
16 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
17 #include "net/base/net_util.h" | 18 #include "net/base/net_util.h" |
18 #include "third_party/WebKit/public/web/WebInputEvent.h" | 19 #include "third_party/WebKit/public/web/WebInputEvent.h" |
19 #include "ui/base/clipboard/clipboard_util_win.h" | 20 #include "ui/base/clipboard/clipboard_util_win.h" |
20 #include "ui/base/dragdrop/os_exchange_data.h" | 21 #include "ui/base/dragdrop/os_exchange_data.h" |
21 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" | 22 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" |
22 #include "ui/base/window_open_disposition.h" | 23 #include "ui/base/window_open_disposition.h" |
23 #include "ui/gfx/point.h" | 24 #include "ui/gfx/point.h" |
24 #include "webkit/common/webdropdata.h" | |
25 | 25 |
26 using WebKit::WebDragOperationNone; | 26 using WebKit::WebDragOperationNone; |
27 using WebKit::WebDragOperationCopy; | 27 using WebKit::WebDragOperationCopy; |
28 using WebKit::WebDragOperationLink; | 28 using WebKit::WebDragOperationLink; |
29 using WebKit::WebDragOperationMove; | 29 using WebKit::WebDragOperationMove; |
30 using WebKit::WebDragOperationGeneric; | 30 using WebKit::WebDragOperationGeneric; |
31 | 31 |
32 namespace content { | 32 namespace content { |
33 namespace { | 33 namespace { |
34 | 34 |
(...skipping 18 matching lines...) Expand all Loading... |
53 modifier_state |= WebKit::WebInputEvent::ControlKey; | 53 modifier_state |= WebKit::WebInputEvent::ControlKey; |
54 if (base::win::IsAltPressed()) | 54 if (base::win::IsAltPressed()) |
55 modifier_state |= WebKit::WebInputEvent::AltKey; | 55 modifier_state |= WebKit::WebInputEvent::AltKey; |
56 if (::GetKeyState(VK_LWIN) & kHighBitMaskShort) | 56 if (::GetKeyState(VK_LWIN) & kHighBitMaskShort) |
57 modifier_state |= WebKit::WebInputEvent::MetaKey; | 57 modifier_state |= WebKit::WebInputEvent::MetaKey; |
58 if (::GetKeyState(VK_RWIN) & kHighBitMaskShort) | 58 if (::GetKeyState(VK_RWIN) & kHighBitMaskShort) |
59 modifier_state |= WebKit::WebInputEvent::MetaKey; | 59 modifier_state |= WebKit::WebInputEvent::MetaKey; |
60 return modifier_state; | 60 return modifier_state; |
61 } | 61 } |
62 | 62 |
63 // Helper method for converting Window's specific IDataObject to a WebDropData | 63 // Helper method for converting Window's specific IDataObject to a DropData |
64 // object. | 64 // object. |
65 void PopulateWebDropData(IDataObject* data_object, WebDropData* drop_data) { | 65 void PopulateDropData(IDataObject* data_object, DropData* drop_data) { |
66 base::string16 url_str; | 66 base::string16 url_str; |
67 if (ui::ClipboardUtil::GetUrl( | 67 if (ui::ClipboardUtil::GetUrl( |
68 data_object, &url_str, &drop_data->url_title, false)) { | 68 data_object, &url_str, &drop_data->url_title, false)) { |
69 GURL test_url(url_str); | 69 GURL test_url(url_str); |
70 if (test_url.is_valid()) | 70 if (test_url.is_valid()) |
71 drop_data->url = test_url; | 71 drop_data->url = test_url; |
72 } | 72 } |
73 std::vector<base::string16> filenames; | 73 std::vector<base::string16> filenames; |
74 ui::ClipboardUtil::GetFilenames(data_object, &filenames); | 74 ui::ClipboardUtil::GetFilenames(data_object, &filenames); |
75 for (size_t i = 0; i < filenames.size(); ++i) | 75 for (size_t i = 0; i < filenames.size(); ++i) |
76 drop_data->filenames.push_back( | 76 drop_data->filenames.push_back( |
77 WebDropData::FileInfo(filenames[i], base::string16())); | 77 DropData::FileInfo(filenames[i], base::string16())); |
78 base::string16 text; | 78 base::string16 text; |
79 ui::ClipboardUtil::GetPlainText(data_object, &text); | 79 ui::ClipboardUtil::GetPlainText(data_object, &text); |
80 if (!text.empty()) { | 80 if (!text.empty()) { |
81 drop_data->text = base::NullableString16(text, false); | 81 drop_data->text = base::NullableString16(text, false); |
82 } | 82 } |
83 base::string16 html; | 83 base::string16 html; |
84 std::string html_base_url; | 84 std::string html_base_url; |
85 ui::ClipboardUtil::GetHtml(data_object, &html, &html_base_url); | 85 ui::ClipboardUtil::GetHtml(data_object, &html, &html_base_url); |
86 if (!html.empty()) { | 86 if (!html.empty()) { |
87 drop_data->html = base::NullableString16(html, false); | 87 drop_data->html = base::NullableString16(html, false); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 | 147 |
148 WebDragDest::~WebDragDest() { | 148 WebDragDest::~WebDragDest() { |
149 } | 149 } |
150 | 150 |
151 DWORD WebDragDest::OnDragEnter(IDataObject* data_object, | 151 DWORD WebDragDest::OnDragEnter(IDataObject* data_object, |
152 DWORD key_state, | 152 DWORD key_state, |
153 POINT cursor_position, | 153 POINT cursor_position, |
154 DWORD effects) { | 154 DWORD effects) { |
155 current_rvh_ = web_contents_->GetRenderViewHost(); | 155 current_rvh_ = web_contents_->GetRenderViewHost(); |
156 | 156 |
157 // TODO(tc): PopulateWebDropData can be slow depending on what is in the | 157 // TODO(tc): PopulateDropData can be slow depending on what is in the |
158 // IDataObject. Maybe we can do this in a background thread. | 158 // IDataObject. Maybe we can do this in a background thread. |
159 scoped_ptr<WebDropData> drop_data; | 159 scoped_ptr<DropData> drop_data; |
160 drop_data.reset(new WebDropData()); | 160 drop_data.reset(new DropData()); |
161 PopulateWebDropData(data_object, drop_data.get()); | 161 PopulateDropData(data_object, drop_data.get()); |
162 | 162 |
163 if (drop_data->url.is_empty()) | 163 if (drop_data->url.is_empty()) |
164 ui::OSExchangeDataProviderWin::GetPlainTextURL(data_object, | 164 ui::OSExchangeDataProviderWin::GetPlainTextURL(data_object, |
165 &drop_data->url); | 165 &drop_data->url); |
166 | 166 |
167 // Give the delegate an opportunity to cancel the drag. | 167 // Give the delegate an opportunity to cancel the drag. |
168 canceled_ = !web_contents_->GetDelegate()->CanDragEnter( | 168 canceled_ = !web_contents_->GetDelegate()->CanDragEnter( |
169 web_contents_, | 169 web_contents_, |
170 *drop_data, | 170 *drop_data, |
171 WinDragOpMaskToWebDragOpMask(effects)); | 171 WinDragOpMaskToWebDragOpMask(effects)); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 // This isn't always correct, but at least it's a close approximation. | 277 // This isn't always correct, but at least it's a close approximation. |
278 // For now, we always map a move to a copy to prevent potential data loss. | 278 // For now, we always map a move to a copy to prevent potential data loss. |
279 DWORD drop_effect = WebDragOpToWinDragOp(drag_cursor_); | 279 DWORD drop_effect = WebDragOpToWinDragOp(drag_cursor_); |
280 DWORD result = drop_effect != DROPEFFECT_MOVE ? drop_effect : DROPEFFECT_COPY; | 280 DWORD result = drop_effect != DROPEFFECT_MOVE ? drop_effect : DROPEFFECT_COPY; |
281 | 281 |
282 drop_data_.reset(); | 282 drop_data_.reset(); |
283 return result; | 283 return result; |
284 } | 284 } |
285 | 285 |
286 } // namespace content | 286 } // namespace content |
OLD | NEW |