Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(641)

Side by Side Diff: chrome/browser/chromeos/login/wizard_accessibility_helper.cc

Issue 5839003: Fix to enable toggling accessibility using Ctrl+Alt+Z (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/login/wizard_accessibility_helper.h" 5 #include "chrome/browser/chromeos/login/wizard_accessibility_helper.h"
6 6
7 #include "app/l10n_util.h"
7 #include "base/logging.h" 8 #include "base/logging.h"
8 #include "base/stl_util-inl.h" 9 #include "base/stl_util-inl.h"
9 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/extensions/extension_accessibility_api.h" 11 #include "chrome/browser/extensions/extension_accessibility_api.h"
11 #include "chrome/browser/prefs/pref_service.h" 12 #include "chrome/browser/prefs/pref_service.h"
12 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/profiles/profile_manager.h" 14 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/common/notification_registrar.h" 15 #include "chrome/common/notification_registrar.h"
15 #include "chrome/common/notification_service.h" 16 #include "chrome/common/notification_service.h"
16 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
18 #include "grit/generated_resources.h"
17 #include "views/accelerator.h" 19 #include "views/accelerator.h"
18 #include "views/view.h" 20 #include "views/view.h"
19 21
20 namespace chromeos { 22 namespace chromeos {
21 23
22 scoped_ptr<views::Accelerator> WizardAccessibilityHelper::accelerator_; 24 scoped_ptr<views::Accelerator> WizardAccessibilityHelper::accelerator_;
23 25
24 // static 26 // static
25 views::Accelerator WizardAccessibilityHelper::GetAccelerator() { 27 views::Accelerator WizardAccessibilityHelper::GetAccelerator() {
26 // Use an accelerator that would never match any hotkey to temporarily
27 // disable the accessibility hotkey per http://crosbug.com/9195
28 // TODO(xiyuan): Change back to real hotkey as the following
29 // new views::Accelerator(app::VKEY_Z, false, true, true)
30 if (!WizardAccessibilityHelper::accelerator_.get()) 28 if (!WizardAccessibilityHelper::accelerator_.get())
31 WizardAccessibilityHelper::accelerator_.reset( 29 WizardAccessibilityHelper::accelerator_.reset(
32 new views::Accelerator(app::VKEY_UNKNOWN, 0xdeadbeef)); 30 new views::Accelerator(app::VKEY_Z, false, true, true));
33 return *(WizardAccessibilityHelper::accelerator_.get()); 31 return *(WizardAccessibilityHelper::accelerator_.get());
34 } 32 }
35 33
36 // static 34 // static
37 WizardAccessibilityHelper* WizardAccessibilityHelper::GetInstance() { 35 WizardAccessibilityHelper* WizardAccessibilityHelper::GetInstance() {
38 return Singleton<WizardAccessibilityHelper>::get(); 36 return Singleton<WizardAccessibilityHelper>::get();
39 } 37 }
40 38
41 WizardAccessibilityHelper::WizardAccessibilityHelper() { 39 WizardAccessibilityHelper::WizardAccessibilityHelper() {
42 accessibility_handler_.reset(new WizardAccessibilityHandler()); 40 accessibility_handler_.reset(new WizardAccessibilityHandler());
(...skipping 20 matching lines...) Expand all
63 registered_notifications_ = true; 61 registered_notifications_ = true;
64 } 62 }
65 63
66 void WizardAccessibilityHelper::UnregisterNotifications() { 64 void WizardAccessibilityHelper::UnregisterNotifications() {
67 if (!registered_notifications_) 65 if (!registered_notifications_)
68 return; 66 return;
69 registrar_.RemoveAll(); 67 registrar_.RemoveAll();
70 registered_notifications_ = false; 68 registered_notifications_ = false;
71 } 69 }
72 70
71 bool WizardAccessibilityHelper::IsAccessibilityEnabled() {
72 return g_browser_process &&
73 g_browser_process->local_state()->GetBoolean(
74 prefs::kAccessibilityEnabled);
75 }
76
73 void WizardAccessibilityHelper::MaybeEnableAccessibility( 77 void WizardAccessibilityHelper::MaybeEnableAccessibility(
74 views::View* view_tree) { 78 views::View* view_tree) {
75 if (g_browser_process && 79 if (IsAccessibilityEnabled()) {
76 g_browser_process->local_state()->GetBoolean( 80 EnableAccessibilityForView(view_tree);
77 prefs::kAccessibilityEnabled)) {
78 EnableAccessibility(view_tree);
79 } else { 81 } else {
80 AddViewToBuffer(view_tree); 82 AddViewToBuffer(view_tree);
81 } 83 }
82 } 84 }
83 85
84 void WizardAccessibilityHelper::MaybeSpeak(const char* str, bool queue, 86 void WizardAccessibilityHelper::MaybeSpeak(const char* str, bool queue,
85 bool interruptible) { 87 bool interruptible) {
86 if (g_browser_process && 88 if (IsAccessibilityEnabled()) {
87 g_browser_process->local_state()->GetBoolean(
88 prefs::kAccessibilityEnabled)) {
89 accessibility_handler_->Speak(str, queue, interruptible); 89 accessibility_handler_->Speak(str, queue, interruptible);
90 } 90 }
91 } 91 }
92 92
93 void WizardAccessibilityHelper::EnableAccessibility(views::View* view_tree) { 93 void WizardAccessibilityHelper::EnableAccessibilityForView(
94 views::View* view_tree) {
94 VLOG(1) << "Enabling accessibility."; 95 VLOG(1) << "Enabling accessibility.";
95 if (!registered_notifications_) 96 if (!registered_notifications_)
96 RegisterNotifications(); 97 RegisterNotifications();
97 if (g_browser_process) { 98 SetAccessibilityEnabled(true);
98 PrefService* prefService = g_browser_process->local_state(); 99 if (view_tree) {
99 if (!prefService->GetBoolean(prefs::kAccessibilityEnabled)) { 100 AddViewToBuffer(view_tree);
100 prefService->SetBoolean(prefs::kAccessibilityEnabled, true); 101 // If accessibility pref is set, enable accessibility for all views in
101 prefService->ScheduleSavePersistentPrefs(); 102 // the buffer for which access is not yet enabled.
102 } 103 for (std::map<views::View*, bool>::iterator iter =
103 } 104 views_buffer_.begin();
104 ExtensionAccessibilityEventRouter::GetInstance()-> 105 iter != views_buffer_.end(); ++iter) {
105 SetAccessibilityEnabled(true); 106 if (!(*iter).second) {
106 AddViewToBuffer(view_tree); 107 AccessibleViewHelper *helper = new AccessibleViewHelper((*iter).first,
107 // If accessibility pref is set, enable accessibility for all views in 108 profile_);
108 // the buffer for which access is not yet enabled. 109 accessible_view_helpers_.push_back(helper);
109 for (std::map<views::View*, bool>::iterator iter = 110 (*iter).second = true;
110 views_buffer_.begin(); 111 }
111 iter != views_buffer_.end(); ++iter) {
112 if (!(*iter).second) {
113 AccessibleViewHelper *helper = new AccessibleViewHelper((*iter).first,
114 profile_);
115 accessible_view_helpers_.push_back(helper);
116 (*iter).second = true;
117 } 112 }
118 } 113 }
119 } 114 }
120 115
116 void WizardAccessibilityHelper::ToggleAccessibility(views::View* view_tree) {
117 if (!IsAccessibilityEnabled()) {
118 EnableAccessibilityForView(view_tree);
119 } else {
120 SetAccessibilityEnabled(false);
121 }
122 }
123
124 void WizardAccessibilityHelper::SetAccessibilityEnabled(bool enabled) {
125 if (g_browser_process) {
126 PrefService* prefService = g_browser_process->local_state();
127 prefService->SetBoolean(prefs::kAccessibilityEnabled, enabled);
128 prefService->ScheduleSavePersistentPrefs();
129 }
130 ExtensionAccessibilityEventRouter::GetInstance()->
131 SetAccessibilityEnabled(enabled);
132 accessibility_handler_->Speak(enabled ?
133 l10n_util::GetStringUTF8(IDS_CHROMEOS_ACC_ACCESS_ENABLED).c_str() :
134 l10n_util::GetStringUTF8(IDS_CHROMEOS_ACC_ACCESS_DISABLED).c_str(),
135 false, true);
136 }
137
121 void WizardAccessibilityHelper::AddViewToBuffer(views::View* view_tree) { 138 void WizardAccessibilityHelper::AddViewToBuffer(views::View* view_tree) {
122 if (!view_tree->GetWidget()) 139 if (!view_tree->GetWidget())
123 return; 140 return;
124 bool view_exists = false; 141 bool view_exists = false;
125 // Check if the view is already queued for enabling accessibility. 142 // Check if the view is already queued for enabling accessibility.
126 // Prevent adding the same view in the buffer twice. 143 // Prevent adding the same view in the buffer twice.
127 for (std::map<views::View*, bool>::iterator iter = views_buffer_.begin(); 144 for (std::map<views::View*, bool>::iterator iter = views_buffer_.begin();
128 iter != views_buffer_.end(); ++iter) { 145 iter != views_buffer_.end(); ++iter) {
129 if ((*iter).first == view_tree) { 146 if ((*iter).first == view_tree) {
130 view_exists = true; 147 view_exists = true;
131 break; 148 break;
132 } 149 }
133 } 150 }
134 if (!view_exists) 151 if (!view_exists)
135 views_buffer_[view_tree] = false; 152 views_buffer_[view_tree] = false;
136 } 153 }
137 154
138 } // namespace chromeos 155 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/wizard_accessibility_helper.h ('k') | chrome/browser/chromeos/login/wizard_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698