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

Fixing switching focus between ToolStrips where TabStop=true with Shift-Tab #5842

Conversation

ArtemTatarinov
Copy link
Contributor

@ArtemTatarinov ArtemTatarinov commented Sep 22, 2021

Fixes #5795

Proposed changes

  • Adapted the logic of the forward block of the if statement to the backward block - no special treatment for the ToolStrip is needed
  • Changed forward condition at the GetNextItem method at the ToolStrip class because it is called after moving focus to the ToolStrip, but when TabStop is true the first item should be always focused
  • Added unit test for checking focus cycling

Customer Impact

  • Before the fix (focus was trapped at the last ToolStrip item while pressing Shift+Tab):
    shiftTabNotWorking

  • After the fix (focus isn't trapped at the last ToolStrip item while pressing Shift+Tab):
    shiftTabWorking

Regression?

  • No

Risk

  • Minimal

Test methodology

  • Manual testing
  • Unit test
  • CTI team

Test environment(s)

Microsoft Windows [Version 10.0.19043.1237]
.NET SDK 7.0.0-alpha.1.21471.1

Microsoft Reviewers: Open in CodeFlow

@ArtemTatarinov ArtemTatarinov requested a review from a team as a code owner September 22, 2021 15:59
@ghost ghost assigned ArtemTatarinov Sep 22, 2021
@ArtemTatarinov ArtemTatarinov added the waiting-review This item is waiting on review by one or more members of team label Sep 22, 2021
@ArtemTatarinov ArtemTatarinov force-pushed the Issue_5795_Fixing_ShiftTabSwitchingBetweenToolStrips branch from 88e8440 to 94d7ef9 Compare September 23, 2021 12:27
@ArtemTatarinov ArtemTatarinov force-pushed the Issue_5795_Fixing_ShiftTabSwitchingBetweenToolStrips branch from 94d7ef9 to 8f6d774 Compare September 29, 2021 14:05
Copy link
Member

@Tanya-Solyanik Tanya-Solyanik left a comment

Choose a reason for hiding this comment

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

Could you please explain why tool strip is a special case?

@ArtemTatarinov ArtemTatarinov force-pushed the Issue_5795_Fixing_ShiftTabSwitchingBetweenToolStrips branch from ac280ca to 5c34ffd Compare September 30, 2021 11:48
@ArtemTatarinov
Copy link
Contributor Author

@Tanya-Solyanik, thank you very much for your review points! While fixing them I've got another solution for the issue and it seems to me more compact and consistent than the previous two. I have adapted the logic of the forward block of the if statement to the backward block - and now no special treatment for the ToolStrip is needed (also I have applied your review points where it was possible).

In the future PR I can refactor both of the forward and backward blocks: extract the common code to separate methods and so on, but now, I guess, it's better not to touch forward code so we can isolate fixing the issue without any other factors. Also, I haven't extracted new methods from the backward block too (except for the one tiny helper method) to keep the changes as close to the original code as possible.

I have manually tested the ToolStrips - Shift+Tab works fines.
RTL=No
shift-tab

RTL=Yes
shift-tab-rtl

Also, I have manually tested all the controls at the child test forms called by these buttons: "Buttons", "ListView", "Calendar", "FontNameEditor", "Multiple Controls", "CollectionEditors", "ComboBoxes", "RichTextBoxes", "ComboBoxes with ScrollBars", "PictureBoxes", "Dialogs", "DataGridView", "FileDialog", "DataGridView in Virtual mode", "ErrorProvider", "Task Dialog", "ContentAlignment", "MessageBox", "Menus", "Panels", "TrackBars", "ScrollBars", "MDI Parent", "ToolTips", "PropertyGrid" (at our test application WinformsControlsTest). Moving focus backward works fine there too.
image

And I have run all unit tests for Control and ToolStrip classes - they're ok.

And just to be sure this solution doesn't affect moving focus when TabStop is false I tested this case for ToolStrips too for both RTL=Yes and RTL=No modes, everything is fine.

@ArtemTatarinov ArtemTatarinov force-pushed the Issue_5795_Fixing_ShiftTabSwitchingBetweenToolStrips branch from 5c34ffd to de51a11 Compare October 1, 2021 14:17
@Tanya-Solyanik
Copy link
Member

@ArtemTatarinov - thank you for the detailed description of testing! This is very helpful!
I agree that follow up clean up is better to put into a separate PR, but please do it while the code is fresh in your mind.

Copy link
Member

@Tanya-Solyanik Tanya-Solyanik left a comment

Choose a reason for hiding this comment

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

Looks good, please address the comment about localization.

@Tanya-Solyanik Tanya-Solyanik added 📭 waiting-author-feedback The team requires more information from the author and removed waiting-review This item is waiting on review by one or more members of team labels Oct 2, 2021
@ghost ghost removed the 📭 waiting-author-feedback The team requires more information from the author label Oct 4, 2021
@ArtemTatarinov ArtemTatarinov force-pushed the Issue_5795_Fixing_ShiftTabSwitchingBetweenToolStrips branch from de51a11 to ad7773d Compare October 4, 2021 07:47
@ArtemTatarinov ArtemTatarinov added the waiting-review This item is waiting on review by one or more members of team label Oct 4, 2021
Copy link
Member

@Tanya-Solyanik Tanya-Solyanik left a comment

Choose a reason for hiding this comment

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

Looks good

@Tanya-Solyanik Tanya-Solyanik added TestingDelayed ready-to-merge PRs that are ready to merge but worth notifying the internal team. and removed waiting-review This item is waiting on review by one or more members of team labels Oct 5, 2021
@Tanya-Solyanik
Copy link
Member

Tanya-Solyanik commented Oct 5, 2021

Tests failed in release:

at System.Windows.Forms.Tests.RichTextBoxTests.RichTextBox_Text_GetWithHandle_ReturnsExpected() in /_/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RichTextBoxTests.cs:line 6919
Assert.Equal() Failure\r\n          ↓ (pos 0)\r\nExpected: a b\r\nActual:    b\r\n          ↑ (pos 0)
 at System.Windows.Forms.Tests.DataGridViewTests.DataGridView_RowHeadersWidth_SetWithParentWithHandle_GetReturnsExpected(DataGridViewRowHeadersWidthSizeMode rowHeadersWidthSizeMode, Boolean rowHeadersVisible, Boolean autoSize, Int32 value, Int32 expectedValue, Int32 expectedInvalidatedCallCount, Int32 expectedLayoutCallCount, Int32 expectedParentLayoutCallCount) in /_/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewTests.cs:line 1208

Assert.Equal() Failure\r\nExpected: 1\r\nActual:   3

@Tanya-Solyanik
Copy link
Member

Tanya-Solyanik commented Oct 5, 2021

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@ghost
Copy link

ghost commented Oct 5, 2021

Hello @Tanya-Solyanik!

Because this pull request has the :octocat: 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.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Happy to oblige

@ghost ghost merged commit 0405ba2 into dotnet:main Oct 5, 2021
@ghost ghost added this to the 7.0 alpha1 milestone Oct 5, 2021
@ArtemTatarinov ArtemTatarinov deleted the Issue_5795_Fixing_ShiftTabSwitchingBetweenToolStrips branch October 6, 2021 09:47
ArtemTatarinov added a commit to ArtemTatarinov/winforms that referenced this pull request Oct 13, 2021
dreddy-work pushed a commit that referenced this pull request Oct 13, 2021
…ft-Tab (port to 7.0) (#5964)

* Revert only Control.cs from commit "Fixing switching focus between ToolStrips where TabStop=true with Shift-Tab (#5842)"

(0405ba2)

* Fixing moving focus backward with Shift-Tab at ToolStrip with TabStop=true.

If we don't found any siblings, and the control is a ToolStripItem that hosts a control itself, then we shouldn't return its parent, because it would be the same ToolStrip we're currently at. Instead, we should return the control that is previous to the current ToolStrip.

Debug.Asserts from 6.0 are replaced for Exceptions with localized strings

(cherry picked from commit 0e53ce7)
@ghost ghost locked as resolved and limited conversation to collaborators Jan 26, 2022
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
:octocat: automerge ready-to-merge PRs that are ready to merge but worth notifying the internal team.
Projects
None yet
4 participants