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; |
| 30 using base::android::ConvertJavaStringToUTF16; |
27 using base::android::ConvertUTF16ToJavaString; | 31 using base::android::ConvertUTF16ToJavaString; |
28 using base::android::JavaRef; | 32 using base::android::JavaRef; |
29 using base::android::ScopedJavaLocalRef; | 33 using base::android::ScopedJavaLocalRef; |
30 | 34 |
31 namespace content { | 35 namespace content { |
32 | 36 |
33 namespace { | 37 namespace { |
34 void DisplayToScreenInfo(const display::Display& display, ScreenInfo* results) { | 38 void DisplayToScreenInfo(const display::Display& display, ScreenInfo* results) { |
35 results->rect = display.bounds(); | 39 results->rect = display.bounds(); |
36 // TODO(husky): Remove any system controls from availableRect. | 40 // TODO(husky): Remove any system controls from availableRect. |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 } | 335 } |
332 | 336 |
333 if (content_view_core_) | 337 if (content_view_core_) |
334 content_view_core_->HidePopupsAndPreserveSelection(); | 338 content_view_core_->HidePopupsAndPreserveSelection(); |
335 } | 339 } |
336 | 340 |
337 void WebContentsViewAndroid::UpdateDragCursor(blink::WebDragOperation op) { | 341 void WebContentsViewAndroid::UpdateDragCursor(blink::WebDragOperation op) { |
338 // Intentional no-op because Android does not have cursor. | 342 // Intentional no-op because Android does not have cursor. |
339 } | 343 } |
340 | 344 |
| 345 bool WebContentsViewAndroid::OnDragEvent(const ui::DragEventAndroid& event) { |
| 346 switch (event.action()) { |
| 347 case JNI_DragEvent::ACTION_DRAG_ENTERED: { |
| 348 std::vector<DropData::Metadata> metadata; |
| 349 for (const base::string16& mime_type : event.mime_types()) { |
| 350 metadata.push_back(DropData::Metadata::CreateForMimeType( |
| 351 DropData::Kind::STRING, mime_type)); |
| 352 } |
| 353 OnDragEntered(metadata, event.GetLocation(), event.GetScreenLocation()); |
| 354 break; |
| 355 } |
| 356 case JNI_DragEvent::ACTION_DRAG_LOCATION: |
| 357 OnDragUpdated(event.GetLocation(), event.GetScreenLocation()); |
| 358 break; |
| 359 case JNI_DragEvent::ACTION_DROP: { |
| 360 DropData drop_data; |
| 361 drop_data.did_originate_from_renderer = false; |
| 362 JNIEnv* env = AttachCurrentThread(); |
| 363 base::string16 drop_content = |
| 364 ConvertJavaStringToUTF16(env, event.GetJavaContent()); |
| 365 for (const base::string16& mime_type : event.mime_types()) { |
| 366 if (base::EqualsASCII(mime_type, ui::Clipboard::kMimeTypeURIList)) { |
| 367 drop_data.url = GURL(drop_content); |
| 368 } else if (base::EqualsASCII(mime_type, ui::Clipboard::kMimeTypeText)) { |
| 369 drop_data.text = base::NullableString16(drop_content, false); |
| 370 } else { |
| 371 drop_data.html = base::NullableString16(drop_content, false); |
| 372 } |
| 373 } |
| 374 |
| 375 OnPerformDrop(&drop_data, event.GetLocation(), event.GetScreenLocation()); |
| 376 break; |
| 377 } |
| 378 case JNI_DragEvent::ACTION_DRAG_EXITED: |
| 379 OnDragExited(); |
| 380 break; |
| 381 case JNI_DragEvent::ACTION_DRAG_ENDED: |
| 382 OnDragEnded(); |
| 383 break; |
| 384 case JNI_DragEvent::ACTION_DRAG_STARTED: |
| 385 // Nothing meaningful to do. |
| 386 break; |
| 387 } |
| 388 return true; |
| 389 } |
| 390 |
341 // TODO(paulmeyer): The drag-and-drop calls on GetRenderViewHost()->GetWidget() | 391 // TODO(paulmeyer): The drag-and-drop calls on GetRenderViewHost()->GetWidget() |
342 // in the following functions will need to be targeted to specific | 392 // in the following functions will need to be targeted to specific |
343 // RenderWidgetHosts in order to work with OOPIFs. See crbug.com/647249. | 393 // RenderWidgetHosts in order to work with OOPIFs. See crbug.com/647249. |
344 | 394 |
345 void WebContentsViewAndroid::OnDragEntered( | 395 void WebContentsViewAndroid::OnDragEntered( |
346 const std::vector<DropData::Metadata>& metadata, | 396 const std::vector<DropData::Metadata>& metadata, |
347 const gfx::Point& location, | 397 const gfx::Point& location, |
348 const gfx::Point& screen_location) { | 398 const gfx::Point& screen_location) { |
349 blink::WebDragOperationsMask allowed_ops = | 399 blink::WebDragOperationsMask allowed_ops = |
350 static_cast<blink::WebDragOperationsMask>(blink::kWebDragOperationCopy | | 400 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()); | 450 content_view_core_->OnTouchDown(event.GetJavaObject()); |
401 return false; // let the children handle the actual event. | 451 return false; // let the children handle the actual event. |
402 } | 452 } |
403 | 453 |
404 void WebContentsViewAndroid::OnPhysicalBackingSizeChanged() { | 454 void WebContentsViewAndroid::OnPhysicalBackingSizeChanged() { |
405 if (web_contents_->GetRenderWidgetHostView()) | 455 if (web_contents_->GetRenderWidgetHostView()) |
406 web_contents_->SendScreenRects(); | 456 web_contents_->SendScreenRects(); |
407 } | 457 } |
408 | 458 |
409 } // namespace content | 459 } // namespace content |
OLD | NEW |