Commit 6b73dc9f authored by Peter Boström's avatar Peter Boström Committed by Commit Bot

Fix escaping focus traversal from LoginUserMenu

Makes use of SetFocusTraversableParent to declare where focus should go
after the view has been fully traversed.

Fixes infinite recursion where LoginUserMenu would redirect focus to its
anchor and then forward focus (which takes it inside LoginUserMenu as
the dialog is anchored).

Bug: chromium:901456
Change-Id: I138be71866760de84980f5e4ca0c1b42d6d1793f
Reviewed-on: https://chromium-review.googlesource.com/c/1338222
Commit-Queue: Peter Boström <pbos@chromium.org>
Reviewed-by: default avatarJacob Dufault <jdufault@chromium.org>
Cr-Commit-Position: refs/heads/master@{#613367}
parent 697c453e
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "ui/views/focus/focus_manager.h" #include "ui/views/focus/focus_manager.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
#include "ui/views/layout/fill_layout.h" #include "ui/views/layout/fill_layout.h"
#include "ui/views/view_properties.h"
#include "ui/wm/core/coordinate_conversion.h" #include "ui/wm/core/coordinate_conversion.h"
namespace ash { namespace ash {
...@@ -325,11 +326,24 @@ class LoginUserMenuView : public LoginBaseBubbleView, ...@@ -325,11 +326,24 @@ class LoginUserMenuView : public LoginBaseBubbleView,
remove_user_button_->SetAccessibleName(remove_user_label_->text()); remove_user_button_->SetAccessibleName(remove_user_label_->text());
container->AddChildView(remove_user_button_); container->AddChildView(remove_user_button_);
} }
}
void RequestFocus() override {
// This view has no actual interesting contents to focus, so immediately
// forward to the button.
if (remove_user_button_)
remove_user_button_->RequestFocus();
}
// The user menu is focusable so that the we can detect when to refocus the void AddedToWidget() override {
// lock window from tab navigation, otherwise focus will be trapped inside LoginBaseBubbleView::AddedToWidget();
// of the bubble. // Set up focus traversable parent so that keyboard focus can continue in
SetFocusBehavior(views::View::FocusBehavior::ALWAYS); // the lock window, otherwise focus will be trapped inside the bubble.
if (GetAnchorView()) {
GetWidget()->SetFocusTraversableParent(
anchor_widget()->GetFocusTraversable());
GetWidget()->SetFocusTraversableParentView(GetAnchorView());
}
} }
~LoginUserMenuView() override = default; ~LoginUserMenuView() override = default;
...@@ -346,16 +360,6 @@ class LoginUserMenuView : public LoginBaseBubbleView, ...@@ -346,16 +360,6 @@ class LoginUserMenuView : public LoginBaseBubbleView,
size.Enlarge(kUserMenuMarginWidth, 0); size.Enlarge(kUserMenuMarginWidth, 0);
return size; return size;
} }
void OnFocus() override {
// This view has no actual interesting contents to focus, so immediately
// forward to the button.
remove_user_button_->RequestFocus();
}
void AboutToRequestFocusFromTabTraversal(bool reverse) override {
// Redirect the focus event to the lock screen.
Shell::Get()->focus_cycler()->FocusWidget(LockScreen::Get()->window());
LockScreen::Get()->window()->GetFocusManager()->AdvanceFocus(reverse);
}
// views::ButtonListener: // views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override { void ButtonPressed(views::Button* sender, const ui::Event& event) override {
...@@ -488,6 +492,7 @@ void LoginBubble::ShowUserMenu(const base::string16& username, ...@@ -488,6 +492,7 @@ void LoginBubble::ShowUserMenu(const base::string16& username,
this, username, email, type, is_owner, anchor_view, bubble_opener, this, username, email, type, is_owner, anchor_view, bubble_opener,
show_remove_user, std::move(on_remove_user_warning_shown), show_remove_user, std::move(on_remove_user_warning_shown),
std::move(on_remove_user_requested)); std::move(on_remove_user_requested));
// Prevent focus from going into |bubble_view_|.
bool had_focus = bubble_view_->GetBubbleOpener() && bool had_focus = bubble_view_->GetBubbleOpener() &&
bubble_view_->GetBubbleOpener()->HasFocus(); bubble_view_->GetBubbleOpener()->HasFocus();
Show(); Show();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment