Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply reviewer suggestions
  • Loading branch information
tugorez committed Mar 7, 2024
commit 87ddd10a7872b87dbf0d6a21d343ba610f46c0d7
18 changes: 3 additions & 15 deletions lib/web_ui/lib/src/engine/platform_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
HighContrastSupport.instance.addListener(_updateHighContrast);
_addFontSizeObserver();
_addLocaleChangedListener();
_addViewFocusChangeListener();
registerHotRestartListener(dispose);
AppLifecycleState.instance.addListener(_setAppLifecycleState);
_viewFocusBinding.init();
domDocument.body?.append(accessibilityPlaceholder);
_onViewDisposedListener = viewManager.onViewDisposed.listen((_) {
// Send a metrics changed event to the framework when a view is disposed.
Expand Down Expand Up @@ -121,7 +121,6 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
_removeBrightnessMediaQueryListener();
_disconnectFontSizeObserver();
_removeLocaleChangedListener();
_removeViewFocusChangeListener();
HighContrastSupport.instance.removeListener(_updateHighContrast);
AppLifecycleState.instance.removeListener(_setAppLifecycleState);
_viewFocusBinding.dispose();
Expand Down Expand Up @@ -229,17 +228,8 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
}
}

late final ViewFocusBinding _viewFocusBinding = ViewFocusBinding(viewManager);
StreamSubscription<ui.ViewFocusEvent>? _onViewFocusChangeSubscription;

void _addViewFocusChangeListener() {
_onViewFocusChangeSubscription = _viewFocusBinding.onViewFocusChange.listen(
invokeOnViewFocusChange,
);
}
void _removeViewFocusChangeListener() {
_onViewFocusChangeSubscription?.cancel();
}
late final ViewFocusBinding _viewFocusBinding =
ViewFocusBinding(viewManager, invokeOnViewFocusChange);

@override
ui.ViewFocusChangeCallback? get onViewFocusChange => _onViewFocusChange;
Expand All @@ -261,7 +251,6 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
);
}


@override
void requestViewFocusChange({
required int viewId,
Expand All @@ -271,7 +260,6 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
// TODO(tugorez): implement this method. At the moment will be a no op call.
}


/// A set of views which have rendered in the current `onBeginFrame` or
/// `onDrawFrame` scope.
Set<ui.FlutterView>? _viewsRenderedInCurrentFrame;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,17 @@ import 'package:ui/ui.dart' as ui;
/// Tracks the [FlutterView]s focus changes.
final class ViewFocusBinding {
/// Creates a [ViewFocusBinding] instance.
ViewFocusBinding(this._viewManager) {
_init();
}
ViewFocusBinding(this._viewManager, this._onViewFocusChange);

final FlutterViewManager _viewManager;

Stream<ui.ViewFocusEvent> get onViewFocusChange => _onViewFocusChangeController.stream;
final StreamController<ui.ViewFocusEvent> _onViewFocusChangeController =
StreamController<ui.ViewFocusEvent>.broadcast(sync: true);

StreamSubscription<int>? _onViewCreatedListener;
final ui.ViewFocusChangeCallback _onViewFocusChange;

int? _lastViewId;
ui.ViewFocusDirection _viewFocusDirection = ui.ViewFocusDirection.forward;

void _init() {
StreamSubscription<int>? _onViewCreatedListener;

void init() {
domDocument.body?.addEventListener(_keyDown, _handleKeyDown);
domDocument.body?.addEventListener(_keyUp, _handleKeyUp);
domDocument.body?.addEventListener(_focusin, _handleFocusin);
Expand Down Expand Up @@ -84,7 +79,7 @@ final class ViewFocusBinding {
_markViewAsFocusable(_lastViewId, reachableByKeyboard: true);
_markViewAsFocusable(viewId, reachableByKeyboard: false);
_lastViewId = viewId;
_onViewFocusChangeController.add(event);
_onViewFocusChange(event);
}

int? _viewId(DomElement? element) {
Expand Down