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

Unified Diff: content/browser/android/content_view_core_impl.cc

Issue 1728193002: Support dragging texts into Android WebView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove dead includes Created 4 years, 6 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/browser/android/content_view_core_impl.cc
diff --git a/content/browser/android/content_view_core_impl.cc b/content/browser/android/content_view_core_impl.cc
index 7d636b6f9cd372551f017f41d54572848b612c65..e46b94bd704de2862152e5e80bea5b60b4a48cdf 100644
--- a/content/browser/android/content_view_core_impl.cc
+++ b/content/browser/android/content_view_core_impl.cc
@@ -14,6 +14,7 @@
#include "base/logging.h"
#include "base/macros.h"
#include "base/metrics/histogram.h"
+#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "cc/layers/layer.h"
@@ -55,6 +56,7 @@
#include "third_party/WebKit/public/web/WebInputEvent.h"
#include "ui/android/view_android.h"
#include "ui/android/window_android.h"
+#include "ui/base/clipboard/clipboard.h"
#include "ui/events/android/motion_event_android.h"
#include "ui/events/blink/blink_event_util.h"
#include "ui/events/event_utils.h"
@@ -91,6 +93,15 @@ enum PopupItemType {
POPUP_ITEM_TYPE_ENABLED,
};
+enum DragEventActions {
+ ACTION_DRAG_STARTED = 1,
dcheng 2016/06/24 23:07:53 Nit: enum class, and just call the members STARTED
hush (inactive) 2016/06/27 19:01:54 Sorry I can't use enum clas here. They have to be
+ ACTION_DRAG_LOCATION,
+ ACTION_DROP,
+ ACTION_DRAG_ENDED,
+ ACTION_DRAG_ENTERED,
+ ACTION_DRAG_EXITED,
+};
+
const void* const kContentViewUserDataKey = &kContentViewUserDataKey;
int GetRenderProcessIdFromRenderViewHost(RenderViewHost* host) {
@@ -1473,6 +1484,61 @@ void ContentViewCoreImpl::SetBackgroundOpaque(JNIEnv* env,
}
}
+void ContentViewCoreImpl::OnDragEvent(
+ JNIEnv* env,
+ const base::android::JavaParamRef<jobject>& jobj,
+ int action,
+ const JavaParamRef<jintArray>& j_locations,
+ const base::android::JavaParamRef<jobjectArray>& j_mimeTypes,
+ const base::android::JavaParamRef<jstring>& j_content) {
+ WebContentsViewAndroid* wcva = static_cast<WebContentsViewAndroid*>(
+ static_cast<WebContentsImpl*>(web_contents())->GetView());
+
+ std::vector<int> locations;
+ base::android::JavaIntArrayToIntVector(env, j_locations, &locations);
+
+ std::vector<base::string16> mime_types;
+ base::android::AppendJavaStringArrayToStringVector(env, j_mimeTypes,
+ &mime_types);
+ switch (action) {
+ case ACTION_DRAG_ENTERED: {
+ std::vector<DropData::Metadata> metadata;
+ for (base::string16 mime_type : mime_types) {
+ metadata.push_back(DropData::Metadata::CreateForMimeType(
+ DropData::Kind::STRING, mime_type));
+ }
+ wcva->OnDragEntered(metadata, locations);
+ break;
+ }
+ case ACTION_DRAG_LOCATION: {
+ wcva->OnDragUpdated(locations);
+ break;
+ }
+ case ACTION_DROP: {
+ base::string16 text_to_drop = ConvertJavaStringToUTF16(env, j_content);
+ DropData drop_data;
+ drop_data.did_originate_from_renderer = false;
+ for (base::string16 mime_type : mime_types) {
dcheng 2016/06/24 23:07:53 const base::string16, otherwise this copies each m
hush (inactive) 2016/06/27 19:01:54 Done.
+ if (base::EqualsASCII(mime_type, ui::Clipboard::kMimeTypeURIList)) {
+ drop_data.url = GURL(text_to_drop);
+ } else if (base::EqualsASCII(mime_type, ui::Clipboard::kMimeTypeText)) {
+ drop_data.text = base::NullableString16(text_to_drop, false);
+ } else {
+ drop_data.html = base::NullableString16(text_to_drop, false);
+ }
+ }
+
+ wcva->OnPerformDrop(drop_data, locations);
+ break;
+ }
+ case ACTION_DRAG_EXITED:
+ wcva->OnDragExited();
+ break;
+ case ACTION_DRAG_ENDED:
+ break;
+ }
+}
+
void ContentViewCoreImpl::RequestTextSurroundingSelection(
int max_length,
const base::Callback<

Powered by Google App Engine
This is Rietveld 408576698