Skip to content

Commit

Permalink
fix: Only check Background on specific elements when hit-testing
Browse files Browse the repository at this point in the history
Align with WinUI, where the presence of a non-null Background only causes a hit-test to pass when it's set on Border, Panel, or ContentPresenter.

In particular this means that Controls with Background set will not themselves intercept pointer events; only elements within their templates will intercept pointers.
  • Loading branch information
davidjohnoliver committed Dec 14, 2021
1 parent 00fc1e3 commit c42f52c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
13 changes: 13 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/Border/Border.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
using Color = System.Drawing.Color;
using View = Windows.UI.Xaml.UIElement;
#endif
using _Debug = System.Diagnostics.Debug;

namespace Windows.UI.Xaml.Controls
{
Expand Down Expand Up @@ -296,5 +297,17 @@ protected virtual void OnBorderBrushChanged(Brush oldValue, Brush newValue)
#endregion

internal override bool CanHaveChildren() => true;

internal override bool IsViewHit() => IsViewHitImpl(this);

internal static bool IsViewHitImpl(FrameworkElement element)
{
_Debug.Assert(element is Panel
|| element is Border
|| element is ContentPresenter
);

return element.Background != null;
}
}
}
2 changes: 0 additions & 2 deletions src/Uno.UI/UI/Xaml/Controls/Border/Border.skia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ protected override void OnBackgroundChanged(DependencyPropertyChangedEventArgs a
UpdateBorder();
}

internal override bool IsViewHit()
=> Background != null || base.IsViewHit();
bool ICustomClippingElement.AllowClippingToLayoutSlot => !(Child is UIElement ue) || ue.RenderTransform == null;
bool ICustomClippingElement.ForceClippingToLayoutSlot => CornerRadius != CornerRadius.None;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1102,5 +1102,7 @@ protected override Size MeasureOverride(Size size)
private protected override Thickness GetBorderThickness() => BorderThickness;

internal override bool CanHaveChildren() => true;

internal override bool IsViewHit() => Border.IsViewHitImpl(this);
}
}
1 change: 1 addition & 0 deletions src/Uno.UI/UI/Xaml/Controls/Panel/Panel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,6 @@ private protected void OnBackgroundSizingChangedInnerPanel(DependencyPropertyCha

partial void UpdateBorder();

internal override bool IsViewHit() => Border.IsViewHitImpl(this);
}
}
3 changes: 1 addition & 2 deletions src/Uno.UI/UI/Xaml/FrameworkElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,7 @@ private bool IsHeightConstrained(View requester)
return this.IsHeightConstrainedSimple();
}

internal override bool IsViewHit()
=> Background != null;
internal override bool IsViewHit() => false;

/// <summary>
/// The list of available children render phases, if this
Expand Down

0 comments on commit c42f52c

Please sign in to comment.