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_android.h" | 5 #include "content/browser/web_contents/web_contents_view_android.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "cc/layers/layer.h" | 10 #include "cc/layers/layer.h" |
11 #include "content/browser/android/content_view_core_impl.h" | 11 #include "content/browser/android/content_view_core_impl.h" |
12 #include "content/browser/frame_host/interstitial_page_impl.h" | 12 #include "content/browser/frame_host/interstitial_page_impl.h" |
13 #include "content/browser/renderer_host/render_view_host_factory.h" | 13 #include "content/browser/renderer_host/render_view_host_factory.h" |
14 #include "content/browser/renderer_host/render_view_host_impl.h" | 14 #include "content/browser/renderer_host/render_view_host_impl.h" |
15 #include "content/browser/renderer_host/render_widget_host_view_android.h" | 15 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
16 #include "content/browser/web_contents/web_contents_impl.h" | 16 #include "content/browser/web_contents/web_contents_impl.h" |
17 #include "content/public/browser/render_widget_host.h" | 17 #include "content/public/browser/render_widget_host.h" |
18 #include "content/public/browser/web_contents_delegate.h" | 18 #include "content/public/browser/web_contents_delegate.h" |
19 #include "content/public/common/drop_data.h" | 19 #include "content/public/common/drop_data.h" |
| 20 #include "jni/DragEvent_jni.h" |
20 #include "ui/android/overscroll_refresh_handler.h" | 21 #include "ui/android/overscroll_refresh_handler.h" |
| 22 #include "ui/base/clipboard/clipboard.h" |
21 #include "ui/display/screen.h" | 23 #include "ui/display/screen.h" |
| 24 #include "ui/events/android/drag_event_android.h" |
22 #include "ui/events/android/motion_event_android.h" | 25 #include "ui/events/android/motion_event_android.h" |
23 #include "ui/gfx/android/java_bitmap.h" | 26 #include "ui/gfx/android/java_bitmap.h" |
24 #include "ui/gfx/image/image_skia.h" | 27 #include "ui/gfx/image/image_skia.h" |
25 | 28 |
26 using base::android::AttachCurrentThread; | 29 using base::android::AttachCurrentThread; |
27 using base::android::ConvertUTF16ToJavaString; | 30 using base::android::ConvertUTF16ToJavaString; |
28 using base::android::JavaRef; | 31 using base::android::JavaRef; |
29 using base::android::ScopedJavaLocalRef; | 32 using base::android::ScopedJavaLocalRef; |
30 | 33 |
31 namespace content { | 34 namespace content { |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 } | 334 } |
332 | 335 |
333 if (content_view_core_) | 336 if (content_view_core_) |
334 content_view_core_->HidePopupsAndPreserveSelection(); | 337 content_view_core_->HidePopupsAndPreserveSelection(); |
335 } | 338 } |
336 | 339 |
337 void WebContentsViewAndroid::UpdateDragCursor(blink::WebDragOperation op) { | 340 void WebContentsViewAndroid::UpdateDragCursor(blink::WebDragOperation op) { |
338 // Intentional no-op because Android does not have cursor. | 341 // Intentional no-op because Android does not have cursor. |
339 } | 342 } |
340 | 343 |
| 344 bool WebContentsViewAndroid::OnDragEvent(const ui::DragEventAndroid& event) { |
| 345 switch (event.action()) { |
| 346 case JNI_DragEvent::ACTION_DRAG_ENTERED: { |
| 347 std::vector<DropData::Metadata> metadata; |
| 348 for (const base::string16& mime_type : event.mime_types()) { |
| 349 metadata.push_back(DropData::Metadata::CreateForMimeType( |
| 350 DropData::Kind::STRING, mime_type)); |
| 351 } |
| 352 OnDragEntered(metadata, event.location(), event.root_location()); |
| 353 break; |
| 354 } |
| 355 case JNI_DragEvent::ACTION_DRAG_LOCATION: |
| 356 OnDragUpdated(event.location(), event.root_location()); |
| 357 break; |
| 358 case JNI_DragEvent::ACTION_DROP: { |
| 359 DropData drop_data; |
| 360 drop_data.did_originate_from_renderer = false; |
| 361 for (const base::string16& mime_type : event.mime_types()) { |
| 362 if (base::EqualsASCII(mime_type, ui::Clipboard::kMimeTypeURIList)) { |
| 363 drop_data.url = GURL(event.content()); |
| 364 } else if (base::EqualsASCII(mime_type, ui::Clipboard::kMimeTypeText)) { |
| 365 drop_data.text = base::NullableString16(event.content(), false); |
| 366 } else { |
| 367 drop_data.html = base::NullableString16(event.content(), false); |
| 368 } |
| 369 } |
| 370 |
| 371 OnPerformDrop(&drop_data, event.location(), event.root_location()); |
| 372 break; |
| 373 } |
| 374 case JNI_DragEvent::ACTION_DRAG_EXITED: |
| 375 OnDragExited(); |
| 376 break; |
| 377 case JNI_DragEvent::ACTION_DRAG_ENDED: |
| 378 OnDragEnded(); |
| 379 break; |
| 380 case JNI_DragEvent::ACTION_DRAG_STARTED: |
| 381 // Nothing meaningful to do. |
| 382 break; |
| 383 } |
| 384 return true; |
| 385 } |
| 386 |
341 // TODO(paulmeyer): The drag-and-drop calls on GetRenderViewHost()->GetWidget() | 387 // TODO(paulmeyer): The drag-and-drop calls on GetRenderViewHost()->GetWidget() |
342 // in the following functions will need to be targeted to specific | 388 // in the following functions will need to be targeted to specific |
343 // RenderWidgetHosts in order to work with OOPIFs. See crbug.com/647249. | 389 // RenderWidgetHosts in order to work with OOPIFs. See crbug.com/647249. |
344 | 390 |
345 void WebContentsViewAndroid::OnDragEntered( | 391 void WebContentsViewAndroid::OnDragEntered( |
346 const std::vector<DropData::Metadata>& metadata, | 392 const std::vector<DropData::Metadata>& metadata, |
347 const gfx::Point& location, | 393 const gfx::Point& location, |
348 const gfx::Point& screen_location) { | 394 const gfx::Point& screen_location) { |
349 blink::WebDragOperationsMask allowed_ops = | 395 blink::WebDragOperationsMask allowed_ops = |
350 static_cast<blink::WebDragOperationsMask>(blink::kWebDragOperationCopy | | 396 static_cast<blink::WebDragOperationsMask>(blink::kWebDragOperationCopy | |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 content_view_core_->OnTouchDown(event.GetJavaObject()); | 446 content_view_core_->OnTouchDown(event.GetJavaObject()); |
401 return false; // let the children handle the actual event. | 447 return false; // let the children handle the actual event. |
402 } | 448 } |
403 | 449 |
404 void WebContentsViewAndroid::OnPhysicalBackingSizeChanged() { | 450 void WebContentsViewAndroid::OnPhysicalBackingSizeChanged() { |
405 if (web_contents_->GetRenderWidgetHostView()) | 451 if (web_contents_->GetRenderWidgetHostView()) |
406 web_contents_->SendScreenRects(); | 452 web_contents_->SendScreenRects(); |
407 } | 453 } |
408 | 454 |
409 } // namespace content | 455 } // namespace content |
OLD | NEW |