Skip to content

Commit

Permalink
chore: add a UNO_HAS_BORDER_VISUAL flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ramezgerges committed May 16, 2024
1 parent 9707b7a commit f32e017
Show file tree
Hide file tree
Showing 17 changed files with 60 additions and 56 deletions.
2 changes: 1 addition & 1 deletion src/Uno.CrossTargetting.targets
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
</PropertyGroup>

<PropertyGroup Condition="'$(UnoRuntimeIdentifier)'=='Skia'">
<DefineConstants>$(DefineConstants);__SKIA__;UNO_HAS_ENHANCED_HIT_TEST_PROPERTY;UNO_HAS_MANAGED_SCROLL_PRESENTER;UNO_HAS_MANAGED_POINTERS;SUPPORTS_RTL;UNO_HAS_ENHANCED_LIFECYCLE</DefineConstants>
<DefineConstants>$(DefineConstants);__SKIA__;UNO_HAS_ENHANCED_HIT_TEST_PROPERTY;UNO_HAS_MANAGED_SCROLL_PRESENTER;UNO_HAS_MANAGED_POINTERS;SUPPORTS_RTL;UNO_HAS_ENHANCED_LIFECYCLE;UNO_HAS_BORDER_VISUAL</DefineConstants>
<DefineConstants>$(DefineConstants);UNO_SUPPORTS_NATIVEHOST;HAS_INPUT_INJECTOR</DefineConstants>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if __SKIA__
using System;
using System;
using Microsoft.UI.Composition;
using Microsoft.UI.Xaml.Media;
using Uno.Disposables;
Expand All @@ -9,18 +8,18 @@ namespace Microsoft.UI.Xaml.Controls.Primitives;

partial class ScrollPresenter : IBorderInfoProvider
{
#if !__SKIA__
#if !UNO_HAS_BORDER_VISUAL
private BorderLayerRenderer _borderRenderer;
#endif

#if !__SKIA__
#if !UNO_HAS_BORDER_VISUAL
partial void InitializePartial()
{
_borderRenderer = new BorderLayerRenderer(this);
}
#endif

#if __SKIA__
#if UNO_HAS_BORDER_VISUAL
private protected override ShapeVisual CreateElementVisual() => Compositor.GetSharedCompositor().CreateBorderVisual();
#endif

Expand All @@ -34,11 +33,10 @@ partial class ScrollPresenter : IBorderInfoProvider

CornerRadius IBorderInfoProvider.CornerRadius => default;

#if __SKIA__
#if UNO_HAS_BORDER_VISUAL
BorderVisual IBorderInfoProvider.BorderVisual => Visual as BorderVisual ?? throw new InvalidCastException($"{nameof(IBorderInfoProvider)}s should use a {nameof(BorderVisual)}.");

SerialDisposable IBorderInfoProvider.BorderBrushSubscriptionDisposable { get; set; } = new();
SerialDisposable IBorderInfoProvider.BackgroundBrushSubscriptionDisposable { get; set; } = new();
#endif
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -3685,8 +3685,10 @@ internal SnapPointWrapper<ZoomSnapPointBase> GetZoomSnapPointWrapper(ZoomSnapPoi
// So, they can just cast ScrollPresenter to Panel and set the Background.
// In our case, we can't do that as there is no multi inheritance in C#.
// We use BorderLayerRenderer to draw the background.
#if __SKIA__
#if UNO_HAS_BORDER_VISUAL
this.UpdateBackground();
#else
_borderRenderer.Update();
#endif

//Panel thisAsPanel = this;
Expand Down
2 changes: 2 additions & 0 deletions src/Uno.UI/UI/Xaml/BorderHelper.skia.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if UNO_HAS_BORDER_VISUAL
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
using Uno.UI.Xaml.Controls;
Expand Down Expand Up @@ -45,3 +46,4 @@ public static void UpdateAllBorderProperties(this IBorderInfoProvider @this)
@this.UpdateBorderThickness();
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ partial class Border : IBorderInfoProvider

CornerRadius IBorderInfoProvider.CornerRadius => CornerRadius;

#if __SKIA__
#if UNO_HAS_BORDER_VISUAL
BorderVisual IBorderInfoProvider.BorderVisual => Visual as BorderVisual ?? throw new InvalidCastException($"{nameof(IBorderInfoProvider)}s should use a {nameof(BorderVisual)}.");

SerialDisposable IBorderInfoProvider.BorderBrushSubscriptionDisposable { get; set; } = new();
Expand Down
20 changes: 10 additions & 10 deletions src/Uno.UI/UI/Xaml/Controls/Border/Border.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ namespace Microsoft.UI.Xaml.Controls
[ContentProperty(Name = nameof(Child))]
public partial class Border : FrameworkElement
{
#if !__SKIA__
#if !UNO_HAS_BORDER_VISUAL
private readonly BorderLayerRenderer _borderRenderer;
#endif

public Border()
{
#if !__SKIA__
#if !UNO_HAS_BORDER_VISUAL
_borderRenderer = new BorderLayerRenderer(this);
#endif
}

#if __SKIA__
#if UNO_HAS_BORDER_VISUAL
private protected override ShapeVisual CreateElementVisual() => Compositor.GetSharedCompositor().CreateBorderVisual();
#endif

Expand Down Expand Up @@ -124,7 +124,7 @@ public CornerRadius CornerRadius

private void OnCornerRadiusChanged(CornerRadius oldValue, CornerRadius newValue)
{
#if __SKIA__
#if UNO_HAS_BORDER_VISUAL
this.UpdateCornerRadius();
#else
UpdateBorder();
Expand Down Expand Up @@ -193,7 +193,7 @@ public Thickness Padding

private void OnPaddingChanged(Thickness oldValue, Thickness newValue)
{
#if __SKIA__
#if UNO_HAS_BORDER_VISUAL
// TODO: https://github.com/unoplatform/uno/issues/16705
#else
UpdateBorder();
Expand All @@ -213,7 +213,7 @@ public BackgroundSizing BackgroundSizing
}
private void OnBackgroundSizingChanged(DependencyPropertyChangedEventArgs e)
{
#if __SKIA__
#if UNO_HAS_BORDER_VISUAL
this.UpdateBackgroundSizing();
#else
UpdateBorder();
Expand All @@ -236,7 +236,7 @@ public Thickness BorderThickness

private void OnBorderThicknessChanged(Thickness oldValue, Thickness newValue)
{
#if __SKIA__
#if UNO_HAS_BORDER_VISUAL
this.UpdateBorderThickness();
#else
UpdateBorder();
Expand Down Expand Up @@ -276,7 +276,7 @@ private void OnBorderBrushChanged(Brush oldValue, Brush newValue)
{
Brush.SetupBrushChanged(oldValue, newValue, ref _borderBrushChanged, _borderBrushChanged ?? (() =>
{
#if __SKIA__
#if UNO_HAS_BORDER_VISUAL
this.UpdateBorderBrush();
#else
UpdateBorder();
Expand All @@ -295,7 +295,7 @@ private void OnBorderBrushChanged(Brush oldValue, Brush newValue)

protected override void OnBackgroundChanged(DependencyPropertyChangedEventArgs e)
{
#if __SKIA__
#if UNO_HAS_BORDER_VISUAL
this.UpdateBackground();
#else
UpdateBorder();
Expand All @@ -319,7 +319,7 @@ internal static bool IsViewHitImpl(FrameworkElement element)
return element.Background != null;
}

#if !__SKIA__
#if !UNO_HAS_BORDER_VISUAL
private void UpdateBorder()
{
_borderRenderer.Update();
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Controls/Border/BorderLayerRenderer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !__SKIA__
#if !UNO_HAS_BORDER_VISUAL
using System;
using Microsoft.UI.Xaml;
using Uno.Disposables;
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Controls/Border/IBorderInfoProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal partial interface IBorderInfoProvider
/// </summary>
CornerRadius CornerRadius { get; }

#if __SKIA__
#if UNO_HAS_BORDER_VISUAL
BorderVisual BorderVisual { get; }

SerialDisposable BorderBrushSubscriptionDisposable { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Brush IBorderInfoProvider.BorderBrush

CornerRadius IBorderInfoProvider.CornerRadius => GetItemCornerRadius();

#if __SKIA__
#if UNO_HAS_BORDER_VISUAL
BorderVisual IBorderInfoProvider.BorderVisual => Visual as BorderVisual ?? throw new InvalidCastException($"{nameof(IBorderInfoProvider)}s should use a {nameof(BorderVisual)}.");

SerialDisposable IBorderInfoProvider.BorderBrushSubscriptionDisposable { get; set; } = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public partial class CalendarViewBaseItem : Control
#if !__NETSTD_REFERENCE__
this.Loaded += (_, _) =>
{
#if !__SKIA__
#if !UNO_HAS_BORDER_VISUAL
_borderRenderer ??= new(this);
#endif
#if !UNO_HAS_ENHANCED_LIFECYCLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.UI.Xaml.Controls
{
partial class CalendarViewBaseItem
{
#if !__SKIA__
#if !UNO_HAS_BORDER_VISUAL
private BorderLayerRenderer _borderRenderer;
#endif

Expand Down Expand Up @@ -54,7 +54,9 @@ internal override void OnArrangeVisual(Rect rect, Rect? clip)

base.OnArrangeVisual(rect, clip);
}
#endif

#if UNO_HAS_BORDER_VISUAL
private protected override ShapeVisual CreateElementVisual() => Compositor.GetSharedCompositor().CreateBorderVisual();
#endif

Expand All @@ -69,7 +71,7 @@ private void UpdateChromeIfNeeded(Rect rect)

private void UpdateChrome()
{
#if !__SKIA__
#if !UNO_HAS_BORDER_VISUAL
_borderRenderer ??= new BorderLayerRenderer(this);
#endif

Expand All @@ -94,7 +96,7 @@ private void UpdateChrome()
}
#endif

#if __SKIA__
#if UNO_HAS_BORDER_VISUAL
this.UpdateAllBorderProperties();
#else
_borderRenderer.Update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ partial class ContentPresenter : IBorderInfoProvider

CornerRadius IBorderInfoProvider.CornerRadius => CornerRadius;

#if __SKIA__
#if UNO_HAS_BORDER_VISUAL
BorderVisual IBorderInfoProvider.BorderVisual => Visual as BorderVisual ?? throw new InvalidCastException($"{nameof(IBorderInfoProvider)}s should use a {nameof(BorderVisual)}.");

SerialDisposable IBorderInfoProvider.BorderBrushSubscriptionDisposable { get; set; } = new();
Expand Down
22 changes: 11 additions & 11 deletions src/Uno.UI/UI/Xaml/Controls/ContentPresenter/ContentPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public partial class ContentPresenter : FrameworkElement, IFrameworkTemplatePool
, ICustomClippingElement
#endif
{
#if !__SKIA__
#if !UNO_HAS_BORDER_VISUAL
private readonly BorderLayerRenderer _borderRenderer;
#endif

Expand All @@ -71,15 +71,15 @@ public partial class ContentPresenter : FrameworkElement, IFrameworkTemplatePool

public ContentPresenter()
{
#if !__SKIA__
#if !UNO_HAS_BORDER_VISUAL
_borderRenderer = new BorderLayerRenderer(this);
#endif
SetDefaultForeground(ForegroundProperty);

InitializePlatform();
}

#if __SKIA__
#if UNO_HAS_BORDER_VISUAL
private protected override ShapeVisual CreateElementVisual() => Compositor.GetSharedCompositor().CreateBorderVisual();
#endif

Expand Down Expand Up @@ -205,7 +205,7 @@ public BackgroundSizing BackgroundSizing
}
private void OnBackgroundSizingChanged(DependencyPropertyChangedEventArgs e)
{
#if __SKIA__
#if UNO_HAS_BORDER_VISUAL
this.UpdateBackgroundSizing();
#else
UpdateBorder();
Expand Down Expand Up @@ -523,7 +523,7 @@ public Thickness Padding

private void OnPaddingChanged(Thickness oldValue, Thickness newValue)
{
#if __SKIA__
#if UNO_HAS_BORDER_VISUAL
// TODO: https://github.com/unoplatform/uno/issues/16705
#else
UpdateBorder();
Expand Down Expand Up @@ -554,7 +554,7 @@ public Thickness BorderThickness

private void OnBorderThicknessChanged(Thickness oldValue, Thickness newValue)
{
#if __SKIA__
#if UNO_HAS_BORDER_VISUAL
this.UpdateBorderThickness();
#else
UpdateBorder();
Expand Down Expand Up @@ -591,7 +591,7 @@ private void OnBorderBrushChanged(Brush oldValue, Brush newValue)
(Content as UIElement)?.InvalidateArrange();
}
#endif
#if __SKIA__
#if UNO_HAS_BORDER_VISUAL
this.UpdateBorderBrush();
#else
UpdateBorder();
Expand All @@ -615,7 +615,7 @@ public CornerRadius CornerRadius

private void OnCornerRadiusChanged(CornerRadius oldValue, CornerRadius newValue)
{
#if __SKIA__
#if UNO_HAS_BORDER_VISUAL
this.UpdateCornerRadius();
#else
UpdateBorder();
Expand Down Expand Up @@ -848,7 +848,7 @@ internal override void Enter(EnterParams @params, int depth)
// as it may have been reset during the last unload.
SynchronizeContentTemplatedParent();

#if !__SKIA__
#if !UNO_HAS_BORDER_VISUAL
UpdateBorder();
#endif

Expand Down Expand Up @@ -1062,7 +1062,7 @@ void ClearImplicitBindinds()
/// </remarks>
protected override void OnBackgroundChanged(DependencyPropertyChangedEventArgs e)
{
#if __SKIA__
#if UNO_HAS_BORDER_VISUAL
this.UpdateBackground();
#else
UpdateBorder();
Expand Down Expand Up @@ -1236,7 +1236,7 @@ protected override Size MeasureOverride(Size size)
/// </summary>
partial void ArrangeNativeElement(Rect arrangeRect);

#if !__SKIA__
#if !UNO_HAS_BORDER_VISUAL
private void UpdateBorder() => _borderRenderer.Update();
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public partial class Page : IBorderInfoProvider

CornerRadius IBorderInfoProvider.CornerRadius => CornerRadius.None;

#if __SKIA__
#if UNO_HAS_BORDER_VISUAL
BorderVisual IBorderInfoProvider.BorderVisual => Visual as BorderVisual ?? throw new InvalidCastException($"{nameof(IBorderInfoProvider)}s should use a {nameof(BorderVisual)}.");

SerialDisposable IBorderInfoProvider.BorderBrushSubscriptionDisposable { get; set; } = new();
Expand Down
10 changes: 5 additions & 5 deletions src/Uno.UI/UI/Xaml/Controls/Page/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ namespace Microsoft.UI.Xaml.Controls;

public partial class Page : UserControl
{
#if !__SKIA__
#if !UNO_HAS_BORDER_VISUAL
private readonly BorderLayerRenderer _borderRenderer;
#endif

public Page()
{
#if !__SKIA__
#if !UNO_HAS_BORDER_VISUAL
_borderRenderer = new BorderLayerRenderer(this);
#endif
}

#if __SKIA__
#if UNO_HAS_BORDER_VISUAL
private protected override ShapeVisual CreateElementVisual() => Compositor.GetSharedCompositor().CreateBorderVisual();
#endif

#if !__SKIA__
#if !UNO_HAS_BORDER_VISUAL
private void UpdateBorder()
{
_borderRenderer.Update();
Expand Down Expand Up @@ -109,7 +109,7 @@ Frame Frame

protected override void OnBackgroundChanged(DependencyPropertyChangedEventArgs e)
{
#if __SKIA__
#if UNO_HAS_BORDER_VISUAL
this.UpdateBackground();
#else
UpdateBorder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ partial class Panel : IBorderInfoProvider

CornerRadius IBorderInfoProvider.CornerRadius => CornerRadiusInternal;

#if __SKIA__
#if UNO_HAS_BORDER_VISUAL
BorderVisual IBorderInfoProvider.BorderVisual => Visual as BorderVisual ?? throw new InvalidCastException($"{nameof(IBorderInfoProvider)}s should use a {nameof(BorderVisual)}.");

SerialDisposable IBorderInfoProvider.BorderBrushSubscriptionDisposable { get; set; } = new();
Expand Down

0 comments on commit f32e017

Please sign in to comment.