Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: content/browser/web_contents/web_contents_view_aura.cc

Issue 18281002: Move WebDropData to content::DropData and split off conversion function. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Mac build error. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_contents_view_aura.h" 5 #include "content/browser/web_contents/web_contents_view_aura.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "content/browser/renderer_host/dip_util.h" 10 #include "content/browser/renderer_host/dip_util.h"
(...skipping 14 matching lines...) Expand all
25 #include "content/public/browser/notification_source.h" 25 #include "content/public/browser/notification_source.h"
26 #include "content/public/browser/notification_types.h" 26 #include "content/public/browser/notification_types.h"
27 #include "content/public/browser/overscroll_configuration.h" 27 #include "content/public/browser/overscroll_configuration.h"
28 #include "content/public/browser/render_view_host.h" 28 #include "content/public/browser/render_view_host.h"
29 #include "content/public/browser/render_widget_host.h" 29 #include "content/public/browser/render_widget_host.h"
30 #include "content/public/browser/render_widget_host_view.h" 30 #include "content/public/browser/render_widget_host_view.h"
31 #include "content/public/browser/web_contents_delegate.h" 31 #include "content/public/browser/web_contents_delegate.h"
32 #include "content/public/browser/web_contents_observer.h" 32 #include "content/public/browser/web_contents_observer.h"
33 #include "content/public/browser/web_contents_view_delegate.h" 33 #include "content/public/browser/web_contents_view_delegate.h"
34 #include "content/public/browser/web_drag_dest_delegate.h" 34 #include "content/public/browser/web_drag_dest_delegate.h"
35 #include "content/public/common/drop_data.h"
35 #include "third_party/WebKit/public/web/WebInputEvent.h" 36 #include "third_party/WebKit/public/web/WebInputEvent.h"
36 #include "ui/aura/client/aura_constants.h" 37 #include "ui/aura/client/aura_constants.h"
37 #include "ui/aura/client/drag_drop_client.h" 38 #include "ui/aura/client/drag_drop_client.h"
38 #include "ui/aura/client/drag_drop_delegate.h" 39 #include "ui/aura/client/drag_drop_delegate.h"
39 #include "ui/aura/root_window.h" 40 #include "ui/aura/root_window.h"
40 #include "ui/aura/root_window_observer.h" 41 #include "ui/aura/root_window_observer.h"
41 #include "ui/aura/window.h" 42 #include "ui/aura/window.h"
42 #include "ui/aura/window_observer.h" 43 #include "ui/aura/window_observer.h"
43 #include "ui/base/clipboard/clipboard.h" 44 #include "ui/base/clipboard/clipboard.h"
44 #include "ui/base/clipboard/custom_data_helper.h" 45 #include "ui/base/clipboard/custom_data_helper.h"
45 #include "ui/base/dragdrop/drag_drop_types.h" 46 #include "ui/base/dragdrop/drag_drop_types.h"
46 #include "ui/base/dragdrop/drag_utils.h" 47 #include "ui/base/dragdrop/drag_utils.h"
47 #include "ui/base/dragdrop/os_exchange_data.h" 48 #include "ui/base/dragdrop/os_exchange_data.h"
48 #include "ui/base/events/event.h" 49 #include "ui/base/events/event.h"
49 #include "ui/base/events/event_utils.h" 50 #include "ui/base/events/event_utils.h"
50 #include "ui/base/hit_test.h" 51 #include "ui/base/hit_test.h"
51 #include "ui/compositor/layer.h" 52 #include "ui/compositor/layer.h"
52 #include "ui/compositor/scoped_layer_animation_settings.h" 53 #include "ui/compositor/scoped_layer_animation_settings.h"
53 #include "ui/gfx/canvas.h" 54 #include "ui/gfx/canvas.h"
54 #include "ui/gfx/image/image.h" 55 #include "ui/gfx/image/image.h"
55 #include "ui/gfx/image/image_png_rep.h" 56 #include "ui/gfx/image/image_png_rep.h"
56 #include "ui/gfx/image/image_skia.h" 57 #include "ui/gfx/image/image_skia.h"
57 #include "ui/gfx/screen.h" 58 #include "ui/gfx/screen.h"
58 #include "webkit/common/webdropdata.h"
59 59
60 namespace content { 60 namespace content {
61 WebContentsViewPort* CreateWebContentsView( 61 WebContentsViewPort* CreateWebContentsView(
62 WebContentsImpl* web_contents, 62 WebContentsImpl* web_contents,
63 WebContentsViewDelegate* delegate, 63 WebContentsViewDelegate* delegate,
64 RenderViewHostDelegateView** render_view_host_delegate_view) { 64 RenderViewHostDelegateView** render_view_host_delegate_view) {
65 WebContentsViewAura* rv = new WebContentsViewAura(web_contents, delegate); 65 WebContentsViewAura* rv = new WebContentsViewAura(web_contents, delegate);
66 *render_view_host_delegate_view = rv; 66 *render_view_host_delegate_view = rv;
67 return rv; 67 return rv;
68 } 68 }
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 aura::Window* window() const { return window_; } 221 aura::Window* window() const { return window_; }
222 222
223 private: 223 private:
224 aura::Window* window_; 224 aura::Window* window_;
225 WebContentsImpl* contents_; 225 WebContentsImpl* contents_;
226 NotificationRegistrar registrar_; 226 NotificationRegistrar registrar_;
227 227
228 DISALLOW_COPY_AND_ASSIGN(WebDragSourceAura); 228 DISALLOW_COPY_AND_ASSIGN(WebDragSourceAura);
229 }; 229 };
230 230
231 // Utility to fill a ui::OSExchangeDataProvider object from WebDropData. 231 // Utility to fill a ui::OSExchangeDataProvider object from DropData.
232 void PrepareDragData(const WebDropData& drop_data, 232 void PrepareDragData(const DropData& drop_data,
233 ui::OSExchangeData::Provider* provider) { 233 ui::OSExchangeData::Provider* provider) {
234 if (!drop_data.text.string().empty()) 234 if (!drop_data.text.string().empty())
235 provider->SetString(drop_data.text.string()); 235 provider->SetString(drop_data.text.string());
236 if (drop_data.url.is_valid()) 236 if (drop_data.url.is_valid())
237 provider->SetURL(drop_data.url, drop_data.url_title); 237 provider->SetURL(drop_data.url, drop_data.url_title);
238 if (!drop_data.html.string().empty()) 238 if (!drop_data.html.string().empty())
239 provider->SetHtml(drop_data.html.string(), drop_data.html_base_url); 239 provider->SetHtml(drop_data.html.string(), drop_data.html_base_url);
240 if (!drop_data.filenames.empty()) { 240 if (!drop_data.filenames.empty()) {
241 std::vector<ui::OSExchangeData::FileInfo> filenames; 241 std::vector<ui::OSExchangeData::FileInfo> filenames;
242 for (std::vector<WebDropData::FileInfo>::const_iterator it = 242 for (std::vector<DropData::FileInfo>::const_iterator it =
243 drop_data.filenames.begin(); 243 drop_data.filenames.begin();
244 it != drop_data.filenames.end(); ++it) { 244 it != drop_data.filenames.end(); ++it) {
245 filenames.push_back( 245 filenames.push_back(
246 ui::OSExchangeData::FileInfo( 246 ui::OSExchangeData::FileInfo(
247 base::FilePath::FromUTF8Unsafe(UTF16ToUTF8(it->path)), 247 base::FilePath::FromUTF8Unsafe(UTF16ToUTF8(it->path)),
248 base::FilePath::FromUTF8Unsafe(UTF16ToUTF8(it->display_name)))); 248 base::FilePath::FromUTF8Unsafe(UTF16ToUTF8(it->display_name))));
249 } 249 }
250 provider->SetFilenames(filenames); 250 provider->SetFilenames(filenames);
251 } 251 }
252 if (!drop_data.custom_data.empty()) { 252 if (!drop_data.custom_data.empty()) {
253 Pickle pickle; 253 Pickle pickle;
254 ui::WriteCustomDataToPickle(drop_data.custom_data, &pickle); 254 ui::WriteCustomDataToPickle(drop_data.custom_data, &pickle);
255 provider->SetPickledData(ui::Clipboard::GetWebCustomDataFormatType(), 255 provider->SetPickledData(ui::Clipboard::GetWebCustomDataFormatType(),
256 pickle); 256 pickle);
257 } 257 }
258 } 258 }
259 259
260 // Utility to fill a WebDropData object from ui::OSExchangeData. 260 // Utility to fill a DropData object from ui::OSExchangeData.
261 void PrepareWebDropData(WebDropData* drop_data, 261 void PrepareDropData(DropData* drop_data, const ui::OSExchangeData& data) {
262 const ui::OSExchangeData& data) {
263 string16 plain_text; 262 string16 plain_text;
264 data.GetString(&plain_text); 263 data.GetString(&plain_text);
265 if (!plain_text.empty()) 264 if (!plain_text.empty())
266 drop_data->text = base::NullableString16(plain_text, false); 265 drop_data->text = base::NullableString16(plain_text, false);
267 266
268 GURL url; 267 GURL url;
269 string16 url_title; 268 string16 url_title;
270 data.GetURLAndTitle(&url, &url_title); 269 data.GetURLAndTitle(&url, &url_title);
271 if (url.is_valid()) { 270 if (url.is_valid()) {
272 drop_data->url = url; 271 drop_data->url = url;
273 drop_data->url_title = url_title; 272 drop_data->url_title = url_title;
274 } 273 }
275 274
276 string16 html; 275 string16 html;
277 GURL html_base_url; 276 GURL html_base_url;
278 data.GetHtml(&html, &html_base_url); 277 data.GetHtml(&html, &html_base_url);
279 if (!html.empty()) 278 if (!html.empty())
280 drop_data->html = base::NullableString16(html, false); 279 drop_data->html = base::NullableString16(html, false);
281 if (html_base_url.is_valid()) 280 if (html_base_url.is_valid())
282 drop_data->html_base_url = html_base_url; 281 drop_data->html_base_url = html_base_url;
283 282
284 std::vector<ui::OSExchangeData::FileInfo> files; 283 std::vector<ui::OSExchangeData::FileInfo> files;
285 if (data.GetFilenames(&files) && !files.empty()) { 284 if (data.GetFilenames(&files) && !files.empty()) {
286 for (std::vector<ui::OSExchangeData::FileInfo>::const_iterator 285 for (std::vector<ui::OSExchangeData::FileInfo>::const_iterator
287 it = files.begin(); it != files.end(); ++it) { 286 it = files.begin(); it != files.end(); ++it) {
288 drop_data->filenames.push_back( 287 drop_data->filenames.push_back(
289 WebDropData::FileInfo( 288 DropData::FileInfo(
290 UTF8ToUTF16(it->path.AsUTF8Unsafe()), 289 UTF8ToUTF16(it->path.AsUTF8Unsafe()),
291 UTF8ToUTF16(it->display_name.AsUTF8Unsafe()))); 290 UTF8ToUTF16(it->display_name.AsUTF8Unsafe())));
292 } 291 }
293 } 292 }
294 293
295 Pickle pickle; 294 Pickle pickle;
296 if (data.GetPickledData(ui::Clipboard::GetWebCustomDataFormatType(), &pickle)) 295 if (data.GetPickledData(ui::Clipboard::GetWebCustomDataFormatType(), &pickle))
297 ui::ReadCustomDataIntoMap( 296 ui::ReadCustomDataIntoMap(
298 pickle.data(), pickle.size(), &drop_data->custom_data); 297 pickle.data(), pickle.size(), &drop_data->custom_data);
299 } 298 }
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 void WebContentsViewAura::StoreFocus() { 1080 void WebContentsViewAura::StoreFocus() {
1082 if (delegate_) 1081 if (delegate_)
1083 delegate_->StoreFocus(); 1082 delegate_->StoreFocus();
1084 } 1083 }
1085 1084
1086 void WebContentsViewAura::RestoreFocus() { 1085 void WebContentsViewAura::RestoreFocus() {
1087 if (delegate_) 1086 if (delegate_)
1088 delegate_->RestoreFocus(); 1087 delegate_->RestoreFocus();
1089 } 1088 }
1090 1089
1091 WebDropData* WebContentsViewAura::GetDropData() const { 1090 DropData* WebContentsViewAura::GetDropData() const {
1092 return current_drop_data_.get(); 1091 return current_drop_data_.get();
1093 } 1092 }
1094 1093
1095 gfx::Rect WebContentsViewAura::GetViewBounds() const { 1094 gfx::Rect WebContentsViewAura::GetViewBounds() const {
1096 return window_->GetBoundsInScreen(); 1095 return window_->GetBoundsInScreen();
1097 } 1096 }
1098 1097
1099 //////////////////////////////////////////////////////////////////////////////// 1098 ////////////////////////////////////////////////////////////////////////////////
1100 // WebContentsViewAura, WebContentsViewPort implementation: 1099 // WebContentsViewAura, WebContentsViewPort implementation:
1101 1100
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 double item_font_size, 1230 double item_font_size,
1232 int selected_item, 1231 int selected_item,
1233 const std::vector<WebMenuItem>& items, 1232 const std::vector<WebMenuItem>& items,
1234 bool right_aligned, 1233 bool right_aligned,
1235 bool allow_multiple_selection) { 1234 bool allow_multiple_selection) {
1236 // External popup menus are only used on Mac and Android. 1235 // External popup menus are only used on Mac and Android.
1237 NOTIMPLEMENTED(); 1236 NOTIMPLEMENTED();
1238 } 1237 }
1239 1238
1240 void WebContentsViewAura::StartDragging( 1239 void WebContentsViewAura::StartDragging(
1241 const WebDropData& drop_data, 1240 const DropData& drop_data,
1242 WebKit::WebDragOperationsMask operations, 1241 WebKit::WebDragOperationsMask operations,
1243 const gfx::ImageSkia& image, 1242 const gfx::ImageSkia& image,
1244 const gfx::Vector2d& image_offset, 1243 const gfx::Vector2d& image_offset,
1245 const DragEventSourceInfo& event_info) { 1244 const DragEventSourceInfo& event_info) {
1246 aura::RootWindow* root_window = GetNativeView()->GetRootWindow(); 1245 aura::RootWindow* root_window = GetNativeView()->GetRootWindow();
1247 if (!aura::client::GetDragDropClient(root_window)) { 1246 if (!aura::client::GetDragDropClient(root_window)) {
1248 web_contents_->SystemDragEnded(); 1247 web_contents_->SystemDragEnded();
1249 return; 1248 return;
1250 } 1249 }
1251 1250
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1515 } 1514 }
1516 } 1515 }
1517 1516
1518 //////////////////////////////////////////////////////////////////////////////// 1517 ////////////////////////////////////////////////////////////////////////////////
1519 // WebContentsViewAura, aura::client::DragDropDelegate implementation: 1518 // WebContentsViewAura, aura::client::DragDropDelegate implementation:
1520 1519
1521 void WebContentsViewAura::OnDragEntered(const ui::DropTargetEvent& event) { 1520 void WebContentsViewAura::OnDragEntered(const ui::DropTargetEvent& event) {
1522 if (drag_dest_delegate_) 1521 if (drag_dest_delegate_)
1523 drag_dest_delegate_->DragInitialize(web_contents_); 1522 drag_dest_delegate_->DragInitialize(web_contents_);
1524 1523
1525 current_drop_data_.reset(new WebDropData()); 1524 current_drop_data_.reset(new DropData());
1526 1525
1527 PrepareWebDropData(current_drop_data_.get(), event.data()); 1526 PrepareDropData(current_drop_data_.get(), event.data());
1528 WebKit::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); 1527 WebKit::WebDragOperationsMask op = ConvertToWeb(event.source_operations());
1529 1528
1530 gfx::Point screen_pt = 1529 gfx::Point screen_pt =
1531 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(); 1530 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint();
1532 current_rvh_for_drag_ = web_contents_->GetRenderViewHost(); 1531 current_rvh_for_drag_ = web_contents_->GetRenderViewHost();
1533 web_contents_->GetRenderViewHost()->DragTargetDragEnter( 1532 web_contents_->GetRenderViewHost()->DragTargetDragEnter(
1534 *current_drop_data_.get(), event.location(), screen_pt, op, 1533 *current_drop_data_.get(), event.location(), screen_pt, op,
1535 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); 1534 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags()));
1536 1535
1537 if (drag_dest_delegate_) { 1536 if (drag_dest_delegate_) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1579 event.location(), 1578 event.location(),
1580 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), 1579 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(),
1581 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); 1580 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags()));
1582 if (drag_dest_delegate_) 1581 if (drag_dest_delegate_)
1583 drag_dest_delegate_->OnDrop(); 1582 drag_dest_delegate_->OnDrop();
1584 current_drop_data_.reset(); 1583 current_drop_data_.reset();
1585 return current_drag_op_; 1584 return current_drag_op_;
1586 } 1585 }
1587 1586
1588 } // namespace content 1587 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_view_aura.h ('k') | content/browser/web_contents/web_contents_view_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698