Commit 73d464a6 authored by Andrew Xu's avatar Andrew Xu Committed by Commit Bot

[Shelf] Show navigation widget before setting the focus

The native view of the navigation widget is not activatable when its
target visibility is false. As a result, when the navigation widget
is hidden, it fails to get the focus through the FOCUS_SHELF
accelerator.

This CL fixes the issue by showing the navigation widget before setting
the focus.

Bug: 1111426
Change-Id: I9a1303ff6170eb98b255e6ce5d3814efce4d08c6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2337097
Commit-Queue: Andrew Xu <andrewxu@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#794746}
parent 9c1c99e9
...@@ -65,7 +65,7 @@ void ShelfFocusCycler::FocusNavigation(bool last_element) { ...@@ -65,7 +65,7 @@ void ShelfFocusCycler::FocusNavigation(bool last_element) {
FocusOut(last_element, SourceView::kShelfNavigationView); FocusOut(last_element, SourceView::kShelfNavigationView);
return; return;
} }
navigation_widget->SetDefaultLastFocusableChild(last_element); navigation_widget->PrepareForGettingFocus(last_element);
Shell::Get()->focus_cycler()->FocusWidget(navigation_widget); Shell::Get()->focus_cycler()->FocusWidget(navigation_widget);
} }
......
...@@ -577,6 +577,26 @@ TEST_P(ShelfLayoutManagerTest, VisibleWhenLockScreenShowing) { ...@@ -577,6 +577,26 @@ TEST_P(ShelfLayoutManagerTest, VisibleWhenLockScreenShowing) {
GetShelfWidget()->GetBackgroundType()); GetShelfWidget()->GetBackgroundType());
} }
// Verifies that the hidden shelf shows after triggering the FOCUS_SHELF
// accelerator (https://crbug.com/1111426).
TEST_F(ShelfLayoutManagerTest, ShowHiddenShelfByFocusShelfAccelerator) {
// Open a window so that the shelf will auto-hide.
std::unique_ptr<aura::Window> window(CreateTestWindow());
window->Show();
Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Focus on the shelf by accelerator.
Shell::Get()->accelerator_controller()->PerformActionIfEnabled(FOCUS_SHELF,
{});
// Shelf should be visible.
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
}
TEST_F(ShelfLayoutManagerTest, ShelfDoesNotAutoHideWithVoxAndTabletMode) { TEST_F(ShelfLayoutManagerTest, ShelfDoesNotAutoHideWithVoxAndTabletMode) {
TabletModeControllerTestApi().EnterTabletMode(); TabletModeControllerTestApi().EnterTabletMode();
// Open a window so that the shelf will auto-hide. // Open a window so that the shelf will auto-hide.
......
...@@ -666,6 +666,21 @@ gfx::Rect ShelfNavigationWidget::GetVisibleBounds() const { ...@@ -666,6 +666,21 @@ gfx::Rect ShelfNavigationWidget::GetVisibleBounds() const {
return gfx::Rect(target_bounds_.origin(), clip_rect_.size()); return gfx::Rect(target_bounds_.origin(), clip_rect_.size());
} }
void ShelfNavigationWidget::PrepareForGettingFocus(bool last_element) {
SetDefaultLastFocusableChild(last_element);
// The native view of the navigation widget is not activatable when its target
// visibility is false. So show the widget before setting focus.
// Layer opacity should be set first. Because it is not allowed that a window
// is visible but the layers alpha is fully transparent.
ui::Layer* layer = GetLayer();
if (layer->GetTargetOpacity() != 1.f)
GetLayer()->SetOpacity(1.f);
if (!IsVisible())
ShowInactive();
}
void ShelfNavigationWidget::HandleLocaleChange() { void ShelfNavigationWidget::HandleLocaleChange() {
delegate_->home_button()->HandleLocaleChange(); delegate_->home_button()->HandleLocaleChange();
delegate_->back_button()->HandleLocaleChange(); delegate_->back_button()->HandleLocaleChange();
......
...@@ -84,6 +84,9 @@ class ASH_EXPORT ShelfNavigationWidget : public ShelfComponent, ...@@ -84,6 +84,9 @@ class ASH_EXPORT ShelfNavigationWidget : public ShelfComponent,
// Returns the visible part's bounds in screen coordinates. // Returns the visible part's bounds in screen coordinates.
gfx::Rect GetVisibleBounds() const; gfx::Rect GetVisibleBounds() const;
// Do preparations before setting focus on the navigation widget.
void PrepareForGettingFocus(bool last_element);
// Called when shelf layout manager detects a locale change. Reloads the // Called when shelf layout manager detects a locale change. Reloads the
// home and back button tooltips and accessibility name strings. // home and back button tooltips and accessibility name strings.
void HandleLocaleChange(); void HandleLocaleChange();
......
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