Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
a4f7a0df
Unverified
Commit
a4f7a0df
authored
Dec 09, 2019
by
Tong Mu
Committed by
GitHub
Dec 09, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert changes to TestPointer; MouseTracker no longer relies on Add events (#46285)
* Revert test pointer * Synthesize new state
parent
5406f2b5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
59 deletions
+21
-59
mouse_tracking.dart
packages/flutter/lib/src/gestures/mouse_tracking.dart
+13
-10
test_pointer.dart
packages/flutter_test/lib/src/test_pointer.dart
+8
-49
No files found.
packages/flutter/lib/src/gestures/mouse_tracking.dart
View file @
a4f7a0df
...
@@ -145,7 +145,7 @@ typedef _UpdatedDeviceHandler = void Function(_MouseState mouseState, LinkedHash
...
@@ -145,7 +145,7 @@ typedef _UpdatedDeviceHandler = void Function(_MouseState mouseState, LinkedHash
// Various states of a connected mouse device used by [MouseTracker].
// Various states of a connected mouse device used by [MouseTracker].
class
_MouseState
{
class
_MouseState
{
_MouseState
({
_MouseState
({
@required
Pointer
Added
Event
initialEvent
,
@required
PointerEvent
initialEvent
,
})
:
assert
(
initialEvent
!=
null
),
})
:
assert
(
initialEvent
!=
null
),
_latestEvent
=
initialEvent
;
_latestEvent
=
initialEvent
;
...
@@ -289,6 +289,7 @@ class MouseTracker extends ChangeNotifier {
...
@@ -289,6 +289,7 @@ class MouseTracker extends ChangeNotifier {
return
;
return
;
final
PointerEvent
previousEvent
=
existingState
?.
latestEvent
;
final
PointerEvent
previousEvent
=
existingState
?.
latestEvent
;
final
Offset
lastHoverPosition
=
previousEvent
is
!
PointerHoverEvent
?
null
:
previousEvent
.
position
;
_updateDevices
(
_updateDevices
(
targetEvent:
event
,
targetEvent:
event
,
handleUpdatedDevice:
(
_MouseState
mouseState
,
LinkedHashSet
<
MouseTrackerAnnotation
>
previousAnnotations
)
{
handleUpdatedDevice:
(
_MouseState
mouseState
,
LinkedHashSet
<
MouseTrackerAnnotation
>
previousAnnotations
)
{
...
@@ -296,7 +297,7 @@ class MouseTracker extends ChangeNotifier {
...
@@ -296,7 +297,7 @@ class MouseTracker extends ChangeNotifier {
_dispatchDeviceCallbacks
(
_dispatchDeviceCallbacks
(
lastAnnotations:
previousAnnotations
,
lastAnnotations:
previousAnnotations
,
nextAnnotations:
mouseState
.
annotations
,
nextAnnotations:
mouseState
.
annotations
,
handledEvent:
previousEvent
,
lastHoverPosition:
lastHoverPosition
,
unhandledEvent:
event
,
unhandledEvent:
event
,
trackedAnnotations:
_trackedAnnotations
,
trackedAnnotations:
_trackedAnnotations
,
);
);
...
@@ -327,10 +328,12 @@ class MouseTracker extends ChangeNotifier {
...
@@ -327,10 +328,12 @@ class MouseTracker extends ChangeNotifier {
void
_updateAllDevices
()
{
void
_updateAllDevices
()
{
_updateDevices
(
_updateDevices
(
handleUpdatedDevice:
(
_MouseState
mouseState
,
LinkedHashSet
<
MouseTrackerAnnotation
>
previousAnnotations
)
{
handleUpdatedDevice:
(
_MouseState
mouseState
,
LinkedHashSet
<
MouseTrackerAnnotation
>
previousAnnotations
)
{
final
PointerEvent
latestEvent
=
mouseState
.
latestEvent
;
final
Offset
lastHoverPosition
=
latestEvent
is
PointerHoverEvent
?
latestEvent
.
position
:
null
;
_dispatchDeviceCallbacks
(
_dispatchDeviceCallbacks
(
lastAnnotations:
previousAnnotations
,
lastAnnotations:
previousAnnotations
,
nextAnnotations:
mouseState
.
annotations
,
nextAnnotations:
mouseState
.
annotations
,
handledEvent:
mouseState
.
latestEvent
,
lastHoverPosition:
lastHoverPosition
,
unhandledEvent:
mouseState
.
latestEvent
,
unhandledEvent:
mouseState
.
latestEvent
,
trackedAnnotations:
_trackedAnnotations
,
trackedAnnotations:
_trackedAnnotations
,
);
);
...
@@ -385,11 +388,11 @@ class MouseTracker extends ChangeNotifier {
...
@@ -385,11 +388,11 @@ class MouseTracker extends ChangeNotifier {
_MouseState
targetState
;
_MouseState
targetState
;
if
(
targetEvent
!=
null
)
{
if
(
targetEvent
!=
null
)
{
targetState
=
_mouseStates
[
targetEvent
.
device
];
targetState
=
_mouseStates
[
targetEvent
.
device
];
assert
((
targetState
==
null
)
==
(
targetEvent
is
PointerAddedEvent
));
if
(
targetState
==
null
)
{
if
(
targetEvent
is
PointerAddedEvent
)
{
targetState
=
_MouseState
(
initialEvent:
targetEvent
);
targetState
=
_MouseState
(
initialEvent:
targetEvent
);
_mouseStates
[
targetState
.
device
]
=
targetState
;
_mouseStates
[
targetState
.
device
]
=
targetState
;
}
else
{
}
else
{
assert
(
targetEvent
is
!
PointerAddedEvent
);
targetState
.
latestEvent
=
targetEvent
;
targetState
.
latestEvent
=
targetEvent
;
// Update mouseState to the latest devices that have not been removed,
// Update mouseState to the latest devices that have not been removed,
// so that [mouseIsConnected], which is decided by `_mouseStates`, is
// so that [mouseIsConnected], which is decided by `_mouseStates`, is
...
@@ -424,17 +427,18 @@ class MouseTracker extends ChangeNotifier {
...
@@ -424,17 +427,18 @@ class MouseTracker extends ChangeNotifier {
// Dispatch callbacks related to a device after all necessary information
// Dispatch callbacks related to a device after all necessary information
// has been collected.
// has been collected.
//
//
// The `unhandledEvent` can be null. Other arguments must not be null.
// The `lastHoverPosition` can be null, which means the last event is not a
// hover. Other arguments must not be null.
static
void
_dispatchDeviceCallbacks
({
static
void
_dispatchDeviceCallbacks
({
@required
LinkedHashSet
<
MouseTrackerAnnotation
>
lastAnnotations
,
@required
LinkedHashSet
<
MouseTrackerAnnotation
>
lastAnnotations
,
@required
LinkedHashSet
<
MouseTrackerAnnotation
>
nextAnnotations
,
@required
LinkedHashSet
<
MouseTrackerAnnotation
>
nextAnnotations
,
@required
PointerEvent
handledEvent
,
@required
Offset
lastHoverPosition
,
@required
PointerEvent
unhandledEvent
,
@required
PointerEvent
unhandledEvent
,
@required
Set
<
MouseTrackerAnnotation
>
trackedAnnotations
,
@required
Set
<
MouseTrackerAnnotation
>
trackedAnnotations
,
})
{
})
{
assert
(
lastAnnotations
!=
null
);
assert
(
lastAnnotations
!=
null
);
assert
(
nextAnnotations
!=
null
);
assert
(
nextAnnotations
!=
null
);
//
handledEvent
can be null
//
lastHoverPosition
can be null
assert
(
unhandledEvent
!=
null
);
assert
(
unhandledEvent
!=
null
);
assert
(
trackedAnnotations
!=
null
);
assert
(
trackedAnnotations
!=
null
);
// Order is important for mouse event callbacks. The `findAnnotations`
// Order is important for mouse event callbacks. The `findAnnotations`
...
@@ -477,8 +481,7 @@ class MouseTracker extends ChangeNotifier {
...
@@ -477,8 +481,7 @@ class MouseTracker extends ChangeNotifier {
// or the position has changed
// or the position has changed
assert
(
trackedAnnotations
.
contains
(
annotation
));
assert
(
trackedAnnotations
.
contains
(
annotation
));
if
(!
lastAnnotations
.
contains
(
annotation
)
if
(!
lastAnnotations
.
contains
(
annotation
)
||
handledEvent
is
!
PointerHoverEvent
||
lastHoverPosition
!=
unhandledEvent
.
position
)
{
||
handledEvent
.
position
!=
unhandledEvent
.
position
)
{
if
(
annotation
.
onHover
!=
null
)
{
if
(
annotation
.
onHover
!=
null
)
{
annotation
.
onHover
(
unhandledEvent
);
annotation
.
onHover
(
unhandledEvent
);
}
}
...
...
packages/flutter_test/lib/src/test_pointer.dart
View file @
a4f7a0df
...
@@ -337,16 +337,12 @@ class TestGesture {
...
@@ -337,16 +337,12 @@ class TestGesture {
_dispatcher
=
dispatcher
,
_dispatcher
=
dispatcher
,
_hitTester
=
hitTester
,
_hitTester
=
hitTester
,
_pointer
=
TestPointer
(
pointer
,
kind
,
device
,
buttons
),
_pointer
=
TestPointer
(
pointer
,
kind
,
device
,
buttons
),
_added
=
false
,
_result
=
null
;
_result
=
null
;
/// Dispatch a pointer down event at the given `downLocation`, caching the
/// Dispatch a pointer down event at the given `downLocation`, caching the
/// hit test result.
/// hit test result.
///
Future
<
void
>
down
(
Offset
downLocation
)
async
{
/// If the pointer has not been added, an added event will be dispatched first.
Future
<
void
>
down
(
Offset
downLocation
)
{
return
TestAsyncUtils
.
guard
<
void
>(()
async
{
return
TestAsyncUtils
.
guard
<
void
>(()
async
{
await
_ensureAdded
(
location:
downLocation
);
_result
=
_hitTester
(
downLocation
);
_result
=
_hitTester
(
downLocation
);
return
_dispatcher
(
_pointer
.
down
(
downLocation
),
_result
);
return
_dispatcher
(
_pointer
.
down
(
downLocation
),
_result
);
});
});
...
@@ -354,12 +350,9 @@ class TestGesture {
...
@@ -354,12 +350,9 @@ class TestGesture {
/// Dispatch a pointer down event at the given `downLocation`, caching the
/// Dispatch a pointer down event at the given `downLocation`, caching the
/// hit test result with a custom down event.
/// hit test result with a custom down event.
///
Future
<
void
>
downWithCustomEvent
(
Offset
downLocation
,
PointerDownEvent
event
)
async
{
/// If the pointer has not been added, an added event will be dispatched first.
_pointer
.
setDownInfo
(
event
,
downLocation
);
Future
<
void
>
downWithCustomEvent
(
Offset
downLocation
,
PointerDownEvent
event
)
{
return
TestAsyncUtils
.
guard
<
void
>(()
async
{
return
TestAsyncUtils
.
guard
<
void
>(()
async
{
await
_ensureAdded
(
location:
downLocation
);
_pointer
.
setDownInfo
(
event
,
downLocation
);
_result
=
_hitTester
(
downLocation
);
_result
=
_hitTester
(
downLocation
);
return
_dispatcher
(
event
,
_result
);
return
_dispatcher
(
event
,
_result
);
});
});
...
@@ -369,22 +362,10 @@ class TestGesture {
...
@@ -369,22 +362,10 @@ class TestGesture {
final
HitTester
_hitTester
;
final
HitTester
_hitTester
;
final
TestPointer
_pointer
;
final
TestPointer
_pointer
;
HitTestResult
_result
;
HitTestResult
_result
;
bool
_added
;
Future
<
void
>
_ensureAdded
({
Offset
location
})
async
{
if
(!
_added
)
{
await
addPointer
(
location:
location
??
_pointer
.
location
);
}
}
/// In a test, send a move event that moves the pointer by the given offset.
/// In a test, send a move event that moves the pointer by the given offset.
///
/// If the pointer has not been added, and the subject event is not an added
/// event, an added event will be dispatched first.
@visibleForTesting
@visibleForTesting
Future
<
void
>
updateWithCustomEvent
(
PointerEvent
event
,
{
Duration
timeStamp
=
Duration
.
zero
})
async
{
Future
<
void
>
updateWithCustomEvent
(
PointerEvent
event
,
{
Duration
timeStamp
=
Duration
.
zero
})
{
if
(
event
is
!
PointerAddedEvent
)
await
_ensureAdded
(
location:
event
.
position
);
_pointer
.
setDownInfo
(
event
,
event
.
position
);
_pointer
.
setDownInfo
(
event
,
event
.
position
);
return
TestAsyncUtils
.
guard
<
void
>(()
{
return
TestAsyncUtils
.
guard
<
void
>(()
{
return
_dispatcher
(
event
,
_result
);
return
_dispatcher
(
event
,
_result
);
...
@@ -392,34 +373,21 @@ class TestGesture {
...
@@ -392,34 +373,21 @@ class TestGesture {
}
}
/// In a test, send a pointer add event for this pointer.
/// In a test, send a pointer add event for this pointer.
///
/// If a pointer has been added, the pointer will be removed first.
Future
<
void
>
addPointer
({
Duration
timeStamp
=
Duration
.
zero
,
Offset
location
})
{
Future
<
void
>
addPointer
({
Duration
timeStamp
=
Duration
.
zero
,
Offset
location
})
{
return
TestAsyncUtils
.
guard
<
void
>(()
async
{
return
TestAsyncUtils
.
guard
<
void
>(()
{
if
(
_added
)
{
await
removePointer
(
timeStamp:
timeStamp
);
}
_added
=
true
;
return
_dispatcher
(
_pointer
.
addPointer
(
timeStamp:
timeStamp
,
location:
location
??
_pointer
.
location
),
null
);
return
_dispatcher
(
_pointer
.
addPointer
(
timeStamp:
timeStamp
,
location:
location
??
_pointer
.
location
),
null
);
});
});
}
}
/// In a test, send a pointer remove event for this pointer.
/// In a test, send a pointer remove event for this pointer.
///
/// If no pointer has been added, the call will be a no-op.
Future
<
void
>
removePointer
({
Duration
timeStamp
=
Duration
.
zero
,
Offset
location
})
{
Future
<
void
>
removePointer
({
Duration
timeStamp
=
Duration
.
zero
,
Offset
location
})
{
return
TestAsyncUtils
.
guard
<
void
>(()
async
{
return
TestAsyncUtils
.
guard
<
void
>(()
{
if
(!
_added
)
return
_dispatcher
(
_pointer
.
removePointer
(
timeStamp:
timeStamp
,
location:
location
??
_pointer
.
location
),
null
);
return
;
_added
=
false
;
await
_dispatcher
(
_pointer
.
removePointer
(
timeStamp:
timeStamp
,
location:
location
??
_pointer
.
location
),
null
);
});
});
}
}
/// Send a move event moving the pointer by the given offset.
/// Send a move event moving the pointer by the given offset.
///
///
/// If the pointer has not been added, an added event will be dispatched first.
///
/// If the pointer is down, then a move event is dispatched. If the pointer is
/// If the pointer is down, then a move event is dispatched. If the pointer is
/// up, then a hover event is dispatched. Touch devices are not able to send
/// up, then a hover event is dispatched. Touch devices are not able to send
/// hover events.
/// hover events.
...
@@ -429,14 +397,11 @@ class TestGesture {
...
@@ -429,14 +397,11 @@ class TestGesture {
/// Send a move event moving the pointer to the given location.
/// Send a move event moving the pointer to the given location.
///
///
/// If the pointer has not been added, an added event will be dispatched first.
///
/// If the pointer is down, then a move event is dispatched. If the pointer is
/// If the pointer is down, then a move event is dispatched. If the pointer is
/// up, then a hover event is dispatched. Touch devices are not able to send
/// up, then a hover event is dispatched. Touch devices are not able to send
/// hover events.
/// hover events.
Future
<
void
>
moveTo
(
Offset
location
,
{
Duration
timeStamp
=
Duration
.
zero
})
{
Future
<
void
>
moveTo
(
Offset
location
,
{
Duration
timeStamp
=
Duration
.
zero
})
{
return
TestAsyncUtils
.
guard
<
void
>(()
async
{
return
TestAsyncUtils
.
guard
<
void
>(()
{
await
_ensureAdded
(
location:
location
);
if
(
_pointer
.
_isDown
)
{
if
(
_pointer
.
_isDown
)
{
assert
(
_result
!=
null
,
assert
(
_result
!=
null
,
'Move events with the pointer down must be preceded by a down '
'Move events with the pointer down must be preceded by a down '
...
@@ -451,11 +416,8 @@ class TestGesture {
...
@@ -451,11 +416,8 @@ class TestGesture {
}
}
/// End the gesture by releasing the pointer.
/// End the gesture by releasing the pointer.
///
/// If the pointer has not been added, an added event will be dispatched first.
Future
<
void
>
up
()
{
Future
<
void
>
up
()
{
return
TestAsyncUtils
.
guard
<
void
>(()
async
{
return
TestAsyncUtils
.
guard
<
void
>(()
async
{
await
_ensureAdded
();
assert
(
_pointer
.
_isDown
);
assert
(
_pointer
.
_isDown
);
await
_dispatcher
(
_pointer
.
up
(),
_result
);
await
_dispatcher
(
_pointer
.
up
(),
_result
);
assert
(!
_pointer
.
_isDown
);
assert
(!
_pointer
.
_isDown
);
...
@@ -466,11 +428,8 @@ class TestGesture {
...
@@ -466,11 +428,8 @@ class TestGesture {
/// End the gesture by canceling the pointer (as would happen if the
/// End the gesture by canceling the pointer (as would happen if the
/// system showed a modal dialog on top of the Flutter application,
/// system showed a modal dialog on top of the Flutter application,
/// for instance).
/// for instance).
///
/// If the pointer has not been added, an added event will be dispatched first.
Future
<
void
>
cancel
()
{
Future
<
void
>
cancel
()
{
return
TestAsyncUtils
.
guard
<
void
>(()
async
{
return
TestAsyncUtils
.
guard
<
void
>(()
async
{
await
_ensureAdded
();
assert
(
_pointer
.
_isDown
);
assert
(
_pointer
.
_isDown
);
await
_dispatcher
(
_pointer
.
cancel
(),
_result
);
await
_dispatcher
(
_pointer
.
cancel
(),
_result
);
assert
(!
_pointer
.
_isDown
);
assert
(!
_pointer
.
_isDown
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment