Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/System.Windows.Forms/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
~override System.Windows.Forms.ToolStripContainer.CreateAccessibilityInstance() -> System.Windows.Forms.AccessibleObject
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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 ToolStripContainer
{
internal class ToolStripContainerAccessibleObject : ControlAccessibleObject
{
public ToolStripContainerAccessibleObject(ToolStripContainer owner) : base(owner)
{
}

internal override object? GetPropertyValue(UiaCore.UIA propertyID)
=> propertyID switch
{
UiaCore.UIA.AutomationIdPropertyId
=> Owner.Name,
UiaCore.UIA.HasKeyboardFocusPropertyId
=> Owner.Focused,
UiaCore.UIA.IsKeyboardFocusablePropertyId
=> (State & AccessibleStates.Focusable) == AccessibleStates.Focusable,
_ => base.GetPropertyValue(propertyID)
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ public bool RightToolStripPanelVisible
}
}

internal override bool SupportsUiaProviders => true;

[SRCategory(nameof(SR.CatAppearance))]
[SRDescription(nameof(SR.ToolStripContainerTopToolStripPanelDescr))]
[Localizable(false)]
Expand Down Expand Up @@ -347,6 +349,9 @@ public bool TopToolStripPanelVisible
get => base.Controls;
}

protected override AccessibleObject CreateAccessibilityInstance()
=> new ToolStripContainerAccessibleObject(this);

[EditorBrowsable(EditorBrowsableState.Advanced)]
protected override ControlCollection CreateControlsInstance()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// 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 ToolStripContainer_ToolStripContainerAccessibleObjectTests : IClassFixture<ThreadExceptionFixture>
{
[WinFormsFact]
public void ToolStripContainerAccessibleObject_Ctor_Default()
{
using ToolStripContainer toolStripContainer = new();
ToolStripContainer.ToolStripContainerAccessibleObject accessibleObject = new(toolStripContainer);

Assert.Equal(toolStripContainer, accessibleObject.Owner);
Assert.False(toolStripContainer.IsHandleCreated);
}

[WinFormsTheory]
[InlineData((int)UIA.NamePropertyId, "TestName")]
[InlineData((int)UIA.AutomationIdPropertyId, "ToolStripContainer1")]
public void ToolStripContainerAccessibleObject_GetPropertyValue_Invoke_ReturnsExpected(int propertyID, object expected)
{
using var control = new ToolStripContainer
{
Name = "ToolStripContainer1",
AccessibleName = "TestName"
};

var accessibleObject = new ToolStripContainer.ToolStripContainerAccessibleObject(control);
object value = accessibleObject.GetPropertyValue((UIA)propertyID);

Assert.Equal(expected, value);
Assert.False(control.IsHandleCreated);
}

[WinFormsFact]
public void ToolStripContainerAccessibleObject_GetPropertyValue_HasKeyboardFocus_ReturnsTrue_IfControlHasFocus()
{
using var control = new ToolStripContainer();

var accessibleObject = new ToolStripContainer.ToolStripContainerAccessibleObject(control);
Assert.False(control.IsHandleCreated);
control.FocusActiveControlInternal();
bool value = (bool)accessibleObject.GetPropertyValue(UIA.HasKeyboardFocusPropertyId);

Assert.True(value);
Assert.True(control.IsHandleCreated);
}

[WinFormsFact]
public void ToolStripContainerAccessibleObject_GetPropertyValue_HasKeyboardFocus_ReturnsFalse_IfControlHasNoFocus()
{
using var control = new ToolStripContainer();

var accessibleObject = new ToolStripContainer.ToolStripContainerAccessibleObject(control);
bool value = (bool)accessibleObject.GetPropertyValue(UIA.HasKeyboardFocusPropertyId);

Assert.False(value);
Assert.False(control.IsHandleCreated);
}
}
}