From f5a7a086ec8d5aeaf2abd9bf3f7f4e0f3320837e Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Tue, 11 Apr 2017 15:14:00 -0700 Subject: [PATCH] Update Objective-C column limit to 100 (#3585) The Google style guide specifies a limit of 100 columns. https://google.github.io/styleguide/objcguide.xml?showone=Line_Length#Line_Length The Chromium style guide specifies 80. https://chromium.googlesource.com/chromium/src/+/master/styleguide/objective-c/objective-c.md --- .clang-format | 3 + fml/platform/darwin/message_loop_darwin.mm | 21 ++- fml/platform/darwin/paths_darwin.mm | 3 +- .../darwin/resource_mapping_darwin.mm | 4 +- shell/platform/darwin/common/platform_mac.mm | 48 +++---- .../platform/darwin/desktop/flutter_window.mm | 38 +++-- shell/platform/darwin/desktop/main_mac.mm | 3 +- .../darwin/desktop/platform_view_mac.mm | 40 +++--- .../framework/Source/FlutterAppDelegate.mm | 5 +- .../ios/framework/Source/FlutterChannels.mm | 126 ++++++---------- .../ios/framework/Source/FlutterCodecs.mm | 18 +-- .../framework/Source/FlutterDartProject.mm | 65 ++++----- .../ios/framework/Source/FlutterDartSource.mm | 13 +- .../framework/Source/FlutterPlatformPlugin.mm | 27 ++-- .../framework/Source/FlutterStandardCodec.mm | 64 +++------ .../Source/FlutterTextInputPlugin.mm | 3 +- .../ios/framework/Source/FlutterView.mm | 10 +- .../framework/Source/FlutterViewController.mm | 136 ++++++++---------- .../framework/Source/accessibility_bridge.mm | 38 ++--- .../Source/flutter_codecs_unittest.mm | 11 +- .../ios/framework/Source/flutter_main_ios.mm | 6 +- .../Source/flutter_standard_codec_unittest.mm | 81 ++++------- .../Source/platform_message_router.mm | 8 +- .../ios/framework/Source/vsync_waiter_ios.mm | 8 +- shell/platform/darwin/ios/ios_gl_context.mm | 50 +++---- shell/platform/darwin/ios/ios_surface.mm | 11 +- shell/platform/darwin/ios/ios_surface_gl.mm | 3 +- .../darwin/ios/ios_surface_software.mm | 8 +- .../platform/darwin/ios/platform_view_ios.mm | 19 +-- 29 files changed, 333 insertions(+), 537 deletions(-) diff --git a/.clang-format b/.clang-format index 780d1a2d1ea08..3c73f32a33408 100644 --- a/.clang-format +++ b/.clang-format @@ -7,3 +7,6 @@ BasedOnStyle: Chromium # 'int>>' if the file already contains at least one such instance.) Standard: Cpp11 SortIncludes: true +--- +Language: ObjC +ColumnLimit: 100 diff --git a/fml/platform/darwin/message_loop_darwin.mm b/fml/platform/darwin/message_loop_darwin.mm index 90977a8b560c6..0f61c661120d5 100644 --- a/fml/platform/darwin/message_loop_darwin.mm +++ b/fml/platform/darwin/message_loop_darwin.mm @@ -19,12 +19,12 @@ CFRunLoopTimerContext timer_context = { .info = this, }; - delayed_wake_timer_.Reset(CFRunLoopTimerCreate( - kCFAllocatorDefault, kDistantFuture /* fire date */, - HUGE_VAL /* interval */, 0 /* flags */, 0 /* order */, - reinterpret_cast(&MessageLoopDarwin::OnTimerFire) - /* callout */, - &timer_context /* context */)); + delayed_wake_timer_.Reset( + CFRunLoopTimerCreate(kCFAllocatorDefault, kDistantFuture /* fire date */, + HUGE_VAL /* interval */, 0 /* flags */, 0 /* order */, + reinterpret_cast(&MessageLoopDarwin::OnTimerFire) + /* callout */, + &timer_context /* context */)); FTL_DCHECK(delayed_wake_timer_ != nullptr); CFRunLoopAddTimer(loop_, delayed_wake_timer_, kCFRunLoopCommonModes); } @@ -41,8 +41,7 @@ while (running_) { @autoreleasepool { - int result = - CFRunLoopRunInMode(kCFRunLoopDefaultMode, kDistantFuture, YES); + int result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, kDistantFuture, YES); if (result == kCFRunLoopRunStopped || result == kCFRunLoopRunFinished) { // This handles the case where the loop is terminated using // CoreFoundation APIs. @@ -65,12 +64,10 @@ // different and must be accounted for. CFRunLoopTimerSetNextFireDate( delayed_wake_timer_, - CFAbsoluteTimeGetCurrent() + - (time_point - ftl::TimePoint::Now()).ToSecondsF()); + CFAbsoluteTimeGetCurrent() + (time_point - ftl::TimePoint::Now()).ToSecondsF()); } -void MessageLoopDarwin::OnTimerFire(CFRunLoopTimerRef timer, - MessageLoopDarwin* loop) { +void MessageLoopDarwin::OnTimerFire(CFRunLoopTimerRef timer, MessageLoopDarwin* loop) { @autoreleasepool { // RunExpiredTasksNow rearms the timer as appropriate via a call to WakeUp. loop->RunExpiredTasksNow(); diff --git a/fml/platform/darwin/paths_darwin.mm b/fml/platform/darwin/paths_darwin.mm index de8c9102f93a6..eea87ffd4970e 100644 --- a/fml/platform/darwin/paths_darwin.mm +++ b/fml/platform/darwin/paths_darwin.mm @@ -12,8 +12,7 @@ namespace paths { std::pair GetExecutableDirectoryPath() { - return {true, files::GetDirectoryName( - [NSBundle mainBundle].executablePath.UTF8String)}; + return {true, files::GetDirectoryName([NSBundle mainBundle].executablePath.UTF8String)}; } } // namespace paths diff --git a/fml/platform/darwin/resource_mapping_darwin.mm b/fml/platform/darwin/resource_mapping_darwin.mm index 03d31840f2c04..5d1b9664e20bc 100644 --- a/fml/platform/darwin/resource_mapping_darwin.mm +++ b/fml/platform/darwin/resource_mapping_darwin.mm @@ -9,8 +9,8 @@ namespace fml { ResourceMappingDarwin::ResourceMappingDarwin(const std::string& resource) - : actual_([[[NSBundle mainBundle] pathForResource:@(resource.c_str()) - ofType:nil] UTF8String]) {} + : actual_([[[NSBundle mainBundle] pathForResource:@(resource.c_str()) ofType:nil] UTF8String]) { +} ResourceMappingDarwin::~ResourceMappingDarwin() = default; diff --git a/shell/platform/darwin/common/platform_mac.mm b/shell/platform/darwin/common/platform_mac.mm index bcf402a975dc7..a53d54623f7c6 100644 --- a/shell/platform/darwin/common/platform_mac.mm +++ b/shell/platform/darwin/common/platform_mac.mm @@ -20,17 +20,14 @@ namespace shell { -static void RedirectIOConnectionsToSyslog( - const ftl::CommandLine& command_line) { +static void RedirectIOConnectionsToSyslog(const ftl::CommandLine& command_line) { #if TARGET_OS_IPHONE if (command_line.HasOption(FlagForSwitch(Switch::NoRedirectToSyslog))) { return; } - asl_log_descriptor(NULL, NULL, ASL_LEVEL_NOTICE, STDOUT_FILENO, - ASL_LOG_DESCRIPTOR_WRITE); - asl_log_descriptor(NULL, NULL, ASL_LEVEL_WARNING, STDERR_FILENO, - ASL_LOG_DESCRIPTOR_WRITE); + asl_log_descriptor(NULL, NULL, ASL_LEVEL_NOTICE, STDOUT_FILENO, ASL_LOG_DESCRIPTOR_WRITE); + asl_log_descriptor(NULL, NULL, ASL_LEVEL_WARNING, STDERR_FILENO, ASL_LOG_DESCRIPTOR_WRITE); #endif } @@ -46,8 +43,7 @@ static void RedirectIOConnectionsToSyslog( class EmbedderState { public: - EmbedderState(std::string icu_data_path, - std::string application_library_path) { + EmbedderState(std::string icu_data_path, std::string application_library_path) { #if TARGET_OS_IPHONE // This calls crashes on MacOS because we haven't run Dart_Initialize yet. // See https://github.com/flutter/flutter/issues/4006 @@ -64,8 +60,7 @@ static void RedirectIOConnectionsToSyslog( // marker that can be used as a reference for startup. TRACE_EVENT_INSTANT0("flutter", "main"); - shell::Shell::InitStandalone(std::move(command_line), icu_data_path, - application_library_path); + shell::Shell::InitStandalone(std::move(command_line), icu_data_path, application_library_path); } ~EmbedderState() {} @@ -74,14 +69,12 @@ static void RedirectIOConnectionsToSyslog( FTL_DISALLOW_COPY_AND_ASSIGN(EmbedderState); }; -void PlatformMacMain(std::string icu_data_path, - std::string application_library_path) { +void PlatformMacMain(std::string icu_data_path, std::string application_library_path) { static std::unique_ptr g_embedder; static std::once_flag once_main; std::call_once(once_main, [&]() { - g_embedder = - WTF::MakeUnique(icu_data_path, application_library_path); + g_embedder = WTF::MakeUnique(icu_data_path, application_library_path); }); } @@ -150,12 +143,9 @@ bool AttemptLaunchFromCommandLineSwitches(Engine* engine) { [defaults synchronize]; } - std::string bundle_path = - ResolveCommandLineLaunchFlag(FlagForSwitch(Switch::FLX)); - std::string main = - ResolveCommandLineLaunchFlag(FlagForSwitch(Switch::MainDartFile)); - std::string packages = - ResolveCommandLineLaunchFlag(FlagForSwitch(Switch::Packages)); + std::string bundle_path = ResolveCommandLineLaunchFlag(FlagForSwitch(Switch::FLX)); + std::string main = ResolveCommandLineLaunchFlag(FlagForSwitch(Switch::MainDartFile)); + std::string packages = ResolveCommandLineLaunchFlag(FlagForSwitch(Switch::Packages)); if (!FlagsValidForCommandLineLaunch(bundle_path, main, packages)) { return false; @@ -164,20 +154,16 @@ bool AttemptLaunchFromCommandLineSwitches(Engine* engine) { // Save the newly resolved dart main file and the package root to user // defaults so that the next time the user launches the application in the // simulator without the tooling, the application boots up. - [defaults setObject:@(bundle_path.c_str()) - forKey:@(FlagForSwitch(Switch::FLX))]; - [defaults setObject:@(main.c_str()) - forKey:@(FlagForSwitch(Switch::MainDartFile))]; - [defaults setObject:@(packages.c_str()) - forKey:@(FlagForSwitch(Switch::Packages))]; + [defaults setObject:@(bundle_path.c_str()) forKey:@(FlagForSwitch(Switch::FLX))]; + [defaults setObject:@(main.c_str()) forKey:@(FlagForSwitch(Switch::MainDartFile))]; + [defaults setObject:@(packages.c_str()) forKey:@(FlagForSwitch(Switch::Packages))]; [defaults synchronize]; - blink::Threads::UI()->PostTask( - [ engine = engine->GetWeakPtr(), bundle_path, main, packages ] { - if (engine) - engine->RunBundleAndSource(bundle_path, main, packages); - }); + blink::Threads::UI()->PostTask([ engine = engine->GetWeakPtr(), bundle_path, main, packages ] { + if (engine) + engine->RunBundleAndSource(bundle_path, main, packages); + }); return true; } diff --git a/shell/platform/darwin/desktop/flutter_window.mm b/shell/platform/darwin/desktop/flutter_window.mm index 5c6397d02450a..6c40730d1f705 100644 --- a/shell/platform/darwin/desktop/flutter_window.mm +++ b/shell/platform/darwin/desktop/flutter_window.mm @@ -15,8 +15,7 @@ @interface FlutterWindow () @end -static inline blink::PointerData::Change PointerChangeFromNSEventPhase( - NSEventPhase phase) { +static inline blink::PointerData::Change PointerChangeFromNSEventPhase(NSEventPhase phase) { switch (phase) { case NSEventPhaseNone: return blink::PointerData::Change::kCancel; @@ -54,13 +53,11 @@ - (void)awakeFromNib { } - (void)setupPlatformView { - FTL_DCHECK(_platformView == nullptr) - << "The platform view must not already be set."; + FTL_DCHECK(_platformView == nullptr) << "The platform view must not already be set."; _platformView.reset(new shell::PlatformViewMac(self.renderSurface)); _platformView->SetupResourceContextOnIOThread(); - _platformView->NotifyCreated( - std::make_unique(_platformView.get())); + _platformView->NotifyCreated(std::make_unique(_platformView.get())); } // TODO(eseidel): This does not belong in flutter_window! @@ -81,12 +78,11 @@ - (void)updateWindowSize { metrics.physical_width = size.width; metrics.physical_height = size.height; - blink::Threads::UI()->PostTask( - [ engine = _platformView->engine().GetWeakPtr(), metrics ] { - if (engine.get()) { - engine->SetViewportMetrics(metrics); - } - }); + blink::Threads::UI()->PostTask([ engine = _platformView->engine().GetWeakPtr(), metrics ] { + if (engine.get()) { + engine->SetViewportMetrics(metrics); + } + }); } - (void)setupSurfaceIfNecessary { @@ -103,8 +99,7 @@ - (void)setupSurfaceIfNecessary { #pragma mark - Responder overrides - (void)dispatchEvent:(NSEvent*)event phase:(NSEventPhase)phase { - NSPoint location = - [_renderSurface convertPoint:event.locationInWindow fromView:nil]; + NSPoint location = [_renderSurface convertPoint:event.locationInWindow fromView:nil]; location.y = _renderSurface.frame.size.height - location.y; blink::PointerData pointer_data; @@ -138,14 +133,13 @@ - (void)dispatchEvent:(NSEvent*)event phase:(NSEventPhase)phase { break; } - blink::Threads::UI()->PostTask( - [ engine = _platformView->engine().GetWeakPtr(), pointer_data ] { - if (engine.get()) { - blink::PointerDataPacket packet(1); - packet.SetPointerData(0, pointer_data); - engine->DispatchPointerDataPacket(packet); - } - }); + blink::Threads::UI()->PostTask([ engine = _platformView->engine().GetWeakPtr(), pointer_data ] { + if (engine.get()) { + blink::PointerDataPacket packet(1); + packet.SetPointerData(0, pointer_data); + engine->DispatchPointerDataPacket(packet); + } + }); } - (void)mouseDown:(NSEvent*)event { diff --git a/shell/platform/darwin/desktop/main_mac.mm b/shell/platform/darwin/desktop/main_mac.mm index 49553c8511484..24a55f3495908 100644 --- a/shell/platform/darwin/desktop/main_mac.mm +++ b/shell/platform/darwin/desktop/main_mac.mm @@ -27,8 +27,7 @@ int main(int argc, const char* argv[]) { } // Decide between interactive and non-interactive modes. - if (command_line.HasOption( - shell::FlagForSwitch(shell::Switch::NonInteractive))) { + if (command_line.HasOption(shell::FlagForSwitch(shell::Switch::NonInteractive))) { if (!shell::InitForTesting(std::move(command_line))) return 1; fml::MessageLoop::GetCurrent().Run(); diff --git a/shell/platform/darwin/desktop/platform_view_mac.mm b/shell/platform/darwin/desktop/platform_view_mac.mm index cb5b6e41ea8d5..9c6528cd7c526 100644 --- a/shell/platform/darwin/desktop/platform_view_mac.mm +++ b/shell/platform/darwin/desktop/platform_view_mac.mm @@ -20,12 +20,10 @@ namespace shell { PlatformViewMac::PlatformViewMac(NSOpenGLView* gl_view) - : PlatformView( - std::make_unique(std::make_unique())), + : PlatformView(std::make_unique(std::make_unique())), opengl_view_([gl_view retain]), - resource_loading_context_([[NSOpenGLContext alloc] - initWithFormat:gl_view.pixelFormat - shareContext:gl_view.openGLContext]) { + resource_loading_context_([[NSOpenGLContext alloc] initWithFormat:gl_view.pixelFormat + shareContext:gl_view.openGLContext]) { CreateEngine(); PostAddToShellTask(); } @@ -41,35 +39,31 @@ const auto& command_line = shell::Shell::Shared().GetCommandLine(); - std::string bundle_path = - command_line.GetOptionValueWithDefault(FlagForSwitch(Switch::FLX), ""); + std::string bundle_path = command_line.GetOptionValueWithDefault(FlagForSwitch(Switch::FLX), ""); if (!bundle_path.empty()) { - blink::Threads::UI()->PostTask( - [ engine = engine().GetWeakPtr(), bundle_path ] { - if (engine) - engine->RunBundle(bundle_path); - }); + blink::Threads::UI()->PostTask([ engine = engine().GetWeakPtr(), bundle_path ] { + if (engine) + engine->RunBundle(bundle_path); + }); return; } auto args = command_line.positional_args(); if (args.size() > 0) { std::string main = args[0]; - std::string packages = command_line.GetOptionValueWithDefault( - FlagForSwitch(Switch::Packages), ""); - blink::Threads::UI()->PostTask( - [ engine = engine().GetWeakPtr(), main, packages ] { - if (engine) - engine->RunBundleAndSource(std::string(), main, packages); - }); + std::string packages = + command_line.GetOptionValueWithDefault(FlagForSwitch(Switch::Packages), ""); + blink::Threads::UI()->PostTask([ engine = engine().GetWeakPtr(), main, packages ] { + if (engine) + engine->RunBundleAndSource(std::string(), main, packages); + }); return; } } -void PlatformViewMac::SetupAndLoadFromSource( - const std::string& assets_directory, - const std::string& main, - const std::string& packages) { +void PlatformViewMac::SetupAndLoadFromSource(const std::string& assets_directory, + const std::string& main, + const std::string& packages) { blink::Threads::UI()->PostTask( [ engine = engine().GetWeakPtr(), assets_directory, main, packages ] { if (engine) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm b/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm index 6af8ce942166d..20bde7589f9c9 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm @@ -10,15 +10,14 @@ @implementation FlutterAppDelegate // Returns the key window's rootViewController, if it's a FlutterViewController. // Otherwise, returns nil. - (FlutterViewController*)rootFlutterViewController { - UIViewController *viewController = - [UIApplication sharedApplication].keyWindow.rootViewController; + UIViewController* viewController = [UIApplication sharedApplication].keyWindow.rootViewController; if ([viewController isKindOfClass:[FlutterViewController class]]) { return (FlutterViewController*)viewController; } return nil; } -- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { +- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { [super touchesBegan:touches withEvent:event]; // Pass status bar taps to key window Flutter rootViewController. diff --git a/shell/platform/darwin/ios/framework/Source/FlutterChannels.mm b/shell/platform/darwin/ios/framework/Source/FlutterChannels.mm index db53870d0f82b..ed13168d410da 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterChannels.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterChannels.mm @@ -14,16 +14,13 @@ @implementation FlutterMessageChannel { + (instancetype)messageChannelWithName:(NSString*)name binaryMessenger:(NSObject*)messenger { NSObject* codec = [FlutterStandardMessageCodec sharedInstance]; - return [FlutterMessageChannel messageChannelWithName:name - binaryMessenger:messenger - codec:codec]; + return [FlutterMessageChannel messageChannelWithName:name binaryMessenger:messenger codec:codec]; } + (instancetype)messageChannelWithName:(NSString*)name binaryMessenger:(NSObject*)messenger codec:(NSObject*)codec { - return [[[FlutterMessageChannel alloc] initWithName:name - binaryMessenger:messenger - codec:codec] autorelease]; + return [[[FlutterMessageChannel alloc] initWithName:name binaryMessenger:messenger codec:codec] + autorelease]; } - (instancetype)initWithName:(NSString*)name @@ -60,8 +57,7 @@ - (void)sendMessage:(id)message replyHandler:(FlutterReplyHandler)handler { - (void)setMessageHandler:(FlutterMessageHandler)handler { if (!handler) { - [_messenger setBinaryMessageHandlerOnChannel:_name - binaryMessageHandler:nil]; + [_messenger setBinaryMessageHandlerOnChannel:_name binaryMessageHandler:nil]; return; } FlutterBinaryMessageHandler messageHandler = @@ -70,25 +66,18 @@ - (void)setMessageHandler:(FlutterMessageHandler)handler { replyHandler([_codec encode:reply]); }); }; - [_messenger setBinaryMessageHandlerOnChannel:_name - binaryMessageHandler:messageHandler]; + [_messenger setBinaryMessageHandlerOnChannel:_name binaryMessageHandler:messageHandler]; } @end #pragma mark - Method channel @implementation FlutterError -+ (instancetype)errorWithCode:(NSString*)code - message:(NSString*)message - details:(id)details { - return - [[[FlutterError alloc] initWithCode:code message:message details:details] - autorelease]; ++ (instancetype)errorWithCode:(NSString*)code message:(NSString*)message details:(id)details { + return [[[FlutterError alloc] initWithCode:code message:message details:details] autorelease]; } -- (instancetype)initWithCode:(NSString*)code - message:(NSString*)message - details:(id)details { +- (instancetype)initWithCode:(NSString*)code message:(NSString*)message details:(id)details { NSAssert(code, @"Code cannot be nil"); self = [super init]; NSAssert(self, @"Super init cannot be nil"); @@ -112,10 +101,8 @@ - (BOOL)isEqual:(id)object { return NO; FlutterError* other = (FlutterError*)object; return [self.code isEqual:other.code] && - ((!self.message && !other.message) || - [self.message isEqual:other.message]) && - ((!self.details && !other.details) || - [self.details isEqual:other.details]); + ((!self.message && !other.message) || [self.message isEqual:other.message]) && + ((!self.details && !other.details) || [self.details isEqual:other.details]); } - (NSUInteger)hash { @@ -124,10 +111,8 @@ - (NSUInteger)hash { @end @implementation FlutterMethodCall -+ (instancetype)methodCallWithMethodName:(NSString*)method - arguments:(id)arguments { - return [[[FlutterMethodCall alloc] initWithMethodName:method - arguments:arguments] autorelease]; ++ (instancetype)methodCallWithMethodName:(NSString*)method arguments:(id)arguments { + return [[[FlutterMethodCall alloc] initWithMethodName:method arguments:arguments] autorelease]; } - (instancetype)initWithMethodName:(NSString*)method arguments:(id)arguments { @@ -152,8 +137,7 @@ - (BOOL)isEqual:(id)object { return NO; FlutterMethodCall* other = (FlutterMethodCall*)object; return [self.method isEqual:[other method]] && - ((!self.arguments && !other.arguments) || - [self.arguments isEqual:other.arguments]); + ((!self.arguments && !other.arguments) || [self.arguments isEqual:other.arguments]); } - (NSUInteger)hash { @@ -170,19 +154,16 @@ @implementation FlutterMethodChannel { } + (instancetype)methodChannelWithName:(NSString*)name - binaryMessenger:(NSObject*)messenger { + binaryMessenger:(NSObject*)messenger { NSObject* codec = [FlutterStandardMethodCodec sharedInstance]; - return [FlutterMethodChannel methodChannelWithName:name - binaryMessenger:messenger - codec:codec]; + return [FlutterMethodChannel methodChannelWithName:name binaryMessenger:messenger codec:codec]; } + (instancetype)methodChannelWithName:(NSString*)name - binaryMessenger:(NSObject*)messenger - codec:(NSObject*)codec { - return [[[FlutterMethodChannel alloc] initWithName:name - binaryMessenger:messenger - codec:codec] autorelease]; + binaryMessenger:(NSObject*)messenger + codec:(NSObject*)codec { + return [[[FlutterMethodChannel alloc] initWithName:name binaryMessenger:messenger codec:codec] + autorelease]; } - (instancetype)initWithName:(NSString*)name @@ -218,36 +199,29 @@ - (void)invokeMethod:(NSString*)method NSData* message = [_codec encodeMethodCall:methodCall]; FlutterBinaryReplyHandler replyHandler = ^(NSData* reply) { if (resultReceiver) { - resultReceiver((reply == nil) - ? FlutterMethodNotImplemented - : [_codec decodeEnvelope:reply]); + resultReceiver((reply == nil) ? FlutterMethodNotImplemented : [_codec decodeEnvelope:reply]); } }; - [_messenger sendBinaryMessage:message - channelName:_name - binaryReplyHandler:replyHandler]; + [_messenger sendBinaryMessage:message channelName:_name binaryReplyHandler:replyHandler]; } - (void)setMethodCallHandler:(FlutterMethodCallHandler)handler { if (!handler) { - [_messenger setBinaryMessageHandlerOnChannel:_name - binaryMessageHandler:nil]; + [_messenger setBinaryMessageHandlerOnChannel:_name binaryMessageHandler:nil]; return; } - FlutterBinaryMessageHandler messageHandler = - ^(NSData* message, FlutterBinaryReplyHandler reply) { - FlutterMethodCall* call = [_codec decodeMethodCall:message]; - handler(call, ^(id result) { - if (result == FlutterMethodNotImplemented) - reply(nil); - else if ([result isKindOfClass:[FlutterError class]]) - reply([_codec encodeErrorEnvelope:(FlutterError*)result]); - else - reply([_codec encodeSuccessEnvelope:result]); - }); - }; - [_messenger setBinaryMessageHandlerOnChannel:_name - binaryMessageHandler:messageHandler]; + FlutterBinaryMessageHandler messageHandler = ^(NSData* message, FlutterBinaryReplyHandler reply) { + FlutterMethodCall* call = [_codec decodeMethodCall:message]; + handler(call, ^(id result) { + if (result == FlutterMethodNotImplemented) + reply(nil); + else if ([result isKindOfClass:[FlutterError class]]) + reply([_codec encodeErrorEnvelope:(FlutterError*)result]); + else + reply([_codec encodeSuccessEnvelope:result]); + }); + }; + [_messenger setBinaryMessageHandlerOnChannel:_name binaryMessageHandler:messageHandler]; } @end @@ -261,19 +235,16 @@ @implementation FlutterEventChannel { NSObject* _codec; } + (instancetype)eventChannelWithName:(NSString*)name - binaryMessenger:(NSObject*)messenger { + binaryMessenger:(NSObject*)messenger { NSObject* codec = [FlutterStandardMethodCodec sharedInstance]; - return [FlutterEventChannel eventChannelWithName:name - binaryMessenger:messenger - codec:codec]; + return [FlutterEventChannel eventChannelWithName:name binaryMessenger:messenger codec:codec]; } + (instancetype)eventChannelWithName:(NSString*)name - binaryMessenger:(NSObject*)messenger - codec:(NSObject*)codec { - return [[[FlutterEventChannel alloc] initWithName:name - binaryMessenger:messenger - codec:codec] autorelease]; + binaryMessenger:(NSObject*)messenger + codec:(NSObject*)codec { + return [[[FlutterEventChannel alloc] initWithName:name binaryMessenger:messenger codec:codec] + autorelease]; } - (instancetype)initWithName:(NSString*)name @@ -289,25 +260,23 @@ - (instancetype)initWithName:(NSString*)name - (void)setStreamHandler:(NSObject*)handler { if (!handler) { - [_messenger setBinaryMessageHandlerOnChannel:_name - binaryMessageHandler:nil]; + [_messenger setBinaryMessageHandlerOnChannel:_name binaryMessageHandler:nil]; return; } - FlutterBinaryMessageHandler messageHandler = ^( - NSData* message, FlutterBinaryReplyHandler reply) { + FlutterBinaryMessageHandler messageHandler = ^(NSData* message, FlutterBinaryReplyHandler reply) { FlutterMethodCall* call = [_codec decodeMethodCall:message]; if ([call.method isEqual:@"listen"]) { FlutterEventReceiver eventReceiver = ^(id event) { if (event == FlutterEndOfEventStream) [_messenger sendBinaryMessage:nil channelName:_name]; - else if ([event isKindOfClass: [FlutterError class]]) + else if ([event isKindOfClass:[FlutterError class]]) [_messenger sendBinaryMessage:[_codec encodeErrorEnvelope:(FlutterError*)event] channelName:_name]; else - [_messenger sendBinaryMessage:[_codec encodeSuccessEnvelope:event] - channelName:_name]; + [_messenger sendBinaryMessage:[_codec encodeSuccessEnvelope:event] channelName:_name]; }; - FlutterError* error = [handler onListenWithArguments:call.arguments eventReceiver:eventReceiver]; + FlutterError* error = + [handler onListenWithArguments:call.arguments eventReceiver:eventReceiver]; if (error) reply([_codec encodeErrorEnvelope:error]); else @@ -322,7 +291,6 @@ - (void)setStreamHandler:(NSObject*)handler { reply(nil); } }; - [_messenger setBinaryMessageHandlerOnChannel:_name - binaryMessageHandler:messageHandler]; + [_messenger setBinaryMessageHandlerOnChannel:_name binaryMessageHandler:messageHandler]; } @end diff --git a/shell/platform/darwin/ios/framework/Source/FlutterCodecs.mm b/shell/platform/darwin/ios/framework/Source/FlutterCodecs.mm index a1246de015010..e37395d69254e 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterCodecs.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterCodecs.mm @@ -41,8 +41,7 @@ - (NSData*)encode:(NSString*)message { - (NSString*)decode:(NSData*)message { if (message == nil) return nil; - return [[[NSString alloc] initWithData:message encoding:NSUTF8StringEncoding] - autorelease]; + return [[[NSString alloc] initWithData:message encoding:NSUTF8StringEncoding] autorelease]; } @end @@ -58,8 +57,7 @@ + (instancetype)sharedInstance { - (NSData*)encode:(id)message { if (message == nil) return nil; - NSData* encoding = - [NSJSONSerialization dataWithJSONObject:message options:0 error:nil]; + NSData* encoding = [NSJSONSerialization dataWithJSONObject:message options:0 error:nil]; NSAssert(encoding, @"Invalid JSON message, encoding failed"); return encoding; } @@ -67,8 +65,7 @@ - (NSData*)encode:(id)message { - (id)decode:(NSData*)message { if (message == nil) return nil; - id decoded = - [NSJSONSerialization JSONObjectWithData:message options:0 error:nil]; + id decoded = [NSJSONSerialization JSONObjectWithData:message options:0 error:nil]; NSAssert(decoded, @"Invalid JSON message, decoding failed"); return decoded; } @@ -85,15 +82,14 @@ + (instancetype)sharedInstance { - (NSData*)encodeMethodCall:(FlutterMethodCall*)call { return [[FlutterJSONMessageCodec sharedInstance] encode:@{ - @"method": call.method, - @"args": (call.arguments == nil ? [NSNull null] : call.arguments), + @"method" : call.method, + @"args" : (call.arguments == nil ? [NSNull null] : call.arguments), }]; } - (NSData*)encodeSuccessEnvelope:(id)result { - return [[FlutterJSONMessageCodec sharedInstance] encode:@[ - result == nil ? [NSNull null] : result - ]]; + return + [[FlutterJSONMessageCodec sharedInstance] encode:@[ result == nil ? [NSNull null] : result ]]; } - (NSData*)encodeErrorEnvelope:(FlutterError*)error { diff --git a/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm b/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm index b3a98a0165fff..80f7e59268d22 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm @@ -79,8 +79,7 @@ - (instancetype)initWithFLXArchiveWithScriptSnapshot:(NSURL*)archiveURL { self = [super init]; if (self) { - _dartSource = [[FlutterDartSource alloc] - initWithFLXArchiveWithScriptSnapshot:archiveURL]; + _dartSource = [[FlutterDartSource alloc] initWithFLXArchiveWithScriptSnapshot:archiveURL]; [self checkReadiness]; } @@ -117,14 +116,10 @@ - (instancetype)initFromDefaultSourceForConfiguration { return nil; } - NSURL* dartMainURL = - URLForSwitch(shell::FlagForSwitch(shell::Switch::MainDartFile)); - NSURL* dartPackagesURL = - URLForSwitch(shell::FlagForSwitch(shell::Switch::Packages)); + NSURL* dartMainURL = URLForSwitch(shell::FlagForSwitch(shell::Switch::MainDartFile)); + NSURL* dartPackagesURL = URLForSwitch(shell::FlagForSwitch(shell::Switch::Packages)); - return [self initWithFLXArchive:flxURL - dartMain:dartMainURL - packages:dartPackagesURL]; + return [self initWithFLXArchive:flxURL dartMain:dartMainURL packages:dartPackagesURL]; } NSAssert(NO, @"Unreachable"); @@ -185,13 +180,12 @@ - (void)launchInEngine:(shell::Engine*)engine } if (_vmTypeRequirement != embedderVMType) { - NSString* message = [NSString - stringWithFormat: - @"Could not load the project because of differing project type. " - @"The project can run in '%@' but the embedder is configured as " - @"'%@'", - NSStringFromVMType(_vmTypeRequirement), - NSStringFromVMType(embedderVMType)]; + NSString* message = + [NSString stringWithFormat:@"Could not load the project because of differing project type. " + @"The project can run in '%@' but the embedder is configured as " + @"'%@'", + NSStringFromVMType(_vmTypeRequirement), + NSStringFromVMType(embedderVMType)]; result(NO, message); return; } @@ -212,41 +206,36 @@ - (void)launchInEngine:(shell::Engine*)engine #pragma mark - Running from precompiled application bundles -- (void)runFromPrecompiledSourceInEngine:(shell::Engine*)engine - result:(LaunchResult)result { +- (void)runFromPrecompiledSourceInEngine:(shell::Engine*)engine result:(LaunchResult)result { if (![_precompiledDartBundle load]) { NSString* message = [NSString - stringWithFormat: - @"Could not load the framework ('%@') containing precompiled code.", - _precompiledDartBundle.bundleIdentifier]; + stringWithFormat:@"Could not load the framework ('%@') containing precompiled code.", + _precompiledDartBundle.bundleIdentifier]; result(NO, message); return; } NSString* path = [self pathForFLXFromBundle:_precompiledDartBundle]; if (path.length == 0) { - NSString* message = - [NSString stringWithFormat:@"Could not find the 'app.flx' archive in " - @"the precompiled Dart bundle with ID '%@'", - _precompiledDartBundle.bundleIdentifier]; + NSString* message = [NSString stringWithFormat:@"Could not find the 'app.flx' archive in " + @"the precompiled Dart bundle with ID '%@'", + _precompiledDartBundle.bundleIdentifier]; result(NO, message); return; } std::string bundle_path = path.UTF8String; - blink::Threads::UI()->PostTask( - [ engine = engine->GetWeakPtr(), bundle_path ] { - if (engine) - engine->RunBundle(bundle_path); - }); + blink::Threads::UI()->PostTask([ engine = engine->GetWeakPtr(), bundle_path ] { + if (engine) + engine->RunBundle(bundle_path); + }); result(YES, @"Success"); } #pragma mark - Running from source -- (void)runFromSourceInEngine:(shell::Engine*)engine - result:(LaunchResult)result { +- (void)runFromSourceInEngine:(shell::Engine*)engine result:(LaunchResult)result { if (_dartSource == nil) { result(NO, @"Dart source not specified."); return; @@ -257,15 +246,13 @@ - (void)runFromSourceInEngine:(shell::Engine*)engine return result(NO, message); } - std::string bundle_path = - _dartSource.flxArchive.absoluteURL.path.UTF8String; + std::string bundle_path = _dartSource.flxArchive.absoluteURL.path.UTF8String; if (_dartSource.archiveContainsScriptSnapshot) { - blink::Threads::UI()->PostTask( - [ engine = engine->GetWeakPtr(), bundle_path ] { - if (engine) - engine->RunBundle(bundle_path); - }); + blink::Threads::UI()->PostTask([ engine = engine->GetWeakPtr(), bundle_path ] { + if (engine) + engine->RunBundle(bundle_path); + }); } else { std::string main = _dartSource.dartMain.absoluteURL.path.UTF8String; std::string packages = _dartSource.packages.absoluteURL.path.UTF8String; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterDartSource.mm b/shell/platform/darwin/ios/framework/Source/FlutterDartSource.mm index dc4b1ed19dcf5..f7fabea4597fb 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterDartSource.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterDartSource.mm @@ -31,10 +31,8 @@ - (instancetype)initWithDartMain:(NSURL*)dartMain NSFileManager* fileManager = [NSFileManager defaultManager]; - const BOOL dartMainExists = - [fileManager fileExistsAtPath:dartMain.absoluteURL.path]; - const BOOL packagesExists = - [fileManager fileExistsAtPath:packages.absoluteURL.path]; + const BOOL dartMainExists = [fileManager fileExistsAtPath:dartMain.absoluteURL.path]; + const BOOL packagesExists = [fileManager fileExistsAtPath:packages.absoluteURL.path]; if (!dartMainExists || !packagesExists) { // We cannot actually verify this without opening up the archive. This is @@ -57,9 +55,7 @@ - (instancetype)initWithFLXArchiveWithScriptSnapshot:(NSURL*)flxArchive { return self; } -static BOOL CheckDartProjectURL(NSMutableString* log, - NSURL* url, - NSString* logLabel) { +static BOOL CheckDartProjectURL(NSMutableString* log, NSURL* url, NSString* logLabel) { if (url == nil) { [log appendFormat:@"The %@ was not specified.\n", logLabel]; return false; @@ -71,8 +67,7 @@ static BOOL CheckDartProjectURL(NSMutableString* log, } if (![[NSFileManager defaultManager] fileExistsAtPath:url.absoluteURL.path]) { - [log appendFormat:@"No file found at '%@' when looking for the %@.\n", url, - logLabel]; + [log appendFormat:@"No file found at '%@' when looking for the %@.\n", url, logLabel]; return false; } diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm index d267a3375d3c0..21ecfb444c0fa 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm @@ -14,8 +14,7 @@ constexpr char kTextPlainFormat[] = "text/plain"; NSString* GetDirectoryOfType(NSSearchPathDirectory dir) { - NSArray* paths = - NSSearchPathForDirectoriesInDomains(dir, NSUserDomainMask, YES); + NSArray* paths = NSSearchPathForDirectoriesInDomains(dir, NSUserDomainMask, YES); if (paths.count == 0) return nil; return paths.firstObject; @@ -41,7 +40,8 @@ @implementation FlutterPlatformPlugin -- (void)handleMethodCall:(FlutterMethodCall*)call resultReceiver:(FlutterResultReceiver)resultReceiver { +- (void)handleMethodCall:(FlutterMethodCall*)call + resultReceiver:(FlutterResultReceiver)resultReceiver { NSString* method = call.method; id args = call.arguments; if ([method isEqualToString:@"SystemSound.play"]) { @@ -99,7 +99,7 @@ - (NSDictionary*)launchURL:(NSString*)urlString { NSURL* url = [NSURL URLWithString:urlString]; UIApplication* application = [UIApplication sharedApplication]; bool success = [application canOpenURL:url] && [application openURL:url]; - return @{ @"succes": @(success) }; + return @{ @"succes" : @(success) }; } - (void)setSystemChromePreferredOrientations:(NSArray*)orientations { @@ -122,13 +122,11 @@ - (void)setSystemChromePreferredOrientations:(NSArray*)orientations { if (!mask) return; - [[NSNotificationCenter defaultCenter] - postNotificationName:@(kOrientationUpdateNotificationName) - object:nil - userInfo:@{ - @(kOrientationUpdateNotificationKey) : @(mask) - }]; - + [[NSNotificationCenter defaultCenter] postNotificationName:@(kOrientationUpdateNotificationName) + object:nil + userInfo:@{ + @(kOrientationUpdateNotificationKey) : @(mask) + }]; } - (void)setSystemChromeApplicationSwitcherDescription:(NSDictionary*)object { @@ -157,8 +155,7 @@ - (void)setSystemChromeSystemUIOverlayStyle:(NSString*)style { NSNumber* infoValue = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIViewControllerBasedStatusBarAppearance"]; - Boolean delegateToViewController = - (infoValue == nil || [infoValue boolValue]); + Boolean delegateToViewController = (infoValue == nil || [infoValue boolValue]); if (delegateToViewController) { // This notification is respected by the iOS embedder @@ -182,11 +179,11 @@ - (void)popSystemNavigator { - (NSDictionary*)getClipboardData:(NSString*)format { UIPasteboard* pasteboard = [UIPasteboard generalPasteboard]; if (!format || [format isEqualToString:@(kTextPlainFormat)]) - return @{ @"text": pasteboard.string }; + return @{ @"text" : pasteboard.string }; return nil; } -- (void)setClipboardData:(NSDictionary *)data { +- (void)setClipboardData:(NSDictionary*)data { UIPasteboard* pasteboard = [UIPasteboard generalPasteboard]; pasteboard.string = data[@"text"]; } diff --git a/shell/platform/darwin/ios/framework/Source/FlutterStandardCodec.mm b/shell/platform/darwin/ios/framework/Source/FlutterStandardCodec.mm index 39d0db48fe63f..f6222760e67a6 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterStandardCodec.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterStandardCodec.mm @@ -27,8 +27,7 @@ - (NSData*)encode:(id)message { - (id)decode:(NSData*)message { if (message == nil) return nil; - FlutterStandardReader* reader = - [FlutterStandardReader readerWithData:message]; + FlutterStandardReader* reader = [FlutterStandardReader readerWithData:message]; id value = [reader readValue]; NSAssert(![reader hasMore], @"Corrupted standard message"); return value; @@ -73,19 +72,16 @@ - (NSData*)encodeErrorEnvelope:(FlutterError*)error { } - (FlutterMethodCall*)decodeMethodCall:(NSData*)message { - FlutterStandardReader* reader = - [FlutterStandardReader readerWithData:message]; + FlutterStandardReader* reader = [FlutterStandardReader readerWithData:message]; id value1 = [reader readValue]; id value2 = [reader readValue]; NSAssert(![reader hasMore], @"Corrupted standard method call"); - NSAssert([value1 isKindOfClass:[NSString class]], - @"Corrupted standard method call"); + NSAssert([value1 isKindOfClass:[NSString class]], @"Corrupted standard method call"); return [FlutterMethodCall methodCallWithMethodName:value1 arguments:value2]; } - (id)decodeEnvelope:(NSData*)envelope { - FlutterStandardReader* reader = - [FlutterStandardReader readerWithData:envelope]; + FlutterStandardReader* reader = [FlutterStandardReader readerWithData:envelope]; UInt8 flag = [reader readByte]; NSAssert(flag <= 1, @"Corrupted standard envelope"); id result; @@ -99,8 +95,7 @@ - (id)decodeEnvelope:(NSData*)envelope { id message = [reader readValue]; id details = [reader readValue]; NSAssert(![reader hasMore], @"Corrupted standard envelope"); - NSAssert([code isKindOfClass:[NSString class]], - @"Invalid standard envelope"); + NSAssert([code isKindOfClass:[NSString class]], @"Invalid standard envelope"); NSAssert(message == nil || [message isKindOfClass:[NSString class]], @"Invalid standard envelope"); result = [FlutterError errorWithCode:code message:message details:details]; @@ -116,40 +111,29 @@ - (id)decodeEnvelope:(NSData*)envelope { @implementation FlutterStandardTypedData + (instancetype)typedDataWithBytes:(NSData*)data { - return - [FlutterStandardTypedData typedDataWithData:data - type:FlutterStandardDataTypeUInt8]; + return [FlutterStandardTypedData typedDataWithData:data type:FlutterStandardDataTypeUInt8]; } + (instancetype)typedDataWithInt32:(NSData*)data { - return - [FlutterStandardTypedData typedDataWithData:data - type:FlutterStandardDataTypeInt32]; + return [FlutterStandardTypedData typedDataWithData:data type:FlutterStandardDataTypeInt32]; } + (instancetype)typedDataWithInt64:(NSData*)data { - return - [FlutterStandardTypedData typedDataWithData:data - type:FlutterStandardDataTypeInt64]; + return [FlutterStandardTypedData typedDataWithData:data type:FlutterStandardDataTypeInt64]; } + (instancetype)typedDataWithFloat64:(NSData*)data { - return [FlutterStandardTypedData - typedDataWithData:data - type:FlutterStandardDataTypeFloat64]; + return [FlutterStandardTypedData typedDataWithData:data type:FlutterStandardDataTypeFloat64]; } -+ (instancetype)typedDataWithData:(NSData*)data - type:(FlutterStandardDataType)type { - return [[[FlutterStandardTypedData alloc] initWithData:data type:type] - autorelease]; ++ (instancetype)typedDataWithData:(NSData*)data type:(FlutterStandardDataType)type { + return [[[FlutterStandardTypedData alloc] initWithData:data type:type] autorelease]; } - (instancetype)initWithData:(NSData*)data type:(FlutterStandardDataType)type { UInt8 elementSize = elementSizeForFlutterStandardDataType(type); NSAssert(data, @"Data cannot be nil"); - NSAssert(data.length % elementSize == 0, - @"Data must contain integral number of elements"); + NSAssert(data.length % elementSize == 0, @"Data must contain integral number of elements"); self = [super init]; NSAssert(self, @"Super init cannot be nil"); _data = [data retain]; @@ -218,8 +202,7 @@ @implementation FlutterStandardWriter { } + (instancetype)writerWithData:(NSMutableData*)data { - FlutterStandardWriter* writer = - [[FlutterStandardWriter alloc] initWithData:data]; + FlutterStandardWriter* writer = [[FlutterStandardWriter alloc] initWithData:data]; [writer autorelease]; return writer; } @@ -276,10 +259,8 @@ - (void)writeValue:(id)value { const char* type = [number objCType]; if ([self isBool:number type:type]) { BOOL b = number.boolValue; - [self - writeByte:(b ? FlutterStandardFieldTrue : FlutterStandardFieldFalse)]; - } else if (strcmp(type, @encode(signed int)) == 0 || - strcmp(type, @encode(signed short)) == 0 || + [self writeByte:(b ? FlutterStandardFieldTrue : FlutterStandardFieldFalse)]; + } else if (strcmp(type, @encode(signed int)) == 0 || strcmp(type, @encode(signed short)) == 0 || strcmp(type, @encode(unsigned short)) == 0 || strcmp(type, @encode(signed char)) == 0 || strcmp(type, @encode(unsigned char)) == 0) { @@ -291,16 +272,14 @@ - (void)writeValue:(id)value { SInt64 n = number.longValue; [self writeByte:FlutterStandardFieldInt64]; [_data appendBytes:(UInt8*)&n length:8]; - } else if (strcmp(type, @encode(double)) == 0 || - strcmp(type, @encode(float)) == 0) { + } else if (strcmp(type, @encode(double)) == 0 || strcmp(type, @encode(float)) == 0) { Float64 f = number.doubleValue; [self writeByte:FlutterStandardFieldFloat64]; [_data appendBytes:(UInt8*)&f length:8]; } else if (strcmp(type, @encode(unsigned long)) == 0 || strcmp(type, @encode(signed long long)) == 0 || strcmp(type, @encode(unsigned long long)) == 0) { - NSString* hex = - [NSString stringWithFormat:@"%llx", number.unsignedLongLongValue]; + NSString* hex = [NSString stringWithFormat:@"%llx", number.unsignedLongLongValue]; [self writeByte:FlutterStandardFieldIntHex]; [self writeUTF8:hex]; } else { @@ -354,8 +333,7 @@ @implementation FlutterStandardReader { } + (instancetype)readerWithData:(NSData*)data { - FlutterStandardReader* reader = - [[FlutterStandardReader alloc] initWithData:data]; + FlutterStandardReader* reader = [[FlutterStandardReader alloc] initWithData:data]; [reader autorelease]; return reader; } @@ -413,8 +391,7 @@ - (NSData*)readData:(int)length { - (NSString*)readUTF8 { NSData* bytes = [self readData:[self readSize]]; - return [[[NSString alloc] initWithData:bytes encoding:NSUTF8StringEncoding] - autorelease]; + return [[[NSString alloc] initWithData:bytes encoding:NSUTF8StringEncoding] autorelease]; } - (void)readAlignment:(UInt8)alignment { @@ -476,8 +453,7 @@ - (id)readValue { } case FlutterStandardFieldMap: { UInt32 size = [self readSize]; - NSMutableDictionary* dict = - [NSMutableDictionary dictionaryWithCapacity:size]; + NSMutableDictionary* dict = [NSMutableDictionary dictionaryWithCapacity:size]; for (UInt32 i = 0; i < size; i++) { id key = [self readValue]; id val = [self readValue]; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm index 841fa55e274f6..fe3ca6d927aa5 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm @@ -188,8 +188,7 @@ - (void)hideTextInput { [_view removeFromSuperview]; } -- (void)setTextInputClient:(int)client - withConfiguration:(NSDictionary*)configuration { +- (void)setTextInputClient:(int)client withConfiguration:(NSDictionary*)configuration { _view.keyboardType = ToUIKeyboardType(configuration[@"inputType"]); [_view setTextInputClient:client]; [_view reloadInputViews]; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterView.mm b/shell/platform/darwin/ios/framework/Source/FlutterView.mm index 079c901885514..67331334e3376 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterView.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterView.mm @@ -60,10 +60,9 @@ void SnapshotRasterizer(ftl::WeakPtr rasterizer, if (size.isEmpty()) { return; } - auto info = - SkImageInfo::MakeN32(size.width(), size.height(), - is_opaque ? SkAlphaType::kOpaque_SkAlphaType - : SkAlphaType::kPremul_SkAlphaType); + auto info = SkImageInfo::MakeN32( + size.width(), size.height(), + is_opaque ? SkAlphaType::kOpaque_SkAlphaType : SkAlphaType::kPremul_SkAlphaType); // Create the backing store and prepare for use. SkBitmap bitmap; @@ -80,8 +79,7 @@ void SnapshotRasterizer(ftl::WeakPtr rasterizer, { flow::CompositorContext compositor_context(nullptr); - auto frame = compositor_context.AcquireFrame(nullptr, &canvas, - false /* instrumentation */); + auto frame = compositor_context.AcquireFrame(nullptr, &canvas, false /* instrumentation */); layer_tree->Raster(frame, false /* ignore raster cache. */); } diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index 4bbe3e95c6386..4b13f0637ef0d 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -41,14 +41,11 @@ void Complete(std::vector data) override { void CompleteEmpty() override { ftl::RefPtr self(this); blink::Threads::Platform()->PostTask( - ftl::MakeCopyable([ self ]() mutable { - self->callback_.get()(nil); - })); + ftl::MakeCopyable([self]() mutable { self->callback_.get()(nil); })); } private: - explicit PlatformMessageResponseDarwin( - PlatformMessageResponseCallback callback) + explicit PlatformMessageResponseDarwin(PlatformMessageResponseCallback callback) : callback_(callback, fml::OwnershipPolicy::Retain) {} fml::ScopedBlock callback_; @@ -56,8 +53,7 @@ explicit PlatformMessageResponseDarwin( } // namespace -@interface FlutterViewController () +@interface FlutterViewController () @end @implementation FlutterViewController { @@ -93,8 +89,7 @@ - (instancetype)initWithProject:(FlutterDartProject*)project if (self) { if (project == nil) - _dartProject.reset( - [[FlutterDartProject alloc] initFromDefaultSourceForConfiguration]); + _dartProject.reset([[FlutterDartProject alloc] initFromDefaultSourceForConfiguration]); else _dartProject.reset([project retain]); @@ -104,8 +99,7 @@ - (instancetype)initWithProject:(FlutterDartProject*)project return self; } -- (instancetype)initWithNibName:(NSString*)nibNameOrNil - bundle:(NSBundle*)nibBundleOrNil { +- (instancetype)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil { return [self initWithProject:nil nibName:nil bundle:nil]; } @@ -123,8 +117,8 @@ - (void)performCommonViewControllerInitialization { _orientationPreferences = UIInterfaceOrientationMaskAll; _statusBarStyle = UIStatusBarStyleDefault; - _platformView = std::make_unique( - reinterpret_cast(self.view.layer)); + _platformView = + std::make_unique(reinterpret_cast(self.view.layer)); _platformView->SetupResourceContextOnIOThread(); _localizationChannel.reset([[FlutterMethodChannel alloc] @@ -158,19 +152,16 @@ - (void)performCommonViewControllerInitialization { codec:[FlutterJSONMessageCodec sharedInstance]]); _platformPlugin.reset([[FlutterPlatformPlugin alloc] init]); - [_platformChannel.get() setMethodCallHandler:^( - FlutterMethodCall* call, - FlutterResultReceiver resultReceiver) { - [_platformPlugin.get() handleMethodCall:call resultReceiver:resultReceiver]; - }]; + [_platformChannel.get() + setMethodCallHandler:^(FlutterMethodCall* call, FlutterResultReceiver resultReceiver) { + [_platformPlugin.get() handleMethodCall:call resultReceiver:resultReceiver]; + }]; _textInputPlugin.reset([[FlutterTextInputPlugin alloc] init]); _textInputPlugin.get().textInputDelegate = self; [_textInputChannel.get() - setMethodCallHandler:^(FlutterMethodCall* call, - FlutterResultReceiver resultReceiver) { - [_textInputPlugin.get() handleMethodCall:call - resultReceiver:resultReceiver]; + setMethodCallHandler:^(FlutterMethodCall* call, FlutterResultReceiver resultReceiver) { + [_textInputPlugin.get() handleMethodCall:call resultReceiver:resultReceiver]; }]; [self setupNotificationCenterObservers]; @@ -228,8 +219,7 @@ - (void)setupNotificationCenterObservers { #pragma mark - Initializing the engine -- (void)alertView:(UIAlertView*)alertView - clickedButtonAtIndex:(NSInteger)buttonIndex { +- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { exit(0); } @@ -237,19 +227,17 @@ - (void)connectToEngineAndLoad { TRACE_EVENT0("flutter", "connectToEngineAndLoad"); // We ask the VM to check what it supports. - const enum VMType type = - Dart_IsPrecompiledRuntime() ? VMTypePrecompilation : VMTypeInterpreter; + const enum VMType type = Dart_IsPrecompiledRuntime() ? VMTypePrecompilation : VMTypeInterpreter; [_dartProject launchInEngine:&_platformView->engine() embedderVMType:type result:^(BOOL success, NSString* message) { if (!success) { - UIAlertView* alert = [[UIAlertView alloc] - initWithTitle:@"Launch Error" - message:message - delegate:self - cancelButtonTitle:@"OK" - otherButtonTitles:nil]; + UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Launch Error" + message:message + delegate:self + cancelButtonTitle:@"OK" + otherButtonTitles:nil]; [alert show]; [alert release]; } @@ -263,8 +251,7 @@ - (void)loadView { self.view = view; self.view.multipleTouchEnabled = YES; - self.view.autoresizingMask = - UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; [view release]; } @@ -287,30 +274,23 @@ - (void)applicationWillResignActive:(NSNotification*)notification { Removed, }; -using PointerChangeMapperPhase = - std::pair; -static inline PointerChangeMapperPhase PointerChangePhaseFromUITouchPhase( - UITouchPhase phase) { +using PointerChangeMapperPhase = std::pair; +static inline PointerChangeMapperPhase PointerChangePhaseFromUITouchPhase(UITouchPhase phase) { switch (phase) { case UITouchPhaseBegan: - return PointerChangeMapperPhase(blink::PointerData::Change::kDown, - MapperPhase::Added); + return PointerChangeMapperPhase(blink::PointerData::Change::kDown, MapperPhase::Added); case UITouchPhaseMoved: case UITouchPhaseStationary: // There is no EVENT_TYPE_POINTER_STATIONARY. So we just pass a move type // with the same coordinates - return PointerChangeMapperPhase(blink::PointerData::Change::kMove, - MapperPhase::Accessed); + return PointerChangeMapperPhase(blink::PointerData::Change::kMove, MapperPhase::Accessed); case UITouchPhaseEnded: - return PointerChangeMapperPhase(blink::PointerData::Change::kUp, - MapperPhase::Removed); + return PointerChangeMapperPhase(blink::PointerData::Change::kUp, MapperPhase::Removed); case UITouchPhaseCancelled: - return PointerChangeMapperPhase(blink::PointerData::Change::kCancel, - MapperPhase::Removed); + return PointerChangeMapperPhase(blink::PointerData::Change::kCancel, MapperPhase::Removed); } - return PointerChangeMapperPhase(blink::PointerData::Change::kCancel, - MapperPhase::Accessed); + return PointerChangeMapperPhase(blink::PointerData::Change::kCancel, MapperPhase::Accessed); } - (void)dispatchTouches:(NSSet*)touches phase:(UITouchPhase)phase { @@ -358,12 +338,11 @@ - (void)dispatchTouches:(NSSet*)touches phase:(UITouchPhase)phase { packet->SetPointerData(i++, pointer_data); } - blink::Threads::UI()->PostTask(ftl::MakeCopyable([ - engine = _platformView->engine().GetWeakPtr(), packet = std::move(packet) - ] { - if (engine.get()) - engine->DispatchPointerDataPacket(*packet); - })); + blink::Threads::UI()->PostTask(ftl::MakeCopyable( + [ engine = _platformView->engine().GetWeakPtr(), packet = std::move(packet) ] { + if (engine.get()) + engine->DispatchPointerDataPacket(*packet); + })); } - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { @@ -385,22 +364,21 @@ - (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event { #pragma mark - Handle view resizing - (void)updateViewportMetrics { - blink::Threads::UI()->PostTask([ - weak_platform_view = _platformView->GetWeakPtr(), metrics = _viewportMetrics - ] { - if (!weak_platform_view) { - return; - } - weak_platform_view->UpdateSurfaceSize(); - weak_platform_view->engine().SetViewportMetrics(metrics); - }); + blink::Threads::UI()->PostTask( + [ weak_platform_view = _platformView->GetWeakPtr(), metrics = _viewportMetrics ] { + if (!weak_platform_view) { + return; + } + weak_platform_view->UpdateSurfaceSize(); + weak_platform_view->engine().SetViewportMetrics(metrics); + }); } - (CGFloat)statusBarPadding { UIScreen* screen = self.view.window.screen; CGRect statusFrame = [UIApplication sharedApplication].statusBarFrame; - CGRect viewFrame = [self.view convertRect:self.view.bounds - toCoordinateSpace:screen.coordinateSpace]; + CGRect viewFrame = + [self.view convertRect:self.view.bounds toCoordinateSpace:screen.coordinateSpace]; CGRect intersection = CGRectIntersection(statusFrame, viewFrame); return CGRectIsNull(intersection) ? 0.0 : intersection.size.height; } @@ -420,8 +398,8 @@ - (void)viewDidLayoutSubviews { - (void)keyboardWasShown:(NSNotification*)notification { NSDictionary* info = [notification userInfo]; - CGFloat bottom = CGRectGetHeight( - [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue]); + CGFloat bottom = + CGRectGetHeight([[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue]); CGFloat scale = [UIScreen mainScreen].scale; _viewportMetrics.physical_padding_bottom = bottom * scale; [self updateViewportMetrics]; @@ -495,8 +473,7 @@ - (void)onLocaleUpdated:(NSNotification*)notification { NSLocale* currentLocale = [NSLocale currentLocale]; NSString* languageCode = [currentLocale objectForKey:NSLocaleLanguageCode]; NSString* countryCode = [currentLocale objectForKey:NSLocaleCountryCode]; - [_localizationChannel.get() invokeMethod:@"setLocale" - arguments:@[ languageCode, countryCode ]]; + [_localizationChannel.get() invokeMethod:@"setLocale" arguments:@[ languageCode, countryCode ]]; } #pragma mark - Surface creation and teardown updates @@ -594,22 +571,21 @@ - (void)sendBinaryMessage:(NSData*)message channelName:(NSString*)channel binaryReplyHandler:(FlutterBinaryReplyHandler)callback { NSAssert(channel, @"The channel must not be null"); - ftl::RefPtr response = (callback == nil) - ? nullptr - : ftl::MakeRefCounted(^(NSData* reply) { - callback(reply); - }); - ftl::RefPtr platformMessage = (message == nil) - ? ftl::MakeRefCounted(channel.UTF8String, response) - : ftl::MakeRefCounted(channel.UTF8String, - shell::GetVectorFromNSData(message), response); + ftl::RefPtr response = + (callback == nil) ? nullptr + : ftl::MakeRefCounted(^(NSData* reply) { + callback(reply); + }); + ftl::RefPtr platformMessage = + (message == nil) ? ftl::MakeRefCounted(channel.UTF8String, response) + : ftl::MakeRefCounted( + channel.UTF8String, shell::GetVectorFromNSData(message), response); _platformView->DispatchPlatformMessage(platformMessage); } - (void)setBinaryMessageHandlerOnChannel:(NSString*)channel binaryMessageHandler:(FlutterBinaryMessageHandler)handler { NSAssert(channel, @"The channel name must not be null"); - _platformView->platform_message_router().SetMessageHandler(channel.UTF8String, - handler); + _platformView->platform_message_router().SetMessageHandler(channel.UTF8String, handler); } @end diff --git a/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm b/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm index 454fee4109c05..5a21b84864f4c 100644 --- a/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm +++ b/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm @@ -4,13 +4,13 @@ #include "flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h" -#include #include +#include #import -#include "lib/ftl/logging.h" #include "flutter/shell/platform/darwin/ios/platform_view_ios.h" +#include "lib/ftl/logging.h" namespace { @@ -20,17 +20,17 @@ UIAccessibilityScrollDirection direction) { switch (direction) { case UIAccessibilityScrollDirectionRight: - case UIAccessibilityScrollDirectionPrevious: // TODO(abarth): Support RTL. + case UIAccessibilityScrollDirectionPrevious: // TODO(abarth): Support RTL. return blink::SemanticsAction::kScrollRight; case UIAccessibilityScrollDirectionLeft: - case UIAccessibilityScrollDirectionNext: // TODO(abarth): Support RTL. + case UIAccessibilityScrollDirectionNext: // TODO(abarth): Support RTL. return blink::SemanticsAction::kScrollLeft; case UIAccessibilityScrollDirectionUp: return blink::SemanticsAction::kScrollUp; case UIAccessibilityScrollDirectionDown: return blink::SemanticsAction::kScrollDown; } - FTL_DCHECK(false); // Unreachable + FTL_DCHECK(false); // Unreachable return blink::SemanticsAction::kScrollDown; } @@ -53,8 +53,7 @@ - (instancetype)init { #pragma mark - Designated initializers -- (instancetype)initWithBridge:(shell::AccessibilityBridge*)bridge - uid:(int32_t)uid { +- (instancetype)initWithBridge:(shell::AccessibilityBridge*)bridge uid:(int32_t)uid { FTL_DCHECK(bridge != nil) << "bridge must be set"; FTL_DCHECK(uid >= kRootNodeId); self = [super init]; @@ -104,8 +103,8 @@ - (UIAccessibilityTraits)accessibilityTraits { if (_node.HasAction(blink::SemanticsAction::kTap)) { traits |= UIAccessibilityTraitButton; } - if (_node.HasAction(blink::SemanticsAction::kIncrease) - || _node.HasAction(blink::SemanticsAction::kDecrease)) { + if (_node.HasAction(blink::SemanticsAction::kIncrease) || + _node.HasAction(blink::SemanticsAction::kDecrease)) { traits |= UIAccessibilityTraitAdjustable; } return traits; @@ -128,8 +127,7 @@ - (CGRect)accessibilityFrame { rect.set(quad, 4); auto result = CGRectMake(rect.x(), rect.y(), rect.width(), rect.height()); - return UIAccessibilityConvertFrameToScreenCoordinates(result, - _bridge->view()); + return UIAccessibilityConvertFrameToScreenCoordinates(result, _bridge->view()); } #pragma mark - UIAccessibilityElement protocol @@ -204,8 +202,7 @@ - (BOOL)accessibilityPerformMagicTap { namespace shell { -AccessibilityBridge::AccessibilityBridge(UIView* view, - PlatformViewIOS* platform_view) +AccessibilityBridge::AccessibilityBridge(UIView* view, PlatformViewIOS* platform_view) : view_(view), platform_view_(platform_view) {} AccessibilityBridge::~AccessibilityBridge() { @@ -252,13 +249,10 @@ - (BOOL)accessibilityPerformMagicTap { } else { view_.accessibilityElements = nil; } - UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, - nil); + UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil); } -void AccessibilityBridge::DispatchSemanticsAction( - int32_t uid, - blink::SemanticsAction action) { +void AccessibilityBridge::DispatchSemanticsAction(int32_t uid, blink::SemanticsAction action) { platform_view_->DispatchSemanticsAction(uid, action); } @@ -271,16 +265,14 @@ - (BOOL)accessibilityPerformMagicTap { return object; } -void AccessibilityBridge::VisitObjectsRecursively( - SemanticsObject* object, - std::unordered_set* visited_objects) { +void AccessibilityBridge::VisitObjectsRecursively(SemanticsObject* object, + std::unordered_set* visited_objects) { visited_objects->insert(object.uid); for (SemanticsObject* child : *[object children]) VisitObjectsRecursively(child, visited_objects); } -void AccessibilityBridge::ReleaseObjects( - const std::unordered_map& objects) { +void AccessibilityBridge::ReleaseObjects(const std::unordered_map& objects) { for (const auto& entry : objects) { SemanticsObject* object = entry.second; [object neuter]; diff --git a/shell/platform/darwin/ios/framework/Source/flutter_codecs_unittest.mm b/shell/platform/darwin/ios/framework/Source/flutter_codecs_unittest.mm index 6f26ca85243dc..cc311b10baf5a 100644 --- a/shell/platform/darwin/ios/framework/Source/flutter_codecs_unittest.mm +++ b/shell/platform/darwin/ios/framework/Source/flutter_codecs_unittest.mm @@ -48,9 +48,7 @@ } TEST(FlutterJSONCodec, CanEncodeAndDecodeArray) { - NSArray* value = - @[ [NSNull null], @"hello", @3.14, @47, - @{ @"a" : @"nested" } ]; + NSArray* value = @[ [NSNull null], @"hello", @3.14, @47, @{ @"a" : @"nested" } ]; FlutterJSONMessageCodec* codec = [FlutterJSONMessageCodec sharedInstance]; NSData* encoded = [codec encode:value]; NSArray* decoded = [codec decode:encoded]; @@ -58,12 +56,7 @@ } TEST(FlutterJSONCodec, CanEncodeAndDecodeDictionary) { - NSDictionary* value = @{ - @"a" : @3.14, - @"b" : @47, - @"c" : [NSNull null], - @"d" : @[ @"nested" ] - }; + NSDictionary* value = @{ @"a" : @3.14, @"b" : @47, @"c" : [NSNull null], @"d" : @[ @"nested" ] }; FlutterJSONMessageCodec* codec = [FlutterJSONMessageCodec sharedInstance]; NSData* encoded = [codec encode:value]; NSDictionary* decoded = [codec decode:encoded]; diff --git a/shell/platform/darwin/ios/framework/Source/flutter_main_ios.mm b/shell/platform/darwin/ios/framework/Source/flutter_main_ios.mm index 44eb279f2d97d..725af176605b4 100644 --- a/shell/platform/darwin/ios/framework/Source/flutter_main_ios.mm +++ b/shell/platform/darwin/ios/framework/Source/flutter_main_ios.mm @@ -11,10 +11,8 @@ void FlutterMain() { NSBundle* bundle = [NSBundle bundleForClass:[FlutterViewController class]]; NSString* icuDataPath = [bundle pathForResource:@"icudtl" ofType:@"dat"]; - NSString* libraryName = - [[NSBundle mainBundle] objectForInfoDictionaryKey:@"FLTLibraryPath"]; - shell::PlatformMacMain(icuDataPath.UTF8String, - libraryName != nil ? libraryName.UTF8String : ""); + NSString* libraryName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"FLTLibraryPath"]; + shell::PlatformMacMain(icuDataPath.UTF8String, libraryName != nil ? libraryName.UTF8String : ""); } } // namespace shell diff --git a/shell/platform/darwin/ios/framework/Source/flutter_standard_codec_unittest.mm b/shell/platform/darwin/ios/framework/Source/flutter_standard_codec_unittest.mm index ebf3931989ece..f9c54c3d6a9d3 100644 --- a/shell/platform/darwin/ios/framework/Source/flutter_standard_codec_unittest.mm +++ b/shell/platform/darwin/ios/framework/Source/flutter_standard_codec_unittest.mm @@ -6,8 +6,7 @@ #include "gtest/gtest.h" void checkEncodeDecode(id value, NSData* expectedEncoding) { - FlutterStandardMessageCodec* codec = - [FlutterStandardMessageCodec sharedInstance]; + FlutterStandardMessageCodec* codec = [FlutterStandardMessageCodec sharedInstance]; NSData* encoded = [codec encode:value]; if (expectedEncoding == nil) ASSERT_TRUE(encoded == nil); @@ -21,8 +20,7 @@ void checkEncodeDecode(id value, NSData* expectedEncoding) { } void checkEncodeDecode(id value) { - FlutterStandardMessageCodec* codec = - [FlutterStandardMessageCodec sharedInstance]; + FlutterStandardMessageCodec* codec = [FlutterStandardMessageCodec sharedInstance]; NSData* encoded = [codec encode:value]; id decoded = [codec decode:encoded]; if (value == nil || value == [NSNull null]) @@ -69,8 +67,7 @@ void checkEncodeDecode(id value) { } TEST(FlutterStandardCodec, CanEncodeAndDecodeUInt64AsHexString) { - FlutterStandardMessageCodec* codec = - [FlutterStandardMessageCodec sharedInstance]; + FlutterStandardMessageCodec* codec = [FlutterStandardMessageCodec sharedInstance]; UInt64 u64 = 0xfffffffffffffffa; NSData* encoded = [codec encode:@(u64)]; FlutterStandardBigInteger* decoded = [codec decode:encoded]; @@ -96,13 +93,12 @@ void checkEncodeDecode(id value) { TEST(FlutterStandardCodec, CanEncodeAndDecodeSInt64) { char bytes[9] = {0x04, 0xef, 0xcd, 0xab, 0x90, 0x78, 0x56, 0x34, 0x12}; - checkEncodeDecode(@(0x1234567890abcdef), - [NSData dataWithBytes:bytes length:9]); + checkEncodeDecode(@(0x1234567890abcdef), [NSData dataWithBytes:bytes length:9]); } TEST(FlutterStandardCodec, CanEncodeAndDecodeBigInteger) { - FlutterStandardBigInteger* value = [FlutterStandardBigInteger - bigIntegerWithHex:@"-abcdef0123456789abcdef01234567890"]; + FlutterStandardBigInteger* value = + [FlutterStandardBigInteger bigIntegerWithHex:@"-abcdef0123456789abcdef01234567890"]; checkEncodeDecode(value); } @@ -113,13 +109,11 @@ void checkEncodeDecode(id value) { TEST(FlutterStandardCodec, CanEncodeAndDecodeFloat64) { char bytes[9] = {0x06, 0x18, 0x2d, 0x44, 0x54, 0xfb, 0x21, 0x09, 0x40}; - checkEncodeDecode(@3.14159265358979311599796346854, - [NSData dataWithBytes:bytes length:9]); + checkEncodeDecode(@3.14159265358979311599796346854, [NSData dataWithBytes:bytes length:9]); } TEST(FlutterStandardCodec, CanEncodeAndDecodeString) { - char bytes[13] = {0x07, 0x0b, 0x68, 0x65, 0x6c, 0x6c, 0x6f, - 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64}; + char bytes[13] = {0x07, 0x0b, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64}; checkEncodeDecode(@"hello world", [NSData dataWithBytes:bytes length:13]); } @@ -134,43 +128,37 @@ void checkEncodeDecode(id value) { } TEST(FlutterStandardCodec, CanEncodeAndDecodeArray) { - NSArray* value = - @[ [NSNull null], @"hello", @3.14, @47, - @{ @42 : @"nested" } ]; + NSArray* value = @[ [NSNull null], @"hello", @3.14, @47, @{ @42 : @"nested" } ]; checkEncodeDecode(value); } TEST(FlutterStandardCodec, CanEncodeAndDecodeDictionary) { - NSDictionary* value = @{ - @"a" : @3.14, - @"b" : @47, - [NSNull null] : [NSNull null], - @3.14 : @[ @"nested" ] - }; + NSDictionary* value = + @{ @"a" : @3.14, + @"b" : @47, + [NSNull null] : [NSNull null], + @3.14 : @[ @"nested" ] }; checkEncodeDecode(value); } TEST(FlutterStandardCodec, CanEncodeAndDecodeByteArray) { char bytes[4] = {0xBA, 0x5E, 0xBA, 0x11}; NSData* data = [NSData dataWithBytes:bytes length:4]; - FlutterStandardTypedData* value = - [FlutterStandardTypedData typedDataWithBytes:data]; + FlutterStandardTypedData* value = [FlutterStandardTypedData typedDataWithBytes:data]; checkEncodeDecode(value); } TEST(FlutterStandardCodec, CanEncodeAndDecodeInt32Array) { char bytes[8] = {0xBA, 0x5E, 0xBA, 0x11, 0xff, 0xff, 0xff, 0xff}; NSData* data = [NSData dataWithBytes:bytes length:8]; - FlutterStandardTypedData* value = - [FlutterStandardTypedData typedDataWithInt32:data]; + FlutterStandardTypedData* value = [FlutterStandardTypedData typedDataWithInt32:data]; checkEncodeDecode(value); } TEST(FlutterStandardCodec, CanEncodeAndDecodeInt64Array) { char bytes[8] = {0xBA, 0x5E, 0xBA, 0x11, 0xff, 0xff, 0xff, 0xff}; NSData* data = [NSData dataWithBytes:bytes length:8]; - FlutterStandardTypedData* value = - [FlutterStandardTypedData typedDataWithInt64:data]; + FlutterStandardTypedData* value = [FlutterStandardTypedData typedDataWithInt64:data]; checkEncodeDecode(value); } @@ -178,34 +166,28 @@ void checkEncodeDecode(id value) { char bytes[16] = {0xBA, 0x5E, 0xBA, 0x11, 0xff, 0xff, 0xff, 0xff, 0xBA, 0x5E, 0xBA, 0x11, 0xff, 0xff, 0xff, 0xff}; NSData* data = [NSData dataWithBytes:bytes length:16]; - FlutterStandardTypedData* value = - [FlutterStandardTypedData typedDataWithFloat64:data]; + FlutterStandardTypedData* value = [FlutterStandardTypedData typedDataWithFloat64:data]; checkEncodeDecode(value); } TEST(FlutterStandardCodec, HandlesMethodCallsWithNilArguments) { - FlutterStandardMethodCodec* codec = - [FlutterStandardMethodCodec sharedInstance]; - FlutterMethodCall* call = - [FlutterMethodCall methodCallWithMethodName:@"hello" arguments:nil]; + FlutterStandardMethodCodec* codec = [FlutterStandardMethodCodec sharedInstance]; + FlutterMethodCall* call = [FlutterMethodCall methodCallWithMethodName:@"hello" arguments:nil]; NSData* encoded = [codec encodeMethodCall:call]; FlutterMethodCall* decoded = [codec decodeMethodCall:encoded]; ASSERT_TRUE([decoded isEqual:call]); } TEST(FlutterStandardCodec, HandlesMethodCallsWithSingleArgument) { - FlutterStandardMethodCodec* codec = - [FlutterStandardMethodCodec sharedInstance]; - FlutterMethodCall* call = - [FlutterMethodCall methodCallWithMethodName:@"hello" arguments:@42]; + FlutterStandardMethodCodec* codec = [FlutterStandardMethodCodec sharedInstance]; + FlutterMethodCall* call = [FlutterMethodCall methodCallWithMethodName:@"hello" arguments:@42]; NSData* encoded = [codec encodeMethodCall:call]; FlutterMethodCall* decoded = [codec decodeMethodCall:encoded]; ASSERT_TRUE([decoded isEqual:call]); } TEST(FlutterStandardCodec, HandlesMethodCallsWithArgumentList) { - FlutterStandardMethodCodec* codec = - [FlutterStandardMethodCodec sharedInstance]; + FlutterStandardMethodCodec* codec = [FlutterStandardMethodCodec sharedInstance]; NSArray* arguments = @[ @42, @"world" ]; FlutterMethodCall* call = [FlutterMethodCall methodCallWithMethodName:@"hello" arguments:arguments]; @@ -215,24 +197,21 @@ void checkEncodeDecode(id value) { } TEST(FlutterStandardCodec, HandlesSuccessEnvelopesWithNilResult) { - FlutterStandardMethodCodec* codec = - [FlutterStandardMethodCodec sharedInstance]; + FlutterStandardMethodCodec* codec = [FlutterStandardMethodCodec sharedInstance]; NSData* encoded = [codec encodeSuccessEnvelope:nil]; id decoded = [codec decodeEnvelope:encoded]; ASSERT_TRUE(decoded == nil); } TEST(FlutterStandardCodec, HandlesSuccessEnvelopesWithSingleResult) { - FlutterStandardMethodCodec* codec = - [FlutterStandardMethodCodec sharedInstance]; + FlutterStandardMethodCodec* codec = [FlutterStandardMethodCodec sharedInstance]; NSData* encoded = [codec encodeSuccessEnvelope:@42]; id decoded = [codec decodeEnvelope:encoded]; ASSERT_TRUE([decoded isEqual:@42]); } TEST(FlutterStandardCodec, HandlesSuccessEnvelopesWithResultMap) { - FlutterStandardMethodCodec* codec = - [FlutterStandardMethodCodec sharedInstance]; + FlutterStandardMethodCodec* codec = [FlutterStandardMethodCodec sharedInstance]; NSDictionary* result = @{ @"a" : @42, @42 : @"a" }; NSData* encoded = [codec encodeSuccessEnvelope:result]; id decoded = [codec decodeEnvelope:encoded]; @@ -240,12 +219,10 @@ void checkEncodeDecode(id value) { } TEST(FlutterStandardCodec, HandlesErrorEnvelopes) { - FlutterStandardMethodCodec* codec = - [FlutterStandardMethodCodec sharedInstance]; + FlutterStandardMethodCodec* codec = [FlutterStandardMethodCodec sharedInstance]; NSDictionary* details = @{ @"a" : @42, @42 : @"a" }; - FlutterError* error = [FlutterError errorWithCode:@"errorCode" - message:@"something failed" - details:details]; + FlutterError* error = + [FlutterError errorWithCode:@"errorCode" message:@"something failed" details:details]; NSData* encoded = [codec encodeErrorEnvelope:error]; id decoded = [codec decodeEnvelope:encoded]; ASSERT_TRUE([decoded isEqual:error]); diff --git a/shell/platform/darwin/ios/framework/Source/platform_message_router.mm b/shell/platform/darwin/ios/framework/Source/platform_message_router.mm index fb6413c70c8e6..8dee005f3411d 100644 --- a/shell/platform/darwin/ios/framework/Source/platform_message_router.mm +++ b/shell/platform/darwin/ios/framework/Source/platform_message_router.mm @@ -14,8 +14,7 @@ PlatformMessageRouter::~PlatformMessageRouter() = default; -void PlatformMessageRouter::HandlePlatformMessage( - ftl::RefPtr message) { +void PlatformMessageRouter::HandlePlatformMessage(ftl::RefPtr message) { ftl::RefPtr completer = message->response(); auto it = message_handlers_.find(message->channel()); if (it != message_handlers_.end()) { @@ -40,9 +39,8 @@ } } -void PlatformMessageRouter::SetMessageHandler( - const std::string& channel, - FlutterBinaryMessageHandler handler) { +void PlatformMessageRouter::SetMessageHandler(const std::string& channel, + FlutterBinaryMessageHandler handler) { if (handler) message_handlers_[channel] = [handler copy]; else { diff --git a/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.mm b/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.mm index 38a76f51a95dd..060bc68f56ddf 100644 --- a/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.mm +++ b/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.mm @@ -27,14 +27,12 @@ - (instancetype)init { self = [super init]; if (self) { - _displayLink = [[CADisplayLink - displayLinkWithTarget:self - selector:@selector(onDisplayLink:)] retain]; + _displayLink = + [[CADisplayLink displayLinkWithTarget:self selector:@selector(onDisplayLink:)] retain]; _displayLink.paused = YES; blink::Threads::UI()->PostTask([client = [self retain]]() { - [client->_displayLink addToRunLoop:[NSRunLoop currentRunLoop] - forMode:NSRunLoopCommonModes]; + [client->_displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes]; [client release]; }); } diff --git a/shell/platform/darwin/ios/ios_gl_context.mm b/shell/platform/darwin/ios/ios_gl_context.mm index 5e44fa01b4fc5..4bb90aed433dc 100644 --- a/shell/platform/darwin/ios/ios_gl_context.mm +++ b/shell/platform/darwin/ios/ios_gl_context.mm @@ -12,13 +12,11 @@ return; \ }; -IOSGLContext::IOSGLContext(PlatformView::SurfaceConfig config, - CAEAGLLayer* layer) +IOSGLContext::IOSGLContext(PlatformView::SurfaceConfig config, CAEAGLLayer* layer) : layer_([layer retain]), context_([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]), - resource_context_([[EAGLContext alloc] - initWithAPI:kEAGLRenderingAPIOpenGLES2 - sharegroup:context_.get().sharegroup]), + resource_context_([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2 + sharegroup:context_.get().sharegroup]), framebuffer_(GL_NONE), colorbuffer_(GL_NONE), depthbuffer_(GL_NONE), @@ -53,8 +51,7 @@ glBindRenderbuffer(GL_RENDERBUFFER, colorbuffer_); VERIFY(glGetError() == GL_NO_ERROR); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, - GL_RENDERBUFFER, colorbuffer_); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorbuffer_); VERIFY(glGetError() == GL_NO_ERROR); // On iOS, if both depth and stencil attachments are requested, we are @@ -67,10 +64,10 @@ glBindRenderbuffer(GL_RENDERBUFFER, depth_stencil_packed_buffer_); VERIFY(depth_stencil_packed_buffer_ != GL_NONE); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, - GL_RENDERBUFFER, depth_stencil_packed_buffer_); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, - GL_RENDERBUFFER, depth_stencil_packed_buffer_); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, + depth_stencil_packed_buffer_); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, + depth_stencil_packed_buffer_); VERIFY(depth_stencil_packed_buffer_ != GL_NONE); } else { // Setup the depth attachment if necessary @@ -81,8 +78,7 @@ glBindRenderbuffer(GL_RENDERBUFFER, depthbuffer_); VERIFY(glGetError() == GL_NO_ERROR); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, - GL_RENDERBUFFER, depthbuffer_); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthbuffer_); VERIFY(glGetError() == GL_NO_ERROR); } @@ -94,8 +90,8 @@ glBindRenderbuffer(GL_RENDERBUFFER, stencilbuffer_); VERIFY(glGetError() == GL_NO_ERROR); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, - GL_RENDERBUFFER, stencilbuffer_); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, + stencilbuffer_); VERIFY(glGetError() == GL_NO_ERROR); } } @@ -139,8 +135,7 @@ GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT, }; - glDiscardFramebufferEXT(GL_FRAMEBUFFER, sizeof(discards) / sizeof(GLenum), - discards); + glDiscardFramebufferEXT(GL_FRAMEBUFFER, sizeof(discards) / sizeof(GLenum), discards); glBindRenderbuffer(GL_RENDERBUFFER, colorbuffer_); return [[EAGLContext currentContext] presentRenderbuffer:GL_RENDERBUFFER]; @@ -152,8 +147,7 @@ const GLint size_width = layer_size.width; const GLint size_height = layer_size.height; - if (size_width == storage_size_width_ && - size_height == storage_size_height_) { + if (size_width == storage_size_width_ && size_height == storage_size_height_) { // Nothing to since the stoage size is already consistent with the layer. return true; } @@ -169,8 +163,7 @@ glBindRenderbuffer(GL_RENDERBUFFER, colorbuffer_); FTL_DCHECK(glGetError() == GL_NO_ERROR); - if (![context_.get() renderbufferStorage:GL_RENDERBUFFER - fromDrawable:layer_.get()]) { + if (![context_.get() renderbufferStorage:GL_RENDERBUFFER fromDrawable:layer_.get()]) { return false; } @@ -182,12 +175,10 @@ depth_stencil_packed_buffer_ != GL_NONE) { // Fetch the dimensions of the color buffer whose backing was just updated // so that backing of the attachments can be updated - glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, - &width); + glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &width); FTL_DCHECK(glGetError() == GL_NO_ERROR); - glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, - &height); + glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &height); FTL_DCHECK(glGetError() == GL_NO_ERROR); rebind_color_buffer = true; @@ -195,8 +186,7 @@ if (depth_stencil_packed_buffer_ != GL_NONE) { glBindRenderbuffer(GL_RENDERBUFFER, depth_stencil_packed_buffer_); - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, width, - height); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, width, height); FTL_DCHECK(glGetError() == GL_NO_ERROR); } @@ -220,15 +210,13 @@ storage_size_width_ = width; storage_size_height_ = height; - FTL_DCHECK(glCheckFramebufferStatus(GL_FRAMEBUFFER) == - GL_FRAMEBUFFER_COMPLETE); + FTL_DCHECK(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE); return true; } bool IOSGLContext::MakeCurrent() { - return UpdateStorageSizeIfNecessary() && - [EAGLContext setCurrentContext:context_.get()]; + return UpdateStorageSizeIfNecessary() && [EAGLContext setCurrentContext:context_.get()]; } bool IOSGLContext::ResourceMakeCurrent() { diff --git a/shell/platform/darwin/ios/ios_surface.mm b/shell/platform/darwin/ios/ios_surface.mm index f231e2f8a6de0..91067838330f6 100644 --- a/shell/platform/darwin/ios/ios_surface.mm +++ b/shell/platform/darwin/ios/ios_surface.mm @@ -13,13 +13,11 @@ namespace shell { -std::unique_ptr IOSSurface::Create( - PlatformView::SurfaceConfig surface_config, - CALayer* layer) { +std::unique_ptr IOSSurface::Create(PlatformView::SurfaceConfig surface_config, + CALayer* layer) { // Check if we can use OpenGL. if ([layer isKindOfClass:[CAEAGLLayer class]]) { - return std::make_unique( - surface_config, reinterpret_cast(layer)); + return std::make_unique(surface_config, reinterpret_cast(layer)); } // If we ever support the metal rendering API, a check for CAMetalLayer would @@ -29,8 +27,7 @@ return std::make_unique(surface_config, layer); } -IOSSurface::IOSSurface(PlatformView::SurfaceConfig surface_config, - CALayer* layer) +IOSSurface::IOSSurface(PlatformView::SurfaceConfig surface_config, CALayer* layer) : surface_config_(surface_config), layer_([layer retain]) {} IOSSurface::~IOSSurface() = default; diff --git a/shell/platform/darwin/ios/ios_surface_gl.mm b/shell/platform/darwin/ios/ios_surface_gl.mm index 8c9d5c6611617..d152521c3fee2 100644 --- a/shell/platform/darwin/ios/ios_surface_gl.mm +++ b/shell/platform/darwin/ios/ios_surface_gl.mm @@ -8,8 +8,7 @@ namespace shell { -IOSSurfaceGL::IOSSurfaceGL(PlatformView::SurfaceConfig surface_config, - CAEAGLLayer* layer) +IOSSurfaceGL::IOSSurfaceGL(PlatformView::SurfaceConfig surface_config, CAEAGLLayer* layer) : IOSSurface(surface_config, reinterpret_cast(layer)), context_(surface_config, layer) {} diff --git a/shell/platform/darwin/ios/ios_surface_software.mm b/shell/platform/darwin/ios/ios_surface_software.mm index f0c651d3fbf10..53c8e1c3baa16 100644 --- a/shell/platform/darwin/ios/ios_surface_software.mm +++ b/shell/platform/darwin/ios/ios_surface_software.mm @@ -14,9 +14,7 @@ namespace shell { -IOSSurfaceSoftware::IOSSurfaceSoftware( - PlatformView::SurfaceConfig surface_config, - CALayer* layer) +IOSSurfaceSoftware::IOSSurfaceSoftware(PlatformView::SurfaceConfig surface_config, CALayer* layer) : IOSSurface(surface_config, layer) { UpdateStorageSizeIfNecessary(); } @@ -63,8 +61,8 @@ return sk_surface_; } - sk_surface_ = SkSurface::MakeRasterN32Premul( - size.fWidth, size.fHeight, nullptr /* SkSurfaceProps as out */); + sk_surface_ = SkSurface::MakeRasterN32Premul(size.fWidth, size.fHeight, + nullptr /* SkSurfaceProps as out */); return sk_surface_; } diff --git a/shell/platform/darwin/ios/platform_view_ios.mm b/shell/platform/darwin/ios/platform_view_ios.mm index c3a0960c35236..8cdf7ced7a493 100644 --- a/shell/platform/darwin/ios/platform_view_ios.mm +++ b/shell/platform/darwin/ios/platform_view_ios.mm @@ -18,8 +18,7 @@ namespace shell { PlatformViewIOS::PlatformViewIOS(CALayer* layer) - : PlatformView( - std::make_unique(std::make_unique())), + : PlatformView(std::make_unique(std::make_unique())), ios_surface_(IOSSurface::Create(surface_config_, layer)), weak_factory_(this) { CreateEngine(); @@ -43,10 +42,9 @@ SetSemanticsEnabled(enabled); } -void PlatformViewIOS::SetupAndLoadFromSource( - const std::string& assets_directory, - const std::string& main, - const std::string& packages) { +void PlatformViewIOS::SetupAndLoadFromSource(const std::string& assets_directory, + const std::string& main, + const std::string& packages) { blink::Threads::UI()->PostTask( [ engine = engine().GetWeakPtr(), assets_directory, main, packages ] { if (engine) @@ -74,18 +72,15 @@ } bool PlatformViewIOS::ResourceContextMakeCurrent() { - return ios_surface_ != nullptr ? ios_surface_->ResourceContextMakeCurrent() - : false; + return ios_surface_ != nullptr ? ios_surface_->ResourceContextMakeCurrent() : false; } -void PlatformViewIOS::UpdateSemantics( - std::vector update) { +void PlatformViewIOS::UpdateSemantics(std::vector update) { if (accessibility_bridge_) accessibility_bridge_->UpdateSemantics(std::move(update)); } -void PlatformViewIOS::HandlePlatformMessage( - ftl::RefPtr message) { +void PlatformViewIOS::HandlePlatformMessage(ftl::RefPtr message) { platform_message_router_.HandlePlatformMessage(std::move(message)); }