Skip to content

Commit

Permalink
fix: Properly override ProcessCandidateTabStopOverride in CalendarView
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Aug 23, 2023
1 parent 0f19751 commit ec72d6c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Windows.UI.Xaml.Input;
using DirectUI;
using DateTime = System.DateTimeOffset;
using Uno.UI.Xaml.Input;

namespace Windows.UI.Xaml.Controls
{
Expand Down Expand Up @@ -368,23 +369,20 @@ private void FocusItem(
return;
}

#if false
// UIElement override for getting next tab stop on path from focus candidate element to root.
private void ProcessCandidateTabStopOverride(
DependencyObject pFocusedElement,
DependencyObject pCandidateTabStopElement,
DependencyObject pOverriddenCandidateTabStopElement,
bool isBackward,
out DependencyObject ppNewTabStop,
out bool pIsCandidateTabStopOverridden)
internal override TabStopProcessingResult ProcessCandidateTabStopOverride(
DependencyObject focusedElement,
DependencyObject candidateTabStopElement,
DependencyObject overriddenCandidateTabStopElement,
bool isBackward)
{
// There is no ICalendarViewBaseItem interface so we can't use ctl.is to check an element is CalendarViewBaseItem or not
// because in ctl.is, it will call ReleaseInterface and CalendarViewBaseItem has multiple interfaces.
// ComPtr will do this in a smarter way - it always casts to IUnknown before release/addso there is no ambiguity.
CalendarViewBaseItem spCandidateAsCalendarViewBaseItem = pCandidateTabStopElement as CalendarViewBaseItem;
CalendarViewBaseItem spCandidateAsCalendarViewBaseItem = candidateTabStopElement as CalendarViewBaseItem;

ppNewTabStop = null;
pIsCandidateTabStopOverridden = false;
DependencyObject newTabStop = null;
var isCandidateTabStopOverridden = false;

// Check if the candidate is a calendaritem and the currently focused is not a calendaritem.
// Which means we Tab (or shift+Tab) into the scrollviewer and we are going to put focus on the candidate.
Expand All @@ -393,7 +391,7 @@ private void ProcessCandidateTabStopOverride(

if (spCandidateAsCalendarViewBaseItem is { })
{
CalendarViewBaseItem spFocusedAsCalendarViewBaseItem = pFocusedElement as CalendarViewBaseItem;
CalendarViewBaseItem spFocusedAsCalendarViewBaseItem = focusedElement as CalendarViewBaseItem;
if (spFocusedAsCalendarViewBaseItem is null)
{
CalendarViewGeneratorHost spHost;
Expand All @@ -409,24 +407,21 @@ private void ProcessCandidateTabStopOverride(
// For other modes (Local or Cycle) we don't want to override.
if (mode == KeyboardNavigationMode.Once)
{
bool isAncestor = false;

// Are we tabbing from/to another view?
// if developer makes other view focusable by re-template and the candidate is not
// in the active view, we'll not override the candidate.
isAncestor = pScrollViewer.IsAncestorOf(pCandidateTabStopElement);
var isAncestor = pScrollViewer.IsAncestorOf(candidateTabStopElement);

if (isAncestor)
{
var pPanel = spHost.Panel;
if (pPanel is { })
{
int index = -1;
DependencyObject spContainer;
//CalendarViewGeneratorHost spHost;
GetActiveGeneratorHost(out spHost);

index = spHost.CalculateOffsetFromMinDate(m_lastDisplayedDate);
var index = spHost.CalculateOffsetFromMinDate(m_lastDisplayedDate);

// This container might not have focus so it could be recycled, bring
// it into view so it can take focus.
Expand All @@ -440,16 +435,16 @@ private void ProcessCandidateTabStopOverride(

global::System.Diagnostics.Debug.Assert(spContainer is { });

ppNewTabStop = spContainer;
pIsCandidateTabStopOverridden = true;
newTabStop = spContainer;
isCandidateTabStopOverridden = true;
}
}
}
}
}
}

return new(isCandidateTabStopOverridden, newTabStop);
}
#endif
}
}
15 changes: 10 additions & 5 deletions src/Uno.UI/UI/Xaml/Input/Internal/TabStopProcessingResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

using Windows.UI.Xaml;

namespace Uno.UI.Xaml.Input
namespace Uno.UI.Xaml.Input;

internal struct TabStopProcessingResult
{
internal struct TabStopProcessingResult
public TabStopProcessingResult(bool isOverriden, DependencyObject? newTabStop)
{
public DependencyObject? NewTabStop { get; set; }

public bool IsOverriden { get; set; }
IsOverriden = isOverriden;
NewTabStop = newTabStop;
}

public bool IsOverriden { get; set; }

public DependencyObject? NewTabStop { get; set; }
}

0 comments on commit ec72d6c

Please sign in to comment.