-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3518 from windows-toolkit/jamesmcroft/3517-bladev…
…iew-automation Added automation peers for BladeView and BladeItem controls
- Loading branch information
Showing
7 changed files
with
350 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
163 changes: 163 additions & 0 deletions
163
Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeItemAutomationPeer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using Microsoft.Toolkit.Uwp.UI.Controls; | ||
using Microsoft.Toolkit.Uwp.UI.Extensions; | ||
using Windows.UI.Xaml.Automation; | ||
using Windows.UI.Xaml.Automation.Peers; | ||
using Windows.UI.Xaml.Controls; | ||
|
||
namespace Microsoft.Toolkit.Uwp.UI.Automation.Peers | ||
{ | ||
/// <summary> | ||
/// Defines a framework element automation peer for the <see cref="BladeItem"/>. | ||
/// </summary> | ||
public class BladeItemAutomationPeer : FrameworkElementAutomationPeer | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="BladeItemAutomationPeer"/> class. | ||
/// </summary> | ||
/// <param name="owner"> | ||
/// The <see cref="BladeItem" /> that is associated with this <see cref="T:Windows.UI.Xaml.Automation.Peers.BladeItemAutomationPeer" />. | ||
/// </param> | ||
public BladeItemAutomationPeer(BladeItem owner) | ||
: base(owner) | ||
{ | ||
} | ||
|
||
private BladeItem OwnerBladeItem | ||
{ | ||
get { return this.Owner as BladeItem; } | ||
} | ||
|
||
/// <summary> | ||
/// Gets the control type for the element that is associated with the UI Automation peer. | ||
/// </summary> | ||
/// <returns>The control type.</returns> | ||
protected override AutomationControlType GetAutomationControlTypeCore() | ||
{ | ||
return AutomationControlType.ListItem; | ||
} | ||
|
||
/// <summary> | ||
/// Called by GetClassName that gets a human readable name that, in addition to AutomationControlType, | ||
/// differentiates the control represented by this AutomationPeer. | ||
/// </summary> | ||
/// <returns>The string that contains the name.</returns> | ||
protected override string GetClassNameCore() | ||
{ | ||
return Owner.GetType().Name; | ||
} | ||
|
||
/// <summary> | ||
/// Called by GetName. | ||
/// </summary> | ||
/// <returns> | ||
/// Returns the first of these that is not null or empty: | ||
/// - Value returned by the base implementation | ||
/// - Name of the owning BladeItem | ||
/// - BladeItem class name | ||
/// </returns> | ||
protected override string GetNameCore() | ||
{ | ||
string name = AutomationProperties.GetName(this.OwnerBladeItem); | ||
if (!string.IsNullOrEmpty(name)) | ||
{ | ||
return name; | ||
} | ||
|
||
name = this.OwnerBladeItem.Name; | ||
if (!string.IsNullOrEmpty(name)) | ||
{ | ||
return name; | ||
} | ||
|
||
name = this.OwnerBladeItem.Header?.ToString(); | ||
if (!string.IsNullOrEmpty(name)) | ||
{ | ||
return name; | ||
} | ||
|
||
TextBlock textBlock = this.OwnerBladeItem.FindDescendant<TextBlock>(); | ||
if (textBlock != null) | ||
{ | ||
return textBlock.Text; | ||
} | ||
|
||
name = base.GetNameCore(); | ||
if (!string.IsNullOrEmpty(name)) | ||
{ | ||
return name; | ||
} | ||
|
||
return string.Empty; | ||
} | ||
|
||
/// <summary> | ||
/// Called by GetAutomationId that gets the **AutomationId** of the element that is associated with the automation peer. | ||
/// </summary> | ||
/// <returns> | ||
/// The string that contains the automation ID. | ||
/// </returns> | ||
protected override string GetAutomationIdCore() | ||
{ | ||
string automationId = base.GetAutomationIdCore(); | ||
if (!string.IsNullOrEmpty(automationId)) | ||
{ | ||
return automationId; | ||
} | ||
|
||
if (this.OwnerBladeItem != null) | ||
{ | ||
return this.GetNameCore(); | ||
} | ||
|
||
return string.Empty; | ||
} | ||
|
||
/// <summary> | ||
/// Returns the size of the set where the element that is associated with the automation peer is located. | ||
/// </summary> | ||
/// <returns> | ||
/// The size of the set. | ||
/// </returns> | ||
protected override int GetSizeOfSetCore() | ||
{ | ||
int sizeOfSet = base.GetSizeOfSetCore(); | ||
|
||
if (sizeOfSet != -1) | ||
{ | ||
return sizeOfSet; | ||
} | ||
|
||
BladeItem owner = this.OwnerBladeItem; | ||
BladeView parent = owner.ParentBladeView; | ||
sizeOfSet = parent.Items.Count; | ||
|
||
return sizeOfSet; | ||
} | ||
|
||
/// <summary> | ||
/// Returns the ordinal position in the set for the element that is associated with the automation peer. | ||
/// </summary> | ||
/// <returns> | ||
/// The ordinal position in the set. | ||
/// </returns> | ||
protected override int GetPositionInSetCore() | ||
{ | ||
int positionInSet = base.GetPositionInSetCore(); | ||
|
||
if (positionInSet != -1) | ||
{ | ||
return positionInSet; | ||
} | ||
|
||
BladeItem owner = this.OwnerBladeItem; | ||
BladeView parent = owner.ParentBladeView; | ||
positionInSet = parent.IndexFromContainer(owner); | ||
|
||
return positionInSet; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
Microsoft.Toolkit.Uwp.UI.Controls/BladeView/BladeViewAutomationPeer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Collections.Generic; | ||
using Microsoft.Toolkit.Uwp.UI.Controls; | ||
using Windows.UI.Xaml.Automation; | ||
using Windows.UI.Xaml.Automation.Peers; | ||
using Windows.UI.Xaml.Controls; | ||
|
||
namespace Microsoft.Toolkit.Uwp.UI.Automation.Peers | ||
{ | ||
/// <summary> | ||
/// Defines a framework element automation peer for the <see cref="BladeView"/> control. | ||
/// </summary> | ||
public class BladeViewAutomationPeer : ItemsControlAutomationPeer | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="BladeViewAutomationPeer"/> class. | ||
/// </summary> | ||
/// <param name="owner"> | ||
/// The <see cref="BladeView" /> that is associated with this <see cref="T:Windows.UI.Xaml.Automation.Peers.BladeViewAutomationPeer" />. | ||
/// </param> | ||
public BladeViewAutomationPeer(BladeView owner) | ||
: base(owner) | ||
{ | ||
} | ||
|
||
private BladeView OwningBladeView | ||
{ | ||
get | ||
{ | ||
return Owner as BladeView; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets the control type for the element that is associated with the UI Automation peer. | ||
/// </summary> | ||
/// <returns>The control type.</returns> | ||
protected override AutomationControlType GetAutomationControlTypeCore() | ||
{ | ||
return AutomationControlType.List; | ||
} | ||
|
||
/// <summary> | ||
/// Called by GetClassName that gets a human readable name that, in addition to AutomationControlType, | ||
/// differentiates the control represented by this AutomationPeer. | ||
/// </summary> | ||
/// <returns>The string that contains the name.</returns> | ||
protected override string GetClassNameCore() | ||
{ | ||
return Owner.GetType().Name; | ||
} | ||
|
||
/// <summary> | ||
/// Called by GetName. | ||
/// </summary> | ||
/// <returns> | ||
/// Returns the first of these that is not null or empty: | ||
/// - Value returned by the base implementation | ||
/// - Name of the owning BladeView | ||
/// - BladeView class name | ||
/// </returns> | ||
protected override string GetNameCore() | ||
{ | ||
string name = AutomationProperties.GetName(this.OwningBladeView); | ||
if (!string.IsNullOrEmpty(name)) | ||
{ | ||
return name; | ||
} | ||
|
||
name = this.OwningBladeView.Name; | ||
if (!string.IsNullOrEmpty(name)) | ||
{ | ||
return name; | ||
} | ||
|
||
name = base.GetNameCore(); | ||
if (!string.IsNullOrEmpty(name)) | ||
{ | ||
return name; | ||
} | ||
|
||
return string.Empty; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the collection of elements that are represented in the UI Automation tree as immediate | ||
/// child elements of the automation peer. | ||
/// </summary> | ||
/// <returns>The children elements.</returns> | ||
protected override IList<AutomationPeer> GetChildrenCore() | ||
{ | ||
BladeView owner = OwningBladeView; | ||
|
||
ItemCollection items = owner.Items; | ||
if (items.Count <= 0) | ||
{ | ||
return null; | ||
} | ||
|
||
List<AutomationPeer> peers = new List<AutomationPeer>(items.Count); | ||
for (int i = 0; i < items.Count; i++) | ||
{ | ||
if (owner.ContainerFromIndex(i) is BladeItem element) | ||
{ | ||
peers.Add(FromElement(element) ?? CreatePeerForElement(element)); | ||
} | ||
} | ||
|
||
return peers; | ||
} | ||
} | ||
} |
Oops, something went wrong.