-
Notifications
You must be signed in to change notification settings - Fork 6k
Scrollwheel #6228
Scrollwheel #6228
Changes from all commits
b0c6a9a
77ed463
aa2d55f
4b2564f
b2f9fb2
a3b9ccf
5df34c7
6d22fd1
5f07f96
aae5b0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,9 @@ enum PointerChange { | |
|
||
/// The pointer has stopped making contact with the device. | ||
up, | ||
|
||
/// The pointer has scrolled | ||
scroll, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you change this back? This is incompatible with the second part of the change I'm working on, to support trackpad gesture scrolling. My intent is to finish that patch and then put both of them up for review so that the reason for the design choices I made was clear. I think it would make a lot more sense to wait and do it that way than to try to land this one and make changes to it without being able to see how that affects the whole design. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They weren't needed to get the mouse wheel scrolling working, and given that your GestureType only had one type of gesture I felt it wasn't necessary to implement it that way. I also thought you were no longer working on this? Didn't realize you intended to bring it through to the finish line. Anyway, I've stopped working on chrome book stuff for now as we are waiting on various design docs to come through. |
||
} | ||
|
||
/// The kind of pointer device. | ||
|
@@ -51,7 +54,7 @@ enum PointerDeviceKind { | |
invertedStylus, | ||
|
||
/// An unknown pointer device. | ||
unknown | ||
unknown, | ||
} | ||
|
||
/// Information about the state of a pointer. | ||
|
@@ -76,7 +79,10 @@ class PointerData { | |
this.radiusMin: 0.0, | ||
this.radiusMax: 0.0, | ||
this.orientation: 0.0, | ||
this.tilt: 0.0 | ||
this.scrollDeltaX: 0.0, | ||
this.scrollDeltaY: 0.0, | ||
this.tilt: 0.0, | ||
this.sentinal: 0.0, | ||
}); | ||
|
||
/// Time of event dispatch, relative to an arbitrary timeline. | ||
|
@@ -190,6 +196,19 @@ class PointerData { | |
/// the stylus is flat on that surface). | ||
final double tilt; | ||
|
||
/// For PointerDeviceKind.gesture with PointerGestureKind.scroll: | ||
/// | ||
/// The amount to scroll in the x direction, in physical pixels. | ||
final double scrollDeltaX; | ||
|
||
/// For PointerDeviceKind.gesture with PointerGestureKind.scroll: | ||
/// | ||
/// The amount to scroll in the y direction, in physical pixels. | ||
final double scrollDeltaY; | ||
|
||
/// A final value that is passed so that we are passing more than 21 values in the packet | ||
final double sentinal; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a way you could keep this field private? |
||
|
||
@override | ||
String toString() => '$runtimeType(x: $physicalX, y: $physicalY)'; | ||
|
||
|
@@ -203,6 +222,7 @@ class PointerData { | |
'physicalX: $physicalX, ' | ||
'physicalY: $physicalY, ' | ||
'buttons: $buttons, ' | ||
'obscured: $obscured' | ||
'pressure: $pressure, ' | ||
'pressureMin: $pressureMin, ' | ||
'pressureMax: $pressureMax, ' | ||
|
@@ -213,7 +233,10 @@ class PointerData { | |
'radiusMin: $radiusMin, ' | ||
'radiusMax: $radiusMax, ' | ||
'orientation: $orientation, ' | ||
'tilt: $tilt' | ||
'tilt: $tilt, ' | ||
'scrollDeltaX: $scrollDeltaX, ' | ||
'scrollDeltaY: $scrollDeltaY,' | ||
'sentinal: $sentinal' | ||
')'; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -371,6 +371,7 @@ public InputConnection onCreateInputConnection(EditorInfo outAttrs) { | |
private static final int kPointerChangeDown = 4; | ||
private static final int kPointerChangeMove = 5; | ||
private static final int kPointerChangeUp = 6; | ||
private static final int kPointerChangeScroll = 7; | ||
|
||
// Must match the PointerDeviceKind enum in pointer.dart. | ||
private static final int kPointerDeviceKindTouch = 0; | ||
|
@@ -401,6 +402,9 @@ private int getPointerChangeForAction(int maskedAction) { | |
if (maskedAction == MotionEvent.ACTION_CANCEL) { | ||
return kPointerChangeCancel; | ||
} | ||
if (maskedAction == MotionEvent.ACTION_SCROLL) { | ||
return kPointerChangeScroll; | ||
} | ||
return -1; | ||
} | ||
|
||
|
@@ -428,6 +432,8 @@ private void addPointerForIndex(MotionEvent event, int pointerIndex, ByteBuffer | |
|
||
int pointerKind = getPointerDeviceTypeForToolType(event.getToolType(pointerIndex)); | ||
|
||
// This is ignored for non-gesture deviced kinds. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure what you mean by this |
||
|
||
long timeStamp = event.getEventTime() * 1000; // Convert from milliseconds to microseconds. | ||
|
||
packet.putLong(timeStamp); // time_stamp | ||
|
@@ -437,6 +443,7 @@ private void addPointerForIndex(MotionEvent event, int pointerIndex, ByteBuffer | |
packet.putDouble(event.getX(pointerIndex)); // physical_x | ||
packet.putDouble(event.getY(pointerIndex)); // physical_y | ||
|
||
|
||
if (pointerKind == kPointerDeviceKindMouse) { | ||
packet.putLong(event.getButtonState() & 0x1F); // buttons | ||
} else if (pointerKind == kPointerDeviceKindStylus) { | ||
|
@@ -468,12 +475,55 @@ private void addPointerForIndex(MotionEvent event, int pointerIndex, ByteBuffer | |
packet.putDouble(0.0); // radius_max | ||
|
||
packet.putDouble(event.getAxisValue(MotionEvent.AXIS_ORIENTATION, pointerIndex)); // orientation | ||
|
||
if (pointerKind == kPointerDeviceKindStylus) { | ||
packet.putDouble(event.getAxisValue(MotionEvent.AXIS_TILT, pointerIndex)); // tilt | ||
} else { | ||
packet.putDouble(0.0); // tilt | ||
packet.putDouble(4.0); // tilt | ||
} | ||
packet.putDouble(event.getAxisValue(MotionEvent.AXIS_HSCROLL)); // scroll_delta_x | ||
packet.putDouble(event.getAxisValue(MotionEvent.AXIS_VSCROLL)); // scroll_delta_y | ||
|
||
// Dummy value that is needed due to bug in the converter writing the last 8 bytes | ||
// of the packet to 0. | ||
packet.putDouble(0.0); | ||
} | ||
|
||
@Override | ||
public boolean onGenericMotionEvent(MotionEvent event) { | ||
if (!isAttached()) { | ||
return false; | ||
} | ||
|
||
int maskedAction = event.getAction(); | ||
if (maskedAction != MotionEvent.ACTION_SCROLL) | ||
return false; | ||
|
||
// TODO(abarth): This version check might not be effective in some | ||
// versions of Android that statically compile code and will be upset | ||
// at the lack of |requestUnbufferedDispatch|. Instead, we should factor | ||
// version-dependent code into separate classes for each supported | ||
// version and dispatch dynamically. | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
requestUnbufferedDispatch(event); | ||
} | ||
|
||
// These values must match the unpacking code in hooks.dart. | ||
final int kPointerDataFieldCount = 22; | ||
final int kBytePerField = 8; | ||
|
||
int pointerCount = event.getPointerCount(); | ||
|
||
ByteBuffer packet = ByteBuffer.allocateDirect(pointerCount * kPointerDataFieldCount * kBytePerField); | ||
packet.order(ByteOrder.LITTLE_ENDIAN); | ||
|
||
for (int p = 0; p < pointerCount; p++) { | ||
addPointerForIndex(event, p, packet); | ||
} | ||
|
||
assert packet.position() % (kPointerDataFieldCount * kBytePerField) == 0; | ||
nativeDispatchPointerDataPacket(mNativeView.get(), packet, packet.position()); | ||
return true; | ||
} | ||
|
||
@Override | ||
|
@@ -492,7 +542,7 @@ public boolean onTouchEvent(MotionEvent event) { | |
} | ||
|
||
// These values must match the unpacking code in hooks.dart. | ||
final int kPointerDataFieldCount = 19; | ||
final int kPointerDataFieldCount = 22; | ||
final int kBytePerField = 8; | ||
|
||
int pointerCount = event.getPointerCount(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error happens when reading from the packet right? do you need to explicitly pass it or can you just ignore the last float?