Skip to content

Commit

Permalink
I think the problem is being reproduced due to competitive requests t…
Browse files Browse the repository at this point in the history
…o Narrator. Periodically it announces expanded state information and periodically skips.

A possible fix is to replace the standard method "RaiseAutomationPropertyChangedEvent" with the "RaiseAutomationNotification" method. In this case, we force the expanded state information to be announced, which helps avoid a possible contention problem.
  • Loading branch information
SergeySmirnov-Akvelon authored and dkazennov committed Jun 15, 2022
1 parent ba2d521 commit e240517
Show file tree
Hide file tree
Showing 16 changed files with 152 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/System.Windows.Forms/src/Resources/SR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -6907,6 +6907,9 @@ Stack trace where the illegal operation occurred was:
<data name="EditDefaultAccessibleName" xml:space="preserve">
<value>Spinner</value>
</data>
<data name="ExpandedStateName" xml:space="preserve">
<value>Expanded</value>
</data>
<data name="ListViewItemAccessibilityObjectRequiresListView" xml:space="preserve">
<value>Cannot get accessiblity object when ListViewItem is not attached to a ListView.</value>
</data>
Expand Down
5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.pt-BR.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.ru.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.tr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.zh-Hans.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/System.Windows.Forms/src/Resources/xlf/SR.zh-Hant.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -1494,10 +1494,10 @@ public void DropDownControl(Control control)
if (gridEntry is not null && IsAccessibilityObjectCreated)
{
gridEntry.AccessibilityObject.RaiseAutomationEvent(UiaCore.UIA.AutomationFocusChangedEventId);
gridEntry.AccessibilityObject.RaiseAutomationPropertyChangedEvent(
UiaCore.UIA.ExpandCollapseExpandCollapseStatePropertyId,
UiaCore.ExpandCollapseState.Collapsed,
UiaCore.ExpandCollapseState.Expanded);
gridEntry.AccessibilityObject.InternalRaiseAutomationNotification(
Automation.AutomationNotificationKind.Other,
Automation.AutomationNotificationProcessing.ImportantMostRecent,
SR.ExpandedStateName);
}

// Control is a top level window. Standard way of setting parent on the control is prohibited for top-level controls.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// See the LICENSE file in the project root for more information.

using Xunit;
using System.ComponentModel;
using System.Windows.Forms.Automation;

namespace System.Windows.Forms.PropertyGridInternal.Tests
{
Expand All @@ -18,5 +20,83 @@ public void PropertyGridView_Ctor_Default()

Assert.NotNull(propertyGridView);
}

[WinFormsFact]
public void PropertyGridView_GridEntry_AccessibleObject_GetsNotification()
{
using PropertyGrid propertyGrid = new();
propertyGrid.CreateControl();
PropertyGridView propertyGridView = propertyGrid.TestAccessor().Dynamic._gridView;
AccessibleObject propertyGridViewAccessibilityObject = propertyGridView.AccessibilityObject;
TestGridEntry parent = new(propertyGrid, parent: null, propertyGridView);
PropertyDescriptor propertyDescriptor = TypeDescriptor.GetProperties(typeof(TestEntity)).
Find(nameof(TestEntity.SizeProperty), ignoreCase: false);

GridEntryWithCustomAccessibleObject testGridEntry = new(propertyGrid, parent, propertyDescriptor, hide: false);
GridEntryAccessibleObjectWithNotificationCounter accessibleObject = (GridEntryAccessibleObjectWithNotificationCounter)testGridEntry.AccessibilityObject;
Assert.Equal(0, accessibleObject.RaiseAutomationNotificationCallCount);

using Button button = new();
propertyGrid.SelectedObject = button;
GridEntryCollection gridEntries = propertyGridView.TestAccessor().Dynamic._allGridEntries;
gridEntries.Insert(0, testGridEntry);

propertyGridView.SelectedGridEntry = testGridEntry;
GridEntry selectedGridEntry = propertyGridView.TestAccessor().Dynamic._selectedGridEntry;
int selectedRow = propertyGridView.TestAccessor().Dynamic._selectedRow;

Assert.True(propertyGridView.IsAccessibilityObjectCreated);
Assert.Equal(testGridEntry, selectedGridEntry);
Assert.Equal(testGridEntry, gridEntries[selectedRow]);
propertyGridView.DropDownControl(new Control());

Assert.Equal(1, accessibleObject.RaiseAutomationNotificationCallCount);
Assert.True(propertyGrid.IsHandleCreated);
Assert.True(propertyGridView.IsHandleCreated);
}

private class TestGridEntry : GridEntry
{
private readonly PropertyGridView _propertyGridView;

public TestGridEntry(PropertyGrid ownerGrid, GridEntry parent, PropertyGridView propertyGridView)
: base(ownerGrid, parent)
{
_propertyGridView = propertyGridView;
}

internal override PropertyGridView OwnerGridView => _propertyGridView;
}

private class GridEntryWithCustomAccessibleObject : PropertyDescriptorGridEntry
{
public GridEntryWithCustomAccessibleObject(PropertyGrid ownerGrid, GridEntry parent, PropertyDescriptor propertyDescriptor, bool hide)
: base(ownerGrid, parent, propertyDescriptor, hide)
{
}

protected override GridEntryAccessibleObjectWithNotificationCounter GetAccessibilityObject() => new(this);
}

private class GridEntryAccessibleObjectWithNotificationCounter : GridEntry.GridEntryAccessibleObject
{
public GridEntryAccessibleObjectWithNotificationCounter(GridEntry owner) : base(owner)
{
}

public int RaiseAutomationNotificationCallCount { get; private set; }

internal override bool InternalRaiseAutomationNotification(AutomationNotificationKind notificationKind,
AutomationNotificationProcessing notificationProcessing, string notificationText)
{
RaiseAutomationNotificationCallCount++;
return base.InternalRaiseAutomationNotification(notificationKind, notificationProcessing, notificationText);
}
}

internal class TestEntity
{
public System.Drawing.Size SizeProperty { get; set; }
}
}
}

0 comments on commit e240517

Please sign in to comment.