Browser vuoto: correzioni dopo la revisione (#52)
La revisione di c49df4c ha trovato alcuni punti deboli. Si correggono qui.
- Fuori vista la pagina torna al 100%. Lo zoom calcolato per uno schermo
piccolo restava anche per le sessioni del motore, e le pagine vedevano un
devicePixelRatio diverso (regola 4). Il rapporto si ricalcola solo quando
la finestra viene sullo schermo.
- Pulsante nella barra delle applicazioni. WPF lo cambia nascondendo la
finestra e mostrandola di nuovo (verificato con un aggancio a
WM_WINDOWPOSCHANGED). Ora il pulsante cambia solo mentre la finestra è
fuori vista. Sullo schermo la finestra chiede di ridisegnarsi
(RedrawWindow), senza nulla che la pagina veda. Una prova con WebView2
vero controlla che la finestra non si nasconda mai sullo schermo.
- Ridotta a icona troppo a lungo, la finestra si ripristina coperta (DWM) e
senza prendere il fuoco, e si sposta fuori vista prima di scoprirsi. Prima
ricompariva per un attimo dove stava. Spostare la posizione di ripristino
non basta: Windows la riporta su uno schermo (provato).
- Dopo un riavvio del processo GPU i bordi della pagina cambiano davvero: un
pixel in meno, poi quelli veri. Gli stessi bordi di nuovo potevano non
servire a nulla.
- «Pagina iniziale», sulla barra di Windows e nella vista remota, passa da
BrowserConnectionService.OpenStartPageAsync. Aspetta la fine della
sessione del motore e il turno della pagina, come l'apertura dal riposo,
e agisce solo mentre Alberto guida.
- Vista remota.
- Dopo un riavvio dei fotogrammi la vista aspetta il primo fotogramma per
mezzo secondo prima dell'immagine ferma: Chromium lo manda solo dopo la
risposta allo start, e prima quasi ogni riavvio costava una cattura.
- L'immagine ferma si scarta se nel frattempo arriva un fotogramma vero.
- Il silenzio si conta dall'avvio.
- Un riavvio del browser durante la chiusura non lascia eccezioni non
osservate.
- Un POST vuoto senza Content-Length (a pezzi, HTTP/2) non dà più 400 su
begin, cancel e browser/show (ApiHttp.OptionalBodyAsync).
- La pagina Browser toglie ?accesso=1 dall'indirizzo. Ricaricarla riapriva
la pagina di accesso.
- RemoteViewFramesTests aspetta fino a 20 s invece di 5. Controlla che
l'immagine arrivi, non quanto in fretta; il tempo va nell'uscita della
prova.
Aggiornati PROTOCOLLO.md, la guida (Primo collegamento, Installazione
Windows) e docs/decisioni.md con le righe di #52.
Prove nuove:
- AFrameSoonAfterARestartNeedsNoStillPicture
- PaginaInizialeWaitsForThePageTurnAndActsOnlyWhileAlbertoIsAtTheBrowser
- ABodyWithoutALengthIsReadAndAnEmptyOneIsNoBody
- nella prova della finestra vera: nessun nascondere sullo schermo e pagina
al 100% fuori vista
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c49df4ca7b
commit
654076d280
25 files changed
+505
-86
No files matched your search
@@ -4,6 +4,7 @@ using System.Windows.Controls;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Threading;
|
||||
using Febe.Desktop.Native;
|
||||
|
||||
namespace Febe.Desktop.Browser;
|
||||
|
||||
@@ -17,10 +18,16 @@ namespace Febe.Desktop.Browser;
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// Issue #52. On screen it has a button in the taskbar, so that minimising it does not make it vanish; minimised it
|
||||
/// keeps Alberto at the wheel, but never for long (S2): after <see cref="MinimizedLimit"/> it is restored and put out of
|
||||
/// view as if he had closed it. When the page and its bar do not fit in the work area of the screen (a small screen, a
|
||||
/// large text scale) the window shrinks to fit and the page is shown zoomed out (<see cref="Fit"/>), always with the
|
||||
/// same size in CSS pixels. While the page is the empty rest page the bar says so.
|
||||
/// keeps Alberto at the wheel, but never for long (S2): after <see cref="MinimizedLimit"/> it is put out of view as if
|
||||
/// he had closed it, restored there without coming on screen. When the page and its bar do not fit in the work area of
|
||||
/// the screen (a small screen, a large text scale) the window shrinks to fit and the page is shown zoomed out
|
||||
/// (<see cref="Fit"/>), always with the same size in CSS pixels; out of view the page is at 100% again, so that the
|
||||
/// engine's pages always see the same browser. While the page is the empty rest page the bar says so.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// WPF changes the taskbar button of a shown window by hiding it and showing it again (seen in WM_WINDOWPOSCHANGED:
|
||||
/// SWP_HIDEWINDOW, then SWP_SHOWWINDOW). The button is therefore changed only while the window is out of view: before it
|
||||
/// comes on screen, after it left.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
internal sealed class BrowserWindow : Window
|
||||
@@ -183,6 +190,8 @@ internal sealed class BrowserWindow : Window
|
||||
{
|
||||
var area = SystemParameters.WorkArea;
|
||||
FitTo(area);
|
||||
|
||||
// Still out of view: the hide and show with which WPF adds the button happen where nobody sees them.
|
||||
ShowInTaskbar = true;
|
||||
var width = ActualWidth > 0 ? ActualWidth : PageWidth * Fit;
|
||||
var height = ActualHeight > 0 ? ActualHeight : (PageHeight * Fit) + BarHeight;
|
||||
@@ -192,19 +201,42 @@ internal sealed class BrowserWindow : Window
|
||||
|
||||
/// <summary>
|
||||
/// Parks the window just right of every screen: open, «visible» for Windows and for WebView2, out of Alberto's view
|
||||
/// (S2), without its taskbar button. Never <c>Hide()</c>, never left minimised.
|
||||
/// (S2), without its taskbar button and with the page at 100% (<see cref="Fit"/> 1). Never <c>Hide()</c>, never
|
||||
/// left minimised: a minimised window is restored without taking the focus and cloaked meanwhile, because Windows
|
||||
/// restores it where it was on screen (a restore position off every screen is moved back onto one).
|
||||
/// </summary>
|
||||
public void MoveOffScreen()
|
||||
{
|
||||
_minimized.Stop();
|
||||
if (WindowState == WindowState.Minimized)
|
||||
var restoring = WindowState == WindowState.Minimized;
|
||||
var cloaked = restoring && Cloak(true);
|
||||
try
|
||||
{
|
||||
WindowState = WindowState.Normal;
|
||||
if (restoring)
|
||||
{
|
||||
Win32.ShowWindow(Handle, Win32.SwShowNoActivate);
|
||||
if (WindowState == WindowState.Minimized)
|
||||
{
|
||||
WindowState = WindowState.Normal;
|
||||
}
|
||||
}
|
||||
|
||||
Left = SystemParameters.VirtualScreenLeft + SystemParameters.VirtualScreenWidth + 64;
|
||||
Top = SystemParameters.VirtualScreenTop;
|
||||
|
||||
// Out of view first: the hide and show with which WPF removes the button happen where nobody sees them.
|
||||
ShowInTaskbar = false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (cloaked)
|
||||
{
|
||||
Cloak(false);
|
||||
}
|
||||
}
|
||||
|
||||
ShowInTaskbar = false;
|
||||
Left = SystemParameters.VirtualScreenLeft + SystemParameters.VirtualScreenWidth + 64;
|
||||
Top = SystemParameters.VirtualScreenTop;
|
||||
// The engine's pages see the browser as it is, at 100%, whatever the size of Alberto's screen (rule 4).
|
||||
SetFit(1);
|
||||
}
|
||||
|
||||
/// <summary>Lets the window really close (Febe is stopping).</summary>
|
||||
@@ -250,7 +282,7 @@ internal sealed class BrowserWindow : Window
|
||||
_minimized.Stop();
|
||||
if (WindowState == WindowState.Minimized)
|
||||
{
|
||||
WindowState = WindowState.Normal;
|
||||
// Restored out of view by the owner (MoveOffScreen), never first on screen where it was.
|
||||
DoneRequested?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
@@ -260,7 +292,11 @@ internal sealed class BrowserWindow : Window
|
||||
// The frame of the window (title bar and borders) around the page and its bar.
|
||||
var frame = SystemParameters.WindowNonClientFrameThickness;
|
||||
var resize = SystemParameters.WindowResizeBorderThickness;
|
||||
var fit = FitFor(area.Width, area.Height, PageWidth, PageHeight, frame.Left + frame.Right + resize.Left + resize.Right, frame.Top + frame.Bottom + resize.Top + resize.Bottom);
|
||||
SetFit(FitFor(area.Width, area.Height, PageWidth, PageHeight, frame.Left + frame.Right + resize.Left + resize.Right, frame.Top + frame.Bottom + resize.Top + resize.Bottom));
|
||||
}
|
||||
|
||||
private void SetFit(double fit)
|
||||
{
|
||||
if (Math.Abs(fit - Fit) < 0.001)
|
||||
{
|
||||
return;
|
||||
@@ -273,6 +309,13 @@ internal sealed class BrowserWindow : Window
|
||||
PageAreaChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
/// <summary>Cloaks or uncloaks the window (DWM); false when DWM refused.</summary>
|
||||
private bool Cloak(bool on)
|
||||
{
|
||||
var value = on ? 1 : 0;
|
||||
return Win32.DwmSetWindowAttribute(Handle, Win32.DwmCloak, ref value, sizeof(int)) == 0;
|
||||
}
|
||||
|
||||
private static Button BarButton(string text, string tip) => new()
|
||||
{
|
||||
Content = text,
|
||||
|
||||
@@ -52,7 +52,7 @@ internal sealed class WebView2Browser : IFebeBrowser
|
||||
_options = new BrowserOptions(ProfileDirectory, settings.Width, settings.Height);
|
||||
Host = new WebView2Host(
|
||||
ui,
|
||||
new WebView2HostOptions(settings.Hosting, settings.AdditionalBrowserArguments, icon, () => context.Tracker.MarkUsed(context.Clock.Now), context.CurrentStartPage),
|
||||
new WebView2HostOptions(settings.Hosting, settings.AdditionalBrowserArguments, icon, () => context.Tracker.MarkUsed(context.Clock.Now), context.OpenStartPage),
|
||||
context.Log);
|
||||
Host.BrowserProcessFailed += (_, _) => RequestRestart(null);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ using Febe.Browser.Hosting;
|
||||
using Febe.Browser.WebView2;
|
||||
using Febe.Core.Abstractions;
|
||||
using Febe.Desktop.Core;
|
||||
using Febe.Desktop.Native;
|
||||
using Microsoft.Web.WebView2.Core;
|
||||
|
||||
namespace Febe.Desktop.Browser;
|
||||
@@ -18,8 +19,11 @@ namespace Febe.Desktop.Browser;
|
||||
/// <param name="AdditionalBrowserArguments">The switches of S2 (<see cref="BrowserArguments.ForWebView2"/>).</param>
|
||||
/// <param name="Icon">The icon of the window.</param>
|
||||
/// <param name="MarkUsed">Called when Alberto uses the browser and when he is done with it («Riprendi»).</param>
|
||||
/// <param name="StartPage">Where «Pagina iniziale» goes: the site's home when connected, the login page otherwise (issue #52).</param>
|
||||
internal sealed record WebView2HostOptions(BrowserHosting Hosting, string AdditionalBrowserArguments, ImageSource? Icon, Action MarkUsed, Func<string>? StartPage = null);
|
||||
/// <param name="OpenStartPage">
|
||||
/// What «Pagina iniziale» does (issue #52): the connection opens the site's home when connected, the login page otherwise,
|
||||
/// once the engine's session ended and with the page's turn. Null: the button does nothing.
|
||||
/// </param>
|
||||
internal sealed record WebView2HostOptions(BrowserHosting Hosting, string AdditionalBrowserArguments, ImageSource? Icon, Action MarkUsed, Func<CancellationToken, Task>? OpenStartPage = null);
|
||||
|
||||
/// <summary>What the host does when a process of WebView2 fails (issue #52).</summary>
|
||||
internal enum ProcessFailureResponse
|
||||
@@ -33,7 +37,7 @@ internal enum ProcessFailureResponse
|
||||
/// <summary>The page crashed (or hangs while nobody looks): back to the rest page (spec §6.1).</summary>
|
||||
Rest,
|
||||
|
||||
/// <summary>The GPU process restarted: the bounds are given again, or the window may stay blank or black.</summary>
|
||||
/// <summary>The GPU process restarted: the page is resized by a pixel and back, or the window may stay blank or black.</summary>
|
||||
Redraw,
|
||||
}
|
||||
|
||||
@@ -179,8 +183,10 @@ internal sealed class WebView2Host : IBrowserHost
|
||||
// The lease first: once the window is on screen the engine must be still, whatever happens to the focus.
|
||||
TakeLease();
|
||||
|
||||
// On screen, perhaps shrunk to fit it: WebView2 gets its bounds again and learns where its window is now.
|
||||
// On screen, perhaps shrunk to fit it: WebView2 gets its bounds again and learns where its window is now, and paints
|
||||
// again (WPF hid and showed the window, out of view, to give it its taskbar button).
|
||||
UpdateBounds();
|
||||
Repaint();
|
||||
try
|
||||
{
|
||||
_controller?.MoveFocus(CoreWebView2MoveFocusReason.Programmatic);
|
||||
@@ -345,7 +351,7 @@ internal sealed class WebView2Host : IBrowserHost
|
||||
window.DoneRequested += (_, _) => Done();
|
||||
window.BackRequested += (_, _) => UserNavigation(core => core.GoBack(), core => core.CanGoBack);
|
||||
window.ReloadRequested += (_, _) => UserNavigation(core => core.Reload(), _ => true);
|
||||
window.HomeRequested += (_, _) => UserNavigation(core => core.Navigate(_settings.StartPage!()), _ => _settings.StartPage is not null);
|
||||
window.HomeRequested += (_, _) => OpenStartPage();
|
||||
window.DpiChanged += (_, _) => UpdateBounds();
|
||||
window.PageAreaChanged += (_, _) => UpdateBounds();
|
||||
|
||||
@@ -508,9 +514,10 @@ internal sealed class WebView2Host : IBrowserHost
|
||||
|
||||
break;
|
||||
case ProcessFailureResponse.Redraw:
|
||||
// A windowed WebView can stay blank or black after the GPU process restarted until its bounds change:
|
||||
// they are given again (never IsVisible = false, S2), once this handler has returned.
|
||||
_ = _ui.InvokeAsync(UpdateBounds, DispatcherPriority.Background);
|
||||
// A windowed WebView can stay blank or black after the GPU process restarted until its size changes: the
|
||||
// same bounds again may be no change at all, so one pixel less and then the real ones (never
|
||||
// IsVisible = false, S2), once this handler has returned.
|
||||
_ = _ui.InvokeAsync(Redraw, DispatcherPriority.Background);
|
||||
break;
|
||||
default:
|
||||
if (kind == CoreWebView2ProcessFailedKind.RenderProcessUnresponsive)
|
||||
@@ -576,6 +583,73 @@ internal sealed class WebView2Host : IBrowserHost
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// «Pagina iniziale»: Alberto's own navigation (rule 7), done by the connection, which first waits for the engine's
|
||||
/// session to end and takes the page's turn (issue #52).
|
||||
/// </summary>
|
||||
private void OpenStartPage()
|
||||
{
|
||||
if (_settings.OpenStartPage is not { } open || _core is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TakeLease();
|
||||
_ = OpenStartPageQuietlyAsync(open);
|
||||
}
|
||||
|
||||
private async Task OpenStartPageQuietlyAsync(Func<CancellationToken, Task> open)
|
||||
{
|
||||
try
|
||||
{
|
||||
await open(CancellationToken.None).ConfigureAwait(true);
|
||||
}
|
||||
catch (Exception ex) when (ex is not OutOfMemoryException)
|
||||
{
|
||||
_log.Warn("browser", $"«Pagina iniziale» non aperta ({ex.GetType().Name}).");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>After a GPU restart: a real change of size (one pixel less), then the real bounds and a repaint.</summary>
|
||||
private void Redraw()
|
||||
{
|
||||
if (_controller is not { } controller || _window is not { } window)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var bounds = window.PageBounds;
|
||||
if (bounds.Height > 1)
|
||||
{
|
||||
controller.Bounds = bounds with { Height = bounds.Height - 1 };
|
||||
}
|
||||
}
|
||||
catch (Exception ex) when (ex is COMException or InvalidOperationException)
|
||||
{
|
||||
// The browser process is gone: the next start sizes the new WebView.
|
||||
return;
|
||||
}
|
||||
|
||||
_ = _ui.InvokeAsync(
|
||||
() =>
|
||||
{
|
||||
UpdateBounds();
|
||||
Repaint();
|
||||
},
|
||||
DispatcherPriority.Background);
|
||||
}
|
||||
|
||||
/// <summary>Asks the window and WebView2's child windows to paint again; nothing the page can see changes.</summary>
|
||||
private void Repaint()
|
||||
{
|
||||
if (_window is { } window)
|
||||
{
|
||||
Win32.RedrawWindow(window.Handle, IntPtr.Zero, IntPtr.Zero, Win32.RdwInvalidate | Win32.RdwAllChildren | Win32.RdwUpdateNow);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateBounds()
|
||||
{
|
||||
if (_controller is not { } controller || _window is not { } window)
|
||||
|
||||
Reference in new issue
Block a user