提交 f5a7a086 编写于 作者: C Chris Bracken 提交者: GitHub

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
上级 1084a83f
......@@ -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
......@@ -19,12 +19,12 @@ MessageLoopDarwin::MessageLoopDarwin()
CFRunLoopTimerContext timer_context = {
.info = this,
};
delayed_wake_timer_.Reset(CFRunLoopTimerCreate(
kCFAllocatorDefault, kDistantFuture /* fire date */,
HUGE_VAL /* interval */, 0 /* flags */, 0 /* order */,
reinterpret_cast<CFRunLoopTimerCallBack>(&MessageLoopDarwin::OnTimerFire)
/* callout */,
&timer_context /* context */));
delayed_wake_timer_.Reset(
CFRunLoopTimerCreate(kCFAllocatorDefault, kDistantFuture /* fire date */,
HUGE_VAL /* interval */, 0 /* flags */, 0 /* order */,
reinterpret_cast<CFRunLoopTimerCallBack>(&MessageLoopDarwin::OnTimerFire)
/* callout */,
&timer_context /* context */));
FTL_DCHECK(delayed_wake_timer_ != nullptr);
CFRunLoopAddTimer(loop_, delayed_wake_timer_, kCFRunLoopCommonModes);
}
......@@ -41,8 +41,7 @@ void MessageLoopDarwin::Run() {
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 @@ void MessageLoopDarwin::WakeUp(ftl::TimePoint time_point) {
// 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();
......
......@@ -12,8 +12,7 @@ namespace fml {
namespace paths {
std::pair<bool, std::string> GetExecutableDirectoryPath() {
return {true, files::GetDirectoryName(
[NSBundle mainBundle].executablePath.UTF8String)};
return {true, files::GetDirectoryName([NSBundle mainBundle].executablePath.UTF8String)};
}
} // namespace paths
......
......@@ -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;
......
......@@ -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 ftl::CommandLine InitializedCommandLine() {
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 @@ class EmbedderState {
// 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 @@ class EmbedderState {
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<EmbedderState> g_embedder;
static std::once_flag once_main;
std::call_once(once_main, [&]() {
g_embedder =
WTF::MakeUnique<EmbedderState>(icu_data_path, application_library_path);
g_embedder = WTF::MakeUnique<EmbedderState>(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;
}
......
......@@ -15,8 +15,7 @@
@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 @@ static inline blink::PointerData::Change PointerChangeFromNSEventPhase(
}
- (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<shell::GPUSurfaceGL>(_platformView.get()));
_platformView->NotifyCreated(std::make_unique<shell::GPUSurfaceGL>(_platformView.get()));
}
// TODO(eseidel): This does not belong in flutter_window!
......@@ -81,12 +78,11 @@ static inline blink::PointerData::Change PointerChangeFromNSEventPhase(
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 @@ static inline blink::PointerData::Change PointerChangeFromNSEventPhase(
#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 @@ static inline blink::PointerData::Change PointerChangeFromNSEventPhase(
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 {
......
......@@ -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();
......
......@@ -20,12 +20,10 @@
namespace shell {
PlatformViewMac::PlatformViewMac(NSOpenGLView* gl_view)
: PlatformView(
std::make_unique<GPURasterizer>(std::make_unique<ProcessInfoMac>())),
: PlatformView(std::make_unique<GPURasterizer>(std::make_unique<ProcessInfoMac>())),
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 @@ void PlatformViewMac::SetupAndLoadDart() {
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)
......
......@@ -10,15 +10,14 @@
// 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.
......
......@@ -14,16 +14,13 @@
+ (instancetype)messageChannelWithName:(NSString*)name
binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger {
NSObject<FlutterMessageCodec>* 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<FlutterBinaryMessenger>*)messenger
codec:(NSObject<FlutterMessageCodec>*)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)setMessageHandler:(FlutterMessageHandler)handler {
if (!handler) {
[_messenger setBinaryMessageHandlerOnChannel:_name
binaryMessageHandler:nil];
[_messenger setBinaryMessageHandlerOnChannel:_name binaryMessageHandler:nil];
return;
}
FlutterBinaryMessageHandler messageHandler =
......@@ -70,25 +66,18 @@
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 @@
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 @@
@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 @@
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 @@ NSObject const* FlutterMethodNotImplemented = [NSObject new];
}
+ (instancetype)methodChannelWithName:(NSString*)name
binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger {
binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger {
NSObject<FlutterMethodCodec>* 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<FlutterBinaryMessenger>*)messenger
codec:(NSObject<FlutterMethodCodec>*)codec {
return [[[FlutterMethodChannel alloc] initWithName:name
binaryMessenger:messenger
codec:codec] autorelease];
binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger
codec:(NSObject<FlutterMethodCodec>*)codec {
return [[[FlutterMethodChannel alloc] initWithName:name binaryMessenger:messenger codec:codec]
autorelease];
}
- (instancetype)initWithName:(NSString*)name
......@@ -218,36 +199,29 @@ NSObject const* FlutterMethodNotImplemented = [NSObject new];
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 @@ NSObject const* FlutterEndOfEventStream = [NSObject new];
NSObject<FlutterMethodCodec>* _codec;
}
+ (instancetype)eventChannelWithName:(NSString*)name
binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger {
binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger {
NSObject<FlutterMethodCodec>* 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<FlutterBinaryMessenger>*)messenger
codec:(NSObject<FlutterMethodCodec>*)codec {
return [[[FlutterEventChannel alloc] initWithName:name
binaryMessenger:messenger
codec:codec] autorelease];
binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger
codec:(NSObject<FlutterMethodCodec>*)codec {
return [[[FlutterEventChannel alloc] initWithName:name binaryMessenger:messenger codec:codec]
autorelease];
}
- (instancetype)initWithName:(NSString*)name
......@@ -289,25 +260,23 @@ NSObject const* FlutterEndOfEventStream = [NSObject new];
- (void)setStreamHandler:(NSObject<FlutterStreamHandler>*)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 @@ NSObject const* FlutterEndOfEventStream = [NSObject new];
reply(nil);
}
};
[_messenger setBinaryMessageHandlerOnChannel:_name
binaryMessageHandler:messageHandler];
[_messenger setBinaryMessageHandlerOnChannel:_name binaryMessageHandler:messageHandler];
}
@end
......@@ -41,8 +41,7 @@
- (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 @@
- (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 @@
- (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 @@
- (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 {
......
......@@ -79,8 +79,7 @@ static NSURL* URLForSwitch(const char* name) {
self = [super init];
if (self) {
_dartSource = [[FlutterDartSource alloc]
initWithFLXArchiveWithScriptSnapshot:archiveURL];
_dartSource = [[FlutterDartSource alloc] initWithFLXArchiveWithScriptSnapshot:archiveURL];
[self checkReadiness];
}
......@@ -117,14 +116,10 @@ static NSURL* URLForSwitch(const char* name) {
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 @@ static NSString* NSStringFromVMType(VMType type) {
}
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 @@ static NSString* NSStringFromVMType(VMType type) {
#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 @@ static NSString* NSStringFromVMType(VMType type) {
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;
......
......@@ -31,10 +31,8 @@
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 @@
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;
}
......
......@@ -14,8 +14,7 @@ namespace {
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 @@ using namespace shell;
@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 @@ using namespace shell;
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 @@ using namespace shell;
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 @@ using namespace shell;
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 @@ using namespace shell;
- (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"];
}
......
......@@ -27,8 +27,7 @@
- (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 @@
}
- (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 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 @@ using namespace shell;
@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 @@ using namespace shell;
}
+ (instancetype)writerWithData:(NSMutableData*)data {
FlutterStandardWriter* writer =
[[FlutterStandardWriter alloc] initWithData:data];
FlutterStandardWriter* writer = [[FlutterStandardWriter alloc] initWithData:data];
[writer autorelease];
return writer;
}
......@@ -276,10 +259,8 @@ using namespace shell;
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 @@ using namespace shell;
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 @@ using namespace shell;
}
+ (instancetype)readerWithData:(NSData*)data {
FlutterStandardReader* reader =
[[FlutterStandardReader alloc] initWithData:data];
FlutterStandardReader* reader = [[FlutterStandardReader alloc] initWithData:data];
[reader autorelease];
return reader;
}
......@@ -413,8 +391,7 @@ using namespace shell;
- (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 @@ using namespace shell;
}
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];
......
......@@ -188,8 +188,7 @@ static UIKeyboardType ToUIKeyboardType(NSString* inputType) {
[_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];
......
......@@ -60,10 +60,9 @@ void SnapshotRasterizer(ftl::WeakPtr<shell::Rasterizer> 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<shell::Rasterizer> 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. */);
}
......
......@@ -41,14 +41,11 @@ class PlatformMessageResponseDarwin : public blink::PlatformMessageResponse {
void CompleteEmpty() override {
ftl::RefPtr<PlatformMessageResponseDarwin> 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<PlatformMessageResponseCallback> callback_;
......@@ -56,8 +53,7 @@ class PlatformMessageResponseDarwin : public blink::PlatformMessageResponse {
} // namespace
@interface FlutterViewController ()<UIAlertViewDelegate,
FlutterTextInputDelegate>
@interface FlutterViewController ()<UIAlertViewDelegate, FlutterTextInputDelegate>
@end
@implementation FlutterViewController {
......@@ -93,8 +89,7 @@ class PlatformMessageResponseDarwin : public blink::PlatformMessageResponse {
if (self) {
if (project == nil)
_dartProject.reset(
[[FlutterDartProject alloc] initFromDefaultSourceForConfiguration]);
_dartProject.reset([[FlutterDartProject alloc] initFromDefaultSourceForConfiguration]);
else
_dartProject.reset([project retain]);
......@@ -104,8 +99,7 @@ class PlatformMessageResponseDarwin : public blink::PlatformMessageResponse {
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 @@ class PlatformMessageResponseDarwin : public blink::PlatformMessageResponse {
_orientationPreferences = UIInterfaceOrientationMaskAll;
_statusBarStyle = UIStatusBarStyleDefault;
_platformView = std::make_unique<shell::PlatformViewIOS>(
reinterpret_cast<CAEAGLLayer*>(self.view.layer));
_platformView =
std::make_unique<shell::PlatformViewIOS>(reinterpret_cast<CAEAGLLayer*>(self.view.layer));
_platformView->SetupResourceContextOnIOThread();
_localizationChannel.reset([[FlutterMethodChannel alloc]
......@@ -158,19 +152,16 @@ class PlatformMessageResponseDarwin : public blink::PlatformMessageResponse {
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 @@ class PlatformMessageResponseDarwin : public blink::PlatformMessageResponse {
#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 @@ class PlatformMessageResponseDarwin : public blink::PlatformMessageResponse {
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 @@ class PlatformMessageResponseDarwin : public blink::PlatformMessageResponse {
self.view = view;
self.view.multipleTouchEnabled = YES;
self.view.autoresizingMask =
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[view release];
}
......@@ -287,30 +274,23 @@ enum MapperPhase {
Removed,
};
using PointerChangeMapperPhase =
std::pair<blink::PointerData::Change, MapperPhase>;
static inline PointerChangeMapperPhase PointerChangePhaseFromUITouchPhase(
UITouchPhase phase) {
using PointerChangeMapperPhase = std::pair<blink::PointerData::Change, MapperPhase>;
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 @@ static inline PointerChangeMapperPhase PointerChangePhaseFromUITouchPhase(
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 @@ static inline PointerChangeMapperPhase PointerChangePhaseFromUITouchPhase(
#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 @@ static inline PointerChangeMapperPhase PointerChangePhaseFromUITouchPhase(
- (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 @@ static inline PointerChangeMapperPhase PointerChangePhaseFromUITouchPhase(
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 @@ constexpr CGFloat kStandardStatusBarHeight = 20.0;
channelName:(NSString*)channel
binaryReplyHandler:(FlutterBinaryReplyHandler)callback {
NSAssert(channel, @"The channel must not be null");
ftl::RefPtr<PlatformMessageResponseDarwin> response = (callback == nil)
? nullptr
: ftl::MakeRefCounted<PlatformMessageResponseDarwin>(^(NSData* reply) {
callback(reply);
});
ftl::RefPtr<blink::PlatformMessage> platformMessage = (message == nil)
? ftl::MakeRefCounted<blink::PlatformMessage>(channel.UTF8String, response)
: ftl::MakeRefCounted<blink::PlatformMessage>(channel.UTF8String,
shell::GetVectorFromNSData(message), response);
ftl::RefPtr<PlatformMessageResponseDarwin> response =
(callback == nil) ? nullptr
: ftl::MakeRefCounted<PlatformMessageResponseDarwin>(^(NSData* reply) {
callback(reply);
});
ftl::RefPtr<blink::PlatformMessage> platformMessage =
(message == nil) ? ftl::MakeRefCounted<blink::PlatformMessage>(channel.UTF8String, response)
: ftl::MakeRefCounted<blink::PlatformMessage>(
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
......@@ -4,13 +4,13 @@
#include "flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h"
#include <vector>
#include <utility>
#include <vector>
#import <UIKit/UIKit.h>
#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 @@ blink::SemanticsAction GetSemanticsActionForScrollDirection(
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 @@ blink::SemanticsAction GetSemanticsActionForScrollDirection(
#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 @@ blink::SemanticsAction GetSemanticsActionForScrollDirection(
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 @@ blink::SemanticsAction GetSemanticsActionForScrollDirection(
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 @@ blink::SemanticsAction GetSemanticsActionForScrollDirection(
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 @@ void AccessibilityBridge::UpdateSemantics(std::vector<blink::SemanticsNode> node
} 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 @@ SemanticsObject* AccessibilityBridge::GetOrCreateObject(int32_t uid) {
return object;
}
void AccessibilityBridge::VisitObjectsRecursively(
SemanticsObject* object,
std::unordered_set<int>* visited_objects) {
void AccessibilityBridge::VisitObjectsRecursively(SemanticsObject* object,
std::unordered_set<int>* visited_objects) {
visited_objects->insert(object.uid);
for (SemanticsObject* child : *[object children])
VisitObjectsRecursively(child, visited_objects);
}
void AccessibilityBridge::ReleaseObjects(
const std::unordered_map<int, SemanticsObject*>& objects) {
void AccessibilityBridge::ReleaseObjects(const std::unordered_map<int, SemanticsObject*>& objects) {
for (const auto& entry : objects) {
SemanticsObject* object = entry.second;
[object neuter];
......
......@@ -48,9 +48,7 @@ TEST(FlutterJSONCodec, CanEncodeAndDecodeNil) {
}
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, CanEncodeAndDecodeArray) {
}
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];
......
......@@ -11,10 +11,8 @@ namespace shell {
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
......@@ -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 @@ TEST(FlutterStandardCodec, CanEncodeAndDecodeUInt32) {
}
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 @@ TEST(FlutterStandardCodec, CanEncodeAndDecodeSInt32) {
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 @@ TEST(FlutterStandardCodec, CanEncodeAndDecodeFloat32) {
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 @@ TEST(FlutterStandardCodec, CanEncodeAndDecodeStringWithNonBMPCodePoint) {
}
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 @@ TEST(FlutterStandardCodec, CanEncodeAndDecodeFloat64Array) {
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 @@ TEST(FlutterStandardCodec, HandlesMethodCallsWithArgumentList) {
}
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 @@ TEST(FlutterStandardCodec, HandlesSuccessEnvelopesWithResultMap) {
}
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]);
......
......@@ -14,8 +14,7 @@ PlatformMessageRouter::PlatformMessageRouter() = default;
PlatformMessageRouter::~PlatformMessageRouter() = default;
void PlatformMessageRouter::HandlePlatformMessage(
ftl::RefPtr<blink::PlatformMessage> message) {
void PlatformMessageRouter::HandlePlatformMessage(ftl::RefPtr<blink::PlatformMessage> message) {
ftl::RefPtr<blink::PlatformMessageResponse> completer = message->response();
auto it = message_handlers_.find(message->channel());
if (it != message_handlers_.end()) {
......@@ -40,9 +39,8 @@ void PlatformMessageRouter::HandlePlatformMessage(
}
}
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 {
......
......@@ -27,14 +27,12 @@
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];
});
}
......
......@@ -12,13 +12,11 @@ namespace shell {
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 @@ IOSGLContext::IOSGLContext(PlatformView::SurfaceConfig config,
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 @@ IOSGLContext::IOSGLContext(PlatformView::SurfaceConfig config,
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 @@ IOSGLContext::IOSGLContext(PlatformView::SurfaceConfig config,
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 @@ IOSGLContext::IOSGLContext(PlatformView::SurfaceConfig config,
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 @@ bool IOSGLContext::PresentRenderBuffer() const {
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 @@ bool IOSGLContext::UpdateStorageSizeIfNecessary() {
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 @@ bool IOSGLContext::UpdateStorageSizeIfNecessary() {
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 @@ bool IOSGLContext::UpdateStorageSizeIfNecessary() {
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 @@ bool IOSGLContext::UpdateStorageSizeIfNecessary() {
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 @@ bool IOSGLContext::UpdateStorageSizeIfNecessary() {
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() {
......
......@@ -13,13 +13,11 @@
namespace shell {
std::unique_ptr<IOSSurface> IOSSurface::Create(
PlatformView::SurfaceConfig surface_config,
CALayer* layer) {
std::unique_ptr<IOSSurface> IOSSurface::Create(PlatformView::SurfaceConfig surface_config,
CALayer* layer) {
// Check if we can use OpenGL.
if ([layer isKindOfClass:[CAEAGLLayer class]]) {
return std::make_unique<IOSSurfaceGL>(
surface_config, reinterpret_cast<CAEAGLLayer*>(layer));
return std::make_unique<IOSSurfaceGL>(surface_config, reinterpret_cast<CAEAGLLayer*>(layer));
}
// If we ever support the metal rendering API, a check for CAMetalLayer would
......@@ -29,8 +27,7 @@ std::unique_ptr<IOSSurface> IOSSurface::Create(
return std::make_unique<IOSSurfaceSoftware>(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;
......
......@@ -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<CALayer*>(layer)),
context_(surface_config, layer) {}
......
......@@ -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 @@ sk_sp<SkSurface> IOSSurfaceSoftware::AcquireBackingStore(const SkISize& size) {
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_;
}
......
......@@ -18,8 +18,7 @@
namespace shell {
PlatformViewIOS::PlatformViewIOS(CALayer* layer)
: PlatformView(
std::make_unique<GPURasterizer>(std::make_unique<ProcessInfoMac>())),
: PlatformView(std::make_unique<GPURasterizer>(std::make_unique<ProcessInfoMac>())),
ios_surface_(IOSSurface::Create(surface_config_, layer)),
weak_factory_(this) {
CreateEngine();
......@@ -43,10 +42,9 @@ void PlatformViewIOS::ToggleAccessibility(UIView* view, bool enabled) {
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 @@ VsyncWaiter* PlatformViewIOS::GetVsyncWaiter() {
}
bool PlatformViewIOS::ResourceContextMakeCurrent() {
return ios_surface_ != nullptr ? ios_surface_->ResourceContextMakeCurrent()
: false;
return ios_surface_ != nullptr ? ios_surface_->ResourceContextMakeCurrent() : false;
}
void PlatformViewIOS::UpdateSemantics(
std::vector<blink::SemanticsNode> update) {
void PlatformViewIOS::UpdateSemantics(std::vector<blink::SemanticsNode> update) {
if (accessibility_bridge_)
accessibility_bridge_->UpdateSemantics(std::move(update));
}
void PlatformViewIOS::HandlePlatformMessage(
ftl::RefPtr<blink::PlatformMessage> message) {
void PlatformViewIOS::HandlePlatformMessage(ftl::RefPtr<blink::PlatformMessage> message) {
platform_message_router_.HandlePlatformMessage(std::move(message));
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册