Repository navigation
[web] Anchor platform view slots to top-left to fix RTL document layout - #194601
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request ensures that Flutter's coordinate space and layout remain left-to-right (LTR) and correctly anchored to the top-left, even when embedded in a right-to-left (RTL) host document. It adds direction properties to DomCSSStyleDeclaration, explicitly anchors platform view slots to top: 0 and left: 0, and enforces direction: ltr on the root element and scene host. Feedback suggests using the :host pseudo-class as a fallback selector in style_manager.dart when cssSelectorPrefix is empty to support shadow DOMs, and explicitly setting text-align: left inline on the root element in dom_manager.dart for consistency.
56ec96e to
dd2472f
Compare
flutter-zl
left a comment
There was a problem hiding this comment.
Thanks, the top: 0; left: 0 in _resetAnchor is the right fix and matches what the semantics host and text editing elements already do.
The direction: ltr on flutter-view goes further than the bug though. flt-platform-view is light DOM under flt-glass-pane, so HtmlElementView content inherits from flutter-view, and embedded HTML with no dir of its own flips from the page's RTL to LTR, which is the opposite of what the description says it preserves. Demo under <html dir="rtl">, the green box's last line is the div's computed
direction:
- master: https://flutter-demo-79-before.web.app, computes rtl
- this PR: https://flutter-demo-79-after.web.app, computes ltr
Could you keep the PR to the _resetAnchor change and drop the direction / text-align rules? If you need them for another reason, a test showing an HtmlElementView child still computes rtl would settle it. Also please link an issue for the regression test.
Platform view slots use `position: absolute` with CSS transforms to position elements. When the host document uses `dir="rtl"`, the browser defaults the static position of unconstrained absolute elements to the right edge instead of the left, pushing the slot offscreen when the 2D translation matrix is applied. This explicitly sets `top: 0` and `left: 0` in `_resetAnchor` to ensure the transform origin and base coordinates always start at (0, 0).
bcb173e to
674457d
Compare
|
Hi, I've kept the _resetAnchor change and dropped the other rules |
flutter-zl
left a comment
There was a problem hiding this comment.
LGTM, thanks for the quick turnaround. Verified with the demo: the slot lands in the right place and an HtmlElementView child with no dir of its own still computes rtl under <html dir="rtl">, which the new assertion covers.
Before landing, please trim the description: it still lists the direction: ltr / text-align: left rules under Fix and the style_manager_test / dom_manager_test additions under Tests Added, none of which are in the diff anymore.
|
autosubmit label was removed for flutter/flutter/194601, because This PR has not met approval requirements for merging. The PR author is not a member of flutter-hackers and needs 1 more review(s) in order to merge this PR.
|
|
autosubmit label was removed for flutter/flutter/194601, because - The status or check suite ci.yaml validation has failed. Please fix the issues identified (or deflake) before re-applying this label. |
|
autosubmit label was removed for flutter/flutter/194601, because - The status or check suite Dashboard Checks has failed. Please fix the issues identified (or deflake) before re-applying this label. |
|
autosubmit label was removed for flutter/flutter/194601, because - The status or check suite Dashboard Checks has failed. Please fix the issues identified (or deflake) before re-applying this label. |
|
Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change). If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review. For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
|
autosubmit label was removed for flutter/flutter/194601, because - The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label. |
flutter/flutter@5e805bf...ee8b482 2026-10-31 [email protected] Roll Skia from 9bab765df357 to 607de4b035dc (1 revision) (flutter/flutter#195728) 2026-10-31 [email protected] Roll Skia from 284054bec98a to 9bab765df357 (2 revisions) (flutter/flutter#195726) 2026-10-31 [email protected] Roll Skia from 3a3f56f7ddd4 to 284054bec98a (1 revision) (flutter/flutter#195724) 2026-10-31 [email protected] Roll Skia from 466994d27b1e to 3a3f56f7ddd4 (1 revision) (flutter/flutter#195719) 2026-10-30 [email protected] Fix XcodeProjectInterpreter dependency cycle in flutter_tools (flutter/flutter#195694) 2026-10-30 [email protected] Document that Positioned also works inside an Overlay (flutter/flutter#190607) 2026-10-30 [email protected] Roll Skia from ce0b85b46db6 to 466994d27b1e (3 revisions) (flutter/flutter#195711) 2026-10-30 [email protected] Adds Vulkan sync validation test run (flutter/flutter#195596) 2026-10-30 [email protected] [Android] Let the raster thread use every core of a chip without little cores (flutter/flutter#195071) 2026-10-30 [email protected] Roll Skia from 121d04c01e2d to ce0b85b46db6 (6 revisions) (flutter/flutter#195699) 2026-10-30 [email protected] [web] Anchor platform view slots to top-left to fix RTL document layout (flutter/flutter#194601) 2026-10-30 [email protected] Update golden file testing docs (flutter/flutter#195449) 2026-10-30 [email protected] [tool] Migrate Cache.flutterRoot static state to instance configuration (flutter/flutter#190795) 2026-10-30 [email protected] Apply view metrics overrides below the framework (flutter/flutter#194311) 2026-10-30 [email protected] Roll Skia from c0c46ee9f938 to 121d04c01e2d (9 revisions) (flutter/flutter#195687) 2026-10-30 [email protected] Use uniforms in the Porter Duff blend shader instead of specialization constants (flutter/flutter#195458) 2026-10-30 [email protected] [flutter_tools] Inject dependencies into iOS, macOS, and Windows application packages (flutter/flutter#194047) If this roll has caused a breakage, revert this CL and set the roller to dry run mode using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…ut (flutter#194601) Platform view slots use `position: absolute` with CSS transforms to position elements. When the host document uses `dir="rtl"`, the browser defaults the static position of unconstrained absolute elements to the right edge instead of the left, pushing the slot offscreen when the 2D translation matrix is applied. This explicitly sets `top: 0` and `left: 0` in `_resetAnchor` to ensure the transform origin and base coordinates always start at (0, 0). ## Description When Flutter Web is embedded in a webpage where `<html dir="rtl">` or `<body dir="rtl">` is set, platform views (`HtmlElementView`) render offscreen to the right. Fixes flutter#195150 ### Cause `<flt-platform-view-slot>` uses `position: absolute` without explicit `top`/`left` anchors. Per CSS 2.1 §10.3.7, an unconstrained absolutely positioned element's static horizontal position aligns to the containing block's right edge in an RTL context. When Flutter translates the element with `transform: matrix(1, 0, 0, 1, x, y)`, the `+x` translation offsets from the right edge rather than (0, 0) top-left, throwing the view offscreen. ### Fix Explicitly set `top: 0` and `left: 0` in `_resetAnchor` (`embedder.dart`) for platform view slots so coordinate transforms always calculate from (0, 0). ## Tests Added - `test/ui/platform_view_position_test.dart`: Added `Platform view slot coordinates are anchored to top-left even in RTL document` validating slot position and rect when `domDocument.documentElement.dir == 'rtl'`. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant in-code documentation (doc comments with `///`). - [ ] If this PR introduces a new feature or capability, I created and linked a website documentation issue or PR in [flutter/website] (or verified none is needed). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. --------- Co-authored-by: Mouad Debbar <[email protected]> Co-authored-by: Mouad Debbar <[email protected]> Co-authored-by: zhongliugo <[email protected]>
Platform view slots use
position: absolutewith CSS transforms to position elements. When the host document usesdir="rtl", the browser defaults the static position of unconstrained absolute elements to the right edge instead of the left, pushing the slot offscreen when the 2D translation matrix is applied.This explicitly sets
top: 0andleft: 0in_resetAnchorto ensure the transform origin and base coordinates alwaysstart at (0, 0).
Description
When Flutter Web is embedded in a webpage where
<html dir="rtl">or<body dir="rtl">is set, platform views (HtmlElementView) render offscreen to the right.Fixes #195150
Cause
<flt-platform-view-slot>usesposition: absolutewithout explicittop/leftanchors. Per CSS 2.1 §10.3.7, an unconstrained absolutely positioned element's static horizontal position aligns to the containing block's right edge in an RTL context. When Flutter translates the element withtransform: matrix(1, 0, 0, 1, x, y), the+xtranslation offsets from the right edge rather than (0, 0) top-left, throwing the view offscreen.Fix
Explicitly set
top: 0andleft: 0in_resetAnchor(embedder.dart) for platform view slots so coordinate transforms always calculate from (0, 0).Tests Added
test/ui/platform_view_position_test.dart: AddedPlatform view slot coordinates are anchored to top-left even in RTL documentvalidating slot position and rect whendomDocument.documentElement.dir == 'rtl'.Pre-launch Checklist
///).