Skip to content
Open
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 @@ -2388,20 +2388,7 @@ protected virtual void OnContentsResized(ContentsResizedEventArgs e)
((ContentsResizedEventHandler?)Events[s_requestSizeEvent])?.Invoke(this, e);
}

protected override void OnGotFocus(EventArgs e)
{
base.OnGotFocus(e);

// Use parent's accessible object because RichTextBox doesn't support UIA Providers, and its
// AccessibilityObject doesn't get created even when assistive tech (e.g. Narrator) is used
if (Parent?.IsAccessibilityObjectCreated == true)
{
Parent.AccessibilityObject.InternalRaiseAutomationNotification(
Automation.AutomationNotificationKind.Other,
Automation.AutomationNotificationProcessing.MostRecent,
Text);
}
}
protected override void OnGotFocus(EventArgs e) => base.OnGotFocus(e);

protected override void OnHandleCreated(EventArgs e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10594,26 +10594,21 @@ public void RichTextBox_CheckRichEditWithVersionCanCreateOldVersions()

[WinFormsTheory]
[NewAndDefaultData<EventArgs>]
public void RichTextBox_OnGotFocus_RaisesAutomationNotification_WithText(EventArgs eventArgs)
public void RichTextBox_OnGotFocus_DoesNotRaiseAutomationNotification(EventArgs eventArgs)
{
// NVDA and JAWS already announce the focused line via native MSAA on focus; an additional
// UIA automation notification caused the line to be read twice. The correct behaviour is
// to let the native accessibility infrastructure handle the announcement.
Mock<Control> mockParent = new() { CallBase = true };
Mock<Control.ControlAccessibleObject> mockAccessibleObject = new(MockBehavior.Strict, mockParent.Object);
mockAccessibleObject
.Setup(a => a.InternalRaiseAutomationNotification(
It.IsAny<AutomationNotificationKind>(),
It.IsAny<AutomationNotificationProcessing>(),
It.IsAny<string>()))
.Returns(true)
.Verifiable();
mockParent.Protected().Setup<AccessibleObject>("CreateAccessibilityInstance")
.Returns(mockAccessibleObject.Object);

using Control parent = mockParent.Object;
string richTextBoxContent = "RichTextBox";
using SubRichTextBox control = new()
{
Parent = parent,
Text = richTextBoxContent,
Text = "RichTextBox",
};

// Enforce accessible object creation
Expand All @@ -10622,10 +10617,10 @@ public void RichTextBox_OnGotFocus_RaisesAutomationNotification_WithText(EventAr
control.OnGotFocus(eventArgs);

mockAccessibleObject.Verify(a => a.InternalRaiseAutomationNotification(
AutomationNotificationKind.Other,
AutomationNotificationProcessing.MostRecent,
richTextBoxContent),
Times.Once);
It.IsAny<AutomationNotificationKind>(),
It.IsAny<AutomationNotificationProcessing>(),
It.IsAny<string>()),
Times.Never);
}

[WinFormsTheory]
Expand Down
Loading