From 3ec84538cade621f3c041d3d058b16c86a661e40 Mon Sep 17 00:00:00 2001 From: Juanjo Tugores Date: Thu, 2 May 2024 14:27:23 -0700 Subject: [PATCH] Put the view focus functionality behind a (disabled by default) flag (flutter/engine#52527) Put the view focus functionality behind a (disabled by default) flag Should unblock https://github.com/flutter/flutter/pull/143259 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- .../platform_dispatcher/view_focus_binding.dart | 15 +++++++++++++++ .../view_focus_binding_test.dart | 8 ++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/platform_dispatcher/view_focus_binding.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/platform_dispatcher/view_focus_binding.dart index 4ec1585463..3a10c4ab72 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/platform_dispatcher/view_focus_binding.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/platform_dispatcher/view_focus_binding.dart @@ -3,6 +3,7 @@ // found in the LICENSE file. import 'dart:async'; +import 'package:meta/meta.dart'; import 'package:ui/src/engine.dart'; import 'package:ui/ui.dart' as ui; @@ -10,6 +11,13 @@ import 'package:ui/ui.dart' as ui; final class ViewFocusBinding { ViewFocusBinding(this._viewManager, this._onViewFocusChange); + + /// Wether [FlutterView] focus changes will be reported and performed. + /// + /// DO NOT rely on this bit as it will go away soon. You're warned :)! + @visibleForTesting + static bool isEnabled = false; + final FlutterViewManager _viewManager; final ui.ViewFocusChangeCallback _onViewFocusChange; @@ -35,6 +43,9 @@ final class ViewFocusBinding { } void changeViewFocus(int viewId, ui.ViewFocusState state) { + if (!isEnabled) { + return; + } final DomElement? viewElement = _viewManager[viewId]?.dom.rootElement; if (state == ui.ViewFocusState.focused) { @@ -69,6 +80,10 @@ final class ViewFocusBinding { }); void _handleFocusChange(DomElement? focusedElement) { + if (!isEnabled) { + return; + } + final int? viewId = _viewId(focusedElement); if (viewId == _lastViewId) { return; diff --git a/engine/src/flutter/lib/web_ui/test/engine/platform_dispatcher/view_focus_binding_test.dart b/engine/src/flutter/lib/web_ui/test/engine/platform_dispatcher/view_focus_binding_test.dart index 419de687ac..b2f947bd7c 100644 --- a/engine/src/flutter/lib/web_ui/test/engine/platform_dispatcher/view_focus_binding_test.dart +++ b/engine/src/flutter/lib/web_ui/test/engine/platform_dispatcher/view_focus_binding_test.dart @@ -17,14 +17,18 @@ void testMain() { late EnginePlatformDispatcher dispatcher; setUp(() { - domDocument.activeElement?.blur(); - EngineSemantics.instance.semanticsEnabled = false; + ViewFocusBinding.isEnabled = true; dispatcher = EnginePlatformDispatcher.instance; dispatchedViewFocusEvents = []; dispatcher.onViewFocusChange = dispatchedViewFocusEvents.add; }); + tearDown(() { + ViewFocusBinding.isEnabled = false; + EngineSemantics.instance.semanticsEnabled = false; + }); + test('The view is focusable and reachable by keyboard when registered', () async { final EngineFlutterView view = createAndRegisterView(dispatcher);