namespace Cef3 { using System; using System.Collections.Generic; using System.Diagnostics; using System.Runtime.InteropServices; using Cef3.Interop; /// /// Class used to represent drag data. The methods of this class may be called /// on any thread. /// public sealed unsafe partial class CefDragData { /// /// Create a new CefDragData object. /// public static CefDragData Create() { return CefDragData.FromNative(cef_drag_data_t.create()); } /// /// Returns a copy of the current object. /// public CefDragData Clone() { return CefDragData.FromNative(cef_drag_data_t.clone(_self)); } /// /// Returns true if this object is read-only. /// public bool IsReadOnly { get { return cef_drag_data_t.is_read_only(_self) != 0; } } /// /// Returns true if the drag data is a link. /// public bool IsLink { get { return cef_drag_data_t.is_link(_self) != 0; } } /// /// Returns true if the drag data is a text or html fragment. /// public bool IsFragment { get { return cef_drag_data_t.is_fragment(_self) != 0; } } /// /// Returns true if the drag data is a file. /// public bool IsFile { get { return cef_drag_data_t.is_file(_self) != 0; } } /// /// Return the link URL that is being dragged. /// public string LinkUrl { get { var n_result = cef_drag_data_t.get_link_url(_self); return cef_string_userfree.ToString(n_result); } } /// /// Return the title associated with the link being dragged. /// public string LinkTitle { get { var n_result = cef_drag_data_t.get_link_title(_self); return cef_string_userfree.ToString(n_result); } } /// /// Return the metadata, if any, associated with the link being dragged. /// public string LinkMetadata { get { var n_result = cef_drag_data_t.get_link_metadata(_self); return cef_string_userfree.ToString(n_result); } } /// /// Return the plain text fragment that is being dragged. /// public string FragmentText { get { var n_result = cef_drag_data_t.get_fragment_text(_self); return cef_string_userfree.ToString(n_result); } } /// /// Return the text/html fragment that is being dragged. /// public string FragmentHtml { get { var n_result = cef_drag_data_t.get_fragment_html(_self); return cef_string_userfree.ToString(n_result); } } /// /// Return the base URL that the fragment came from. This value is used for /// resolving relative URLs and may be empty. /// public string FragmentBaseUrl { get { var n_result = cef_drag_data_t.get_fragment_base_url(_self); return cef_string_userfree.ToString(n_result); } } /// /// Return the name of the file being dragged out of the browser window. /// public string FileName { get { var n_result = cef_drag_data_t.get_file_name(_self); return cef_string_userfree.ToString(n_result); } } /// /// Write the contents of the file being dragged out of the web view into /// |writer|. Returns the number of bytes sent to |writer|. If |writer| is /// NULL this method will return the size of the file contents in bytes. /// Call GetFileName() to get a suggested name for the file. /// public ulong GetFileContents(CefStreamWriter writer) { var n_writer = writer != null ? writer.ToNative() : null; return (ulong)cef_drag_data_t.get_file_contents(_self, n_writer); } /// /// Retrieve the list of file names that are being dragged into the browser /// window. /// public string[] GetFileNames() { cef_string_list* n_result = null; try { n_result = libcef.string_list_alloc(); var success = cef_drag_data_t.get_file_names(_self, n_result) != 0; if (!success) return null; return cef_string_list.ToArray(n_result); } finally { if (n_result != null) libcef.string_list_free(n_result); } } /// /// Set the link URL that is being dragged. /// public void SetLinkURL(string url) { fixed (char* url_str = url) { var n_url = new cef_string_t(url_str, url != null ? url.Length : 0); cef_drag_data_t.set_link_url(_self, &n_url); } } /// /// Set the title associated with the link being dragged. /// public void SetLinkTitle(string title) { fixed (char* title_str = title) { var n_title = new cef_string_t(title_str, title != null ? title.Length : 0); cef_drag_data_t.set_link_title(_self, &n_title); } } /// /// Set the metadata associated with the link being dragged. /// public void SetLinkMetadata(string data) { fixed (char* data_str = data) { var n_data = new cef_string_t(data_str, data != null ? data.Length : 0); cef_drag_data_t.set_link_metadata(_self, &n_data); } } /// /// Set the plain text fragment that is being dragged. /// public void SetFragmentText(string text) { fixed (char* text_str = text) { var n_text = new cef_string_t(text_str, text != null ? text.Length : 0); cef_drag_data_t.set_fragment_text(_self, &n_text); } } /// /// Set the text/html fragment that is being dragged. /// public void SetFragmentHtml(string html) { fixed (char* html_str = html) { var n_html = new cef_string_t(html_str, html != null ? html.Length : 0); cef_drag_data_t.set_fragment_html(_self, &n_html); } } /// /// Set the base URL that the fragment came from. /// public void SetFragmentBaseURL(string baseUrl) { fixed (char* baseUrl_str = baseUrl) { var n_baseUrl = new cef_string_t(baseUrl_str, baseUrl != null ? baseUrl.Length : 0); cef_drag_data_t.set_fragment_base_url(_self, &n_baseUrl); } } /// /// Reset the file contents. You should do this before calling /// CefBrowserHost::DragTargetDragEnter as the web view does not allow us to /// drag in this kind of data. /// public void ResetFileContents() { cef_drag_data_t.reset_file_contents(_self); } /// /// Add a file that is being dragged into the webview. /// public void AddFile(string path, string displayName) { fixed (char* path_str = path) fixed (char* displayName_str = displayName) { var n_path = new cef_string_t(path_str, path != null ? path.Length : 0); var n_displayName = new cef_string_t(displayName_str, displayName != null ? displayName.Length : 0); cef_drag_data_t.add_file(_self, &n_path, &n_displayName); } } } }