[web] close input connection when window/iframe loses focus#166804
[web] close input connection when window/iframe loses focus#166804auto-submit[bot] merged 8 commits intoflutter:masterfrom
Conversation
ditman
left a comment
There was a problem hiding this comment.
This PR seems to be fixing 3 different problems/issues. Please make its description a little bit nicer, if you're planning on landing this! :
(And don't block on anything I've said :P)
| // Simply tabbing into the placeholder element should not cause semantics | ||
| // to be enabled. The user should actually click on the placeholder. | ||
| if (event.isA<DomKeyboardEvent>()) { | ||
| event as DomKeyboardEvent; | ||
| if (event.key == 'Tab') { | ||
| return true; | ||
| } |
There was a problem hiding this comment.
I don't understand this comment, it says "simply by tabbing should not cause semantics to be enabled" but then it returns true if event.key is 'Tab'?
There was a problem hiding this comment.
This looks like a fix for a different issue, please list it in the "Fixes" of the description of this PR?
There was a problem hiding this comment.
The name of the method - shouldEnableSemantics - is misleading. true return value means "yes, forward the event to the framework; do not consume it". I plan to do some renaming, but not in this PR. The reason I included it in this PR is because as I was testing focus functionality I noticed that stumbling upon the placeholder threw off focus management because it enabled semantics and completely changed the DOM structure. With this fix I can cleanly leave and re-enter the iframe that hosts the Flutter app.
engine/src/flutter/lib/web_ui/lib/src/engine/text_editing/text_editing.dart
Outdated
Show resolved
Hide resolved
engine/src/flutter/lib/web_ui/test/engine/semantics/semantics_helper_test.dart
Show resolved
Hide resolved
engine/src/flutter/lib/web_ui/lib/src/engine/platform_dispatcher/view_focus_binding.dart
Show resolved
Hide resolved
engine/src/flutter/lib/web_ui/lib/src/engine/text_editing/text_editing.dart
Show resolved
Hide resolved
b357aef to
f099c79
Compare
f099c79 to
900a05d
Compare
ditman
left a comment
There was a problem hiding this comment.
LGTM! Please fix the TODO to comply with the Flutter styleguide though!
| // This is a mysterious behavior in Firefox. Even though the engine does | ||
| // call <input>.focus() the browser doesn't move focus to the target | ||
| // element. This only happens in the test harness. When testing | ||
| // manually, Firefox happily moves focus to the input element. | ||
| expect(domDocument.activeElement, flutterView.dom.rootElement); |
There was a problem hiding this comment.
Well, at least it behaves the same as Safari :P
| // If the focus stays within the same FlutterView, ensure the focus stays | ||
| // on the input element. | ||
|
|
||
| // TODO(166857): the motivation/reasoning behind this remains murky. |
There was a problem hiding this comment.
Please, follow the style guide for flutter TODOs:
TODOs should include the string TODO in all caps, followed by the GitHub username of the person with the best context about the problem referenced by the TODO in parentheses. A TODO is not a commitment that the person referenced will fix the problem, it is intended to be the person with enough context to explain the problem. Thus, when you create a TODO, it is almost always your username that is given.
| // TODO(166857): the motivation/reasoning behind this remains murky. | |
| // TODO(yjbanov): Make text input less grabby. See: https://github.com/flutter/flutter/issues/166857 | |
| // The motivation/reasoning behind whay this is needed is murky. |
| _callback = (String channel, ByteData? data, PlatformMessageResponseCallback? callback) { | ||
| messages.add(PlatformMessage(channel, const JSONMethodCodec().decodeMethodCall(data))); | ||
| if (channel == 'flutter/lifecycle') { | ||
| strings.add(PlatformStringMessage(channel, const StringCodec().decodeMessage(data!))); |
There was a problem hiding this comment.
Are we even using the strings anywhere in tests? Or is this to be able to listen to all channels, even flutter/lifecycle?
|
While working on the fix for #157579 I noticed this PR and tried it locally. It works well with the one-line fields, but unfortunately, the multiline text field editing is now broken.
There is an error.movAssertion ErrorSample Codeimport 'package:flutter/material.dart';
void main() async {
runApp(
MaterialApp(
home: Screen(),
),
);
}
class Screen extends StatelessWidget {
const Screen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: TextField(
minLines: 1,
maxLines: null,
),
),
);
}
} |
|
@ksokolovskyi Thanks for the heads up! I'll test this scenario. |
|
I'm taking over this PR. @ksokolovskyi I think I fixed the issue you encountered. Would you mind checking again please? |
| final host = view!.dom.textEditingHost; | ||
| if (!host.contains(element)) { | ||
| host.append(element); | ||
| } |
There was a problem hiding this comment.
Oh, this prevents blurs because the element gets "moved" in the DOM when already inserted? I think this deserves a small comment so it doesn't get "optimized" in the future :P
There was a problem hiding this comment.
Exactly. Yes a comment is in order.
Hi @mdebbar, I was not able to reproduce the issue on Chrome, Safari, and Firefox. Thanks for the fix! |
|
@ksokolovskyi – thank you SO MUCH for following along closely and verifying! |
flutter/flutter@3ed38e2...cfb887c 2025-04-20 [email protected] Roll Fuchsia Linux SDK from 0U_vEALFF7qRJZ_cE... to RGmU4KeQhrxqE7hsr... (flutter/flutter#167447) 2025-04-19 [email protected] Roll Skia from 3dc3ffeb45f0 to bd9ef4955aad (1 revision) (flutter/flutter#167434) 2025-04-19 [email protected] Roll Fuchsia Linux SDK from MwYckh5OvwwmIYLx0... to 0U_vEALFF7qRJZ_cE... (flutter/flutter#167430) 2025-04-19 [email protected] Roll Skia from 177a2929e32f to 3dc3ffeb45f0 (1 revision) (flutter/flutter#167428) 2025-04-19 [email protected] Revert "Reduce app startup latency by initializing the engine on a separate thread (#166918)" (flutter/flutter#167427) 2025-04-18 [email protected] Fix keyboard cover SearchAnchor list results (flutter/flutter#165382) 2025-04-18 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Mark `windows_host_engine_test` flaky (#167419)" (flutter/flutter#167425) 2025-04-18 [email protected] Docs: Update date picker theme day color properties doc (flutter/flutter#166122) 2025-04-18 [email protected] Add ktlint test for generated files from templates (flutter/flutter#167378) 2025-04-18 [email protected] Revert "[Windows] Enable merged platform and UI thread by default" (flutter/flutter#167420) 2025-04-18 [email protected] Add a DrivenScrollActivity.simulation constructor (flutter/flutter#166730) 2025-04-18 [email protected] Added missing period for consistency and readability (flutter/flutter#162887) 2025-04-18 [email protected] Roll Skia from 6c4595124690 to 177a2929e32f (1 revision) (flutter/flutter#167417) 2025-04-18 [email protected] Fix codesigning for `Mac_arm64_ios imitation_game_flutter` (flutter/flutter#167307) 2025-04-18 [email protected] Mark `windows_host_engine_test` flaky (flutter/flutter#167419) 2025-04-18 [email protected] Roll Dart SDK from ab60afc99bcb to 0cfefe2a03fb (1 revision) (flutter/flutter#167414) 2025-04-18 [email protected] [web] close input connection when window/iframe loses focus (flutter/flutter#166804) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: 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
flutter/flutter@3ed38e2...cfb887c 2025-04-20 [email protected] Roll Fuchsia Linux SDK from 0U_vEALFF7qRJZ_cE... to RGmU4KeQhrxqE7hsr... (flutter/flutter#167447) 2025-04-19 [email protected] Roll Skia from 3dc3ffeb45f0 to bd9ef4955aad (1 revision) (flutter/flutter#167434) 2025-04-19 [email protected] Roll Fuchsia Linux SDK from MwYckh5OvwwmIYLx0... to 0U_vEALFF7qRJZ_cE... (flutter/flutter#167430) 2025-04-19 [email protected] Roll Skia from 177a2929e32f to 3dc3ffeb45f0 (1 revision) (flutter/flutter#167428) 2025-04-19 [email protected] Revert "Reduce app startup latency by initializing the engine on a separate thread (#166918)" (flutter/flutter#167427) 2025-04-18 [email protected] Fix keyboard cover SearchAnchor list results (flutter/flutter#165382) 2025-04-18 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Mark `windows_host_engine_test` flaky (#167419)" (flutter/flutter#167425) 2025-04-18 [email protected] Docs: Update date picker theme day color properties doc (flutter/flutter#166122) 2025-04-18 [email protected] Add ktlint test for generated files from templates (flutter/flutter#167378) 2025-04-18 [email protected] Revert "[Windows] Enable merged platform and UI thread by default" (flutter/flutter#167420) 2025-04-18 [email protected] Add a DrivenScrollActivity.simulation constructor (flutter/flutter#166730) 2025-04-18 [email protected] Added missing period for consistency and readability (flutter/flutter#162887) 2025-04-18 [email protected] Roll Skia from 6c4595124690 to 177a2929e32f (1 revision) (flutter/flutter#167417) 2025-04-18 [email protected] Fix codesigning for `Mac_arm64_ios imitation_game_flutter` (flutter/flutter#167307) 2025-04-18 [email protected] Mark `windows_host_engine_test` flaky (flutter/flutter#167419) 2025-04-18 [email protected] Roll Dart SDK from ab60afc99bcb to 0cfefe2a03fb (1 revision) (flutter/flutter#167414) 2025-04-18 [email protected] [web] close input connection when window/iframe loses focus (flutter/flutter#166804) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: 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
flutter/flutter@3ed38e2...cfb887c 2025-04-20 [email protected] Roll Fuchsia Linux SDK from 0U_vEALFF7qRJZ_cE... to RGmU4KeQhrxqE7hsr... (flutter/flutter#167447) 2025-04-19 [email protected] Roll Skia from 3dc3ffeb45f0 to bd9ef4955aad (1 revision) (flutter/flutter#167434) 2025-04-19 [email protected] Roll Fuchsia Linux SDK from MwYckh5OvwwmIYLx0... to 0U_vEALFF7qRJZ_cE... (flutter/flutter#167430) 2025-04-19 [email protected] Roll Skia from 177a2929e32f to 3dc3ffeb45f0 (1 revision) (flutter/flutter#167428) 2025-04-19 [email protected] Revert "Reduce app startup latency by initializing the engine on a separate thread (#166918)" (flutter/flutter#167427) 2025-04-18 [email protected] Fix keyboard cover SearchAnchor list results (flutter/flutter#165382) 2025-04-18 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Mark `windows_host_engine_test` flaky (#167419)" (flutter/flutter#167425) 2025-04-18 [email protected] Docs: Update date picker theme day color properties doc (flutter/flutter#166122) 2025-04-18 [email protected] Add ktlint test for generated files from templates (flutter/flutter#167378) 2025-04-18 [email protected] Revert "[Windows] Enable merged platform and UI thread by default" (flutter/flutter#167420) 2025-04-18 [email protected] Add a DrivenScrollActivity.simulation constructor (flutter/flutter#166730) 2025-04-18 [email protected] Added missing period for consistency and readability (flutter/flutter#162887) 2025-04-18 [email protected] Roll Skia from 6c4595124690 to 177a2929e32f (1 revision) (flutter/flutter#167417) 2025-04-18 [email protected] Fix codesigning for `Mac_arm64_ios imitation_game_flutter` (flutter/flutter#167307) 2025-04-18 [email protected] Mark `windows_host_engine_test` flaky (flutter/flutter#167419) 2025-04-18 [email protected] Roll Dart SDK from ab60afc99bcb to 0cfefe2a03fb (1 revision) (flutter/flutter#167414) 2025-04-18 [email protected] [web] close input connection when window/iframe loses focus (flutter/flutter#166804) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: 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
flutter/flutter@3ed38e2...cfb887c 2025-04-20 [email protected] Roll Fuchsia Linux SDK from 0U_vEALFF7qRJZ_cE... to RGmU4KeQhrxqE7hsr... (flutter/flutter#167447) 2025-04-19 [email protected] Roll Skia from 3dc3ffeb45f0 to bd9ef4955aad (1 revision) (flutter/flutter#167434) 2025-04-19 [email protected] Roll Fuchsia Linux SDK from MwYckh5OvwwmIYLx0... to 0U_vEALFF7qRJZ_cE... (flutter/flutter#167430) 2025-04-19 [email protected] Roll Skia from 177a2929e32f to 3dc3ffeb45f0 (1 revision) (flutter/flutter#167428) 2025-04-19 [email protected] Revert "Reduce app startup latency by initializing the engine on a separate thread (#166918)" (flutter/flutter#167427) 2025-04-18 [email protected] Fix keyboard cover SearchAnchor list results (flutter/flutter#165382) 2025-04-18 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Mark `windows_host_engine_test` flaky (#167419)" (flutter/flutter#167425) 2025-04-18 [email protected] Docs: Update date picker theme day color properties doc (flutter/flutter#166122) 2025-04-18 [email protected] Add ktlint test for generated files from templates (flutter/flutter#167378) 2025-04-18 [email protected] Revert "[Windows] Enable merged platform and UI thread by default" (flutter/flutter#167420) 2025-04-18 [email protected] Add a DrivenScrollActivity.simulation constructor (flutter/flutter#166730) 2025-04-18 [email protected] Added missing period for consistency and readability (flutter/flutter#162887) 2025-04-18 [email protected] Roll Skia from 6c4595124690 to 177a2929e32f (1 revision) (flutter/flutter#167417) 2025-04-18 [email protected] Fix codesigning for `Mac_arm64_ios imitation_game_flutter` (flutter/flutter#167307) 2025-04-18 [email protected] Mark `windows_host_engine_test` flaky (flutter/flutter#167419) 2025-04-18 [email protected] Roll Dart SDK from ab60afc99bcb to 0cfefe2a03fb (1 revision) (flutter/flutter#167414) 2025-04-18 [email protected] [web] close input connection when window/iframe loses focus (flutter/flutter#166804) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: 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
flutter/flutter@3ed38e2...cfb887c 2025-04-20 [email protected] Roll Fuchsia Linux SDK from 0U_vEALFF7qRJZ_cE... to RGmU4KeQhrxqE7hsr... (flutter/flutter#167447) 2025-04-19 [email protected] Roll Skia from 3dc3ffeb45f0 to bd9ef4955aad (1 revision) (flutter/flutter#167434) 2025-04-19 [email protected] Roll Fuchsia Linux SDK from MwYckh5OvwwmIYLx0... to 0U_vEALFF7qRJZ_cE... (flutter/flutter#167430) 2025-04-19 [email protected] Roll Skia from 177a2929e32f to 3dc3ffeb45f0 (1 revision) (flutter/flutter#167428) 2025-04-19 [email protected] Revert "Reduce app startup latency by initializing the engine on a separate thread (#166918)" (flutter/flutter#167427) 2025-04-18 [email protected] Fix keyboard cover SearchAnchor list results (flutter/flutter#165382) 2025-04-18 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Mark `windows_host_engine_test` flaky (#167419)" (flutter/flutter#167425) 2025-04-18 [email protected] Docs: Update date picker theme day color properties doc (flutter/flutter#166122) 2025-04-18 [email protected] Add ktlint test for generated files from templates (flutter/flutter#167378) 2025-04-18 [email protected] Revert "[Windows] Enable merged platform and UI thread by default" (flutter/flutter#167420) 2025-04-18 [email protected] Add a DrivenScrollActivity.simulation constructor (flutter/flutter#166730) 2025-04-18 [email protected] Added missing period for consistency and readability (flutter/flutter#162887) 2025-04-18 [email protected] Roll Skia from 6c4595124690 to 177a2929e32f (1 revision) (flutter/flutter#167417) 2025-04-18 [email protected] Fix codesigning for `Mac_arm64_ios imitation_game_flutter` (flutter/flutter#167307) 2025-04-18 [email protected] Mark `windows_host_engine_test` flaky (flutter/flutter#167419) 2025-04-18 [email protected] Roll Dart SDK from ab60afc99bcb to 0cfefe2a03fb (1 revision) (flutter/flutter#167414) 2025-04-18 [email protected] [web] close input connection when window/iframe loses focus (flutter/flutter#166804) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: 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
…166804) Fixes flutter#155265 This includes 2 fixes: * When the window/iframe loses focus, close the text input connection instead of grabbing the focus again. * Do not enable semantics using the placeholder when moving focus using the "Tab" key. Bonus: remove the no longer necessary `ViewFocusBinding.isEnabled` (doesn't fix any issues, just a clean-up). --------- Co-authored-by: Mouad Debbar <[email protected]>
Fixes #155265
This includes 2 fixes:
Bonus: remove the no longer necessary
ViewFocusBinding.isEnabled(doesn't fix any issues, just a clean-up).