CefDragHandler.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. namespace Xilium.CefGlue
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.Runtime.InteropServices;
  7. using Xilium.CefGlue.Interop;
  8. /// <summary>
  9. /// Implement this interface to handle events related to dragging. The methods of
  10. /// this class will be called on the UI thread.
  11. /// </summary>
  12. public abstract unsafe partial class CefDragHandler
  13. {
  14. private int on_drag_enter(cef_drag_handler_t* self, cef_browser_t* browser, cef_drag_data_t* dragData, CefDragOperationsMask mask)
  15. {
  16. CheckSelf(self);
  17. var m_browser = CefBrowser.FromNative(browser);
  18. var m_dragData = CefDragData.FromNative(dragData); // TODO dispose?
  19. var m_result = OnDragEnter(m_browser, m_dragData, mask);
  20. return m_result ? 1 : 0;
  21. }
  22. /// <summary>
  23. /// Called when an external drag event enters the browser window. |dragData|
  24. /// contains the drag event data and |mask| represents the type of drag
  25. /// operation. Return false for default drag handling behavior or true to
  26. /// cancel the drag event.
  27. /// </summary>
  28. protected abstract bool OnDragEnter(CefBrowser browser, CefDragData dragData, CefDragOperationsMask mask);
  29. private static readonly CefDraggableRegion[] EmptyDraggableRegion = new CefDraggableRegion[0];
  30. private void on_draggable_regions_changed(cef_drag_handler_t* self, cef_browser_t* browser, cef_frame_t* frame, UIntPtr regionsCount, cef_draggable_region_t* regions)
  31. {
  32. CheckSelf(self);
  33. var m_browser = CefBrowser.FromNative(browser);
  34. var m_frame = CefFrame.FromNative(frame);
  35. CefDraggableRegion[] m_regions;
  36. var m_count = (int)regionsCount;
  37. if (m_count == 0) m_regions = EmptyDraggableRegion;
  38. else
  39. {
  40. m_regions = new CefDraggableRegion[m_count];
  41. for (var i = 0; i < m_count; i++)
  42. {
  43. m_regions[i] = CefDraggableRegion.FromNative(regions + i); // TODO dispose?
  44. }
  45. }
  46. OnDraggableRegionsChanged(m_browser, m_frame, m_regions);
  47. }
  48. /// <summary>
  49. /// Called whenever draggable regions for the browser window change. These can
  50. /// be specified using the '-webkit-app-region: drag/no-drag' CSS-property. If
  51. /// draggable regions are never defined in a document this method will also
  52. /// never be called. If the last draggable region is removed from a document
  53. /// this method will be called with an empty vector.
  54. /// </summary>
  55. protected abstract void OnDraggableRegionsChanged(CefBrowser browser, CefFrame frame, CefDraggableRegion[] regions);
  56. }
  57. }