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

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

Issue 11444013: Get drag and drop working for win aura. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync Created 8 years 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
« no previous file with comments | « chrome/test/base/view_event_test_base.cc ('k') | ui/aura/ui_controls_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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
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
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
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 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 void WebContentsViewAura::StartDragging( 680 void WebContentsViewAura::StartDragging(
666 const WebDropData& drop_data, 681 const WebDropData& drop_data,
667 WebKit::WebDragOperationsMask operations, 682 WebKit::WebDragOperationsMask operations,
668 const gfx::ImageSkia& image, 683 const gfx::ImageSkia& image,
669 const gfx::Vector2d& image_offset, 684 const gfx::Vector2d& image_offset,
670 const DragEventSourceInfo& event_info) { 685 const DragEventSourceInfo& event_info) {
671 aura::RootWindow* root_window = GetNativeView()->GetRootWindow(); 686 aura::RootWindow* root_window = GetNativeView()->GetRootWindow();
672 if (!aura::client::GetDragDropClient(root_window)) 687 if (!aura::client::GetDragDropClient(root_window))
673 return; 688 return;
674 689
675 ui::OSExchangeDataProviderAura* provider = new ui::OSExchangeDataProviderAura; 690 ui::OSExchangeData::Provider* provider = ui::OSExchangeData::CreateProvider();
676 PrepareDragData(drop_data, provider); 691 PrepareDragData(drop_data, provider);
692
693 ui::OSExchangeData data(provider); // takes ownership of |provider|.
694
677 if (!image.isNull()) { 695 if (!image.isNull()) {
678 provider->set_drag_image(image); 696 drag_utils::SetDragImageOnDataObject(image,
679 provider->set_drag_image_offset(image_offset); 697 gfx::Size(image.width(), image.height()), image_offset, &data);
680 } 698 }
681 ui::OSExchangeData data(provider); // takes ownership of |provider|.
682 699
683 scoped_ptr<WebDragSourceAura> drag_source( 700 scoped_ptr<WebDragSourceAura> drag_source(
684 new WebDragSourceAura(GetNativeView(), web_contents_)); 701 new WebDragSourceAura(GetNativeView(), web_contents_));
685 702
686 // We need to enable recursive tasks on the message loop so we can get 703 // We need to enable recursive tasks on the message loop so we can get
687 // updates while in the system DoDragDrop loop. 704 // updates while in the system DoDragDrop loop.
688 int result_op = 0; 705 int result_op = 0;
689 { 706 {
690 gfx::NativeView content_native_view = GetContentNativeView(); 707 gfx::NativeView content_native_view = GetContentNativeView();
691 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); 708 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 event.location(), 999 event.location(),
983 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), 1000 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(),
984 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); 1001 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags()));
985 if (drag_dest_delegate_) 1002 if (drag_dest_delegate_)
986 drag_dest_delegate_->OnDrop(); 1003 drag_dest_delegate_->OnDrop();
987 current_drop_data_.reset(); 1004 current_drop_data_.reset();
988 return current_drag_op_; 1005 return current_drag_op_;
989 } 1006 }
990 1007
991 } // namespace content 1008 } // namespace content
OLDNEW
« no previous file with comments | « chrome/test/base/view_event_test_base.cc ('k') | ui/aura/ui_controls_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698