SystemClipboard Class

The system clipboard (https://w3c.github.io/clipboard-apis/#system-clipboard) of the browsing contexts that share a BrowsingContextOptions: the data of the copy and cut actions, of navigator.clipboard.write() and writeText(), read by the paste action, read() and readText(). The default implementation keeps the data in memory: the application can read and replace it to observe or simulate what the user copies. Override SystemClipboard.Items, SystemClipboard.ChangeCount and SystemClipboard.Write to use another clipboard (e.g. the clipboard of the operating system), and call SystemClipboard.OnChanged when it is changed by another application.

public class SystemClipboard

Remarks

The names of the representations are the formats of the clipboard of Linux, ChromeOS and Android (https://w3c.github.io/clipboard-apis/#os-specific-well-known-format): the MIME types text/plain, text/html, image/png and image/svg+xml, and for the web custom formats, application/web;type="custom/formatmap" (a JSON object mapping each MIME type to its format) and application/web;type="custom/format0", application/web;type="custom/format1"... The data written by the DataTransfer of a copy event with other types is stored under these types.

Constructors

NameDescription
SystemClipboard()

SystemClipboard()

SystemClipboard.cs
public SystemClipboard()

No documentation is available.

Properties

NameDescription
ChangeCountGets the clipboard change count (https://w3c.github.io/clipboard-apis/#clipboard-change-count): a value that changes each time the data is modified.
ItemsGets the system clipboard items (https://w3c.github.io/clipboard-apis/#system-clipboard-data).

Gets the clipboard change count (https://w3c.github.io/clipboard-apis/#clipboard-change-count): a value that changes each time the data is modified.

public virtual long ChangeCount { get; }

Property value

long

Gets the system clipboard items (https://w3c.github.io/clipboard-apis/#system-clipboard-data).

public virtual IReadOnlyList<SystemClipboardItem> Items { get; }

Methods

NameDescription
Clear()Clears the clipboard.
OnChanged()Raises SystemClipboard.Changed, then fires the clipboardchange events of the documents. It must be called on the thread of the event loop of the browsing contexts.
ReadText()Returns the plain text of the clipboard (the first text/plain representation, decoded as UTF-8), or null when there is none.
Write(IReadOnlyList<SystemClipboardItem>)Replaces the data of the clipboard, then raises SystemClipboard.Changed. An override must call SystemClipboard.OnChanged when the data changed.
WriteText(string)Replaces the data of the clipboard with a plain text representation (text/plain, UTF-8 encoded).

Clears the clipboard.

public void Clear()

Raises SystemClipboard.Changed, then fires the clipboardchange events of the documents. It must be called on the thread of the event loop of the browsing contexts.

protected void OnChanged()

Returns the plain text of the clipboard (the first text/plain representation, decoded as UTF-8), or null when there is none.

public string? ReadText()

Returns

string?

Write(IReadOnlyList<SystemClipboardItem>)

SystemClipboard.cs

Replaces the data of the clipboard, then raises SystemClipboard.Changed. An override must call SystemClipboard.OnChanged when the data changed.

public virtual void Write(IReadOnlyList<SystemClipboardItem> items)

WriteText(string)

SystemClipboard.cs

Replaces the data of the clipboard with a plain text representation (text/plain, UTF-8 encoded).

public void WriteText(string text)

Parameters

text string

Events

NameDescription
ChangedRaised when the data of the clipboard changes (SystemClipboard.OnChanged), e.g. to fire the clipboardchange events.

Changed

Raised when the data of the clipboard changes (SystemClipboard.OnChanged), e.g. to fire the clipboardchange events.

public event EventHandler? Changed

Constants

NameDescription
WebCustomFormatMapNameThe name of the representation of the web custom format map (https://w3c.github.io/clipboard-apis/#os-specific-custom-map-name).
WebCustomFormatNameThe prefix of the names of the representations of the web custom formats (https://w3c.github.io/clipboard-apis/#os-specific-custom-name).

WebCustomFormatMapName

The name of the representation of the web custom format map (https://w3c.github.io/clipboard-apis/#os-specific-custom-map-name).

public const string WebCustomFormatMapName = "application/web;type=\"custom/formatmap\""

WebCustomFormatName

The prefix of the names of the representations of the web custom formats (https://w3c.github.io/clipboard-apis/#os-specific-custom-name).

public const string WebCustomFormatName = "application/web;type=\"custom/format"