Chromium Code Reviews| Index: content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java |
| diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java |
| index 7de8b4ae1d59448eb065e245f793592f7f3cf859..45ed8468b2750ce26150d2d14a0894520403a2bd 100644 |
| --- a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java |
| +++ b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java |
| @@ -9,6 +9,8 @@ import android.annotation.TargetApi; |
| import android.app.Activity; |
| import android.app.SearchManager; |
| import android.app.assist.AssistStructure.ViewNode; |
| +import android.content.ClipData; |
| +import android.content.ClipDescription; |
| import android.content.ClipboardManager; |
| import android.content.ContentResolver; |
| import android.content.Context; |
| @@ -27,6 +29,7 @@ import android.text.TextUtils; |
| import android.util.Pair; |
| import android.util.TypedValue; |
| import android.view.ActionMode; |
| +import android.view.DragEvent; |
| import android.view.HapticFeedbackConstants; |
| import android.view.InputDevice; |
| import android.view.KeyEvent; |
| @@ -106,7 +109,7 @@ import java.util.Map.Entry; |
| @JNINamespace("content") |
| public class ContentViewCore implements AccessibilityStateChangeListener, ScreenOrientationObserver, |
| SystemCaptioningBridge.SystemCaptioningBridgeListener { |
| - private static final String TAG = "cr.ContentViewCore"; |
| + private static final String TAG = "cr_ContentViewCore"; |
| // Used to avoid enabling zooming in / out if resulting zooming will |
| // produce little visible difference. |
| @@ -3273,6 +3276,54 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Screen |
| } |
| } |
| + public boolean onDragEvent(DragEvent event) { |
|
Ted C
2016/06/30 00:15:42
add
/**
* @see View#onDragEvent(DragEvent)
*/
hush (inactive)
2016/06/30 18:19:06
Done.
|
| + if (mNativeContentViewCore == 0) { |
|
Ted C
2016/06/30 00:15:42
make this a one liner since it'll all fit on one
hush (inactive)
2016/06/30 18:19:06
Done.
|
| + return false; |
| + } |
| + |
| + ClipDescription clipDescription = event.getClipDescription(); |
| + if (clipDescription == null && event.getAction() != DragEvent.ACTION_DRAG_ENDED) { |
| + Log.e(TAG, "Null clipDescription when the drag is not ended."); |
| + return false; |
| + } |
| + |
| + if (event.getAction() == DragEvent.ACTION_DRAG_STARTED) { |
| + // TODO(hush): support dragging more than just text. |
| + return clipDescription.hasMimeType(ClipDescription.MIMETYPE_TEXT_HTML) |
| + || clipDescription.hasMimeType(clipDescription.MIMETYPE_TEXT_PLAIN); |
| + } |
| + |
| + // text/* will match text/uri-list, text/html, text/plain. |
| + String[] mimeTypes = |
| + clipDescription == null ? new String[0] : clipDescription.filterMimeTypes("text/*"); |
| + |
| + StringBuilder content = new StringBuilder(""); |
| + if (event.getAction() == DragEvent.ACTION_DROP) { |
| + // TODO(hush): obtain dragdrop permissions (via reflection?), when dragging files into |
| + // Chrome/WebView is supported. Not necessary to do so for now, because only text |
| + // dragging is supported. |
| + ClipData clipData = event.getClipData(); |
| + final int itemCount = clipData.getItemCount(); |
| + for (int i = 0; i < itemCount; i++) { |
| + ClipData.Item item = clipData.getItemAt(i); |
| + content.append(item.coerceToStyledText(mContainerView.getContext())); |
| + } |
| + } |
| + |
| + float scale = (float) DeviceDisplayInfo.create(mContainerView.getContext()).getDIPScale(); |
| + int[] locationOnScreen = new int[2]; |
| + mContainerView.getLocationOnScreen(locationOnScreen); |
| + |
| + int x = (int) (event.getX() / scale); |
| + int y = (int) (event.getY() / scale); |
| + int screenX = (int) ((event.getX() + locationOnScreen[0]) / scale); |
| + int screenY = (int) ((event.getY() + locationOnScreen[1]) / scale); |
| + |
| + nativeOnDragEvent(mNativeContentViewCore, event.getAction(), x, y, screenX, screenY, |
| + mimeTypes, content.toString()); |
| + return true; |
| + } |
| + |
| /** |
| * Offer a long press gesture to the embedding View, primarily for WebView compatibility. |
| * |
| @@ -3512,4 +3563,6 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Screen |
| int x, int y, int w, int h); |
| private native void nativeSetBackgroundOpaque(long nativeContentViewCoreImpl, boolean opaque); |
| + private native void nativeOnDragEvent(long nativeContentViewCoreImpl, int action, int x, int y, |
| + int screenX, int screenY, String[] mimeTypes, String content); |
| } |