Merge commit 'c65a66d9bb27a16c8fc201f25dd5df6c2076682c' into pipelines/run-20261111-0338-cupertino-out-search-5420
This commit is contained in:
@@ -75,22 +75,54 @@ String windowFrameKey(String kind, String? serverKey, String contentId) =>
|
||||
'$kind\n${serverKey ?? ''}\n$contentId';
|
||||
|
||||
/// [rect] moved and shrunk to fit inside [bounds], at least [minSize] where
|
||||
/// the bounds allow it.
|
||||
/// the bounds allow it, on whole logical pixels.
|
||||
///
|
||||
/// Whole pixels keep a moved window exactly its size from frame to frame: a
|
||||
/// `Rect` stores left, top, right and bottom, so shifting a frame by a
|
||||
/// fractional delta makes its width differ in its last bits, and every widget
|
||||
/// that reads the window's size (its `MediaQuery`) rebuilds and lays out
|
||||
/// again on every pointer event.
|
||||
Rect fitWindowFrame(Rect rect, Size bounds, Size minSize) {
|
||||
final width = rect.width
|
||||
.clamp(minSize.width, double.infinity)
|
||||
.clamp(0.0, bounds.width);
|
||||
final height = rect.height
|
||||
.clamp(minSize.height, double.infinity)
|
||||
.clamp(0.0, bounds.height);
|
||||
final width = _wholePixel(
|
||||
rect.width.clamp(minSize.width, double.infinity).clamp(0.0, bounds.width),
|
||||
minSize.width,
|
||||
bounds.width,
|
||||
);
|
||||
final height = _wholePixel(
|
||||
rect.height
|
||||
.clamp(minSize.height, double.infinity)
|
||||
.clamp(0.0, bounds.height),
|
||||
minSize.height,
|
||||
bounds.height,
|
||||
);
|
||||
return Rect.fromLTWH(
|
||||
rect.left.clamp(0.0, bounds.width - width),
|
||||
rect.top.clamp(0.0, bounds.height - height),
|
||||
_wholePixel(
|
||||
rect.left.clamp(0.0, bounds.width - width),
|
||||
0,
|
||||
bounds.width - width,
|
||||
),
|
||||
_wholePixel(
|
||||
rect.top.clamp(0.0, bounds.height - height),
|
||||
0,
|
||||
bounds.height - height,
|
||||
),
|
||||
width,
|
||||
height,
|
||||
);
|
||||
}
|
||||
|
||||
/// [value] rounded to a whole logical pixel and kept within
|
||||
/// `[minimum, limit]`.
|
||||
///
|
||||
/// A fractional [minimum] rounds up, so the whole-pixel size never drops below
|
||||
/// the minimum the caller asked for; when the limit is too small to hold that,
|
||||
/// the limit wins.
|
||||
double _wholePixel(double value, double minimum, double limit) {
|
||||
final max = limit.floorToDouble();
|
||||
final min = minimum.ceilToDouble().clamp(0.0, max);
|
||||
return value.roundToDouble().clamp(min, max);
|
||||
}
|
||||
|
||||
/// Where [entry] is drawn inside [bounds]: fitted, or filling the area less
|
||||
/// a margin when maximised.
|
||||
Rect drawnWindowFrame(WindowEntry entry, Size bounds, Size minSize) =>
|
||||
|
||||
@@ -106,12 +106,26 @@ class _WindowLayerState extends State<WindowLayer>
|
||||
/// Where the pointer is in the host while the title is dragged.
|
||||
Offset? _pointer;
|
||||
|
||||
/// The frame the current move or resize started from and the pointer delta
|
||||
/// summed since. Every event sets the frame from `start + total`: fitting
|
||||
/// one fractional step after another would round part of the pointer's
|
||||
/// movement away each time and drift, and shifting the fitted frame would
|
||||
/// change its size in its last bits.
|
||||
Rect? _dragStart;
|
||||
Offset _dragTotal = Offset.zero;
|
||||
|
||||
void _move(Offset delta, Offset globalPosition) {
|
||||
final box = context.findRenderObject();
|
||||
_pointer = box is RenderBox ? box.globalToLocal(globalPosition) : null;
|
||||
final start = _dragStart ??= _current;
|
||||
_dragTotal += delta;
|
||||
widget.manager.setFrame(
|
||||
_id,
|
||||
fitWindowFrame(_current.shift(delta), widget.bounds, widget.kind.minSize),
|
||||
fitWindowFrame(
|
||||
start.shift(_dragTotal),
|
||||
widget.bounds,
|
||||
widget.kind.minSize,
|
||||
),
|
||||
save: false,
|
||||
);
|
||||
}
|
||||
@@ -121,6 +135,7 @@ class _WindowLayerState extends State<WindowLayer>
|
||||
void _moveEnded() {
|
||||
final pointer = _pointer;
|
||||
_pointer = null;
|
||||
_endDrag();
|
||||
final bounds = widget.bounds;
|
||||
final snap = pointer == null ? null : windowSnapFor(pointer, bounds);
|
||||
if (snap == WindowSnap.maximize) {
|
||||
@@ -145,15 +160,16 @@ class _WindowLayerState extends State<WindowLayer>
|
||||
}
|
||||
|
||||
void _resize(Offset delta) {
|
||||
final rect = _current;
|
||||
final start = _dragStart ??= _current;
|
||||
_dragTotal += delta;
|
||||
widget.manager.setFrame(
|
||||
_id,
|
||||
fitWindowFrame(
|
||||
Rect.fromLTWH(
|
||||
rect.left,
|
||||
rect.top,
|
||||
rect.width + delta.dx,
|
||||
rect.height + delta.dy,
|
||||
start.left,
|
||||
start.top,
|
||||
start.width + _dragTotal.dx,
|
||||
start.height + _dragTotal.dy,
|
||||
),
|
||||
widget.bounds,
|
||||
widget.kind.minSize,
|
||||
@@ -162,16 +178,34 @@ class _WindowLayerState extends State<WindowLayer>
|
||||
);
|
||||
}
|
||||
|
||||
void _resizeEnded() {
|
||||
_endDrag();
|
||||
widget.manager.commit(_id);
|
||||
}
|
||||
|
||||
/// A drag ends here even if it is cancelled or another gesture begins.
|
||||
void _endDrag() {
|
||||
_dragStart = null;
|
||||
_dragTotal = Offset.zero;
|
||||
}
|
||||
|
||||
/// A press brings the window to the top and gives it the keyboard at
|
||||
/// once, before the press does anything else (focus a field, open a
|
||||
/// popup that takes the keyboard itself).
|
||||
void _pressed() {
|
||||
// A new gesture measures from where it starts, even if the last drag was
|
||||
// cancelled before it ended.
|
||||
_endDrag();
|
||||
if (!widget.focus.has(_id)) widget.focus.focusNow(_id);
|
||||
widget.manager.raise(_id);
|
||||
}
|
||||
|
||||
ThemeData _pageThemeFor(ThemeData theme) {
|
||||
if (identical(theme, _themeSource)) return _pageTheme!;
|
||||
// Equal to the last theme means the same page theme, even when the app's
|
||||
// animated theme hands over a new but equal `ThemeData` object: a new
|
||||
// page theme would notify every content widget that reads the theme on
|
||||
// every frame of a move.
|
||||
if (theme == _themeSource) return _pageTheme!;
|
||||
_themeSource = theme;
|
||||
return _pageTheme = WindowNavigator.themeData(theme);
|
||||
}
|
||||
@@ -263,7 +297,7 @@ class _WindowLayerState extends State<WindowLayer>
|
||||
bottom: widget.bounds.height - frame.bottom,
|
||||
child: WindowResizeCorner(
|
||||
onResize: _resize,
|
||||
onResizeEnd: () => manager.commit(_id),
|
||||
onResizeEnd: _resizeEnded,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user