Skip to content

Commit

Permalink
Revert "Add support for double tap action from Apple Pencil 2" (#41138)
Browse files Browse the repository at this point in the history
Reverts #39637

Since this feature flutter/flutter#73172 has
been scrapped for now, previous engine work should be reverted. Refer to
[this design
doc](https://docs.google.com/document/d/1r4P5r-jGt2Sjqro3ldCU2axUiHTpu3yhIycnI94OKQw/edit
) for more discussion and details.
  • Loading branch information
LouiseHsu committed Apr 13, 2023
1 parent 1289f4b commit ce7be00
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 230 deletions.
3 changes: 1 addition & 2 deletions lib/ui/platform_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ class PlatformDispatcher {
// * pointer_data.cc
// * pointer.dart
// * AndroidTouchProcessor.java
static const int _kPointerDataFieldCount = 36;
static const int _kPointerDataFieldCount = 35;

static PointerDataPacket _unpackPointerDataPacket(ByteData packet) {
const int kStride = Int64List.bytesPerElement;
Expand Down Expand Up @@ -438,7 +438,6 @@ class PlatformDispatcher {
panDeltaY: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
scale: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
rotation: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
preferredStylusAuxiliaryAction: PointerPreferredStylusAuxiliaryAction.values[packet.getInt64(kStride * offset++, _kFakeHostEndian)],
));
assert(offset == (i + 1) * _kPointerDataFieldCount);
}
Expand Down
30 changes: 1 addition & 29 deletions lib/ui/pointer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,31 +133,10 @@ enum PointerSignalKind {
/// A pointer-generated scale event (e.g. trackpad pinch).
scale,

/// A stylus generated action (e.g. double tap on Apple Pencil 2)
stylusAuxiliaryAction,

/// An unknown pointer signal kind.
unknown
}

/// The preferred action for stylus action
enum PointerPreferredStylusAuxiliaryAction {
/// Ignore pointer input
ignore,

/// Show colour palette if available
showColorPalette,

/// Switch to eraser if available
switchEraser,

/// Switch to previous tool
switchPrevious,

/// unknown preferred action
unknown,
}

/// Information about the state of a pointer.
class PointerData {
/// Creates an object that represents the state of a pointer.
Expand Down Expand Up @@ -197,7 +176,6 @@ class PointerData {
this.panDeltaY = 0.0,
this.scale = 0.0,
this.rotation = 0.0,
this.preferredStylusAuxiliaryAction = PointerPreferredStylusAuxiliaryAction.ignore,
});

/// Unique identifier that ties the [PointerEvent] to embedder event created it.
Expand Down Expand Up @@ -396,11 +374,6 @@ class PointerData {
/// The current angle of the pan/zoom in radians, with 0.0 as the initial angle.
final double rotation;

/// For events with signal kind of stylusAuxiliaryAction
///
/// The current preferred action for stylusAuxiliaryAction, with ignore as the default.
final PointerPreferredStylusAuxiliaryAction preferredStylusAuxiliaryAction;

@override
String toString() => 'PointerData(x: $physicalX, y: $physicalY)';

Expand Down Expand Up @@ -440,8 +413,7 @@ class PointerData {
'panDeltaX: $panDeltaX, '
'panDeltaY: $panDeltaY, '
'scale: $scale, '
'rotation: $rotation, '
'preferredStylusAuxiliaryAction: $preferredStylusAuxiliaryAction'
'rotation: $rotation'
')';
}
}
Expand Down
13 changes: 1 addition & 12 deletions lib/ui/window/pointer_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace flutter {

// If this value changes, update the pointer data unpacking code in
// platform_dispatcher.dart.
static constexpr int kPointerDataFieldCount = 36;
static constexpr int kPointerDataFieldCount = 35;
static constexpr int kBytesPerField = sizeof(int64_t);
// Must match the button constants in events.dart.
enum PointerButtonMouse : int64_t {
Expand Down Expand Up @@ -63,16 +63,6 @@ struct alignas(8) PointerData {
kScroll,
kScrollInertiaCancel,
kScale,
kStylusAuxiliaryAction,
};

// Must match the PreferredStylusAuxiliaryAction enum in pointer.dart.
enum class PreferredStylusAuxiliaryAction : int64_t {
kIgnore,
kShowColorPalette,
kSwitchEraser,
kSwitchPrevious,
kUnknown
};

int64_t embedder_id;
Expand Down Expand Up @@ -110,7 +100,6 @@ struct alignas(8) PointerData {
double pan_delta_y;
double scale;
double rotation;
PreferredStylusAuxiliaryAction preferred_auxiliary_stylus_action;

void Clear();
};
Expand Down
1 change: 0 additions & 1 deletion lib/ui/window/pointer_data_packet_converter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ void PointerDataPacketConverter::ConvertPointerData(
switch (pointer_data.signal_kind) {
case PointerData::SignalKind::kScroll:
case PointerData::SignalKind::kScrollInertiaCancel:
case PointerData::SignalKind::kStylusAuxiliaryAction:
case PointerData::SignalKind::kScale: {
// Makes sure we have an existing pointer
auto iter = states_.find(pointer_data.device);
Expand Down
6 changes: 0 additions & 6 deletions lib/ui/window/pointer_data_packet_converter_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ void CreateSimulatedPointerData(PointerData& data, // NOLINT
data.platformData = 0;
data.scroll_delta_x = 0.0;
data.scroll_delta_y = 0.0;
data.preferred_auxiliary_stylus_action =
PointerData::PreferredStylusAuxiliaryAction::kIgnore;
}

void CreateSimulatedMousePointerData(PointerData& data, // NOLINT
Expand Down Expand Up @@ -86,8 +84,6 @@ void CreateSimulatedMousePointerData(PointerData& data, // NOLINT
data.platformData = 0;
data.scroll_delta_x = scroll_delta_x;
data.scroll_delta_y = scroll_delta_y;
data.preferred_auxiliary_stylus_action =
PointerData::PreferredStylusAuxiliaryAction::kIgnore;
}

void CreateSimulatedTrackpadGestureData(PointerData& data, // NOLINT
Expand Down Expand Up @@ -133,8 +129,6 @@ void CreateSimulatedTrackpadGestureData(PointerData& data, // NOLINT
data.pan_delta_y = 0.0;
data.scale = scale;
data.rotation = rotation;
data.preferred_auxiliary_stylus_action =
PointerData::PreferredStylusAuxiliaryAction::kIgnore;
}

void UnpackPointerPacket(std::vector<PointerData>& output, // NOLINT
Expand Down
23 changes: 1 addition & 22 deletions lib/web_ui/lib/pointer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,6 @@ enum PointerSignalKind {
unknown
}

/// The preferred action for stylus action
enum PointerPreferredStylusAuxiliaryAction {
/// Ignore pointer input
ignore,

/// Show colour palette if available
showColorPalette,

/// Switch to eraser if available
switchEraser,

/// Switch to previous tool
switchPrevious,

/// unknown preferred action
unknown,
}

class PointerData {
const PointerData({
this.embedderId = 0,
Expand Down Expand Up @@ -89,7 +71,6 @@ class PointerData {
this.panDeltaY = 0.0,
this.scale = 0.0,
this.rotation = 0.0,
this.preferredStylusAuxiliaryAction = PointerPreferredStylusAuxiliaryAction.ignore,
});
final int embedderId;
final Duration timeStamp;
Expand Down Expand Up @@ -126,7 +107,6 @@ class PointerData {
final double panDeltaY;
final double scale;
final double rotation;
final PointerPreferredStylusAuxiliaryAction preferredStylusAuxiliaryAction;

@override
String toString() => 'PointerData(x: $physicalX, y: $physicalY)';
Expand Down Expand Up @@ -165,8 +145,7 @@ class PointerData {
'panDeltaX: $panDeltaX, '
'panDeltaY: $panDeltaY, '
'scale: $scale, '
'rotation: $rotation, '
'preferredStylusAuxiliaryAction: $preferredStylusAuxiliaryAction'
'rotation: $rotation'
')';
}
}
Expand Down
2 changes: 0 additions & 2 deletions shell/common/input_events_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ void CreateSimulatedPointerData(PointerData& data,
data.platformData = 0;
data.scroll_delta_x = 0.0;
data.scroll_delta_y = 0.0;
data.preferred_auxiliary_stylus_action =
PointerData::PreferredStylusAuxiliaryAction::kIgnore;
}

TEST_F(ShellTest, MissAtMostOneFrameForIrregularInputEvents) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,36 +66,18 @@ public class AndroidTouchProcessor {
PointerSignalKind.SCROLL,
PointerSignalKind.SCROLL_INERTIA_CANCEL,
PointerSignalKind.SCALE,
PointerSignalKind.STYLUS_AUXILIARY_ACTION,
PointerSignalKind.UNKNOWN
})
public @interface PointerSignalKind {
int NONE = 0;
int SCROLL = 1;
int SCROLL_INERTIA_CANCEL = 2;
int SCALE = 3;
int STYLUS_AUXILIARY_ACTION = 4;
int UNKNOWN = 5;
}

// Must match the PointerPreferredStylusAuxiliaryAction enum in pointer.dart.
@IntDef({
PointerPreferredStylusAuxiliaryAction.IGNORE,
PointerPreferredStylusAuxiliaryAction.SHOW_COLOR_PALETTE,
PointerPreferredStylusAuxiliaryAction.SWITCH_ERASER,
PointerPreferredStylusAuxiliaryAction.SWITCH_PREVIOUS,
PointerPreferredStylusAuxiliaryAction.UNKNOWN
})
public @interface PointerPreferredStylusAuxiliaryAction {
int IGNORE = 0;
int SHOW_COLOR_PALETTE = 1;
int SWITCH_ERASER = 2;
int SWITCH_PREVIOUS = 3;
int UNKNOWN = 4;
}

// Must match the unpacking code in hooks.dart.
private static final int POINTER_DATA_FIELD_COUNT = 36;
private static final int POINTER_DATA_FIELD_COUNT = 35;
@VisibleForTesting static final int BYTES_PER_FIELD = 8;

// This value must match the value in framework's platform_view.dart.
Expand Down Expand Up @@ -373,8 +355,6 @@ private void addPointerForIndex(
packet.putDouble(1.0); // scale
packet.putDouble(0.0); // rotation

packet.putLong(PointerPreferredStylusAuxiliaryAction.IGNORE); // preferred stylus action

if (isTrackpadPan && getPointerChangeForPanZoom(pointerChange) == PointerChange.PAN_ZOOM_END) {
ongoingPans.remove(event.getPointerId(pointerIndex));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@
// This is left a FlutterBinaryMessenger privately for now to give people a chance to notice the
// change. Unfortunately unless you have Werror turned on, incompatible pointers as arguments are
// just a warning.
@interface FlutterViewController () <FlutterBinaryMessenger,
UIScrollViewDelegate,
UIPencilInteractionDelegate>
@interface FlutterViewController () <FlutterBinaryMessenger, UIScrollViewDelegate>
@property(nonatomic, readwrite, getter=isDisplayingFlutterUI) BOOL displayingFlutterUI;
@property(nonatomic, assign) BOOL isHomeIndicatorHidden;
@property(nonatomic, assign) BOOL isPresentingViewControllerAnimating;
Expand Down Expand Up @@ -99,7 +97,7 @@ @interface FlutterViewController () <FlutterBinaryMessenger,
// Trackpad rotating
@property(nonatomic, retain)
UIRotationGestureRecognizer* rotationGestureRecognizer API_AVAILABLE(ios(13.4));
@property(nonatomic, retain) UIPencilInteraction* pencilInteraction API_AVAILABLE(ios(13.4));

/**
* Creates and registers plugins used by this view controller.
*/
Expand Down Expand Up @@ -724,10 +722,6 @@ - (void)viewDidLoad {
[self createTouchRateCorrectionVSyncClientIfNeeded];

if (@available(iOS 13.4, *)) {
_pencilInteraction = [[UIPencilInteraction alloc] init];
_pencilInteraction.delegate = self;
[_flutterView addInteraction:_pencilInteraction];

_hoverGestureRecognizer =
[[UIHoverGestureRecognizer alloc] initWithTarget:self action:@selector(hoverEvent:)];
_hoverGestureRecognizer.delegate = self;
Expand Down Expand Up @@ -901,8 +895,6 @@ - (void)dealloc {
[_pinchGestureRecognizer release];
_rotationGestureRecognizer.delegate = nil;
[_rotationGestureRecognizer release];
_pencilInteraction.delegate = nil;
[_pencilInteraction release];
[super dealloc];
}

Expand Down Expand Up @@ -977,7 +969,7 @@ - (void)goToApplicationLifecycle:(nonnull NSString*)state {
case UITouchTypeDirect:
case UITouchTypeIndirect:
return flutter::PointerData::DeviceKind::kTouch;
case UITouchTypePencil:
case UITouchTypeStylus:
return flutter::PointerData::DeviceKind::kStylus;
case UITouchTypeIndirectPointer:
return flutter::PointerData::DeviceKind::kMouse;
Expand Down Expand Up @@ -1232,50 +1224,6 @@ - (void)invalidateTouchRateCorrectionVSyncClient {
_touchRateCorrectionVSyncClient = nil;
}

#pragma mark - Stylus Events

- (void)pencilInteractionDidTap:(UIPencilInteraction*)interaction API_AVAILABLE(ios(13.4)) {
flutter::PointerData pointer_data = [self createAuxillaryStylusActionData];

auto packet = std::make_unique<flutter::PointerDataPacket>(1);
packet->SetPointerData(/*index=*/0, pointer_data);
[_engine.get() dispatchPointerDataPacket:std::move(packet)];
}

- (flutter::PointerData)createAuxillaryStylusActionData API_AVAILABLE(ios(13.4)) {
flutter::PointerData pointer_data;
pointer_data.Clear();

switch (UIPencilInteraction.preferredTapAction) {
case UIPencilPreferredActionIgnore:
pointer_data.preferred_auxiliary_stylus_action =
flutter::PointerData::PreferredStylusAuxiliaryAction::kIgnore;
break;
case UIPencilPreferredActionShowColorPalette:
pointer_data.preferred_auxiliary_stylus_action =
flutter::PointerData::PreferredStylusAuxiliaryAction::kShowColorPalette;
break;
case UIPencilPreferredActionSwitchEraser:
pointer_data.preferred_auxiliary_stylus_action =
flutter::PointerData::PreferredStylusAuxiliaryAction::kSwitchEraser;
break;
case UIPencilPreferredActionSwitchPrevious:
pointer_data.preferred_auxiliary_stylus_action =
flutter::PointerData::PreferredStylusAuxiliaryAction::kSwitchPrevious;
break;
default:
pointer_data.preferred_auxiliary_stylus_action =
flutter::PointerData::PreferredStylusAuxiliaryAction::kUnknown;
break;
}

pointer_data.time_stamp = [[NSProcessInfo processInfo] systemUptime] * kMicrosecondsPerSecond;
pointer_data.kind = flutter::PointerData::DeviceKind::kStylus;
pointer_data.signal_kind = flutter::PointerData::SignalKind::kStylusAuxiliaryAction;

return pointer_data;
}

#pragma mark - Handle view resizing

- (void)updateViewportMetrics {
Expand Down
Loading

0 comments on commit ce7be00

Please sign in to comment.