Adding UIA accessibility support for PictureBox control (#3233)

This commit is contained in:
Mikhail Lipin 2020-06-29 09:17:38 +03:00 коммит произвёл GitHub
Родитель cc0c82707b
Коммит 1678a756fb
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 164 добавлений и 1 удалений

Просмотреть файл

@ -5,3 +5,4 @@ System.Windows.Forms.ListViewGroup.TitleImageKey.get -> string!
System.Windows.Forms.ListViewGroup.TitleImageKey.set -> void
~System.Windows.Forms.ListView.GroupImageList.get -> System.Windows.Forms.ImageList
~System.Windows.Forms.ListView.GroupImageList.set -> void
~override System.Windows.Forms.PictureBox.CreateAccessibilityInstance() -> System.Windows.Forms.AccessibleObject

Просмотреть файл

@ -0,0 +1,32 @@
// 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 static Interop;
namespace System.Windows.Forms
{
public partial class PictureBox
{
internal class PictureBoxAccessibleObject : ControlAccessibleObject
{
public PictureBoxAccessibleObject(PictureBox owner) : base(owner)
{
}
internal override object? GetPropertyValue(UiaCore.UIA propertyID)
=> propertyID switch
{
UiaCore.UIA.NamePropertyId
=> Name,
UiaCore.UIA.ControlTypePropertyId
=> UiaCore.UIA.PaneControlTypeId,
UiaCore.UIA.AutomationIdPropertyId
=> Owner.Name,
UiaCore.UIA.IsKeyboardFocusablePropertyId
=> true,
_ => base.GetPropertyValue(propertyID)
};
}
}
}

Просмотреть файл

@ -27,7 +27,7 @@ namespace System.Windows.Forms
[Docking(DockingBehavior.Ask)]
[Designer("System.Windows.Forms.Design.PictureBoxDesigner, " + AssemblyRef.SystemDesign)]
[SRDescription(nameof(SR.DescriptionPictureBox))]
public class PictureBox : Control, ISupportInitialize
public partial class PictureBox : Control, ISupportInitialize
{
/// <summary>
/// The type of border this control will have.
@ -837,6 +837,8 @@ namespace System.Windows.Forms
remove => Events.RemoveHandler(EVENT_SIZEMODECHANGED, value);
}
internal override bool SupportsUiaProviders => true;
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public new bool TabStop
@ -969,6 +971,9 @@ namespace System.Windows.Forms
}
}
protected override AccessibleObject CreateAccessibilityInstance()
=> new PictureBoxAccessibleObject(this);
protected override void Dispose(bool disposing)
{
if (disposing)

Просмотреть файл

@ -0,0 +1,125 @@
// 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 Xunit;
using static Interop.UiaCore;
namespace System.Windows.Forms.Tests
{
public class PictureBox_PictureBoxAccessibleObjectTests
{
[WinFormsFact]
public void PictureBoxAccessibleObject_Ctor_NullControl_ThrowsArgumentNullException()
{
Assert.Throws<ArgumentNullException>("ownerControl", () => new PictureBox.PictureBoxAccessibleObject(null));
}
[WinFormsFact]
public void PictureBoxAccessibleObject_Ctor_Default()
{
using var pictureBox = new PictureBox();
Assert.False(pictureBox.IsHandleCreated);
var pictureBoxAccessibleObject = new PictureBox.PictureBoxAccessibleObject(pictureBox);
Assert.NotNull(pictureBoxAccessibleObject.Owner);
// TODO: ControlAccessibleObject shouldn't force handle creation, tracked in https://github.com/dotnet/winforms/issues/3062
Assert.True(pictureBox.IsHandleCreated);
}
[WinFormsFact]
public void PictureBoxAccessibleObject_Description_ReturnsExpected()
{
using var pictureBox = new PictureBox
{
AccessibleDescription = "TestDescription",
};
Assert.False(pictureBox.IsHandleCreated);
var pictureBoxAccessibleObject = new PictureBox.PictureBoxAccessibleObject(pictureBox);
Assert.Equal("TestDescription", pictureBoxAccessibleObject.Description);
// TODO: ControlAccessibleObject shouldn't force handle creation, tracked in https://github.com/dotnet/winforms/issues/3062
Assert.True(pictureBox.IsHandleCreated);
}
[WinFormsFact]
public void PictureBoxAccessibleObject_Name_ReturnsExpected()
{
using var pictureBox = new PictureBox
{
AccessibleName = "TestName"
};
Assert.False(pictureBox.IsHandleCreated);
var pictureBoxAccessibleObject = new PictureBox.PictureBoxAccessibleObject(pictureBox);
Assert.Equal("TestName", pictureBoxAccessibleObject.Name);
// TODO: ControlAccessibleObject shouldn't force handle creation, tracked in https://github.com/dotnet/winforms/issues/3062
Assert.True(pictureBox.IsHandleCreated);
}
[WinFormsFact]
public void PictureBoxAccessibleObject_CustomRole_ReturnsExpected()
{
using var pictureBox = new PictureBox
{
AccessibleRole = AccessibleRole.PushButton
};
Assert.False(pictureBox.IsHandleCreated);
var pictureBoxAccessibleObject = new PictureBox.PictureBoxAccessibleObject(pictureBox);
Assert.Equal(AccessibleRole.PushButton, pictureBoxAccessibleObject.Role);
// TODO: ControlAccessibleObject shouldn't force handle creation, tracked in https://github.com/dotnet/winforms/issues/3062
Assert.True(pictureBox.IsHandleCreated);
}
[WinFormsFact]
public void PictureBoxAccessibleObject_DefaultRole_ReturnsExpected()
{
using var pictureBox = new PictureBox();
Assert.False(pictureBox.IsHandleCreated);
var pictureBoxAccessibleObject = new PictureBox.PictureBoxAccessibleObject(pictureBox);
Assert.Equal(AccessibleRole.Client, pictureBoxAccessibleObject.Role);
// TODO: ControlAccessibleObject shouldn't force handle creation, tracked in https://github.com/dotnet/winforms/issues/3062
Assert.True(pictureBox.IsHandleCreated);
}
[WinFormsTheory]
[InlineData((int)UIA.NamePropertyId, "TestName")]
[InlineData((int)UIA.ControlTypePropertyId, UIA.PaneControlTypeId)]
[InlineData((int)UIA.IsKeyboardFocusablePropertyId, true)]
[InlineData((int)UIA.AutomationIdPropertyId, "PictureBox1")]
public void PictureBoxAccessibleObject_GetPropertyValue_Invoke_ReturnsExpected(int propertyID, object expected)
{
using var pictureBox = new PictureBox
{
Name = "PictureBox1",
AccessibleName = "TestName"
};
Assert.False(pictureBox.IsHandleCreated);
var pictureBoxAccessibleObject = new PictureBox.PictureBoxAccessibleObject(pictureBox);
object value = pictureBoxAccessibleObject.GetPropertyValue((UIA)propertyID);
Assert.Equal(expected, value);
// TODO: ControlAccessibleObject shouldn't force handle creation, tracked in https://github.com/dotnet/winforms/issues/3062
Assert.True(pictureBox.IsHandleCreated);
}
[WinFormsFact]
public void PictureBoxAccessibleObject_IsPatternSupported_Invoke_ReturnsTrue_ForLegacyIAccessiblePatternId()
{
using var pictureBox = new PictureBox();
Assert.False(pictureBox.IsHandleCreated);
var pictureBoxAccessibleObject = new PictureBox.PictureBoxAccessibleObject(pictureBox);
Assert.True(pictureBoxAccessibleObject.IsPatternSupported(UIA.LegacyIAccessiblePatternId));
// TODO: ControlAccessibleObject shouldn't force handle creation, tracked in https://github.com/dotnet/winforms/issues/3062
Assert.True(pictureBox.IsHandleCreated);
}
}
}