Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions shell/platform/darwin/macos/framework/Source/FLEViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

namespace {

/// Clipboard plain text format.
constexpr char kTextPlainFormat[] = "text/plain";

/**
* State tracking for mouse events, to adapt between the events coming from the system and the
* events that the embedding API expects.
Expand Down Expand Up @@ -156,6 +159,18 @@ - (void)onSettingsChanged:(NSNotification*)notification;
*/
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result;

/**
* Reads the data from the clipboard. |format| specifies the media type of the
* data to obtain.
*/
- (NSDictionary*)getClipboardData:(NSString*)format;

/**
* Clears contents and writes new data into clipboard. |data| is a dictionary where
* the keys are the type of data, and tervalue the data to be stored.
*/
- (void)setClipboardData:(NSDictionary*)data;

@end

#pragma mark - Static methods provided to engine configuration
Expand Down Expand Up @@ -612,11 +627,34 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
if ([call.method isEqualToString:@"SystemNavigator.pop"]) {
[NSApp terminate:self];
result(nil);
} else if ([call.method isEqualToString:@"Clipboard.getData"]) {
result([self getClipboardData:call.arguments]);
} else if ([call.method isEqualToString:@"Clipboard.setData"]) {
[self setClipboardData:call.arguments];
result(nil);
} else {
result(FlutterMethodNotImplemented);
}
}

- (NSDictionary*)getClipboardData:(NSString*)format {
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
if ([format isEqualToString:@(kTextPlainFormat)]) {
NSString* stringInPasteboard = [pasteboard stringForType:NSPasteboardTypeString];
return stringInPasteboard == nil ? nil : @{@"text" : stringInPasteboard};
}
return nil;
}

- (void)setClipboardData:(NSDictionary*)data {
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
NSString* text = data[@"text"];
if (text && ![text isEqual:[NSNull null]]) {
[pasteboard clearContents];
[pasteboard setString:text forType:NSPasteboardTypeString];
}
}

#pragma mark - FLEReshapeListener

/**
Expand Down