diff --git a/src/System.Windows.Forms/System/Windows/Forms/Controls/RichTextBox/RichTextBox.cs b/src/System.Windows.Forms/System/Windows/Forms/Controls/RichTextBox/RichTextBox.cs index 4a6c7972a34..48b0044159c 100644 --- a/src/System.Windows.Forms/System/Windows/Forms/Controls/RichTextBox/RichTextBox.cs +++ b/src/System.Windows.Forms/System/Windows/Forms/Controls/RichTextBox/RichTextBox.cs @@ -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) { diff --git a/src/test/unit/System.Windows.Forms/System/Windows/Forms/RichTextBoxTests.cs b/src/test/unit/System.Windows.Forms/System/Windows/Forms/RichTextBoxTests.cs index 349b5f21983..662fae62fbf 100644 --- a/src/test/unit/System.Windows.Forms/System/Windows/Forms/RichTextBoxTests.cs +++ b/src/test/unit/System.Windows.Forms/System/Windows/Forms/RichTextBoxTests.cs @@ -10594,26 +10594,21 @@ public void RichTextBox_CheckRichEditWithVersionCanCreateOldVersions() [WinFormsTheory] [NewAndDefaultData] - 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 mockParent = new() { CallBase = true }; Mock mockAccessibleObject = new(MockBehavior.Strict, mockParent.Object); - mockAccessibleObject - .Setup(a => a.InternalRaiseAutomationNotification( - It.IsAny(), - It.IsAny(), - It.IsAny())) - .Returns(true) - .Verifiable(); mockParent.Protected().Setup("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 @@ -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(), + It.IsAny(), + It.IsAny()), + Times.Never); } [WinFormsTheory]