diff options
author | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-22 00:12:15 +0000 |
---|---|---|
committer | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-22 00:12:15 +0000 |
commit | 124825ede0f1ff53db9ca2255142c4fcec1ad5ca (patch) | |
tree | a6182880b9caba34bf738bee043c109ba16838a7 /webkit/glue/webview_impl.cc | |
parent | 478ff2ed6a244658c0a30d6cbfff1a9046b9ba9d (diff) | |
download | chromium_src-124825ede0f1ff53db9ca2255142c4fcec1ad5ca.zip chromium_src-124825ede0f1ff53db9ca2255142c4fcec1ad5ca.tar.gz chromium_src-124825ede0f1ff53db9ca2255142c4fcec1ad5ca.tar.bz2 |
Provide an override for Webview drop effect.
Used for gears file drag & drop in chrome, provide a setter api to override
the default webview drop effect. If gears overrides the drop_effect, then
either a "copy" or "none" cursor is shown to the user. Otherwise, the drop
effect shown is the default for the webview (controlled by WebKit).
Also remove a TODO: during drag and drop, remember the drop accept state of
the webview (in drag enter, drag over). Use that to prevent drops on webviews
that can't accept the drop data.
BUG=7995
Original patch from Noel Gordon via
http://codereview.chromium.org/67297
Review URL: http://codereview.chromium.org/88073
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14162 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/webview_impl.cc')
-rw-r--r-- | webkit/glue/webview_impl.cc | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/webkit/glue/webview_impl.cc b/webkit/glue/webview_impl.cc index 03db938..e974d44 100644 --- a/webkit/glue/webview_impl.cc +++ b/webkit/glue/webview_impl.cc @@ -363,6 +363,8 @@ WebViewImpl::WebViewImpl() ime_accept_events_(true), drag_target_dispatch_(false), drag_identity_(0), + drop_effect_(DROP_EFFECT_DEFAULT), + drop_accept_(false), autocomplete_popup_showing_(false) { // WebKit/win/WebView.cpp does the same thing, except they call the // KJS specific wrapper around this method. We need to have threading @@ -1632,11 +1634,15 @@ bool WebViewImpl::DragTargetDragEnter( webkit_glue::WebPointToIntPoint(client_point), webkit_glue::WebPointToIntPoint(screen_point), kDropTargetOperation); + + drop_effect_ = DROP_EFFECT_DEFAULT; drag_target_dispatch_ = true; DragOperation effect = page_->dragController()->dragEntered(&drag_data); drag_target_dispatch_ = false; - return effect != DragOperationNone; + if (drop_effect_ != DROP_EFFECT_DEFAULT) + return drop_accept_ = (drop_effect_ != DROP_EFFECT_NONE); + return drop_accept_ = (effect != DragOperationNone); } bool WebViewImpl::DragTargetDragOver( @@ -1649,11 +1655,15 @@ bool WebViewImpl::DragTargetDragOver( webkit_glue::WebPointToIntPoint(client_point), webkit_glue::WebPointToIntPoint(screen_point), kDropTargetOperation); + + drop_effect_ = DROP_EFFECT_DEFAULT; drag_target_dispatch_ = true; DragOperation effect = page_->dragController()->dragUpdated(&drag_data); drag_target_dispatch_ = false; - return effect != DragOperationNone; + if (drop_effect_ != DROP_EFFECT_DEFAULT) + return drop_accept_ = (drop_effect_ != DROP_EFFECT_NONE); + return drop_accept_ = (effect != DragOperationNone); } void WebViewImpl::DragTargetDragLeave() { @@ -1664,11 +1674,14 @@ void WebViewImpl::DragTargetDragLeave() { IntPoint(), IntPoint(), kDropTargetOperation); + drag_target_dispatch_ = true; page_->dragController()->dragExited(&drag_data); drag_target_dispatch_ = false; current_drag_data_ = NULL; + drop_effect_ = DROP_EFFECT_DEFAULT; + drop_accept_ = false; drag_identity_ = 0; } @@ -1677,16 +1690,31 @@ void WebViewImpl::DragTargetDrop( const WebPoint& screen_point) { DCHECK(current_drag_data_.get()); + // If this webview transitions from the "drop accepting" state to the "not + // accepting" state, then our IPC message reply indicating that may be in- + // flight, or else delayed by javascript processing in this webview. If a + // drop happens before our IPC reply has reached the browser process, then + // the browser forwards the drop to this webview. So only allow a drop to + // proceed if our webview drop_accept_ state is true. + + if (!drop_accept_) { // IPC RACE CONDITION: do not allow this drop. + DragTargetDragLeave(); + return; + } + DragData drag_data( current_drag_data_.get(), webkit_glue::WebPointToIntPoint(client_point), webkit_glue::WebPointToIntPoint(screen_point), kDropTargetOperation); + drag_target_dispatch_ = true; page_->dragController()->performDrag(&drag_data); drag_target_dispatch_ = false; current_drag_data_ = NULL; + drop_effect_ = DROP_EFFECT_DEFAULT; + drop_accept_ = false; drag_identity_ = 0; } @@ -1696,6 +1724,15 @@ int32 WebViewImpl::GetDragIdentity() { return 0; } +bool WebViewImpl::SetDropEffect(bool accept) { + if (drag_target_dispatch_) { + drop_effect_ = accept ? DROP_EFFECT_COPY : DROP_EFFECT_NONE; + return true; + } else { + return false; + } +} + SearchableFormData* WebViewImpl::CreateSearchableFormDataForFocusedNode() { if (!page_.get()) return NULL; |