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

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

Issue 2135493002: Support dragging texts out of webview/Chrome. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Workaround b/30148704 Created 4 years, 5 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 a1c24280c5b732b2a1b95590c535631f9fb6ad3a..be34d7dcd57cad827f55dae5c70fc4d44f7cdb6f 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
@@ -47,6 +47,7 @@ import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
import android.widget.FrameLayout;
+import android.widget.ImageView;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.CommandLine;
@@ -155,6 +156,8 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Screen
* that clients can safely hold to instances of this class.
*/
private static class ContentViewAndroidDelegate implements ViewAndroidDelegate {
+ // TODO(hush): use View#DRAG_FLAG_GLOBAL when Chromium starts to build with API 24.
+ private static final int DRAG_FLAG_GLOBAL = 1 << 8;
/**
* Represents the position of an anchor view.
*/
@@ -297,6 +300,23 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Screen
}
}
}
+
+ @SuppressWarnings("deprecation")
+ @Override
+ public void startDragAndDrop(String text, Bitmap shadowImage) {
+ ClipData data = ClipData.newPlainText(null, text);
+
+ ViewGroup containerView = mCurrentContainerView.get();
+ if (containerView == null) return;
+
+ ImageView imageView = new ImageView(containerView.getContext());
+ imageView.setImageBitmap(shadowImage);
+ imageView.layout(0, 0, shadowImage.getWidth(), shadowImage.getHeight());
+
+ // TODO(hush): use View#startDragAndDrop when Chromium starts to build with API 24.
+ containerView.startDrag(
+ data, new View.DragShadowBuilder(imageView), null, DRAG_FLAG_GLOBAL);
+ }
}
/**
@@ -1466,6 +1486,7 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Screen
hidePopups();
}
+ @CalledByNative
private void hidePopupsAndPreserveSelection() {
mUnselectAllOnActionModeDismiss = false;
hidePopups();
@@ -3285,12 +3306,7 @@ public class ContentViewCore implements AccessibilityStateChangeListener, Screen
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;
- }
// text/* will match text/uri-list, text/html, text/plain.
String[] mimeTypes =

Powered by Google App Engine
This is Rietveld 408576698