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

Unified Diff: content/browser/web_contents/web_contents_view_android.cc

Issue 1728193002: Support dragging texts into Android WebView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/browser/web_contents/web_contents_view_android.cc
diff --git a/content/browser/web_contents/web_contents_view_android.cc b/content/browser/web_contents/web_contents_view_android.cc
index 0716d13d2fb2ae9053899b12397de5234c4c44ea..c615e33da7e3826d697b72b48d0d904c21001d5a 100644
--- a/content/browser/web_contents/web_contents_view_android.cc
+++ b/content/browser/web_contents/web_contents_view_android.cc
@@ -5,6 +5,8 @@
#include "content/browser/web_contents/web_contents_view_android.h"
#include "base/logging.h"
+#include "base/pickle.h"
+#include "base/strings/utf_string_conversions.h"
#include "content/browser/android/content_view_core_impl.h"
#include "content/browser/frame_host/interstitial_page_impl.h"
#include "content/browser/renderer_host/render_widget_host_view_android.h"
@@ -13,8 +15,27 @@
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/render_widget_host.h"
#include "content/public/browser/web_contents_delegate.h"
+#include "content/public/common/drop_data.h"
+#include "ui/base/dragdrop/drag_drop_types.h"
+#include "ui/base/dragdrop/drop_target_event.h"
+#include "ui/base/dragdrop/os_exchange_data.h"
namespace content {
+
+namespace {
+
+void PrepareDropData(DropData* drop_data, const ui::OSExchangeData& data) {
+ // TODO(hush): support dragging files here.
+ drop_data->did_originate_from_renderer = data.DidOriginateFromRenderer();
+
+ base::string16 plain_text;
+ data.GetString(&plain_text);
+ if (!plain_text.empty())
+ drop_data->text = base::NullableString16(plain_text, false);
+}
+
+} // namespace
+
WebContentsView* CreateWebContentsView(
WebContentsImpl* web_contents,
WebContentsViewDelegate* delegate,
@@ -199,6 +220,36 @@ void WebContentsViewAndroid::UpdateDragCursor(blink::WebDragOperation op) {
NOTIMPLEMENTED();
}
+void WebContentsViewAndroid::OnDragEntered(const ui::DropTargetEvent& event) {
+ current_drop_data_.reset(new DropData());
+ PrepareDropData(current_drop_data_.get(), event.data());
+
+ web_contents_->GetRenderViewHost()->DragTargetDragEnter(
+ *current_drop_data_.get(), event.location(), event.root_location(),
+ blink::WebDragOperationCopy, 0);
+}
+
+void WebContentsViewAndroid::OnDragUpdated(const ui::DropTargetEvent& event) {
+ if (!current_drop_data_)
+ return;
+
+ web_contents_->GetRenderViewHost()->DragTargetDragOver(
+ event.location(), event.root_location(), blink::WebDragOperationCopy, 0);
+}
+
+void WebContentsViewAndroid::OnDragExited() {
+ web_contents_->GetRenderViewHost()->DragTargetDragLeave();
+ current_drop_data_.reset();
+}
+
+void WebContentsViewAndroid::OnPerformDrop(const ui::DropTargetEvent& event) {
+ current_drop_data_.reset(new DropData());
+ PrepareDropData(current_drop_data_.get(), event.data());
+
+ web_contents_->GetRenderViewHost()->DragTargetDropWithData(
+ *current_drop_data_.get(), event.location(), event.root_location(), 0);
+}
+
void WebContentsViewAndroid::GotFocus() {
// This is only used in the views FocusManager stuff but it bleeds through
// all subclasses. http://crbug.com/21875

Powered by Google App Engine
This is Rietveld 408576698