| 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..a02d2e845a71c137af6f5c2732218a731aee8ebb 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.
|
| @@ -3274,6 +3277,68 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Screen
|
| }
|
|
|
| /**
|
| + * Returns the location of the DragEvent normalized by dpi scale. The first 2 points are x and y
|
| + * coordinates in application window space, the latter 2 points are x and y coordinates in
|
| + * physical screen space.
|
| + */
|
| + private int[] getDragEventLocations(DragEvent event) {
|
| + int[] locations = new int[4];
|
| + float scale = (float) DeviceDisplayInfo.create(mContainerView.getContext()).getDIPScale();
|
| + int[] locationOnScreen = new int[2];
|
| + mContainerView.getLocationOnScreen(locationOnScreen);
|
| + float screenX = event.getX() + locationOnScreen[0];
|
| + float screenY = event.getY() + locationOnScreen[1];
|
| +
|
| + locations[0] = (int) (event.getX() / scale);
|
| + locations[1] = (int) (event.getY() / scale);
|
| + locations[2] = (int) (screenX / scale);
|
| + locations[3] = (int) (screenY / scale);
|
| +
|
| + return locations;
|
| + }
|
| +
|
| + public boolean onDragEvent(DragEvent event) {
|
| + if (mNativeContentViewCore == 0) {
|
| + 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/*");
|
| +
|
| + int[] locations = getDragEventLocations(event);
|
| +
|
| + 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()));
|
| + }
|
| + }
|
| +
|
| + nativeOnDragEvent(mNativeContentViewCore, event.getAction(), locations, mimeTypes,
|
| + content.toString());
|
| + return true;
|
| + }
|
| +
|
| + /**
|
| * Offer a long press gesture to the embedding View, primarily for WebView compatibility.
|
| *
|
| * @return true if the embedder handled the event.
|
| @@ -3512,4 +3577,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[] locations, String[] mimeTypes, String content);
|
| }
|
|
|