From 05dffe75fdcc44bab567db72269437981ba63fe8 Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Wed, 3 Apr 2024 14:59:33 +0200 Subject: [PATCH] feat: Add basic support for ContentSite and ContentSiteView --- .../Microsoft.UI.Content/ContentSite.cs | 14 +++---- .../Microsoft.UI.Content/ContentSiteView.cs | 12 +++--- src/Uno.UI/UI/Content/ContentIsland.cs | 11 ++--- src/Uno.UI/UI/Content/ContentSite.cs | 39 ++++++++++++++++++ src/Uno.UI/UI/Content/ContentSiteView.cs | 41 +++++++++++++++++++ .../ContentManager/IContentHost.skia.cs | 6 --- 6 files changed, 99 insertions(+), 24 deletions(-) create mode 100644 src/Uno.UI/UI/Content/ContentSite.cs create mode 100644 src/Uno.UI/UI/Content/ContentSiteView.cs delete mode 100644 src/Uno.UI/UI/Xaml/Internal/ContentManager/IContentHost.skia.cs diff --git a/src/Uno.UI/Generated/3.0.0.0/Microsoft.UI.Content/ContentSite.cs b/src/Uno.UI/Generated/3.0.0.0/Microsoft.UI.Content/ContentSite.cs index 9ad0e99c1f6c..b5fc68c7a8a5 100644 --- a/src/Uno.UI/Generated/3.0.0.0/Microsoft.UI.Content/ContentSite.cs +++ b/src/Uno.UI/Generated/3.0.0.0/Microsoft.UI.Content/ContentSite.cs @@ -3,12 +3,12 @@ #pragma warning disable 114 // new keyword hiding namespace Microsoft.UI.Content { -#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__ +#if false [global::Uno.NotImplemented] #endif public partial class ContentSite : global::System.IDisposable, global::Microsoft.UI.IClosableNotifier { -#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__ +#if false internal ContentSite() { } @@ -27,7 +27,7 @@ public bool ShouldApplyRasterizationScale } } #endif -#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__ +#if false [global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")] public float ParentScale { @@ -41,7 +41,7 @@ public float ParentScale } } #endif -#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__ +#if false [global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")] public float OverrideScale { @@ -69,7 +69,7 @@ public float OverrideScale } } #endif -#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__ +#if false [global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")] public bool IsSiteVisible { @@ -165,7 +165,7 @@ public bool IsConnected } } #endif -#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__ +#if false [global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")] public float RasterizationScale { @@ -185,7 +185,7 @@ public float RasterizationScale } } #endif -#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__ +#if false [global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")] public global::Microsoft.UI.Content.ContentSiteView View { diff --git a/src/Uno.UI/Generated/3.0.0.0/Microsoft.UI.Content/ContentSiteView.cs b/src/Uno.UI/Generated/3.0.0.0/Microsoft.UI.Content/ContentSiteView.cs index 42e9645eac6e..8f814aa5dc83 100644 --- a/src/Uno.UI/Generated/3.0.0.0/Microsoft.UI.Content/ContentSiteView.cs +++ b/src/Uno.UI/Generated/3.0.0.0/Microsoft.UI.Content/ContentSiteView.cs @@ -3,12 +3,12 @@ #pragma warning disable 114 // new keyword hiding namespace Microsoft.UI.Content { -#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__ +#if false [global::Uno.NotImplemented] #endif public partial class ContentSiteView { -#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__ +#if false internal ContentSiteView() { } @@ -83,7 +83,7 @@ public bool IsSiteEnabled } } #endif -#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__ +#if false [global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")] public bool IsSiteVisible { @@ -103,7 +103,7 @@ public bool IsSiteVisible } } #endif -#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__ +#if false [global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")] public float OverrideScale { @@ -113,7 +113,7 @@ public float OverrideScale } } #endif -#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__ +#if false [global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")] public float ParentScale { @@ -123,7 +123,7 @@ public float ParentScale } } #endif -#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__ +#if false [global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")] public float RasterizationScale { diff --git a/src/Uno.UI/UI/Content/ContentIsland.cs b/src/Uno.UI/UI/Content/ContentIsland.cs index 9ab975d03085..d73daf2e33a9 100644 --- a/src/Uno.UI/UI/Content/ContentIsland.cs +++ b/src/Uno.UI/UI/Content/ContentIsland.cs @@ -2,6 +2,7 @@ using Microsoft.UI; using Microsoft.UI.Composition; using Uno; +using Uno.UI.Content; using Uno.UI.Hosting; using Uno.UI.Xaml.Controls; using Windows.Foundation; @@ -16,22 +17,22 @@ public partial class ContentIsland : IDisposable, IClosableNotifier, ICompositionSupportsSystemBackdrop #endif { - private readonly INativeWindowWrapper _nativeWindowWrapper; + private readonly ContentSiteView _contentSiteView; - internal ContentIsland(INativeWindowWrapper nativeWindowWrapper) + internal ContentIsland(ContentSiteView contentSiteView) { - _nativeWindowWrapper = nativeWindowWrapper; + _contentSiteView = contentSiteView ?? throw new ArgumentNullException(nameof(contentSiteView)); } /// /// Gets the local dots per inch (dpi) of a Microsoft.UI.Composition.ICompositionSurface. /// - public float RasterizationScale => _nativeWindowWrapper.RasterizationScale; + public float RasterizationScale => _contentSiteView.RasterizationScale; /// /// Gets whether the associated ContentSite is visible. /// - public bool IsSiteVisible => _nativeWindowWrapper.Visible; + public bool IsSiteVisible => _contentSiteView.IsSiteVisible; /// /// Occurs when a state property for this ContentIsland changes. diff --git a/src/Uno.UI/UI/Content/ContentSite.cs b/src/Uno.UI/UI/Content/ContentSite.cs new file mode 100644 index 000000000000..887f7d8bee46 --- /dev/null +++ b/src/Uno.UI/UI/Content/ContentSite.cs @@ -0,0 +1,39 @@ +using System; + +namespace Microsoft.UI.Content; + +/// +/// Provides a host environment for a ContentIsland. +/// +public partial class ContentSite +#if HAS_UNO_WINUI // These interfaces are not currently implemented and the Generated partial does not exist in UWP build. + : IDisposable, IClosableNotifier +#endif +{ + internal ContentSite() => View = new(this); + + /// + /// Gets or sets whether this ContentSite is visible. + /// + public bool IsSiteVisible { get; set; } + + /// + /// Gets or sets the parent default scaling factor for this ContentSite. + /// + public float ParentScale { get; set; } = 1f; + + /// + /// Gets or sets the scaling factor to use for this ContentSite, which overrides the ParentScale. + /// + public float OverrideScale { get; set; } = 1f; + + /// + /// Gets the computed local DPI for this ContentSite. + /// + public float RasterizationScale => OverrideScale * ParentScale; + + /// + /// Gets the ContentSiteView associated with this ContentSite. + /// + public ContentSiteView View { get; } +} diff --git a/src/Uno.UI/UI/Content/ContentSiteView.cs b/src/Uno.UI/UI/Content/ContentSiteView.cs new file mode 100644 index 000000000000..6c18e8d244e2 --- /dev/null +++ b/src/Uno.UI/UI/Content/ContentSiteView.cs @@ -0,0 +1,41 @@ +using System; + +namespace Microsoft.UI.Content; + +/// +/// Provides access to a read-only view of ContentSite properties. +/// +/// +/// This object exposes the most recent values from a ContentSite, +/// it is not a snapshot in time. +/// +public partial class ContentSiteView +{ + private readonly ContentSite _contentSite; + + internal ContentSiteView(ContentSite contentSite) + { + _contentSite = contentSite ?? throw new ArgumentNullException(nameof(contentSite)); + } + + /// + /// Gets the IsSiteVisible state reported by the ContentSite. + /// + public bool IsSiteVisible => _contentSite.IsSiteVisible; + + /// + /// Gets the default scaling factor of the parent for a single ContentSite. + /// + public float ParentScale => _contentSite.ParentScale; + + /// + /// Gets the override scaling factor for a single ContentSite, ignoring the default scaling factor of the parent. + /// + public float OverrideScale => _contentSite.OverrideScale; + + /// + /// Gets the computed local DPI for the associated ContentSite, + /// which is computed from the OverrideScale and ParentScale. + /// + public float RasterizationScale => _contentSite.RasterizationScale; +} diff --git a/src/Uno.UI/UI/Xaml/Internal/ContentManager/IContentHost.skia.cs b/src/Uno.UI/UI/Xaml/Internal/ContentManager/IContentHost.skia.cs deleted file mode 100644 index 16e09b0b988c..000000000000 --- a/src/Uno.UI/UI/Xaml/Internal/ContentManager/IContentHost.skia.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Uno.UI.Xaml.Controls; - -internal interface IContentHost -{ - bool IsInitialized { get; } -}