Commit a71ca1b7 authored by Min Chen's avatar Min Chen Committed by Commit Bot

Enable arrow key in PowerButtonController instead of PowerButtonMenuScreenView.

The contents view of |menu_widget_| in PowerButtonController will be updated
when showing menu, which means the destructor of PowerButtonMenuScreenView
will not be called when DismissMenu. This will cause the arrow key traversal
enabled value in FocusManager will not be restored correctly. Move the logic from
PowerbuttonMenuScreenView into PowerButtonController to make sure the value
can be restored correctly if dismiss the menu.

Bug: 846639
Change-Id: I32ceebb8e81cf19e3fed119af0ccee3bd8c55638
Reviewed-on: https://chromium-review.googlesource.com/1114309
Commit-Queue: Min Chen <minch@chromium.org>
Reviewed-by: default avatarQiang Xu <warx@google.com>
Reviewed-by: default avatarDan Erat <derat@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570323}
parent a8c3e9c8
...@@ -145,7 +145,9 @@ class PowerButtonController::ActiveWindowWidgetController ...@@ -145,7 +145,9 @@ class PowerButtonController::ActiveWindowWidgetController
PowerButtonController::PowerButtonController( PowerButtonController::PowerButtonController(
BacklightsForcedOffSetter* backlights_forced_off_setter) BacklightsForcedOffSetter* backlights_forced_off_setter)
: backlights_forced_off_setter_(backlights_forced_off_setter), : arrow_key_traversal_initially_enabled_(
views::FocusManager::arrow_key_traversal_enabled()),
backlights_forced_off_setter_(backlights_forced_off_setter),
lock_state_controller_(Shell::Get()->lock_state_controller()), lock_state_controller_(Shell::Get()->lock_state_controller()),
tick_clock_(base::DefaultTickClock::GetInstance()), tick_clock_(base::DefaultTickClock::GetInstance()),
backlights_forced_off_observer_(this), backlights_forced_off_observer_(this),
...@@ -348,6 +350,8 @@ void PowerButtonController::DismissMenu() { ...@@ -348,6 +350,8 @@ void PowerButtonController::DismissMenu() {
show_menu_animation_done_ = false; show_menu_animation_done_ = false;
active_window_widget_controller_.reset(); active_window_widget_controller_.reset();
views::FocusManager::set_arrow_key_traversal_enabled(
arrow_key_traversal_initially_enabled_);
} }
void PowerButtonController::OnDisplayModeChanged( void PowerButtonController::OnDisplayModeChanged(
...@@ -511,6 +515,9 @@ void PowerButtonController::LockScreenIfRequired() { ...@@ -511,6 +515,9 @@ void PowerButtonController::LockScreenIfRequired() {
void PowerButtonController::SetShowMenuAnimationDone() { void PowerButtonController::SetShowMenuAnimationDone() {
show_menu_animation_done_ = true; show_menu_animation_done_ = true;
// Enable arrow key in FocusManager. Arrow right/left and down/up triggers
// the same focus movement as tab/shift+tab.
views::FocusManager::set_arrow_key_traversal_enabled(true);
pre_shutdown_timer_.Start(FROM_HERE, kStartShutdownAnimationTimeout, this, pre_shutdown_timer_.Start(FROM_HERE, kStartShutdownAnimationTimeout, this,
&PowerButtonController::OnPreShutdownTimeout); &PowerButtonController::OnPreShutdownTimeout);
} }
......
...@@ -230,6 +230,9 @@ class ASH_EXPORT PowerButtonController ...@@ -230,6 +230,9 @@ class ASH_EXPORT PowerButtonController
// True if the next button release event should force the display off. // True if the next button release event should force the display off.
bool force_off_on_button_up_ = false; bool force_off_on_button_up_ = false;
// Whether FocusManager can handle arrow key before showing the power menu.
const bool arrow_key_traversal_initially_enabled_;
// Used to force backlights off, when needed. // Used to force backlights off, when needed.
BacklightsForcedOffSetter* backlights_forced_off_setter_; // Not owned. BacklightsForcedOffSetter* backlights_forced_off_setter_; // Not owned.
......
...@@ -108,9 +108,7 @@ PowerButtonMenuScreenView::PowerButtonMenuScreenView( ...@@ -108,9 +108,7 @@ PowerButtonMenuScreenView::PowerButtonMenuScreenView(
double power_button_offset_percentage, double power_button_offset_percentage,
base::RepeatingClosure show_animation_done) base::RepeatingClosure show_animation_done)
: power_button_position_(power_button_position), : power_button_position_(power_button_position),
power_button_offset_percentage_(power_button_offset_percentage), power_button_offset_percentage_(power_button_offset_percentage) {
arrow_key_traversal_initially_enabled_(
views::FocusManager::arrow_key_traversal_enabled()) {
power_button_screen_background_shield_ = power_button_screen_background_shield_ =
new PowerButtonMenuBackgroundView(show_animation_done); new PowerButtonMenuBackgroundView(show_animation_done);
AddChildView(power_button_screen_background_shield_); AddChildView(power_button_screen_background_shield_);
...@@ -122,16 +120,11 @@ PowerButtonMenuScreenView::PowerButtonMenuScreenView( ...@@ -122,16 +120,11 @@ PowerButtonMenuScreenView::PowerButtonMenuScreenView(
if (power_button_position_ != PowerButtonPosition::NONE) if (power_button_position_ != PowerButtonPosition::NONE)
InitializeMenuBoundsOrigins(); InitializeMenuBoundsOrigins();
// Enable arrow key in FocusManager. Arrow left/right and up/down triggers
// the same focus movement as tab/shift+tab.
views::FocusManager::set_arrow_key_traversal_enabled(true);
AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
} }
PowerButtonMenuScreenView::~PowerButtonMenuScreenView() { PowerButtonMenuScreenView::~PowerButtonMenuScreenView() {
display::Screen::GetScreen()->RemoveObserver(this); display::Screen::GetScreen()->RemoveObserver(this);
views::FocusManager::set_arrow_key_traversal_enabled(
arrow_key_traversal_initially_enabled_);
} }
void PowerButtonMenuScreenView::ScheduleShowHideAnimation(bool show) { void PowerButtonMenuScreenView::ScheduleShowHideAnimation(bool show) {
......
...@@ -80,9 +80,6 @@ class ASH_EXPORT PowerButtonMenuScreenView : public views::View, ...@@ -80,9 +80,6 @@ class ASH_EXPORT PowerButtonMenuScreenView : public views::View,
// The origin of the menu bounds in different screen orientations. // The origin of the menu bounds in different screen orientations.
std::unordered_map<OrientationLockType, gfx::Point> menu_bounds_origins_; std::unordered_map<OrientationLockType, gfx::Point> menu_bounds_origins_;
// Whether FocusManager can handle arrow key before this class is constructed.
const bool arrow_key_traversal_initially_enabled_;
DISALLOW_COPY_AND_ASSIGN(PowerButtonMenuScreenView); DISALLOW_COPY_AND_ASSIGN(PowerButtonMenuScreenView);
}; };
......
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