diff options
author | chaitanyag@chromium.org <chaitanyag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-16 22:21:28 +0000 |
---|---|---|
committer | chaitanyag@chromium.org <chaitanyag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-16 22:21:28 +0000 |
commit | 72f5a791e19a3e7fd75d3622e35ca0ece51ce892 (patch) | |
tree | 0b7acd3bb40ec31bb3146a3e792f78b64e6e43bf | |
parent | 74c8a07a137e5d79323c92dbe88c4dc1cddfc91f (diff) | |
download | chromium_src-72f5a791e19a3e7fd75d3622e35ca0ece51ce892.zip chromium_src-72f5a791e19a3e7fd75d3622e35ca0ece51ce892.tar.gz chromium_src-72f5a791e19a3e7fd75d3622e35ca0ece51ce892.tar.bz2 |
Fix to enable toggling accessibility using Ctrl+Alt+Z
Review URL: http://codereview.chromium.org/5839003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69475 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/generated_resources.grd | 9 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/existing_user_view.cc | 8 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/existing_user_view.h | 2 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/guest_user_view.cc | 8 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/guest_user_view.h | 2 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/new_user_view.cc | 10 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/new_user_view.h | 2 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/wizard_accessibility_helper.cc | 79 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/wizard_accessibility_helper.h | 11 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/wizard_controller.cc | 10 |
10 files changed, 89 insertions, 52 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 9d75f72..dfd9b2c 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -10638,6 +10638,15 @@ Keep your key file in a safe place. You will need it to create new versions of y <message name="IDS_CHROMEOS_ACC_TEXT_UNSELECTED" desc="A phrase to indicate to the user that text has been unselected."> Unselected </message> + <message name="IDS_CHROMEOS_ACC_ACCESS_ENABLED" desc="A phrase to speak when accessibility is enabled."> + Accessibility turned on. + </message> + <message name="IDS_CHROMEOS_ACC_ACCESS_DISABLED" desc="A phrase to speak when accessibility is disabled."> + Accessibility turned off. + </message> + <message name="IDS_CHROMEOS_ACC_USERNAME_LABEL" desc="Label for the username text field."> + Username. + </message> <!-- Network state strings for ChromeOS --> <message name="IDS_CHROMEOS_NETWORK_STATE_UNKNOWN" desc="Network state in about:network: UNKNOWN"> diff --git a/chrome/browser/chromeos/login/existing_user_view.cc b/chrome/browser/chromeos/login/existing_user_view.cc index 6f4e60e..ed94278 100644 --- a/chrome/browser/chromeos/login/existing_user_view.cc +++ b/chrome/browser/chromeos/login/existing_user_view.cc @@ -60,10 +60,10 @@ ExistingUserView::ExistingUserView(UserController* user_controller) password_field_(NULL), accel_login_off_the_record_( views::Accelerator(app::VKEY_B, false, false, true)), - accel_enable_accessibility_( + accel_toggle_accessibility_( WizardAccessibilityHelper::GetAccelerator()) { AddAccelerator(accel_login_off_the_record_); - AddAccelerator(accel_enable_accessibility_); + AddAccelerator(accel_toggle_accessibility_); } void ExistingUserView::RecreateFields() { @@ -89,8 +89,8 @@ bool ExistingUserView::AcceleratorPressed( if (accelerator == accel_login_off_the_record_) { user_controller_->OnLoginOffTheRecord(); return true; - } else if (accelerator == accel_enable_accessibility_) { - WizardAccessibilityHelper::GetInstance()->EnableAccessibility(this); + } else if (accelerator == accel_toggle_accessibility_) { + WizardAccessibilityHelper::GetInstance()->ToggleAccessibility(this); return true; } return false; diff --git a/chrome/browser/chromeos/login/existing_user_view.h b/chrome/browser/chromeos/login/existing_user_view.h index 42253d4..9d3dff8 100644 --- a/chrome/browser/chromeos/login/existing_user_view.h +++ b/chrome/browser/chromeos/login/existing_user_view.h @@ -56,7 +56,7 @@ class ExistingUserView : public ThrobberHostView, views::Textfield* password_field_; views::Accelerator accel_login_off_the_record_; - views::Accelerator accel_enable_accessibility_; + views::Accelerator accel_toggle_accessibility_; DISALLOW_COPY_AND_ASSIGN(ExistingUserView); }; diff --git a/chrome/browser/chromeos/login/guest_user_view.cc b/chrome/browser/chromeos/login/guest_user_view.cc index 049879d..c83d897 100644 --- a/chrome/browser/chromeos/login/guest_user_view.cc +++ b/chrome/browser/chromeos/login/guest_user_view.cc @@ -45,7 +45,7 @@ class UserEntryButton : public login::WideButton { GuestUserView::GuestUserView(UserController* uc) : submit_button_(NULL), user_controller_(uc), - accel_enable_accessibility_( + accel_toggle_accessibility_( WizardAccessibilityHelper::GetAccelerator()), accel_login_off_the_record_( views::Accelerator(app::VKEY_B, false, false, true)), @@ -53,7 +53,7 @@ GuestUserView::GuestUserView(UserController* uc) views::Accelerator(app::VKEY_LEFT, false, false, false)), accel_next_pod_by_arrow_( views::Accelerator(app::VKEY_RIGHT, false, false, false)) { - AddAccelerator(accel_enable_accessibility_); + AddAccelerator(accel_toggle_accessibility_); AddAccelerator(accel_login_off_the_record_); AddAccelerator(accel_previous_pod_by_arrow_); AddAccelerator(accel_next_pod_by_arrow_); @@ -78,8 +78,8 @@ bool GuestUserView::AcceleratorPressed( const views::Accelerator& accelerator) { if (accelerator == accel_login_off_the_record_) user_controller_->OnLoginOffTheRecord(); - else if (accelerator == accel_enable_accessibility_) - WizardAccessibilityHelper::GetInstance()->EnableAccessibility(this); + else if (accelerator == accel_toggle_accessibility_) + WizardAccessibilityHelper::GetInstance()->ToggleAccessibility(this); else if (accelerator == accel_previous_pod_by_arrow_) user_controller_->SelectUserRelative(-1); else if (accelerator == accel_next_pod_by_arrow_) diff --git a/chrome/browser/chromeos/login/guest_user_view.h b/chrome/browser/chromeos/login/guest_user_view.h index 1820f0e..a7b31b4 100644 --- a/chrome/browser/chromeos/login/guest_user_view.h +++ b/chrome/browser/chromeos/login/guest_user_view.h @@ -55,7 +55,7 @@ class GuestUserView : public ThrobberHostView, UserController* user_controller_; - views::Accelerator accel_enable_accessibility_; + views::Accelerator accel_toggle_accessibility_; views::Accelerator accel_login_off_the_record_; views::Accelerator accel_previous_pod_by_arrow_; views::Accelerator accel_previous_pod_by_tab_; diff --git a/chrome/browser/chromeos/login/new_user_view.cc b/chrome/browser/chromeos/login/new_user_view.cc index 6331fbb..203a791 100644 --- a/chrome/browser/chromeos/login/new_user_view.cc +++ b/chrome/browser/chromeos/login/new_user_view.cc @@ -98,7 +98,7 @@ NewUserView::NewUserView(Delegate* delegate, accel_focus_user_(views::Accelerator(app::VKEY_U, false, false, true)), accel_login_off_the_record_( views::Accelerator(app::VKEY_B, false, false, true)), - accel_enable_accessibility_(WizardAccessibilityHelper::GetAccelerator()), + accel_toggle_accessibility_(WizardAccessibilityHelper::GetAccelerator()), delegate_(delegate), ALLOW_THIS_IN_INITIALIZER_LIST(focus_grabber_factory_(this)), focus_delayed_(false), @@ -150,6 +150,8 @@ void NewUserView::Init() { username_field_ = new UsernameField(); username_field_->set_background(new CopyBackground(this)); + username_field_->SetAccessibleName( + ASCIIToWide(l10n_util::GetStringUTF8(IDS_CHROMEOS_ACC_USERNAME_LABEL))); AddChildView(username_field_); password_field_ = new TextfieldWithMargin(views::Textfield::STYLE_PASSWORD); @@ -173,7 +175,7 @@ void NewUserView::Init() { AddAccelerator(accel_focus_user_); AddAccelerator(accel_focus_pass_); AddAccelerator(accel_login_off_the_record_); - AddAccelerator(accel_enable_accessibility_); + AddAccelerator(accel_toggle_accessibility_); OnLocaleChanged(); @@ -196,8 +198,8 @@ bool NewUserView::AcceleratorPressed(const views::Accelerator& accelerator) { password_field_->RequestFocus(); } else if (accelerator == accel_login_off_the_record_) { delegate_->OnLoginOffTheRecord(); - } else if (accelerator == accel_enable_accessibility_) { - WizardAccessibilityHelper::GetInstance()->EnableAccessibility(this); + } else if (accelerator == accel_toggle_accessibility_) { + WizardAccessibilityHelper::GetInstance()->ToggleAccessibility(this); } else { return false; } diff --git a/chrome/browser/chromeos/login/new_user_view.h b/chrome/browser/chromeos/login/new_user_view.h index 6b282d0..6378672 100644 --- a/chrome/browser/chromeos/login/new_user_view.h +++ b/chrome/browser/chromeos/login/new_user_view.h @@ -165,7 +165,7 @@ class NewUserView : public ThrobberHostView, views::Accelerator accel_focus_pass_; views::Accelerator accel_focus_user_; views::Accelerator accel_login_off_the_record_; - views::Accelerator accel_enable_accessibility_; + views::Accelerator accel_toggle_accessibility_; // Notifications receiver. Delegate* delegate_; diff --git a/chrome/browser/chromeos/login/wizard_accessibility_helper.cc b/chrome/browser/chromeos/login/wizard_accessibility_helper.cc index 6183c07..c8c8668 100644 --- a/chrome/browser/chromeos/login/wizard_accessibility_helper.cc +++ b/chrome/browser/chromeos/login/wizard_accessibility_helper.cc @@ -4,6 +4,7 @@ #include "chrome/browser/chromeos/login/wizard_accessibility_helper.h" +#include "app/l10n_util.h" #include "base/logging.h" #include "base/stl_util-inl.h" #include "chrome/browser/browser_process.h" @@ -14,6 +15,7 @@ #include "chrome/common/notification_registrar.h" #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" +#include "grit/generated_resources.h" #include "views/accelerator.h" #include "views/view.h" @@ -23,13 +25,9 @@ scoped_ptr<views::Accelerator> WizardAccessibilityHelper::accelerator_; // static views::Accelerator WizardAccessibilityHelper::GetAccelerator() { - // Use an accelerator that would never match any hotkey to temporarily - // disable the accessibility hotkey per http://crosbug.com/9195 - // TODO(xiyuan): Change back to real hotkey as the following - // new views::Accelerator(app::VKEY_Z, false, true, true) if (!WizardAccessibilityHelper::accelerator_.get()) WizardAccessibilityHelper::accelerator_.reset( - new views::Accelerator(app::VKEY_UNKNOWN, 0xdeadbeef)); + new views::Accelerator(app::VKEY_Z, false, true, true)); return *(WizardAccessibilityHelper::accelerator_.get()); } @@ -70,12 +68,16 @@ void WizardAccessibilityHelper::UnregisterNotifications() { registered_notifications_ = false; } +bool WizardAccessibilityHelper::IsAccessibilityEnabled() { + return g_browser_process && + g_browser_process->local_state()->GetBoolean( + prefs::kAccessibilityEnabled); +} + void WizardAccessibilityHelper::MaybeEnableAccessibility( views::View* view_tree) { - if (g_browser_process && - g_browser_process->local_state()->GetBoolean( - prefs::kAccessibilityEnabled)) { - EnableAccessibility(view_tree); + if (IsAccessibilityEnabled()) { + EnableAccessibilityForView(view_tree); } else { AddViewToBuffer(view_tree); } @@ -83,39 +85,54 @@ void WizardAccessibilityHelper::MaybeEnableAccessibility( void WizardAccessibilityHelper::MaybeSpeak(const char* str, bool queue, bool interruptible) { - if (g_browser_process && - g_browser_process->local_state()->GetBoolean( - prefs::kAccessibilityEnabled)) { + if (IsAccessibilityEnabled()) { accessibility_handler_->Speak(str, queue, interruptible); } } -void WizardAccessibilityHelper::EnableAccessibility(views::View* view_tree) { +void WizardAccessibilityHelper::EnableAccessibilityForView( + views::View* view_tree) { VLOG(1) << "Enabling accessibility."; if (!registered_notifications_) RegisterNotifications(); + SetAccessibilityEnabled(true); + if (view_tree) { + AddViewToBuffer(view_tree); + // If accessibility pref is set, enable accessibility for all views in + // the buffer for which access is not yet enabled. + for (std::map<views::View*, bool>::iterator iter = + views_buffer_.begin(); + iter != views_buffer_.end(); ++iter) { + if (!(*iter).second) { + AccessibleViewHelper *helper = new AccessibleViewHelper((*iter).first, + profile_); + accessible_view_helpers_.push_back(helper); + (*iter).second = true; + } + } + } +} + +void WizardAccessibilityHelper::ToggleAccessibility(views::View* view_tree) { + if (!IsAccessibilityEnabled()) { + EnableAccessibilityForView(view_tree); + } else { + SetAccessibilityEnabled(false); + } +} + +void WizardAccessibilityHelper::SetAccessibilityEnabled(bool enabled) { if (g_browser_process) { PrefService* prefService = g_browser_process->local_state(); - if (!prefService->GetBoolean(prefs::kAccessibilityEnabled)) { - prefService->SetBoolean(prefs::kAccessibilityEnabled, true); - prefService->ScheduleSavePersistentPrefs(); - } + prefService->SetBoolean(prefs::kAccessibilityEnabled, enabled); + prefService->ScheduleSavePersistentPrefs(); } ExtensionAccessibilityEventRouter::GetInstance()-> - SetAccessibilityEnabled(true); - AddViewToBuffer(view_tree); - // If accessibility pref is set, enable accessibility for all views in - // the buffer for which access is not yet enabled. - for (std::map<views::View*, bool>::iterator iter = - views_buffer_.begin(); - iter != views_buffer_.end(); ++iter) { - if (!(*iter).second) { - AccessibleViewHelper *helper = new AccessibleViewHelper((*iter).first, - profile_); - accessible_view_helpers_.push_back(helper); - (*iter).second = true; - } - } + SetAccessibilityEnabled(enabled); + accessibility_handler_->Speak(enabled ? + l10n_util::GetStringUTF8(IDS_CHROMEOS_ACC_ACCESS_ENABLED).c_str() : + l10n_util::GetStringUTF8(IDS_CHROMEOS_ACC_ACCESS_DISABLED).c_str(), + false, true); } void WizardAccessibilityHelper::AddViewToBuffer(views::View* view_tree) { diff --git a/chrome/browser/chromeos/login/wizard_accessibility_helper.h b/chrome/browser/chromeos/login/wizard_accessibility_helper.h index f3b2963..c27ef3c 100644 --- a/chrome/browser/chromeos/login/wizard_accessibility_helper.h +++ b/chrome/browser/chromeos/login/wizard_accessibility_helper.h @@ -37,7 +37,7 @@ class WizardAccessibilityHelper { // Enables Accessibility by setting the accessibility pref and registers // all views in the view buffer to raise accessibility notifications, // including the specified |view_tree|. - void EnableAccessibility(views::View* view_tree); + void EnableAccessibilityForView(views::View* view_tree); // Enables accessibility for the specified |view_tree| if the // accessibility pref is already set. Otherwise the |view_tree| is @@ -54,6 +54,11 @@ class WizardAccessibilityHelper { // Unregisters all accessibility notifications void UnregisterNotifications(); + // Toggles accessibility support. If |view_tree| is null, only the + // access preference setting is toggled. |view_tree| has no effect while + // disabling accessibility. + void ToggleAccessibility(views::View* view_tree); + private: friend struct DefaultSingletonTraits<WizardAccessibilityHelper>; @@ -63,6 +68,10 @@ class WizardAccessibilityHelper { void RegisterNotifications(); + bool IsAccessibilityEnabled(); + + void SetAccessibilityEnabled(bool); + static scoped_ptr<views::Accelerator> accelerator_; void AddViewToBuffer(views::View* view_tree); diff --git a/chrome/browser/chromeos/login/wizard_controller.cc b/chrome/browser/chromeos/login/wizard_controller.cc index 50aa4b2..db100bc 100644 --- a/chrome/browser/chromeos/login/wizard_controller.cc +++ b/chrome/browser/chromeos/login/wizard_controller.cc @@ -80,7 +80,7 @@ const int kWaitForRebootTimeSec = 3; class ContentView : public views::View { public: ContentView() - : accel_enable_accessibility_( + : accel_toggle_accessibility_( chromeos::WizardAccessibilityHelper::GetAccelerator()) { #if defined(OFFICIAL_BUILD) accel_cancel_update_ = views::Accelerator(app::VKEY_ESCAPE, @@ -110,7 +110,7 @@ class ContentView : public views::View { AddAccelerator(accel_eula_screen_); AddAccelerator(accel_register_screen_); #endif - AddAccelerator(accel_enable_accessibility_); + AddAccelerator(accel_toggle_accessibility_); AddAccelerator(accel_cancel_update_); } @@ -126,8 +126,8 @@ class ContentView : public views::View { if (!controller) return false; - if (accel == accel_enable_accessibility_) { - chromeos::WizardAccessibilityHelper::GetInstance()->EnableAccessibility( + if (accel == accel_toggle_accessibility_) { + chromeos::WizardAccessibilityHelper::GetInstance()->ToggleAccessibility( controller->contents()); } else if (accel == accel_cancel_update_) { controller->CancelOOBEUpdate(); @@ -174,7 +174,7 @@ class ContentView : public views::View { views::Accelerator accel_eula_screen_; views::Accelerator accel_register_screen_; #endif - views::Accelerator accel_enable_accessibility_; + views::Accelerator accel_toggle_accessibility_; views::Accelerator accel_cancel_update_; DISALLOW_COPY_AND_ASSIGN(ContentView); |