| 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 89414b4ab13612e3db29577d84c7e4f425d16c15..d468d59bb3e86f6094c85691259e787a1bf2cbc0 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,7 @@ 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.ClipboardManager;
|
| import android.content.ContentResolver;
|
| import android.content.Context;
|
| @@ -27,6 +28,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;
|
| @@ -3110,6 +3112,77 @@ 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 void onDragEntered(DragEvent event) {
|
| + if (mNativeContentViewCore == 0) {
|
| + return;
|
| + }
|
| +
|
| + int[] locations = getDragEventLocations(event);
|
| + nativeOnDragEntered(
|
| + mNativeContentViewCore, locations[0], locations[1], locations[2], locations[3]);
|
| + }
|
| +
|
| + public void onDragUpdated(DragEvent event) {
|
| + if (mNativeContentViewCore == 0) {
|
| + return;
|
| + }
|
| +
|
| + int[] locations = getDragEventLocations(event);
|
| + nativeOnDragUpdated(
|
| + mNativeContentViewCore, locations[0], locations[1], locations[2], locations[3]);
|
| + }
|
| +
|
| + public void onPerformDrop(DragEvent event) {
|
| + if (mNativeContentViewCore == 0) {
|
| + return;
|
| + }
|
| +
|
| + StringBuilder content = new StringBuilder("");
|
| +
|
| + // TODO(hush): obtain dragdrop persmissions 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()));
|
| + }
|
| +
|
| + int[] locations = getDragEventLocations(event);
|
| + nativeOnPerformDrop(mNativeContentViewCore, locations[0], locations[1], locations[2],
|
| + locations[3], content.toString());
|
| + }
|
| +
|
| + public void onDragExited() {
|
| + if (mNativeContentViewCore == 0) {
|
| + return;
|
| + }
|
| +
|
| + nativeOnDragExited(mNativeContentViewCore);
|
| + }
|
| +
|
| + /**
|
| * Offer a long press gesture to the embedding View, primarily for WebView compatibility.
|
| *
|
| * @return true if the embedder handled the event.
|
| @@ -3316,4 +3389,11 @@ 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 nativeOnDragEntered(
|
| + long nativeContentViewCoreImpl, int x, int y, int screenX, int screenY);
|
| + private native void nativeOnDragUpdated(
|
| + long nativeContentViewCoreImpl, int x, int y, int screenX, int screenY);
|
| + private native void nativeOnPerformDrop(
|
| + long nativeContentViewCoreImpl, int x, int y, int screenX, int screenY, String content);
|
| + private native void nativeOnDragExited(long nativeContentViewCoreImpl);
|
| }
|
|
|