-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Fix unexpected ViewFocus events when Text Editing utilities change focus in the middle of a blur call. #54965
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to that, during
focusout
processing,activeElement
typically points to<body />
. However, if an element is focused during ablur
event,activeElement
points to that focused element. Although, undocumented it can be verified with:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <div id="container"> <input type="" value="1" id="input1"> <input type="" value="2" id="input2"> <input type="" value="3" id="input3"> </div> <script> container.addEventListener('focusin', (ev) => { console.log('focusin: was gained by', ev.target); }); container.addEventListener('focusout', (ev) => { console.log('document.hasFocus()', document.hasFocus()); console.log('document.activeElement', document.activeElement); console.log('focusout: focus is leaving', ev.target, 'and it will go to', ev.relatedTarget); }); input2.addEventListener('blur', (ev) => { input2.focus(); }); </script> </body> </html>
I tried this on multiple browsers to make sure they have the same behavior. Chrome and Safari match the behavior you described. Firefox didn't. In fact, Firefox seems to be ignoring input2.focus()
completely.
Anyhow, I think your change is okay. On Firefox, it has no effect because that condition is never true.
lib/web_ui/lib/src/engine/platform_dispatcher/view_focus_binding.dart
Outdated
Show resolved
Hide resolved
That is actually true. Super interesting. This is a different, special, behavior tho. If the same node tries to get refocused firefox "prevents it". So in a sense, firefox doesn't allow a node to keep focus against the user will. If you change the code to something like this, you'll see the originally described behavior. <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div id="container">
<input type="" value="1" id="input1">
<input type="" value="2" id="input2">
<input type="" value="3" id="input3">
</div>
<script>
container.addEventListener('focusin', (ev) => {
console.log('focusin: was gained by', ev.target);
});
container.addEventListener('focusout', (ev) => {
console.log('document.hasFocus()', document.hasFocus());
console.log('document.activeElement', document.activeElement);
console.log('focusout: focus is leaving', ev.target, 'and it will go to', ev.relatedTarget);
});
input2.addEventListener('blur', (ev) => {
input1.focus();
});
</script>
</body>
</html> |
…ng.dart Co-authored-by: Mouad Debbar <mouad.debbar@gmail.com>
… change focus in the middle of a blur call. (flutter/engine#54965)
… change focus in the middle of a blur call. (flutter/engine#54965)
…154691) flutter/engine@c50eb8a...015f3b1 2024-09-05 jonahwilliams@google.com [engine] always force platform channel responses to schedule a task. (flutter/engine#54975) 2024-09-05 tugorez@users.noreply.github.com Fix unexpected ViewFocus events when Text Editing utilities change focus in the middle of a blur call. (flutter/engine#54965) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC codefu@google.com,rmistry@google.com,zra@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…isions) (#154691)" (#154726) Reverts: #154691 Initiated by: jtmcdole Reason for reverting: breaking flutter-dashboard Original PR Author: engine-flutter-autoroll Reviewed By: {fluttergithubbot} This change reverts the following previous change: flutter/engine@c50eb8a...015f3b1 2024-09-05 jonahwilliams@google.com [engine] always force platform channel responses to schedule a task. (flutter/engine#54975) 2024-09-05 tugorez@users.noreply.github.com Fix unexpected ViewFocus events when Text Editing utilities change focus in the middle of a blur call. (flutter/engine#54965) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC codefu@google.com,rmistry@google.com,zra@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
… change focus in the middle of a blur call. (flutter/engine#54965)
… change focus in the middle of a blur call. (flutter/engine#54965)
… change focus in the middle of a blur call. (flutter/engine#54965)
flutter/engine@c50eb8a...419fb8c 2024-09-06 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[engine] always force platform channel responses to schedule a task. (#54975)" (flutter/engine#55000) 2024-09-06 [skia-flutter-autoroll@skia.org](mailto:skia-flutter-autoroll@skia.org) Roll Skia from b6bab0fde426 to 6ad117bd2efe (2 revisions) (flutter/engine#54999) 2024-09-06 [skia-flutter-autoroll@skia.org](mailto:skia-flutter-autoroll@skia.org) Roll Fuchsia Test Scripts from D9INMR2u4wcyiZ750... to 5dqcFlKzRjJb6V95W... (flutter/engine#54998) 2024-09-06 [skia-flutter-autoroll@skia.org](mailto:skia-flutter-autoroll@skia.org) Roll Skia from a09312b70d37 to b6bab0fde426 (3 revisions) (flutter/engine#54997) 2024-09-06 [skia-flutter-autoroll@skia.org](mailto:skia-flutter-autoroll@skia.org) Roll Skia from 368f209ccca5 to a09312b70d37 (1 revision) (flutter/engine#54995) 2024-09-06 [skia-flutter-autoroll@skia.org](mailto:skia-flutter-autoroll@skia.org) Roll Skia from aec11ae18bb6 to 368f209ccca5 (3 revisions) (flutter/engine#54992) 2024-09-06 [skia-flutter-autoroll@skia.org](mailto:skia-flutter-autoroll@skia.org) Roll Fuchsia Linux SDK from xNv47d1TZmK9XgTxu... to PBeI0gGvgFdXV6hCg... (flutter/engine#54990) 2024-09-06 [skia-flutter-autoroll@skia.org](mailto:skia-flutter-autoroll@skia.org) Roll Skia from 809f868ded1c to aec11ae18bb6 (22 revisions) (flutter/engine#54988) 2024-09-06 [30870216+gaaclarke@users.noreply.github.com](mailto:30870216+gaaclarke@users.noreply.github.com) Removes the int storage from Color (flutter/engine#54714) 2024-09-06 [chris@bracken.jp](mailto:chris@bracken.jp) iOS,macOS: Add logging of duplicate codesign binaries (flutter/engine#54987) 2024-09-06 [skia-flutter-autoroll@skia.org](mailto:skia-flutter-autoroll@skia.org) Roll Fuchsia Test Scripts from k4lKsecg0pdIp-U7c... to D9INMR2u4wcyiZ750... (flutter/engine#54984) 2024-09-05 [a-siva@users.noreply.github.com](mailto:a-siva@users.noreply.github.com) Manual roll of Dart. (flutter/engine#54983) 2024-09-05 [chris@bracken.jp](mailto:chris@bracken.jp) iOS,macOS: add unsigned_binaries.txt (flutter/engine#54977) 2024-09-05 [jason-simmons@users.noreply.github.com](mailto:jason-simmons@users.noreply.github.com) Manual Skia roll to 809f868ded1c (flutter/engine#54972) 2024-09-05 [1961493+harryterkelsen@users.noreply.github.com](mailto:1961493+harryterkelsen@users.noreply.github.com) [canvaskit] Fix incorrect calculation of ImageFilter paint bounds (flutter/engine#54980) 2024-09-05 [jonahwilliams@google.com](mailto:jonahwilliams@google.com) [engine] always force platform channel responses to schedule a task. (flutter/engine#54975) 2024-09-05 [tugorez@users.noreply.github.com](mailto:tugorez@users.noreply.github.com) Fix unexpected ViewFocus events when Text Editing utilities change focus in the middle of a blur call. (flutter/engine#54965) Also rolling transitive DEPS: fuchsia/sdk/core/linux-amd64 from xNv47d1TZmK9 to PBeI0gGvgFdX --------- Co-authored-by: Christopher Fujino <christopherfujino@gmail.com> Co-authored-by: Zachary Anderson <zanderso@users.noreply.github.com>
In some cases, text editing utilities re-focus the
<input />
element during a blur event. This causes an unusual sequence offocusin
andfocusout
events, leading to the engine sending unintended events.Consider the following HTML code:
Clicking input1, then input2, then input3 produces the following console logs:
Now, let's add a blur handler that changes focus:
The log sequence changes and gives the wrong impression that no dom element has focus:
In addition to that, during
focusout
processing,activeElement
typically points to<body />
. However, if an element is focused during ablur
event,activeElement
points to that focused element. Although, undocumented it can be verified with:We leverage these behaviors to ignore
focusout
events when the document has focus butactiveElement
is not<body />
.flutter/flutter#153022
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.