Commit 211cdf11 authored by Peter Boström's avatar Peter Boström Committed by Commit Bot

Keep focus inside BubbleDialogDelegateView

Removes Widget::SetFocusTraversableParent* calls since we don't want
focus to escape bubble dialogs once they get here. There are several
bubbles that close once focus escapes.

We still set kAnchoredDialogKey of the anchor view to make sure that
focus can move into attached dialogs (this makes them keyboard
accessible).

Bug: chromium:899601, chromium:899996
Change-Id: Idc5d60c2f41ae20a343324ae75b0fd304f273c94
Reviewed-on: https://chromium-review.googlesource.com/c/1311090Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Commit-Queue: Peter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604464}
parent 0c509ea6
...@@ -164,12 +164,6 @@ const char* BubbleDialogDelegateView::GetClassName() const { ...@@ -164,12 +164,6 @@ const char* BubbleDialogDelegateView::GetClassName() const {
return kViewClassName; return kViewClassName;
} }
void BubbleDialogDelegateView::AddedToWidget() {
DialogDelegateView::AddedToWidget();
if (GetAnchorView())
EnableFocusTraversalFromAnchorView();
}
void BubbleDialogDelegateView::OnWidgetDestroying(Widget* widget) { void BubbleDialogDelegateView::OnWidgetDestroying(Widget* widget) {
if (anchor_widget() == widget) if (anchor_widget() == widget)
SetAnchorView(NULL); SetAnchorView(NULL);
...@@ -271,17 +265,6 @@ void BubbleDialogDelegateView::OnAnchorBoundsChanged() { ...@@ -271,17 +265,6 @@ void BubbleDialogDelegateView::OnAnchorBoundsChanged() {
SizeToContents(); SizeToContents();
} }
void BubbleDialogDelegateView::EnableFocusTraversalFromAnchorView() {
DCHECK(GetWidget());
DCHECK(GetAnchorView());
DCHECK(anchor_widget());
GetWidget()->SetFocusTraversableParent(
anchor_widget()->GetFocusTraversable());
GetWidget()->SetFocusTraversableParentView(GetAnchorView());
GetAnchorView()->SetProperty(kAnchoredDialogKey,
static_cast<BubbleDialogDelegateView*>(this));
}
BubbleDialogDelegateView::BubbleDialogDelegateView() BubbleDialogDelegateView::BubbleDialogDelegateView()
: BubbleDialogDelegateView(nullptr, BubbleBorder::TOP_LEFT) {} : BubbleDialogDelegateView(nullptr, BubbleBorder::TOP_LEFT) {}
...@@ -349,13 +332,8 @@ void BubbleDialogDelegateView::OnNativeThemeChanged( ...@@ -349,13 +332,8 @@ void BubbleDialogDelegateView::OnNativeThemeChanged(
void BubbleDialogDelegateView::Init() {} void BubbleDialogDelegateView::Init() {}
void BubbleDialogDelegateView::SetAnchorView(View* anchor_view) { void BubbleDialogDelegateView::SetAnchorView(View* anchor_view) {
if (GetAnchorView()) { if (GetAnchorView())
if (GetWidget()) {
GetWidget()->SetFocusTraversableParent(nullptr);
GetWidget()->SetFocusTraversableParentView(nullptr);
}
GetAnchorView()->ClearProperty(kAnchoredDialogKey); GetAnchorView()->ClearProperty(kAnchoredDialogKey);
}
// When the anchor view gets set the associated anchor widget might // When the anchor view gets set the associated anchor widget might
// change as well. // change as well.
...@@ -388,10 +366,12 @@ void BubbleDialogDelegateView::SetAnchorView(View* anchor_view) { ...@@ -388,10 +366,12 @@ void BubbleDialogDelegateView::SetAnchorView(View* anchor_view) {
// point. (It's safe to skip this, since if we were to update the // point. (It's safe to skip this, since if we were to update the
// bounds when |anchor_view| is NULL, the bubble won't move.) // bounds when |anchor_view| is NULL, the bubble won't move.)
OnAnchorBoundsChanged(); OnAnchorBoundsChanged();
}
// Make sure that focus can move into here from the anchor view. If there's if (anchor_view) {
// no widget yet, focus traversal will be set up in ::AddedToWidget(). // Make sure that focus can move into here from the anchor view (but not
EnableFocusTraversalFromAnchorView(); // out, focus will cycle inside the dialog once it gets here).
anchor_view->SetProperty(kAnchoredDialogKey, this);
} }
} }
......
...@@ -49,7 +49,6 @@ class VIEWS_EXPORT BubbleDialogDelegateView : public DialogDelegateView, ...@@ -49,7 +49,6 @@ class VIEWS_EXPORT BubbleDialogDelegateView : public DialogDelegateView,
static Widget* CreateBubble(BubbleDialogDelegateView* bubble_delegate); static Widget* CreateBubble(BubbleDialogDelegateView* bubble_delegate);
// DialogDelegateView: // DialogDelegateView:
void AddedToWidget() override;
BubbleDialogDelegateView* AsBubbleDialogDelegate() override; BubbleDialogDelegateView* AsBubbleDialogDelegate() override;
bool ShouldShowCloseButton() const override; bool ShouldShowCloseButton() const override;
ClientView* CreateClientView(Widget* widget) override; ClientView* CreateClientView(Widget* widget) override;
...@@ -122,11 +121,6 @@ class VIEWS_EXPORT BubbleDialogDelegateView : public DialogDelegateView, ...@@ -122,11 +121,6 @@ class VIEWS_EXPORT BubbleDialogDelegateView : public DialogDelegateView,
// bounds change as a result of the widget's bounds changing. // bounds change as a result of the widget's bounds changing.
void OnAnchorBoundsChanged(); void OnAnchorBoundsChanged();
// If this is called, enables focus to traverse from the anchor view
// to inside this dialog and back out. This may become the default in
// the future.
void EnableFocusTraversalFromAnchorView();
protected: protected:
BubbleDialogDelegateView(); BubbleDialogDelegateView();
// |shadow| usually doesn't need to be explicitly set, just uses the default // |shadow| usually doesn't need to be explicitly set, just uses the default
......
...@@ -942,7 +942,10 @@ TEST_F(FocusManagerTest, NavigateIntoAnchoredDialog) { ...@@ -942,7 +942,10 @@ TEST_F(FocusManagerTest, NavigateIntoAnchoredDialog) {
new TestBubbleDialogDelegateView(parent3); new TestBubbleDialogDelegateView(parent3);
test::WidgetTest::WidgetAutoclosePtr bubble_widget( test::WidgetTest::WidgetAutoclosePtr bubble_widget(
BubbleDialogDelegateView::CreateBubble(bubble_delegate)); BubbleDialogDelegateView::CreateBubble(bubble_delegate));
bubble_delegate->EnableFocusTraversalFromAnchorView(); bubble_widget->SetFocusTraversableParent(
bubble_delegate->anchor_widget()->GetFocusTraversable());
bubble_widget->SetFocusTraversableParentView(parent3);
View* child1 = new View(); View* child1 = new View();
View* child2 = new View(); View* child2 = new View();
child1->SetFocusBehavior(View::FocusBehavior::ALWAYS); child1->SetFocusBehavior(View::FocusBehavior::ALWAYS);
...@@ -1003,7 +1006,9 @@ TEST_F(FocusManagerTest, AnchoredDialogOnContainerView) { ...@@ -1003,7 +1006,9 @@ TEST_F(FocusManagerTest, AnchoredDialogOnContainerView) {
new TestBubbleDialogDelegateView(parent_group); new TestBubbleDialogDelegateView(parent_group);
test::WidgetTest::WidgetAutoclosePtr bubble_widget( test::WidgetTest::WidgetAutoclosePtr bubble_widget(
BubbleDialogDelegateView::CreateBubble(bubble_delegate)); BubbleDialogDelegateView::CreateBubble(bubble_delegate));
bubble_delegate->EnableFocusTraversalFromAnchorView(); bubble_widget->SetFocusTraversableParent(
bubble_delegate->anchor_widget()->GetFocusTraversable());
bubble_widget->SetFocusTraversableParentView(parent_group);
View* child1 = new View(); View* child1 = new View();
View* child2 = new View(); View* child2 = new View();
child1->SetFocusBehavior(View::FocusBehavior::ALWAYS); child1->SetFocusBehavior(View::FocusBehavior::ALWAYS);
...@@ -1067,7 +1072,9 @@ TEST_F(FocusManagerTest, AnchoredDialogInDesktopNativeWidgetAura) { ...@@ -1067,7 +1072,9 @@ TEST_F(FocusManagerTest, AnchoredDialogInDesktopNativeWidgetAura) {
bubble_delegate->UseNativeWidgetAura(); bubble_delegate->UseNativeWidgetAura();
test::WidgetTest::WidgetAutoclosePtr bubble_widget( test::WidgetTest::WidgetAutoclosePtr bubble_widget(
BubbleDialogDelegateView::CreateBubble(bubble_delegate)); BubbleDialogDelegateView::CreateBubble(bubble_delegate));
bubble_delegate->EnableFocusTraversalFromAnchorView(); bubble_widget->SetFocusTraversableParent(
bubble_delegate->anchor_widget()->GetFocusTraversable());
bubble_widget->SetFocusTraversableParentView(parent2);
View* child = new View(); View* child = new View();
child->SetFocusBehavior(View::FocusBehavior::ALWAYS); child->SetFocusBehavior(View::FocusBehavior::ALWAYS);
bubble_widget->GetRootView()->AddChildView(child); bubble_widget->GetRootView()->AddChildView(child);
......
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