|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | +// See the LICENSE file in the project root for more information. |
| 4 | + |
| 5 | +using System.Collections.Generic; |
| 6 | +using Microsoft.Toolkit.Uwp.UI.Controls; |
| 7 | +using Windows.UI.Xaml.Automation; |
| 8 | +using Windows.UI.Xaml.Automation.Peers; |
| 9 | +using Windows.UI.Xaml.Controls; |
| 10 | + |
| 11 | +namespace Microsoft.Toolkit.Uwp.UI.Automation.Peers |
| 12 | +{ |
| 13 | + /// <summary> |
| 14 | + /// Defines a framework element automation peer for the <see cref="TokenizingTextBox"/> control. |
| 15 | + /// </summary> |
| 16 | + public class TokenizingTextBoxAutomationPeer : ListViewBaseAutomationPeer |
| 17 | + { |
| 18 | + /// <summary> |
| 19 | + /// Initializes a new instance of the <see cref="TokenizingTextBoxAutomationPeer"/> class. |
| 20 | + /// </summary> |
| 21 | + /// <param name="owner"> |
| 22 | + /// The <see cref="TokenizingTextBox" /> that is associated with this <see cref="T:Microsoft.Toolkit.Uwp.UI.Automation.Peers.TokenizingTextBoxAutomationPeer" />. |
| 23 | + /// </param> |
| 24 | + public TokenizingTextBoxAutomationPeer(TokenizingTextBox owner) |
| 25 | + : base(owner) |
| 26 | + { |
| 27 | + } |
| 28 | + |
| 29 | + private TokenizingTextBox OwningTokenizingTextBox |
| 30 | + { |
| 31 | + get |
| 32 | + { |
| 33 | + return Owner as TokenizingTextBox; |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + /// <summary> |
| 38 | + /// Called by GetClassName that gets a human readable name that, in addition to AutomationControlType, |
| 39 | + /// differentiates the control represented by this AutomationPeer. |
| 40 | + /// </summary> |
| 41 | + /// <returns>The string that contains the name.</returns> |
| 42 | + protected override string GetClassNameCore() |
| 43 | + { |
| 44 | + return Owner.GetType().Name; |
| 45 | + } |
| 46 | + |
| 47 | + /// <summary> |
| 48 | + /// Called by GetName. |
| 49 | + /// </summary> |
| 50 | + /// <returns> |
| 51 | + /// Returns the first of these that is not null or empty: |
| 52 | + /// - Value returned by the base implementation |
| 53 | + /// - Name of the owning Carousel |
| 54 | + /// - Carousel class name |
| 55 | + /// </returns> |
| 56 | + protected override string GetNameCore() |
| 57 | + { |
| 58 | + string name = this.OwningTokenizingTextBox.Name; |
| 59 | + if (!string.IsNullOrEmpty(name)) |
| 60 | + { |
| 61 | + return name; |
| 62 | + } |
| 63 | + |
| 64 | + name = AutomationProperties.GetName(this.OwningTokenizingTextBox); |
| 65 | + if (!string.IsNullOrEmpty(name)) |
| 66 | + { |
| 67 | + return name; |
| 68 | + } |
| 69 | + |
| 70 | + return base.GetNameCore(); |
| 71 | + } |
| 72 | + |
| 73 | + /// <summary> |
| 74 | + /// Gets the control pattern that is associated with the specified Windows.UI.Xaml.Automation.Peers.PatternInterface. |
| 75 | + /// </summary> |
| 76 | + /// <param name="patternInterface">A value from the Windows.UI.Xaml.Automation.Peers.PatternInterface enumeration.</param> |
| 77 | + /// <returns>The object that supports the specified pattern, or null if unsupported.</returns> |
| 78 | + protected override object GetPatternCore(PatternInterface patternInterface) |
| 79 | + { |
| 80 | + switch (patternInterface) |
| 81 | + { |
| 82 | + case PatternInterface.Selection: |
| 83 | + return this; |
| 84 | + } |
| 85 | + |
| 86 | + return base.GetPatternCore(patternInterface); |
| 87 | + } |
| 88 | + |
| 89 | + /// <summary> |
| 90 | + /// Gets the collection of elements that are represented in the UI Automation tree as immediate |
| 91 | + /// child elements of the automation peer. |
| 92 | + /// </summary> |
| 93 | + /// <returns>The children elements.</returns> |
| 94 | + protected override IList<AutomationPeer> GetChildrenCore() |
| 95 | + { |
| 96 | + TokenizingTextBox owner = this.OwningTokenizingTextBox; |
| 97 | + |
| 98 | + ItemCollection items = owner.Items; |
| 99 | + if (items.Count <= 0) |
| 100 | + { |
| 101 | + return null; |
| 102 | + } |
| 103 | + |
| 104 | + List<AutomationPeer> peers = new List<AutomationPeer>(items.Count); |
| 105 | + for (int i = 0; i < items.Count; i++) |
| 106 | + { |
| 107 | + if (owner.ContainerFromIndex(i) is TokenizingTextBoxItem element) |
| 108 | + { |
| 109 | + peers.Add(FromElement(element) ?? CreatePeerForElement(element)); |
| 110 | + } |
| 111 | + } |
| 112 | + |
| 113 | + return peers; |
| 114 | + } |
| 115 | + } |
| 116 | +} |
0 commit comments