Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Refactor highlight handling in FocusManager #119075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 24, 2023

Conversation

gspencergoog
Copy link
Contributor

@gspencergoog gspencergoog commented Jan 24, 2023

Description

This refactors the highlight mode management in the FocusManager to separate it out into a separate private class. The public API hasn't changed, but this separates the responsibilities so it's easier to tell what part of the code is focus management and which part is highlight management. They're linked in that they both operate off of the same key event stream, but they probably should have been separate from the beginning.

Tests

  • This is a refactor without any semantic change, so no test changes needed.

@flutter-dashboard flutter-dashboard bot added f: focus Focus traversal, gaining or losing focus framework flutter/packages/flutter repository. See also f: labels. labels Jan 24, 2023
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@Hixie
Copy link
Contributor

Hixie commented Jan 24, 2023

test-exempt: code refactor with no semantic change

Comment on lines 1563 to 1567
if (_markedForFocus == node) {
_markedForFocus = null;
}
_dirtyNodes.remove(node);
_pendingAutofocuses.removeWhere((_Autofocus autofocus) => autofocus.autofocusNode == node || autofocus.scope == node);
Copy link
Member

Choose a reason for hiding this comment

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

Is this new/changed functionality that should be tested?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh! Yes, although I actually meant for that to be in another PR (later). I'll remove it for now.

I think this is something that should be happening, but currently isn't being done.

// A class to detect and manage the highlight mode transitions.
// An instance of this is owned by the FocusManager.
class _HighlightModeManager {
_HighlightModeManager();
Copy link
Member

Choose a reason for hiding this comment

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

Do you need this empty constructor? Actually kinds surprised that no lint is flagging this...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I guess not. Will remove.

Yes, kind of odd that there's no lint.


/// Remove a previously registered closure from the list of closures that the
/// [FocusManager] notifies.
void removeListener(ValueChanged<FocusHighlightMode> listener) => _listeners.remove(listener);
Copy link
Member

Choose a reason for hiding this comment

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

add/removeListener appears to be operating on the static _emptyListeners list instead of an instance variable since _listeners is never set to anything but the static _emptyListeners. That's probably not intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ooh, good catch. If I could have made the empty one const, I would have. Instead of the static empty list, I decided to just re-init the _listeners to a new empty list when it gets disposed, so that there's no chance that something will operate on a static list, inserting things while disposed, making all disposed instances point to the same (now non-empty!) list.

GestureBinding.instance.pointerRouter.removeGlobalRoute(handlePointerEvent);
ServicesBinding.instance.keyEventManager.keyMessageHandler = null;
}
_listeners = _emptyListeners;
Copy link
Member

Choose a reason for hiding this comment

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

See other comment, I believe even before this line, _listeners always equals to _emptyListeners.

}

@pragma('vm:notify-debugger-on-exception')
void notifyListeners() {
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason this class can't just extend/mixin ChangeNotifier instead of re-implementing that functionality?

Copy link
Member

Choose a reason for hiding this comment

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

If there is a reason, maybe document it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, because ChangeNotifier doesn't provide the modified value in the callback. I'll add some docs.

@gspencergoog gspencergoog force-pushed the separate_highlight_manager branch from 462851d to c08e85c Compare January 24, 2023 18:31
@gspencergoog gspencergoog force-pushed the separate_highlight_manager branch from c08e85c to 9691a5a Compare January 24, 2023 18:31
Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

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

LGTM

@gspencergoog gspencergoog added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 24, 2023
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 24, 2023
@auto-submit
Copy link
Contributor

auto-submit bot commented Jan 24, 2023

auto label is removed for flutter/flutter, pr: 119075, due to - The status or check suite Mac build_tests_2_4 has failed. Please fix the issues identified (or deflake) before re-applying this label.

@goderbauer goderbauer added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 24, 2023
@auto-submit auto-submit bot merged commit 2f0dd56 into flutter:master Jan 24, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 25, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Jan 25, 2023
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Jan 25, 2023
* 3735231 Cleanup old Dart SDK layout compatibility (flutter/flutter#118819)

* 4d25030 Add leak_tracker as dev_dependency.  (flutter/flutter#118952)

* e3c51a2 Add Windows unit tests to plugin template (flutter/flutter#118638)

* d20dd9e Roll Flutter Engine from 7d3233d26d09 to 71ee5f19bc16 (15 revisions) (flutter/flutter#119081)

* 5dabe10 Fix path name to discover debug apk on add2app builds (flutter/flutter#117999)

* 50ed8a3 Enable `unnecessary_null_comparison` check (flutter/flutter#118849)

* 455e6ac Test integration test apps' runner files against current template app (flutter/flutter#118646)

* a788e1b Roll Flutter Engine from 71ee5f19bc16 to 59ea78bfabda (2 revisions) (flutter/flutter#119087)

* c35370c Roll Flutter Engine from 59ea78bfabda to 2499a5d9fca7 (2 revisions) (flutter/flutter#119089)

* 2f0dd56 Refactor highlight handling in FocusManager (flutter/flutter#119075)

* 2759f3f Roll Flutter Engine from 2499a5d9fca7 to d98926c32ee7 (2 revisions) (flutter/flutter#119090)

* 760fb21 Roll Flutter Engine from d98926c32ee7 to bec40654a5d7 (2 revisions) (flutter/flutter#119093)

* bbca694 Roll Flutter Engine from bec40654a5d7 to 5405f2c26e85 (2 revisions) (flutter/flutter#119095)

* 6414c36 f1464b49c Manually roll ANGLE, vulkan-deps, SwiftShader (flutter/engine#38650) (flutter/flutter#119097)

* 426cdd9 55bb8deaf [Impeller] Linear sample atlas glyphs when the CTM isn't translation/scale only (flutter/engine#39112) (flutter/flutter#119098)

* 83c3a61 Only emit image painting events in debug & profile modes. (flutter/flutter#118872)

* b113df2 bffb98352 Roll Skia from b72fececbdcc to 8ffd5c20d634 (3 revisions) (flutter/engine#39114) (flutter/flutter#119099)

* 351466a Add Decoding Flutter videos to API docs (flutter/flutter#116454)

* 318f875 Pass through magnifierConfiguration (flutter/flutter#118270)

* eced23e d39ab638b Roll Fuchsia Mac SDK from MUvFS0baOnigVUIND... to _H53AyDxR9Pm2TbwN... (flutter/engine#39122) (flutter/flutter#119126)

* 29ab437 Add Material 3 `CheckboxListTile` example and update existing examples (flutter/flutter#118792)

* a815ee6 8efc7183b Roll Skia from 8ffd5c20d634 to da5034f9d117 (4 revisions) (flutter/engine#39123) (flutter/flutter#119129)
auto-submit bot pushed a commit to flutter/plugins that referenced this pull request Jan 25, 2023
* 3735231 Cleanup old Dart SDK layout compatibility (flutter/flutter#118819)

* 4d25030 Add leak_tracker as dev_dependency.  (flutter/flutter#118952)

* e3c51a2 Add Windows unit tests to plugin template (flutter/flutter#118638)

* d20dd9e Roll Flutter Engine from 7d3233d26d09 to 71ee5f19bc16 (15 revisions) (flutter/flutter#119081)

* 5dabe10 Fix path name to discover debug apk on add2app builds (flutter/flutter#117999)

* 50ed8a3 Enable `unnecessary_null_comparison` check (flutter/flutter#118849)

* 455e6ac Test integration test apps' runner files against current template app (flutter/flutter#118646)

* a788e1b Roll Flutter Engine from 71ee5f19bc16 to 59ea78bfabda (2 revisions) (flutter/flutter#119087)

* c35370c Roll Flutter Engine from 59ea78bfabda to 2499a5d9fca7 (2 revisions) (flutter/flutter#119089)

* 2f0dd56 Refactor highlight handling in FocusManager (flutter/flutter#119075)

* 2759f3f Roll Flutter Engine from 2499a5d9fca7 to d98926c32ee7 (2 revisions) (flutter/flutter#119090)

* 760fb21 Roll Flutter Engine from d98926c32ee7 to bec40654a5d7 (2 revisions) (flutter/flutter#119093)

* bbca694 Roll Flutter Engine from bec40654a5d7 to 5405f2c26e85 (2 revisions) (flutter/flutter#119095)

* 6414c36 f1464b49c Manually roll ANGLE, vulkan-deps, SwiftShader (flutter/engine#38650) (flutter/flutter#119097)

* 426cdd9 55bb8deaf [Impeller] Linear sample atlas glyphs when the CTM isn't translation/scale only (flutter/engine#39112) (flutter/flutter#119098)

* 83c3a61 Only emit image painting events in debug & profile modes. (flutter/flutter#118872)

* b113df2 bffb98352 Roll Skia from b72fececbdcc to 8ffd5c20d634 (3 revisions) (flutter/engine#39114) (flutter/flutter#119099)

* 351466a Add Decoding Flutter videos to API docs (flutter/flutter#116454)

* 318f875 Pass through magnifierConfiguration (flutter/flutter#118270)

* eced23e d39ab638b Roll Fuchsia Mac SDK from MUvFS0baOnigVUIND... to _H53AyDxR9Pm2TbwN... (flutter/engine#39122) (flutter/flutter#119126)

* 29ab437 Add Material 3 `CheckboxListTile` example and update existing examples (flutter/flutter#118792)

* a815ee6 8efc7183b Roll Skia from 8ffd5c20d634 to da5034f9d117 (4 revisions) (flutter/engine#39123) (flutter/flutter#119129)
mauricioluz pushed a commit to mauricioluz/plugins that referenced this pull request Jan 26, 2023
* 3735231 Cleanup old Dart SDK layout compatibility (flutter/flutter#118819)

* 4d25030 Add leak_tracker as dev_dependency.  (flutter/flutter#118952)

* e3c51a2 Add Windows unit tests to plugin template (flutter/flutter#118638)

* d20dd9e Roll Flutter Engine from 7d3233d26d09 to 71ee5f19bc16 (15 revisions) (flutter/flutter#119081)

* 5dabe10 Fix path name to discover debug apk on add2app builds (flutter/flutter#117999)

* 50ed8a3 Enable `unnecessary_null_comparison` check (flutter/flutter#118849)

* 455e6ac Test integration test apps' runner files against current template app (flutter/flutter#118646)

* a788e1b Roll Flutter Engine from 71ee5f19bc16 to 59ea78bfabda (2 revisions) (flutter/flutter#119087)

* c35370c Roll Flutter Engine from 59ea78bfabda to 2499a5d9fca7 (2 revisions) (flutter/flutter#119089)

* 2f0dd56 Refactor highlight handling in FocusManager (flutter/flutter#119075)

* 2759f3f Roll Flutter Engine from 2499a5d9fca7 to d98926c32ee7 (2 revisions) (flutter/flutter#119090)

* 760fb21 Roll Flutter Engine from d98926c32ee7 to bec40654a5d7 (2 revisions) (flutter/flutter#119093)

* bbca694 Roll Flutter Engine from bec40654a5d7 to 5405f2c26e85 (2 revisions) (flutter/flutter#119095)

* 6414c36 f1464b49c Manually roll ANGLE, vulkan-deps, SwiftShader (flutter/engine#38650) (flutter/flutter#119097)

* 426cdd9 55bb8deaf [Impeller] Linear sample atlas glyphs when the CTM isn't translation/scale only (flutter/engine#39112) (flutter/flutter#119098)

* 83c3a61 Only emit image painting events in debug & profile modes. (flutter/flutter#118872)

* b113df2 bffb98352 Roll Skia from b72fececbdcc to 8ffd5c20d634 (3 revisions) (flutter/engine#39114) (flutter/flutter#119099)

* 351466a Add Decoding Flutter videos to API docs (flutter/flutter#116454)

* 318f875 Pass through magnifierConfiguration (flutter/flutter#118270)

* eced23e d39ab638b Roll Fuchsia Mac SDK from MUvFS0baOnigVUIND... to _H53AyDxR9Pm2TbwN... (flutter/engine#39122) (flutter/flutter#119126)

* 29ab437 Add Material 3 `CheckboxListTile` example and update existing examples (flutter/flutter#118792)

* a815ee6 8efc7183b Roll Skia from 8ffd5c20d634 to da5034f9d117 (4 revisions) (flutter/engine#39123) (flutter/flutter#119129)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App f: focus Focus traversal, gaining or losing focus framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants