Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@nbayati
Copy link
Contributor

@nbayati nbayati commented Jun 24, 2022

Add support for high contrast on Windows. Previously, the value of high contrast flag in AccessibilityFeatures was always false. This PR addresses the issue by reading the value from the browser using mediaQuery of forced-colors: active and updating AccessibilityFeatures accordingly.

Fixes flutter/flutter#104272

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added the platform-web Code specifically for the web engine label Jun 24, 2022
@nbayati nbayati requested a review from mdebbar June 24, 2022 18:45
@nbayati nbayati requested a review from yjbanov July 6, 2022 22:23
Copy link
Contributor

@yjbanov yjbanov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a bunch of nitpicks, suggestions, and pointers. None of this is blocking, so LGTM.


/// Reference to css media query that indicates whether high contrast is on.
final html.MediaQueryList _highContrastMediaQuery =
html.window.matchMedia(_highContrastMediaQueryString);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be cleaned up in some way when the instance of HighContrastSupport is no longer needed? For example, when hot-restart is invoked we will reinitialize the state of the Dart program. Would that create a dangling MediaQueryList from a previous iteration of the app?

Here's an example of a class that performs hot restart clean-up:

registerHotRestartListener(_instance!._reset);


/// Updates [_highContrast] and invokes [onHighContrastModeChanged]
/// callback if [_highContrast] changed.
void _updateHighContrast(bool value) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we simplify the logic here by calling initializeAccessibilityFeatures?

void dispose() {
_removeBrightnessMediaQueryListener();
_disconnectFontSizeObserver();
HighContrastSupport.instance.removeListener(_updateHighContrast);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see that this covers the hot-restart case. This is unusual because typically our singletons manage their own lifecycle w.r.t. to hot-restart, but in this case the lifecycle of HighContrastSupport is owned by EnginePlatformDispatcher. It not necessarily a bug, but could be confusing because it deviates from other similar classes. I think the initialization of HighContrastSupport may need to change for it to self-manage. Feel free to proceed how you see fit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate on "I think the initialization of HighContrastSupport may need to change for it to self-manage."?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant was that HighContrastSupport would need something like ensureInitialized method that creates the singleton and attaches a hot-restart listener that cleans up the singleton, similar to how KeyboardBinding does it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

platform-web Code specifically for the web engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[web] MediaQuery highContrast is always false

3 participants