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
Revert mixin changes
  • Loading branch information
tugorez committed Mar 7, 2024
commit f3ba20d1f5668ab967c3e974035086d5e089768f
11 changes: 6 additions & 5 deletions lib/web_ui/lib/src/engine/platform_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class HighContrastSupport {
///
/// This is the central entry point for platform messages and configuration
/// events from the platform.
class EnginePlatformDispatcher extends ui.PlatformDispatcher with ViewFocusBinding {
class EnginePlatformDispatcher extends ui.PlatformDispatcher {
/// Private constructor, since only dart:ui is supposed to create one of
/// these.
EnginePlatformDispatcher() {
Expand All @@ -79,7 +79,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher with ViewFocusBindi
_addLocaleChangedListener();
registerHotRestartListener(dispose);
AppLifecycleState.instance.addListener(_setAppLifecycleState);
initViewFocusBindings();
_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 @@ -123,7 +123,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher with ViewFocusBindi
_removeLocaleChangedListener();
HighContrastSupport.instance.removeListener(_updateHighContrast);
AppLifecycleState.instance.removeListener(_setAppLifecycleState);
disposeViewFocusBindings();
_viewFocusBinding.dispose();
accessibilityPlaceholder.remove();
_onViewDisposedListener.cancel();
viewManager.dispose();
Expand Down Expand Up @@ -153,7 +153,6 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher with ViewFocusBindi
EngineFlutterDisplay.instance,
];

@override
late final FlutterViewManager viewManager = FlutterViewManager(this);

/// The current list of windows.
Expand Down Expand Up @@ -229,6 +228,9 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher with ViewFocusBindi
}
}

late final ViewFocusBinding _viewFocusBinding =
ViewFocusBinding(viewManager, invokeOnViewFocusChange);

@override
ui.ViewFocusChangeCallback? get onViewFocusChange => _onViewFocusChange;
ui.ViewFocusChangeCallback? _onViewFocusChange;
Expand All @@ -241,7 +243,6 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher with ViewFocusBindi

// Engine code should use this method instead of the callback directly.
// Otherwise zones won't work properly.
@override
void invokeOnViewFocusChange(ui.ViewFocusEvent viewFocusEvent) {
invoke1<ui.ViewFocusEvent>(
_onViewFocusChange,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,26 @@ import 'package:ui/src/engine.dart';
import 'package:ui/ui.dart' as ui;

/// Tracks the [FlutterView]s focus changes.
mixin ViewFocusBinding {
FlutterViewManager get viewManager;
void invokeOnViewFocusChange(ui.ViewFocusEvent viewFocusEvent);
final class ViewFocusBinding {
ViewFocusBinding(this._viewManager, this._onViewFocusChange);

final FlutterViewManager _viewManager;
final ui.ViewFocusChangeCallback _onViewFocusChange;

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

StreamSubscription<int>? _onViewCreatedListener;

void initViewFocusBindings() {
void init() {
domDocument.body?.addEventListener(_keyDown, _handleKeyDown);
domDocument.body?.addEventListener(_keyUp, _handleKeyUp);
domDocument.body?.addEventListener(_focusin, _handleFocusin);
domDocument.body?.addEventListener(_focusout, _handleFocusout);
_onViewCreatedListener = viewManager.onViewCreated.listen(_handleViewCreated);
_onViewCreatedListener = _viewManager.onViewCreated.listen(_handleViewCreated);
}

void disposeViewFocusBindings() {
void dispose() {
domDocument.body?.removeEventListener(_keyDown, _handleKeyDown);
domDocument.body?.removeEventListener(_keyUp, _handleKeyUp);
domDocument.body?.removeEventListener(_focusin, _handleFocusin);
Expand Down Expand Up @@ -76,15 +78,15 @@ mixin ViewFocusBinding {
_markViewAsFocusable(_lastViewId, reachableByKeyboard: true);
_markViewAsFocusable(viewId, reachableByKeyboard: false);
_lastViewId = viewId;
invokeOnViewFocusChange(event);
_onViewFocusChange(event);
}

int? _viewId(DomElement? element) {
final DomElement? rootElement = element?.closest(DomManager.flutterViewTagName);
if (rootElement == null) {
return null;
}
return viewManager.viewIdForRootElement(rootElement);
return _viewManager.viewIdForRootElement(rootElement);
}

void _handleViewCreated(int viewId) {
Expand All @@ -105,7 +107,7 @@ mixin ViewFocusBinding {
// the flutter view and having it with a zero tabindex messes the focus
// traversal order when pressing tab or shift tab.
final int tabIndex = reachableByKeyboard ? 0 : -1;
viewManager[viewId]?.dom.rootElement.setAttribute('tabindex', tabIndex);
_viewManager[viewId]?.dom.rootElement.setAttribute('tabindex', tabIndex);
}

static const String _focusin = 'focusin';
Expand Down