Commit 48c5ee02 authored by Hwanseung Lee's avatar Hwanseung Lee Committed by Commit Bot

Convert enum to enum class for FocusManager::FocusChangeReason

Use enum class instead of enum for FocusManager::FocusChangeReason
enum class is more type safety.

Bug: 940736
Change-Id: Ic635038be25929f3b9a233490617bdb5deb6d141
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1767281
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#689740}
parent 65dbb500
...@@ -161,6 +161,7 @@ bool AccessiblePaneView::AcceleratorPressed( ...@@ -161,6 +161,7 @@ bool AccessiblePaneView::AcceleratorPressed(
if (!ContainsForFocusSearch(this, focused_view)) if (!ContainsForFocusSearch(this, focused_view))
return false; return false;
using FocusChangeReason = views::FocusManager::FocusChangeReason;
switch (accelerator.key_code()) { switch (accelerator.key_code()) {
case ui::VKEY_ESCAPE: { case ui::VKEY_ESCAPE: {
RemovePaneFocus(); RemovePaneFocus();
...@@ -170,7 +171,7 @@ bool AccessiblePaneView::AcceleratorPressed( ...@@ -170,7 +171,7 @@ bool AccessiblePaneView::AcceleratorPressed(
last_focused_view = nullptr; last_focused_view = nullptr;
if (last_focused_view) { if (last_focused_view) {
focus_manager_->SetFocusedViewWithReason( focus_manager_->SetFocusedViewWithReason(
last_focused_view, FocusManager::kReasonFocusRestore); last_focused_view, FocusChangeReason::kFocusRestore);
} else if (allow_deactivate_on_esc_) { } else if (allow_deactivate_on_esc_) {
focused_view->GetWidget()->Deactivate(); focused_view->GetWidget()->Deactivate();
} }
...@@ -184,11 +185,11 @@ bool AccessiblePaneView::AcceleratorPressed( ...@@ -184,11 +185,11 @@ bool AccessiblePaneView::AcceleratorPressed(
return true; return true;
case ui::VKEY_HOME: case ui::VKEY_HOME:
focus_manager_->SetFocusedViewWithReason( focus_manager_->SetFocusedViewWithReason(
GetFirstFocusableChild(), views::FocusManager::kReasonFocusTraversal); GetFirstFocusableChild(), FocusChangeReason::kFocusTraversal);
return true; return true;
case ui::VKEY_END: case ui::VKEY_END:
focus_manager_->SetFocusedViewWithReason( focus_manager_->SetFocusedViewWithReason(
GetLastFocusableChild(), views::FocusManager::kReasonFocusTraversal); GetLastFocusableChild(), FocusChangeReason::kFocusTraversal);
return true; return true;
default: default:
return false; return false;
...@@ -228,7 +229,7 @@ void AccessiblePaneView::OnDidChangeFocus(views::View* focused_before, ...@@ -228,7 +229,7 @@ void AccessiblePaneView::OnDidChangeFocus(views::View* focused_before,
focus_manager_->focus_change_reason(); focus_manager_->focus_change_reason();
if (!ContainsForFocusSearch(this, focused_now) || if (!ContainsForFocusSearch(this, focused_now) ||
reason == views::FocusManager::kReasonDirectFocusChange) { reason == views::FocusManager::FocusChangeReason::kDirectFocusChange) {
// We should remove pane focus (i.e. make most of the controls // We should remove pane focus (i.e. make most of the controls
// not focusable again) because the focus has left the pane, // not focusable again) because the focus has left the pane,
// or because the focus changed within the pane due to the user // or because the focus changed within the pane due to the user
......
...@@ -94,7 +94,8 @@ bool FocusManager::OnKeyEvent(const ui::KeyEvent& event) { ...@@ -94,7 +94,8 @@ bool FocusManager::OnKeyEvent(const ui::KeyEvent& event) {
index = views.size() - 1; index = views.size() - 1;
else else
index += next ? 1 : -1; index += next ? 1 : -1;
SetFocusedViewWithReason(views[index], kReasonFocusTraversal); SetFocusedViewWithReason(views[index],
FocusChangeReason::kFocusTraversal);
return false; return false;
} }
} }
...@@ -136,7 +137,7 @@ void FocusManager::AdvanceFocus(bool reverse) { ...@@ -136,7 +137,7 @@ void FocusManager::AdvanceFocus(bool reverse) {
// FocusManager. // FocusManager.
DCHECK(v->GetWidget()); DCHECK(v->GetWidget());
v->GetWidget()->GetFocusManager()->SetFocusedViewWithReason( v->GetWidget()->GetFocusManager()->SetFocusedViewWithReason(
v, kReasonFocusTraversal); v, FocusChangeReason::kFocusTraversal);
// When moving focus from a child widget to a top-level widget, // When moving focus from a child widget to a top-level widget,
// the top-level widget may report IsActive()==true because it's // the top-level widget may report IsActive()==true because it's
...@@ -433,7 +434,7 @@ bool FocusManager::RestoreFocusedView() { ...@@ -433,7 +434,7 @@ bool FocusManager::RestoreFocusedView() {
if (!view->IsFocusable() && view->IsAccessibilityFocusable()) { if (!view->IsFocusable() && view->IsAccessibilityFocusable()) {
// RequestFocus would fail, but we want to restore focus to controls // RequestFocus would fail, but we want to restore focus to controls
// that had focus in accessibility mode. // that had focus in accessibility mode.
SetFocusedViewWithReason(view, kReasonFocusRestore); SetFocusedViewWithReason(view, FocusChangeReason::kFocusRestore);
} else { } else {
// This usually just sets the focus if this view is focusable, but // This usually just sets the focus if this view is focusable, but
// let the view override RequestFocus if necessary. // let the view override RequestFocus if necessary.
...@@ -442,7 +443,7 @@ bool FocusManager::RestoreFocusedView() { ...@@ -442,7 +443,7 @@ bool FocusManager::RestoreFocusedView() {
// If it succeeded, the reason would be incorrect; set it to // If it succeeded, the reason would be incorrect; set it to
// focus restore. // focus restore.
if (focused_view_ == view) if (focused_view_ == view)
focus_change_reason_ = kReasonFocusRestore; focus_change_reason_ = FocusChangeReason::kFocusRestore;
} }
} }
// The |keyboard_accessible_| mode may have changed while the widget was // The |keyboard_accessible_| mode may have changed while the widget was
......
...@@ -124,17 +124,17 @@ class VIEWS_EXPORT FocusChangeListener { ...@@ -124,17 +124,17 @@ class VIEWS_EXPORT FocusChangeListener {
class VIEWS_EXPORT FocusManager : public ViewObserver { class VIEWS_EXPORT FocusManager : public ViewObserver {
public: public:
// The reason why the focus changed. // The reason why the focus changed.
enum FocusChangeReason { enum class FocusChangeReason {
// The focus changed because the user traversed focusable views using // The focus changed because the user traversed focusable views using
// keys like Tab or Shift+Tab. // keys like Tab or Shift+Tab.
kReasonFocusTraversal, kFocusTraversal,
// The focus changed due to restoring the focus. // The focus changed due to restoring the focus.
kReasonFocusRestore, kFocusRestore,
// The focus changed due to a click or a shortcut to jump directly to // The focus changed due to a click or a shortcut to jump directly to
// a particular view. // a particular view.
kReasonDirectFocusChange kDirectFocusChange
}; };
// TODO: use Direction in place of bool reverse throughout. // TODO: use Direction in place of bool reverse throughout.
...@@ -172,7 +172,7 @@ class VIEWS_EXPORT FocusManager : public ViewObserver { ...@@ -172,7 +172,7 @@ class VIEWS_EXPORT FocusManager : public ViewObserver {
// currenty focusable, enabled, and visible, call view->RequestFocus(). // currenty focusable, enabled, and visible, call view->RequestFocus().
void SetFocusedViewWithReason(View* view, FocusChangeReason reason); void SetFocusedViewWithReason(View* view, FocusChangeReason reason);
void SetFocusedView(View* view) { void SetFocusedView(View* view) {
SetFocusedViewWithReason(view, kReasonDirectFocusChange); SetFocusedViewWithReason(view, FocusChangeReason::kDirectFocusChange);
} }
// Get the reason why the focus most recently changed. // Get the reason why the focus most recently changed.
...@@ -363,7 +363,8 @@ class VIEWS_EXPORT FocusManager : public ViewObserver { ...@@ -363,7 +363,8 @@ class VIEWS_EXPORT FocusManager : public ViewObserver {
std::unique_ptr<ViewTracker> view_tracker_for_stored_view_; std::unique_ptr<ViewTracker> view_tracker_for_stored_view_;
// The reason why the focus most recently changed. // The reason why the focus most recently changed.
FocusChangeReason focus_change_reason_ = kReasonDirectFocusChange; FocusChangeReason focus_change_reason_ =
FocusChangeReason::kDirectFocusChange;
// The list of registered FocusChange listeners. // The list of registered FocusChange listeners.
base::ObserverList<FocusChangeListener, true>::Unchecked base::ObserverList<FocusChangeListener, true>::Unchecked
......
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