Skip to content

CefDragData

Header: cef_drag_data.h
Category: Core APIs

Overview

Foundational interfaces: process bootstrap, browser lifecycle, frames, DOM, requests, and data objects.

CefDragData

Source File: include/cef_drag_data.h

Process / Thread Context: Any thread (per class comment: "The methods of this class may be called on any thread.")

Purpose: USER-CALLED library interface representing drag-and-drop payload data (link, fragment, file, image). Used by CefDragHandler callbacks and CefBrowserHost::DragTargetDragEnter/DragTargetDragOver/DragTargetDragLeave/DragTargetDrop to inspect and populate the drag payload.

Methods

static CefRefPtr<CefDragData> Create()

Parameters:

  • None.

Return Value: A new empty CefDragData instance.

Usage Instruction: Use to fabricate drag data for synthetic drag events passed to CefBrowserHost::DragTargetDragEnter().

Threading Constraint: Any thread.

CefRefPtr<CefDragData> Clone()

Return Value: Returns a copy of the current object.

Threading Constraint: Threading constraint not specified in source.

bool IsReadOnly()

Return Value: True if read-only (e.g., the object was supplied by an incoming drag event the application cannot modify).

Threading Constraint: Threading constraint not specified in source.

Return Value: True if payload is a link drag.

Threading Constraint: Threading constraint not specified in source.

bool IsFragment()

Return Value: True if payload is a text/HTML fragment drag.

Threading Constraint: Threading constraint not specified in source.

bool IsFile()

Return Value: True if payload is a file drag.

Threading Constraint: Threading constraint not specified in source.

CefString GetFileName()

Return Value: Suggested file name for the dragged file (drag-out).

Threading Constraint: Threading constraint not specified in source.

size_t GetFileContents(CefRefPtr<CefStreamWriter> writer)

Parameters:

  • writer: target writer; if NULL, returns the byte size only without writing.

Return Value: Number of bytes written (or file size if writer is NULL).

Usage Instruction: Use to materialize a drag-out file's bytes into a writer stream.

Threading Constraint: Any thread.

bool GetFileNames(std::vector<CefString>& names)

Return Value: Drag-in file names.

Threading Constraint: Threading constraint not specified in source.

bool GetFilePaths(std::vector<CefString>& paths)

Return Value: Drag-in full file paths.

Threading Constraint: Threading constraint not specified in source.

void AddFile(const CefString& path, const CefString& display_name)

Return Value: Adds a file drag entry. display_name optional.

Threading Constraint: Threading constraint not specified in source.

void ClearFilenames()

Return Value: Clears the filename list.

Threading Constraint: Threading constraint not specified in source.

void ResetFileContents()

Return Value: Resets file contents; call before CefBrowserHost::DragTargetDragEnter() because the webview does not allow file-content drag-in.

Threading Constraint: Threading constraint not specified in source.

CefRefPtr<CefImage> GetImage()

Return Value: Image representation, or NULL if none.

Threading Constraint: Threading constraint not specified in source.

CefPoint GetImageHotspot()

Return Value: Drag start location relative to image dimensions.

Threading Constraint: Threading constraint not specified in source.

bool HasImage()

Return Value: True if an image representation is available.

Threading Constraint: Threading constraint not specified in source.

Usage Example

cpp
// INSPECT incoming drag (CefDragHandler::OnDragEnter):
bool OnDragEnter(CefRefPtr<CefBrowser> browser,
                 CefRefPtr<CefDragData> dragData,
                 CefDragHandler::DragOperationsMask mask) override {
  if (dragData->IsLink()) {
    CefString url = dragData->GetLinkURL();
    CefString title = dragData->GetLinkTitle();
  }
  if (dragData->IsFile()) {
    std::vector<CefString> paths;
    dragData->GetFilePaths(paths);
  }
  return false;  // allow default drop
}

// SYNTHESIZE a drag for DragTargetDragEnter:
CefRefPtr<CefDragData> data = CefDragData::Create();
data->SetLinkURL("https://example.com");
data->SetLinkTitle("Example");
CefBrowserHost::DragTargetDragEnter(browser, data, ...);

Derived from the CEF C++ headers — © Marshall A. Greenblatt, Google Inc. & contributors (BSD-style license). Not an official CEF project.