Skip to content

Read-only states for UIA objects#10494

Merged
feerrenrut merged 10 commits into
nvaccess:masterfrom
francipvb:uia-readonly-state
Jul 23, 2020
Merged

Read-only states for UIA objects#10494
feerrenrut merged 10 commits into
nvaccess:masterfrom
francipvb:uia-readonly-state

Conversation

@francipvb

@francipvb francipvb commented Nov 14, 2019

Copy link
Copy Markdown
Contributor

Link to issue number:

None.

Summary of the issue:

For various WPF text controls, read-only state isn't added. This is because the current implementation only tries to get the ValueIsReadOnly property. However WPF text controls don't support it.

Description of how this pull request fixes the issue:

This PR adds checks and looks at the document range from the text pattern, if the control implements it. Then it checks for the Is Read-Only attribute and adds the state according to the returned value.

Testing performed:

Tested with output text view of Visual Studio 2019.

Known issues with pull request:

None known.

Change log entry:

Section: Changes

  • Now NVDA detects more read-only text UIA controls.

@francipvb

Copy link
Copy Markdown
Contributor Author

CC @LeonarddeR @josephsl @Adriani90

@LeonarddeR

LeonarddeR commented Nov 15, 2019

Copy link
Copy Markdown
Collaborator

Thanks for this contribution. I think that the code will be more readable if the STATE_READONLY state is only added once in the code. Something like this:

		except COMError:
			isReadOnly=UIAHandler.handler.reservedNotSupportedValue
		if (
			isReadOnly == UIAHandler.handler.reservedNotSupportedValue
			and self.UIATextPattern
		):
			# Most UIA text controls don't support the "ValueIsReadOnly" property, so we need to
			# 	look at root document "IsReadOnly" attribute.
			document = self.UIATextPattern.documentRange
			isReadOnly = document.GetAttributeValue(UIAHandler.UIA_IsReadOnlyAttributeId)
		if isReadOnly != UIAHandler.handler.reservedNotSupportedValue:
			states.add(controlTypes.STATE_READONLY)

@francipvb francipvb marked this pull request as ready for review November 15, 2019 20:13
Comment thread source/NVDAObjects/UIA/__init__.py Outdated
if isReadOnly != UIAHandler.handler.reservedNotSupportedValue:
states.add(controlTypes.STATE_READONLY)

if (

This comment was marked as outdated.

Comment thread source/NVDAObjects/UIA/__init__.py Outdated
document = self.UIATextPattern.documentRange
isReadOnly = document.GetAttributeValue(UIAHandler.UIA_IsReadOnlyAttributeId)
# We can check "isReadOnly" again
if isReadOnly:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think reservedNotSupportedValue evaluates to True. I think we either need to do

Suggested change
if isReadOnly:
if isReadOnly and isReadOnly != UIAHandler.handler.reservedNotSupportedValue:

or

Suggested change
if isReadOnly:
if isReadOnly is True:

This is to ensure "isReadOnly" is not "reservedNotSupportedValue" when returning from
document range. Additionally, this value is set if there is a "COMError".
Applied suggested change from @LeonarddeR.

@LeonarddeR LeonarddeR left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for this.

One additional suggestion in which case this new patch improves things.

In the outlook appModule, OutlookUIAWordDocument class, the isReadonlyViewer property can now simply return controlTypes.STATE_READONLY in self.states. SO, we no longer have to rely on the object model.

I leave it up to you whether you want to file this as a separate pr after this one, or do it in this one. I think it makes sense to do it as part of this pr.

Now it reports the read-only flag according to the state if it is added
to the "states" set.

@LeonarddeR LeonarddeR left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @francipvb, confirmed that Outlook still behaves as expected with this.

@LeonarddeR

Copy link
Copy Markdown
Collaborator

@michaelDCurran I think this code looks ok. Could either you or @feerrenrut have a look? This one is pretty small, so shouldn't take longer than a minute or five.

@feerrenrut feerrenrut left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall this looks good, thank you @francipvb . Please let me know if you won't have time to extract the method.

Comment thread source/NVDAObjects/UIA/__init__.py Outdated
if self._getUIACacheablePropertyValue(UIAHandler.UIA_IsRequiredForFormPropertyId):
states.add(controlTypes.STATE_REQUIRED)

# Read-only state

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you please extract this whole section into a new private method _getIsReadOnlyState()

@francipvb

francipvb commented Jul 22, 2020 via email

Copy link
Copy Markdown
Contributor Author

@feerrenrut feerrenrut merged commit 124bb02 into nvaccess:master Jul 23, 2020
@nvaccessAuto nvaccessAuto added this to the 2020.3 milestone Jul 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants