diff options
author | dmazzoni@chromium.org <dmazzoni@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-30 16:37:54 +0000 |
---|---|---|
committer | dmazzoni@chromium.org <dmazzoni@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-30 16:37:54 +0000 |
commit | 44db7c6b5a0dd41bfbd8145a74cc6948fe2d6c04 (patch) | |
tree | 17e926b6917b11264605ca01c7c9c1bfb3125d55 /views | |
parent | 7f593b65f3d11c6754ca6db19a42df2872338ef2 (diff) | |
download | chromium_src-44db7c6b5a0dd41bfbd8145a74cc6948fe2d6c04.zip chromium_src-44db7c6b5a0dd41bfbd8145a74cc6948fe2d6c04.tar.gz chromium_src-44db7c6b5a0dd41bfbd8145a74cc6948fe2d6c04.tar.bz2 |
Minor fixes to toolbar keyboard accessibility: focusing the location bar
should select all, accessibility focus should be preserved when the whole
window loses and regains focus, and clicking on the location bar should exit
accessibility focus mode.
BUG=47380
BUG=36070
BUG=47784
TEST=none
Review URL: http://codereview.chromium.org/2833040
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51262 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/focus/focus_manager.cc | 18 | ||||
-rw-r--r-- | views/focus/focus_manager.h | 33 |
2 files changed, 43 insertions, 8 deletions
diff --git a/views/focus/focus_manager.cc b/views/focus/focus_manager.cc index 9646bb8..733d921 100644 --- a/views/focus/focus_manager.cc +++ b/views/focus/focus_manager.cc @@ -67,7 +67,8 @@ void FocusManager::WidgetFocusManager::OnWidgetFocusEvent( FocusManager::FocusManager(Widget* widget) : widget_(widget), - focused_view_(NULL) { + focused_view_(NULL), + focus_change_reason_(kReasonDirectFocusChange) { DCHECK(widget_); stored_focused_view_storage_id_ = ViewStorage::GetSharedInstance()->CreateStorageID(); @@ -123,7 +124,7 @@ bool FocusManager::OnKeyEvent(const KeyEvent& event) { } else if (index >= static_cast<int>(views.size())) { index = 0; } - SetFocusedView(views[index]); + SetFocusedViewWithReason(views[index], kReasonFocusTraversal); return false; } @@ -184,7 +185,7 @@ void FocusManager::AdvanceFocus(bool reverse) { // first element on the page. if (v) { v->AboutToRequestFocusFromTabTraversal(reverse); - SetFocusedView(v); + SetFocusedViewWithReason(v, kReasonFocusTraversal); } } @@ -279,7 +280,10 @@ View* FocusManager::GetNextFocusableView(View* original_starting_view, return NULL; } -void FocusManager::SetFocusedView(View* view) { +void FocusManager::SetFocusedViewWithReason( + View* view, FocusChangeReason reason) { + focus_change_reason_ = reason; + if (focused_view_ == view) return; @@ -357,8 +361,10 @@ void FocusManager::RestoreFocusedView() { View* view = view_storage->RetrieveView(stored_focused_view_storage_id_); if (view) { - if (ContainsView(view)) - view->RequestFocus(); + if (ContainsView(view) && + (view->IsFocusable() || view->IsAccessibilityFocusable())) { + SetFocusedViewWithReason(view, kReasonFocusRestore); + } } else { // Clearing the focus will focus the root window, so we still get key // events. diff --git a/views/focus/focus_manager.h b/views/focus/focus_manager.h index d789d12..7abe1d0 100644 --- a/views/focus/focus_manager.h +++ b/views/focus/focus_manager.h @@ -148,6 +148,20 @@ class FocusManager { DISALLOW_COPY_AND_ASSIGN(WidgetFocusManager); }; + // The reason why the focus changed. + enum FocusChangeReason { + // The focus changed because the user traversed focusable views using + // keys like Tab or Shift+Tab. + kReasonFocusTraversal, + + // The focus changed due to restoring the focus. + kReasonFocusRestore, + + // The focus changed due to a click or a shortcut to jump directly to + // a particular view. + kReasonDirectFocusChange + }; + explicit FocusManager(Widget* widget); virtual ~FocusManager(); @@ -168,9 +182,21 @@ class FocusManager { // Advances the focus (backward if reverse is true). void AdvanceFocus(bool reverse); - // The FocusManager is handling the selected view for the RootView. + // The FocusManager keeps track of the focused view within a RootView. View* GetFocusedView() const { return focused_view_; } - void SetFocusedView(View* view); + + // Low-level methods to force the focus to change (and optionally provide + // a reason). If the focus change should only happen if the view is + // currenty focusable, enabled, and visible, call view->RequestFocus(). + void SetFocusedViewWithReason(View* view, FocusChangeReason reason); + void SetFocusedView(View* view) { + SetFocusedViewWithReason(view, kReasonDirectFocusChange); + } + + // Get the reason why the focus most recently changed. + FocusChangeReason focus_change_reason() const { + return focus_change_reason_; + } // Clears the focused view. The window associated with the top root view gets // the native focus (so we still get keyboard events). @@ -272,6 +298,9 @@ class FocusManager { // had focus. int stored_focused_view_storage_id_; + // The reason why the focus most recently changed. + FocusChangeReason focus_change_reason_; + // The accelerators and associated targets. typedef std::list<AcceleratorTarget*> AcceleratorTargetList; typedef std::map<Accelerator, AcceleratorTargetList> AcceleratorMap; |