Skip to content

Commit 3a30ae3

Browse files
author
nturgut
authored
Fix ios voiceover (for safari >13.4) (flutter#22965)
* fixes voice over for higher ios-safari versions * change enable conditions for webkit * adding click event for removal. adding unit tests * run the mobile semantics enabler test on mobile browsers * remove test method that gave different result on LUCI.(further inv. needed)
1 parent 4797b06 commit 3a30ae3

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

lib/web_ui/lib/src/engine/semantics/semantics_helper.dart

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,11 @@ class MobileSemanticsEnabler extends SemanticsEnabler {
256256
@override
257257
bool tryEnableSemantics(html.Event event) {
258258
if (_schedulePlaceholderRemoval) {
259-
final bool removeNow =
260-
(browserEngine != BrowserEngine.webkit || event.type == 'touchend');
259+
// The event type can also be click for VoiceOver.
260+
final bool removeNow = (browserEngine != BrowserEngine.webkit ||
261+
event.type == 'touchend' ||
262+
event.type == 'pointerup' ||
263+
event.type == 'click');
261264
if (removeNow) {
262265
_semanticsPlaceholder!.remove();
263266
_semanticsPlaceholder = null;
@@ -280,10 +283,16 @@ class MobileSemanticsEnabler extends SemanticsEnabler {
280283
return true;
281284
}
282285

286+
// ios-safari browsers which starts sending `pointer` events instead of
287+
// `touch` events. (Tested with 12.1 which uses touch events vs 13.5
288+
// which uses pointer events.)
283289
const Set<String> kInterestingEventTypes = <String>{
284290
'click',
285291
'touchstart',
286292
'touchend',
293+
'pointerdown',
294+
'pointermove',
295+
'pointerup',
287296
};
288297

289298
if (!kInterestingEventTypes.contains(event.type)) {
@@ -333,6 +342,11 @@ class MobileSemanticsEnabler extends SemanticsEnabler {
333342
final html.TouchEvent touch = event as html.TouchEvent;
334343
activationPoint = touch.changedTouches!.first.client;
335344
break;
345+
case 'pointerdown':
346+
case 'pointerup':
347+
final html.PointerEvent touch = event as html.PointerEvent;
348+
activationPoint = new html.Point(touch.client.x, touch.client.y);
349+
break;
336350
default:
337351
// The event is not relevant, forward to framework as normal.
338352
return true;
@@ -341,9 +355,11 @@ class MobileSemanticsEnabler extends SemanticsEnabler {
341355
final html.Rectangle<num> activatingElementRect =
342356
domRenderer.glassPaneElement!.getBoundingClientRect();
343357
final double midX = (activatingElementRect.left +
344-
(activatingElementRect.right - activatingElementRect.left) / 2).toDouble();
358+
(activatingElementRect.right - activatingElementRect.left) / 2)
359+
.toDouble();
345360
final double midY = (activatingElementRect.top +
346-
(activatingElementRect.bottom - activatingElementRect.top) / 2).toDouble();
361+
(activatingElementRect.bottom - activatingElementRect.top) / 2)
362+
.toDouble();
347363
final double deltaX = activationPoint.x.toDouble() - midX;
348364
final double deltaY = activationPoint.y.toDouble() - midY;
349365
final double deltaSquared = deltaX * deltaX + deltaY * deltaY;

lib/web_ui/test/engine/semantics/semantics_helper_test.dart

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import 'package:test/bootstrap/browser.dart';
99
import 'package:test/test.dart';
1010
import 'package:ui/src/engine.dart';
1111

12+
const PointerSupportDetector _defaultSupportDetector = PointerSupportDetector();
13+
1214
void main() {
1315
internalBootstrapBrowserTest(() => testMain);
1416
}
@@ -151,15 +153,22 @@ void testMain() {
151153
skip: browserEngine == BrowserEngine.webkit);
152154

153155
test('Not relevant events should be forwarded to the framework', () async {
154-
final html.Event event = html.TouchEvent('touchcancel');
156+
html.Event event;
157+
if (_defaultSupportDetector.hasPointerEvents) {
158+
event = html.PointerEvent('pointermove');
159+
} else if (_defaultSupportDetector.hasTouchEvents) {
160+
event = html.TouchEvent('touchcancel');
161+
} else {
162+
event = html.MouseEvent('mousemove');
163+
}
164+
155165
bool shouldForwardToFramework =
156166
mobileSemanticsEnabler.tryEnableSemantics(event);
157167

158168
expect(shouldForwardToFramework, true);
159-
},
160-
// TODO(nurhan): https://github.com/flutter/flutter/issues/50590
161-
// TODO(nurhan): https://github.com/flutter/flutter/issues/46638
162-
// TODO(nurhan): https://github.com/flutter/flutter/issues/50754
163-
skip: browserEngine != BrowserEngine.blink);
164-
});
169+
});
170+
}, // Run the `MobileSemanticsEnabler` only on mobile browsers.
171+
skip: operatingSystem == OperatingSystem.linux ||
172+
operatingSystem == OperatingSystem.macOs ||
173+
operatingSystem == OperatingSystem.windows);
165174
}

0 commit comments

Comments
 (0)