Skip to content

Commit

Permalink
Update Objective-C column limit to 100 (flutter#3585)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbracken authored Apr 11, 2017
1 parent 1084a83 commit f5a7a08
Show file tree
Hide file tree
Showing 29 changed files with 333 additions and 537 deletions.
3 changes: 3 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 9 additions & 12 deletions fml/platform/darwin/message_loop_darwin.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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<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);
}
Expand All @@ -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.
Expand All @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions fml/platform/darwin/paths_darwin.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
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
Expand Down
4 changes: 2 additions & 2 deletions fml/platform/darwin/resource_mapping_darwin.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
48 changes: 17 additions & 31 deletions shell/platform/darwin/common/platform_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
Expand All @@ -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() {}
Expand All @@ -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<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);
});
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
38 changes: 16 additions & 22 deletions shell/platform/darwin/desktop/flutter_window.mm
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ @interface FlutterWindow ()<NSWindowDelegate>

@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;
Expand Down Expand Up @@ -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<shell::GPUSurfaceGL>(_platformView.get()));
_platformView->NotifyCreated(std::make_unique<shell::GPUSurfaceGL>(_platformView.get()));
}

// TODO(eseidel): This does not belong in flutter_window!
Expand All @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions shell/platform/darwin/desktop/main_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
40 changes: 17 additions & 23 deletions shell/platform/darwin/desktop/platform_view_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading

0 comments on commit f5a7a08

Please sign in to comment.