mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-06 12:09:40 +00:00
Implement start drag for WPF browser
Exposed the necessary functions for start drag to work: * StartDragging (RenderClientAdapter) * OnDragSourceEndedAt (ManagedCefBrowserAdapter) * OnDragSourceSystemDragEnded (ManagedCefBrowserAdapter) Implemented IRenderWebBrowser.StartDragging for the WPF ChromiumWebBrowser. TODO: Would like to add an adorner layer for the dragged text (using the supplied fragment html), but feels like a project for later.
This commit is contained in:
@@ -177,6 +177,13 @@ namespace CefSharp
|
||||
_renderWebBrowser->SetCursor((IntPtr)cursor, (CefSharp::CefCursorType)type);
|
||||
};
|
||||
|
||||
virtual DECL bool StartDragging(CefRefPtr<CefBrowser> browser, CefRefPtr<CefDragData> drag_data,
|
||||
CefRenderHandler::DragOperationsMask allowed_ops, int x, int y)
|
||||
{
|
||||
CefDragDataWrapper dragDataWrapper(drag_data);
|
||||
return _renderWebBrowser->StartDragging(%dragDataWrapper, (CefSharp::DragOperationsMask)allowed_ops, x, y);
|
||||
}
|
||||
|
||||
private:
|
||||
void ReleaseBitmapHandlers(BitmapInfo^ bitmapInfo)
|
||||
{
|
||||
|
||||
@@ -335,6 +335,26 @@ void ManagedCefBrowserAdapter::OnDragTargetDragDrop(MouseEvent^ mouseEvent)
|
||||
}
|
||||
}
|
||||
|
||||
void ManagedCefBrowserAdapter::OnDragSourceEndedAt(int x, int y, DragOperationsMask op)
|
||||
{
|
||||
auto browser = _clientAdapter->GetCefBrowser();
|
||||
|
||||
if (browser != nullptr)
|
||||
{
|
||||
browser->GetHost()->DragSourceEndedAt(x, y, (CefBrowserHost::DragOperationsMask)op);
|
||||
}
|
||||
}
|
||||
|
||||
void ManagedCefBrowserAdapter::OnDragSourceSystemDragEnded()
|
||||
{
|
||||
auto browser = _clientAdapter->GetCefBrowser();
|
||||
|
||||
if (browser != nullptr)
|
||||
{
|
||||
browser->GetHost()->DragSourceSystemDragEnded();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the CefBrowserWrapper instance
|
||||
/// </summary>
|
||||
|
||||
@@ -133,6 +133,9 @@ namespace CefSharp
|
||||
void OnDragTargetDragLeave();
|
||||
void OnDragTargetDragDrop(MouseEvent^ mouseEvent);
|
||||
|
||||
void OnDragSourceEndedAt(int x, int y, DragOperationsMask op);
|
||||
void OnDragSourceSystemDragEnded();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the CefBrowserWrapper instance
|
||||
/// </summary>
|
||||
|
||||
@@ -324,6 +324,11 @@ namespace CefSharp.OffScreen
|
||||
{
|
||||
}
|
||||
|
||||
bool IRenderWebBrowser.StartDragging(IDragData dragData, DragOperationsMask mask, int x, int y)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void IRenderWebBrowser.SetPopupIsOpen(bool show)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -251,6 +251,21 @@ namespace CefSharp.Wpf
|
||||
return BitmapFactory.CreateBitmap(isPopup);
|
||||
}
|
||||
|
||||
bool IRenderWebBrowser.StartDragging(IDragData dragData, DragOperationsMask mask, int x, int y)
|
||||
{
|
||||
var dragDataCopy = CefDragDataWrapper.Create();
|
||||
dragDataCopy.FragmentText = dragData.FragmentText;
|
||||
dragDataCopy.FragmentHtml = dragData.FragmentHtml;
|
||||
|
||||
UiThreadRunAsync(delegate
|
||||
{
|
||||
var results = DragDrop.DoDragDrop(this, dragDataCopy.FragmentHtml, GetDragEffects(mask));
|
||||
managedCefBrowserAdapter.OnDragSourceEndedAt(0, 0, GetDragOperationsMask((DragDropEffects)results));
|
||||
managedCefBrowserAdapter.OnDragSourceSystemDragEnded();
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
void IRenderWebBrowser.InvokeRenderAsync(BitmapInfo bitmapInfo)
|
||||
{
|
||||
UiThreadRunAsync(delegate
|
||||
@@ -754,6 +769,27 @@ namespace CefSharp.Wpf
|
||||
return operations;
|
||||
}
|
||||
|
||||
private DragDropEffects GetDragEffects(DragOperationsMask mask)
|
||||
{
|
||||
if ((mask & DragOperationsMask.Every) == DragOperationsMask.Every)
|
||||
{
|
||||
return DragDropEffects.All;
|
||||
}
|
||||
if ((mask & DragOperationsMask.Copy) == DragOperationsMask.Copy)
|
||||
{
|
||||
return DragDropEffects.Copy;
|
||||
}
|
||||
if ((mask & DragOperationsMask.Move) == DragOperationsMask.Move)
|
||||
{
|
||||
return DragDropEffects.Move;
|
||||
}
|
||||
if ((mask & DragOperationsMask.Link) == DragOperationsMask.Link)
|
||||
{
|
||||
return DragDropEffects.Link;
|
||||
}
|
||||
return DragDropEffects.None;
|
||||
}
|
||||
|
||||
private void PresentationSourceChangedHandler(object sender, SourceChangedEventArgs args)
|
||||
{
|
||||
if (args.NewSource != null)
|
||||
|
||||
@@ -15,6 +15,8 @@ namespace CefSharp.Internals
|
||||
|
||||
void SetCursor(IntPtr cursor, CefCursorType type);
|
||||
|
||||
bool StartDragging(IDragData dragData, DragOperationsMask mask, int x, int y);
|
||||
|
||||
void SetPopupIsOpen(bool show);
|
||||
void SetPopupSizeAndPosition(int width, int height, int x, int y);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user