Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding TextPattern providers to Text controls (port from 5.0) #3853

Closed

Conversation

vladimir-krestov
Copy link
Contributor

@vladimir-krestov vladimir-krestov commented Sep 8, 2020

Fixes #1588
Related PR: #2701 (see comments for more information)

Proposed changes

  • Adding ITextPatternProvider and ITextPatternProvider2 and related imported accessibility interfaces to WinForms Accessibility
  • Implementing TextPattern Provider functionality to allow accessibility client apps interact and announce (screen readers) text content of the Text controls

Customer Impact

  • Visually impaired users will be able to read and interact with the text content of the input text elements
  • Text inputs and up-down inputs will be fully accessible

Regression?

  • No

Risk

  • Minimal

Before

  • Narrator does not announce the text navigation and selection of the TextBox, MaskedTextBox and other

After

  • Narrator announces the text content of the text input controls (navigation, selection)

Test methodology

  • Manual testing
  • Unit testing
  • Automation tests
  • CTI

Accessibility testing

  • Using Inspect and Narrator

Test environment(s)

  • .Net 5.0 Version: 5.0.0-rc.1.20431.5
  • Microsoft Windows [Version 10.0.19041.450]
Microsoft Reviewers: Open in CodeFlow

- Add ITextRange and ITextProvider interfaces as a base of TextPattern
  Refer to:
      https://docs.microsoft.com/dotnet/api/system.windows.automation.provider.itextprovider
      https://docs.microsoft.com/dotnet/api/system.windows.automation.provider.itextrangeprovider
- Implement UiaTextRange and UiaTextProvider to support text pattern in textbox controls
- Add tests
- Move IAutomationLiveRegion to Primitives

(cherry picked from commit 7545756)
- Implement base integration to AccessibleObject
- Add TextPattern support for TextBox (singleline and multiline) and MaskedTextBox
- Disable managed UiaTextProvider for RichTextBox to use native provider as the native
  Win32 RichEdit control already supports TextPattern.
  Return ControlAccessibleObject as AccessibilityInstance instead TextBoxBaseAccessibleObject
  (the latter supports managed UiaTextProvider).
- Add tests

Fixes dotnet#1588

(cherry picked from commit f2baffc)
@vladimir-krestov vladimir-krestov requested a review from a team as a code owner September 8, 2020 13:53
@ghost ghost assigned vladimir-krestov Sep 8, 2020
@vladimir-krestov vladimir-krestov added the waiting-review This item is waiting on review by one or more members of team label Sep 8, 2020
@vladimir-krestov vladimir-krestov added this to the 6.0 Preview1 milestone Sep 8, 2020
@RussKie RussKie changed the title Adding TextPattern providers to Text controls Adding TextPattern providers to Text controls (port from 5.0) Sep 9, 2020
@RussKie RussKie requested a review from JeremyKuhne September 9, 2020 06:55
@RussKie RussKie added Priority:1 Work that is critical for the release, but we could probably ship without and removed Priority:1 Work that is critical for the release, but we could probably ship without labels Sep 10, 2020

// Convert screen to client coordinates.
// (Essentially ScreenToClient but MapWindowPoints accounts for window mirroring using WS_EX_LAYOUTRTL.)
if (MapWindowPoints(new HandleRef(null, IntPtr.Zero), new HandleRef(this, _owningTextBoxBase.Handle), ref clientLocation, 1) == 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is technically incorrect. HandleRef should have the object that will potentially close the handle if disposed. this does have a handle to _owningTextBoxBase so that should root it. We should fix this in master and we should implement the IHandle overload on the P/Invoke as we do in other places to avoid this sort of mistake. Additionally we already have an overload that takes IntPtr for the first argument, we shouldn't be wrapping nothing in a HandleRef or at the very least we can pass default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I implemented IHandle overload for MapWindowPoints like this.
I orientated to SendMessageW methods.
image

And now the method call looks like this:
image

Is it correct?
I added this implementation to .Net 5.0-release in #3865


public override int LinesCount
=> _owningTextBoxBase.IsHandleCreated
? (int)(long)SendMessageW(new HandleRef(this, _owningTextBoxBase.Handle), (WM)EM.GETLINECOUNT)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above. In this case we already have an IHandle overload so you can just pass _owningTextBoxBase.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeremy, should I port this to #2701 (release-rc2)?


public abstract void SetSelection(int start, int end);

public ES GetEditStyle(IntPtr hWnd) => hWnd != IntPtr.Zero ? (ES)GetWindowLong(new HandleRef(null, hWnd), GWL.STYLE) : ES.LEFT;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we not rooting the objects that own the handles in these three methods (e.g. passing in IHandle or HandleRef)? Also, the check for a null HWND here indicates that we may be hiding some other bug- where are we passing in a null handle?


public override WS_EX WindowExStyle
=> _owningTextBoxBase.IsHandleCreated
? GetWindowExStyle(_owningTextBoxBase.Handle)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These calls are problematic as we're not keeping the _owningTextBoxBase rooted by pulling out the Handle and P\Invoking in the base class.

@vladimir-krestov vladimir-krestov removed the waiting-review This item is waiting on review by one or more members of team label Sep 15, 2020
@RussKie RussKie marked this pull request as draft September 17, 2020 23:40
@vladimir-krestov vladimir-krestov deleted the Issue_1588_TextPattern branch November 4, 2020 07:37
@ghost ghost added the draft draft PR label Sep 11, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Jan 30, 2022
@RussKie RussKie removed this from the 6.0 Preview1 milestone May 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
draft draft PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants