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

Conversation

@htoor3
Copy link
Contributor

@htoor3 htoor3 commented May 9, 2023

Text inputs have moved outside of the shadowDOM and are now using the pointer event offset calculation algorithm that platform views use. However, transforms (e.g. scaling) applied to the input element aren't currently accounted for, which leads to incorrect offsets and clicks being registered inaccurately.

This PR attempts to transform those offset coordinates using the transform matrix data that is included in the geometry information sent over to text_editing.dart from the framework.

Issues

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 May 9, 2023
@htoor3 htoor3 requested review from ditman, mdebbar and yjbanov May 9, 2023 20:20
ui.Offset _computeOffsetForInputs(DomMouseEvent event) {
final Float32List matrix = textEditing.strategy.geometry!.globalTransform;
final FastMatrix32 fastMatrix = FastMatrix32(matrix);
fastMatrix.transform(event.offsetX, event.offsetY);
Copy link
Contributor Author

@htoor3 htoor3 May 9, 2023

Choose a reason for hiding this comment

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

@yjbanov, fastMatrix.transform works pretty well for this use case (scaling and translation). Are there any limitations to this? Scaling and translation are probably the most commonly applied transforms to inputs, but this still work for rotation and skew, or is that something we need to account for?

Copy link
Contributor

Choose a reason for hiding this comment

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

If this is performance-critical, I'd first check if the matrix is within the limits that FastMatrix32 can deal with and only use it then, and fallback to full matrix otherwise. I thinktransformKindOf should give you the right info.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ditman DOMMatrixReadOnly and its instance method transformPoint could certainly work, although it's missing documentation on MDN. But the API seems well supported across different browsers. We can also init it with globalTransform which should be a 16 length array. Do you think there would be significant advantages to using the browser API? Maybe their transformPoint is more optimized?

@yjbanov I don't see any docs outlining the limitations of the FastMatrix32, do you mean it only support matrices that perform simple 2D transforms and Matrix4 should be used for 3D transforms?

Copy link
Member

@ditman ditman May 18, 2023

Choose a reason for hiding this comment

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

(@yjbanov mentioned offline that DOMMatrix might not be fully supported everywhere, so I guess we're sticking to our own implementation!)

Copy link
Contributor

@mdebbar mdebbar left a comment

Choose a reason for hiding this comment

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

Thanks for putting a fix together!

Comment on lines 58 to 59
final FastMatrix32 fastMatrix = FastMatrix32(matrix);
fastMatrix.transform(event.offsetX, event.offsetY);
Copy link
Contributor

Choose a reason for hiding this comment

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

@yjbanov is this the right API to use for transforming an offset?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we want to support the general case. See my comment above for more details.

@htoor3 htoor3 requested a review from mdebbar May 16, 2023 19:26
assert(targetElement == domElement, 'The targeted input element must be the active input element');
final Float32List transformValues = inputGeometry.globalTransform;
assert(transformValues.length == 16);
final Matrix4 transform = Matrix4(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I replaced FastMatrix32 with Matrix4 @yjbanov

cc @ditman

Copy link
Contributor

Choose a reason for hiding this comment

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

Since the transform is applied once per DOM event no extra optimization is necessary. The default transform should be fast enough.

@htoor3 htoor3 marked this pull request as ready for review May 16, 2023 20:14
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.

LGTM if LGT @ditman

@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.

Copy link
Member

@ditman ditman left a comment

Choose a reason for hiding this comment

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

Can you give this a quick test with this with this app:

And see if the input is still working as expected when the glassPane is being transformed too? (for example when the app is rotated a few degrees!)

Other than that, this is similar to what we discussed. That globalTransform matrix looks HANDY! 🙏

@htoor3
Copy link
Contributor Author

htoor3 commented May 18, 2023

Can you give this a quick test with this with this app:

And see if the input is still working as expected when the glassPane is being transformed too? (for example when the app is rotated a few degrees!)

Other than that, this is similar to what we discussed. That globalTransform matrix looks HANDY! 🙏

Just tested with your demo and added an input and it works well. I actually noticed an issue on the demo (without these changes) where if the embedded app is rotated at a steep angle, clicking anywhere in a focused input blurs it. This also seems to be fixed with these changes!

@ditman
Copy link
Member

ditman commented May 18, 2023

I've tested the fix against a bunch of test apps (most of them linked above), and it seems to improve things. Currently writing a test. (We should cherry-pick this into 3.10 stable @yjbanov @kevmoo)

Add TODO in the place where we need to compute 3D transforms.
@ditman ditman requested review from mdebbar and yjbanov May 19, 2023 00:03
@ditman ditman changed the title [web] - add helper to calculate offsets for transformed inputs [web] Fix event offset for transformed widgets (and text input nodes). May 19, 2023
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.

lgtm

Copy link
Contributor

@mdebbar mdebbar left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @htoor3 and @ditman for fixing this!

@ditman ditman added the autosubmit Merge PR when tree becomes green via auto submit App label May 19, 2023
@auto-submit auto-submit bot merged commit 4f3f7bb into flutter:main May 19, 2023
ditman pushed a commit to ditman/flutter-engine that referenced this pull request May 19, 2023
* git cherry-pick 4f3f7bb (+ conflict fixes)

This cherry-pick backports flutter#41870 to Flutter 3.10.

Original commit message below:

[web] Fix event offset for transformed widgets (and text input nodes). (flutter#41870)

Text inputs have moved outside of the shadowDOM and are now using the pointer event offset calculation algorithm that platform views use.  However, transforms (e.g. scaling) applied to the input element aren't currently accounted for, which leads to incorrect offsets and clicks being registered inaccurately.

This PR attempts to transform those offset coordinates using the transform matrix data that is included in the geometry information sent over to `text_editing.dart` from the framework.

* Fixes flutter/flutter#125948 (text editing)
* Fixes flutter/flutter#126661 (platform view scaling)
* Fixes flutter/flutter#126754
ditman pushed a commit to ditman/flutter-engine that referenced this pull request May 19, 2023
* git cherry-pick 4f3f7bb (+ conflict fixes)

This cherry-pick backports flutter#41870 to Flutter 3.10.

Original commit message below:

[web] Fix event offset for transformed widgets (and text input nodes). (flutter#41870)

Text inputs have moved outside of the shadowDOM and are now using the pointer event offset calculation algorithm that platform views use.  However, transforms (e.g. scaling) applied to the input element aren't currently accounted for, which leads to incorrect offsets and clicks being registered inaccurately.

This PR attempts to transform those offset coordinates using the transform matrix data that is included in the geometry information sent over to `text_editing.dart` from the framework.

* Fixes flutter/flutter#125948 (text editing)
* Fixes flutter/flutter#126661 (platform view scaling)
* Fixes flutter/flutter#126754
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 19, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request May 19, 2023
…127233)

flutter/engine@3267fa2...f0c02ae

2023-05-19 [email protected] Roll Fuchsia Linux SDK from eal6a4HeaQon_Y4ml... to TWjmvLCOnYAUgAzvT... (flutter/engine#42168)
2023-05-19 [email protected] [macOS] Extract PlatformView mutator clip updating (flutter/engine#42164)
2023-05-19 [email protected] [web] Fix event offset for transformed widgets (and text input nodes). (flutter/engine#41870)
2023-05-19 [email protected] Roll goldctl to f808dcff91b221ae313e540c09d79696cd08b8de (flutter/engine#42166)

Also rolling transitive DEPS:
  fuchsia/sdk/core/linux-amd64 from eal6a4HeaQon to TWjmvLCOnYAU

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 [email protected],[email protected] 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://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
auto-submit bot pushed a commit that referenced this pull request May 24, 2023
This cherry-pick backports #41870 to Flutter 3.10.

* git cherry-pick 4f3f7bb (+ conflict fixes)

Original commit message below:

[web] Fix event offset for transformed widgets (and text input nodes). (#41870)

Text inputs have moved outside of the shadowDOM and are now using the pointer event offset calculation algorithm that platform views use.  However, transforms (e.g. scaling) applied to the input element aren't currently accounted for, which leads to incorrect offsets and clicks being registered inaccurately.

This PR attempts to transform those offset coordinates using the transform matrix data that is included in the geometry information sent over to `text_editing.dart` from the framework.

* Fixes flutter/flutter#125948 (text editing)
* Fixes flutter/flutter#126661 (platform view scaling)
* Fixes flutter/flutter#126754

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
CaseyHillers pushed a commit to CaseyHillers/flutter that referenced this pull request May 24, 2023
…lutter#127233)

flutter/engine@3267fa2...f0c02ae

2023-05-19 [email protected] Roll Fuchsia Linux SDK from eal6a4HeaQon_Y4ml... to TWjmvLCOnYAUgAzvT... (flutter/engine#42168)
2023-05-19 [email protected] [macOS] Extract PlatformView mutator clip updating (flutter/engine#42164)
2023-05-19 [email protected] [web] Fix event offset for transformed widgets (and text input nodes). (flutter/engine#41870)
2023-05-19 [email protected] Roll goldctl to f808dcff91b221ae313e540c09d79696cd08b8de (flutter/engine#42166)

Also rolling transitive DEPS:
  fuchsia/sdk/core/linux-amd64 from eal6a4HeaQon to TWjmvLCOnYAU

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 [email protected],[email protected] 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://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

autosubmit Merge PR when tree becomes green via auto submit App needs tests platform-web Code specifically for the web engine

Projects

None yet

4 participants