Commit edccc9b7 authored by Weidong Guo's avatar Weidong Guo Committed by Commit Bot

Fix arrow button issue in tablet mode

Changes:
Only reset views::FocusManager::arrow_key_traversal_enabled_ when power
button menu is shown before.

Bug: 898716
Change-Id: I01de4fe8b9438e75d1104997aa0e90c61ae52dd2
Reviewed-on: https://chromium-review.googlesource.com/c/1300685
Commit-Queue: Weidong Guo <weidongg@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Reviewed-by: default avatarMin Chen <minch@chromium.org>
Cr-Commit-Position: refs/heads/master@{#603589}
parent 05faba13
...@@ -289,8 +289,6 @@ AppListView::AppListView(AppListViewDelegate* delegate) ...@@ -289,8 +289,6 @@ AppListView::AppListView(AppListViewDelegate* delegate)
std::make_unique<HideViewAnimationObserver>()), std::make_unique<HideViewAnimationObserver>()),
transition_animation_observer_( transition_animation_observer_(
std::make_unique<TransitionAnimationObserver>(this)), std::make_unique<TransitionAnimationObserver>(this)),
previous_arrow_key_traversal_enabled_(
views::FocusManager::arrow_key_traversal_enabled()),
state_animation_metrics_reporter_( state_animation_metrics_reporter_(
std::make_unique<StateAnimationMetricsReporter>()), std::make_unique<StateAnimationMetricsReporter>()),
is_home_launcher_enabled_(app_list_features::IsHomeLauncherEnabled()), is_home_launcher_enabled_(app_list_features::IsHomeLauncherEnabled()),
...@@ -298,18 +296,12 @@ AppListView::AppListView(AppListViewDelegate* delegate) ...@@ -298,18 +296,12 @@ AppListView::AppListView(AppListViewDelegate* delegate)
app_list_features::IsNewStyleLauncherEnabled()), app_list_features::IsNewStyleLauncherEnabled()),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
CHECK(delegate); CHECK(delegate);
// 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);
} }
AppListView::~AppListView() { AppListView::~AppListView() {
hide_view_animation_observer_.reset(); hide_view_animation_observer_.reset();
// Remove child views first to ensure no remaining dependencies on delegate_. // Remove child views first to ensure no remaining dependencies on delegate_.
RemoveAllChildViews(true); RemoveAllChildViews(true);
views::FocusManager::set_arrow_key_traversal_enabled(
previous_arrow_key_traversal_enabled_);
} }
// static // static
...@@ -592,6 +584,11 @@ void AppListView::InitializeFullscreen(gfx::NativeView parent) { ...@@ -592,6 +584,11 @@ void AppListView::InitializeFullscreen(gfx::NativeView parent) {
fullscreen_widget_->GetNativeView()->SetBounds( fullscreen_widget_->GetNativeView()->SetBounds(
GetPreferredWidgetBoundsForState(AppListViewState::CLOSED)); GetPreferredWidgetBoundsForState(AppListViewState::CLOSED));
// Enable arrow key in FocusManager. Arrow left/right and up/down triggers
// the same focus movement as tab/shift+tab.
fullscreen_widget_->GetFocusManager()
->set_arrow_key_traversal_enabled_for_widget(true);
widget_observer_ = std::make_unique<FullscreenWidgetObserver>(this); widget_observer_ = std::make_unique<FullscreenWidgetObserver>(this);
} }
......
...@@ -409,9 +409,6 @@ class APP_LIST_EXPORT AppListView : public views::WidgetDelegateView { ...@@ -409,9 +409,6 @@ class APP_LIST_EXPORT AppListView : public views::WidgetDelegateView {
// Accessibility announcement dialogue. // Accessibility announcement dialogue.
base::string16 state_announcement_; base::string16 state_announcement_;
// Whether FocusManager can handle arrow key before this class is constructed.
const bool previous_arrow_key_traversal_enabled_;
// Metric reporter for state change animations. // Metric reporter for state change animations.
const std::unique_ptr<ui::AnimationMetricsReporter> const std::unique_ptr<ui::AnimationMetricsReporter>
state_animation_metrics_reporter_; state_animation_metrics_reporter_;
......
...@@ -76,6 +76,11 @@ std::unique_ptr<views::Widget> CreateMenuWidget() { ...@@ -76,6 +76,11 @@ std::unique_ptr<views::Widget> CreateMenuWidget() {
gfx::Rect widget_bounds = gfx::Rect widget_bounds =
display::Screen::GetScreen()->GetPrimaryDisplay().bounds(); display::Screen::GetScreen()->GetPrimaryDisplay().bounds();
menu_widget->SetBounds(widget_bounds); menu_widget->SetBounds(widget_bounds);
// Enable arrow key in FocusManager. Arrow right/left and down/up triggers
// the same focus movement as tab/shift+tab.
menu_widget->GetFocusManager()->set_arrow_key_traversal_enabled_for_widget(
true);
return menu_widget; return menu_widget;
} }
...@@ -143,9 +148,7 @@ class PowerButtonController::ActiveWindowWidgetController ...@@ -143,9 +148,7 @@ class PowerButtonController::ActiveWindowWidgetController
PowerButtonController::PowerButtonController( PowerButtonController::PowerButtonController(
BacklightsForcedOffSetter* backlights_forced_off_setter) BacklightsForcedOffSetter* backlights_forced_off_setter)
: arrow_key_traversal_initially_enabled_( : backlights_forced_off_setter_(backlights_forced_off_setter),
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),
...@@ -347,8 +350,6 @@ void PowerButtonController::DismissMenu() { ...@@ -347,8 +350,6 @@ 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::StopForcingBacklightsOff() { void PowerButtonController::StopForcingBacklightsOff() {
...@@ -521,9 +522,6 @@ void PowerButtonController::LockScreenIfRequired() { ...@@ -521,9 +522,6 @@ 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);
} }
......
...@@ -237,9 +237,6 @@ class ASH_EXPORT PowerButtonController ...@@ -237,9 +237,6 @@ 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.
......
...@@ -68,8 +68,11 @@ bool FocusManager::OnKeyEvent(const ui::KeyEvent& event) { ...@@ -68,8 +68,11 @@ bool FocusManager::OnKeyEvent(const ui::KeyEvent& event) {
return false; return false;
} }
if (arrow_key_traversal_enabled_ && ProcessArrowKeyTraversal(event)) if ((arrow_key_traversal_enabled_ ||
arrow_key_traversal_enabled_for_widget_) &&
ProcessArrowKeyTraversal(event)) {
return false; return false;
}
// Intercept arrow key messages to switch between grouped views. // Intercept arrow key messages to switch between grouped views.
bool is_left = key_code == ui::VKEY_LEFT || key_code == ui::VKEY_UP; bool is_left = key_code == ui::VKEY_LEFT || key_code == ui::VKEY_UP;
......
...@@ -75,7 +75,7 @@ namespace ui { ...@@ -75,7 +75,7 @@ namespace ui {
class Accelerator; class Accelerator;
class AcceleratorTarget; class AcceleratorTarget;
class KeyEvent; class KeyEvent;
} } // namespace ui
namespace views { namespace views {
...@@ -176,9 +176,7 @@ class VIEWS_EXPORT FocusManager : public ViewObserver { ...@@ -176,9 +176,7 @@ class VIEWS_EXPORT FocusManager : public ViewObserver {
} }
// Get the reason why the focus most recently changed. // Get the reason why the focus most recently changed.
FocusChangeReason focus_change_reason() const { FocusChangeReason focus_change_reason() const { return focus_change_reason_; }
return focus_change_reason_;
}
// Clears the focused view. The window associated with the top root view gets // Clears the focused view. The window associated with the top root view gets
// the native focus (so we still get keyboard events). // the native focus (so we still get keyboard events).
...@@ -297,6 +295,13 @@ class VIEWS_EXPORT FocusManager : public ViewObserver { ...@@ -297,6 +295,13 @@ class VIEWS_EXPORT FocusManager : public ViewObserver {
return arrow_key_traversal_enabled_; return arrow_key_traversal_enabled_;
} }
// TODO(weidongg): converts compatible usages of
// |arrow_key_traversal_enabled_| to this (https://crbug.com/899431).
// Similar to above, but only for the widget that owns this FocusManager.
void set_arrow_key_traversal_enabled_for_widget(bool enabled) {
arrow_key_traversal_enabled_for_widget_ = enabled;
}
// Returns the next focusable view. Traversal starts at |starting_view|. If // Returns the next focusable view. Traversal starts at |starting_view|. If
// |starting_view| is NULL |starting_widget| is consuled to determine which // |starting_view| is NULL |starting_widget| is consuled to determine which
// Widget to start from. See // Widget to start from. See
...@@ -334,9 +339,13 @@ class VIEWS_EXPORT FocusManager : public ViewObserver { ...@@ -334,9 +339,13 @@ class VIEWS_EXPORT FocusManager : public ViewObserver {
// ViewObserver: // ViewObserver:
void OnViewIsDeleting(View* view) override; void OnViewIsDeleting(View* view) override;
// Whether arrow key traversal is enabled. // Whether arrow key traversal is enabled globally.
static bool arrow_key_traversal_enabled_; static bool arrow_key_traversal_enabled_;
// Whether arrow key traversal is enabled for all widgets under the top-level
// widget that owns the FocusManager.
bool arrow_key_traversal_enabled_for_widget_ = false;
// The top-level Widget this FocusManager is associated with. // The top-level Widget this FocusManager is associated with.
Widget* widget_; Widget* widget_;
......
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