未验证 提交 a6b71ac4 编写于 作者: M Matej Knopp 提交者: GitHub

Fix accent popup position (#25524)

上级 2db8af2d
......@@ -29,4 +29,5 @@
// Private methods made visible for testing
@interface FlutterTextInputPlugin (TestMethods)
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result;
- (NSRect)firstRectForCharacterRange:(NSRange)range actualRange:(NSRangePointer)actualRange;
@end
......@@ -21,6 +21,8 @@ static NSString* const kShowMethod = @"TextInput.show";
static NSString* const kHideMethod = @"TextInput.hide";
static NSString* const kClearClientMethod = @"TextInput.clearClient";
static NSString* const kSetEditingStateMethod = @"TextInput.setEditingState";
static NSString* const kSetEditableSizeAndTransform = @"TextInput.setEditableSizeAndTransform";
static NSString* const kSetCaretRect = @"TextInput.setCaretRect";
static NSString* const kUpdateEditStateResponseMethod = @"TextInputClient.updateEditingState";
static NSString* const kPerformAction = @"TextInputClient.performAction";
static NSString* const kMultilineInputType = @"TextInputType.multiline";
......@@ -39,6 +41,7 @@ static NSString* const kSelectionIsDirectionalKey = @"selectionIsDirectional";
static NSString* const kComposingBaseKey = @"composingBase";
static NSString* const kComposingExtentKey = @"composingExtent";
static NSString* const kTextKey = @"text";
static NSString* const kTransformKey = @"transform";
/**
* The affinity of the current cursor position. If the cursor is at a position representing
......@@ -163,6 +166,8 @@ static flutter::TextRange RangeFromBaseExtent(NSNumber* base,
_textInputContext = [[NSTextInputContext alloc] initWithClient:self];
_previouslyPressedFlags = 0;
_flutterViewController = viewController;
// Initialize with the zero matrix which is not
// an affine transform.
_editableTransform = CATransform3D();
......@@ -215,10 +220,10 @@ static flutter::TextRange RangeFromBaseExtent(NSNumber* base,
// engine since it sent this update, and needs to now be made to match the
// engine's version of the state.
[self updateEditState];
} else if ([method isEqualToString:@"TextInput.setEditableSizeAndTransform"]) {
} else if ([method isEqualToString:kSetEditableSizeAndTransform]) {
NSDictionary* state = call.arguments;
[self setEditableTransform:state[@"transform"]];
} else if ([method isEqualToString:@"TextInput.setCaretRect"]) {
[self setEditableTransform:state[kTransformKey]];
} else if ([method isEqualToString:kSetCaretRect]) {
NSDictionary* rect = call.arguments;
[self updateCaretRect:rect];
} else {
......@@ -462,9 +467,10 @@ static flutter::TextRange RangeFromBaseExtent(NSNumber* base,
CGRect rect =
CGRectApplyAffineTransform(_caretRect, CATransform3DGetAffineTransform(_editableTransform));
// flip and convert to screen coordinates
double viewHeight = self.flutterViewController.view.bounds.size.height;
rect.origin.y = viewHeight - rect.origin.y;
// convert to window coordinates
rect = [self.flutterViewController.view convertRect:rect toView:nil];
// convert to screen coordinates
return [self.flutterViewController.view.window convertRectToScreen:rect];
} else {
return CGRectZero;
......
......@@ -81,6 +81,80 @@
return true;
}
- (bool)testFirstRectForCharacterRange {
id engineMock = OCMClassMock([FlutterEngine class]);
id binaryMessengerMock = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
OCMStub( // NOLINT(google-objc-avoid-throwing-exception)
[engineMock binaryMessenger])
.andReturn(binaryMessengerMock);
id controllerMock = OCMClassMock([FlutterViewController class]);
OCMStub( // NOLINT(google-objc-avoid-throwing-exception)
[controllerMock engine])
.andReturn(engineMock);
id viewMock = OCMClassMock([NSView class]);
OCMStub( // NOLINT(google-objc-avoid-throwing-exception)
[viewMock bounds])
.andReturn(NSMakeRect(0, 0, 200, 200));
OCMStub( // NOLINT(google-objc-avoid-throwing-exception)
[controllerMock view])
.andReturn(viewMock);
id windowMock = OCMClassMock([NSWindow class]);
OCMStub( // NOLINT(google-objc-avoid-throwing-exception)
[viewMock window])
.andReturn(windowMock);
OCMExpect( // NOLINT(google-objc-avoid-throwing-exception)
[viewMock convertRect:NSMakeRect(28, 10, 2, 19) toView:nil])
.andReturn(NSMakeRect(28, 10, 2, 19));
OCMExpect( // NOLINT(google-objc-avoid-throwing-exception)
[windowMock convertRectToScreen:NSMakeRect(28, 10, 2, 19)])
.andReturn(NSMakeRect(38, 20, 2, 19));
FlutterTextInputPlugin* plugin =
[[FlutterTextInputPlugin alloc] initWithViewController:controllerMock];
FlutterMethodCall* call = [FlutterMethodCall
methodCallWithMethodName:@"TextInput.setEditableSizeAndTransform"
arguments:@{
@"height" : @(20.0),
@"transform" : @[
@(1.0), @(0.0), @(0.0), @(0.0), @(0.0), @(1.0), @(0.0), @(0.0), @(0.0),
@(0.0), @(1.0), @(0.0), @(20.0), @(10.0), @(0.0), @(1.0)
],
@"width" : @(400.0),
}];
[plugin handleMethodCall:call
result:^(id){
}];
call = [FlutterMethodCall methodCallWithMethodName:@"TextInput.setCaretRect"
arguments:@{
@"height" : @(19.0),
@"width" : @(2.0),
@"x" : @(8.0),
@"y" : @(0.0),
}];
[plugin handleMethodCall:call
result:^(id){
}];
NSRect rect = [plugin firstRectForCharacterRange:NSMakeRange(0, 0) actualRange:nullptr];
@try {
OCMVerify( // NOLINT(google-objc-avoid-throwing-exception)
[windowMock convertRectToScreen:NSMakeRect(28, 10, 2, 19)]);
} @catch (...) {
return false;
}
return NSEqualRects(rect, NSMakeRect(38, 20, 2, 19));
}
@end
namespace flutter::testing {
......@@ -89,4 +163,8 @@ TEST(FlutterTextInputPluginTest, TestEmptyCompositionRange) {
ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testEmptyCompositionRange]);
}
TEST(FlutterTextInputPluginTest, TestFirstRectForCharacterRange) {
ASSERT_TRUE([[FlutterInputPluginTestObjc alloc] testFirstRectForCharacterRange]);
}
} // namespace flutter::testing
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册