Merge commit '148b3e790560f14d97c6ebfee69b0bf578c9d11d' into pipelines/run-20261111-0216-cupertino-out-templates-29f5

This commit is contained in:
2026-11-11 03:06:11 +00:00
22 changed files with 536 additions and 698 deletions
@@ -1,8 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../ui/adaptive/segmented_bar.dart'; import '../../../ui/adaptive/segmented_bar.dart';
import '../../../ui/adaptive/host.dart';
import '../../../ui/adaptive/floating_bar_layout.dart'; import '../../../ui/adaptive/floating_bar_layout.dart';
import 'graph_viewport.dart'; import 'graph_viewport.dart';
import 'graph_viewport_controller.dart'; import 'graph_viewport_controller.dart';
@@ -100,23 +98,6 @@ class _GraphExpandedViewState extends State<GraphExpandedView> {
Expanded(child: viewport), Expanded(child: viewport),
], ],
); );
if (usesCupertinoHost(context)) {
return CupertinoPageScaffold(
navigationBar: SegmentedBar(
cupertino: true,
automaticallyImplyLeading: false,
leading: SegmentedBackButton(cupertino: true, onPressed: _close),
title: widget.title,
actions: [
_GraphFitButton(
cupertino: true,
onPressed: _controller.fitToViewport,
),
],
),
child: BelowTopBar(child: body),
);
}
return Scaffold( return Scaffold(
extendBodyBehindAppBar: true, extendBodyBehindAppBar: true,
appBar: SegmentedBar( appBar: SegmentedBar(
@@ -124,12 +105,7 @@ class _GraphExpandedViewState extends State<GraphExpandedView> {
title: widget.title, title: widget.title,
automaticallyImplyLeading: false, automaticallyImplyLeading: false,
leading: SegmentedBackButton(cupertino: false, onPressed: _close), leading: SegmentedBackButton(cupertino: false, onPressed: _close),
actions: [ actions: [_GraphFitButton(onPressed: _controller.fitToViewport)],
_GraphFitButton(
cupertino: false,
onPressed: _controller.fitToViewport,
),
],
), ),
body: BelowTopBar(child: body), body: BelowTopBar(child: body),
); );
@@ -137,9 +113,8 @@ class _GraphExpandedViewState extends State<GraphExpandedView> {
} }
class _GraphFitButton extends StatelessWidget { class _GraphFitButton extends StatelessWidget {
const _GraphFitButton({required this.cupertino, required this.onPressed}); const _GraphFitButton({required this.onPressed});
final bool cupertino;
final VoidCallback onPressed; final VoidCallback onPressed;
@override @override
@@ -147,22 +122,15 @@ class _GraphFitButton extends StatelessWidget {
child: Semantics( child: Semantics(
button: true, button: true,
label: graphFitLabel, label: graphFitLabel,
child: cupertino child: Tooltip(
? CupertinoButton( message: graphFitLabel,
key: const Key('graph-fit'), excludeFromSemantics: true,
padding: const EdgeInsets.all(8), child: IconButton(
onPressed: onPressed, key: const Key('graph-fit'),
child: const ExcludeSemantics(child: Icon(CupertinoIcons.resize)), onPressed: onPressed,
) icon: const ExcludeSemantics(child: Icon(Icons.fit_screen)),
: Tooltip( ),
message: graphFitLabel, ),
excludeFromSemantics: true,
child: IconButton(
key: const Key('graph-fit'),
onPressed: onPressed,
icon: const ExcludeSemantics(child: Icon(Icons.fit_screen)),
),
),
), ),
); );
} }
@@ -190,8 +158,9 @@ Future<void> openGraphExpanded(
selectedStage: selectedStage, selectedStage: selectedStage,
header: header, header: header,
); );
final route = usesCupertinoHost(context) final route = MaterialPageRoute<void>(
? CupertinoPageRoute<void>(fullscreenDialog: true, builder: (_) => page) fullscreenDialog: true,
: MaterialPageRoute<void>(fullscreenDialog: true, builder: (_) => page); builder: (_) => page,
);
return Navigator.of(context).push(route); return Navigator.of(context).push(route);
} }
@@ -1,7 +1,5 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../ui/adaptive/host.dart';
import '../../../ui/adaptive/glass_pill.dart'; import '../../../ui/adaptive/glass_pill.dart';
import 'graph_viewport_controller.dart'; import 'graph_viewport_controller.dart';
@@ -121,20 +119,20 @@ class _GraphViewportState extends State<GraphViewport> {
top: 8, top: 8,
end: 8, end: 8,
child: GlassPill( child: GlassPill(
cupertino: usesCupertinoHost(context), cupertino: false,
child: Wrap( child: Wrap(
spacing: 2, spacing: 2,
children: [ children: [
_ViewportButton( _ViewportButton(
buttonKey: const Key('graph-fit'), buttonKey: const Key('graph-fit'),
icon: _fitIcon(context), icon: Icons.fit_screen,
label: graphFitLabel, label: graphFitLabel,
onPressed: widget.controller.fitToViewport, onPressed: widget.controller.fitToViewport,
), ),
if (widget.onExpand != null) if (widget.onExpand != null)
_ViewportButton( _ViewportButton(
buttonKey: const Key('graph-expand'), buttonKey: const Key('graph-expand'),
icon: _expandIcon(context), icon: Icons.fullscreen,
label: graphExpandLabel, label: graphExpandLabel,
onPressed: widget.onExpand, onPressed: widget.onExpand,
), ),
@@ -147,12 +145,6 @@ class _GraphViewportState extends State<GraphViewport> {
}, },
); );
} }
IconData _fitIcon(BuildContext context) =>
usesCupertinoHost(context) ? CupertinoIcons.resize : Icons.fit_screen;
IconData _expandIcon(BuildContext context) =>
usesCupertinoHost(context) ? CupertinoIcons.fullscreen : Icons.fullscreen;
} }
/// One native graph control inside the shared floating glass pill. /// One native graph control inside the shared floating glass pill.
@@ -160,7 +152,7 @@ class _GraphViewportState extends State<GraphViewport> {
/// The label and the button's own tap action must reach the same semantics /// The label and the button's own tap action must reach the same semantics
/// node: the icon is the only excluded child, and [MergeSemantics] folds the /// node: the icon is the only excluded child, and [MergeSemantics] folds the
/// host button's action into the labelled node, so a screen reader can activate /// host button's action into the labelled node, so a screen reader can activate
/// Fit and Expand on either host. A hand-written `Semantics` sibling around an /// Fit and Expand. A hand-written `Semantics` sibling around an
/// excluded button would announce the control with no action at all. /// excluded button would announce the control with no action at all.
class _ViewportButton extends StatelessWidget { class _ViewportButton extends StatelessWidget {
const _ViewportButton({ const _ViewportButton({
@@ -181,24 +173,17 @@ class _ViewportButton extends StatelessWidget {
child: Semantics( child: Semantics(
button: true, button: true,
label: label, label: label,
child: usesCupertinoHost(context) child: Tooltip(
? CupertinoButton( message: label,
key: buttonKey, // The merged node already carries the label; the tooltip is
padding: const EdgeInsets.all(8), // only the pointer affordance.
onPressed: onPressed, excludeFromSemantics: true,
child: ExcludeSemantics(child: Icon(icon)), child: IconButton(
) key: buttonKey,
: Tooltip( onPressed: onPressed,
message: label, icon: ExcludeSemantics(child: Icon(icon)),
// The merged node already carries the label; the tooltip is ),
// only the pointer affordance. ),
excludeFromSemantics: true,
child: IconButton(
key: buttonKey,
onPressed: onPressed,
icon: ExcludeSemantics(child: Icon(icon)),
),
),
), ),
); );
} }
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart'; import '../../../core/api_gateway.dart';
@@ -1,7 +1,5 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../ui/adaptive/host.dart';
import '../layout/layout_models.dart'; import '../layout/layout_models.dart';
import '../routing/route_models.dart'; import '../routing/route_models.dart';
@@ -32,9 +30,9 @@ RoutingConfig graphCanvasRoutingConfig() => RoutingConfig(
/// The native theme roles one definition graph canvas needs. /// The native theme roles one definition graph canvas needs.
/// ///
/// No palette, font family or size is defined here: every value comes from the /// No palette, font family or size is defined here: every value comes from the
/// ambient Material or Cupertino theme, so light/dark and text scaling follow /// ambient Material theme, so light/dark and text scaling follow the host
/// the host exactly. Edge labels and diagnostics are metadata, so they use the /// exactly. Edge labels and diagnostics are metadata, so they use the host's
/// host's secondary-label role rather than the node's own label style. /// secondary-label role rather than the node's own label style.
class GraphCanvasStyle { class GraphCanvasStyle {
const GraphCanvasStyle({ const GraphCanvasStyle({
required this.labelStyle, required this.labelStyle,
@@ -44,20 +42,6 @@ class GraphCanvasStyle {
}); });
factory GraphCanvasStyle.of(BuildContext context) { factory GraphCanvasStyle.of(BuildContext context) {
if (usesCupertinoHost(context)) {
final theme = CupertinoTheme.of(context);
final secondary = CupertinoColors.secondaryLabel.resolveFrom(context);
return GraphCanvasStyle(
labelStyle: theme.textTheme.tabLabelTextStyle.copyWith(
color: secondary,
),
messageStyle: theme.textTheme.textStyle.copyWith(color: secondary),
edgeColor: CupertinoColors.separator.resolveFrom(context),
// Cupertino has no divider-thickness token; its separators are one
// logical pixel hairlines, so the stroke keeps that native default.
edgeWidth: 1,
);
}
final theme = Theme.of(context); final theme = Theme.of(context);
final secondary = theme.colorScheme.onSurfaceVariant; final secondary = theme.colorScheme.onSurfaceVariant;
return GraphCanvasStyle( return GraphCanvasStyle(
@@ -1,7 +1,5 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../ui/adaptive/host.dart';
import '../../../ui/status/run_status_icon.dart'; import '../../../ui/status/run_status_icon.dart';
import '../domain/graph_definition.dart'; import '../domain/graph_definition.dart';
@@ -37,7 +35,7 @@ class GraphStageNode extends StatelessWidget {
/// Reports [node.key] exactly as the definition recorded it. /// Reports [node.key] exactly as the definition recorded it.
final ValueChanged<String> onSelected; final ValueChanged<String> onSelected;
/// Content inset shared by both hosts. It is spacing, not a size: the control /// Content inset for a graph node. It is spacing, not a size: the control
/// still takes its size from its label, and the inset keeps wrapped glyphs /// still takes its size from its label, and the inset keeps wrapped glyphs
/// clear of a rounded surface's corners. /// clear of a rounded surface's corners.
static const EdgeInsets _contentPadding = EdgeInsets.all(16); static const EdgeInsets _contentPadding = EdgeInsets.all(16);
@@ -61,9 +59,7 @@ class GraphStageNode extends StatelessWidget {
button: true, button: true,
selected: selected, selected: selected,
label: _label, label: _label,
child: usesCupertinoHost(context) child: _materialCard(onPressed, content),
? _cupertinoButton(onPressed, content)
: _materialCard(onPressed, content),
), ),
); );
return active ? StageActivityHalo(child: control) : control; return active ? StageActivityHalo(child: control) : control;
@@ -106,12 +102,6 @@ class GraphStageNode extends StatelessWidget {
); );
} }
/// Tinted is Cupertino's stock low-emphasis surface, so an unselected node is
/// still a visible node body; filled raises the selected one.
Widget _cupertinoButton(VoidCallback onPressed, Widget content) => selected
? CupertinoButton.filled(onPressed: onPressed, child: content)
: CupertinoButton.tinted(onPressed: onPressed, child: content);
Widget _content(BuildContext context) { Widget _content(BuildContext context) {
final status = _status; final status = _status;
// The recorded status reads apart from the name: a coloured dot and // The recorded status reads apart from the name: a coloured dot and
@@ -215,10 +205,7 @@ class _StageActivityHaloState extends State<StageActivityHalo>
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context); final color = Theme.of(context).colorScheme.primary;
final color = cupertino
? CupertinoTheme.of(context).primaryColor
: Theme.of(context).colorScheme.primary;
return AnimatedBuilder( return AnimatedBuilder(
animation: _controller, animation: _controller,
builder: (context, child) => CustomPaint( builder: (context, child) => CustomPaint(
@@ -1,8 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart' show listEquals; import 'package:flutter/foundation.dart' show listEquals;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../ui/adaptive/host.dart';
import '../domain/graph_definition.dart'; import '../domain/graph_definition.dart';
import '../domain/run_graph_state.dart'; import '../domain/run_graph_state.dart';
import '../layout/layout_models.dart'; import '../layout/layout_models.dart';
@@ -200,10 +198,7 @@ class RunGraphCanvas extends StatelessWidget {
final executedIds = {for (final route in executed) route.id}; final executedIds = {for (final route in executed) route.id};
final size = Size(routing.width, routing.height); final size = Size(routing.width, routing.height);
final activeStage = state.activeStage; final activeStage = state.activeStage;
final cupertino = usesCupertinoHost(context); final executedColor = Theme.of(context).colorScheme.primary;
final executedColor = cupertino
? CupertinoTheme.of(context).primaryColor
: Theme.of(context).colorScheme.primary;
return Stack( return Stack(
clipBehavior: Clip.none, clipBehavior: Clip.none,
children: [ children: [
@@ -1,7 +1,5 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../ui/adaptive/host.dart';
import '../domain/run_graph_state.dart'; import '../domain/run_graph_state.dart';
import 'graph_canvas_style.dart'; import 'graph_canvas_style.dart';
@@ -31,10 +29,7 @@ class RunGraphHeader extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context); final executedColor = Theme.of(context).colorScheme.primary;
final executedColor = cupertino
? CupertinoTheme.of(context).primaryColor
: Theme.of(context).colorScheme.primary;
final mutedColor = style.edgeColor; final mutedColor = style.edgeColor;
final active = state.activeStage; final active = state.activeStage;
return Padding( return Padding(
@@ -53,14 +48,12 @@ class RunGraphHeader extends StatelessWidget {
crossAxisAlignment: WrapCrossAlignment.center, crossAxisAlignment: WrapCrossAlignment.center,
children: [ children: [
_LegendEntry( _LegendEntry(
icon: cupertino icon: Icons.arrow_forward,
? CupertinoIcons.arrow_right
: Icons.arrow_forward,
label: runGraphExecuted, label: runGraphExecuted,
color: executedColor, color: executedColor,
), ),
_LegendEntry( _LegendEntry(
icon: cupertino ? CupertinoIcons.minus : Icons.remove, icon: Icons.remove,
label: runGraphNotExecuted, label: runGraphNotExecuted,
color: mutedColor, color: mutedColor,
), ),
@@ -1,14 +1,12 @@
import '../../../ui/adaptive/segmented_bar.dart';
import 'dart:convert'; import 'dart:convert';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../ui/adaptive/segmented_bar.dart';
import '../../../ui/text/markdown_source_view.dart'; import '../../../ui/text/markdown_source_view.dart';
import '../../chat/ui/transcript/chat_markdown_view.dart'; import '../../chat/ui/transcript/chat_markdown_view.dart';
import '../../../core/api_gateway.dart'; import '../../../core/api_gateway.dart';
import '../../../ui/adaptive/floating_bar_layout.dart'; import '../../../ui/adaptive/floating_bar_layout.dart';
import '../../../ui/adaptive/host.dart';
import '../domain/graph_protocol.dart'; import '../domain/graph_protocol.dart';
import '../domain/stage_definition.dart'; import '../domain/stage_definition.dart';
@@ -159,30 +157,14 @@ Future<void> openStageDefinition(
// A terminal is a definition target, not its protocol key: the web pane // A terminal is a definition target, not its protocol key: the web pane
// titles it with `nodeDisplayLabel` (`Failure`/`Success`). // titles it with `nodeDisplayLabel` (`Failure`/`Success`).
final title = '${nodeDisplayLabel(stageKey)} definition'; final title = '${nodeDisplayLabel(stageKey)} definition';
final route = usesCupertinoHost(context) final route = MaterialPageRoute<void>(
? CupertinoPageRoute<void>( settings: settings,
settings: settings, builder: (_) => Scaffold(
builder: (_) => CupertinoPageScaffold( extendBodyBehindAppBar: true,
navigationBar: SegmentedBar( appBar: SegmentedBar(cupertino: false, title: title, subtitle: identity),
cupertino: true, body: SafeArea(top: false, bottom: false, child: view),
title: title, ),
subtitle: identity, );
),
child: SafeArea(top: false, bottom: false, child: view),
),
)
: MaterialPageRoute<void>(
settings: settings,
builder: (_) => Scaffold(
extendBodyBehindAppBar: true,
appBar: SegmentedBar(
cupertino: false,
title: title,
subtitle: identity,
),
body: SafeArea(top: false, bottom: false, child: view),
),
);
return Navigator.of(context).push(route); return Navigator.of(context).push(route);
} }
@@ -263,22 +245,6 @@ class _StageDefinitionStyle {
}); });
factory _StageDefinitionStyle.of(BuildContext context) { factory _StageDefinitionStyle.of(BuildContext context) {
if (usesCupertinoHost(context)) {
final theme = CupertinoTheme.of(context);
final secondary = CupertinoColors.secondaryLabel.resolveFrom(context);
return _StageDefinitionStyle(
label: theme.textTheme.tabLabelTextStyle.copyWith(color: secondary),
// SelectableText needs a style it can merge into the default text
// style; Cupertino's textStyle is a complete style with `inherit: false`
// and no baseline.
value: theme.textTheme.textStyle.copyWith(inherit: true),
muted: theme.textTheme.textStyle.copyWith(
inherit: true,
color: secondary,
),
heading: theme.textTheme.navTitleTextStyle,
);
}
final theme = Theme.of(context); final theme = Theme.of(context);
return _StageDefinitionStyle( return _StageDefinitionStyle(
label: (theme.textTheme.labelMedium ?? const TextStyle()).copyWith( label: (theme.textTheme.labelMedium ?? const TextStyle()).copyWith(
+52 -24
View File
@@ -55,6 +55,16 @@ class _WindowLayerState extends State<WindowLayer>
final GlobalKey _navigator = GlobalKey(); final GlobalKey _navigator = GlobalKey();
late final LocalKey _rootPage = ValueKey('window-root-${widget.entry.id}'); late final LocalKey _rootPage = ValueKey('window-root-${widget.entry.id}');
/// The page-transition theme handed to the window's navigator, rebuilt only
/// when the app's theme itself changes.
ThemeData? _themeSource;
ThemeData? _pageTheme;
/// The root page kept across builds: a new page object would rebuild the
/// window's content on every move and resize.
WindowKind? _pageKind;
Page<void>? _page;
String get _id => widget.entry.id; String get _id => widget.entry.id;
@override @override
@@ -160,6 +170,22 @@ class _WindowLayerState extends State<WindowLayer>
widget.manager.raise(_id); widget.manager.raise(_id);
} }
ThemeData _pageThemeFor(ThemeData theme) {
if (identical(theme, _themeSource)) return _pageTheme!;
_themeSource = theme;
return _pageTheme = WindowNavigator.themeData(theme);
}
Page<void> _rootPageFor(WindowKind kind) {
final page = _page;
if (page != null && identical(kind, _pageKind)) return page;
_pageKind = kind;
return _page = MaterialPage<void>(
key: _rootPage,
child: _WindowContent(kind: kind),
);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final manager = widget.manager; final manager = widget.manager;
@@ -174,6 +200,7 @@ class _WindowLayerState extends State<WindowLayer>
frame.bottom, frame.bottom,
); );
final title = kind.title(context, entry); final title = kind.title(context, entry);
final pageTheme = _pageThemeFor(Theme.of(context));
final hiding = !widget.visible; final hiding = !widget.visible;
final content = Stack( final content = Stack(
fit: StackFit.expand, fit: StackFit.expand,
@@ -185,17 +212,21 @@ class _WindowLayerState extends State<WindowLayer>
explicitChildNodes: true, explicitChildNodes: true,
label: 'Window: $title', label: 'Window: $title',
identifier: 'window-${entry.kind}', identifier: 'window-${entry.kind}',
child: WindowFrame( // Its own layer: moving the window moves the title bar without
title: title, // repainting it.
icon: kind.icon, child: RepaintBoundary(
actions: kind.actions(context, entry), child: WindowFrame(
maximized: entry.maximized, title: title,
onMove: _move, icon: kind.icon,
onMoveEnd: _moveEnded, actions: kind.actions(context, entry),
onMinimize: () => manager.setMinimized(_id, true), maximized: entry.maximized,
onToggleMaximized: () => onMove: _move,
manager.setMaximized(_id, !entry.maximized), onMoveEnd: _moveEnded,
onClose: () => manager.close(_id), onMinimize: () => manager.setMinimized(_id, true),
onToggleMaximized: () =>
manager.setMaximized(_id, !entry.maximized),
onClose: () => manager.close(_id),
),
), ),
), ),
), ),
@@ -210,19 +241,16 @@ class _WindowLayerState extends State<WindowLayer>
child: WindowScope( child: WindowScope(
manager: manager, manager: manager,
entry: entry, entry: entry,
body: body, child: WindowBodyScope(
child: ScaffoldMessenger( body: body,
child: WindowNavigator.theme( child: ScaffoldMessenger(
context, child: Theme(
child: WindowNavigator( data: pageTheme,
key: _navigator, child: WindowNavigator(
pages: [ key: _navigator,
MaterialPage<void>( pages: [_rootPageFor(kind)],
key: _rootPage, onDidRemovePage: (_) {},
child: _WindowContent(kind: kind), ),
),
],
onDidRemovePage: (_) {},
), ),
), ),
), ),
+18 -19
View File
@@ -18,23 +18,21 @@ import 'window_scope.dart';
class WindowNavigator extends Navigator { class WindowNavigator extends Navigator {
const WindowNavigator({super.key, super.pages, super.onDidRemovePage}); const WindowNavigator({super.key, super.pages, super.onDidRemovePage});
/// [child] with page transitions that keep every `MaterialPageRoute` of a /// [theme] with page transitions that keep every `MaterialPageRoute` of a
/// window navigator below it inside the window's content area. /// window navigator inside the window's content area. The caller keeps the
static Widget theme(BuildContext context, {required Widget child}) { /// result, so rebuilding a window layer does not hand its contents a new
final theme = Theme.of(context); /// theme.
static ThemeData themeData(ThemeData theme) {
final builders = theme.pageTransitionsTheme.builders; final builders = theme.pageTransitionsTheme.builders;
return Theme( return theme.copyWith(
data: theme.copyWith( pageTransitionsTheme: PageTransitionsTheme(
pageTransitionsTheme: PageTransitionsTheme( builders: {
builders: { for (final platform in TargetPlatform.values)
for (final platform in TargetPlatform.values) platform: _WindowPageTransitions(
platform: _WindowPageTransitions( builders[platform] ?? const ZoomPageTransitionsBuilder(),
builders[platform] ?? const ZoomPageTransitionsBuilder(), ),
), },
},
),
), ),
child: child,
); );
} }
@@ -117,9 +115,8 @@ class WindowPageBox extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final scope = WindowScope.maybeOf(context); final body = WindowBodyScope.maybeOf(context);
if (scope == null) return child; if (body == null) return child;
final body = scope.body;
const radius = Radius.circular(windowCornerRadius); const radius = Radius.circular(windowCornerRadius);
return Stack( return Stack(
children: [ children: [
@@ -140,7 +137,9 @@ class WindowPageBox extends StatelessWidget {
child: Scaffold( child: Scaffold(
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
primary: false, primary: false,
body: child, // Its own layer: moving or resizing the window repositions the
// page without repainting it.
body: RepaintBoundary(child: child),
), ),
), ),
), ),
+29 -10
View File
@@ -1,27 +1,26 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'window_entry.dart'; import 'window_entry.dart';
import 'window_manager.dart'; import 'window_manager.dart';
/// The floating window some content is in: its entry, the manager, and where /// The floating window some content is in: its entry and the manager. Absent
/// the content area is drawn in the window host. Absent outside a window, so /// outside a window, so shared content can tell the tiled app from a window.
/// shared content can tell the tiled app from a window. ///
/// Content depends on what it can read of the entry, not on where the window
/// is drawn: moving, resizing, minimising or maximising a window keeps its
/// content as it is.
class WindowScope extends InheritedWidget { class WindowScope extends InheritedWidget {
const WindowScope({ const WindowScope({
super.key, super.key,
required this.manager, required this.manager,
required this.entry, required this.entry,
required this.body,
required super.child, required super.child,
}); });
final WindowManager manager; final WindowManager manager;
final WindowEntry entry; final WindowEntry entry;
/// The content area (the window less its title bar), in the host's
/// coordinates.
final Rect body;
static WindowScope? maybeOf(BuildContext context) => static WindowScope? maybeOf(BuildContext context) =>
context.dependOnInheritedWidgetOfExactType<WindowScope>(); context.dependOnInheritedWidgetOfExactType<WindowScope>();
@@ -30,6 +29,26 @@ class WindowScope extends InheritedWidget {
@override @override
bool updateShouldNotify(WindowScope oldWidget) => bool updateShouldNotify(WindowScope oldWidget) =>
oldWidget.manager != manager || oldWidget.manager != manager ||
oldWidget.entry != entry || oldWidget.entry.id != entry.id ||
oldWidget.body != body; oldWidget.entry.kind != entry.kind ||
oldWidget.entry.contentId != entry.contentId ||
oldWidget.entry.serverKey != entry.serverKey ||
!mapEquals(oldWidget.entry.data, entry.data);
}
/// Where a window's content area is drawn in the window host. Kept apart from
/// [WindowScope] so a move or a resize repositions the page without rebuilding
/// what the page shows.
class WindowBodyScope extends InheritedWidget {
const WindowBodyScope({super.key, required this.body, required super.child});
/// The content area (the window less its title bar), in the host's
/// coordinates.
final Rect body;
static Rect? maybeOf(BuildContext context) =>
context.dependOnInheritedWidgetOfExactType<WindowBodyScope>()?.body;
@override
bool updateShouldNotify(WindowBodyScope oldWidget) => oldWidget.body != body;
} }
+102
View File
@@ -0,0 +1,102 @@
# Performance round 5: moving a window does not rebuild its content
Round 5's candidate: every pointer event of a window drag rebuilt every
window's whole content. `WindowScope` carried the body `Rect` and compared the
whole `WindowEntry`, the navigator's `ThemeData` was rebuilt with `copyWith` on
every build, and the root `MaterialPage` was a new object on every build.
## Change
`lib/shell/windows/`:
- `window_scope.dart`: `WindowScope` keeps only `manager` and `entry`, and
notifies only when what content can read changes (id, kind, contentId,
serverKey, `data`). A new `WindowBodyScope` (an `InheritedWidget` with the
body `Rect`) carries the position and size that used to be in `WindowScope`.
- `window_navigator.dart`: `WindowNavigator.theme(context, child:)` became
`WindowNavigator.themeData(theme)`, so the layer can keep the
page-transition `ThemeData`. `WindowPageBox` reads the body from
`WindowBodyScope`, and its page child is a `RepaintBoundary`.
- `window_layer.dart`: `_WindowLayerState` keeps the page-transition theme in a
field and rebuilds it only when `Theme.of(context)` is a different object; it
keeps the root `MaterialPage` in a field (same key) and rebuilds it only when
the kind changes. `WindowFrame` is wrapped in a `RepaintBoundary`.
No behaviour change: frames, snapping, resize limits, popups, pushed pages,
minimise/maximise, focus and the shell's APIs are as before.
`tool/capture/window_probe.dart`: `ProbeContentState.lastSize` records the
`MediaQuery` size the content built at, so tests can see a resize reach it
(no visual change).
## Deterministic build counts
`test/shell/windows/window_rebuild_test.dart`:
- dragging a window's title over 8 pointer moves: the dragged window's content
and the other window's content keep their `builds` count (0 rebuilds);
- resizing a window over 5 pointer moves: the other window keeps its count,
the resized window's content rebuilds and sees the new `MediaQuery` size
(360x380 -> 280x330 body);
- `manager.setContent` retargets a content whose element is keyed stably: the
same state rebuilds with the new contentId.
Against the old implementation (lib changes stashed, test run unchanged): 2
failed — `dragged window rebuilt at move 0` (builds 2 -> 3) and `other window
rebuilt at move 0` (2 -> 3). The new code passes all 3.
## Browser bench
Built twice: the old code (lib/shell/windows changes stashed) into
`build/probe-before`, and this branch into `build/probe-app`:
```
/Users/alan/development/flutter/bin/flutter build web \
--target tool/search_selection_probe_entry.dart --output build/probe-before
/Users/alan/development/flutter/bin/flutter build web \
--target tool/search_selection_probe_entry.dart --output build/probe-app
```
Run, from `app/`, against each build in turn:
```
node tool/perf/interaction_bench.mjs --build build/probe-before --out /tmp/bench \
--gpu --only 'desktop: drag a probe window' --repeat 3
node tool/perf/interaction_bench.mjs --build build/probe-app --out /tmp/bench \
--gpu --only 'desktop: drag a probe window' --repeat 3
```
Three before/after rounds (the machine was shared with other pipeline test
runs; load average 9-14 during these, so frame counts vary. `buildMs/frame =
buildSum / frames`):
| round | code | frames | buildSum | ms/frame | buildMax | longest | over16 | rasterSum |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| 1 | before | 50 | 952.2 | 19.0 | 63.5 | 73.9 | 31 | 107.4 |
| 1 | after | 49 | 824.8 | 16.8 | 59.1 | 74.0 | 27 | 107.9 |
| 2 | before | 49 | 615.6 | 12.6 | 25.5 | 28.4 | 15 | 62.1 |
| 2 | after | 51 | 583.0 | 11.4 | 37.4 | 39.9 | 13 | 87.2 |
| 3 | before | 51 | 527.9 | 10.4 | 16.2 | 20.3 | 9 | 68.3 |
| 3 | after | 47 | 606.8 | 12.9 | 24.1 | 26.9 | 18 | 83.5 |
The browser numbers are inconclusive on this loaded machine: only round 1
shows less build work, and the spread between rounds (10.4-19.0 ms/frame on the
same code) is larger than the change. The reliable result is the build count:
the drag went from one content build per pointer event per window (120 builds
over a 40-move drag with three windows) to none. Window chrome and framework
layout still run on every pointer event; that is the remaining build cost in
this scenario, not content.
## Checks
- `tool/memwatch/full.sh 'test/shell/windows test/features/chat/chat_floating_pane_test.dart test/features/terminal'`:
119 passed, 0 failed.
- `tool/analyze.sh`: clean.
## Affected UI states (for ui-review)
`/runs?windows=2` at 1280x800 light: the windows after a title drag
(`drag=250,132>300,150`), after a corner resize
(`drag=483,523>120,80`), and a page pushed inside a window (click `page`) then
dragged: the content must follow the window, stay inside it, and show no stale
or clipped frame.
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/semantics.dart'; import 'package:flutter/semantics.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
@@ -164,95 +163,27 @@ void main() {
expect(clamped, lessThan(panned)); expect(clamped, lessThan(panned));
}); });
testWidgets('320px at 2x opens and closes on the dark Cupertino host', ( testWidgets('expanded Fit is an activatable labelled button', (tester) async {
tester,
) async {
tester.view.physicalSize = const Size(320, 700);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final picked = <String>[];
await tester.pumpWidget( await tester.pumpWidget(
CupertinoApp( _materialHost(
theme: const CupertinoThemeData(brightness: Brightness.dark), graph: linearGraph(),
home: CupertinoPageScaffold( selected: 'build',
child: Builder( onSelected: (_) {},
builder: (context) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: const TextScaler.linear(2)),
child: DefinitionGraphView(
graph: linearGraph(),
selectedStage: 'build',
onSelected: picked.add,
),
),
),
),
), ),
); );
await _settle(tester); await _settle(tester);
final inline = _inlineTransform(tester);
final inlineMatrix = Matrix4.copy(inline.value);
await tester.tap(find.byKey(const Key('graph-expand'))); await tester.tap(find.byKey(const Key('graph-expand')));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.byType(GraphExpandedView), findsOneWidget);
final fit = tester
.getSemantics(_inExpanded(find.byKey(const Key('graph-fit'))))
.getSemanticsData();
expect(fit.label, graphFitLabel);
expect(fit.flagsCollection.isButton, isTrue);
expect( expect(
_inExpanded(find.byType(CupertinoNavigationBarBackButton)), fit.hasAction(SemanticsAction.tap),
findsOneWidget,
);
expect(_inExpanded(find.byKey(const Key('graph-fit'))), findsOneWidget);
expect(
tester.widget<GraphStageNode>(_inExpanded(_node('build'))).selected,
isTrue, isTrue,
reason: 'Fit must expose its tap action on the labelled node',
); );
expect(tester.takeException(), isNull);
await tester.tap(find.byType(CupertinoNavigationBarBackButton));
await tester.pumpAndSettle();
expect(find.byType(GraphExpandedView), findsNothing);
expect(tester.widget<GraphStageNode>(_node('build')).selected, isTrue);
expect(inline.value.storage, orderedEquals(inlineMatrix.storage));
expect(picked, isEmpty);
expect(tester.takeException(), isNull);
});
testWidgets('expanded Fit is an activatable labelled button on both hosts', (
tester,
) async {
for (final cupertino in [false, true]) {
final host = cupertino ? 'Cupertino' : 'Material';
await tester.pumpWidget(
cupertino
? CupertinoApp(
home: CupertinoPageScaffold(
child: DefinitionGraphView(
graph: linearGraph(),
selectedStage: 'build',
onSelected: (_) {},
),
),
)
: _materialHost(
graph: linearGraph(),
selected: 'build',
onSelected: (_) {},
),
);
await _settle(tester);
await tester.tap(find.byKey(const Key('graph-expand')));
await tester.pumpAndSettle();
final fit = tester
.getSemantics(_inExpanded(find.byKey(const Key('graph-fit'))))
.getSemanticsData();
expect(fit.label, graphFitLabel, reason: '$host Fit must be labelled');
expect(fit.flagsCollection.isButton, isTrue);
expect(
fit.hasAction(SemanticsAction.tap),
isTrue,
reason: '$host Fit must expose its tap action on the labelled node',
);
}
}); });
} }
@@ -7,101 +7,79 @@ import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
import 'graph_viewport_fixtures.dart'; import 'graph_viewport_fixtures.dart';
void main() { void main() {
testWidgets('Fit and Expand stay labelled, activatable buttons on both hosts', ( testWidgets('Fit and Expand stay labelled, activatable buttons', (
tester, tester,
) async { ) async {
for (final cupertino in [false, true]) { final controller = GraphViewportController();
final host = cupertino ? 'cupertino' : 'material'; addTearDown(controller.dispose);
final controller = GraphViewportController(); var expands = 0;
addTearDown(controller.dispose); await tester.pumpWidget(
var expands = 0; viewportHost(
await tester.pumpWidget( controller: controller,
viewportHost( child: viewportTargets([]),
controller: controller, onExpand: () => expands += 1,
child: viewportTargets([]), ),
cupertino: cupertino, );
onExpand: () => expands += 1, await settleViewport(tester);
), final fitted = controller.snapshot;
); expect(
await settleViewport(tester); find.ancestor(
final fitted = controller.snapshot; of: find.byKey(const Key('graph-fit')),
expect( matching: find.byType(GlassPill),
find.ancestor( ),
of: find.byKey(const Key('graph-fit')), findsOneWidget,
matching: find.byType(GlassPill), );
),
findsOneWidget,
);
for (final control in viewportControls().entries) { for (final control in viewportControls().entries) {
final node = tester.getSemantics(find.byKey(control.key)); final node = tester.getSemantics(find.byKey(control.key));
final data = node.getSemanticsData(); final data = node.getSemanticsData();
expect( expect(data.label, control.value);
data.label, expect(data.flagsCollection.isButton, isTrue);
control.value, // A labelled button with no action is unusable with a screen reader;
reason: '$host ${control.key} must have the web name', // this is the regression the excluded-button wrapper introduced.
); expect(data.hasAction(SemanticsAction.tap), isTrue);
expect(
data.flagsCollection.isButton,
isTrue,
reason: '$host ${control.key} must be announced as a button',
);
// A labelled button with no action is unusable with VoiceOver/TalkBack;
// this is the regression the excluded-button wrapper introduced.
expect(
data.hasAction(SemanticsAction.tap),
isTrue,
reason: '$host ${control.key} must expose a tap action',
);
}
// The exposed action must run the real callback, not just be announced.
await pinchViewport(tester, const Offset(200, 150), 2);
await tester.pumpAndSettle();
expect(controller.snapshot, isNot(fitted));
performViewportTap(tester, find.byKey(const Key('graph-fit')));
await tester.pump();
expect(controller.scale, closeTo(fitted.scale, 1e-9));
performViewportTap(tester, find.byKey(const Key('graph-expand')));
await tester.pump();
expect(expands, 1, reason: '$host Expand must activate');
} }
// The exposed action must run the real callback, not just be announced.
await pinchViewport(tester, const Offset(200, 150), 2);
await tester.pumpAndSettle();
expect(controller.snapshot, isNot(fitted));
performViewportTap(tester, find.byKey(const Key('graph-fit')));
await tester.pump();
expect(controller.scale, closeTo(fitted.scale, 1e-9));
performViewportTap(tester, find.byKey(const Key('graph-expand')));
await tester.pump();
expect(expands, 1);
}); });
testWidgets('320px at 2x keeps native controls and gestures on both hosts', ( testWidgets('320px at 2x keeps native controls and gestures', (tester) async {
tester, final controller = GraphViewportController();
) async { addTearDown(controller.dispose);
for (final cupertino in [false, true]) { await tester.pumpWidget(
final controller = GraphViewportController(); viewportHost(
addTearDown(controller.dispose); controller: controller,
await tester.pumpWidget( child: viewportTargets([]),
viewportHost( textScale: 2,
controller: controller, viewport: const Size(320, 300),
child: viewportTargets([]), onExpand: () {},
cupertino: cupertino, ),
dark: cupertino, );
textScale: 2, await settleViewport(tester);
viewport: const Size(320, 300), expect(find.byKey(const Key('graph-fit')), findsOneWidget);
onExpand: () {}, expect(find.byKey(const Key('graph-expand')), findsOneWidget);
), expect(tester.takeException(), isNull);
);
await settleViewport(tester);
expect(find.byKey(const Key('graph-fit')), findsOneWidget);
expect(find.byKey(const Key('graph-expand')), findsOneWidget);
expect(tester.takeException(), isNull);
final before = controller.offset; final before = controller.offset;
await dragViewport( await dragViewport(
tester, tester,
find.byKey(const Key('graph-viewport')), find.byKey(const Key('graph-viewport')),
const Offset(-30, -10), const Offset(-30, -10),
); );
expect(controller.offset, isNot(before)); expect(controller.offset, isNot(before));
await pinchViewport(tester, const Offset(160, 150), 2); await pinchViewport(tester, const Offset(160, 150), 2);
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(controller.scale, greaterThan(0.3)); expect(controller.scale, greaterThan(0.3));
expect(tester.takeException(), isNull); expect(tester.takeException(), isNull);
}
}); });
} }
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
@@ -48,7 +47,6 @@ Widget viewportHost({
required GraphViewportController controller, required GraphViewportController controller,
required Widget child, required Widget child,
VoidCallback? onExpand, VoidCallback? onExpand,
bool cupertino = false,
bool dark = false, bool dark = false,
double textScale = 1, double textScale = 1,
Size viewport = defaultViewportSize, Size viewport = defaultViewportSize,
@@ -65,14 +63,6 @@ Widget viewportHost({
), ),
), ),
); );
if (cupertino) {
return CupertinoApp(
theme: CupertinoThemeData(
brightness: dark ? Brightness.dark : Brightness.light,
),
home: CupertinoPageScaffold(child: Center(child: graph)),
);
}
return MaterialApp( return MaterialApp(
theme: dark ? ThemeData.dark() : ThemeData.light(), theme: dark ? ThemeData.dark() : ThemeData.light(),
home: Scaffold(body: Center(child: graph)), home: Scaffold(body: Center(child: graph)),
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
@@ -57,21 +56,6 @@ Widget _materialHost(
); );
} }
Widget _cupertinoHost(JsonMap graph, {ValueChanged<String>? onSelected}) {
return CupertinoApp(
home: CupertinoPageScaffold(
child: SizedBox(
width: 900,
height: 700,
child: DefinitionGraphView(
graph: graph,
onSelected: onSelected ?? (_) {},
),
),
),
);
}
/// Settles the two-frame measure-then-place contract. /// Settles the two-frame measure-then-place contract.
Future<void> _settle(WidgetTester tester) async { Future<void> _settle(WidgetTester tester) async {
await tester.pump(); await tester.pump();
@@ -315,27 +299,4 @@ void main() {
expect(find.byType(GraphStageNode), findsNothing); expect(find.byType(GraphStageNode), findsNothing);
expect(find.byType(InteractiveViewer), findsNothing); expect(find.byType(InteractiveViewer), findsNothing);
}); });
testWidgets('cupertino host composes native buttons and keeps identity', (
tester,
) async {
final picked = <String>[];
await tester.pumpWidget(
_cupertinoHost(linearGraph(), onSelected: picked.add),
);
await _settle(tester);
expect(
find.descendant(
of: find.byType(GraphStageNode),
matching: find.byType(CupertinoButton),
),
findsNWidgets(5),
);
expect(find.byType(Card), findsNothing);
_expectNoOverlaps(tester);
await _tapNode(tester, '#failure');
expect(picked, ['#failure']);
});
} }
@@ -1,7 +1,6 @@
import 'dart:typed_data'; import 'dart:typed_data';
import 'dart:ui' as ui; import 'dart:ui' as ui;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
@@ -21,10 +20,6 @@ Widget _material(Widget child) => MaterialApp(
home: Scaffold(body: Center(child: child)), home: Scaffold(body: Center(child: child)),
); );
Widget _cupertino(Widget child) => CupertinoApp(
home: CupertinoPageScaffold(child: Center(child: child)),
);
/// The node centred on an opaque page, inside its own repaint boundary so the /// The node centred on an opaque page, inside its own repaint boundary so the
/// painted result can be read back as pixels. /// painted result can be read back as pixels.
Widget _framed(Key key, Widget Function(Widget) wrap, Widget child) => wrap( Widget _framed(Key key, Widget Function(Widget) wrap, Widget child) => wrap(
@@ -153,58 +148,27 @@ void main() {
} }
}); });
testWidgets('unselected cupertino node paints a visible container', ( testWidgets('selected state changes the painted surface', (tester) async {
tester, final colors = <bool, Color>{};
) async { for (final selected in [false, true]) {
final key = GlobalKey(); final key = GlobalKey();
await tester.pumpWidget( await tester.pumpWidget(
_framed( _framed(
key, key,
_cupertino, _material,
GraphStageNode(node: _stage, onSelected: (_) {}), GraphStageNode(node: _stage, selected: selected, onSelected: (_) {}),
), ),
);
final shot = await _shot(tester, key);
final rect = tester.getRect(find.byType(CupertinoButton));
// Just inside the left edge of the control, clear of the label's inset.
final body = shot.at(rect.centerLeft + const Offset(4, 0));
final page = shot.at(const Offset(4, 4));
expect(
_distance(body, page),
greaterThan(24),
reason: 'an unselected cupertino node needs its own visible surface',
);
});
testWidgets('selected state changes the painted surface in both hosts', (
tester,
) async {
for (final wrap in [_material, _cupertino]) {
final colors = <bool, Color>{};
for (final selected in [false, true]) {
final key = GlobalKey();
await tester.pumpWidget(
_framed(
key,
wrap,
GraphStageNode(
node: _stage,
selected: selected,
onSelected: (_) {},
),
),
);
final shot = await _shot(tester, key);
final rect = tester.getRect(find.byType(GraphStageNode));
colors[selected] = shot.at(rect.centerLeft + const Offset(4, 0));
}
expect(
_distance(colors[false]!, colors[true]!),
greaterThan(16),
reason:
'selection must be visible, not only announced: the surface fill '
'and the outlined border change together',
); );
final shot = await _shot(tester, key);
final rect = tester.getRect(find.byType(GraphStageNode));
colors[selected] = shot.at(rect.centerLeft + const Offset(4, 0));
} }
expect(
_distance(colors[false]!, colors[true]!),
greaterThan(16),
reason:
'selection must be visible, not only announced: the surface fill '
'and the outlined border change together',
);
}); });
} }
@@ -1,6 +1,5 @@
import 'dart:ui' show Tristate; import 'dart:ui' show Tristate;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
@@ -17,10 +16,6 @@ Widget _material(Widget child) => MaterialApp(
home: Scaffold(body: Center(child: child)), home: Scaffold(body: Center(child: child)),
); );
Widget _cupertino(Widget child) => CupertinoApp(
home: CupertinoPageScaffold(child: Center(child: child)),
);
/// Applies a 2x text scale below the app so the fixture renders as a real /// Applies a 2x text scale below the app so the fixture renders as a real
/// scale-2 layout rather than a test-only text property. /// scale-2 layout rather than a test-only text property.
Widget _scaled(Widget child) => Builder( Widget _scaled(Widget child) => Builder(
@@ -65,9 +60,7 @@ void main() {
expect(_semantics(tester).label, 'Success'); expect(_semantics(tester).label, 'Success');
}); });
testWidgets('selected node is announced selected in both native hosts', ( testWidgets('selected node is announced selected', (tester) async {
tester,
) async {
await tester.pumpWidget( await tester.pumpWidget(
_material( _material(
GraphStageNode(node: _stage, selected: true, onSelected: (_) {}), GraphStageNode(node: _stage, selected: true, onSelected: (_) {}),
@@ -76,15 +69,6 @@ void main() {
expect(find.byType(Card), findsOneWidget); expect(find.byType(Card), findsOneWidget);
expect(find.byType(InkWell), findsOneWidget); expect(find.byType(InkWell), findsOneWidget);
_expectSelectable(tester, selected: true); _expectSelectable(tester, selected: true);
await tester.pumpWidget(
_cupertino(
GraphStageNode(node: _stage, selected: true, onSelected: (_) {}),
),
);
expect(find.byType(CupertinoButton), findsOneWidget);
expect(find.byType(Card), findsNothing);
_expectSelectable(tester, selected: true);
}); });
testWidgets('unselected node is not announced selected', (tester) async { testWidgets('unselected node is not announced selected', (tester) async {
@@ -96,17 +80,15 @@ void main() {
}); });
testWidgets('keyboard activation selects the node', (tester) async { testWidgets('keyboard activation selects the node', (tester) async {
for (final wrap in [_material, _cupertino]) { final picked = <String>[];
final picked = <String>[]; await tester.pumpWidget(
await tester.pumpWidget( _material(GraphStageNode(node: _stage, onSelected: picked.add)),
wrap(GraphStageNode(node: _stage, onSelected: picked.add)), );
); await tester.sendKeyEvent(LogicalKeyboardKey.tab);
await tester.sendKeyEvent(LogicalKeyboardKey.tab); await tester.pumpAndSettle();
await tester.pumpAndSettle(); await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.sendKeyEvent(LogicalKeyboardKey.enter); await tester.pumpAndSettle();
await tester.pumpAndSettle(); expect(picked, ['build']);
expect(picked, ['build']);
}
}); });
testWidgets('keyboard selection keeps focus inside the material node', ( testWidgets('keyboard selection keeps focus inside the material node', (
@@ -144,46 +126,44 @@ void main() {
) async { ) async {
const label = 'implementer-with-an-unshortened-stage-label'; const label = 'implementer-with-an-unshortened-stage-label';
const node = GraphNode(key: label, terminal: false, stageIndex: 0); const node = GraphNode(key: label, terminal: false, stageIndex: 0);
for (final wrap in [_material, _cupertino]) { await tester.pumpWidget(
await tester.pumpWidget( _material(
wrap( _scaled(
_scaled( SizedBox(
SizedBox( width: 150,
width: 150, child: GraphStageNode(node: node, onSelected: (_) {}),
child: GraphStageNode(node: node, onSelected: (_) {}),
),
), ),
), ),
); ),
);
expect(tester.takeException(), isNull); expect(tester.takeException(), isNull);
final text = tester.widget<Text>(_visual(label)); final text = tester.widget<Text>(_visual(label));
expect(text.data!.replaceAll('\u200B', ''), label); expect(text.data!.replaceAll('\u200B', ''), label);
expect(text.maxLines, isNull); expect(text.maxLines, isNull);
expect(text.overflow, isNull); expect(text.overflow, isNull);
final paragraph = tester.renderObject<RenderParagraph>(_visual(label)); final paragraph = tester.renderObject<RenderParagraph>(_visual(label));
expect(paragraph.size.width, lessThanOrEqualTo(150)); expect(paragraph.size.width, lessThanOrEqualTo(150));
expect( expect(
paragraph.size.height, paragraph.size.height,
greaterThan(50), greaterThan(50),
reason: 'the 2x label must occupy more than one 2x text line', reason: 'the 2x label must occupy more than one 2x text line',
); );
// No glyph may paint outside the paragraph: every laid-out line, // No glyph may paint outside the paragraph: every laid-out line,
// including a hyphen-broken segment, fits the width the control gave it. // including a hyphen-broken segment, fits the width the control gave it.
final painter = TextPainter( final painter = TextPainter(
text: paragraph.text, text: paragraph.text,
textDirection: paragraph.textDirection, textDirection: paragraph.textDirection,
textScaler: paragraph.textScaler, textScaler: paragraph.textScaler,
textAlign: paragraph.textAlign, textAlign: paragraph.textAlign,
)..layout(maxWidth: paragraph.size.width); )..layout(maxWidth: paragraph.size.width);
expect( expect(
painter.computeLineMetrics().every( painter.computeLineMetrics().every(
(line) => line.width <= paragraph.size.width + 0.5, (line) => line.width <= paragraph.size.width + 0.5,
), ),
isTrue, isTrue,
reason: 'an unshortened label must wrap, not paint over the control', reason: 'an unshortened label must wrap, not paint over the control',
); );
}
}); });
testWidgets('terminal shows its definition label and no invented status', ( testWidgets('terminal shows its definition label and no invented status', (
@@ -207,7 +187,7 @@ void main() {
testWidgets('a recorded status is shown verbatim', (tester) async { testWidgets('a recorded status is shown verbatim', (tester) async {
await tester.pumpWidget( await tester.pumpWidget(
_cupertino( _material(
GraphStageNode( GraphStageNode(
node: _stage, node: _stage,
recordedStatus: 'failed', recordedStatus: 'failed',
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/semantics.dart'; import 'package:flutter/semantics.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
@@ -113,35 +112,6 @@ Widget _materialHost(
); );
} }
Widget _cupertinoHost(
JsonMap graph,
JsonMap run, {
ValueChanged<String>? onSelected,
double scale = 1,
}) {
return CupertinoApp(
theme: const CupertinoThemeData(brightness: Brightness.dark),
home: CupertinoPageScaffold(
child: Builder(
builder: (context) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: TextScaler.linear(scale)),
child: SizedBox(
width: 320,
height: 700,
child: RunGraphView(
graph: graph,
run: run,
onStageSelected: onSelected ?? (_) {},
),
),
),
),
),
);
}
Future<void> _settle(WidgetTester tester) async { Future<void> _settle(WidgetTester tester) async {
await tester.pump(); await tester.pump();
await tester.pump(); await tester.pump();
@@ -450,39 +420,4 @@ void main() {
_expectNoOverlaps(tester); _expectNoOverlaps(tester);
expect(tester.takeException(), isNull); expect(tester.takeException(), isNull);
}); });
testWidgets('dark Cupertino host keeps native nodes and evidence', (
tester,
) async {
final picked = <String>[];
await tester.pumpWidget(
_cupertinoHost(linearGraph(), _runningRun(), onSelected: picked.add),
);
await _settle(tester);
expect(find.byType(Card), findsNothing);
expect(
find.descendant(
of: find.byType(GraphStageNode),
matching: find.byType(CupertinoButton),
),
findsNWidgets(5),
);
expect(find.text(runGraphExecuted), findsOneWidget);
expect(find.text(runGraphNotExecuted), findsOneWidget);
expect(
tester.widget<GraphStageNode>(_node('plan')).recordedStatus,
'completed',
);
expect(
tester.widget<GraphStageNode>(_node('build')).recordedStatus,
'running',
);
_expectNoOverlaps(tester);
await tester.tap(_node('plan'));
await tester.pump();
expect(picked, ['plan']);
expect(tester.takeException(), isNull);
});
} }
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
@@ -37,13 +36,6 @@ Widget _material(Widget child) => MaterialApp(
), ),
); );
Widget _cupertino(Widget child, {bool dark = false}) => CupertinoApp(
theme: CupertinoThemeData(
brightness: dark ? Brightness.dark : Brightness.light,
),
home: CupertinoPageScaffold(child: child),
);
StageDefinitionView _view({String key = 'plan'}) => StageDefinitionView( StageDefinitionView _view({String key = 'plan'}) => StageDefinitionView(
graph: _graph(), graph: _graph(),
stageKey: key, stageKey: key,
@@ -138,26 +130,6 @@ void main() {
expect(_text('successful'), findsNothing); expect(_text('successful'), findsNothing);
}); });
testWidgets('Cupertino uses its theme roles in dark mode', (tester) async {
late Color secondary;
await tester.pumpWidget(
_cupertino(
Builder(
builder: (context) {
secondary = CupertinoColors.secondaryLabel.resolveFrom(context);
return _view();
},
),
dark: true,
),
);
final identity = tester.widget<Text>(_text('Demo pipeline · v7'));
expect(identity.style?.color, secondary);
expect(_text('Plan the change.'), findsOneWidget);
expect(tester.takeException(), isNull);
});
testWidgets('the Material helper opens one bar and Back closes it', ( testWidgets('the Material helper opens one bar and Back closes it', (
tester, tester,
) async { ) async {
@@ -198,44 +170,6 @@ void main() {
expect(find.byType(StageDefinitionView), findsNothing); expect(find.byType(StageDefinitionView), findsNothing);
}); });
testWidgets('the Cupertino helper opens one native bar and Back closes it', (
tester,
) async {
await tester.pumpWidget(
CupertinoApp(
home: Builder(
builder: (context) => CupertinoPageScaffold(
child: CupertinoButton(
onPressed: () => openStageDefinition(
context,
graph: _graph(),
stageKey: '#success',
pipelineId: 41,
pipelineName: 'Demo pipeline',
version: 7,
),
child: const Text('Open terminal'),
),
),
),
),
);
await tester.tap(find.text('Open terminal'));
await tester.pumpAndSettle();
expect(_text('Success definition'), findsOneWidget);
expect(_text('#success definition'), findsNothing);
expect(find.byType(SegmentedBar), findsOneWidget);
expect(find.byType(CupertinoNavigationBarBackButton), findsOneWidget);
expect(_text('Incoming routes'), findsOneWidget);
await tester.tap(find.byType(CupertinoNavigationBarBackButton));
await tester.pumpAndSettle();
expect(_text('Open terminal'), findsOneWidget);
expect(find.byType(StageDefinitionView), findsNothing);
});
testWidgets('the Material helper titles a terminal with its display label', ( testWidgets('the Material helper titles a terminal with its display label', (
tester, tester,
) async { ) async {
@@ -270,7 +204,11 @@ void main() {
testWidgets('selectable blocks force the host strut for one line rhythm', ( testWidgets('selectable blocks force the host strut for one line rhythm', (
tester, tester,
) async { ) async {
await tester.pumpWidget(_cupertino(_view())); // Tall enough that the raw section below the prompt is built.
tester.view.physicalSize = const Size(800, 2000);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(_material(_view()));
final selectable = tester final selectable = tester
.widgetList<SelectableText>(find.byType(SelectableText)) .widgetList<SelectableText>(find.byType(SelectableText))
@@ -0,0 +1,130 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/windows/window_entry.dart';
import 'package:pipelines_app/shell/windows/window_kind.dart';
import 'package:pipelines_app/shell/windows/window_layer.dart';
import 'package:pipelines_app/shell/windows/window_manager.dart';
import 'window_test_harness.dart';
/// A probe kind whose content keeps its element when the window is retargeted,
/// so a rebuild is visible in the same state's counter.
class _StableProbeKind extends WindowKind {
@override
String get key => 'stable';
@override
bool get serverScoped => false;
@override
IconData get icon => Icons.science_outlined;
@override
String title(BuildContext context, WindowEntry entry) =>
'Probe ${entry.contentId}';
@override
Widget build(BuildContext context, WindowEntry entry) =>
ProbeContent(key: const ValueKey('stable-content'), id: entry.contentId);
}
void main() {
late WindowManager manager;
setUp(() => manager = probeManager());
Finder window(String title) => find.byWidgetPredicate(
(w) => w is WindowLayer && 'Probe ${w.entry.contentId}' == title,
);
Finder inWindow(String title, Finder what) =>
find.descendant(of: window(title), matching: what);
ProbeContentState content(WidgetTester tester, String id) =>
tester.state<ProbeContentState>(find.byKey(ValueKey('content-$id')));
Future<void> openTwo(WidgetTester tester) async {
manager.open('probe', 'a', frame: const Rect.fromLTWH(100, 80, 360, 420));
manager.open('probe', 'b', frame: const Rect.fromLTWH(600, 200, 360, 420));
await pumpProbe(tester, manager);
}
testWidgets('dragging a window moves it without rebuilding any content', (
tester,
) async {
await openTwo(tester);
final a = content(tester, 'a');
final b = content(tester, 'b');
final beforeA = a.builds;
final beforeB = b.builds;
final start = windowRect(tester, 'Probe a').topLeft;
final fieldStart = tester
.getRect(find.byKey(const ValueKey('a-field')))
.topLeft;
final gesture = await tester.startGesture(
tester.getCenter(
inWindow('Probe a', find.byKey(const ValueKey('window-title'))),
),
);
for (var i = 0; i < 8; i++) {
await gesture.moveBy(const Offset(12, 6));
await tester.pump();
expect(a.builds, beforeA, reason: 'dragged window rebuilt at move $i');
expect(b.builds, beforeB, reason: 'other window rebuilt at move $i');
}
await gesture.up();
await tester.pumpAndSettle();
// It really moved, and its content followed it.
expect(windowRect(tester, 'Probe a').topLeft, start + const Offset(96, 48));
expect(
tester.getRect(find.byKey(const ValueKey('a-field'))).topLeft,
fieldStart + const Offset(96, 48),
);
expect(content(tester, 'a').builds, beforeA);
expect(content(tester, 'b').builds, beforeB);
});
testWidgets('resizing a window keeps another window and sees the new size', (
tester,
) async {
await openTwo(tester);
final a = content(tester, 'a');
final b = content(tester, 'b');
final beforeA = a.builds;
final beforeB = b.builds;
final beforeSize = b.lastSize!;
final gesture = await tester.startGesture(
tester.getCenter(
inWindow('Probe b', find.byKey(const ValueKey('window-resize'))),
),
);
for (var i = 0; i < 5; i++) {
await gesture.moveBy(const Offset(-16, -10));
await tester.pump();
expect(a.builds, beforeA, reason: 'other window rebuilt at move $i');
}
await gesture.up();
await tester.pumpAndSettle();
expect(content(tester, 'a').builds, beforeA);
final state = content(tester, 'b');
expect(state.builds, greaterThan(beforeB));
expect(state.lastSize!.width, beforeSize.width - 80);
expect(state.lastSize!.height, beforeSize.height - 50);
});
testWidgets('content still rebuilds when its window is retargeted', (
tester,
) async {
manager = WindowManager(
kinds: WindowKinds()..register(_StableProbeKind()),
);
final entry = manager.open('stable', 'a');
await pumpProbe(tester, manager);
final state = tester.state<ProbeContentState>(
find.byKey(const ValueKey('stable-content')),
);
final before = state.builds;
manager.setContent(entry.id, 'c');
await tester.pumpAndSettle();
final after = tester.state<ProbeContentState>(
find.byKey(const ValueKey('stable-content')),
);
expect(after, same(state));
expect(after.builds, greaterThan(before));
expect(after.widget.id, 'c');
expect(find.text('Probe c'), findsOneWidget);
});
}
+5
View File
@@ -52,6 +52,10 @@ class ProbeContentState extends State<ProbeContent> {
int builds = 0; int builds = 0;
String? picked; String? picked;
/// The size the content was last laid out at (the window's content area),
/// so tests can see a resize reach it.
Size? lastSize;
@override @override
void dispose() { void dispose() {
text.dispose(); text.dispose();
@@ -67,6 +71,7 @@ class ProbeContentState extends State<ProbeContent> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
builds++; builds++;
lastSize = MediaQuery.sizeOf(context);
final id = widget.id; final id = widget.id;
return ListView( return ListView(
children: [ children: [