View.Navigation.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. #nullable enable
  2. using System.Diagnostics;
  3. namespace Terminal.Gui;
  4. public partial class View // Focus and cross-view navigation management (TabStop, TabIndex, etc...)
  5. {
  6. private bool _canFocus;
  7. /// <summary>
  8. /// Advances the focus to the next or previous view in the focus chain, based on
  9. /// <paramref name="direction"/>.
  10. /// itself.
  11. /// </summary>
  12. /// <remarks>
  13. /// <para>
  14. /// If there is no next/previous view, the focus is set to the view itself.
  15. /// </para>
  16. /// </remarks>
  17. /// <param name="direction"></param>
  18. /// <param name="behavior"></param>
  19. /// <returns>
  20. /// <see langword="true"/> if focus was changed to another subview (or stayed on this one), <see langword="false"/>
  21. /// otherwise.
  22. /// </returns>
  23. public bool AdvanceFocus (NavigationDirection direction, TabBehavior? behavior)
  24. {
  25. if (!CanBeVisible (this)) // TODO: is this check needed?
  26. {
  27. return false;
  28. }
  29. View? focused = Focused;
  30. if (focused is { } && focused.AdvanceFocus (direction, behavior))
  31. {
  32. return true;
  33. }
  34. View [] index = GetSubviewFocusChain (direction, behavior);
  35. if (index.Length == 0)
  36. {
  37. return false;
  38. }
  39. int focusedIndex = index.IndexOf (Focused); // Will return -1 if Focused can't be found or is null
  40. var next = 0;
  41. if (focusedIndex < index.Length - 1)
  42. {
  43. // We're moving w/in the subviews
  44. next = focusedIndex + 1;
  45. }
  46. else
  47. {
  48. // We're moving beyond the last subview
  49. // Determine if focus should remain in this focus chain, or move to the superview's focus chain
  50. //// - If we are TabStop and our SuperView is TabStop move to superview's focus chain
  51. //if (TabStop == TabBehavior.TabStop && SuperView is { TabStop: TabBehavior.TabStop })
  52. //{
  53. // return false;
  54. //}
  55. // - If we are TabStop and our SuperView has at least one other TabStop subview, move to the SuperView's chain
  56. if (TabStop == TabBehavior.TabStop && SuperView is { } && SuperView.GetSubviewFocusChain (direction, behavior).Length > 1)
  57. {
  58. return false;
  59. }
  60. // - If we are TabGrup and our SuperView has at least one other TabGroup subview, move to the SuperView's chain
  61. if (TabStop == TabBehavior.TabGroup && SuperView is { TabStop: TabBehavior.TabGroup })
  62. {
  63. if (behavior == TabBehavior.TabGroup)
  64. {
  65. // Wrap to first focusable views
  66. // BUGBUG: This should do a Restore Focus instead
  67. index = GetSubviewFocusChain (direction, null);
  68. }
  69. }
  70. }
  71. View view = index [next];
  72. if (view.HasFocus)
  73. {
  74. // We could not advance
  75. return view == this;
  76. }
  77. // The subview does not have focus, but at least one other that can. Can this one be focused?
  78. (bool focusSet, bool _) = view.SetHasFocusTrue (Focused);
  79. return focusSet;
  80. }
  81. /// <summary>Gets or sets a value indicating whether this <see cref="View"/> can be focused.</summary>
  82. /// <remarks>
  83. /// <para>
  84. /// <see cref="SuperView"/> must also have <see cref="CanFocus"/> set to <see langword="true"/>.
  85. /// </para>
  86. /// <para>
  87. /// When set to <see langword="false"/>, if an attempt is made to make this view focused, the focus will be set to
  88. /// the next focusable view.
  89. /// </para>
  90. /// <para>
  91. /// When set to <see langword="false"/>, the value of <see cref="CanFocus"/> for all
  92. /// subviews will be cached so that when <see cref="CanFocus"/> is set back to <see langword="true"/>, the subviews
  93. /// will be restored to their previous values.
  94. /// </para>
  95. /// <para>
  96. /// Changing this property to <see langword="true"/> will cause <see cref="TabStop"/> to be set to
  97. /// <see cref="TabBehavior.TabStop"/>" as a convenience. Changing this property to
  98. /// <see langword="false"/> will have no effect on <see cref="TabStop"/>.
  99. /// </para>
  100. /// </remarks>
  101. public bool CanFocus
  102. {
  103. get => _canFocus;
  104. set
  105. {
  106. if (_canFocus == value)
  107. {
  108. return;
  109. }
  110. _canFocus = value;
  111. if (TabStop is null && _canFocus)
  112. {
  113. TabStop = TabBehavior.TabStop;
  114. }
  115. if (!_canFocus && HasFocus)
  116. {
  117. // If CanFocus is set to false and this view has focus, make it leave focus
  118. HasFocus = false;
  119. }
  120. if (_canFocus && !HasFocus && Visible && SuperView is { } && SuperView.Focused is null)
  121. {
  122. // If CanFocus is set to true and this view does not have focus, make it enter focus
  123. SetFocus ();
  124. }
  125. OnCanFocusChanged ();
  126. }
  127. }
  128. /// <summary>Raised when <see cref="CanFocus"/> has been changed.</summary>
  129. /// <remarks>
  130. /// Raised by the <see cref="OnCanFocusChanged"/> virtual method.
  131. /// </remarks>
  132. public event EventHandler? CanFocusChanged;
  133. /// <summary>
  134. /// Focuses the deepest focusable Subview if one exists. If there are no focusable Subviews then the focus is set to the view itself.
  135. /// </summary>
  136. /// <param name="direction"></param>
  137. /// <param name="behavior"></param>
  138. /// <returns><see langword="true"/> if a subview other than this was focused.</returns>
  139. public bool FocusDeepest (NavigationDirection direction, TabBehavior? behavior)
  140. {
  141. View? deepest = FindDeepestFocusableView (direction, behavior);
  142. if (deepest is { })
  143. {
  144. return deepest.SetFocus ();
  145. }
  146. return SetFocus ();
  147. }
  148. /// <summary>Gets the currently focused Subview of this view, or <see langword="null"/> if nothing is focused.</summary>
  149. public View? Focused
  150. {
  151. get { return Subviews.FirstOrDefault (v => v.HasFocus); }
  152. }
  153. /// <summary>Returns a value indicating if this View is currently on Top (Active)</summary>
  154. public bool IsCurrentTop => Application.Current == this;
  155. /// <summary>
  156. /// Returns the most focused Subview down the subview-hierarchy.
  157. /// </summary>
  158. /// <value>The most focused Subview, or <see langword="null"/> if no Subview is focused.</value>
  159. public View? MostFocused
  160. {
  161. get
  162. {
  163. // TODO: Remove this API. It's duplicative of Application.Navigation.GetFocused.
  164. if (Focused is null)
  165. {
  166. return null;
  167. }
  168. View? most = Focused.MostFocused;
  169. if (most is { })
  170. {
  171. return most;
  172. }
  173. return Focused;
  174. }
  175. }
  176. /// <summary>Invoked when the <see cref="CanFocus"/> property from a view is changed.</summary>
  177. /// <remarks>
  178. /// Raises the <see cref="CanFocusChanged"/> event.
  179. /// </remarks>
  180. public virtual void OnCanFocusChanged () { CanFocusChanged?.Invoke (this, EventArgs.Empty); }
  181. /// <summary>
  182. /// INTERNAL API to restore focus to the subview that had focus before this view lost focus.
  183. /// </summary>
  184. /// <returns>
  185. /// Returns true if focus was restored to a subview, false otherwise.
  186. /// </returns>
  187. internal bool RestoreFocus (TabBehavior? behavior)
  188. {
  189. if (Focused is null && _subviews?.Count > 0)
  190. {
  191. if (_previouslyMostFocused is { } /* && (behavior is null || _previouslyMostFocused.TabStop == behavior)*/)
  192. {
  193. return _previouslyMostFocused.SetFocus ();
  194. }
  195. return false;
  196. }
  197. return false;
  198. }
  199. private View? FindDeepestFocusableView (NavigationDirection direction, TabBehavior? behavior)
  200. {
  201. View [] indicies = GetSubviewFocusChain (direction, behavior);
  202. foreach (View v in indicies)
  203. {
  204. return v.FindDeepestFocusableView (direction, behavior);
  205. }
  206. return null;
  207. }
  208. #region HasFocus
  209. // Backs `HasFocus` and is the ultimate source of truth whether a View has focus or not.
  210. private bool _hasFocus;
  211. /// <summary>
  212. /// Gets or sets whether this view has focus.
  213. /// </summary>
  214. /// <remarks>
  215. /// <para>
  216. /// Only Views that are visible, enabled, and have <see cref="CanFocus"/> set to <see langword="true"/> are
  217. /// focusable. If
  218. /// these conditions are not met when this property is set to <see langword="true"/> <see cref="HasFocus"/> will
  219. /// not change.
  220. /// </para>
  221. /// <para>
  222. /// Setting this property causes the <see cref="OnHasFocusChanging"/> and <see cref="OnHasFocusChanged"/> virtual
  223. /// methods (and <see cref="HasFocusChanging"/> and
  224. /// <see cref="HasFocusChanged"/> events to be raised). If the event is cancelled, <see cref="HasFocus"/> will not
  225. /// be changed.
  226. /// </para>
  227. /// <para>
  228. /// Setting this property to <see langword="true"/> will recursively set <see cref="HasFocus"/> to
  229. /// <see langword="true"/> for all SuperViews up the hierarchy.
  230. /// </para>
  231. /// <para>
  232. /// Setting this property to <see langword="true"/> will cause the subview furthest down the hierarchy that is
  233. /// focusable to also gain focus (as long as <see cref="TabStop"/>
  234. /// </para>
  235. /// <para>
  236. /// Setting this property to <see langword="false"/> will cause <see cref="AdvanceFocus"/> to set
  237. /// the focus on the next view to be focused.
  238. /// </para>
  239. /// </remarks>
  240. public bool HasFocus
  241. {
  242. set
  243. {
  244. if (HasFocus != value)
  245. {
  246. if (value)
  247. {
  248. // NOTE: If Application.Navigation is null, we pass null to FocusChanging. For unit tests.
  249. (bool focusSet, bool _) = SetHasFocusTrue (Application.Navigation?.GetFocused ());
  250. if (focusSet)
  251. {
  252. // The change happened
  253. // HasFocus is now true
  254. }
  255. }
  256. else
  257. {
  258. SetHasFocusFalse (null);
  259. }
  260. }
  261. }
  262. get => _hasFocus;
  263. }
  264. /// <summary>
  265. /// Causes this view to be focused. Calling this method has the same effect as setting <see cref="HasFocus"/> to
  266. /// <see langword="true"/> but with the added benefit of returning a value indicating whether the focus was set.
  267. /// </summary>
  268. public bool SetFocus ()
  269. {
  270. (bool focusSet, bool _) = SetHasFocusTrue (Application.Navigation?.GetFocused ());
  271. return focusSet;
  272. }
  273. /// <summary>
  274. /// INTERNAL: Called when focus is going to change to this view. This method is called by <see cref="SetFocus"/> and
  275. /// other methods that
  276. /// set or remove focus from a view.
  277. /// </summary>
  278. /// <param name="previousFocusedView">
  279. /// The previously focused view. If <see langword="null"/> there is no previously focused
  280. /// view.
  281. /// </param>
  282. /// <param name="traversingUp"></param>
  283. /// <returns><see langword="true"/> if <see cref="HasFocus"/> was changed to <see langword="true"/>.</returns>
  284. /// <exception cref="InvalidOperationException"></exception>
  285. private (bool focusSet, bool cancelled) SetHasFocusTrue (View? previousFocusedView, bool traversingUp = false)
  286. {
  287. Debug.Assert (ApplicationNavigation.IsInHierarchy (SuperView, this));
  288. // Pre-conditions
  289. if (_hasFocus)
  290. {
  291. return (false, false);
  292. }
  293. if (CanFocus && SuperView is { CanFocus: false })
  294. {
  295. Debug.WriteLine ($@"WARNING: Attempt to FocusChanging where SuperView.CanFocus == false. {this}");
  296. return (false, false);
  297. }
  298. if (!CanBeVisible (this) || !Enabled)
  299. {
  300. return (false, false);
  301. }
  302. if (!CanFocus)
  303. {
  304. return (false, false);
  305. }
  306. bool previousValue = HasFocus;
  307. bool cancelled = NotifyFocusChanging (false, true, previousFocusedView, this);
  308. if (cancelled)
  309. {
  310. return (false, true);
  311. }
  312. // Make sure superviews up the superview hierarchy have focus.
  313. // Any of them may cancel gaining focus. In which case we need to back out.
  314. if (SuperView is { HasFocus: false } sv)
  315. {
  316. (bool focusSet, bool svCancelled) = sv.SetHasFocusTrue (previousFocusedView, true);
  317. if (!focusSet)
  318. {
  319. return (false, svCancelled);
  320. }
  321. }
  322. if (_hasFocus)
  323. {
  324. // Something else beat us to the change (likely a FocusChanged handler).
  325. return (true, false);
  326. }
  327. // By setting _hasFocus to true we definitively change HasFocus for this view.
  328. // Get whatever peer has focus, if any
  329. View? focusedPeer = SuperView?.Focused;
  330. _hasFocus = true;
  331. // Ensure that the peer loses focus
  332. focusedPeer?.SetHasFocusFalse (this, true);
  333. if (!traversingUp)
  334. {
  335. // Restore focus to the previously most focused subview in the subview-hierarchy
  336. if (!RestoreFocus (TabStop))
  337. {
  338. // Couldn't restore focus, so use Advance to navigate to the next focusable subview
  339. if (!AdvanceFocus (NavigationDirection.Forward, null))
  340. {
  341. // Couldn't advance, so we're the most focused view in the application
  342. _previouslyMostFocused = null;
  343. Application.Navigation?.SetFocused (this);
  344. }
  345. }
  346. }
  347. if (previousFocusedView is { HasFocus: true } && Subviews.Contains (previousFocusedView))
  348. {
  349. previousFocusedView.SetHasFocusFalse (this);
  350. }
  351. NotifyFocusChanged (HasFocus, previousFocusedView, this);
  352. SetNeedsDisplay ();
  353. // Post-conditions - prove correctness
  354. if (HasFocus == previousValue)
  355. {
  356. throw new InvalidOperationException ("NotifyFocusChanging was not cancelled and the HasFocus value did not change.");
  357. }
  358. return (true, false);
  359. }
  360. private bool NotifyFocusChanging (bool currentHasFocus, bool newHasFocus, View? currentFocused, View? newFocused)
  361. {
  362. // Call the virtual method
  363. if (OnHasFocusChanging (currentHasFocus, newHasFocus, currentFocused, newFocused))
  364. {
  365. // The event was cancelled
  366. return true;
  367. }
  368. var args = new HasFocusEventArgs (currentHasFocus, newHasFocus, currentFocused, newFocused);
  369. HasFocusChanging?.Invoke (this, args);
  370. if (args.Cancel)
  371. {
  372. // The event was cancelled
  373. return true;
  374. }
  375. return false;
  376. }
  377. /// <summary>
  378. /// Invoked when <see cref="View.HasFocus"/> is about to change. This method is called before the
  379. /// <see cref="HasFocusChanging"/> event is raised.
  380. /// </summary>
  381. /// <remarks>
  382. /// <para>
  383. /// Use <see cref="OnHasFocusChanged"/> to be notified after the focus has changed.
  384. /// </para>
  385. /// </remarks>
  386. /// <param name="currentHasFocus">The current value of <see cref="View.HasFocus"/>.</param>
  387. /// <param name="newHasFocus">The value <see cref="View.HasFocus"/> will have if the focus change happens.</param>
  388. /// <param name="currentFocused">The view that is currently Focused. May be <see langword="null"/>.</param>
  389. /// <param name="newFocused">The view that will be focused. May be <see langword="null"/>.</param>
  390. /// <returns>
  391. /// <see langword="true"/>, if the change to <see cref="View.HasFocus"/> is to be cancelled, <see langword="false"/>
  392. /// otherwise.
  393. /// </returns>
  394. protected virtual bool OnHasFocusChanging (bool currentHasFocus, bool newHasFocus, View? currentFocused, View? newFocused)
  395. {
  396. return false;
  397. }
  398. /// <summary>
  399. /// Raised when <see cref="View.HasFocus"/> is about to change.
  400. /// </summary>
  401. /// <remarks>
  402. /// <para>
  403. /// Cancel the event to prevent the focus from changing.
  404. /// </para>
  405. /// <para>
  406. /// Use <see cref="HasFocusChanged"/> to be notified after the focus has changed.
  407. /// </para>
  408. /// </remarks>
  409. public event EventHandler<HasFocusEventArgs>? HasFocusChanging;
  410. /// <summary>
  411. /// Called when this view should stop being focused.
  412. /// </summary>
  413. /// <param name="newFocusedView">The new focused view. If <see langword="null"/> it is not known which view will be focused.</param>
  414. /// <param name="traversingDown">Set to true to indicate method is being called recurively, traversing down the focus chain.</param>
  415. /// <exception cref="InvalidOperationException"></exception>
  416. private void SetHasFocusFalse (View? newFocusedView, bool traversingDown = false)
  417. {
  418. // Pre-conditions
  419. if (!_hasFocus)
  420. {
  421. throw new InvalidOperationException ("SetHasFocusFalse should not be called if the view does not have focus.");
  422. }
  423. // If newFocusedVew is null, we need to find the view that should get focus, and SetFocus on it.
  424. if (!traversingDown && newFocusedView is null)
  425. {
  426. if (SuperView?._previouslyMostFocused is { } && SuperView?._previouslyMostFocused != this)
  427. {
  428. SuperView?._previouslyMostFocused?.SetFocus ();
  429. // The above will cause SetHasFocusFalse, so we can return
  430. return;
  431. }
  432. if (SuperView is { } && SuperView.AdvanceFocus (NavigationDirection.Forward, TabStop))
  433. {
  434. // The above will cause SetHasFocusFalse, so we can return
  435. return;
  436. }
  437. if (Application.Navigation is { } && Application.Current is { })
  438. {
  439. // Temporarily ensure this view can't get focus
  440. bool prevCanFocus = _canFocus;
  441. _canFocus = false;
  442. bool restoredFocus = Application.Current!.RestoreFocus (null);
  443. _canFocus = prevCanFocus;
  444. if (restoredFocus)
  445. {
  446. // The above caused SetHasFocusFalse, so we can return
  447. return;
  448. }
  449. }
  450. // No other focusable view to be found. Just "leave" us...
  451. }
  452. // Before we can leave focus, we need to make sure that all views down the subview-hierarchy have left focus.
  453. View? mostFocused = MostFocused;
  454. if (mostFocused is { } && (newFocusedView is null || mostFocused != newFocusedView))
  455. {
  456. // Start at the bottom and work our way up to us
  457. View? bottom = mostFocused;
  458. while (bottom is { } && bottom != this)
  459. {
  460. if (bottom.HasFocus)
  461. {
  462. bottom.SetHasFocusFalse (newFocusedView, true);
  463. }
  464. bottom = bottom.SuperView;
  465. }
  466. _previouslyMostFocused = mostFocused;
  467. }
  468. bool previousValue = HasFocus;
  469. // Note, can't be cancelled.
  470. NotifyFocusChanging (HasFocus, !HasFocus, newFocusedView, this);
  471. // Get whatever peer has focus, if any
  472. View? focusedPeer = SuperView?.Focused;
  473. _hasFocus = false;
  474. if (Application.Navigation is { })
  475. {
  476. View? appFocused = Application.Navigation.GetFocused ();
  477. if (appFocused is { } || appFocused == this)
  478. {
  479. Application.Navigation.SetFocused (newFocusedView ?? SuperView);
  480. }
  481. }
  482. NotifyFocusChanged (HasFocus, this, newFocusedView);
  483. if (_hasFocus)
  484. {
  485. // Notify caused HasFocus to change to true.
  486. return;
  487. }
  488. if (SuperView is { })
  489. {
  490. SuperView._previouslyMostFocused = focusedPeer;
  491. }
  492. // Post-conditions - prove correctness
  493. if (HasFocus == previousValue)
  494. {
  495. throw new InvalidOperationException ("SetHasFocusFalse and the HasFocus value did not change.");
  496. }
  497. SetNeedsDisplay ();
  498. }
  499. /// <summary>
  500. /// Caches the most focused subview when this view is losing focus. This is used by <see cref="RestoreFocus"/>.
  501. /// </summary>
  502. private View? _previouslyMostFocused;
  503. private void NotifyFocusChanged (bool newHasFocus, View? previousFocusedView, View? focusedVew)
  504. {
  505. // Call the virtual method
  506. OnHasFocusChanged (newHasFocus, previousFocusedView, focusedVew);
  507. // Raise the event
  508. var args = new HasFocusEventArgs (newHasFocus, newHasFocus, previousFocusedView, focusedVew);
  509. HasFocusChanged?.Invoke (this, args);
  510. }
  511. /// <summary>
  512. /// Invoked after <see cref="HasFocus"/> has changed. This method is called before the <see cref="HasFocusChanged"/>
  513. /// event is raised.
  514. /// </summary>
  515. /// <remarks>
  516. /// <para>
  517. /// This event cannot be cancelled.
  518. /// </para>
  519. /// </remarks>
  520. /// <param name="newHasFocus">The new value of <see cref="View.HasFocus"/>.</param>
  521. /// <param name="previousFocusedView"></param>
  522. /// <param name="focusedVew">The view that is now focused. May be <see langword="null"/></param>
  523. protected virtual void OnHasFocusChanged (bool newHasFocus, View? previousFocusedView, View? focusedVew) { }
  524. /// <summary>Raised after <see cref="HasFocus"/> has changed.</summary>
  525. /// <remarks>
  526. /// <para>
  527. /// This event cannot be cancelled.
  528. /// </para>
  529. /// </remarks>
  530. public event EventHandler<HasFocusEventArgs>? HasFocusChanged;
  531. #endregion HasFocus
  532. #region Tab/Focus Handling
  533. /// <summary>
  534. /// Gets TabIndexes that are scoped to the specified behavior and direction. If behavior is null, all TabIndexes are
  535. /// returned.
  536. /// </summary>
  537. /// <param name="direction"></param>
  538. /// <param name="behavior"></param>
  539. /// <returns></returns>
  540. /// GetScopedTabIndexes
  541. private View [] GetSubviewFocusChain (NavigationDirection direction, TabBehavior? behavior)
  542. {
  543. IEnumerable<View>? fitleredSubviews;
  544. if (behavior.HasValue)
  545. {
  546. fitleredSubviews = _subviews?.Where (v => v.TabStop == behavior && v is { CanFocus: true, Visible: true, Enabled: true });
  547. }
  548. else
  549. {
  550. fitleredSubviews = _subviews?.Where (v => v is { CanFocus: true, Visible: true, Enabled: true });
  551. }
  552. if (direction == NavigationDirection.Backward)
  553. {
  554. fitleredSubviews = fitleredSubviews?.Reverse ();
  555. }
  556. return fitleredSubviews?.ToArray () ?? Array.Empty<View> ();
  557. }
  558. private TabBehavior? _tabStop;
  559. /// <summary>
  560. /// Gets or sets the behavior of <see cref="AdvanceFocus"/> for keyboard navigation.
  561. /// </summary>
  562. /// <remarks>
  563. /// <para>
  564. /// If <see langword="null"/> the tab stop has not been set and setting <see cref="CanFocus"/> to true will set it
  565. /// to
  566. /// <see cref="TabBehavior.TabStop"/>.
  567. /// </para>
  568. /// <para>
  569. /// TabStop is independent of <see cref="CanFocus"/>. If <see cref="CanFocus"/> is <see langword="false"/>, the
  570. /// view will not gain
  571. /// focus even if this property is set and vice-versa.
  572. /// </para>
  573. /// <para>
  574. /// The default <see cref="TabBehavior.TabStop"/> keys are <see cref="Application.NextTabKey"/> (<c>Key.Tab</c>)
  575. /// and <see cref="Application.PrevTabKey"/> (<c>Key>Tab.WithShift</c>).
  576. /// </para>
  577. /// <para>
  578. /// The default <see cref="TabBehavior.TabGroup"/> keys are <see cref="Application.NextTabGroupKey"/> (
  579. /// <c>Key.F6</c>) and <see cref="Application.PrevTabGroupKey"/> (<c>Key>Key.F6.WithShift</c>).
  580. /// </para>
  581. /// </remarks>
  582. public TabBehavior? TabStop
  583. {
  584. get => _tabStop;
  585. set
  586. {
  587. if (_tabStop == value)
  588. {
  589. return;
  590. }
  591. _tabStop = value;
  592. }
  593. }
  594. #endregion Tab/Focus Handling
  595. }