mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Introduce 2 new classes for a11y focus management: * `AccessibilityFocusManager`: a generic class that attaches "focus" and "blur" event handlers, and forwards the events to the framework as `SemanticsAction.didGainAccessibilityFocus` and `SemanticsAction.didLoseAccessibilityFocus` respectively. Provides the `changeFocus` method for the framework to move a11y focus to the target element. * `Focusable`: a role manager that provides generic focus management functionality to `SemanticsObject`s that don't need anything special. Rewrites focus management using the above two classes as follows: * All focusable nodes except text fields and incrementables get the `Focusable` role (all custom focus stuff in `Tappable` was removed and delegated to `Focusable`). * `Incrementable` uses a custom `<input>` internally and so it cannot use the `Focusable` role. Instead, it uses `AccessibilityFocusManager` to manage the focus on the `<input>` element. Behavioral changes: * Fixes https://github.com/flutter/flutter/issues/118737, but more generally fixes all nodes that use the `isFocusable` and `hasFocus` bits. * `Tappable` only partially implemented focusability (e.g. it didn't generate the respective `SemanticsAction` events). Now by delegating to `Focusable`, it will inherit all the functionality. * `Incrementable` and `Checkable` (checkboxes, radios, switches) get focus management features for the first time. * Elements that are not inherently focusable (text, images) can now be focused if semantics requires them to be. * `TextField` is left alone for now as focus and on-screen keyboard interact with each other in non-obvious ways.