From 0abb1665f57b3fda8c7c498cf988122252f11ff3 Mon Sep 17 00:00:00 2001 From: jslavitz Date: Thu, 13 Dec 2018 18:45:38 -0800 Subject: [PATCH] Adds force cursor support (flutter/engine#6945) * engine force cursor support --- .../ios/framework/Source/FlutterEngine.mm | 19 +++++++++++++++++++ .../Source/FlutterTextInputDelegate.h | 9 +++++++++ .../Source/FlutterTextInputPlugin.mm | 18 ++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index c5f3b8d9ac..09a7dd0277 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -373,6 +373,25 @@ arguments:@[ @(client), state ]]; } +- (void)updateFloatingCursor:(FlutterFloatingCursorDragState)state + withClient:(int)client + withPosition:(NSDictionary*)position { + NSString* stateString; + switch (state) { + case FlutterFloatingCursorDragStateStart: + stateString = @"FloatingCursorDragState.start"; + break; + case FlutterFloatingCursorDragStateUpdate: + stateString = @"FloatingCursorDragState.update"; + break; + case FlutterFloatingCursorDragStateEnd: + stateString = @"FloatingCursorDragState.end"; + break; + } + [_textInputChannel.get() invokeMethod:@"TextInputClient.updateFloatingCursor" + arguments:@[ @(client), stateString, position ]]; +} + - (void)performAction:(FlutterTextInputAction)action withClient:(int)client { NSString* actionString; switch (action) { diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputDelegate.h b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputDelegate.h index 11e9f5bd5f..d3451b5bd4 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputDelegate.h +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputDelegate.h @@ -21,10 +21,19 @@ typedef NS_ENUM(NSInteger, FlutterTextInputAction) { FlutterTextInputActionNewline, }; +typedef NS_ENUM(NSInteger, FlutterFloatingCursorDragState) { + FlutterFloatingCursorDragStateStart, + FlutterFloatingCursorDragStateUpdate, + FlutterFloatingCursorDragStateEnd, +}; + @protocol FlutterTextInputDelegate - (void)updateEditingClient:(int)client withState:(NSDictionary*)state; - (void)performAction:(FlutterTextInputAction)action withClient:(int)client; +- (void)updateFloatingCursor:(FlutterFloatingCursorDragState)state + withClient:(int)client + withPosition:(NSDictionary*)point; @end diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm index 0f7dc0a0d6..a50d7b4e51 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm @@ -566,6 +566,24 @@ static UIReturnKeyType ToUIReturnKeyType(NSString* inputType) { return [FlutterTextRange rangeWithNSRange:[self rangeForCharacterAtIndex:currentIndex]]; } +- (void)beginFloatingCursorAtPoint:(CGPoint)point { + [_textInputDelegate updateFloatingCursor:FlutterFloatingCursorDragStateStart + withClient:_textInputClient + withPosition:@{@"X" : @(point.x), @"Y" : @(point.y)}]; +} + +- (void)updateFloatingCursorAtPoint:(CGPoint)point { + [_textInputDelegate updateFloatingCursor:FlutterFloatingCursorDragStateUpdate + withClient:_textInputClient + withPosition:@{@"X" : @(point.x), @"Y" : @(point.y)}]; +} + +- (void)endFloatingCursor { + [_textInputDelegate updateFloatingCursor:FlutterFloatingCursorDragStateEnd + withClient:_textInputClient + withPosition:@{@"X" : @(0), @"Y" : @(0)}]; +} + #pragma mark - UIKeyInput Overrides - (void)updateEditingState {