OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/android/content_view_core_impl.h" | 5 #include "content/browser/android/content_view_core_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 #include "content/public/browser/ssl_host_state_delegate.h" | 47 #include "content/public/browser/ssl_host_state_delegate.h" |
48 #include "content/public/browser/web_contents.h" | 48 #include "content/public/browser/web_contents.h" |
49 #include "content/public/common/content_client.h" | 49 #include "content/public/common/content_client.h" |
50 #include "content/public/common/content_switches.h" | 50 #include "content/public/common/content_switches.h" |
51 #include "content/public/common/menu_item.h" | 51 #include "content/public/common/menu_item.h" |
52 #include "content/public/common/user_agent.h" | 52 #include "content/public/common/user_agent.h" |
53 #include "jni/ContentViewCore_jni.h" | 53 #include "jni/ContentViewCore_jni.h" |
54 #include "third_party/WebKit/public/web/WebInputEvent.h" | 54 #include "third_party/WebKit/public/web/WebInputEvent.h" |
55 #include "ui/android/view_android.h" | 55 #include "ui/android/view_android.h" |
56 #include "ui/android/window_android.h" | 56 #include "ui/android/window_android.h" |
| 57 #include "ui/base/dragdrop/drop_target_event.h" |
| 58 #include "ui/base/dragdrop/os_exchange_data_provider_android.h" |
57 #include "ui/events/android/motion_event_android.h" | 59 #include "ui/events/android/motion_event_android.h" |
58 #include "ui/gfx/android/java_bitmap.h" | 60 #include "ui/gfx/android/java_bitmap.h" |
59 #include "ui/gfx/geometry/point_conversions.h" | 61 #include "ui/gfx/geometry/point_conversions.h" |
60 #include "ui/gfx/geometry/size_conversions.h" | 62 #include "ui/gfx/geometry/size_conversions.h" |
61 #include "ui/gfx/geometry/size_f.h" | 63 #include "ui/gfx/geometry/size_f.h" |
62 | 64 |
63 using base::android::AttachCurrentThread; | 65 using base::android::AttachCurrentThread; |
64 using base::android::ConvertJavaStringToUTF16; | 66 using base::android::ConvertJavaStringToUTF16; |
65 using base::android::ConvertJavaStringToUTF8; | 67 using base::android::ConvertJavaStringToUTF8; |
66 using base::android::ConvertUTF16ToJavaString; | 68 using base::android::ConvertUTF16ToJavaString; |
(...skipping 14 matching lines...) Expand all Loading... |
81 // Popup item is of type group | 83 // Popup item is of type group |
82 POPUP_ITEM_TYPE_GROUP, | 84 POPUP_ITEM_TYPE_GROUP, |
83 | 85 |
84 // Popup item is disabled | 86 // Popup item is disabled |
85 POPUP_ITEM_TYPE_DISABLED, | 87 POPUP_ITEM_TYPE_DISABLED, |
86 | 88 |
87 // Popup item is enabled | 89 // Popup item is enabled |
88 POPUP_ITEM_TYPE_ENABLED, | 90 POPUP_ITEM_TYPE_ENABLED, |
89 }; | 91 }; |
90 | 92 |
| 93 enum DragEventActions { |
| 94 ACTION_DRAG_STARTED = 1, |
| 95 ACTION_DRAG_LOCATION, |
| 96 ACTION_DROP, |
| 97 ACTION_DRAG_ENDED, |
| 98 ACTION_DRAG_ENTERED, |
| 99 ACTION_DRAG_EXITED, |
| 100 }; |
| 101 |
91 const void* const kContentViewUserDataKey = &kContentViewUserDataKey; | 102 const void* const kContentViewUserDataKey = &kContentViewUserDataKey; |
92 | 103 |
93 int GetRenderProcessIdFromRenderViewHost(RenderViewHost* host) { | 104 int GetRenderProcessIdFromRenderViewHost(RenderViewHost* host) { |
94 DCHECK(host); | 105 DCHECK(host); |
95 RenderProcessHost* render_process = host->GetProcess(); | 106 RenderProcessHost* render_process = host->GetProcess(); |
96 DCHECK(render_process); | 107 DCHECK(render_process); |
97 if (render_process->HasConnection()) | 108 if (render_process->HasConnection()) |
98 return render_process->GetHandle(); | 109 return render_process->GetHandle(); |
99 return 0; | 110 return 0; |
100 } | 111 } |
(...skipping 1301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1402 const JavaParamRef<jobject>& jobj, | 1413 const JavaParamRef<jobject>& jobj, |
1403 jboolean opaque) { | 1414 jboolean opaque) { |
1404 if (GetRenderWidgetHostViewAndroid()) { | 1415 if (GetRenderWidgetHostViewAndroid()) { |
1405 if (opaque) | 1416 if (opaque) |
1406 GetRenderWidgetHostViewAndroid()->SetBackgroundColorToDefault(); | 1417 GetRenderWidgetHostViewAndroid()->SetBackgroundColorToDefault(); |
1407 else | 1418 else |
1408 GetRenderWidgetHostViewAndroid()->SetBackgroundColor(SK_ColorTRANSPARENT); | 1419 GetRenderWidgetHostViewAndroid()->SetBackgroundColor(SK_ColorTRANSPARENT); |
1409 } | 1420 } |
1410 } | 1421 } |
1411 | 1422 |
| 1423 void ContentViewCoreImpl::OnDragEvent( |
| 1424 JNIEnv* env, |
| 1425 const base::android::JavaParamRef<jobject>& jobj, |
| 1426 int action, |
| 1427 const JavaParamRef<jintArray>& j_locations, |
| 1428 const base::android::JavaParamRef<jstring>& content) { |
| 1429 WebContentsViewAndroid* wcva = static_cast<WebContentsViewAndroid*>( |
| 1430 static_cast<WebContentsImpl*>(web_contents())->GetView()); |
| 1431 |
| 1432 std::vector<int> locations; |
| 1433 base::android::JavaIntArrayToIntVector(env, j_locations, &locations); |
| 1434 int x = locations[0]; |
| 1435 int y = locations[1]; |
| 1436 int screen_x = locations[2]; |
| 1437 int screen_y = locations[3]; |
| 1438 |
| 1439 switch (action) { |
| 1440 case ACTION_DRAG_ENTERED: { |
| 1441 ui::OSExchangeData data(new ui::OSExchangeDataProviderAndroid()); |
| 1442 // Text being dragged is not available when drag enters. Use an empty |
| 1443 // string to declare that the DropData contains string. The DropData will |
| 1444 // be updated with real string being dragged during ACTION_DROP. |
| 1445 data.SetString(base::string16()); |
| 1446 ui::DropTargetEvent event(data, gfx::Point(x, y), |
| 1447 gfx::Point(screen_x, screen_y), |
| 1448 ui::DragDropTypes::DRAG_COPY); |
| 1449 |
| 1450 wcva->OnDragEntered(event); |
| 1451 break; |
| 1452 } |
| 1453 case ACTION_DRAG_LOCATION: { |
| 1454 ui::OSExchangeData data(new ui::OSExchangeDataProviderAndroid()); |
| 1455 ui::DropTargetEvent event(data, gfx::Point(x, y), |
| 1456 gfx::Point(screen_x, screen_y), |
| 1457 ui::DragDropTypes::DRAG_COPY); |
| 1458 |
| 1459 wcva->OnDragUpdated(event); |
| 1460 break; |
| 1461 } |
| 1462 case ACTION_DROP: { |
| 1463 base::string16 text_to_drop = ConvertJavaStringToUTF16(env, content); |
| 1464 ui::OSExchangeData data(new ui::OSExchangeDataProviderAndroid()); |
| 1465 data.SetString(text_to_drop); |
| 1466 ui::DropTargetEvent event(data, gfx::Point(x, y), |
| 1467 gfx::Point(screen_x, screen_y), |
| 1468 ui::DragDropTypes::DRAG_COPY); |
| 1469 |
| 1470 wcva->OnPerformDrop(event); |
| 1471 break; |
| 1472 } |
| 1473 case ACTION_DRAG_EXITED: |
| 1474 wcva->OnDragExited(); |
| 1475 break; |
| 1476 case ACTION_DRAG_ENDED: |
| 1477 break; |
| 1478 } |
| 1479 } |
| 1480 |
1412 void ContentViewCoreImpl::RequestTextSurroundingSelection( | 1481 void ContentViewCoreImpl::RequestTextSurroundingSelection( |
1413 int max_length, | 1482 int max_length, |
1414 const base::Callback< | 1483 const base::Callback< |
1415 void(const base::string16& content, int start_offset, int end_offset)>& | 1484 void(const base::string16& content, int start_offset, int end_offset)>& |
1416 callback) { | 1485 callback) { |
1417 DCHECK(!callback.is_null()); | 1486 DCHECK(!callback.is_null()); |
1418 RenderFrameHost* focused_frame = web_contents_->GetFocusedFrame(); | 1487 RenderFrameHost* focused_frame = web_contents_->GetFocusedFrame(); |
1419 if (!focused_frame) | 1488 if (!focused_frame) |
1420 return; | 1489 return; |
1421 if (GetRenderWidgetHostViewAndroid()) { | 1490 if (GetRenderWidgetHostViewAndroid()) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1521 return ScopedJavaLocalRef<jobject>(); | 1590 return ScopedJavaLocalRef<jobject>(); |
1522 | 1591 |
1523 return view->GetJavaObject(); | 1592 return view->GetJavaObject(); |
1524 } | 1593 } |
1525 | 1594 |
1526 bool RegisterContentViewCore(JNIEnv* env) { | 1595 bool RegisterContentViewCore(JNIEnv* env) { |
1527 return RegisterNativesImpl(env); | 1596 return RegisterNativesImpl(env); |
1528 } | 1597 } |
1529 | 1598 |
1530 } // namespace content | 1599 } // namespace content |
OLD | NEW |