From 13a1166eb46a5b98e1cf5fce21ae327f3e059aa5 Mon Sep 17 00:00:00 2001 From: "dcheng@chromium.org" Date: Tue, 6 Apr 2010 16:58:34 +0000 Subject: Win32 plumbing for dragend event. This plumbs the actual dropEffect that occurred back into WebKit so that dragend is dispatched with the correct dropEffect. Note that this only helps with drags that start in Chrome and end outside of Chrome. Since WebDropTarget always lies and claims that no drop occurred, drags that start in Chrome and end in Chrome will still be incorrect. BUG=39399 TEST=Manual testing using the attached test case on the bug. Review URL: http://codereview.chromium.org/1136007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43726 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/tab_contents/web_drag_source_win.cc | 12 ++++----- chrome/browser/tab_contents/web_drag_source_win.h | 4 +++ chrome/browser/tab_contents/web_drag_utils_win.cc | 29 ++++++++++++++++++++++ chrome/browser/tab_contents/web_drag_utils_win.h | 19 ++++++++++++++ chrome/browser/tab_contents/web_drop_target_win.cc | 16 +++--------- 5 files changed, 61 insertions(+), 19 deletions(-) create mode 100644 chrome/browser/tab_contents/web_drag_utils_win.cc create mode 100644 chrome/browser/tab_contents/web_drag_utils_win.h (limited to 'chrome/browser/tab_contents') diff --git a/chrome/browser/tab_contents/web_drag_source_win.cc b/chrome/browser/tab_contents/web_drag_source_win.cc index 62fe910..1b1ced1 100644 --- a/chrome/browser/tab_contents/web_drag_source_win.cc +++ b/chrome/browser/tab_contents/web_drag_source_win.cc @@ -8,11 +8,11 @@ #include "chrome/browser/chrome_thread.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/tab_contents/web_drag_utils_win.h" #include "chrome/common/notification_type.h" #include "chrome/common/notification_service.h" using WebKit::WebDragOperationNone; -using WebKit::WebDragOperationCopy; namespace { @@ -34,7 +34,8 @@ WebDragSource::WebDragSource(gfx::NativeWindow source_wnd, TabContents* tab_contents) : BaseDragSource(), source_wnd_(source_wnd), - render_view_host_(tab_contents->render_view_host()) { + render_view_host_(tab_contents->render_view_host()), + effect_(DROPEFFECT_NONE) { registrar_.Add(this, NotificationType::TAB_CONTENTS_SWAPPED, Source(tab_contents)); registrar_.Add(this, NotificationType::TAB_CONTENTS_DISCONNECTED, @@ -79,10 +80,9 @@ void WebDragSource::DelayedOnDragSourceDrop() { gfx::Point client; gfx::Point screen; GetCursorPositions(source_wnd_, &client, &screen); - render_view_host_->DragSourceEndedAt(client.x(), client.y(), - screen.x(), screen.y(), - WebDragOperationCopy); - // TODO(jpa): This needs to be fixed to send the actual drag operation. + render_view_host_->DragSourceEndedAt( + client.x(), client.y(), screen.x(), screen.y(), + web_drag_utils_win::WinDragOpToWebDragOp(effect_)); } void WebDragSource::OnDragSourceMove() { diff --git a/chrome/browser/tab_contents/web_drag_source_win.h b/chrome/browser/tab_contents/web_drag_source_win.h index c0a8eb0..986d70c 100644 --- a/chrome/browser/tab_contents/web_drag_source_win.h +++ b/chrome/browser/tab_contents/web_drag_source_win.h @@ -36,6 +36,8 @@ class WebDragSource : public BaseDragSource, const NotificationSource& source, const NotificationDetails& details); + void set_effect(DWORD effect) { effect_ = effect; } + protected: // BaseDragSource virtual void OnDragSourceCancel(); @@ -60,6 +62,8 @@ class WebDragSource : public BaseDragSource, NotificationRegistrar registrar_; + DWORD effect_; + DISALLOW_COPY_AND_ASSIGN(WebDragSource); }; diff --git a/chrome/browser/tab_contents/web_drag_utils_win.cc b/chrome/browser/tab_contents/web_drag_utils_win.cc new file mode 100644 index 0000000..5c15f45 --- /dev/null +++ b/chrome/browser/tab_contents/web_drag_utils_win.cc @@ -0,0 +1,29 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/tab_contents/web_drag_utils_win.h" + +#include + +using WebKit::WebDragOperationsMask; +using WebKit::WebDragOperationNone; +using WebKit::WebDragOperationCopy; +using WebKit::WebDragOperationLink; +using WebKit::WebDragOperationMove; + +namespace web_drag_utils_win { + +WebDragOperationsMask WinDragOpToWebDragOp(DWORD effect) { + WebDragOperationsMask op = WebDragOperationNone; + if (effect & DROPEFFECT_COPY) + op = static_cast(op | WebDragOperationCopy); + if (effect & DROPEFFECT_LINK) + op = static_cast(op | WebDragOperationLink); + if (effect & DROPEFFECT_MOVE) + op = static_cast(op | WebDragOperationMove); + return op; +} + +} // namespace web_drag_utils_win + diff --git a/chrome/browser/tab_contents/web_drag_utils_win.h b/chrome/browser/tab_contents/web_drag_utils_win.h new file mode 100644 index 0000000..14e8389 --- /dev/null +++ b/chrome/browser/tab_contents/web_drag_utils_win.h @@ -0,0 +1,19 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_TAB_CONTENTS_WEB_DRAG_UTILS_WIN_H_ +#define CHROME_BROWSER_TAB_CONTENTS_WEB_DRAG_UTILS_WIN_H_ + +#include "third_party/WebKit/WebKit/chromium/public/WebDragOperation.h" + +#include + +namespace web_drag_utils_win { + +WebKit::WebDragOperationsMask WinDragOpToWebDragOp(DWORD effect); + +} // namespace web_drag_utils_win + +#endif // CHROME_BROWSER_TAB_CONTENTS_WEB_DRAG_UTILS_WIN_H_ + diff --git a/chrome/browser/tab_contents/web_drop_target_win.cc b/chrome/browser/tab_contents/web_drop_target_win.cc index 2ba66a9..1ea79a8 100644 --- a/chrome/browser/tab_contents/web_drop_target_win.cc +++ b/chrome/browser/tab_contents/web_drop_target_win.cc @@ -13,6 +13,7 @@ #include "chrome/browser/bookmarks/bookmark_drag_data.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/tab_contents/web_drag_utils_win.h" #include "gfx/point.h" #include "googleurl/src/gurl.h" #include "net/base/net_util.h" @@ -48,17 +49,6 @@ DWORD GetPreferredDragCursor(WebDragOperationsMask op) { return DROPEFFECT_NONE; } -WebDragOperationsMask WinDragOpToWebDragOp(DWORD effect) { - WebDragOperationsMask op = WebDragOperationNone; - if (effect & DROPEFFECT_COPY) - op = static_cast(op | WebDragOperationCopy); - if (effect & DROPEFFECT_LINK) - op = static_cast(op | WebDragOperationLink); - if (effect & DROPEFFECT_MOVE) - op = static_cast(op | WebDragOperationMove); - return op; -} - } // anonymous namespace // InterstitialDropTarget is like a BaseDropTarget implementation that @@ -142,7 +132,7 @@ DWORD WebDropTarget::OnDragEnter(IDataObject* data_object, tab_contents_->render_view_host()->DragTargetDragEnter(drop_data, gfx::Point(client_pt.x, client_pt.y), gfx::Point(cursor_position.x, cursor_position.y), - WinDragOpToWebDragOp(effect)); + web_drag_utils_win::WinDragOpToWebDragOp(effect)); // This is non-null if tab_contents_ is showing an ExtensionDOMUI with // support for (at the moment experimental) drag and drop extensions. @@ -174,7 +164,7 @@ DWORD WebDropTarget::OnDragOver(IDataObject* data_object, tab_contents_->render_view_host()->DragTargetDragOver( gfx::Point(client_pt.x, client_pt.y), gfx::Point(cursor_position.x, cursor_position.y), - WinDragOpToWebDragOp(effect)); + web_drag_utils_win::WinDragOpToWebDragOp(effect)); if (tab_contents_->GetBookmarkDragDelegate()) { OSExchangeData os_exchange_data(new OSExchangeDataProviderWin(data_object)); -- cgit v1.1