Repository navigation
Commit 3c9f3a4
authored
Apply view metrics overrides below the framework (flutter#194311)
Part of flutter/devtools#9893 (the DevTools accessibility page). Design:
[flutter.dev/go/view-metrics-overrides](https://flutter.dev/go/view-metrics-overrides).
flutter#192764 added the `debugViewMetricsOverrides` registry and the
`ext.flutter.viewMetricsOverride` service extension. This PR makes those
overrides take effect, which the DevTools override controls depend on.
Next up: `flutter_test` support for test views with their own ids, and
moving `ext.flutter.brightnessOverride` onto the registry.
## What this does
In debug mode, `BindingBase.platformDispatcher` wraps
`PlatformDispatcher.instance`. The wrapper and its views report
overridden metrics, so everything that reads them through the binding
(`MediaQuery`, `RenderView`, gestures, semantics, image resolution,
accessibility evaluations) sees the overrides without any
override-specific code. Changing an override fires the same `dart:ui`
callbacks a real platform change would.
`RenderView`, `View`, `RawView` and `MediaQueryData.fromView` map a raw
engine view to the binding's wrapped one, so overrides apply to it too.
Widget tests see overrides through `TestWidgetsFlutterBinding`, and
explicit test values still take precedence. Profile and release builds
are unchanged.
New API: `debugApplyViewMetricsOverrides` wraps a dispatcher, for
bindings that supply their own, and `debugViewWithMetricsOverrides` maps
a raw engine view to its wrapper.
## Behavior changes and caveats
- Debug only: `View.of(context)` and the binding's views are no longer
`identical` to the ones `PlatformDispatcher.instance` reports. A view's
`platformDispatcher` is a wrapper for that view, not
`PlatformDispatcher.instance` or an app binding's dispatcher. Compare
views by `viewId`.
- Debug only: a `FlutterView` test double passed to `View`, `RawView`,
`RenderView` or `MediaQueryData.fromView` must implement
`platformDispatcher` and `viewId`.
- `TestPlatformDispatcher.scaleFontSize` asks the wrapped dispatcher
unless `textScaleFactorTestValue` is set, so non-linear text scaling
applies in tests. A fake dispatcher without `scaleFontSize` still gets
linear scaling.
- An overridden `physicalSize` lays out at that size but still renders
into the real surface, anchored top-left.
- An ancestor `MediaQuery` still wins over platform-wide overrides, as
it does over real platform settings. `debugBrightnessOverride` still
wins over an overridden brightness.
- `ui.window`, direct `PlatformDispatcher.instance` reads and
engine-drawn content (platform views, system UI, keyboard) don't see
overrides.
- Text scalers compare by `textScaleFactor`, so a new `textScaling`
table with the same first-point ratio only reaches already laid-out text
when that text lays out again.
## Tests
- `foundation/debug_view_metrics_override_test.dart`: the wrappers, per
metric and per view, plus view identity, normalization, change
notifications and validation.
- `widgets/debug_view_metrics_override_test.dart`: end to end through
`MediaQuery`, views, layout, pointer events, semantics, images and
accessibility evaluations, and precedence of explicit test values.
- `service_extensions_test.dart` covers an override set through the
extension. `platform_dispatcher_test.dart` covers `scaleFontSize`
delegation and its fallback for fakes.
## 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
`///`).
- [x] 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.
If you need help, consider asking for advice on the #hackers-new channel
on [Discord].
<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[AI contribution guidelines]:
https://github.com/flutter/flutter/blob/main/CONTRIBUTING.ai.md
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[flutter/website]: https://github.com/flutter/website
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md1 parent 2accf87 commit 3c9f3a4
13 files changed
Lines changed: 3717 additions & 96 deletions
File tree
- packages
- flutter_test
- lib/src
- test
- flutter
- lib/src
- foundation
- rendering
- widgets
- test
- foundation
- rendering
- widgets
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
212 | 212 | | |
213 | 213 | | |
214 | 214 | | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
215 | 220 | | |
216 | 221 | | |
217 | 222 | | |
| |||
247 | 252 | | |
248 | 253 | | |
249 | 254 | | |
250 | | - | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
251 | 269 | | |
252 | 270 | | |
253 | 271 | | |
| |||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
108 | 113 | | |
109 | 114 | | |
110 | 115 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
144 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
145 | 151 | | |
146 | 152 | | |
147 | 153 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
295 | 295 | | |
296 | 296 | | |
297 | 297 | | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
298 | 305 | | |
299 | 306 | | |
300 | 307 | | |
301 | 308 | | |
302 | 309 | | |
303 | 310 | | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
304 | 322 | | |
305 | 323 | | |
306 | 324 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
25 | 42 | | |
26 | 43 | | |
27 | 44 | | |
| |||
80 | 97 | | |
81 | 98 | | |
82 | 99 | | |
83 | | - | |
| 100 | + | |
84 | 101 | | |
85 | 102 | | |
86 | 103 | | |
| |||
94 | 111 | | |
95 | 112 | | |
96 | 113 | | |
97 | | - | |
| 114 | + | |
| 115 | + | |
98 | 116 | | |
99 | 117 | | |
100 | 118 | | |
101 | 119 | | |
102 | 120 | | |
103 | 121 | | |
104 | | - | |
105 | | - | |
| 122 | + | |
106 | 123 | | |
107 | 124 | | |
108 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
109 | 130 | | |
110 | 131 | | |
111 | 132 | | |
| |||
129 | 150 | | |
130 | 151 | | |
131 | 152 | | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
132 | 163 | | |
133 | 164 | | |
134 | 165 | | |
| |||
150 | 181 | | |
151 | 182 | | |
152 | 183 | | |
| 184 | + | |
| 185 | + | |
153 | 186 | | |
154 | 187 | | |
155 | 188 | | |
| |||
337 | 370 | | |
338 | 371 | | |
339 | 372 | | |
340 | | - | |
| 373 | + | |
341 | 374 | | |
342 | 375 | | |
343 | 376 | | |
| |||
351 | 384 | | |
352 | 385 | | |
353 | 386 | | |
354 | | - | |
| 387 | + | |
| 388 | + | |
355 | 389 | | |
356 | 390 | | |
357 | 391 | | |
358 | 392 | | |
359 | 393 | | |
360 | 394 | | |
361 | | - | |
362 | | - | |
| 395 | + | |
363 | 396 | | |
364 | 397 | | |
365 | 398 | | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
366 | 403 | | |
367 | 404 | | |
368 | 405 | | |
| |||
0 commit comments