9551eceaed
Remove obsolete control-family flags and icon metadata across all callers, dead alternate themes and host helpers, obsolete test setup, and the unused icon-font dependency. Preserve native Material Back transitions. Make navigation fixtures independent of update plugins and answer auxiliary shell snapshots so the complete application suite can run deterministically.
105 lines
3.5 KiB
Dart
105 lines
3.5 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../ui/adaptive/segmented_bar_overflow.dart';
|
|
import '../actions/artifact_file_actions.dart';
|
|
|
|
/// Marks a subtree as the artifact viewer's full-screen view, where an HTML
|
|
/// document takes every gesture over it (scroll, pan, pinch) instead of
|
|
/// sharing them with the viewer's page swipe, and follows [htmlZoom].
|
|
class ArtifactFullscreenScope extends InheritedWidget {
|
|
const ArtifactFullscreenScope({
|
|
super.key,
|
|
required this.htmlZoom,
|
|
required super.child,
|
|
});
|
|
|
|
/// The HTML document's zoom factor (1 is the document's own size), set by
|
|
/// [ArtifactHtmlZoomActions].
|
|
final ValueListenable<double> htmlZoom;
|
|
|
|
static ArtifactFullscreenScope? maybeOf(BuildContext context) =>
|
|
context.dependOnInheritedWidgetOfExactType<ArtifactFullscreenScope>();
|
|
|
|
@override
|
|
bool updateShouldNotify(ArtifactFullscreenScope oldWidget) =>
|
|
htmlZoom != oldWidget.htmlZoom;
|
|
}
|
|
|
|
/// The full-screen view's route, pushed on the root navigator so it covers
|
|
/// the shell's bars and list pane. A full-screen dialog route: its bar shows
|
|
/// the platform's Close, and the system back gesture leaves it.
|
|
///
|
|
/// Uses the native Material fullscreen route.
|
|
Route<void> artifactFullscreenRoute({required WidgetBuilder builder}) =>
|
|
MaterialPageRoute<void>(fullscreenDialog: true, builder: builder);
|
|
|
|
/// The zoom factors Zoom in and Zoom out step through.
|
|
const List<double> artifactHtmlZoomSteps = [
|
|
0.5, 0.67, 0.8, 0.9, 1, 1.1, 1.25, 1.5, 1.75, 2, 2.5, 3, 4, //
|
|
];
|
|
|
|
/// The next zoom step from [current] in [direction] (+1 in, -1 out), held at
|
|
/// both ends.
|
|
double artifactHtmlZoomStep(double current, int direction) {
|
|
if (direction > 0) {
|
|
return artifactHtmlZoomSteps.firstWhere(
|
|
(step) => step > current + 0.001,
|
|
orElse: () => artifactHtmlZoomSteps.last,
|
|
);
|
|
}
|
|
return artifactHtmlZoomSteps.lastWhere(
|
|
(step) => step < current - 0.001,
|
|
orElse: () => artifactHtmlZoomSteps.first,
|
|
);
|
|
}
|
|
|
|
const artifactZoomOutKey = ValueKey<String>('artifact-zoom-out');
|
|
const artifactZoomResetKey = ValueKey<String>('artifact-zoom-reset');
|
|
const artifactZoomInKey = ValueKey<String>('artifact-zoom-in');
|
|
|
|
/// Zoom out, actual size and zoom in for an HTML document, as top-bar
|
|
/// actions (a narrow bar moves them into its More menu). Used where the
|
|
/// document cannot be pinched (the web's sandboxed frame): the frame keeps
|
|
/// scrolling the live document at the chosen size.
|
|
List<Widget> artifactHtmlZoomActions(ValueNotifier<double> zoom) {
|
|
void step(int direction) =>
|
|
zoom.value = artifactHtmlZoomStep(zoom.value, direction);
|
|
final percent = '${(zoom.value * 100).round()}%';
|
|
Widget action(
|
|
Key key,
|
|
String label,
|
|
IconData icon,
|
|
VoidCallback? onPressed,
|
|
) => SegmentedOverflowAction(
|
|
key: key,
|
|
overflowEntry: SegmentedOverflowEntry(
|
|
label: label,
|
|
icon: icon,
|
|
onPressed: onPressed,
|
|
),
|
|
child: ArtifactIconAction(label: label, icon: icon, onPressed: onPressed),
|
|
);
|
|
final value = zoom.value;
|
|
return [
|
|
action(
|
|
artifactZoomOutKey,
|
|
'Zoom out',
|
|
Icons.zoom_out,
|
|
value > artifactHtmlZoomSteps.first + 0.001 ? () => step(-1) : null,
|
|
),
|
|
action(
|
|
artifactZoomResetKey,
|
|
'Actual size ($percent)',
|
|
Icons.restart_alt,
|
|
(value - 1).abs() > 0.001 ? () => zoom.value = 1 : null,
|
|
),
|
|
action(
|
|
artifactZoomInKey,
|
|
'Zoom in',
|
|
Icons.zoom_in,
|
|
value < artifactHtmlZoomSteps.last - 0.001 ? () => step(1) : null,
|
|
),
|
|
];
|
|
}
|