4e0481fd8d
Full screen button in the viewer's bottom bar opens a root full-screen route with the same bar and top bar; exit by the bar, Close, Escape or back. It renders the already fetched bytes, never the system browser. The external Open action is now labelled Open in browser. Native web views claim their gestures (vertical drags inline, every pointer in full screen) so the page swipe no longer starves them. On the web, full screen adds zoom buttons that scale the live sandboxed frame. Links: in-page anchors scroll, http(s)/mailto open outside, everything else is inert. Capture kit: --touch, swipe=, pinch=, tabs=; html=1 fixture artifact.
117 lines
3.8 KiB
Dart
117 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.
|
|
Route<void> artifactFullscreenRoute({
|
|
required bool cupertino,
|
|
required WidgetBuilder builder,
|
|
}) => cupertino
|
|
? CupertinoPageRoute<void>(fullscreenDialog: true, builder: 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,
|
|
),
|
|
];
|
|
}
|