From dbe42683b9236bb2d93620b2ee8c5f0cb3c63bd2 Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Fri, 12 Nov 2021 18:42:29 -0800 Subject: [PATCH] Fix 'google-readability-braces-around-statements' analyzer warning in macOS and iOS (flutter/engine#29723) --- .../flow/display_list_canvas_unittests.cc | 12 ++- .../flutter/flow/display_list_unittests.cc | 3 +- .../darwin/string_range_sanitization.mm | 3 +- engine/src/flutter/lib/ui/window/window.cc | 3 +- engine/src/flutter/runtime/dart_snapshot.cc | 6 +- .../src/flutter/shell/common/platform_view.cc | 3 +- engine/src/flutter/shell/common/rasterizer.cc | 3 +- engine/src/flutter/shell/common/shell.cc | 9 +- .../shell/common/vsync_waiter_fallback.cc | 3 +- .../framework/Source/FlutterChannels.mm | 42 ++++---- .../common/framework/Source/FlutterCodecs.mm | 15 ++- .../framework/Source/FlutterStandardCodec.mm | 12 ++- .../Source/flutter_standard_codec_unittest.mm | 15 +-- .../framework/Source/FlutterPlatformPlugin.mm | 15 +-- .../Source/FlutterTextInputPlugin.mm | 96 ++++++++++++------- .../framework/Source/FlutterViewController.mm | 36 +++---- .../ios/framework/Source/SemanticsObject.mm | 81 ++++++++++------ .../framework/Source/accessibility_bridge.mm | 3 +- .../Source/accessibility_text_entry.mm | 33 ++++--- .../Source/FlutterEmbedderKeyResponder.mm | 6 +- .../FlutterEmbedderKeyResponderUnittests.mm | 3 +- .../Source/FlutterMouseCursorPlugin.mm | 3 +- .../framework/Source/FlutterViewController.mm | 3 +- .../Source/FlutterViewControllerTest.mm | 3 +- 24 files changed, 266 insertions(+), 145 deletions(-) diff --git a/engine/src/flutter/flow/display_list_canvas_unittests.cc b/engine/src/flutter/flow/display_list_canvas_unittests.cc index 9bb35ebd9c..8a4cc37b81 100644 --- a/engine/src/flutter/flow/display_list_canvas_unittests.cc +++ b/engine/src/flutter/flow/display_list_canvas_unittests.cc @@ -1287,14 +1287,18 @@ class CanvasCompareTester { const uint32_t* test_row = test_pixels.addr32(0, y); for (int x = 0; x < width; x++) { if (bounds && test_row[x] != untouched) { - if (minX > x) + if (minX > x) { minX = x; - if (minY > y) + } + if (minY > y) { minY = y; - if (maxX <= x) + } + if (maxX <= x) { maxX = x + 1; - if (maxY <= y) + } + if (maxY <= y) { maxY = y + 1; + } if (!i_bounds.contains(x, y)) { pixels_oob++; } diff --git a/engine/src/flutter/flow/display_list_unittests.cc b/engine/src/flutter/flow/display_list_unittests.cc index 8339a60c91..1c590c7caf 100644 --- a/engine/src/flutter/flow/display_list_unittests.cc +++ b/engine/src/flutter/flow/display_list_unittests.cc @@ -859,8 +859,9 @@ static sk_sp Build(size_t g_index, size_t v_index) { for (size_t i = 0; i < allGroups.size(); i++) { DisplayListInvocationGroup& group = allGroups[i]; size_t j = (i == g_index ? v_index : 0); - if (j >= group.variants.size()) + if (j >= group.variants.size()) { continue; + } DisplayListInvocation& invocation = group.variants[j]; op_count += invocation.op_count(); byte_count += invocation.raw_byte_count(); diff --git a/engine/src/flutter/fml/platform/darwin/string_range_sanitization.mm b/engine/src/flutter/fml/platform/darwin/string_range_sanitization.mm index 8100ba9154..bed509508f 100644 --- a/engine/src/flutter/fml/platform/darwin/string_range_sanitization.mm +++ b/engine/src/flutter/fml/platform/darwin/string_range_sanitization.mm @@ -10,8 +10,9 @@ NSRange RangeForCharacterAtIndex(NSString* text, NSUInteger index) { if (text == nil || index > text.length) { return NSMakeRange(NSNotFound, 0); } - if (index < text.length) + if (index < text.length) { return [text rangeOfComposedCharacterSequenceAtIndex:index]; + } return NSMakeRange(index, 0); } diff --git a/engine/src/flutter/lib/ui/window/window.cc b/engine/src/flutter/lib/ui/window/window.cc index 66f5e2e7db..f02f76503d 100644 --- a/engine/src/flutter/lib/ui/window/window.cc +++ b/engine/src/flutter/lib/ui/window/window.cc @@ -39,8 +39,9 @@ void Window::DispatchPointerDataPacket(const PointerDataPacket& packet) { void Window::DispatchKeyDataPacket(const KeyDataPacket& packet, uint64_t response_id) { std::shared_ptr dart_state = library_.dart_state().lock(); - if (!dart_state) + if (!dart_state) { return; + } tonic::DartState::Scope scope(dart_state); const std::vector& buffer = packet.data(); diff --git a/engine/src/flutter/runtime/dart_snapshot.cc b/engine/src/flutter/runtime/dart_snapshot.cc index 12aab73db5..e567dd58d4 100644 --- a/engine/src/flutter/runtime/dart_snapshot.cc +++ b/engine/src/flutter/runtime/dart_snapshot.cc @@ -250,10 +250,12 @@ const uint8_t* DartSnapshot::GetInstructionsMapping() const { } bool DartSnapshot::IsDontNeedSafe() const { - if (data_ && !data_->IsDontNeedSafe()) + if (data_ && !data_->IsDontNeedSafe()) { return false; - if (instructions_ && !instructions_->IsDontNeedSafe()) + } + if (instructions_ && !instructions_->IsDontNeedSafe()) { return false; + } return true; } diff --git a/engine/src/flutter/shell/common/platform_view.cc b/engine/src/flutter/shell/common/platform_view.cc index 2752a6e5da..dee2fea53f 100644 --- a/engine/src/flutter/shell/common/platform_view.cc +++ b/engine/src/flutter/shell/common/platform_view.cc @@ -113,8 +113,9 @@ void PlatformView::UpdateSemantics(SemanticsNodeUpdates update, void PlatformView::HandlePlatformMessage( std::unique_ptr message) { - if (auto response = message->response()) + if (auto response = message->response()) { response->CompleteEmpty(); + } } void PlatformView::OnPreEngineRestart() const {} diff --git a/engine/src/flutter/shell/common/rasterizer.cc b/engine/src/flutter/shell/common/rasterizer.cc index 9a0dddfa1f..0cd00173ab 100644 --- a/engine/src/flutter/shell/common/rasterizer.cc +++ b/engine/src/flutter/shell/common/rasterizer.cc @@ -272,8 +272,9 @@ sk_sp Rasterizer::DoMakeRasterSnapshot( snapshot_surface = surface_.get(); } else if (snapshot_surface_producer_) { pbuffer_surface = snapshot_surface_producer_->CreateSnapshotSurface(); - if (pbuffer_surface && pbuffer_surface->GetContext()) + if (pbuffer_surface && pbuffer_surface->GetContext()) { snapshot_surface = pbuffer_surface.get(); + } } if (!snapshot_surface) { diff --git a/engine/src/flutter/shell/common/shell.cc b/engine/src/flutter/shell/common/shell.cc index df301e717f..d78f28b406 100644 --- a/engine/src/flutter/shell/common/shell.cc +++ b/engine/src/flutter/shell/common/shell.cc @@ -1212,15 +1212,18 @@ void Shell::HandleEngineSkiaMessage(std::unique_ptr message) { rapidjson::Document document; document.Parse(reinterpret_cast(data.GetMapping()), data.GetSize()); - if (document.HasParseError() || !document.IsObject()) + if (document.HasParseError() || !document.IsObject()) { return; + } auto root = document.GetObject(); auto method = root.FindMember("method"); - if (method->value != "Skia.setResourceCacheMaxBytes") + if (method->value != "Skia.setResourceCacheMaxBytes") { return; + } auto args = root.FindMember("args"); - if (args == root.MemberEnd() || !args->value.IsInt()) + if (args == root.MemberEnd() || !args->value.IsInt()) { return; + } task_runners_.GetRasterTaskRunner()->PostTask( [rasterizer = rasterizer_->GetWeakPtr(), max_bytes = args->value.GetInt(), diff --git a/engine/src/flutter/shell/common/vsync_waiter_fallback.cc b/engine/src/flutter/shell/common/vsync_waiter_fallback.cc index 120e9a7855..cb042c5e08 100644 --- a/engine/src/flutter/shell/common/vsync_waiter_fallback.cc +++ b/engine/src/flutter/shell/common/vsync_waiter_fallback.cc @@ -17,8 +17,9 @@ static fml::TimePoint SnapToNextTick(fml::TimePoint value, fml::TimePoint tick_phase, fml::TimeDelta tick_interval) { fml::TimeDelta offset = (tick_phase - value) % tick_interval; - if (offset != fml::TimeDelta::Zero()) + if (offset != fml::TimeDelta::Zero()) { offset = offset + tick_interval; + } return value + offset; } diff --git a/engine/src/flutter/shell/platform/darwin/common/framework/Source/FlutterChannels.mm b/engine/src/flutter/shell/platform/darwin/common/framework/Source/FlutterChannels.mm index eb03ce6913..9bb6ad0810 100644 --- a/engine/src/flutter/shell/platform/darwin/common/framework/Source/FlutterChannels.mm +++ b/engine/src/flutter/shell/platform/darwin/common/framework/Source/FlutterChannels.mm @@ -61,8 +61,9 @@ static void ResizeChannelBuffer(NSObject* binaryMessenge - (void)sendMessage:(id)message reply:(FlutterReply)callback { FlutterBinaryReply reply = ^(NSData* data) { - if (callback) + if (callback) { callback([_codec decode:data]); + } }; [_messenger sendOnChannel:_name message:[_codec encode:message] binaryReply:reply]; } @@ -118,10 +119,12 @@ static void ResizeChannelBuffer(NSObject* binaryMessenge } - (BOOL)isEqual:(id)object { - if (self == object) + if (self == object) { return YES; - if (![object isKindOfClass:[FlutterError class]]) + } + if (![object isKindOfClass:[FlutterError class]]) { return NO; + } FlutterError* other = (FlutterError*)object; return [self.code isEqual:other.code] && ((!self.message && !other.message) || [self.message isEqual:other.message]) && @@ -154,10 +157,12 @@ static void ResizeChannelBuffer(NSObject* binaryMessenge } - (BOOL)isEqual:(id)object { - if (self == object) + if (self == object) { return YES; - if (![object isKindOfClass:[FlutterMethodCall class]]) + } + if (![object isKindOfClass:[FlutterMethodCall class]]) { return NO; + } FlutterMethodCall* other = (FlutterMethodCall*)object; return [self.method isEqual:[other method]] && ((!self.arguments && !other.arguments) || [self.arguments isEqual:other.arguments]); @@ -242,12 +247,13 @@ NSObject const* FlutterMethodNotImplemented = [NSObject new]; FlutterBinaryMessageHandler messageHandler = ^(NSData* message, FlutterBinaryReply callback) { FlutterMethodCall* call = [codec decodeMethodCall:message]; handler(call, ^(id result) { - if (result == FlutterMethodNotImplemented) + if (result == FlutterMethodNotImplemented) { callback(nil); - else if ([result isKindOfClass:[FlutterError class]]) + } else if ([result isKindOfClass:[FlutterError class]]) { callback([codec encodeErrorEnvelope:(FlutterError*)result]); - else + } else { callback([codec encodeSuccessEnvelope:result]); + } }); }; _connection = [_messenger setMessageHandlerOnChannel:_name binaryMessageHandler:messageHandler]; @@ -309,23 +315,26 @@ static void SetStreamHandlerMessageHandlerOnChannel(NSObject 0) { // Replace text in the marked range with the new text. @@ -1265,8 +1291,9 @@ static BOOL isScribbleAvailable() { } - (void)unmarkText { - if (!self.markedTextRange) + if (!self.markedTextRange) { return; + } self.markedTextRange = nil; if (_enableDeltaModel) { [self updateEditingStateWithDelta:[FlutterTextEditingDelta deltaWithNonText:self.text]]; @@ -1314,11 +1341,13 @@ static BOOL isScribbleAvailable() { } if (offset >= 0) { - for (NSInteger i = 0; i < offset && offsetPosition < self.text.length; ++i) + for (NSInteger i = 0; i < offset && offsetPosition < self.text.length; ++i) { offsetPosition = [self incrementOffsetPosition:offsetPosition]; + } } else { - for (NSInteger i = 0; i < ABS(offset) && offsetPosition > 0; ++i) + for (NSInteger i = 0; i < ABS(offset) && offsetPosition > 0; ++i) { offsetPosition = [self decrementOffsetPosition:offsetPosition]; + } } return [FlutterTextPosition positionWithIndex:offsetPosition]; } @@ -1348,10 +1377,12 @@ static BOOL isScribbleAvailable() { - (NSComparisonResult)comparePosition:(UITextPosition*)position toPosition:(UITextPosition*)other { NSUInteger positionIndex = ((FlutterTextPosition*)position).index; NSUInteger otherIndex = ((FlutterTextPosition*)other).index; - if (positionIndex < otherIndex) + if (positionIndex < otherIndex) { return NSOrderedAscending; - if (positionIndex > otherIndex) + } + if (positionIndex > otherIndex) { return NSOrderedDescending; + } return NSOrderedSame; } @@ -1832,8 +1863,9 @@ static BOOL isScribbleAvailable() { } } - if (!_selectedTextRange.isEmpty) + if (!_selectedTextRange.isEmpty) { [self replaceRange:_selectedTextRange withText:@""]; + } } - (void)postAccessibilityNotification:(UIAccessibilityNotifications)notification target:(id)target { diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index 523a7969c1..ae68d3c089 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -242,8 +242,9 @@ typedef enum UIAccessibilityContrast : NSInteger { #pragma mark - Common view controller initialization tasks - (void)performCommonViewControllerInitialization { - if (_initialized) + if (_initialized) { return; + } _initialized = YES; @@ -803,8 +804,9 @@ static void sendFakeTouchEvent(FlutterEngine* engine, - (void)applicationBecameActive:(NSNotification*)notification { TRACE_EVENT0("flutter", "applicationBecameActive"); self.view.accessibilityElementsHidden = NO; - if (_viewportMetrics.physical_width) + if (_viewportMetrics.physical_width) { [self surfaceUpdated:YES]; + } [self goToApplicationLifecycle:@"AppLifecycleState.resumed"]; } @@ -1424,8 +1426,9 @@ static flutter::PointerData::DeviceKind DeviceKindFromTouchType(UITouch* touch) #else _isVoiceOverRunning = UIAccessibilityIsVoiceOverRunning(); bool enabled = _isVoiceOverRunning || UIAccessibilityIsSwitchControlRunning(); - if (enabled) + if (enabled) { flags |= static_cast(flutter::AccessibilityFeatureFlag::kAccessibleNavigation); + } platformView->SetSemanticsEnabled(enabled || UIAccessibilityIsSpeakScreenEnabled()); platformView->SetAccessibilityFeatures(flags); #endif @@ -1471,32 +1474,33 @@ static flutter::PointerData::DeviceKind DeviceKindFromTouchType(UITouch* touch) // We compute the scale as relative difference from size L (large, the default size), where // L is assumed to have scale 1.0. - if ([category isEqualToString:UIContentSizeCategoryExtraSmall]) + if ([category isEqualToString:UIContentSizeCategoryExtraSmall]) { return xs / l; - else if ([category isEqualToString:UIContentSizeCategorySmall]) + } else if ([category isEqualToString:UIContentSizeCategorySmall]) { return s / l; - else if ([category isEqualToString:UIContentSizeCategoryMedium]) + } else if ([category isEqualToString:UIContentSizeCategoryMedium]) { return m / l; - else if ([category isEqualToString:UIContentSizeCategoryLarge]) + } else if ([category isEqualToString:UIContentSizeCategoryLarge]) { return 1.0; - else if ([category isEqualToString:UIContentSizeCategoryExtraLarge]) + } else if ([category isEqualToString:UIContentSizeCategoryExtraLarge]) { return xl / l; - else if ([category isEqualToString:UIContentSizeCategoryExtraExtraLarge]) + } else if ([category isEqualToString:UIContentSizeCategoryExtraExtraLarge]) { return xxl / l; - else if ([category isEqualToString:UIContentSizeCategoryExtraExtraExtraLarge]) + } else if ([category isEqualToString:UIContentSizeCategoryExtraExtraExtraLarge]) { return xxxl / l; - else if ([category isEqualToString:UIContentSizeCategoryAccessibilityMedium]) + } else if ([category isEqualToString:UIContentSizeCategoryAccessibilityMedium]) { return ax1 / l; - else if ([category isEqualToString:UIContentSizeCategoryAccessibilityLarge]) + } else if ([category isEqualToString:UIContentSizeCategoryAccessibilityLarge]) { return ax2 / l; - else if ([category isEqualToString:UIContentSizeCategoryAccessibilityExtraLarge]) + } else if ([category isEqualToString:UIContentSizeCategoryAccessibilityExtraLarge]) { return ax3 / l; - else if ([category isEqualToString:UIContentSizeCategoryAccessibilityExtraExtraLarge]) + } else if ([category isEqualToString:UIContentSizeCategoryAccessibilityExtraExtraLarge]) { return ax4 / l; - else if ([category isEqualToString:UIContentSizeCategoryAccessibilityExtraExtraExtraLarge]) + } else if ([category isEqualToString:UIContentSizeCategoryAccessibilityExtraExtraExtraLarge]) { return ax5 / l; - else + } else { return 1.0; + } } - (BOOL)isAlwaysUse24HourFormat { diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm index dfdf02a005..e73e776686 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm @@ -439,16 +439,18 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) { #pragma mark - UIAccessibility overrides - (BOOL)isAccessibilityElement { - if (![self isAccessibilityBridgeAlive]) + if (![self isAccessibilityBridgeAlive]) { return false; + } // Note: hit detection will only apply to elements that report // -isAccessibilityElement of YES. The framework will continue scanning the // entire element tree looking for such a hit. // We enforce in the framework that no other useful semantics are merged with these nodes. - if ([self node].HasFlag(flutter::SemanticsFlags::kScopesRoute)) + if ([self node].HasFlag(flutter::SemanticsFlags::kScopesRoute)) { return false; + } // If the node is scrollable AND hidden OR // The node has a label, value, or hint OR @@ -465,8 +467,9 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) { } - (void)collectRoutes:(NSMutableArray*)edges { - if ([self node].HasFlag(flutter::SemanticsFlags::kScopesRoute)) + if ([self node].HasFlag(flutter::SemanticsFlags::kScopesRoute)) { [edges addObject:self]; + } if ([self hasChildren]) { for (SemanticsObject* child in self.children) { [child collectRoutes:edges]; @@ -475,8 +478,9 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) { } - (BOOL)onCustomAccessibilityAction:(FlutterCustomAccessibilityAction*)action { - if (![self node].HasAction(flutter::SemanticsAction::kCustomAction)) + if (![self node].HasAction(flutter::SemanticsAction::kCustomAction)) { return NO; + } int32_t action_id = action.uid; std::vector args; args.push_back(3); // type=int32. @@ -491,8 +495,9 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) { } - (NSString*)accessibilityLabel { - if (![self isAccessibilityBridgeAlive]) + if (![self isAccessibilityBridgeAlive]) { return nil; + } NSString* label = nil; if (![self node].label.empty()) { label = @([self node].label.data()); @@ -506,30 +511,35 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) { - (NSAttributedString*)accessibilityAttributedLabel { NSString* label = [self accessibilityLabel]; - if (label.length == 0) + if (label.length == 0) { return nil; + } return [self createAttributedStringFromString:label withAttributes:[self node].labelAttributes]; } - (NSString*)accessibilityHint { - if (![self isAccessibilityBridgeAlive]) + if (![self isAccessibilityBridgeAlive]) { return nil; + } - if ([self node].hint.empty()) + if ([self node].hint.empty()) { return nil; + } return @([self node].hint.data()); } - (NSAttributedString*)accessibilityAttributedHint { NSString* hint = [self accessibilityHint]; - if (hint.length == 0) + if (hint.length == 0) { return nil; + } return [self createAttributedStringFromString:hint withAttributes:[self node].hintAttributes]; } - (NSString*)accessibilityValue { - if (![self isAccessibilityBridgeAlive]) + if (![self isAccessibilityBridgeAlive]) { return nil; + } if (![self node].value.empty()) { return @([self node].value.data()); @@ -551,14 +561,16 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) { - (NSAttributedString*)accessibilityAttributedValue { NSString* value = [self accessibilityValue]; - if (value.length == 0) + if (value.length == 0) { return nil; + } return [self createAttributedStringFromString:value withAttributes:[self node].valueAttributes]; } - (CGRect)accessibilityFrame { - if (![self isAccessibilityBridgeAlive]) + if (![self isAccessibilityBridgeAlive]) { return CGRectMake(0, 0, 0, 0); + } if ([self node].HasFlag(flutter::SemanticsFlags::kIsHidden)) { return [super accessibilityFrame]; @@ -593,9 +605,10 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) { } if ([self hasChildren] || [self uid] == kRootNodeId) { - if (_container == nil) + if (_container == nil) { _container.reset([[SemanticsObjectContainer alloc] initWithSemanticsObject:self bridge:[self bridge]]); + } return _container.get(); } if ([self parent] == nil) { @@ -610,17 +623,20 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) { #pragma mark - UIAccessibilityAction overrides - (BOOL)accessibilityActivate { - if (![self isAccessibilityBridgeAlive]) + if (![self isAccessibilityBridgeAlive]) { return NO; - if (![self node].HasAction(flutter::SemanticsAction::kTap)) + } + if (![self node].HasAction(flutter::SemanticsAction::kTap)) { return NO; + } [self bridge]->DispatchSemanticsAction([self uid], flutter::SemanticsAction::kTap); return YES; } - (void)accessibilityIncrement { - if (![self isAccessibilityBridgeAlive]) + if (![self isAccessibilityBridgeAlive]) { return; + } if ([self node].HasAction(flutter::SemanticsAction::kIncrease)) { [self node].value = [self node].increasedValue; [self bridge]->DispatchSemanticsAction([self uid], flutter::SemanticsAction::kIncrease); @@ -628,8 +644,9 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) { } - (void)accessibilityDecrement { - if (![self isAccessibilityBridgeAlive]) + if (![self isAccessibilityBridgeAlive]) { return; + } if ([self node].HasAction(flutter::SemanticsAction::kDecrease)) { [self node].value = [self node].decreasedValue; [self bridge]->DispatchSemanticsAction([self uid], flutter::SemanticsAction::kDecrease); @@ -637,20 +654,24 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) { } - (BOOL)accessibilityScroll:(UIAccessibilityScrollDirection)direction { - if (![self isAccessibilityBridgeAlive]) + if (![self isAccessibilityBridgeAlive]) { return NO; + } flutter::SemanticsAction action = GetSemanticsActionForScrollDirection(direction); - if (![self node].HasAction(action)) + if (![self node].HasAction(action)) { return NO; + } [self bridge]->DispatchSemanticsAction([self uid], action); return YES; } - (BOOL)accessibilityPerformEscape { - if (![self isAccessibilityBridgeAlive]) + if (![self isAccessibilityBridgeAlive]) { return NO; - if (![self node].HasAction(flutter::SemanticsAction::kDismiss)) + } + if (![self node].HasAction(flutter::SemanticsAction::kDismiss)) { return NO; + } [self bridge]->DispatchSemanticsAction([self uid], flutter::SemanticsAction::kDismiss); return YES; } @@ -658,8 +679,9 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) { #pragma mark UIAccessibilityFocus overrides - (void)accessibilityElementDidBecomeFocused { - if (![self isAccessibilityBridgeAlive]) + if (![self isAccessibilityBridgeAlive]) { return; + } [self bridge]->AccessibilityObjectDidBecomeFocused([self uid]); if ([self node].HasFlag(flutter::SemanticsFlags::kIsHidden) || [self node].HasFlag(flutter::SemanticsFlags::kIsHeader)) { @@ -672,8 +694,9 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) { } - (void)accessibilityElementDidLoseFocus { - if (![self isAccessibilityBridgeAlive]) + if (![self isAccessibilityBridgeAlive]) { return; + } [self bridge]->AccessibilityObjectDidLoseFocus([self uid]); if ([self node].HasAction(flutter::SemanticsAction::kDidLoseAccessibilityFocus)) { [self bridge]->DispatchSemanticsAction([self uid], @@ -816,29 +839,33 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) { } - (nullable id)accessibilityElementAtIndex:(NSInteger)index { - if (index < 0 || index >= [self accessibilityElementCount]) + if (index < 0 || index >= [self accessibilityElementCount]) { return nil; + } if (index == 0) { return _semanticsObject.nativeAccessibility; } SemanticsObject* child = [_semanticsObject children][index - 1]; - if ([child hasChildren]) + if ([child hasChildren]) { return [child accessibilityContainer]; + } return child.nativeAccessibility; } - (NSInteger)indexOfAccessibilityElement:(id)element { - if (element == _semanticsObject) + if (element == _semanticsObject) { return 0; + } NSArray* children = [_semanticsObject children]; for (size_t i = 0; i < [children count]; i++) { SemanticsObject* child = children[i]; if ((![child hasChildren] && child == element) || - ([child hasChildren] && [child accessibilityContainer] == element)) + ([child hasChildren] && [child accessibilityContainer] == element)) { return i + 1; + } } return NSNotFound; } diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm index 81c4302f0e..8efbd498e1 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm @@ -326,8 +326,9 @@ SemanticsObject* AccessibilityBridge::FindNextFocusableIfNecessary() { SemanticsObject* AccessibilityBridge::FindFirstFocusable(SemanticsObject* parent) { SemanticsObject* currentObject = parent ?: objects_.get()[@(kRootNodeId)]; ; - if (!currentObject) + if (!currentObject) { return nil; + } if (currentObject.isAccessibilityElement) { return currentObject; diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_text_entry.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_text_entry.mm index 2bbddf3f75..edec6680ac 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_text_entry.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_text_entry.mm @@ -237,62 +237,73 @@ static const UIAccessibilityTraits UIAccessibilityTraitUndocumentedEmptyLine = 0 } - (void)accessibilityElementDidBecomeFocused { - if (![self isAccessibilityBridgeAlive]) + if (![self isAccessibilityBridgeAlive]) { return; + } [[self textInputSurrogate] accessibilityElementDidBecomeFocused]; [super accessibilityElementDidBecomeFocused]; } - (void)accessibilityElementDidLoseFocus { - if (![self isAccessibilityBridgeAlive]) + if (![self isAccessibilityBridgeAlive]) { return; + } [[self textInputSurrogate] accessibilityElementDidLoseFocus]; [super accessibilityElementDidLoseFocus]; } - (BOOL)accessibilityElementIsFocused { - if (![self isAccessibilityBridgeAlive]) + if (![self isAccessibilityBridgeAlive]) { return false; + } return [self node].HasFlag(flutter::SemanticsFlags::kIsFocused); } - (BOOL)accessibilityActivate { - if (![self isAccessibilityBridgeAlive]) + if (![self isAccessibilityBridgeAlive]) { return false; + } return [[self textInputSurrogate] accessibilityActivate]; } - (NSString*)accessibilityLabel { - if (![self isAccessibilityBridgeAlive]) + if (![self isAccessibilityBridgeAlive]) { return nil; + } NSString* label = [super accessibilityLabel]; - if (label != nil) + if (label != nil) { return label; + } return [self textInputSurrogate].accessibilityLabel; } - (NSString*)accessibilityHint { - if (![self isAccessibilityBridgeAlive]) + if (![self isAccessibilityBridgeAlive]) { return nil; + } NSString* hint = [super accessibilityHint]; - if (hint != nil) + if (hint != nil) { return hint; + } return [self textInputSurrogate].accessibilityHint; } - (NSString*)accessibilityValue { - if (![self isAccessibilityBridgeAlive]) + if (![self isAccessibilityBridgeAlive]) { return nil; + } NSString* value = [super accessibilityValue]; - if (value != nil) + if (value != nil) { return value; + } return [self textInputSurrogate].accessibilityValue; } - (UIAccessibilityTraits)accessibilityTraits { - if (![self isAccessibilityBridgeAlive]) + if (![self isAccessibilityBridgeAlive]) { return 0; + } // Adding UIAccessibilityTraitKeyboardKey to the trait list so that iOS treats it like // a keyboard entry control, thus adding support for text editing features, such as // pinch to select text, and up/down fling to move cursor. diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterEmbedderKeyResponder.mm b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterEmbedderKeyResponder.mm index bcab9b0ecf..dd65f2e972 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterEmbedderKeyResponder.mm +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterEmbedderKeyResponder.mm @@ -78,8 +78,9 @@ static uint64_t GetPhysicalKeyForKeyCode(unsigned short keyCode) { */ static uint64_t GetLogicalKeyForModifier(unsigned short keyCode, uint64_t hidCode) { NSNumber* fromKeyCode = [keyCodeToLogicalKey objectForKey:@(keyCode)]; - if (fromKeyCode != nil) + if (fromKeyCode != nil) { return fromKeyCode.unsignedLongLongValue; + } return KeyOfPlane(hidCode, kMacosPlane); } @@ -120,8 +121,9 @@ static uint64_t toLower(uint64_t n) { static uint64_t GetLogicalKeyForEvent(NSEvent* event, uint64_t physicalKey) { // Look to see if the keyCode can be mapped from keycode. NSNumber* fromKeyCode = [keyCodeToLogicalKey objectForKey:@(event.keyCode)]; - if (fromKeyCode != nil) + if (fromKeyCode != nil) { return fromKeyCode.unsignedLongLongValue; + } NSString* keyLabel = event.charactersIgnoringModifiers; NSUInteger keyLabelLength = [keyLabel length]; diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterEmbedderKeyResponderUnittests.mm b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterEmbedderKeyResponderUnittests.mm index 4a5cde6558..7e1012569a 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterEmbedderKeyResponderUnittests.mm +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterEmbedderKeyResponderUnittests.mm @@ -51,8 +51,9 @@ } - (void)dealloc { - if (_data->character != nullptr) + if (_data->character != nullptr) { delete[] _data->character; + } delete _data; } @end diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterMouseCursorPlugin.mm b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterMouseCursorPlugin.mm index e73331db17..273f4c3533 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterMouseCursorPlugin.mm +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterMouseCursorPlugin.mm @@ -51,8 +51,9 @@ static NSCursor* GetCursorForKind(NSString* kind) { }; } NSCursor* result = [systemCursors objectForKey:kind]; - if (result == nil) + if (result == nil) { return [NSCursor arrowCursor]; + } return result; } diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm index ffbfa255be..2bd004cc37 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm @@ -404,8 +404,9 @@ static void CommonInit(FlutterViewController* controller) { ([[event window] firstResponder] == weakSelf.flutterView) && ([event modifierFlags] & NSEventModifierFlagCommand) && - ([event type] == NSEventTypeKeyUp)) + ([event type] == NSEventTypeKeyUp)) { [weakSelf keyUp:event]; + } return event; }]; } diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterViewControllerTest.mm b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterViewControllerTest.mm index 1726f79f84..4432da813c 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterViewControllerTest.mm +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterViewControllerTest.mm @@ -518,8 +518,9 @@ TEST(FlutterViewControllerTest, TestKeyboardIsRestartedOnEngineRestart) { + (void)respondFalseForSendEvent:(const FlutterKeyEvent&)event callback:(nullable FlutterKeyEventCallback)callback userData:(nullable void*)userData { - if (callback != nullptr) + if (callback != nullptr) { callback(false, userData); + } } @end