Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(736)

Unified Diff: content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java

Issue 1728193002: Support dragging texts into Android WebView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: gyp and gn Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..19a12785a930672faecba2912d977560ec533424 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;
@@ -3110,6 +3113,59 @@ 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;
+ }
+
+ if (event.getAction() == DragEvent.ACTION_DRAG_STARTED) {
+ ClipDescription clipDescription = event.getClipDescription();
+ // TODO(hush): support dragging more than just text.
+ return clipDescription.hasMimeType(ClipDescription.MIMETYPE_TEXT_HTML)
+ || clipDescription.hasMimeType(clipDescription.MIMETYPE_TEXT_PLAIN);
+ }
+
+ int[] locations = getDragEventLocations(event);
+
+ StringBuilder content = new StringBuilder("");
+ if (event.getAction() == DragEvent.ACTION_DROP) {
+ // 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()));
+ }
+ }
+
+ nativeOnDragEvent(mNativeContentViewCore, event.getAction(), locations, 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.
@@ -3316,4 +3372,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 content);
}

Powered by Google App Engine
This is Rietveld 408576698