From c94d335b6b4bb2c94b877ca155896211d35a2363 Mon Sep 17 00:00:00 2001 From: Matej Knopp Date: Thu, 28 Sep 2023 21:05:55 +0200 Subject: [PATCH] [macOS] FlutterTextInputPlugin should clip to bounds (flutter/engine#46142) Fixes https://github.com/flutter/flutter/issues/135219 (formerly https://github.com/flutter/flutter/issues/128956) [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- .../darwin/macos/framework/Source/FlutterTextInputPlugin.h | 5 +++++ .../darwin/macos/framework/Source/FlutterTextInputPlugin.mm | 1 + .../macos/framework/Source/FlutterTextInputPluginTest.mm | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.h b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.h index dedfc66188..70a8ff5156 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.h +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.h @@ -9,6 +9,11 @@ @class FlutterTextField; +@interface NSView (ClipsToBounds) +// This property is available since macOS 10.9 but only declared in macOS 14 SDK. +@property BOOL clipsToBounds API_AVAILABLE(macos(10.9)); +@end + /** * A plugin to handle text input. * diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm index f6460f2309..1d195efe26 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm @@ -342,6 +342,7 @@ static char markerKey; // The view needs an empty frame otherwise it is visible on dark background. // https://github.com/flutter/flutter/issues/118504 self = [super initWithFrame:NSZeroRect]; + self.clipsToBounds = YES; if (self != nil) { _flutterViewController = viewController; _channel = [FlutterMethodChannel methodChannelWithName:kTextInputChannel diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm index 00bbb68dc6..9c656c0ca9 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputPluginTest.mm @@ -1962,7 +1962,7 @@ TEST(FlutterTextInputPluginTest, IsAddedAndRemovedFromViewHierarchy) { ASSERT_FALSE(window.firstResponder == viewController.textInputPlugin); } -TEST(FlutterTextInputPluginTest, HasZeroSize) { +TEST(FlutterTextInputPluginTest, HasZeroSizeAndClipsToBounds) { id engineMock = flutter::testing::CreateMockFlutterEngine(@""); id binaryMessengerMock = OCMProtocolMock(@protocol(FlutterBinaryMessenger)); OCMStub( // NOLINT(google-objc-avoid-throwing-exception) @@ -1977,6 +1977,7 @@ TEST(FlutterTextInputPluginTest, HasZeroSize) { [[FlutterTextInputPlugin alloc] initWithViewController:viewController]; ASSERT_TRUE(NSIsEmptyRect(plugin.frame)); + ASSERT_TRUE(plugin.clipsToBounds); } } // namespace flutter::testing