Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,6 @@ FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterView.mm
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/flutter_touch_mapper.h
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/flutter_touch_mapper.mm
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/platform_message_router.h
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/platform_message_router.mm
FILE: ../../../flutter/shell/platform/darwin/ios/platform_view_ios.h
Expand Down
2 changes: 0 additions & 2 deletions shell/platform/darwin/ios/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ shared_library("create_flutter_framework_dylib") {
"framework/Source/accessibility_bridge.mm",
"framework/Source/accessibility_text_entry.h",
"framework/Source/accessibility_text_entry.mm",
"framework/Source/flutter_touch_mapper.h",
"framework/Source/flutter_touch_mapper.mm",
"framework/Source/platform_message_response_darwin.h",
"framework/Source/platform_message_response_darwin.mm",
"framework/Source/platform_message_router.h",
Expand Down
77 changes: 29 additions & 48 deletions shell/platform/darwin/ios/framework/Source/FlutterViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputDelegate.h"
#include "flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.h"
#include "flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h"
#include "flutter/shell/platform/darwin/ios/framework/Source/flutter_touch_mapper.h"
#include "flutter/shell/platform/darwin/ios/framework/Source/platform_message_response_darwin.h"
#include "flutter/shell/platform/darwin/ios/platform_view_ios.h"

Expand Down Expand Up @@ -55,7 +54,6 @@ @implementation FlutterViewController {
UIInterfaceOrientationMask _orientationPreferences;
UIStatusBarStyle _statusBarStyle;
blink::ViewportMetrics _viewportMetrics;
shell::TouchMapper _touchMapper;
int64_t _nextTextureId;
BOOL _initialized;
}
Expand Down Expand Up @@ -543,32 +541,25 @@ - (void)applicationWillEnterForeground:(NSNotification*)notification {

#pragma mark - Touch event handling

enum MapperPhase {
Accessed,
Added,
Removed,
};

using PointerChangeMapperPhase = std::pair<blink::PointerData::Change, MapperPhase>;
static inline PointerChangeMapperPhase PointerChangePhaseFromUITouchPhase(UITouchPhase phase) {
static blink::PointerData::Change PointerDataChangeFromUITouchPhase(UITouchPhase phase) {
switch (phase) {
case UITouchPhaseBegan:
return PointerChangeMapperPhase(blink::PointerData::Change::kDown, MapperPhase::Added);
return blink::PointerData::Change::kDown;
case UITouchPhaseMoved:
case UITouchPhaseStationary:
// There is no EVENT_TYPE_POINTER_STATIONARY. So we just pass a move type
// with the same coordinates
return PointerChangeMapperPhase(blink::PointerData::Change::kMove, MapperPhase::Accessed);
return blink::PointerData::Change::kMove;
case UITouchPhaseEnded:
return PointerChangeMapperPhase(blink::PointerData::Change::kUp, MapperPhase::Removed);
return blink::PointerData::Change::kUp;
case UITouchPhaseCancelled:
return PointerChangeMapperPhase(blink::PointerData::Change::kCancel, MapperPhase::Removed);
return blink::PointerData::Change::kCancel;
}

return PointerChangeMapperPhase(blink::PointerData::Change::kCancel, MapperPhase::Accessed);
return blink::PointerData::Change::kCancel;
}

static inline blink::PointerData::DeviceKind DeviceKindFromTouchType(UITouch* touch) {
static blink::PointerData::DeviceKind DeviceKindFromTouchType(UITouch* touch) {
if (@available(iOS 9, *)) {
switch (touch.type) {
case UITouchTypeDirect:
Expand All @@ -584,33 +575,18 @@ static inline PointerChangeMapperPhase PointerChangePhaseFromUITouchPhase(UITouc
return blink::PointerData::DeviceKind::kTouch;
}

- (void)dispatchTouches:(NSSet*)touches phase:(UITouchPhase)phase {
// Note: we cannot rely on touch.phase, since in some cases, e.g.,
// handleStatusBarTouches, we synthesize touches from existing events.
//
// TODO(cbracken) consider creating out own class with the touch fields we
// need.
auto eventTypePhase = PointerChangePhaseFromUITouchPhase(phase);
// Dispatches the UITouches to the engine. Usually, the type of change of the touch is determined
// from the UITouch's phase. However, FlutterAppDelegate fakes touches to ensure that touch events
// in the status bar area are available to framework code. The change type (optional) of the faked
// touch is specified in the second argument.
- (void)dispatchTouches:(NSSet*)touches
pointerDataChangeOverride:(blink::PointerData::Change*)overridden_change {
const CGFloat scale = [UIScreen mainScreen].scale;
auto packet = std::make_unique<blink::PointerDataPacket>(touches.count);

int i = 0;
for (UITouch* touch in touches) {
int device_id = 0;

switch (eventTypePhase.second) {
case Accessed:
device_id = _touchMapper.identifierOf(touch);
break;
case Added:
device_id = _touchMapper.registerTouch(touch);
break;
case Removed:
device_id = _touchMapper.unregisterTouch(touch);
break;
}
size_t pointer_index = 0;

FML_DCHECK(device_id != 0);
for (UITouch* touch in touches) {
CGPoint windowCoordinates = [touch locationInView:self.view];

blink::PointerData pointer_data;
Expand All @@ -619,11 +595,13 @@ - (void)dispatchTouches:(NSSet*)touches phase:(UITouchPhase)phase {
constexpr int kMicrosecondsPerSecond = 1000 * 1000;
pointer_data.time_stamp = touch.timestamp * kMicrosecondsPerSecond;

pointer_data.change = eventTypePhase.first;
pointer_data.change = overridden_change != nullptr
? *overridden_change
: PointerDataChangeFromUITouchPhase(touch.phase);

pointer_data.kind = DeviceKindFromTouchType(touch);

pointer_data.device = device_id;
pointer_data.device = reinterpret_cast<int64_t>(touch);

pointer_data.physical_x = windowCoordinates.x * scale;
pointer_data.physical_y = windowCoordinates.y * scale;
Expand Down Expand Up @@ -681,7 +659,7 @@ - (void)dispatchTouches:(NSSet*)touches phase:(UITouchPhase)phase {
pointer_data.orientation = [touch azimuthAngleInView:nil] - M_PI_2;
}

packet->SetPointerData(i++, pointer_data);
packet->SetPointerData(pointer_index++, pointer_data);
}

_shell->GetTaskRunners().GetUITaskRunner()->PostTask(
Expand All @@ -693,19 +671,19 @@ - (void)dispatchTouches:(NSSet*)touches phase:(UITouchPhase)phase {
}

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
[self dispatchTouches:touches phase:UITouchPhaseBegan];
[self dispatchTouches:touches pointerDataChangeOverride:nullptr];
}

- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
[self dispatchTouches:touches phase:UITouchPhaseMoved];
[self dispatchTouches:touches pointerDataChangeOverride:nullptr];
}

- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {
[self dispatchTouches:touches phase:UITouchPhaseEnded];
[self dispatchTouches:touches pointerDataChangeOverride:nullptr];
}

- (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event {
[self dispatchTouches:touches phase:UITouchPhaseCancelled];
[self dispatchTouches:touches pointerDataChangeOverride:nullptr];
}

#pragma mark - Handle view resizing
Expand Down Expand Up @@ -1024,8 +1002,11 @@ - (void)handleStatusBarTouches:(UIEvent*)event {
CGPoint screenLoc = [touch.window convertPoint:windowLoc toWindow:nil];
if (CGRectContainsPoint(statusBarFrame, screenLoc)) {
NSSet* statusbarTouches = [NSSet setWithObject:touch];
[self dispatchTouches:statusbarTouches phase:UITouchPhaseBegan];
[self dispatchTouches:statusbarTouches phase:UITouchPhaseEnded];

blink::PointerData::Change change = blink::PointerData::Change::kDown;
[self dispatchTouches:statusbarTouches pointerDataChangeOverride:&change];
change = blink::PointerData::Change::kUp;
[self dispatchTouches:statusbarTouches pointerDataChangeOverride:&change];
return;
}
}
Expand Down
40 changes: 0 additions & 40 deletions shell/platform/darwin/ios/framework/Source/flutter_touch_mapper.h

This file was deleted.

31 changes: 0 additions & 31 deletions shell/platform/darwin/ios/framework/Source/flutter_touch_mapper.mm

This file was deleted.