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

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

Issue 6312160: Map Views to Profiles directly from their window, eliminating the need... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 months 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 "base/logging.h" 7 #include "base/logging.h"
8 #include "base/stl_util-inl.h" 8 #include "base/stl_util-inl.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/extensions/extension_accessibility_api.h" 10 #include "chrome/browser/extensions/extension_accessibility_api.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 registrar_.RemoveAll(); 67 registrar_.RemoveAll();
68 registered_notifications_ = false; 68 registered_notifications_ = false;
69 } 69 }
70 70
71 bool WizardAccessibilityHelper::IsAccessibilityEnabled() { 71 bool WizardAccessibilityHelper::IsAccessibilityEnabled() {
72 return g_browser_process && 72 return g_browser_process &&
73 g_browser_process->local_state()->GetBoolean( 73 g_browser_process->local_state()->GetBoolean(
74 prefs::kAccessibilityEnabled); 74 prefs::kAccessibilityEnabled);
75 } 75 }
76 76
77 void WizardAccessibilityHelper::MaybeEnableAccessibility(
78 views::View* view_tree) {
79 if (IsAccessibilityEnabled()) {
80 EnableAccessibilityForView(view_tree);
81 } else {
82 AddViewToBuffer(view_tree);
83 }
84 }
85
86 void WizardAccessibilityHelper::MaybeSpeak(const char* str, bool queue, 77 void WizardAccessibilityHelper::MaybeSpeak(const char* str, bool queue,
87 bool interruptible) { 78 bool interruptible) {
88 if (IsAccessibilityEnabled()) { 79 if (IsAccessibilityEnabled()) {
89 accessibility_handler_->Speak(str, queue, interruptible); 80 accessibility_handler_->Speak(str, queue, interruptible);
90 } 81 }
91 } 82 }
92 83
93 void WizardAccessibilityHelper::EnableAccessibilityForView( 84 void WizardAccessibilityHelper::ToggleAccessibility() {
94 views::View* view_tree) {
95 VLOG(1) << "Enabling accessibility.";
96 if (!registered_notifications_)
97 RegisterNotifications();
98 SetAccessibilityEnabled(true);
99 if (view_tree) {
100 AddViewToBuffer(view_tree);
101 // If accessibility pref is set, enable accessibility for all views in
102 // the buffer for which access is not yet enabled.
103 for (std::map<views::View*, bool>::iterator iter =
104 views_buffer_.begin();
105 iter != views_buffer_.end(); ++iter) {
106 if (!(*iter).second) {
107 AccessibleViewHelper *helper = new AccessibleViewHelper((*iter).first,
108 profile_);
109 accessible_view_helpers_.push_back(helper);
110 (*iter).second = true;
111 }
112 }
113 }
114 }
115
116 void WizardAccessibilityHelper::ToggleAccessibility(views::View* view_tree) {
117 if (!IsAccessibilityEnabled()) { 85 if (!IsAccessibilityEnabled()) {
118 EnableAccessibilityForView(view_tree); 86 VLOG(1) << "Enabling accessibility.";
87 if (!registered_notifications_)
88 RegisterNotifications();
89 SetAccessibilityEnabled(true);
119 } else { 90 } else {
120 SetAccessibilityEnabled(false); 91 SetAccessibilityEnabled(false);
121 if (registered_notifications_) 92 if (registered_notifications_)
122 UnregisterNotifications(); 93 UnregisterNotifications();
123 } 94 }
124 } 95 }
125 96
126 void WizardAccessibilityHelper::SetAccessibilityEnabled(bool enabled) { 97 void WizardAccessibilityHelper::SetAccessibilityEnabled(bool enabled) {
127 bool doSpeak = (IsAccessibilityEnabled() != enabled); 98 bool doSpeak = (IsAccessibilityEnabled() != enabled);
128 if (g_browser_process) { 99 if (g_browser_process) {
129 PrefService* prefService = g_browser_process->local_state(); 100 PrefService* prefService = g_browser_process->local_state();
130 prefService->SetBoolean(prefs::kAccessibilityEnabled, enabled); 101 prefService->SetBoolean(prefs::kAccessibilityEnabled, enabled);
131 prefService->ScheduleSavePersistentPrefs(); 102 prefService->ScheduleSavePersistentPrefs();
132 } 103 }
133 ExtensionAccessibilityEventRouter::GetInstance()-> 104 ExtensionAccessibilityEventRouter::GetInstance()->
134 SetAccessibilityEnabled(enabled); 105 SetAccessibilityEnabled(enabled);
135 if (doSpeak) { 106 if (doSpeak) {
136 accessibility_handler_->Speak(enabled ? 107 accessibility_handler_->Speak(enabled ?
137 l10n_util::GetStringUTF8(IDS_CHROMEOS_ACC_ACCESS_ENABLED).c_str() : 108 l10n_util::GetStringUTF8(IDS_CHROMEOS_ACC_ACCESS_ENABLED).c_str() :
138 l10n_util::GetStringUTF8(IDS_CHROMEOS_ACC_ACCESS_DISABLED).c_str(), 109 l10n_util::GetStringUTF8(IDS_CHROMEOS_ACC_ACCESS_DISABLED).c_str(),
139 false, true); 110 false, true);
140 } 111 }
141 } 112 }
142 113
143 void WizardAccessibilityHelper::AddViewToBuffer(views::View* view_tree) {
144 if (!view_tree->GetWidget())
145 return;
146 bool view_exists = false;
147 // Check if the view is already queued for enabling accessibility.
148 // Prevent adding the same view in the buffer twice.
149 for (std::map<views::View*, bool>::iterator iter = views_buffer_.begin();
150 iter != views_buffer_.end(); ++iter) {
151 if ((*iter).first == view_tree) {
152 view_exists = true;
153 break;
154 }
155 }
156 if (!view_exists)
157 views_buffer_[view_tree] = false;
158 }
159
160 } // namespace chromeos 114 } // 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