Skip to content

Commit 32e7fff

Browse files
authored
[web] Anchor flt-semantics-host at 0,0 to fix WebKit semantics offset (flutter#190486)
Fixes flutter#190483. This is the part of the fix to flutter#129324. **Problem** On iOS every browser uses WebKit. `<flt-semantics-host>` is `position: absolute` with no `left` or `top`, so it falls back to its CSS static position. WebKit resolves that static position past the in-flow `<flt-glass-pane>`, so the entire semantics layer is shifted roughly one viewport off-screen. VoiceOver focus lands off-screen for every control, text-field taps miss the `<input>`. Blink and Gecko resolve the same static position to 0, so they are unaffected. **Fix** Set `left: 0; top: 0` in `StyleManager.styleSemanticsHost` so the host is anchored at the view origin. **Demo** Measured on an iPhone at 430px width and devicePixelRatio 3, with semantics enabled: - Before, stock engine: https://flutter-demo-57-before.web.app reports 4 of 5 accessibility nodes off-screen, VoiceOver focus lands off-screen, and picking a dropdown item blanks the screen. - After, this fix: https://flutter-demo-57-after.web.app reports 0 of 5, VoiceOver focus lands on each control, and the dropdown works. Please note that there is a known issue that the webkit delays keyboard's pop up when voice over is enabled.
1 parent 6603e14 commit 32e7fff

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

‎engine/src/flutter/lib/web_ui/lib/src/engine/view_embedder/style_manager.dart‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ class StyleManager {
5252
assert(semanticsHost.tagName.toLowerCase() == DomManager.semanticsHostTagName.toLowerCase());
5353
semanticsHost.style
5454
..position = 'absolute'
55+
// Anchor the host at the view origin. Without an explicit left/top, this
56+
// position:absolute element falls back to its static position. On WebKit
57+
// (all iOS browsers) that static position is flowed past the in-flow
58+
// sibling hosts (flt-glass-pane, one viewport wide), offsetting every
59+
// semantic element horizontally so taps on text fields land off the
60+
// <input> and the keyboard never opens. Blink and Gecko resolve the same
61+
// static position to 0, so this is a no-op there.
62+
// See: https://github.com/flutter/flutter/issues/190483
63+
..left = '0'
64+
..top = '0'
5565
..transformOrigin = '0 0 0';
5666
scaleSemanticsHost(semanticsHost, devicePixelRatio);
5767
}

‎engine/src/flutter/lib/web_ui/test/engine/view_embedder/style_manager_test.dart‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ void doTests() {
6161
StyleManager.styleSemanticsHost(semanticsHost, 4.0);
6262
expect(semanticsHost.style.transform, 'scale(0.25)');
6363
expect(semanticsHost.style.position, 'absolute');
64+
// The host must be anchored at the view origin. Without an explicit
65+
// left/top it falls back to a static position flowed after its sibling
66+
// hosts, offsetting the whole semantics tree. See:
67+
// https://github.com/flutter/flutter/issues/190483
68+
expect(semanticsHost.style.left, '0px');
69+
expect(semanticsHost.style.top, '0px');
6470
expect(semanticsHost.style.transformOrigin, anyOf('0px 0px 0px', '0px 0px'));
6571
});
6672

0 commit comments

Comments
 (0)