Skip to content

Conversation

dkwingsmt
Copy link
Contributor

@dkwingsmt dkwingsmt commented May 24, 2021

This PR relands #81148, which fixes a bug where mouse pointers can't trigger enter/exit events when pressed, credit to @xu-baolin .

Additionally, this PR also fixes MouseTracker to no longer trigger hit tests for non-mouse pointers.

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, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt.
  • 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 framework flutter/packages/flutter repository. See also f: labels. label May 24, 2021
@google-cla google-cla bot added the cla: yes label May 24, 2021
@goderbauer
Copy link
Member

(PR triage) @dkwingsmt Do you still need this?

@dkwingsmt
Copy link
Contributor Author

It seems that this PR does bring behavioral changes to internal tests in an unexpected way. I would investigate further but still haven't got time for it.

@xu-baolin
Copy link
Member

Thanks.

@dkwingsmt dkwingsmt marked this pull request as ready for review June 11, 2021 11:30
@dkwingsmt dkwingsmt changed the title [WIP] Test if #81148 breaks Reland: MouseRegion enter/exit event can be triggered with button pressed Jun 11, 2021
@dkwingsmt dkwingsmt requested a review from gspencergoog June 11, 2021 12:17
@@ -282,7 +282,14 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
event is PointerAddedEvent ||
event is PointerRemovedEvent) {
assert(event.position != null);
_mouseTracker!.updateWithEvent(event, () => hitTestResult ?? renderView.hitTestMouseTrackers(event.position));
_mouseTracker!.updateWithEvent(
Copy link
Member

Choose a reason for hiding this comment

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

Could we only call _mouseTracker!.updateWithEven when it is a mouse event?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea is that RendererBinding provides all events and a way to compute hit test result for MouseTracker to retrieve when needed. In this way most logic is hidden in MouseTracker. Nevertheless I agree that the hit testing function is a little cumbersome. I'll take a moment to think if there's a better way but I'm probably sticking to it in the end.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It turns out that the if clause is unnecessary at all (according to the documentation, which I trust). Several assertions can also be removed since the NNBD. This should feel much cleaner.

Copy link
Contributor

@gspencergoog gspencergoog left a comment

Choose a reason for hiding this comment

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

32384589-a60f0e74-c078-11e7-9bc1-e5b5287aea9d

@@ -282,7 +282,14 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
event is PointerAddedEvent ||
event is PointerRemovedEvent) {
assert(event.position != null);
_mouseTracker!.updateWithEvent(event, () => hitTestResult ?? renderView.hitTestMouseTrackers(event.position));
_mouseTracker!.updateWithEvent(
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Member

@xu-baolin xu-baolin left a comment

Choose a reason for hiding this comment

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

LGTM

void updateWithEvent(PointerEvent event, ValueGetter<HitTestResult> getResult) {
assert(event != null);
final HitTestResult result = event is PointerRemovedEvent ? HitTestResult() : getResult();
assert(result != null);
if (event.kind != PointerDeviceKind.mouse)
return;
if (event is PointerSignalEvent)
return;
Copy link
Member

Choose a reason for hiding this comment

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

small nit:

if (event.kind != PointerDeviceKind.mouse || event is PointerSignalEvent)
  return;

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 slightly prefer the current way since they're describing 2 different things and splitting them is clearer.

@@ -278,12 +278,14 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture

@override // from GestureBinding
void dispatchEvent(PointerEvent event, HitTestResult? hitTestResult) {
if (hitTestResult != null ||
event is PointerAddedEvent ||
event is PointerRemovedEvent) {
Copy link
Member

Choose a reason for hiding this comment

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

Why did you think that this clause is unnecessary ?
For example hitTestResult == null && event is PointerMoveEvent, it seems that change some behaviours , right?

Copy link
Contributor Author

@dkwingsmt dkwingsmt Jun 12, 2021

Choose a reason for hiding this comment

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

According to https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/gestures/binding.dart#L390,

/// The `hitTestResult` argument may only be null for [PointerAddedEvent]s or
/// [PointerRemovedEvent]s.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for explanation, LGTM again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants