Web source: geometry-agnostic viewport==box model — viewport locked to element box, Stretch=Fill, no dead space

This commit is contained in:
2026-08-28 10:48:53 -07:00
parent 9d4103c44b
commit 8d793af91a
5 changed files with 121 additions and 82 deletions
+53 -25
View File
@@ -20,29 +20,7 @@ public sealed class WebView2ManagerTests
}
[Fact]
public void WebView2_Control_Size_Is_Fixed_At_Canvas_Resolution()
{
_app.Run(() =>
{
var panel = new Canvas();
var source = new Source
{
Type = SourceType.WebSource,
Width = 640,
Height = 480,
};
using var manager = new WebView2Manager(panel, Dispatcher.CurrentDispatcher);
manager.Register(source);
var webView = panel.Children.OfType<WebView2>().First();
Assert.Equal(1920.0, webView.Width);
Assert.Equal(1080.0, webView.Height);
});
}
[Fact]
public void WebView2_Control_Size_Does_Not_Track_Source_Dimensions()
public void WebView2_Control_Size_Tracks_Source_Dimensions()
{
_app.Run(() =>
{
@@ -58,12 +36,62 @@ public sealed class WebView2ManagerTests
manager.Register(source);
var webView = panel.Children.OfType<WebView2>().First();
Assert.Equal(640.0, webView.Width);
Assert.Equal(480.0, webView.Height);
source.Width = 1024;
source.Height = 768;
Assert.Equal(1920.0, webView.Width);
Assert.Equal(1080.0, webView.Height);
Assert.Equal(1024.0, webView.Width);
Assert.Equal(768.0, webView.Height);
});
}
[Fact]
public void WebView2_Control_Size_Ignores_Sub_One_Pixel_Drift()
{
_app.Run(() =>
{
var panel = new Canvas();
var source = new Source
{
Type = SourceType.WebSource,
Width = 640,
Height = 480,
};
using var manager = new WebView2Manager(panel, Dispatcher.CurrentDispatcher);
manager.Register(source);
var webView = panel.Children.OfType<WebView2>().First();
source.Width = 640.4;
Assert.Equal(640.0, webView.Width);
source.Height = 480.4;
Assert.Equal(480.0, webView.Height);
});
}
[Fact]
public void WebView2_Control_Size_Minimum_Is_One()
{
_app.Run(() =>
{
var panel = new Canvas();
var source = new Source
{
Type = SourceType.WebSource,
Width = 0,
Height = 0,
};
using var manager = new WebView2Manager(panel, Dispatcher.CurrentDispatcher);
manager.Register(source);
var webView = panel.Children.OfType<WebView2>().First();
Assert.Equal(1.0, webView.Width);
Assert.Equal(1.0, webView.Height);
});
}