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
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using static Interop;

namespace System.Windows.Forms.PropertyGridInternal
Expand All @@ -14,11 +12,16 @@ private partial class GridViewEdit
{
protected class GridViewEditAccessibleObject : ControlAccessibleObject
{
private readonly PropertyGridView propertyGridView;
private readonly PropertyGridView _owningPropertyGridView;
private readonly TextBoxBaseUiaTextProvider _textProvider;
private readonly GridViewEdit _owningGridViewEdit;

public GridViewEditAccessibleObject(GridViewEdit owner) : base(owner)
{
propertyGridView = owner.psheet;
_owningPropertyGridView = owner.psheet;
_owningGridViewEdit = owner;
_textProvider = new TextBoxBaseUiaTextProvider(owner);
UseTextProviders(_textProvider, _textProvider);
}

public override AccessibleStates State
Expand All @@ -45,28 +48,28 @@ public override AccessibleStates State
/// </summary>
/// <param name="direction">Indicates the direction in which to navigate.</param>
/// <returns>Returns the element in the specified direction.</returns>
internal override UiaCore.IRawElementProviderFragment FragmentNavigate(UiaCore.NavigateDirection direction)
internal override UiaCore.IRawElementProviderFragment? FragmentNavigate(UiaCore.NavigateDirection direction)
{
if (direction == UiaCore.NavigateDirection.Parent && propertyGridView.SelectedGridEntry != null)
if (direction == UiaCore.NavigateDirection.Parent && _owningPropertyGridView.SelectedGridEntry != null)
{
return propertyGridView.SelectedGridEntry.AccessibilityObject;
return _owningPropertyGridView.SelectedGridEntry.AccessibilityObject;
}
else if (direction == UiaCore.NavigateDirection.NextSibling)
{
if (propertyGridView.DropDownButton.Visible)
if (_owningPropertyGridView.DropDownButton.Visible)
{
return propertyGridView.DropDownButton.AccessibilityObject;
return _owningPropertyGridView.DropDownButton.AccessibilityObject;
}
else if (propertyGridView.DialogButton.Visible)
else if (_owningPropertyGridView.DialogButton.Visible)
{
return propertyGridView.DialogButton.AccessibilityObject;
return _owningPropertyGridView.DialogButton.AccessibilityObject;
}
}
else if (direction == UiaCore.NavigateDirection.PreviousSibling)
{
if (propertyGridView.DropDownVisible)
if (_owningPropertyGridView.DropDownVisible)
{
return propertyGridView.DropDownControlHolder.AccessibilityObject;
return _owningPropertyGridView.DropDownControlHolder.AccessibilityObject;
}
}

Expand All @@ -77,9 +80,9 @@ internal override UiaCore.IRawElementProviderFragment FragmentNavigate(UiaCore.N
/// Gets the top level element.
/// </summary>
internal override UiaCore.IRawElementProviderFragmentRoot FragmentRoot
=> propertyGridView.AccessibilityObject;
=> _owningPropertyGridView.AccessibilityObject;

internal override object GetPropertyValue(UiaCore.UIA propertyID)
internal override object? GetPropertyValue(UiaCore.UIA propertyID)
{
switch (propertyID)
{
Expand All @@ -99,22 +102,25 @@ internal override object GetPropertyValue(UiaCore.UIA propertyID)
return NativeMethods.WinFormFrameworkId;
case UiaCore.UIA.IsValuePatternAvailablePropertyId:
return IsPatternSupported(UiaCore.UIA.ValuePatternId);
case UiaCore.UIA.IsTextPatternAvailablePropertyId:
return IsPatternSupported(UiaCore.UIA.TextPatternId);
case UiaCore.UIA.IsTextPattern2AvailablePropertyId:
return IsPatternSupported(UiaCore.UIA.TextPattern2Id);
}

return base.GetPropertyValue(propertyID);
}

internal override bool IsPatternSupported(UiaCore.UIA patternId)
{
if (patternId == UiaCore.UIA.ValuePatternId)
=> patternId switch
{
return true;
}

return base.IsPatternSupported(patternId);
}
UiaCore.UIA.ValuePatternId => true,
UiaCore.UIA.TextPatternId => true,
UiaCore.UIA.TextPattern2Id => true,
_ => base.IsPatternSupported(patternId)
};

internal override UiaCore.IRawElementProviderSimple HostRawElementProvider
internal override UiaCore.IRawElementProviderSimple? HostRawElementProvider
{
get
{
Expand All @@ -126,7 +132,7 @@ internal override UiaCore.IRawElementProviderSimple HostRawElementProvider
}
}

public override string Name
public override string? Name
{
get
{
Expand All @@ -137,7 +143,7 @@ public override string Name
}
else
{
GridEntry selectedGridEntry = propertyGridView.SelectedGridEntry;
GridEntry selectedGridEntry = _owningPropertyGridView.SelectedGridEntry;
if (selectedGridEntry != null)
{
return selectedGridEntry.AccessibilityObject.Name;
Expand All @@ -149,12 +155,12 @@ public override string Name
set => base.Name = value;
}

internal override int[] RuntimeId
internal override int[]? RuntimeId
{
get
{
var selectedGridEntryAccessibleRuntimeId =
propertyGridView?.SelectedGridEntry?.AccessibilityObject?.RuntimeId;
_owningPropertyGridView?.SelectedGridEntry?.AccessibilityObject?.RuntimeId;

if (selectedGridEntryAccessibleRuntimeId is null)
{
Expand All @@ -179,7 +185,7 @@ internal override bool IsReadOnly
{
get
{
return !(propertyGridView.SelectedGridEntry is PropertyDescriptorGridEntry propertyDescriptorGridEntry) || propertyDescriptorGridEntry.IsPropertyReadOnly;
return !(_owningPropertyGridView.SelectedGridEntry is PropertyDescriptorGridEntry propertyDescriptorGridEntry) || propertyDescriptorGridEntry.IsPropertyReadOnly;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
// See the LICENSE file in the project root for more information.

using System.Drawing;
using System.Reflection;
using Xunit;
using static System.Windows.Forms.Control;
using static Interop;

namespace System.Windows.Forms.PropertyGridInternal.Tests
Expand Down Expand Up @@ -85,5 +87,56 @@ internal void SetState(int flag, bool value)
SetState((States)flag, value);
}
}

[WinFormsFact]
public void GridViewEditAccessibleObjectt_ctor_default()
{
using PropertyGrid propertyGrid = new PropertyGrid();
PropertyGridView gridView = propertyGrid.TestAccessor().GridView;
Type gridViewEditType = typeof(PropertyGridView).GetNestedType("GridViewEdit", BindingFlags.NonPublic);
Assert.NotNull(gridViewEditType);
TextBox gridViewEdit = (TextBox)Activator.CreateInstance(gridViewEditType, gridView);
Type accessibleObjectType = gridViewEditType.GetNestedType("GridViewEditAccessibleObject", BindingFlags.NonPublic);
Assert.NotNull(accessibleObjectType);
ControlAccessibleObject accessibleObject = (ControlAccessibleObject)Activator.CreateInstance(accessibleObjectType, gridViewEdit);
Assert.Equal(gridViewEdit, accessibleObject.Owner);
}

[WinFormsFact]
public void GridViewEditAccessibleObjectt_ctor_ThrowsException_IfOwnerIsNull()
{
using PropertyGrid propertyGrid = new PropertyGrid();
PropertyGridView gridView = propertyGrid.TestAccessor().GridView;
Type gridViewEditType = typeof(PropertyGridView).GetNestedType("GridViewEdit", BindingFlags.NonPublic);
Assert.NotNull(gridViewEditType);
TextBox gridViewEdit = (TextBox)Activator.CreateInstance(gridViewEditType, gridView);
Type accessibleObjectType = gridViewEditType.GetNestedType("GridViewEditAccessibleObject", BindingFlags.NonPublic);
Assert.NotNull(accessibleObjectType);
Assert.Throws<TargetInvocationException>(() => Activator.CreateInstance(accessibleObjectType, (TextBox)null));
}

[WinFormsTheory]
[InlineData((int)UiaCore.UIA.IsTextPatternAvailablePropertyId)]
[InlineData((int)UiaCore.UIA.IsTextPattern2AvailablePropertyId)]
[InlineData((int)UiaCore.UIA.IsValuePatternAvailablePropertyId)]
public void ToolStripTextBoxControlAccessibleObject_GetPropertyValue_PatternsSuported(int propertyID)
{
using PropertyGrid propertyGrid = new PropertyGrid();
PropertyGridView gridView = propertyGrid.TestAccessor().GridView;
AccessibleObject accessibleObject = gridView.EditAccessibleObject;
Assert.True((bool)accessibleObject.GetPropertyValue((UiaCore.UIA)propertyID));
}

[WinFormsTheory]
[InlineData((int)UiaCore.UIA.ValuePatternId)]
[InlineData((int)UiaCore.UIA.TextPatternId)]
[InlineData((int)UiaCore.UIA.TextPattern2Id)]
public void ToolStripTextBoxControlAccessibleObject_IsPatternSupported_PatternsSuported(int patternId)
{
using PropertyGrid propertyGrid = new PropertyGrid();
PropertyGridView gridView = propertyGrid.TestAccessor().GridView;
AccessibleObject accessibleObject = gridView.EditAccessibleObject;
Assert.True(accessibleObject.IsPatternSupported((UiaCore.UIA)patternId));
}
}
}