f46b82e207
Keep the Material implementation while preserving public parameters needed by callers. Remove Cupertino-only tests and variants because the app runs exclusively under MaterialApp.
118 lines
3.8 KiB
Dart
118 lines
3.8 KiB
Dart
import 'package:flutter/cupertino.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.
|
|
///
|
|
/// [cupertino] is retained for callers that still pass it; the route is always
|
|
/// the Material one.
|
|
Route<void> artifactFullscreenRoute({
|
|
required bool cupertino,
|
|
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,
|
|
IconData cupertinoIcon,
|
|
VoidCallback? onPressed,
|
|
) => SegmentedOverflowAction(
|
|
key: key,
|
|
overflowEntry: SegmentedOverflowEntry(
|
|
label: label,
|
|
icon: icon,
|
|
onPressed: onPressed,
|
|
),
|
|
child: ArtifactIconAction(
|
|
label: label,
|
|
icon: icon,
|
|
cupertinoIcon: cupertinoIcon,
|
|
onPressed: onPressed,
|
|
),
|
|
);
|
|
final value = zoom.value;
|
|
return [
|
|
action(
|
|
artifactZoomOutKey,
|
|
'Zoom out',
|
|
Icons.zoom_out,
|
|
CupertinoIcons.zoom_out,
|
|
value > artifactHtmlZoomSteps.first + 0.001 ? () => step(-1) : null,
|
|
),
|
|
action(
|
|
artifactZoomResetKey,
|
|
'Actual size ($percent)',
|
|
Icons.restart_alt,
|
|
CupertinoIcons.arrow_counterclockwise,
|
|
(value - 1).abs() > 0.001 ? () => zoom.value = 1 : null,
|
|
),
|
|
action(
|
|
artifactZoomInKey,
|
|
'Zoom in',
|
|
Icons.zoom_in,
|
|
CupertinoIcons.zoom_in,
|
|
value < artifactHtmlZoomSteps.last - 0.001 ? () => step(1) : null,
|
|
),
|
|
];
|
|
}
|