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

Replace UIA CompareInBounds with til::point comparators #14551

Merged
3 commits merged into from
Dec 19, 2022

Conversation

carlos-zamora
Copy link
Member

This PR replaces the uses of Viewport::CompareInBounds() in the UIA code with til::point comparators. Additionally, it simplifies the logic further by using std::max and std::min.

In doing so, we are no longer hitting the assert in CompareInBounds().

Closes #14542

@ghost ghost added Area-Accessibility Issues related to accessibility Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal. labels Dec 14, 2022
@carlos-zamora carlos-zamora changed the title dev/cazamor/a11y/comparisons Replace UIA CompareInBounds with til::point comparators Dec 14, 2022
@DHowett
Copy link
Member

DHowett commented Dec 14, 2022

Since this looks like a new version of #13244, which was reverted in #13907, I may need an explanation as to why the reason stated for the revert doesn't apply 😄

Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

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

as noted

@ghost ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Dec 14, 2022
@carlos-zamora
Copy link
Member Author

@DHowett

Ok. This is "great". Here's what happened:

        if (!bufferSize.IsInBounds(_start, true) || !bufferSize.IsInBounds(_end, true))
        {
            THROW_HR(E_FAIL);
        }
  • is replaced with this code:
        THROW_HR_IF(E_FAIL, !bufferSize.IsInBounds(_start) || !bufferSize.IsInBounds(_end));

@ghost ghost removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Dec 14, 2022
@carlos-zamora
Copy link
Member Author

We could still do the other CompareInBounds() replacements throughout the codebase (as in #13244). Figured specifically focusing on UIA would be nicer though.

@@ -293,7 +276,7 @@ void UiaTextRangeBase::_expandToEnclosingUnit(TextUnit unit)
// If we're past document end,
// set us to ONE BEFORE the document end.
// This allows us to expand properly.
if (bufferSize.CompareInBounds(_start, documentEnd, true) >= 0)
Copy link
Member

Choose a reason for hiding this comment

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

FYI: The final boolean parameter in CompareInBounds is ignored in Release mode builds anyways, so from a perspective of "could this potentially crash?" it doesn't matter if the old code used to have true, false, or no boolean argument at all.

Comment on lines +1028 to +1029
_start = std::min(_start, documentEnd);
_end = std::min(_end, documentEnd);
Copy link
Member

Choose a reason for hiding this comment

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

To make sure that the _start/_end range is properly degenerate here we'd have to use something like this right?

    _end = std::min(_end, documentEnd);
    _start = std::min(_start, _end);

Otherwise _start > _end is possible. I mean technically this function doesn't even touch these two members at this point, but this made me wonder if we should change IsDegenerate() from _start == _end to _start >= _end just in case?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm conflicted. On one hand, IsDegenerate() would be fixed, but on the other hand, we clearly messed up if _start > _end at any point. These two lines help alleviate that by clamping down to documentEnd. Maybe adding an assert(_start <= _end) in IsDegenerate() would be good to detect if we ever run into that? idk, if that would be useful though. idk.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure what to do either, but I personally would make the change to IsDegenerate() regardless. Simply because bugs will exist in our code regardless of how hard we try, so we might as well build our code around that assumption. But I could also be completely wrong about it here, since I'm not completely familiar with how IsDegenerate() is used and whether such a change would make any tangible safety improvements at all in the first place.
assert()s are IMO a great idea in either case, and the more we use them the better, because it's like test driven programming, but at runtime and it's more productive (arguably). 😅

Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

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

Way cleaner! Thanks!

@carlos-zamora carlos-zamora added the AutoMerge Marked for automatic merge by the bot when requirements are met label Dec 19, 2022
@ghost
Copy link

ghost commented Dec 19, 2022

Hello @carlos-zamora!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 7ab0e98 into main Dec 19, 2022
@ghost ghost deleted the dev/cazamor/a11y/comparisons branch December 19, 2022 18:09
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Accessibility Issues related to accessibility AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using Narrator on a newly opened tab hits an assert
3 participants