OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_handler.h" | 5 #include "chrome/browser/chromeos/login/wizard_accessibility_handler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/i18n/char_iterator.h" | 9 #include "base/i18n/char_iterator.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
13 #include "chrome/browser/accessibility_events.h" | 13 #include "chrome/browser/accessibility_events.h" |
14 #include "chrome/browser/chromeos/cros/cros_library.h" | 14 #include "chrome/browser/chromeos/cros/cros_library.h" |
15 #include "chrome/browser/chromeos/cros/speech_synthesis_library.h" | 15 #include "chrome/browser/chromeos/cros/speech_synthesis_library.h" |
16 #include "chrome/browser/extensions/extension_accessibility_api.h" | 16 #include "chrome/browser/extensions/extension_accessibility_api.h" |
17 #include "chrome/browser/extensions/extension_accessibility_api_constants.h" | 17 #include "chrome/browser/extensions/extension_accessibility_api_constants.h" |
18 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
| 19 #include "chrome/common/chrome_notification_types.h" |
19 #include "content/common/notification_details.h" | 20 #include "content/common/notification_details.h" |
20 #include "content/common/notification_source.h" | 21 #include "content/common/notification_source.h" |
21 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
22 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
23 | 24 |
24 namespace keys = extension_accessibility_api_constants; | 25 namespace keys = extension_accessibility_api_constants; |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
28 static std::string SubstringUTF8(std::string str, int start, int len) { | 29 static std::string SubstringUTF8(std::string str, int start, int len) { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 AppendUtterance(l10n_util::GetStringFUTF8(IDS_CHROMEOS_ACC_INDEX_OF_COUNT, | 94 AppendUtterance(l10n_util::GetStringFUTF8(IDS_CHROMEOS_ACC_INDEX_OF_COUNT, |
94 index_str, | 95 index_str, |
95 count_str), str); | 96 count_str), str); |
96 } | 97 } |
97 | 98 |
98 } // anonymous namespace | 99 } // anonymous namespace |
99 | 100 |
100 namespace chromeos { | 101 namespace chromeos { |
101 | 102 |
102 void WizardAccessibilityHandler::Observe( | 103 void WizardAccessibilityHandler::Observe( |
103 NotificationType type, | 104 int type, |
104 const NotificationSource& source, | 105 const NotificationSource& source, |
105 const NotificationDetails& details) { | 106 const NotificationDetails& details) { |
106 const AccessibilityControlInfo *control_info = | 107 const AccessibilityControlInfo *control_info = |
107 Details<const AccessibilityControlInfo>(details).ptr(); | 108 Details<const AccessibilityControlInfo>(details).ptr(); |
108 std::string description; | 109 std::string description; |
109 EarconType earcon = NO_EARCON; | 110 EarconType earcon = NO_EARCON; |
110 DescribeAccessibilityEvent(type, control_info, &description, &earcon); | 111 DescribeAccessibilityEvent(type, control_info, &description, &earcon); |
111 Speak(description.c_str(), false, true); | 112 Speak(description.c_str(), false, true); |
112 } | 113 } |
113 | 114 |
114 void WizardAccessibilityHandler::Speak(const char* speak_str, | 115 void WizardAccessibilityHandler::Speak(const char* speak_str, |
115 bool queue, | 116 bool queue, |
116 bool interruptible) { | 117 bool interruptible) { |
117 if (chromeos::CrosLibrary::Get()->EnsureLoaded()) { | 118 if (chromeos::CrosLibrary::Get()->EnsureLoaded()) { |
118 if (queue || !interruptible) { | 119 if (queue || !interruptible) { |
119 std::string props = ""; | 120 std::string props = ""; |
120 props.append("enqueue="); | 121 props.append("enqueue="); |
121 props.append(queue ? "1;" : "0;"); | 122 props.append(queue ? "1;" : "0;"); |
122 props.append("interruptible="); | 123 props.append("interruptible="); |
123 props.append(interruptible ? "1;" : "0;"); | 124 props.append(interruptible ? "1;" : "0;"); |
124 chromeos::CrosLibrary::Get()->GetSpeechSynthesisLibrary()-> | 125 chromeos::CrosLibrary::Get()->GetSpeechSynthesisLibrary()-> |
125 SetSpeakProperties(props.c_str()); | 126 SetSpeakProperties(props.c_str()); |
126 } | 127 } |
127 chromeos::CrosLibrary::Get()->GetSpeechSynthesisLibrary()-> | 128 chromeos::CrosLibrary::Get()->GetSpeechSynthesisLibrary()-> |
128 Speak(speak_str); | 129 Speak(speak_str); |
129 } | 130 } |
130 } | 131 } |
131 | 132 |
132 void WizardAccessibilityHandler::DescribeAccessibilityEvent( | 133 void WizardAccessibilityHandler::DescribeAccessibilityEvent( |
133 NotificationType event_type, | 134 int event_type, |
134 const AccessibilityControlInfo* control_info, | 135 const AccessibilityControlInfo* control_info, |
135 std::string* out_spoken_description, | 136 std::string* out_spoken_description, |
136 EarconType* out_earcon) { | 137 EarconType* out_earcon) { |
137 *out_spoken_description = std::string(); | 138 *out_spoken_description = std::string(); |
138 *out_earcon = NO_EARCON; | 139 *out_earcon = NO_EARCON; |
139 | 140 |
140 switch (event_type.value) { | 141 switch (event_type) { |
141 case NotificationType::ACCESSIBILITY_CONTROL_FOCUSED: | 142 case chrome::NOTIFICATION_ACCESSIBILITY_CONTROL_FOCUSED: |
142 DescribeControl(control_info, false, out_spoken_description, out_earcon); | 143 DescribeControl(control_info, false, out_spoken_description, out_earcon); |
143 break; | 144 break; |
144 case NotificationType::ACCESSIBILITY_CONTROL_ACTION: | 145 case chrome::NOTIFICATION_ACCESSIBILITY_CONTROL_ACTION: |
145 DescribeControl(control_info, true, out_spoken_description, out_earcon); | 146 DescribeControl(control_info, true, out_spoken_description, out_earcon); |
146 break; | 147 break; |
147 case NotificationType::ACCESSIBILITY_TEXT_CHANGED: | 148 case chrome::NOTIFICATION_ACCESSIBILITY_TEXT_CHANGED: |
148 DescribeTextChanged(control_info, out_spoken_description, out_earcon); | 149 DescribeTextChanged(control_info, out_spoken_description, out_earcon); |
149 break; | 150 break; |
150 case NotificationType::ACCESSIBILITY_MENU_OPENED: | 151 case chrome::NOTIFICATION_ACCESSIBILITY_MENU_OPENED: |
151 *out_earcon = EARCON_OBJECT_OPENED; | 152 *out_earcon = EARCON_OBJECT_OPENED; |
152 break; | 153 break; |
153 case NotificationType::ACCESSIBILITY_MENU_CLOSED: | 154 case chrome::NOTIFICATION_ACCESSIBILITY_MENU_CLOSED: |
154 *out_earcon = EARCON_OBJECT_CLOSED; | 155 *out_earcon = EARCON_OBJECT_CLOSED; |
155 break; | 156 break; |
156 default: | 157 default: |
157 NOTREACHED(); | 158 NOTREACHED(); |
158 return; | 159 return; |
159 } | 160 } |
160 | 161 |
161 if (control_info->type() == keys::kTypeTextBox) { | 162 if (control_info->type() == keys::kTypeTextBox) { |
162 const AccessibilityTextBoxInfo* text_box = | 163 const AccessibilityTextBoxInfo* text_box = |
163 static_cast<const AccessibilityTextBoxInfo*>(control_info); | 164 static_cast<const AccessibilityTextBoxInfo*>(control_info); |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 } else if (!inserted.empty()) { | 437 } else if (!inserted.empty()) { |
437 // Speak inserted text. | 438 // Speak inserted text. |
438 AppendUtterance(inserted, out_spoken_description); | 439 AppendUtterance(inserted, out_spoken_description); |
439 } else if (!deleted.empty()) { | 440 } else if (!deleted.empty()) { |
440 // Speak deleted text. | 441 // Speak deleted text. |
441 AppendUtterance(deleted, out_spoken_description); | 442 AppendUtterance(deleted, out_spoken_description); |
442 } | 443 } |
443 } | 444 } |
444 | 445 |
445 } // namespace chromeos | 446 } // namespace chromeos |
OLD | NEW |