| 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_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/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "content/browser/renderer_host/dip_util.h" | 9 #include "content/browser/renderer_host/dip_util.h" |
| 10 #include "content/browser/renderer_host/overscroll_controller.h" | 10 #include "content/browser/renderer_host/overscroll_controller.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 27 #include "ui/aura/client/aura_constants.h" | 27 #include "ui/aura/client/aura_constants.h" |
| 28 #include "ui/aura/client/drag_drop_client.h" | 28 #include "ui/aura/client/drag_drop_client.h" |
| 29 #include "ui/aura/client/drag_drop_delegate.h" | 29 #include "ui/aura/client/drag_drop_delegate.h" |
| 30 #include "ui/aura/root_window.h" | 30 #include "ui/aura/root_window.h" |
| 31 #include "ui/aura/root_window_observer.h" | 31 #include "ui/aura/root_window_observer.h" |
| 32 #include "ui/aura/window.h" | 32 #include "ui/aura/window.h" |
| 33 #include "ui/aura/window_observer.h" | 33 #include "ui/aura/window_observer.h" |
| 34 #include "ui/base/clipboard/custom_data_helper.h" | 34 #include "ui/base/clipboard/custom_data_helper.h" |
| 35 #include "ui/base/dragdrop/drag_drop_types.h" | 35 #include "ui/base/dragdrop/drag_drop_types.h" |
| 36 #include "ui/base/dragdrop/drag_utils.h" |
| 36 #include "ui/base/dragdrop/os_exchange_data.h" | 37 #include "ui/base/dragdrop/os_exchange_data.h" |
| 37 #include "ui/base/dragdrop/os_exchange_data_provider_aura.h" | |
| 38 #include "ui/base/events/event.h" | 38 #include "ui/base/events/event.h" |
| 39 #include "ui/base/events/event_utils.h" | 39 #include "ui/base/events/event_utils.h" |
| 40 #include "ui/base/hit_test.h" | 40 #include "ui/base/hit_test.h" |
| 41 #include "ui/compositor/layer.h" | 41 #include "ui/compositor/layer.h" |
| 42 #include "ui/compositor/scoped_layer_animation_settings.h" | 42 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 43 #include "ui/gfx/image/image_skia.h" |
| 43 #include "ui/gfx/screen.h" | 44 #include "ui/gfx/screen.h" |
| 44 #include "webkit/glue/webdropdata.h" | 45 #include "webkit/glue/webdropdata.h" |
| 45 | 46 |
| 47 #if defined(OS_WIN) |
| 48 #include "ui/base/clipboard/clipboard_util_win.h" |
| 49 #endif |
| 50 |
| 46 namespace content { | 51 namespace content { |
| 47 WebContentsView* CreateWebContentsView( | 52 WebContentsView* CreateWebContentsView( |
| 48 WebContentsImpl* web_contents, | 53 WebContentsImpl* web_contents, |
| 49 WebContentsViewDelegate* delegate, | 54 WebContentsViewDelegate* delegate, |
| 50 RenderViewHostDelegateView** render_view_host_delegate_view) { | 55 RenderViewHostDelegateView** render_view_host_delegate_view) { |
| 51 WebContentsViewAura* rv = new WebContentsViewAura(web_contents, delegate); | 56 WebContentsViewAura* rv = new WebContentsViewAura(web_contents, delegate); |
| 52 *render_view_host_delegate_view = rv; | 57 *render_view_host_delegate_view = rv; |
| 53 return rv; | 58 return rv; |
| 54 } | 59 } |
| 55 | 60 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 aura::Window* window() const { return window_; } | 126 aura::Window* window() const { return window_; } |
| 122 | 127 |
| 123 private: | 128 private: |
| 124 aura::Window* window_; | 129 aura::Window* window_; |
| 125 WebContentsImpl* contents_; | 130 WebContentsImpl* contents_; |
| 126 NotificationRegistrar registrar_; | 131 NotificationRegistrar registrar_; |
| 127 | 132 |
| 128 DISALLOW_COPY_AND_ASSIGN(WebDragSourceAura); | 133 DISALLOW_COPY_AND_ASSIGN(WebDragSourceAura); |
| 129 }; | 134 }; |
| 130 | 135 |
| 131 // Utility to fill a ui::OSExchangeDataProviderAura object from WebDropData. | 136 // Utility to fill a ui::OSExchangeDataProvider object from WebDropData. |
| 132 void PrepareDragData(const WebDropData& drop_data, | 137 void PrepareDragData(const WebDropData& drop_data, |
| 133 ui::OSExchangeDataProviderAura* provider) { | 138 ui::OSExchangeData::Provider* provider) { |
| 134 if (!drop_data.text.string().empty()) | 139 if (!drop_data.text.string().empty()) |
| 135 provider->SetString(drop_data.text.string()); | 140 provider->SetString(drop_data.text.string()); |
| 136 if (drop_data.url.is_valid()) | 141 if (drop_data.url.is_valid()) |
| 137 provider->SetURL(drop_data.url, drop_data.url_title); | 142 provider->SetURL(drop_data.url, drop_data.url_title); |
| 138 if (!drop_data.html.string().empty()) | 143 if (!drop_data.html.string().empty()) |
| 139 provider->SetHtml(drop_data.html.string(), drop_data.html_base_url); | 144 provider->SetHtml(drop_data.html.string(), drop_data.html_base_url); |
| 140 if (!drop_data.filenames.empty()) { | 145 if (!drop_data.filenames.empty()) { |
| 141 std::vector<ui::OSExchangeData::FileInfo> filenames; | 146 std::vector<ui::OSExchangeData::FileInfo> filenames; |
| 142 for (std::vector<WebDropData::FileInfo>::const_iterator it = | 147 for (std::vector<WebDropData::FileInfo>::const_iterator it = |
| 143 drop_data.filenames.begin(); | 148 drop_data.filenames.begin(); |
| 144 it != drop_data.filenames.end(); ++it) { | 149 it != drop_data.filenames.end(); ++it) { |
| 145 filenames.push_back( | 150 filenames.push_back( |
| 146 ui::OSExchangeData::FileInfo( | 151 ui::OSExchangeData::FileInfo( |
| 147 FilePath::FromUTF8Unsafe(UTF16ToUTF8(it->path)), | 152 FilePath::FromUTF8Unsafe(UTF16ToUTF8(it->path)), |
| 148 FilePath::FromUTF8Unsafe(UTF16ToUTF8(it->display_name)))); | 153 FilePath::FromUTF8Unsafe(UTF16ToUTF8(it->display_name)))); |
| 149 } | 154 } |
| 150 provider->SetFilenames(filenames); | 155 provider->SetFilenames(filenames); |
| 151 } | 156 } |
| 152 if (!drop_data.custom_data.empty()) { | 157 if (!drop_data.custom_data.empty()) { |
| 153 Pickle pickle; | 158 Pickle pickle; |
| 154 ui::WriteCustomDataToPickle(drop_data.custom_data, &pickle); | 159 ui::WriteCustomDataToPickle(drop_data.custom_data, &pickle); |
| 160 #if defined(OS_WIN) |
| 161 provider->SetPickledData( |
| 162 ui::ClipboardUtil::GetWebCustomDataFormat()->cfFormat, pickle); |
| 163 #else |
| 155 provider->SetPickledData(ui::Clipboard::GetWebCustomDataFormatType(), | 164 provider->SetPickledData(ui::Clipboard::GetWebCustomDataFormatType(), |
| 156 pickle); | 165 pickle); |
| 166 #endif |
| 157 } | 167 } |
| 158 } | 168 } |
| 159 | 169 |
| 160 // Utility to fill a WebDropData object from ui::OSExchangeData. | 170 // Utility to fill a WebDropData object from ui::OSExchangeData. |
| 161 void PrepareWebDropData(WebDropData* drop_data, | 171 void PrepareWebDropData(WebDropData* drop_data, |
| 162 const ui::OSExchangeData& data) { | 172 const ui::OSExchangeData& data) { |
| 163 string16 plain_text; | 173 string16 plain_text; |
| 164 data.GetString(&plain_text); | 174 data.GetString(&plain_text); |
| 165 if (!plain_text.empty()) | 175 if (!plain_text.empty()) |
| 166 drop_data->text = NullableString16(plain_text, false); | 176 drop_data->text = NullableString16(plain_text, false); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 186 for (std::vector<ui::OSExchangeData::FileInfo>::const_iterator | 196 for (std::vector<ui::OSExchangeData::FileInfo>::const_iterator |
| 187 it = files.begin(); it != files.end(); ++it) { | 197 it = files.begin(); it != files.end(); ++it) { |
| 188 drop_data->filenames.push_back( | 198 drop_data->filenames.push_back( |
| 189 WebDropData::FileInfo( | 199 WebDropData::FileInfo( |
| 190 UTF8ToUTF16(it->path.AsUTF8Unsafe()), | 200 UTF8ToUTF16(it->path.AsUTF8Unsafe()), |
| 191 UTF8ToUTF16(it->display_name.AsUTF8Unsafe()))); | 201 UTF8ToUTF16(it->display_name.AsUTF8Unsafe()))); |
| 192 } | 202 } |
| 193 } | 203 } |
| 194 | 204 |
| 195 Pickle pickle; | 205 Pickle pickle; |
| 206 #if defined(OS_WIN) |
| 207 if (data.GetPickledData(ui::ClipboardUtil::GetWebCustomDataFormat()->cfFormat, |
| 208 &pickle)) |
| 209 #else |
| 196 if (data.GetPickledData(ui::Clipboard::GetWebCustomDataFormatType(), | 210 if (data.GetPickledData(ui::Clipboard::GetWebCustomDataFormatType(), |
| 197 &pickle)) | 211 &pickle)) |
| 212 #endif |
| 198 ui::ReadCustomDataIntoMap(pickle.data(), pickle.size(), | 213 ui::ReadCustomDataIntoMap(pickle.data(), pickle.size(), |
| 199 &drop_data->custom_data); | 214 &drop_data->custom_data); |
| 200 } | 215 } |
| 201 | 216 |
| 202 // Utilities to convert between WebKit::WebDragOperationsMask and | 217 // Utilities to convert between WebKit::WebDragOperationsMask and |
| 203 // ui::DragDropTypes. | 218 // ui::DragDropTypes. |
| 204 int ConvertFromWeb(WebKit::WebDragOperationsMask ops) { | 219 int ConvertFromWeb(WebKit::WebDragOperationsMask ops) { |
| 205 int drag_op = ui::DragDropTypes::DRAG_NONE; | 220 int drag_op = ui::DragDropTypes::DRAG_NONE; |
| 206 if (ops & WebKit::WebDragOperationCopy) | 221 if (ops & WebKit::WebDragOperationCopy) |
| 207 drag_op |= ui::DragDropTypes::DRAG_COPY; | 222 drag_op |= ui::DragDropTypes::DRAG_COPY; |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 void WebContentsViewAura::StartDragging( | 685 void WebContentsViewAura::StartDragging( |
| 671 const WebDropData& drop_data, | 686 const WebDropData& drop_data, |
| 672 WebKit::WebDragOperationsMask operations, | 687 WebKit::WebDragOperationsMask operations, |
| 673 const gfx::ImageSkia& image, | 688 const gfx::ImageSkia& image, |
| 674 const gfx::Vector2d& image_offset, | 689 const gfx::Vector2d& image_offset, |
| 675 const DragEventSourceInfo& event_info) { | 690 const DragEventSourceInfo& event_info) { |
| 676 aura::RootWindow* root_window = GetNativeView()->GetRootWindow(); | 691 aura::RootWindow* root_window = GetNativeView()->GetRootWindow(); |
| 677 if (!aura::client::GetDragDropClient(root_window)) | 692 if (!aura::client::GetDragDropClient(root_window)) |
| 678 return; | 693 return; |
| 679 | 694 |
| 680 ui::OSExchangeDataProviderAura* provider = new ui::OSExchangeDataProviderAura; | 695 ui::OSExchangeData::Provider* provider = ui::OSExchangeData::CreateProvider(); |
| 681 PrepareDragData(drop_data, provider); | 696 PrepareDragData(drop_data, provider); |
| 697 |
| 698 ui::OSExchangeData data(provider); // takes ownership of |provider|. |
| 699 |
| 682 if (!image.isNull()) { | 700 if (!image.isNull()) { |
| 683 provider->set_drag_image(image); | 701 drag_utils::SetDragImageOnDataObject(image, |
| 684 provider->set_drag_image_offset(image_offset); | 702 gfx::Size(image.width(), image.height()), image_offset, &data); |
| 685 } | 703 } |
| 686 ui::OSExchangeData data(provider); // takes ownership of |provider|. | |
| 687 | 704 |
| 688 scoped_ptr<WebDragSourceAura> drag_source( | 705 scoped_ptr<WebDragSourceAura> drag_source( |
| 689 new WebDragSourceAura(GetNativeView(), web_contents_)); | 706 new WebDragSourceAura(GetNativeView(), web_contents_)); |
| 690 | 707 |
| 691 // We need to enable recursive tasks on the message loop so we can get | 708 // We need to enable recursive tasks on the message loop so we can get |
| 692 // updates while in the system DoDragDrop loop. | 709 // updates while in the system DoDragDrop loop. |
| 693 int result_op = 0; | 710 int result_op = 0; |
| 694 { | 711 { |
| 695 gfx::NativeView content_native_view = view_? GetContentNativeView() : NULL; | 712 gfx::NativeView content_native_view = view_? GetContentNativeView() : NULL; |
| 696 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); | 713 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 987 event.location(), | 1004 event.location(), |
| 988 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), | 1005 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), |
| 989 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); | 1006 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); |
| 990 if (drag_dest_delegate_) | 1007 if (drag_dest_delegate_) |
| 991 drag_dest_delegate_->OnDrop(); | 1008 drag_dest_delegate_->OnDrop(); |
| 992 current_drop_data_.reset(); | 1009 current_drop_data_.reset(); |
| 993 return current_drag_op_; | 1010 return current_drag_op_; |
| 994 } | 1011 } |
| 995 | 1012 |
| 996 } // namespace content | 1013 } // namespace content |
| OLD | NEW |