Unverified Commit 94515ba5 authored by Tong Mu's avatar Tong Mu Committed by GitHub

Make MouseTracker.sendMouseNotifications private (#41879)

* Make sendMouseNotifications private
parent 10ddb7db
...@@ -131,8 +131,8 @@ class MouseTracker extends ChangeNotifier { ...@@ -131,8 +131,8 @@ class MouseTracker extends ChangeNotifier {
/// Stops tracking an annotation, indicating that it has been removed from the /// Stops tracking an annotation, indicating that it has been removed from the
/// layer tree. /// layer tree.
/// ///
/// If the associated layer is not removed, and receives a hit, then /// An assertion error will be thrown if the associated layer is not removed
/// [sendMouseNotifications] will assert the next time it is called. /// and receives another mouse hit.
void detachAnnotation(MouseTrackerAnnotation annotation) { void detachAnnotation(MouseTrackerAnnotation annotation) {
final _TrackedAnnotation trackedAnnotation = _findAnnotation(annotation); final _TrackedAnnotation trackedAnnotation = _findAnnotation(annotation);
for (int deviceId in trackedAnnotation.activeDevices) { for (int deviceId in trackedAnnotation.activeDevices) {
...@@ -155,7 +155,7 @@ class MouseTracker extends ChangeNotifier { ...@@ -155,7 +155,7 @@ class MouseTracker extends ChangeNotifier {
if (_trackedAnnotations.isNotEmpty && !_scheduledPostFramePositionCheck) { if (_trackedAnnotations.isNotEmpty && !_scheduledPostFramePositionCheck) {
_scheduledPostFramePositionCheck = true; _scheduledPostFramePositionCheck = true;
SchedulerBinding.instance.addPostFrameCallback((Duration duration) { SchedulerBinding.instance.addPostFrameCallback((Duration duration) {
sendMouseNotifications(_lastMouseEvent.keys); _sendMouseNotifications(_lastMouseEvent.keys);
_scheduledPostFramePositionCheck = false; _scheduledPostFramePositionCheck = false;
}); });
} }
...@@ -171,14 +171,14 @@ class MouseTracker extends ChangeNotifier { ...@@ -171,14 +171,14 @@ class MouseTracker extends ChangeNotifier {
// If we are adding the device again, then we're not removing it anymore. // If we are adding the device again, then we're not removing it anymore.
_pendingRemovals.remove(deviceId); _pendingRemovals.remove(deviceId);
_addMouseEvent(deviceId, event); _addMouseEvent(deviceId, event);
sendMouseNotifications(<int>{deviceId}); _sendMouseNotifications(<int>{deviceId});
return; return;
} }
if (event is PointerRemovedEvent) { if (event is PointerRemovedEvent) {
_removeMouseEvent(deviceId, event); _removeMouseEvent(deviceId, event);
// If the mouse was removed, then we need to schedule one more check to // If the mouse was removed, then we need to schedule one more check to
// exit any annotations that were active. // exit any annotations that were active.
sendMouseNotifications(<int>{deviceId}); _sendMouseNotifications(<int>{deviceId});
} else { } else {
if (event is PointerMoveEvent || event is PointerHoverEvent || event is PointerDownEvent) { if (event is PointerMoveEvent || event is PointerHoverEvent || event is PointerDownEvent) {
final PointerEvent lastEvent = _lastMouseEvent[deviceId]; final PointerEvent lastEvent = _lastMouseEvent[deviceId];
...@@ -187,7 +187,7 @@ class MouseTracker extends ChangeNotifier { ...@@ -187,7 +187,7 @@ class MouseTracker extends ChangeNotifier {
lastEvent is PointerAddedEvent || lastEvent.position != event.position) { lastEvent is PointerAddedEvent || lastEvent.position != event.position) {
// Only schedule a frame if we have our first event, or if the // Only schedule a frame if we have our first event, or if the
// location of the mouse has changed, and only if there are tracked annotations. // location of the mouse has changed, and only if there are tracked annotations.
sendMouseNotifications(<int>{deviceId}); _sendMouseNotifications(<int>{deviceId});
} }
} }
} }
...@@ -212,17 +212,13 @@ class MouseTracker extends ChangeNotifier { ...@@ -212,17 +212,13 @@ class MouseTracker extends ChangeNotifier {
return _trackedAnnotations.containsKey(annotation); return _trackedAnnotations.containsKey(annotation);
} }
/// Tells interested objects that a mouse has entered, exited, or moved, given // Tells interested objects that a mouse has entered, exited, or moved, given
/// a callback to fetch the [MouseTrackerAnnotation] associated with a global // a callback to fetch the [MouseTrackerAnnotation] associated with a global
/// offset. // offset.
/// //
/// This is called from a post-frame callback when the layer tree has been // This is called from a post-frame callback when the layer tree has been
/// updated, right after rendering the frame. // updated, right after rendering the frame.
/// void _sendMouseNotifications(Iterable<int> deviceIds) {
/// This function is only public to allow for proper testing of the
/// MouseTracker. Do not call in other contexts.
@visibleForTesting
void sendMouseNotifications(Iterable<int> deviceIds) {
if (_trackedAnnotations.isEmpty) { if (_trackedAnnotations.isEmpty) {
return; return;
} }
......
...@@ -93,7 +93,6 @@ void main() { ...@@ -93,7 +93,6 @@ void main() {
_pointerData(PointerChange.hover, const Offset(1.0, 401.0), device: 1), _pointerData(PointerChange.hover, const Offset(1.0, 401.0), device: 1),
]); ]);
RendererBinding.instance.mouseTracker.attachAnnotation(annotation); RendererBinding.instance.mouseTracker.attachAnnotation(annotation);
RendererBinding.instance.mouseTracker.sendMouseNotifications(<int>{0});
isInHitRegionOne = true; isInHitRegionOne = true;
ui.window.onPointerDataPacket(packet1); ui.window.onPointerDataPacket(packet1);
expect(events, _equalToEventsOnCriticalFields(<PointerEvent>[ expect(events, _equalToEventsOnCriticalFields(<PointerEvent>[
...@@ -124,11 +123,9 @@ void main() { ...@@ -124,11 +123,9 @@ void main() {
// add in a second mouse simultaneously. // add in a second mouse simultaneously.
clear(); clear();
ui.window.onPointerDataPacket(packet5); ui.window.onPointerDataPacket(packet5);
RendererBinding.instance.mouseTracker.sendMouseNotifications(<int>{1});
expect(events, _equalToEventsOnCriticalFields(<PointerEvent>[ expect(events, _equalToEventsOnCriticalFields(<PointerEvent>[
const PointerEnterEvent(position: Offset(1.0, 401.0), device: 1), const PointerEnterEvent(position: Offset(1.0, 401.0), device: 1),
const PointerHoverEvent(position: Offset(1.0, 401.0), device: 1), const PointerHoverEvent(position: Offset(1.0, 401.0), device: 1),
const PointerHoverEvent(position: Offset(1.0, 401.0), device: 1),
])); ]));
}); });
...@@ -142,7 +139,6 @@ void main() { ...@@ -142,7 +139,6 @@ void main() {
]); ]);
isInHitRegionOne = true; isInHitRegionOne = true;
RendererBinding.instance.mouseTracker.attachAnnotation(annotation); RendererBinding.instance.mouseTracker.attachAnnotation(annotation);
RendererBinding.instance.mouseTracker.sendMouseNotifications(<int>{0});
ui.window.onPointerDataPacket(packet1); ui.window.onPointerDataPacket(packet1);
...@@ -196,7 +192,6 @@ void main() { ...@@ -196,7 +192,6 @@ void main() {
]); ]);
isInHitRegionOne = true; isInHitRegionOne = true;
RendererBinding.instance.mouseTracker.attachAnnotation(annotation); RendererBinding.instance.mouseTracker.attachAnnotation(annotation);
RendererBinding.instance.mouseTracker.sendMouseNotifications(<int>{0});
ui.window.onPointerDataPacket(packet1); ui.window.onPointerDataPacket(packet1);
ui.window.onPointerDataPacket(packet2); ui.window.onPointerDataPacket(packet2);
expect(events, _equalToEventsOnCriticalFields(<PointerEvent>[ expect(events, _equalToEventsOnCriticalFields(<PointerEvent>[
...@@ -219,7 +214,6 @@ void main() { ...@@ -219,7 +214,6 @@ void main() {
]); ]);
isInHitRegionOne = true; isInHitRegionOne = true;
RendererBinding.instance.mouseTracker.attachAnnotation(annotation); RendererBinding.instance.mouseTracker.attachAnnotation(annotation);
RendererBinding.instance.mouseTracker.sendMouseNotifications(<int>{0});
ui.window.onPointerDataPacket(packet1); ui.window.onPointerDataPacket(packet1);
ui.window.onPointerDataPacket(packet2); ui.window.onPointerDataPacket(packet2);
expect(events, _equalToEventsOnCriticalFields(<PointerEvent>[ expect(events, _equalToEventsOnCriticalFields(<PointerEvent>[
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment