2011-02-28 01:33:11 +01:00
|
|
|
// Copyright (c) 2011 The Chromium Embedded Framework Authors.
|
|
|
|
// Portions copyright (c) 2011 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.
|
|
|
|
|
2011-08-22 03:31:55 +02:00
|
|
|
#include "browser_impl.h"
|
2011-02-28 01:33:11 +01:00
|
|
|
#include "cef_context.h"
|
2011-08-22 03:31:55 +02:00
|
|
|
#include "drag_data_impl.h"
|
2011-02-28 01:33:11 +01:00
|
|
|
#include "web_drag_utils_win.h"
|
2011-08-22 03:31:55 +02:00
|
|
|
#include "web_drop_target_win.h"
|
2011-02-28 01:33:11 +01:00
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <shlobj.h>
|
|
|
|
|
|
|
|
#include "googleurl/src/gurl.h"
|
|
|
|
#include "net/base/net_util.h"
|
2011-12-16 15:51:10 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.h"
|
2011-12-21 19:35:55 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
|
2011-02-28 01:33:11 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
|
|
|
|
#include "ui/base/clipboard/clipboard_util_win.h"
|
|
|
|
#include "ui/base/dragdrop/os_exchange_data.h"
|
|
|
|
#include "ui/base/dragdrop/os_exchange_data_provider_win.h"
|
|
|
|
#include "webkit/glue/webdropdata.h"
|
|
|
|
#include "webkit/glue/window_open_disposition.h"
|
|
|
|
|
|
|
|
using WebKit::WebDragOperation;
|
|
|
|
using WebKit::WebDragOperationNone;
|
|
|
|
using WebKit::WebDragOperationCopy;
|
|
|
|
using WebKit::WebDragOperationLink;
|
|
|
|
using WebKit::WebDragOperationMove;
|
|
|
|
using WebKit::WebDragOperationGeneric;
|
|
|
|
using WebKit::WebPoint;
|
2011-08-22 03:31:55 +02:00
|
|
|
using WebKit::WebView;
|
2011-02-28 01:33:11 +01:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// A helper method for getting the preferred drop effect.
|
|
|
|
DWORD GetPreferredDropEffect(DWORD effect) {
|
|
|
|
if (effect & DROPEFFECT_COPY)
|
|
|
|
return DROPEFFECT_COPY;
|
|
|
|
if (effect & DROPEFFECT_LINK)
|
|
|
|
return DROPEFFECT_LINK;
|
|
|
|
if (effect & DROPEFFECT_MOVE)
|
|
|
|
return DROPEFFECT_MOVE;
|
|
|
|
return DROPEFFECT_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2011-08-22 03:31:55 +02:00
|
|
|
WebDropTarget::WebDropTarget(CefBrowserImpl* browser)
|
|
|
|
: ui::DropTarget(browser->UIT_GetWebViewWndHandle()),
|
|
|
|
browser_(browser),
|
2011-02-28 01:33:11 +01:00
|
|
|
current_wvh_(NULL),
|
2011-08-22 03:31:55 +02:00
|
|
|
drag_cursor_(WebDragOperationNone),
|
|
|
|
canceled_(false) {
|
2011-02-28 01:33:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
WebDropTarget::~WebDropTarget() {
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD WebDropTarget::OnDragEnter(IDataObject* data_object,
|
|
|
|
DWORD key_state,
|
|
|
|
POINT cursor_position,
|
|
|
|
DWORD effects) {
|
|
|
|
current_wvh_ = _Context->current_webviewhost();
|
2011-06-14 17:45:00 +02:00
|
|
|
DCHECK(current_wvh_);
|
2011-02-28 01:33:11 +01:00
|
|
|
|
|
|
|
// TODO(tc): PopulateWebDropData can be slow depending on what is in the
|
|
|
|
// IDataObject. Maybe we can do this in a background thread.
|
2011-04-05 18:17:33 +02:00
|
|
|
WebDropData drop_data;
|
2011-02-28 01:33:11 +01:00
|
|
|
WebDropData::PopulateWebDropData(data_object, &drop_data);
|
|
|
|
|
|
|
|
if (drop_data.url.is_empty())
|
|
|
|
ui::OSExchangeDataProviderWin::GetPlainTextURL(data_object, &drop_data.url);
|
|
|
|
|
2011-08-22 03:31:55 +02:00
|
|
|
WebKit::WebDragOperationsMask mask =
|
|
|
|
web_drag_utils_win::WinDragOpMaskToWebDragOpMask(effects);
|
|
|
|
|
|
|
|
canceled_ = false;
|
|
|
|
|
|
|
|
CefRefPtr<CefClient> client = browser_->GetClient();
|
|
|
|
if (client.get()) {
|
|
|
|
CefRefPtr<CefDragHandler> handler = client->GetDragHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
CefRefPtr<CefDragData> data(new CefDragDataImpl(drop_data));
|
|
|
|
if (handler->OnDragEnter(browser_, data,
|
|
|
|
static_cast<CefDragHandler::DragOperationsMask>(mask))) {
|
|
|
|
canceled_ = true;
|
|
|
|
return DROPEFFECT_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-28 01:33:11 +01:00
|
|
|
drag_cursor_ = WebDragOperationNone;
|
|
|
|
|
|
|
|
POINT client_pt = cursor_position;
|
|
|
|
ScreenToClient(GetHWND(), &client_pt);
|
2011-12-01 18:11:45 +01:00
|
|
|
WebDragOperation operation;
|
|
|
|
if (browser_->UIT_GetWebView()) {
|
|
|
|
operation = browser_->UIT_GetWebView()->dragTargetDragEnter(
|
|
|
|
drop_data.ToDragData(),
|
|
|
|
WebPoint(client_pt.x, client_pt.y),
|
|
|
|
WebPoint(cursor_position.x, cursor_position.y),
|
|
|
|
mask);
|
|
|
|
} else {
|
|
|
|
operation = WebDragOperationNone;
|
|
|
|
}
|
2011-02-28 01:33:11 +01:00
|
|
|
|
|
|
|
return web_drag_utils_win::WebDragOpToWinDragOp(operation);
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD WebDropTarget::OnDragOver(IDataObject* data_object,
|
|
|
|
DWORD key_state,
|
|
|
|
POINT cursor_position,
|
|
|
|
DWORD effects) {
|
|
|
|
DCHECK(current_wvh_);
|
|
|
|
if (current_wvh_ != _Context->current_webviewhost())
|
|
|
|
OnDragEnter(data_object, key_state, cursor_position, effects);
|
|
|
|
|
2011-08-22 03:31:55 +02:00
|
|
|
if (canceled_)
|
|
|
|
return DROPEFFECT_NONE;
|
|
|
|
|
2011-02-28 01:33:11 +01:00
|
|
|
POINT client_pt = cursor_position;
|
|
|
|
ScreenToClient(GetHWND(), &client_pt);
|
2011-12-01 18:11:45 +01:00
|
|
|
WebDragOperation operation;
|
|
|
|
if (browser_->UIT_GetWebView()) {
|
2011-12-08 02:11:08 +01:00
|
|
|
operation = browser_->UIT_GetWebView()->dragTargetDragOver(
|
2011-12-01 18:11:45 +01:00
|
|
|
WebPoint(client_pt.x, client_pt.y),
|
|
|
|
WebPoint(cursor_position.x, cursor_position.y),
|
|
|
|
web_drag_utils_win::WinDragOpMaskToWebDragOpMask(effects));
|
|
|
|
} else {
|
|
|
|
operation = WebDragOperationNone;
|
|
|
|
}
|
2011-02-28 01:33:11 +01:00
|
|
|
|
|
|
|
return web_drag_utils_win::WebDragOpToWinDragOp(operation);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebDropTarget::OnDragLeave(IDataObject* data_object) {
|
|
|
|
DCHECK(current_wvh_);
|
|
|
|
if (current_wvh_ != _Context->current_webviewhost())
|
|
|
|
return;
|
|
|
|
|
2011-08-22 03:31:55 +02:00
|
|
|
if (canceled_)
|
|
|
|
return;
|
|
|
|
|
2011-12-01 18:11:45 +01:00
|
|
|
if (browser_->UIT_GetWebView())
|
|
|
|
browser_->UIT_GetWebView()->dragTargetDragLeave();
|
2011-02-28 01:33:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DWORD WebDropTarget::OnDrop(IDataObject* data_object,
|
|
|
|
DWORD key_state,
|
|
|
|
POINT cursor_position,
|
|
|
|
DWORD effect) {
|
|
|
|
DCHECK(current_wvh_);
|
|
|
|
if (current_wvh_ != _Context->current_webviewhost())
|
|
|
|
OnDragEnter(data_object, key_state, cursor_position, effect);
|
|
|
|
|
|
|
|
POINT client_pt = cursor_position;
|
|
|
|
ScreenToClient(GetHWND(), &client_pt);
|
2011-10-18 02:23:32 +02:00
|
|
|
|
|
|
|
browser_->set_is_dropping(true);
|
2011-12-01 18:11:45 +01:00
|
|
|
if (browser_->UIT_GetWebView()) {
|
|
|
|
browser_->UIT_GetWebView()->dragTargetDrop(
|
|
|
|
WebPoint(client_pt.x, client_pt.y),
|
|
|
|
WebPoint(cursor_position.x, cursor_position.y));
|
|
|
|
}
|
2011-10-18 02:23:32 +02:00
|
|
|
browser_->set_is_dropping(false);
|
2011-02-28 01:33:11 +01:00
|
|
|
|
|
|
|
current_wvh_ = NULL;
|
|
|
|
|
|
|
|
// This isn't always correct, but at least it's a close approximation.
|
|
|
|
// For now, we always map a move to a copy to prevent potential data loss.
|
|
|
|
DWORD drop_effect = web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_);
|
|
|
|
return drop_effect != DROPEFFECT_MOVE ? drop_effect : DROPEFFECT_COPY;
|
|
|
|
}
|