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
7b2004b0
Commit
7b2004b0
authored
Nov 17, 2015
by
Adam Barth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert PointerInputEvent to Duration for timestamp
To make the units clear.
parent
7ad947ac
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
26 additions
and
33 deletions
+26
-33
events.dart
packages/flutter/lib/src/gestures/events.dart
+3
-8
velocity_tracker.dart
packages/flutter/lib/src/gestures/velocity_tracker.dart
+12
-15
binding.dart
packages/flutter/lib/src/rendering/binding.dart
+3
-2
mock_events.dart
packages/unit/test/engine/mock_events.dart
+4
-4
velocity_tracker_test.dart
packages/unit/test/gestures/velocity_tracker_test.dart
+1
-1
widget_tester.dart
packages/unit/test/widget/widget_tester.dart
+3
-3
No files found.
packages/flutter/lib/src/gestures/events.dart
View file @
7b2004b0
...
...
@@ -8,14 +8,9 @@ export 'dart:ui' show Point;
/// Base class for input events.
class
InputEvent
{
const
InputEvent
({
this
.
type
,
this
.
timeStamp
:
0.0
});
const
InputEvent
({
this
.
type
,
this
.
timeStamp
:
const
Duration
()
});
final
String
type
;
// TODO: Should timeStamp be a DateTime object instead of double?
// Some client code (e.g. drag.dart) does math on the time stamp.
final
double
timeStamp
;
final
Duration
timeStamp
;
}
/// Input event representing a touch or button.
...
...
@@ -23,7 +18,7 @@ class PointerInputEvent extends InputEvent {
const
PointerInputEvent
({
String
type
,
double
timeStamp:
0.0
,
Duration
timeStamp:
const
Duration
()
,
this
.
pointer
:
0
,
this
.
kind
,
this
.
x
:
0.0
,
...
...
packages/flutter/lib/src/gestures/velocity_tracker.dart
View file @
7b2004b0
...
...
@@ -16,7 +16,7 @@ class GestureVelocity {
class
_Estimator
{
int
degree
;
double
time
;
Duration
time
;
List
<
double
>
xCoefficients
;
List
<
double
>
yCoefficients
;
double
confidence
;
...
...
@@ -32,7 +32,7 @@ class _Estimator {
}
abstract
class
_VelocityTrackerStrategy
{
void
addMovement
(
double
timeStamp
,
double
x
,
double
y
);
void
addMovement
(
Duration
timeStamp
,
double
x
,
double
y
);
bool
getEstimator
(
_Estimator
estimator
);
void
clear
();
}
...
...
@@ -45,7 +45,7 @@ enum _Weighting {
}
class
_Movement
{
double
eventTime
=
0.0
;
Duration
eventTime
=
const
Duration
()
;
ui
.
Point
position
=
ui
.
Point
.
origin
;
}
...
...
@@ -61,7 +61,7 @@ class _LeastSquaresVelocityTrackerStrategy extends _VelocityTrackerStrategy {
final
List
<
_Movement
>
_movements
;
int
_index
;
void
addMovement
(
double
timeStamp
,
double
x
,
double
y
)
{
void
addMovement
(
Duration
timeStamp
,
double
x
,
double
y
)
{
if
(++
_index
==
kHistorySize
)
_index
=
0
;
_Movement
movement
=
_getMovement
(
_index
);
...
...
@@ -81,7 +81,7 @@ class _LeastSquaresVelocityTrackerStrategy extends _VelocityTrackerStrategy {
do
{
_Movement
movement
=
_getMovement
(
index
);
double
age
=
newestMovement
.
eventTime
-
movement
.
eventTime
;
double
age
=
(
newestMovement
.
eventTime
-
movement
.
eventTime
).
inMilliseconds
.
toDouble
()
;
if
(
age
>
kHorizonMilliseconds
)
break
;
...
...
@@ -143,8 +143,7 @@ class _LeastSquaresVelocityTrackerStrategy extends _VelocityTrackerStrategy {
return
1.0
;
}
int
nextIndex
=
(
index
+
1
)
%
kHistorySize
;
double
deltaMilliseconds
=
_movements
[
nextIndex
].
eventTime
-
_movements
[
index
].
eventTime
;
int
deltaMilliseconds
=
(
_movements
[
nextIndex
].
eventTime
-
_movements
[
index
].
eventTime
).
inMilliseconds
;
if
(
deltaMilliseconds
<
0
)
return
0.5
;
if
(
deltaMilliseconds
<
10
)
...
...
@@ -159,8 +158,7 @@ class _LeastSquaresVelocityTrackerStrategy extends _VelocityTrackerStrategy {
// age 10ms: 1.0
// age 50ms: 1.0
// age 60ms: 0.5
double
ageMilliseconds
=
_movements
[
_index
].
eventTime
-
_movements
[
index
].
eventTime
;
int
ageMilliseconds
=
(
_movements
[
_index
].
eventTime
-
_movements
[
index
].
eventTime
).
inMilliseconds
;
if
(
ageMilliseconds
<
0
)
return
0.5
;
if
(
ageMilliseconds
<
10
)
...
...
@@ -177,8 +175,7 @@ class _LeastSquaresVelocityTrackerStrategy extends _VelocityTrackerStrategy {
// age 0ms: 1.0
// age 50ms: 1.0
// age 100ms: 0.5
double
ageMilliseconds
=
_movements
[
_index
].
eventTime
-
_movements
[
index
].
eventTime
;
int
ageMilliseconds
=
(
_movements
[
_index
].
eventTime
-
_movements
[
index
].
eventTime
).
inMilliseconds
;
if
(
ageMilliseconds
<
50
)
{
return
1.0
;
}
...
...
@@ -207,13 +204,13 @@ class _LeastSquaresVelocityTrackerStrategy extends _VelocityTrackerStrategy {
class
VelocityTracker
{
static
const
int
kAssumePointerMoveStoppedTimeMs
=
40
;
VelocityTracker
()
:
_
lastTimeStamp
=
0.0
,
_
strategy
=
_createStrategy
();
VelocityTracker
()
:
_strategy
=
_createStrategy
();
double
_lastTimeStamp
;
Duration
_lastTimeStamp
=
const
Duration
()
;
_VelocityTrackerStrategy
_strategy
;
void
addPosition
(
double
timeStamp
,
double
x
,
double
y
)
{
if
((
timeStamp
-
_lastTimeStamp
)
>=
kAssumePointerMoveStoppedTimeMs
)
void
addPosition
(
Duration
timeStamp
,
double
x
,
double
y
)
{
if
((
timeStamp
-
_lastTimeStamp
)
.
inMilliseconds
>=
kAssumePointerMoveStoppedTimeMs
)
_strategy
.
clear
();
_lastTimeStamp
=
timeStamp
;
_strategy
.
addMovement
(
timeStamp
,
x
,
y
);
...
...
packages/flutter/lib/src/rendering/binding.dart
View file @
7b2004b0
...
...
@@ -90,7 +90,7 @@ class _PointerEventConverter {
return
new
PointerInputEvent
(
type:
eventType
,
timeStamp:
pointer
.
timeStamp
.
toDouble
(
),
timeStamp:
new
Duration
(
microseconds:
pointer
.
timeStamp
),
pointer:
pointerIndex
,
kind:
_mapPointerKindToString
(
pointer
.
kind
),
x:
pointer
.
x
,
...
...
@@ -200,11 +200,12 @@ class FlutterBinding extends HitTestTarget {
/// Stops calling listener for every event that isn't localized to a given view coordinate
bool
removeEventListener
(
EventListener
listener
)
=>
_eventListeners
.
remove
(
listener
);
// TODO(abarth): The engine should give us the timeStamp in Durations.
void
_handleEvent
(
String
eventType
,
double
timeStamp
)
{
assert
(
eventType
==
'back'
);
InputEvent
ourEvent
=
new
InputEvent
(
type:
eventType
,
timeStamp:
timeStamp
timeStamp:
new
Duration
(
microseconds:
timeStamp
.
round
())
);
for
(
EventListener
listener
in
_eventListeners
)
listener
(
ourEvent
);
...
...
packages/unit/test/engine/mock_events.dart
View file @
7b2004b0
...
...
@@ -11,7 +11,7 @@ class TestPointer {
bool
isDown
=
false
;
ui
.
Point
location
;
PointerInputEvent
down
(
ui
.
Point
newLocation
,
{
double
timeStamp:
0.0
})
{
PointerInputEvent
down
(
ui
.
Point
newLocation
,
{
Duration
timeStamp:
const
Duration
()
})
{
assert
(!
isDown
);
isDown
=
true
;
location
=
newLocation
;
...
...
@@ -24,7 +24,7 @@ class TestPointer {
);
}
PointerInputEvent
move
(
ui
.
Point
newLocation
,
{
double
timeStamp:
0.0
})
{
PointerInputEvent
move
(
ui
.
Point
newLocation
,
{
Duration
timeStamp:
const
Duration
()
})
{
assert
(
isDown
);
ui
.
Offset
delta
=
newLocation
-
location
;
location
=
newLocation
;
...
...
@@ -39,7 +39,7 @@ class TestPointer {
);
}
PointerInputEvent
up
({
double
timeStamp:
0.0
})
{
PointerInputEvent
up
({
Duration
timeStamp:
const
Duration
()
})
{
assert
(
isDown
);
isDown
=
false
;
return
new
PointerInputEvent
(
...
...
@@ -51,7 +51,7 @@ class TestPointer {
);
}
PointerInputEvent
cancel
({
double
timeStamp:
0.0
})
{
PointerInputEvent
cancel
({
Duration
timeStamp:
const
Duration
()
})
{
assert
(
isDown
);
isDown
=
false
;
return
new
PointerInputEvent
(
...
...
packages/unit/test/gestures/velocity_tracker_test.dart
View file @
7b2004b0
...
...
@@ -24,7 +24,7 @@ List<PointerInputEvent> _eventFromMap(List<Map> intermediate) {
PointerInputEvent
_eventFor
(
Map
entry
)
{
PointerInputEvent
result
=
new
PointerInputEvent
(
type:
entry
[
'type'
],
timeStamp:
entry
[
'timeStamp'
]
,
timeStamp:
new
Duration
(
milliseconds:
entry
[
'timeStamp'
].
round
())
,
pointer:
entry
[
'pointer'
],
x:
entry
[
'x'
],
y:
entry
[
'y'
]
...
...
packages/unit/test/widget/widget_tester.dart
View file @
7b2004b0
...
...
@@ -165,13 +165,13 @@ class WidgetTester {
final
kMoveCount
=
50
;
// Needs to be >= kHistorySize, see _LeastSquaresVelocityTrackerStrategy
final
double
timeStampDelta
=
1000.0
*
offset
.
distance
/
(
kMoveCount
*
velocity
);
double
timeStamp
=
0.0
;
_dispatchEvent
(
p
.
down
(
startLocation
,
timeStamp:
timeStamp
),
result
);
_dispatchEvent
(
p
.
down
(
startLocation
,
timeStamp:
new
Duration
(
milliseconds:
timeStamp
.
round
())
),
result
);
for
(
int
i
=
0
;
i
<
kMoveCount
;
i
++)
{
final
Point
location
=
startLocation
+
Offset
.
lerp
(
Offset
.
zero
,
offset
,
i
/
kMoveCount
);
_dispatchEvent
(
p
.
move
(
location
,
timeStamp:
timeStamp
),
result
);
_dispatchEvent
(
p
.
move
(
location
,
timeStamp:
new
Duration
(
milliseconds:
timeStamp
.
round
())
),
result
);
timeStamp
+=
timeStampDelta
;
}
_dispatchEvent
(
p
.
up
(
timeStamp:
timeStamp
),
result
);
_dispatchEvent
(
p
.
up
(
timeStamp:
new
Duration
(
milliseconds:
timeStamp
.
round
())
),
result
);
}
void
scroll
(
Element
element
,
Offset
offset
,
{
int
pointer:
1
})
{
...
...
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