summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views
diff options
context:
space:
mode:
authormhm@chromium.org <mhm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-20 21:21:01 +0000
committermhm@chromium.org <mhm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-20 21:21:01 +0000
commit1334d31adf23e7a17489821b2b5dc7f1eb36cf7a (patch)
treebd23f5c167b9617303f42361f2cb29ea13fc133e /chrome/browser/views
parentf8d19e8bfe27bfd47a0d22878d6ab98b08f6275f (diff)
downloadchromium_src-1334d31adf23e7a17489821b2b5dc7f1eb36cf7a.zip
chromium_src-1334d31adf23e7a17489821b2b5dc7f1eb36cf7a.tar.gz
chromium_src-1334d31adf23e7a17489821b2b5dc7f1eb36cf7a.tar.bz2
Allow ESC to cancel ALT+SHIFT+T in Toolbar.
By overriding SkipDefaultKeyEventProcessing in View, it will ensure that the current hackish implementation of Toolbar request focus will be dealt before any other focus related actions and accelerators. BUG=8239 TEST=Press ESC while in accessibility mode. Review URL: http://codereview.chromium.org/272024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29572 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r--chrome/browser/views/frame/browser_view.cc8
-rw-r--r--chrome/browser/views/toolbar_view.cc60
-rw-r--r--chrome/browser/views/toolbar_view.h5
3 files changed, 57 insertions, 16 deletions
diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc
index eae4ec7..674c435 100644
--- a/chrome/browser/views/frame/browser_view.cc
+++ b/chrome/browser/views/frame/browser_view.cc
@@ -957,13 +957,7 @@ void BrowserView::UpdateToolbar(TabContents* contents,
}
void BrowserView::FocusToolbar() {
- // Do not restore the button that previously had accessibility focus, if
- // focus is set by using the toolbar focus keyboard shortcut.
- toolbar_->set_acc_focused_view(NULL);
- // HACK: Do not use RequestFocus() here, as the toolbar is not marked as
- // "focusable". Instead bypass the sanity check in RequestFocus() and just
- // force it to focus, which will do the right thing.
- GetRootView()->FocusView(toolbar_);
+ toolbar_->InitializeTraversal();
}
void BrowserView::DestroyBrowser() {
diff --git a/chrome/browser/views/toolbar_view.cc b/chrome/browser/views/toolbar_view.cc
index 42e2f531..8ba0e5c 100644
--- a/chrome/browser/views/toolbar_view.cc
+++ b/chrome/browser/views/toolbar_view.cc
@@ -50,6 +50,8 @@
#include "views/controls/button/button_dropdown.h"
#include "views/controls/label.h"
#include "views/drag_utils.h"
+#include "views/focus/view_storage.h"
+#include "views/widget/root_view.h"
#include "views/widget/tooltip_manager.h"
#include "views/window/non_client_view.h"
#include "views/window/window.h"
@@ -151,6 +153,8 @@ void ZoomMenuModel::Build() {
ToolbarView::ToolbarView(Browser* browser)
: model_(browser->toolbar_model()),
acc_focused_view_(NULL),
+ last_focused_view_storage_id_(
+ views::ViewStorage::GetSharedInstance()->CreateStorageID()),
back_(NULL),
forward_(NULL),
reload_(NULL),
@@ -243,6 +247,23 @@ int ToolbarView::GetNextAccessibleViewIndex(int view_index, bool nav_left) {
return view_index;
}
+void ToolbarView::InitializeTraversal() {
+ // If MSAA focus exists, we don't need to traverse, since its already active.
+ if (acc_focused_view_ != NULL)
+ return;
+
+ // Save the last focused view so that when the user presses ESC, it will
+ // return back to the last focus.
+ views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance();
+ view_storage->StoreView(last_focused_view_storage_id_,
+ GetRootView()->GetFocusedView());
+
+ // HACK: Do not use RequestFocus() here, as the toolbar is not marked as
+ // "focusable". Instead bypass the sanity check in RequestFocus() and just
+ // force it to focus, which will do the right thing.
+ GetRootView()->FocusView(this);
+}
+
////////////////////////////////////////////////////////////////////////////////
// ToolbarView, Menu::BaseControllerDelegate overrides:
@@ -658,10 +679,13 @@ void ToolbarView::WillLoseFocus() {
if (GetWidget() && GetWidget()->GetTooltipManager())
GetWidget()->GetTooltipManager()->HideKeyboardTooltip();
- // Removes the Child MSAA view's focus when toolbar loses focus.
+ // Removes the Child MSAA view's focus and the view from the ViewStorage,
+ // when toolbar loses focus.
if (acc_focused_view_) {
acc_focused_view_->SetHotTracked(false);
acc_focused_view_ = NULL;
+ views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance();
+ view_storage->RemoveView(last_focused_view_storage_id_);
}
}
@@ -669,14 +693,12 @@ void ToolbarView::RequestFocus() {
// When the toolbar needs to request focus, the default implementation of
// View::RequestFocus requires the View to be focusable. Since ToolbarView is
// not technically focused, we need to temporarily set and remove focus so
- // that it can focus back to its MSAA focused state.
- if (acc_focused_view_) {
- SetFocusable(true);
- View::RequestFocus();
- SetFocusable(false);
- } else {
- View::RequestFocus();
- }
+ // that it can focus back to its MSAA focused state. |acc_focused_view_| is
+ // not necessarily set since it can be null if this view has already lost
+ // focus, such as traversing through the context menu.
+ SetFocusable(true);
+ View::RequestFocus();
+ SetFocusable(false);
}
bool ToolbarView::OnKeyPressed(const views::KeyEvent& e) {
@@ -762,6 +784,26 @@ bool ToolbarView::OnKeyReleased(const views::KeyEvent& e) {
return acc_focused_view_->OnKeyReleased(e);
}
+bool ToolbarView::SkipDefaultKeyEventProcessing(const views::KeyEvent& e) {
+ if (acc_focused_view_ && e.GetKeyCode() == base::VKEY_ESCAPE) {
+ // Retrieve the focused view from the storage so we can request focus back
+ // to it. If |focus_view| is null, we place focus on the location bar.
+ // |acc_focused_view_| doesn't need to be resetted here since it will be
+ // dealt within the WillLoseFocus method.
+ views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance();
+ views::View* focused_view =
+ view_storage->RetrieveView(last_focused_view_storage_id_);
+ if (focused_view) {
+ view_storage->RemoveView(last_focused_view_storage_id_);
+ focused_view->RequestFocus();
+ } else {
+ location_bar_->RequestFocus();
+ }
+ return true;
+ }
+ return false;
+}
+
bool ToolbarView::GetAccessibleName(std::wstring* name) {
if (!accessible_name_.empty()) {
(*name).assign(accessible_name_);
diff --git a/chrome/browser/views/toolbar_view.h b/chrome/browser/views/toolbar_view.h
index 97fba3b..94b54e4 100644
--- a/chrome/browser/views/toolbar_view.h
+++ b/chrome/browser/views/toolbar_view.h
@@ -97,6 +97,9 @@ class ToolbarView : public views::View,
// first accessible child, based on the above policy.
int GetNextAccessibleViewIndex(int view_index, bool nav_left);
+ // Initialize the MSAA focus traversal on the toolbar.
+ void InitializeTraversal();
+
void set_acc_focused_view(views::View* acc_focused_view) {
acc_focused_view_ = acc_focused_view;
}
@@ -155,6 +158,7 @@ class ToolbarView : public views::View,
virtual void RequestFocus();
virtual bool OnKeyPressed(const views::KeyEvent& e);
virtual bool OnKeyReleased(const views::KeyEvent& e);
+ virtual bool SkipDefaultKeyEventProcessing(const views::KeyEvent& e);
virtual bool GetAccessibleName(std::wstring* name);
virtual bool GetAccessibleRole(AccessibilityTypes::Role* role);
virtual void SetAccessibleName(const std::wstring& name);
@@ -212,6 +216,7 @@ class ToolbarView : public views::View,
// Child view currently having MSAA focus (location bar excluded from arrow
// navigation).
views::View* acc_focused_view_;
+ int last_focused_view_storage_id_;
// Controls
views::ImageButton* back_;