accessibility_controller_impl.cc 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/accessibility/accessibility_controller_impl.h"
  5. #include <map>
  6. #include <memory>
  7. #include <set>
  8. #include <string>
  9. #include <utility>
  10. #include "ash/accelerators/accelerator_controller_impl.h"
  11. #include "ash/accessibility/accessibility_observer.h"
  12. #include "ash/accessibility/autoclick/autoclick_controller.h"
  13. #include "ash/accessibility/dictation_nudge_controller.h"
  14. #include "ash/accessibility/sticky_keys/sticky_keys_controller.h"
  15. #include "ash/accessibility/switch_access/point_scan_controller.h"
  16. #include "ash/accessibility/ui/accessibility_highlight_controller.h"
  17. #include "ash/accessibility/ui/accessibility_panel_layout_manager.h"
  18. #include "ash/constants/ash_constants.h"
  19. #include "ash/constants/ash_pref_names.h"
  20. #include "ash/constants/notifier_catalogs.h"
  21. #include "ash/events/accessibility_event_rewriter.h"
  22. #include "ash/events/select_to_speak_event_handler.h"
  23. #include "ash/high_contrast/high_contrast_controller.h"
  24. #include "ash/keyboard/keyboard_controller_impl.h"
  25. #include "ash/keyboard/ui/keyboard_util.h"
  26. #include "ash/login_status.h"
  27. #include "ash/policy/policy_recommendation_restorer.h"
  28. #include "ash/public/cpp/accessibility_controller_client.h"
  29. #include "ash/public/cpp/ash_constants.h"
  30. #include "ash/public/cpp/notification_utils.h"
  31. #include "ash/public/cpp/session/session_observer.h"
  32. #include "ash/public/cpp/shell_window_ids.h"
  33. #include "ash/resources/vector_icons/vector_icons.h"
  34. #include "ash/root_window_controller.h"
  35. #include "ash/session/session_controller_impl.h"
  36. #include "ash/shell.h"
  37. #include "ash/strings/grit/ash_strings.h"
  38. #include "ash/system/accessibility/accessibility_feature_disable_dialog.h"
  39. #include "ash/system/accessibility/dictation_bubble_controller.h"
  40. #include "ash/system/accessibility/dictation_button_tray.h"
  41. #include "ash/system/accessibility/floating_accessibility_controller.h"
  42. #include "ash/system/accessibility/select_to_speak/select_to_speak_menu_bubble_controller.h"
  43. #include "ash/system/accessibility/switch_access/switch_access_menu_bubble_controller.h"
  44. #include "ash/system/power/backlights_forced_off_setter.h"
  45. #include "ash/system/power/power_status.h"
  46. #include "ash/system/power/scoped_backlights_forced_off.h"
  47. #include "ash/wm/tablet_mode/tablet_mode_controller.h"
  48. #include "base/bind.h"
  49. #include "base/callback_helpers.h"
  50. #include "base/metrics/histogram_functions.h"
  51. #include "base/metrics/histogram_macros.h"
  52. #include "base/metrics/user_metrics.h"
  53. #include "base/strings/string_number_conversions.h"
  54. #include "chromeos/ash/components/audio/cras_audio_handler.h"
  55. #include "chromeos/ash/components/audio/sounds.h"
  56. #include "components/live_caption/caption_util.h"
  57. #include "components/live_caption/pref_names.h"
  58. #include "components/pref_registry/pref_registry_syncable.h"
  59. #include "components/prefs/pref_change_registrar.h"
  60. #include "components/prefs/pref_registry_simple.h"
  61. #include "components/prefs/pref_service.h"
  62. #include "components/vector_icons/vector_icons.h"
  63. #include "media/base/media_switches.h"
  64. #include "ui/accessibility/accessibility_features.h"
  65. #include "ui/accessibility/accessibility_switches.h"
  66. #include "ui/accessibility/aura/aura_window_properties.h"
  67. #include "ui/aura/window.h"
  68. #include "ui/base/cursor/cursor_size.h"
  69. #include "ui/base/l10n/l10n_util.h"
  70. #include "ui/message_center/message_center.h"
  71. #include "ui/message_center/public/cpp/notifier_id.h"
  72. #include "ui/wm/core/cursor_manager.h"
  73. using session_manager::SessionState;
  74. namespace ash {
  75. namespace {
  76. using FeatureType = AccessibilityControllerImpl::FeatureType;
  77. // These classes are used to store the static configuration for a11y features.
  78. struct FeatureData {
  79. FeatureType type;
  80. const char* pref;
  81. const gfx::VectorIcon* icon;
  82. FeatureType conflicting_feature = FeatureType::kNoConflictingFeature;
  83. };
  84. struct FeatureDialogData {
  85. AccessibilityControllerImpl::FeatureType type;
  86. const char* pref;
  87. int title;
  88. int body;
  89. bool mandatory;
  90. };
  91. // A static array describing each feature.
  92. const FeatureData kFeatures[] = {
  93. {FeatureType::kAutoclick, prefs::kAccessibilityAutoclickEnabled,
  94. &kSystemMenuAccessibilityAutoClickIcon},
  95. {FeatureType::kCaretHighlight, prefs::kAccessibilityCaretHighlightEnabled,
  96. nullptr},
  97. {FeatureType::kCursorHighlight, prefs::kAccessibilityCursorHighlightEnabled,
  98. nullptr},
  99. {FeatureType::kCursorColor, prefs::kAccessibilityCursorColorEnabled,
  100. nullptr},
  101. {FeatureType::kDictation, prefs::kAccessibilityDictationEnabled,
  102. &kDictationMenuIcon},
  103. {FeatureType::kFocusHighlight, prefs::kAccessibilityFocusHighlightEnabled,
  104. nullptr, /* conflicting_feature= */ FeatureType::kSpokenFeedback},
  105. {FeatureType::kFloatingMenu, prefs::kAccessibilityFloatingMenuEnabled,
  106. nullptr},
  107. {FeatureType::kFullscreenMagnifier,
  108. prefs::kAccessibilityScreenMagnifierEnabled,
  109. &kSystemMenuAccessibilityFullscreenMagnifierIcon},
  110. {FeatureType::kDockedMagnifier, prefs::kDockedMagnifierEnabled,
  111. &kSystemMenuAccessibilityDockedMagnifierIcon},
  112. {FeatureType::kHighContrast, prefs::kAccessibilityHighContrastEnabled,
  113. &kSystemMenuAccessibilityContrastIcon},
  114. {FeatureType::kLargeCursor, prefs::kAccessibilityLargeCursorEnabled,
  115. nullptr},
  116. {FeatureType::kLiveCaption, ::prefs::kLiveCaptionEnabled,
  117. &vector_icons::kLiveCaptionOnIcon},
  118. {FeatureType::kMonoAudio, prefs::kAccessibilityMonoAudioEnabled, nullptr},
  119. {FeatureType::kSpokenFeedback, prefs::kAccessibilitySpokenFeedbackEnabled,
  120. &kSystemMenuAccessibilityChromevoxIcon},
  121. {FeatureType::kSelectToSpeak, prefs::kAccessibilitySelectToSpeakEnabled,
  122. &kSystemMenuAccessibilitySelectToSpeakIcon},
  123. {FeatureType::kStickyKeys, prefs::kAccessibilityStickyKeysEnabled, nullptr},
  124. {FeatureType::kSwitchAccess, prefs::kAccessibilitySwitchAccessEnabled,
  125. &kSwitchAccessIcon},
  126. {FeatureType::kVirtualKeyboard, prefs::kAccessibilityVirtualKeyboardEnabled,
  127. &kSystemMenuKeyboardLegacyIcon}};
  128. // An array describing the confirmation dialogs for the features which have
  129. // them.
  130. const FeatureDialogData kFeatureDialogs[] = {
  131. {FeatureType::kFullscreenMagnifier,
  132. prefs::kScreenMagnifierAcceleratorDialogHasBeenAccepted,
  133. IDS_ASH_SCREEN_MAGNIFIER_TITLE, IDS_ASH_SCREEN_MAGNIFIER_BODY, false},
  134. {FeatureType::kDockedMagnifier,
  135. prefs::kDockedMagnifierAcceleratorDialogHasBeenAccepted,
  136. IDS_ASH_DOCKED_MAGNIFIER_TITLE, IDS_ASH_DOCKED_MAGNIFIER_BODY, false},
  137. {FeatureType::kHighContrast,
  138. prefs::kHighContrastAcceleratorDialogHasBeenAccepted,
  139. IDS_ASH_HIGH_CONTRAST_TITLE, IDS_ASH_HIGH_CONTRAST_BODY, false}};
  140. constexpr char kNotificationId[] = "chrome://settings/accessibility";
  141. constexpr char kNotifierAccessibility[] = "ash.accessibility";
  142. // TODO(warx): Signin screen has more controllable accessibility prefs. We may
  143. // want to expand this to a complete list. If so, merge this with
  144. // |kCopiedOnSigninAccessibilityPrefs|.
  145. constexpr const char* const kA11yPrefsForRecommendedValueOnSignin[]{
  146. prefs::kAccessibilityLargeCursorEnabled,
  147. prefs::kAccessibilityHighContrastEnabled,
  148. prefs::kAccessibilityScreenMagnifierEnabled,
  149. prefs::kAccessibilitySpokenFeedbackEnabled,
  150. prefs::kAccessibilityVirtualKeyboardEnabled,
  151. };
  152. // List of accessibility prefs that are to be copied (if changed by the user) on
  153. // signin screen profile to a newly created user profile or a guest session.
  154. constexpr const char* const kCopiedOnSigninAccessibilityPrefs[]{
  155. prefs::kAccessibilityAutoclickDelayMs,
  156. prefs::kAccessibilityAutoclickEnabled,
  157. prefs::kAccessibilityCaretHighlightEnabled,
  158. prefs::kAccessibilityCursorHighlightEnabled,
  159. prefs::kAccessibilityCursorColorEnabled,
  160. prefs::kAccessibilityCursorColor,
  161. prefs::kAccessibilityDictationEnabled,
  162. prefs::kAccessibilityDictationLocale,
  163. prefs::kAccessibilityDictationLocaleOfflineNudge,
  164. prefs::kAccessibilityFocusHighlightEnabled,
  165. prefs::kAccessibilityHighContrastEnabled,
  166. prefs::kAccessibilityLargeCursorEnabled,
  167. prefs::kAccessibilityMonoAudioEnabled,
  168. prefs::kAccessibilityScreenMagnifierEnabled,
  169. prefs::kAccessibilityScreenMagnifierFocusFollowingEnabled,
  170. prefs::kAccessibilityScreenMagnifierMouseFollowingMode,
  171. prefs::kAccessibilityScreenMagnifierScale,
  172. prefs::kAccessibilitySelectToSpeakEnabled,
  173. prefs::kAccessibilitySpokenFeedbackEnabled,
  174. prefs::kAccessibilityStickyKeysEnabled,
  175. prefs::kAccessibilityShortcutsEnabled,
  176. prefs::kAccessibilitySwitchAccessEnabled,
  177. prefs::kAccessibilityVirtualKeyboardEnabled,
  178. prefs::kDockedMagnifierEnabled,
  179. prefs::kDockedMagnifierScale,
  180. prefs::kDockedMagnifierScreenHeightDivisor,
  181. prefs::kHighContrastAcceleratorDialogHasBeenAccepted,
  182. prefs::kScreenMagnifierAcceleratorDialogHasBeenAccepted,
  183. prefs::kDockedMagnifierAcceleratorDialogHasBeenAccepted,
  184. prefs::kDictationAcceleratorDialogHasBeenAccepted,
  185. prefs::kDisplayRotationAcceleratorDialogHasBeenAccepted2,
  186. };
  187. // List of switch access accessibility prefs that are to be copied (if changed
  188. // by the user) from the current user to the signin screen profile. That way
  189. // if a switch access user signs out, their switch continues to function.
  190. constexpr const char* const kSwitchAccessPrefsCopiedToSignin[]{
  191. prefs::kAccessibilitySwitchAccessAutoScanEnabled,
  192. prefs::kAccessibilitySwitchAccessAutoScanKeyboardSpeedMs,
  193. prefs::kAccessibilitySwitchAccessAutoScanSpeedMs,
  194. prefs::kAccessibilitySwitchAccessPointScanSpeedDipsPerSecond,
  195. prefs::kAccessibilitySwitchAccessEnabled,
  196. prefs::kAccessibilitySwitchAccessNextDeviceKeyCodes,
  197. prefs::kAccessibilitySwitchAccessPreviousDeviceKeyCodes,
  198. prefs::kAccessibilitySwitchAccessSelectDeviceKeyCodes,
  199. };
  200. // Helper function that is used to verify the validity of kFeatures and
  201. // kFeatureDialogs.
  202. bool VerifyFeaturesData() {
  203. // All feature prefs must be unique.
  204. std::set<const char*> feature_prefs;
  205. for (auto feature_data : kFeatures) {
  206. if (feature_prefs.find(feature_data.pref) != feature_prefs.end())
  207. return false;
  208. feature_prefs.insert(feature_data.pref);
  209. }
  210. for (auto dialog_data : kFeatureDialogs) {
  211. if (feature_prefs.find(dialog_data.pref) != feature_prefs.end())
  212. return false;
  213. feature_prefs.insert(dialog_data.pref);
  214. }
  215. return true;
  216. }
  217. // Returns true if |pref_service| is the one used for the signin screen.
  218. bool IsSigninPrefService(PrefService* pref_service) {
  219. const PrefService* signin_pref_service =
  220. Shell::Get()->session_controller()->GetSigninScreenPrefService();
  221. DCHECK(signin_pref_service);
  222. return pref_service == signin_pref_service;
  223. }
  224. // Returns true if the current session is the guest session.
  225. bool IsCurrentSessionGuest() {
  226. const absl::optional<user_manager::UserType> user_type =
  227. Shell::Get()->session_controller()->GetUserType();
  228. return user_type && *user_type == user_manager::USER_TYPE_GUEST;
  229. }
  230. bool IsUserFirstLogin() {
  231. return Shell::Get()->session_controller()->IsUserFirstLogin();
  232. }
  233. // The copying of any modified accessibility prefs on the signin prefs happens
  234. // when the |previous_pref_service| is of the signin profile, and the
  235. // |current_pref_service| is of a newly created profile first logged in, or if
  236. // the current session is the guest session.
  237. bool ShouldCopySigninPrefs(PrefService* previous_pref_service,
  238. PrefService* current_pref_service) {
  239. DCHECK(previous_pref_service);
  240. if (IsUserFirstLogin() && IsSigninPrefService(previous_pref_service) &&
  241. !IsSigninPrefService(current_pref_service)) {
  242. // If the user set a pref value on the login screen and is now starting a
  243. // session with a new profile, copy the pref value to the profile.
  244. return true;
  245. }
  246. if (IsCurrentSessionGuest()) {
  247. // Guest sessions don't have their own prefs, so always copy.
  248. return true;
  249. }
  250. return false;
  251. }
  252. // On a user's first login into a device, any a11y features enabled/disabled
  253. // by the user on the login screen are enabled/disabled in the user's profile.
  254. // This function copies settings from the signin prefs into the user's prefs
  255. // when it detects a login with a newly created profile.
  256. void CopySigninPrefsIfNeeded(PrefService* previous_pref_service,
  257. PrefService* current_pref_service) {
  258. DCHECK(current_pref_service);
  259. if (!ShouldCopySigninPrefs(previous_pref_service, current_pref_service))
  260. return;
  261. PrefService* signin_prefs =
  262. Shell::Get()->session_controller()->GetSigninScreenPrefService();
  263. DCHECK(signin_prefs);
  264. for (const auto* pref_path : kCopiedOnSigninAccessibilityPrefs) {
  265. const PrefService::Preference* pref =
  266. signin_prefs->FindPreference(pref_path);
  267. // Ignore if the pref has not been set by the user.
  268. if (!pref || !pref->IsUserControlled())
  269. continue;
  270. // Copy the pref value from the signin profile.
  271. const base::Value* value_on_login = pref->GetValue();
  272. current_pref_service->Set(pref_path, *value_on_login);
  273. }
  274. }
  275. // Returns notification icon based on the A11yNotificationType.
  276. const gfx::VectorIcon& GetNotificationIcon(A11yNotificationType type) {
  277. switch (type) {
  278. case A11yNotificationType::kSpokenFeedbackBrailleEnabled:
  279. return kNotificationAccessibilityIcon;
  280. case A11yNotificationType::kBrailleDisplayConnected:
  281. return kNotificationAccessibilityBrailleIcon;
  282. case A11yNotificationType::kSwitchAccessEnabled:
  283. return kSwitchAccessIcon;
  284. case A11yNotificationType::kSpeechRecognitionFilesDownloaded:
  285. case A11yNotificationType::kSpeechRecognitionFilesFailed:
  286. return kDictationMenuIcon;
  287. default:
  288. return kNotificationChromevoxIcon;
  289. }
  290. }
  291. void ShowAccessibilityNotification(
  292. const AccessibilityControllerImpl::A11yNotificationWrapper& wrapper) {
  293. A11yNotificationType type = wrapper.type;
  294. const auto& replacements = wrapper.replacements;
  295. message_center::MessageCenter* message_center =
  296. message_center::MessageCenter::Get();
  297. message_center->RemoveNotification(kNotificationId, false /* by_user */);
  298. if (type == A11yNotificationType::kNone)
  299. return;
  300. std::u16string text;
  301. std::u16string title;
  302. std::u16string display_source;
  303. auto catalog_name = NotificationCatalogName::kNone;
  304. bool pinned = true;
  305. message_center::SystemNotificationWarningLevel warning =
  306. message_center::SystemNotificationWarningLevel::NORMAL;
  307. if (type == A11yNotificationType::kBrailleDisplayConnected) {
  308. text = l10n_util::GetStringUTF16(
  309. IDS_ASH_STATUS_TRAY_BRAILLE_DISPLAY_CONNECTED);
  310. catalog_name = NotificationCatalogName::kBrailleDisplayConnected;
  311. } else if (type == A11yNotificationType::kSwitchAccessEnabled) {
  312. title = l10n_util::GetStringUTF16(
  313. IDS_ASH_STATUS_TRAY_SWITCH_ACCESS_ENABLED_TITLE);
  314. text = l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SWITCH_ACCESS_ENABLED);
  315. catalog_name = NotificationCatalogName::kSwitchAccessEnabled;
  316. } else if (type == A11yNotificationType::kSpeechRecognitionFilesDownloaded) {
  317. display_source =
  318. l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ACCESSIBILITY_DICTATION);
  319. title = l10n_util::GetStringFUTF16(
  320. IDS_ASH_A11Y_DICTATION_NOTIFICATION_SODA_DOWNLOAD_SUCCEEDED_TITLE,
  321. replacements, nullptr);
  322. text = l10n_util::GetStringUTF16(
  323. IDS_ASH_A11Y_DICTATION_NOTIFICATION_SODA_DOWNLOAD_SUCCEEDED_DESC);
  324. pinned = false;
  325. catalog_name = NotificationCatalogName::kSpeechRecognitionFilesDownloaded;
  326. } else if (type == A11yNotificationType::kSpeechRecognitionFilesFailed) {
  327. display_source =
  328. l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ACCESSIBILITY_DICTATION);
  329. title = l10n_util::GetStringFUTF16(
  330. IDS_ASH_A11Y_DICTATION_NOTIFICATION_SODA_DOWNLOAD_FAILED_TITLE,
  331. replacements, nullptr);
  332. text = l10n_util::GetStringUTF16(
  333. IDS_ASH_A11Y_DICTATION_NOTIFICATION_SODA_DOWNLOAD_FAILED_DESC);
  334. // Use CRITICAL_WARNING to force the notification color to red.
  335. warning = message_center::SystemNotificationWarningLevel::CRITICAL_WARNING;
  336. pinned = false;
  337. catalog_name = NotificationCatalogName::kSpeechRecognitionFilesFailed;
  338. } else {
  339. bool is_tablet = Shell::Get()->tablet_mode_controller()->InTabletMode();
  340. title = l10n_util::GetStringUTF16(
  341. type == A11yNotificationType::kSpokenFeedbackBrailleEnabled
  342. ? IDS_ASH_STATUS_TRAY_SPOKEN_FEEDBACK_BRAILLE_ENABLED_TITLE
  343. : IDS_ASH_STATUS_TRAY_SPOKEN_FEEDBACK_ENABLED_TITLE);
  344. text = l10n_util::GetStringUTF16(
  345. is_tablet ? IDS_ASH_STATUS_TRAY_SPOKEN_FEEDBACK_ENABLED_TABLET
  346. : IDS_ASH_STATUS_TRAY_SPOKEN_FEEDBACK_ENABLED);
  347. catalog_name = type == A11yNotificationType::kSpokenFeedbackBrailleEnabled
  348. ? NotificationCatalogName::kSpokenFeedbackBrailleEnabled
  349. : NotificationCatalogName::kSpokenFeedbackEnabled;
  350. }
  351. message_center::RichNotificationData options;
  352. options.should_make_spoken_feedback_for_popup_updates = false;
  353. std::unique_ptr<message_center::Notification> notification =
  354. ash::CreateSystemNotification(
  355. message_center::NOTIFICATION_TYPE_SIMPLE, kNotificationId, title,
  356. text, display_source, GURL(),
  357. message_center::NotifierId(
  358. message_center::NotifierType::SYSTEM_COMPONENT,
  359. kNotifierAccessibility, catalog_name),
  360. options, nullptr, GetNotificationIcon(type), warning);
  361. notification->set_pinned(pinned);
  362. message_center->AddNotification(std::move(notification));
  363. }
  364. void RemoveAccessibilityNotification() {
  365. ShowAccessibilityNotification(
  366. AccessibilityControllerImpl::A11yNotificationWrapper(
  367. A11yNotificationType::kNone, std::vector<std::u16string>()));
  368. }
  369. AccessibilityPanelLayoutManager* GetLayoutManager() {
  370. // The accessibility panel is only shown on the primary display.
  371. aura::Window* root = Shell::GetPrimaryRootWindow();
  372. aura::Window* container =
  373. Shell::GetContainer(root, kShellWindowId_AccessibilityPanelContainer);
  374. // TODO(jamescook): Avoid this cast by moving ash::AccessibilityObserver
  375. // ownership to this class and notifying it on accessibility panel fullscreen
  376. // updates.
  377. return static_cast<AccessibilityPanelLayoutManager*>(
  378. container->layout_manager());
  379. }
  380. std::string PrefKeyForSwitchAccessCommand(SwitchAccessCommand command) {
  381. switch (command) {
  382. case SwitchAccessCommand::kSelect:
  383. return prefs::kAccessibilitySwitchAccessSelectDeviceKeyCodes;
  384. case SwitchAccessCommand::kNext:
  385. return prefs::kAccessibilitySwitchAccessNextDeviceKeyCodes;
  386. case SwitchAccessCommand::kPrevious:
  387. return prefs::kAccessibilitySwitchAccessPreviousDeviceKeyCodes;
  388. case SwitchAccessCommand::kNone:
  389. NOTREACHED();
  390. return "";
  391. }
  392. }
  393. std::string UmaNameForSwitchAccessCommand(SwitchAccessCommand command) {
  394. switch (command) {
  395. case SwitchAccessCommand::kSelect:
  396. return "Accessibility.CrosSwitchAccess.SelectKeyCode";
  397. case SwitchAccessCommand::kNext:
  398. return "Accessibility.CrosSwitchAccess.NextKeyCode";
  399. case SwitchAccessCommand::kPrevious:
  400. return "Accessibility.CrosSwitchAccess.PreviousKeyCode";
  401. case SwitchAccessCommand::kNone:
  402. NOTREACHED();
  403. return "";
  404. }
  405. }
  406. // These values are persisted to logs. Entries should not be renumbered and
  407. // numeric values should never be reused.
  408. enum class SwitchAccessKeyCode {
  409. kUnknown = 0,
  410. kKeycode1 = 1,
  411. kKeycode2 = 2,
  412. kKeycode3 = 3,
  413. kKeycode4 = 4,
  414. kKeycode5 = 5,
  415. kKeycode6 = 6,
  416. kKeycode7 = 7,
  417. kBackspace = 8,
  418. kTab = 9,
  419. kKeycode10 = 10,
  420. kKeycode11 = 11,
  421. kClear = 12,
  422. kReturn = 13,
  423. kKeycode14 = 14,
  424. kKeycode15 = 15,
  425. kShift = 16,
  426. kControl = 17,
  427. kAlt = 18,
  428. kPause = 19,
  429. kCapital = 20,
  430. kKana = 21,
  431. kKeycode22 = 22,
  432. kJunja = 23,
  433. kFinal = 24,
  434. kHanja = 25,
  435. kKeycode26 = 26,
  436. kEscape = 27,
  437. kConvert = 28,
  438. kNonconvert = 29,
  439. kAccept = 30,
  440. kModechange = 31,
  441. kSpace = 32,
  442. kPrior = 33,
  443. kNext = 34,
  444. kEnd = 35,
  445. kHome = 36,
  446. kLeft = 37,
  447. kUp = 38,
  448. kRight = 39,
  449. kDown = 40,
  450. kSelect = 41,
  451. kPrint = 42,
  452. kExecute = 43,
  453. kSnapshot = 44,
  454. kInsert = 45,
  455. kKeyDelete = 46,
  456. kHelp = 47,
  457. kNum0 = 48,
  458. kNum1 = 49,
  459. kNum2 = 50,
  460. kNum3 = 51,
  461. kNum4 = 52,
  462. kNum5 = 53,
  463. kNum6 = 54,
  464. kNum7 = 55,
  465. kNum8 = 56,
  466. kNum9 = 57,
  467. kKeycode58 = 58,
  468. kKeycode59 = 59,
  469. kKeycode60 = 60,
  470. kKeycode61 = 61,
  471. kKeycode62 = 62,
  472. kKeycode63 = 63,
  473. kKeycode64 = 64,
  474. kA = 65,
  475. kB = 66,
  476. kC = 67,
  477. kD = 68,
  478. kE = 69,
  479. kF = 70,
  480. kG = 71,
  481. kH = 72,
  482. kI = 73,
  483. kJ = 74,
  484. kK = 75,
  485. kL = 76,
  486. kM = 77,
  487. kN = 78,
  488. kO = 79,
  489. kP = 80,
  490. kQ = 81,
  491. kR = 82,
  492. kS = 83,
  493. kT = 84,
  494. kU = 85,
  495. kV = 86,
  496. kW = 87,
  497. kX = 88,
  498. kY = 89,
  499. kZ = 90,
  500. kLwin = 91,
  501. kRwin = 92,
  502. kApps = 93,
  503. kKeycode94 = 94,
  504. kSleep = 95,
  505. kNumpad0 = 96,
  506. kNumpad1 = 97,
  507. kNumpad2 = 98,
  508. kNumpad3 = 99,
  509. kNumpad4 = 100,
  510. kNumpad5 = 101,
  511. kNumpad6 = 102,
  512. kNumpad7 = 103,
  513. kNumpad8 = 104,
  514. kNumpad9 = 105,
  515. kMultiply = 106,
  516. kAdd = 107,
  517. kSeparator = 108,
  518. kSubtract = 109,
  519. kDecimal = 110,
  520. kDivide = 111,
  521. kF1 = 112,
  522. kF2 = 113,
  523. kF3 = 114,
  524. kF4 = 115,
  525. kF5 = 116,
  526. kF6 = 117,
  527. kF7 = 118,
  528. kF8 = 119,
  529. kF9 = 120,
  530. kF10 = 121,
  531. kF11 = 122,
  532. kF12 = 123,
  533. kF13 = 124,
  534. kF14 = 125,
  535. kF15 = 126,
  536. kF16 = 127,
  537. kF17 = 128,
  538. kF18 = 129,
  539. kF19 = 130,
  540. kF20 = 131,
  541. kF21 = 132,
  542. kF22 = 133,
  543. kF23 = 134,
  544. kF24 = 135,
  545. kKeycode136 = 136,
  546. kKeycode137 = 137,
  547. kKeycode138 = 138,
  548. kKeycode139 = 139,
  549. kKeycode140 = 140,
  550. kKeycode141 = 141,
  551. kKeycode142 = 142,
  552. kKeycode143 = 143,
  553. kNumlock = 144,
  554. kScroll = 145,
  555. kKeycode146 = 146,
  556. kKeycode147 = 147,
  557. kKeycode148 = 148,
  558. kKeycode149 = 149,
  559. kKeycode150 = 150,
  560. kWlan = 151,
  561. kPower = 152,
  562. kAssistant = 153,
  563. kKeycode154 = 154,
  564. kKeycode155 = 155,
  565. kKeycode156 = 156,
  566. kKeycode157 = 157,
  567. kKeycode158 = 158,
  568. kKeycode159 = 159,
  569. kLshift = 160,
  570. kRshift = 161,
  571. kLcontrol = 162,
  572. kRcontrol = 163,
  573. kLmenu = 164,
  574. kRmenu = 165,
  575. kBrowserBack = 166,
  576. kBrowserForward = 167,
  577. kBrowserRefresh = 168,
  578. kBrowserStop = 169,
  579. kBrowserSearch = 170,
  580. kBrowserFavorites = 171,
  581. kBrowserHome = 172,
  582. kVolumeMute = 173,
  583. kVolumeDown = 174,
  584. kVolumeUp = 175,
  585. kMediaNextTrack = 176,
  586. kMediaPrevTrack = 177,
  587. kMediaStop = 178,
  588. kMediaPlayPause = 179,
  589. kMediaLaunchMail = 180,
  590. kMediaLaunchMediaSelect = 181,
  591. kMediaLaunchApp1 = 182,
  592. kMediaLaunchApp2 = 183,
  593. kKeycode184 = 184,
  594. kKeycode185 = 185,
  595. kOem1 = 186,
  596. kOemPlus = 187,
  597. kOemComma = 188,
  598. kOemMinus = 189,
  599. kOemPeriod = 190,
  600. kOem2 = 191,
  601. kOem3 = 192,
  602. kKeycode193 = 193,
  603. kKeycode194 = 194,
  604. kKeycode195 = 195,
  605. kKeycode196 = 196,
  606. kKeycode197 = 197,
  607. kKeycode198 = 198,
  608. kKeycode199 = 199,
  609. kKeycode200 = 200,
  610. kKeycode201 = 201,
  611. kKeycode202 = 202,
  612. kKeycode203 = 203,
  613. kKeycode204 = 204,
  614. kKeycode205 = 205,
  615. kKeycode206 = 206,
  616. kKeycode207 = 207,
  617. kKeycode208 = 208,
  618. kKeycode209 = 209,
  619. kKeycode210 = 210,
  620. kKeycode211 = 211,
  621. kKeycode212 = 212,
  622. kKeycode213 = 213,
  623. kKeycode214 = 214,
  624. kKeycode215 = 215,
  625. kBrightnessDown = 216,
  626. kBrightnessUp = 217,
  627. kKbdBrightnessDown = 218,
  628. kOem4 = 219,
  629. kOem5 = 220,
  630. kOem6 = 221,
  631. kOem7 = 222,
  632. kOem8 = 223,
  633. kKeycode224 = 224,
  634. kAltgr = 225,
  635. kOem102 = 226,
  636. kKeycode227 = 227,
  637. kKeycode228 = 228,
  638. kProcesskey = 229,
  639. kCompose = 230,
  640. kPacket = 231,
  641. kKbdBrightnessUp = 232,
  642. kKeycode233 = 233,
  643. kKeycode234 = 234,
  644. kKeycode235 = 235,
  645. kKeycode236 = 236,
  646. kKeycode237 = 237,
  647. kKeycode238 = 238,
  648. kKeycode239 = 239,
  649. kKeycode240 = 240,
  650. kKeycode241 = 241,
  651. kKeycode242 = 242,
  652. kDbeSbcschar = 243,
  653. kDbeDbcschar = 244,
  654. kKeycode245 = 245,
  655. kAttn = 246,
  656. kCrsel = 247,
  657. kExsel = 248,
  658. kEreof = 249,
  659. kPlay = 250,
  660. kZoom = 251,
  661. kNoname = 252,
  662. kPa1 = 253,
  663. kOemClear = 254,
  664. kKeycode255 = 255,
  665. kNone = 256,
  666. kMaxValue = kNone,
  667. };
  668. } // namespace
  669. AccessibilityControllerImpl::Feature::Feature(
  670. FeatureType type,
  671. const std::string& pref_name,
  672. const gfx::VectorIcon* icon,
  673. AccessibilityControllerImpl* controller)
  674. : type_(type), pref_name_(pref_name), icon_(icon), owner_(controller) {}
  675. AccessibilityControllerImpl::Feature::~Feature() = default;
  676. void AccessibilityControllerImpl::Feature::SetEnabled(bool enabled) {
  677. PrefService* prefs = owner_->active_user_prefs_;
  678. if (!prefs)
  679. return;
  680. prefs->SetBoolean(pref_name_, enabled);
  681. prefs->CommitPendingWrite();
  682. }
  683. bool AccessibilityControllerImpl::Feature::IsVisibleInTray() const {
  684. return (conflicting_feature_ == kNoConflictingFeature ||
  685. !owner_->GetFeature(conflicting_feature_).enabled()) &&
  686. owner_->IsAccessibilityFeatureVisibleInTrayMenu(pref_name_);
  687. }
  688. bool AccessibilityControllerImpl::Feature::IsEnterpriseIconVisible() const {
  689. return owner_->IsEnterpriseIconVisibleInTrayMenu(pref_name_);
  690. }
  691. const gfx::VectorIcon& AccessibilityControllerImpl::Feature::icon() const {
  692. DCHECK(icon_);
  693. if (icon_)
  694. return *icon_;
  695. return kPaletteTrayIconDefaultIcon;
  696. }
  697. void AccessibilityControllerImpl::Feature::UpdateFromPref() {
  698. PrefService* prefs = owner_->active_user_prefs_;
  699. DCHECK(prefs);
  700. bool enabled = prefs->GetBoolean(pref_name_);
  701. if (conflicting_feature_ != FeatureType::kNoConflictingFeature &&
  702. owner_->GetFeature(conflicting_feature_).enabled()) {
  703. enabled = false;
  704. }
  705. if (enabled == enabled_)
  706. return;
  707. enabled_ = enabled;
  708. owner_->UpdateFeatureFromPref(type_);
  709. }
  710. void AccessibilityControllerImpl::Feature::SetConflictingFeature(
  711. AccessibilityControllerImpl::FeatureType feature) {
  712. DCHECK_EQ(conflicting_feature_, FeatureType::kNoConflictingFeature);
  713. conflicting_feature_ = feature;
  714. }
  715. AccessibilityControllerImpl::FeatureWithDialog::FeatureWithDialog(
  716. FeatureType type,
  717. const std::string& pref_name,
  718. const gfx::VectorIcon* icon,
  719. const Dialog& dialog,
  720. AccessibilityControllerImpl* controller)
  721. : AccessibilityControllerImpl::Feature(type, pref_name, icon, controller),
  722. dialog_(dialog) {}
  723. AccessibilityControllerImpl::FeatureWithDialog::~FeatureWithDialog() = default;
  724. void AccessibilityControllerImpl::FeatureWithDialog::SetDialogAccepted() {
  725. PrefService* prefs = owner_->active_user_prefs_;
  726. if (!prefs)
  727. return;
  728. prefs->SetBoolean(dialog_.pref_name, true);
  729. prefs->CommitPendingWrite();
  730. }
  731. bool AccessibilityControllerImpl::FeatureWithDialog::WasDialogAccepted() const {
  732. PrefService* prefs = owner_->active_user_prefs_;
  733. DCHECK(prefs);
  734. return prefs->GetBoolean(dialog_.pref_name);
  735. }
  736. void AccessibilityControllerImpl::FeatureWithDialog::SetEnabledWithDialog(
  737. bool enabled,
  738. base::OnceClosure completion_callback) {
  739. PrefService* prefs = owner_->active_user_prefs_;
  740. if (!prefs)
  741. return;
  742. // We should not show the dialog when the feature is already enabled.
  743. if (enabled && !this->enabled() && !WasDialogAccepted()) {
  744. Shell::Get()->accelerator_controller()->MaybeShowConfirmationDialog(
  745. dialog_.title_resource_id, dialog_.body_resource_id,
  746. // Callback for if the user accepts the dialog
  747. base::BindOnce(
  748. [](base::WeakPtr<AccessibilityControllerImpl> owner,
  749. FeatureType type, base::OnceClosure completion_callback) {
  750. if (!owner)
  751. return;
  752. static_cast<FeatureWithDialog&>(owner->GetFeature(type))
  753. .SetDialogAccepted();
  754. // If they accept, try again to set value to true
  755. owner->GetFeature(type).SetEnabled(true);
  756. std::move(completion_callback).Run();
  757. },
  758. owner_->weak_ptr_factory_.GetWeakPtr(), type_,
  759. std::move(completion_callback)),
  760. base::DoNothing());
  761. return;
  762. }
  763. Feature::SetEnabled(enabled);
  764. std::move(completion_callback).Run();
  765. }
  766. void AccessibilityControllerImpl::FeatureWithDialog::SetEnabled(bool enabled) {
  767. if (dialog_.mandatory)
  768. SetEnabledWithDialog(enabled, base::DoNothing());
  769. else
  770. Feature::SetEnabled(enabled);
  771. }
  772. AccessibilityControllerImpl::AccessibilityControllerImpl()
  773. : autoclick_delay_(AutoclickController::GetDefaultAutoclickDelay()) {
  774. Shell::Get()->session_controller()->AddObserver(this);
  775. Shell::Get()->tablet_mode_controller()->AddObserver(this);
  776. CreateAccessibilityFeatures();
  777. }
  778. AccessibilityControllerImpl::~AccessibilityControllerImpl() {
  779. floating_menu_controller_.reset();
  780. }
  781. void AccessibilityControllerImpl::CreateAccessibilityFeatures() {
  782. DCHECK(VerifyFeaturesData());
  783. // First, build all features with dialog.
  784. std::map<FeatureType, Dialog> dialogs;
  785. for (auto dialog_data : kFeatureDialogs) {
  786. dialogs[dialog_data.type] = {dialog_data.pref, dialog_data.title,
  787. dialog_data.body, dialog_data.mandatory};
  788. }
  789. for (auto feature_data : kFeatures) {
  790. DCHECK(!features_[feature_data.type]);
  791. auto it = dialogs.find(feature_data.type);
  792. if (it == dialogs.end()) {
  793. features_[feature_data.type] = std::make_unique<Feature>(
  794. feature_data.type, feature_data.pref, feature_data.icon, this);
  795. } else {
  796. features_[feature_data.type] = std::make_unique<FeatureWithDialog>(
  797. feature_data.type, feature_data.pref, feature_data.icon, it->second,
  798. this);
  799. }
  800. }
  801. }
  802. // static
  803. void AccessibilityControllerImpl::RegisterProfilePrefs(
  804. PrefRegistrySimple* registry) {
  805. //
  806. // Non-syncable prefs.
  807. //
  808. // These prefs control whether an accessibility feature is enabled. They are
  809. // not synced due to the impact they have on device interaction.
  810. registry->RegisterBooleanPref(prefs::kAccessibilityAutoclickEnabled, false);
  811. registry->RegisterBooleanPref(prefs::kAccessibilityCursorColorEnabled, false);
  812. registry->RegisterBooleanPref(prefs::kAccessibilityCaretHighlightEnabled,
  813. false);
  814. registry->RegisterBooleanPref(prefs::kAccessibilityCursorHighlightEnabled,
  815. false);
  816. registry->RegisterBooleanPref(prefs::kAccessibilityDictationEnabled, false);
  817. registry->RegisterBooleanPref(prefs::kAccessibilityFloatingMenuEnabled,
  818. false);
  819. registry->RegisterBooleanPref(prefs::kAccessibilityFocusHighlightEnabled,
  820. false);
  821. registry->RegisterBooleanPref(prefs::kAccessibilityHighContrastEnabled,
  822. false);
  823. registry->RegisterBooleanPref(prefs::kAccessibilityLargeCursorEnabled, false);
  824. registry->RegisterBooleanPref(prefs::kAccessibilityMonoAudioEnabled, false);
  825. registry->RegisterBooleanPref(prefs::kAccessibilityScreenMagnifierEnabled,
  826. false);
  827. registry->RegisterBooleanPref(prefs::kAccessibilitySpokenFeedbackEnabled,
  828. false);
  829. registry->RegisterBooleanPref(prefs::kAccessibilitySelectToSpeakEnabled,
  830. false);
  831. registry->RegisterBooleanPref(prefs::kAccessibilityStickyKeysEnabled, false);
  832. registry->RegisterBooleanPref(prefs::kAccessibilityShortcutsEnabled, true);
  833. registry->RegisterBooleanPref(prefs::kAccessibilitySwitchAccessEnabled,
  834. false);
  835. registry->RegisterBooleanPref(prefs::kAccessibilityVirtualKeyboardEnabled,
  836. false);
  837. registry->RegisterBooleanPref(
  838. prefs::kAccessibilityTabletModeShelfNavigationButtonsEnabled, false);
  839. // Not syncable because it might change depending on application locale,
  840. // user settings, and because different languages can cause speech recognition
  841. // files to download.
  842. registry->RegisterStringPref(prefs::kAccessibilityDictationLocale,
  843. std::string());
  844. registry->RegisterDictionaryPref(
  845. prefs::kAccessibilityDictationLocaleOfflineNudge);
  846. // A pref in this list is associated with accepting for the first time,
  847. // enabling of some pref above. Non-syncable like all of the above prefs.
  848. registry->RegisterBooleanPref(
  849. prefs::kHighContrastAcceleratorDialogHasBeenAccepted, false);
  850. registry->RegisterBooleanPref(
  851. prefs::kScreenMagnifierAcceleratorDialogHasBeenAccepted, false);
  852. registry->RegisterBooleanPref(
  853. prefs::kDockedMagnifierAcceleratorDialogHasBeenAccepted, false);
  854. registry->RegisterBooleanPref(
  855. prefs::kDictationAcceleratorDialogHasBeenAccepted, false);
  856. registry->RegisterBooleanPref(
  857. prefs::kDisplayRotationAcceleratorDialogHasBeenAccepted2, false);
  858. registry->RegisterBooleanPref(prefs::kShouldAlwaysShowAccessibilityMenu,
  859. false);
  860. //
  861. // Syncable prefs.
  862. //
  863. // These prefs pertain to specific features. They are synced to preserve
  864. // behaviors tied to user accounts once that user enables a feature.
  865. registry->RegisterIntegerPref(
  866. prefs::kAccessibilityAutoclickDelayMs, kDefaultAutoclickDelayMs,
  867. user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
  868. registry->RegisterIntegerPref(
  869. prefs::kAccessibilityAutoclickEventType,
  870. static_cast<int>(kDefaultAutoclickEventType),
  871. user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
  872. registry->RegisterBooleanPref(
  873. prefs::kAccessibilityAutoclickRevertToLeftClick, true,
  874. user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
  875. registry->RegisterBooleanPref(
  876. prefs::kAccessibilityAutoclickStabilizePosition, false,
  877. user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
  878. registry->RegisterIntegerPref(
  879. prefs::kAccessibilityAutoclickMovementThreshold,
  880. kDefaultAutoclickMovementThreshold,
  881. user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
  882. registry->RegisterIntegerPref(
  883. prefs::kAccessibilityAutoclickMenuPosition,
  884. static_cast<int>(kDefaultAutoclickMenuPosition),
  885. user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
  886. registry->RegisterIntegerPref(
  887. prefs::kAccessibilityCursorColor, 0,
  888. user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
  889. registry->RegisterIntegerPref(
  890. prefs::kAccessibilityFloatingMenuPosition,
  891. static_cast<int>(kDefaultFloatingMenuPosition),
  892. user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
  893. registry->RegisterIntegerPref(prefs::kAccessibilityLargeCursorDipSize,
  894. kDefaultLargeCursorSize);
  895. registry->RegisterIntegerPref(
  896. prefs::kAccessibilityScreenMagnifierMouseFollowingMode,
  897. static_cast<int>(MagnifierMouseFollowingMode::kEdge),
  898. user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
  899. registry->RegisterBooleanPref(
  900. prefs::kAccessibilityScreenMagnifierCenterFocus, true,
  901. user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
  902. registry->RegisterBooleanPref(
  903. prefs::kAccessibilityScreenMagnifierFocusFollowingEnabled, true,
  904. user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
  905. registry->RegisterDoublePref(prefs::kAccessibilityScreenMagnifierScale,
  906. std::numeric_limits<double>::min());
  907. registry->RegisterDictionaryPref(
  908. prefs::kAccessibilitySwitchAccessSelectDeviceKeyCodes,
  909. base::Value(base::Value::Type::DICTIONARY),
  910. user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
  911. registry->RegisterDictionaryPref(
  912. prefs::kAccessibilitySwitchAccessNextDeviceKeyCodes,
  913. base::Value(base::Value::Type::DICTIONARY),
  914. user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
  915. registry->RegisterDictionaryPref(
  916. prefs::kAccessibilitySwitchAccessPreviousDeviceKeyCodes,
  917. base::Value(base::Value::Type::DICTIONARY),
  918. user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
  919. registry->RegisterBooleanPref(
  920. prefs::kAccessibilitySwitchAccessAutoScanEnabled, false,
  921. user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
  922. registry->RegisterIntegerPref(
  923. prefs::kAccessibilitySwitchAccessAutoScanSpeedMs,
  924. kDefaultSwitchAccessAutoScanSpeed.InMilliseconds(),
  925. user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
  926. registry->RegisterIntegerPref(
  927. prefs::kAccessibilitySwitchAccessAutoScanKeyboardSpeedMs,
  928. kDefaultSwitchAccessAutoScanSpeed.InMilliseconds(),
  929. user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
  930. registry->RegisterIntegerPref(
  931. prefs::kAccessibilitySwitchAccessPointScanSpeedDipsPerSecond,
  932. kDefaultSwitchAccessPointScanSpeedDipsPerSecond,
  933. user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
  934. registry->RegisterBooleanPref(
  935. prefs::kAccessibilityEnhancedNetworkVoicesInSelectToSpeakAllowed, true,
  936. user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
  937. }
  938. void AccessibilityControllerImpl::Shutdown() {
  939. Shell::Get()->tablet_mode_controller()->RemoveObserver(this);
  940. Shell::Get()->session_controller()->RemoveObserver(this);
  941. // Clean up any child windows and widgets that might be animating out.
  942. dictation_nudge_controller_.reset();
  943. dictation_bubble_controller_.reset();
  944. for (auto& observer : observers_)
  945. observer.OnAccessibilityControllerShutdown();
  946. }
  947. bool AccessibilityControllerImpl::
  948. HasDisplayRotationAcceleratorDialogBeenAccepted() const {
  949. return active_user_prefs_ &&
  950. active_user_prefs_->GetBoolean(
  951. prefs::kDisplayRotationAcceleratorDialogHasBeenAccepted2);
  952. }
  953. void AccessibilityControllerImpl::
  954. SetDisplayRotationAcceleratorDialogBeenAccepted() {
  955. if (!active_user_prefs_)
  956. return;
  957. active_user_prefs_->SetBoolean(
  958. prefs::kDisplayRotationAcceleratorDialogHasBeenAccepted2, true);
  959. active_user_prefs_->CommitPendingWrite();
  960. }
  961. void AccessibilityControllerImpl::AddObserver(AccessibilityObserver* observer) {
  962. observers_.AddObserver(observer);
  963. }
  964. void AccessibilityControllerImpl::RemoveObserver(
  965. AccessibilityObserver* observer) {
  966. observers_.RemoveObserver(observer);
  967. }
  968. AccessibilityControllerImpl::Feature& AccessibilityControllerImpl::GetFeature(
  969. FeatureType type) const {
  970. DCHECK(features_[type].get());
  971. return *features_[type].get();
  972. }
  973. base::WeakPtr<AccessibilityControllerImpl>
  974. AccessibilityControllerImpl::GetWeakPtr() {
  975. return weak_ptr_factory_.GetWeakPtr();
  976. }
  977. AccessibilityControllerImpl::Feature& AccessibilityControllerImpl::autoclick()
  978. const {
  979. return GetFeature(FeatureType::kAutoclick);
  980. }
  981. AccessibilityControllerImpl::Feature&
  982. AccessibilityControllerImpl::caret_highlight() const {
  983. return GetFeature(FeatureType::kCaretHighlight);
  984. }
  985. AccessibilityControllerImpl::Feature&
  986. AccessibilityControllerImpl::cursor_highlight() const {
  987. return GetFeature(FeatureType::kCursorHighlight);
  988. }
  989. AccessibilityControllerImpl::Feature&
  990. AccessibilityControllerImpl::cursor_color() const {
  991. return GetFeature(FeatureType::kCursorColor);
  992. }
  993. AccessibilityControllerImpl::Feature& AccessibilityControllerImpl::dictation()
  994. const {
  995. return GetFeature(FeatureType::kDictation);
  996. }
  997. AccessibilityControllerImpl::Feature&
  998. AccessibilityControllerImpl::focus_highlight() const {
  999. return GetFeature(FeatureType::kFocusHighlight);
  1000. }
  1001. AccessibilityControllerImpl::Feature&
  1002. AccessibilityControllerImpl::floating_menu() const {
  1003. return GetFeature(FeatureType::kFloatingMenu);
  1004. }
  1005. AccessibilityControllerImpl::FeatureWithDialog&
  1006. AccessibilityControllerImpl::fullscreen_magnifier() const {
  1007. return static_cast<FeatureWithDialog&>(
  1008. GetFeature(FeatureType::kFullscreenMagnifier));
  1009. }
  1010. AccessibilityControllerImpl::FeatureWithDialog&
  1011. AccessibilityControllerImpl::docked_magnifier() const {
  1012. return static_cast<FeatureWithDialog&>(
  1013. GetFeature(FeatureType::kDockedMagnifier));
  1014. }
  1015. AccessibilityControllerImpl::FeatureWithDialog&
  1016. AccessibilityControllerImpl::high_contrast() const {
  1017. return static_cast<FeatureWithDialog&>(
  1018. GetFeature(FeatureType::kHighContrast));
  1019. }
  1020. AccessibilityControllerImpl::Feature&
  1021. AccessibilityControllerImpl::large_cursor() const {
  1022. return GetFeature(FeatureType::kLargeCursor);
  1023. }
  1024. AccessibilityControllerImpl::Feature&
  1025. AccessibilityControllerImpl::live_caption() const {
  1026. return GetFeature(FeatureType::kLiveCaption);
  1027. }
  1028. AccessibilityControllerImpl::Feature& AccessibilityControllerImpl::mono_audio()
  1029. const {
  1030. return GetFeature(FeatureType::kMonoAudio);
  1031. }
  1032. AccessibilityControllerImpl::Feature&
  1033. AccessibilityControllerImpl::spoken_feedback() const {
  1034. return GetFeature(FeatureType::kSpokenFeedback);
  1035. }
  1036. AccessibilityControllerImpl::Feature&
  1037. AccessibilityControllerImpl::select_to_speak() const {
  1038. return GetFeature(FeatureType::kSelectToSpeak);
  1039. }
  1040. AccessibilityControllerImpl::Feature& AccessibilityControllerImpl::sticky_keys()
  1041. const {
  1042. return GetFeature(FeatureType::kStickyKeys);
  1043. }
  1044. AccessibilityControllerImpl::Feature&
  1045. AccessibilityControllerImpl::switch_access() const {
  1046. return GetFeature(FeatureType::kSwitchAccess);
  1047. }
  1048. AccessibilityControllerImpl::Feature&
  1049. AccessibilityControllerImpl::virtual_keyboard() const {
  1050. return GetFeature(FeatureType::kVirtualKeyboard);
  1051. }
  1052. bool AccessibilityControllerImpl::IsAutoclickSettingVisibleInTray() {
  1053. return autoclick().IsVisibleInTray();
  1054. }
  1055. bool AccessibilityControllerImpl::IsEnterpriseIconVisibleForAutoclick() {
  1056. return autoclick().IsEnterpriseIconVisible();
  1057. }
  1058. bool AccessibilityControllerImpl::IsPrimarySettingsViewVisibleInTray() {
  1059. return (IsSpokenFeedbackSettingVisibleInTray() ||
  1060. IsSelectToSpeakSettingVisibleInTray() ||
  1061. IsDictationSettingVisibleInTray() ||
  1062. IsHighContrastSettingVisibleInTray() ||
  1063. IsFullScreenMagnifierSettingVisibleInTray() ||
  1064. IsDockedMagnifierSettingVisibleInTray() ||
  1065. IsAutoclickSettingVisibleInTray() ||
  1066. IsVirtualKeyboardSettingVisibleInTray() ||
  1067. IsSwitchAccessSettingVisibleInTray() ||
  1068. IsLiveCaptionSettingVisibleInTray());
  1069. }
  1070. bool AccessibilityControllerImpl::IsAdditionalSettingsViewVisibleInTray() {
  1071. return (IsLargeCursorSettingVisibleInTray() ||
  1072. IsMonoAudioSettingVisibleInTray() ||
  1073. IsCaretHighlightSettingVisibleInTray() ||
  1074. IsCursorHighlightSettingVisibleInTray() ||
  1075. IsFocusHighlightSettingVisibleInTray() ||
  1076. IsStickyKeysSettingVisibleInTray());
  1077. }
  1078. bool AccessibilityControllerImpl::IsAdditionalSettingsSeparatorVisibleInTray() {
  1079. return IsPrimarySettingsViewVisibleInTray() &&
  1080. IsAdditionalSettingsViewVisibleInTray();
  1081. }
  1082. bool AccessibilityControllerImpl::IsCaretHighlightSettingVisibleInTray() {
  1083. return caret_highlight().IsVisibleInTray();
  1084. }
  1085. bool AccessibilityControllerImpl::IsEnterpriseIconVisibleForCaretHighlight() {
  1086. return caret_highlight().IsEnterpriseIconVisible();
  1087. }
  1088. bool AccessibilityControllerImpl::IsCursorHighlightSettingVisibleInTray() {
  1089. return cursor_highlight().IsVisibleInTray();
  1090. }
  1091. bool AccessibilityControllerImpl::IsEnterpriseIconVisibleForCursorHighlight() {
  1092. return cursor_highlight().IsEnterpriseIconVisible();
  1093. }
  1094. bool AccessibilityControllerImpl::IsDictationSettingVisibleInTray() {
  1095. return dictation().IsVisibleInTray();
  1096. }
  1097. bool AccessibilityControllerImpl::IsEnterpriseIconVisibleForDictation() {
  1098. return dictation().IsEnterpriseIconVisible();
  1099. }
  1100. bool AccessibilityControllerImpl::IsFocusHighlightSettingVisibleInTray() {
  1101. return focus_highlight().IsVisibleInTray();
  1102. }
  1103. bool AccessibilityControllerImpl::IsEnterpriseIconVisibleForFocusHighlight() {
  1104. return focus_highlight().IsEnterpriseIconVisible();
  1105. }
  1106. bool AccessibilityControllerImpl::IsFullScreenMagnifierSettingVisibleInTray() {
  1107. return fullscreen_magnifier().IsVisibleInTray();
  1108. }
  1109. bool AccessibilityControllerImpl::
  1110. IsEnterpriseIconVisibleForFullScreenMagnifier() {
  1111. return fullscreen_magnifier().IsEnterpriseIconVisible();
  1112. }
  1113. bool AccessibilityControllerImpl::IsDockedMagnifierSettingVisibleInTray() {
  1114. return docked_magnifier().IsVisibleInTray();
  1115. }
  1116. bool AccessibilityControllerImpl::IsEnterpriseIconVisibleForDockedMagnifier() {
  1117. return docked_magnifier().IsEnterpriseIconVisible();
  1118. }
  1119. bool AccessibilityControllerImpl::IsHighContrastSettingVisibleInTray() {
  1120. return high_contrast().IsVisibleInTray();
  1121. }
  1122. bool AccessibilityControllerImpl::IsEnterpriseIconVisibleForHighContrast() {
  1123. return high_contrast().IsEnterpriseIconVisible();
  1124. }
  1125. bool AccessibilityControllerImpl::IsLargeCursorSettingVisibleInTray() {
  1126. return large_cursor().IsVisibleInTray();
  1127. }
  1128. bool AccessibilityControllerImpl::IsEnterpriseIconVisibleForLargeCursor() {
  1129. return large_cursor().IsEnterpriseIconVisible();
  1130. }
  1131. bool AccessibilityControllerImpl::IsLiveCaptionSettingVisibleInTray() {
  1132. return captions::IsLiveCaptionFeatureSupported() &&
  1133. base::FeatureList::IsEnabled(
  1134. media::kLiveCaptionSystemWideOnChromeOS) &&
  1135. live_caption().IsVisibleInTray();
  1136. }
  1137. bool AccessibilityControllerImpl::IsEnterpriseIconVisibleForLiveCaption() {
  1138. return captions::IsLiveCaptionFeatureSupported() &&
  1139. base::FeatureList::IsEnabled(
  1140. media::kLiveCaptionSystemWideOnChromeOS) &&
  1141. live_caption().IsEnterpriseIconVisible();
  1142. }
  1143. bool AccessibilityControllerImpl::IsMonoAudioSettingVisibleInTray() {
  1144. return mono_audio().IsVisibleInTray();
  1145. }
  1146. bool AccessibilityControllerImpl::IsEnterpriseIconVisibleForMonoAudio() {
  1147. return mono_audio().IsEnterpriseIconVisible();
  1148. }
  1149. void AccessibilityControllerImpl::SetSpokenFeedbackEnabled(
  1150. bool enabled,
  1151. AccessibilityNotificationVisibility notify) {
  1152. spoken_feedback().SetEnabled(enabled);
  1153. // Value could be left unchanged because of higher-priority pref source, eg.
  1154. // policy. See crbug.com/953245.
  1155. const bool actual_enabled = active_user_prefs_->GetBoolean(
  1156. prefs::kAccessibilitySpokenFeedbackEnabled);
  1157. A11yNotificationType type = A11yNotificationType::kNone;
  1158. if (enabled && actual_enabled && notify == A11Y_NOTIFICATION_SHOW)
  1159. type = A11yNotificationType::kSpokenFeedbackEnabled;
  1160. ShowAccessibilityNotification(
  1161. A11yNotificationWrapper(type, std::vector<std::u16string>()));
  1162. }
  1163. bool AccessibilityControllerImpl::IsSpokenFeedbackSettingVisibleInTray() {
  1164. return spoken_feedback().IsVisibleInTray();
  1165. }
  1166. bool AccessibilityControllerImpl::IsEnterpriseIconVisibleForSpokenFeedback() {
  1167. return spoken_feedback().IsEnterpriseIconVisible();
  1168. }
  1169. bool AccessibilityControllerImpl::IsSelectToSpeakSettingVisibleInTray() {
  1170. return select_to_speak().IsVisibleInTray();
  1171. }
  1172. bool AccessibilityControllerImpl::IsEnterpriseIconVisibleForSelectToSpeak() {
  1173. return select_to_speak().IsEnterpriseIconVisible();
  1174. }
  1175. void AccessibilityControllerImpl::RequestSelectToSpeakStateChange() {
  1176. client_->RequestSelectToSpeakStateChange();
  1177. }
  1178. void AccessibilityControllerImpl::SetSelectToSpeakState(
  1179. SelectToSpeakState state) {
  1180. select_to_speak_state_ = state;
  1181. // Forward the state change event to select_to_speak_event_handler_.
  1182. // The extension may have requested that the handler enter SELECTING state.
  1183. // Prepare to start capturing events from stylus, mouse or touch.
  1184. if (select_to_speak_event_handler_) {
  1185. select_to_speak_event_handler_->SetSelectToSpeakStateSelecting(
  1186. state == SelectToSpeakState::kSelectToSpeakStateSelecting);
  1187. }
  1188. NotifyAccessibilityStatusChanged();
  1189. }
  1190. void AccessibilityControllerImpl::SetSelectToSpeakEventHandlerDelegate(
  1191. SelectToSpeakEventHandlerDelegate* delegate) {
  1192. select_to_speak_event_handler_delegate_ = delegate;
  1193. MaybeCreateSelectToSpeakEventHandler();
  1194. }
  1195. SelectToSpeakState AccessibilityControllerImpl::GetSelectToSpeakState() const {
  1196. return select_to_speak_state_;
  1197. }
  1198. void AccessibilityControllerImpl::ShowSelectToSpeakPanel(
  1199. const gfx::Rect& anchor,
  1200. bool is_paused,
  1201. double speech_rate) {
  1202. if (!select_to_speak_bubble_controller_) {
  1203. select_to_speak_bubble_controller_ =
  1204. std::make_unique<SelectToSpeakMenuBubbleController>();
  1205. }
  1206. select_to_speak_bubble_controller_->Show(anchor, is_paused, speech_rate);
  1207. }
  1208. void AccessibilityControllerImpl::HideSelectToSpeakPanel() {
  1209. if (!select_to_speak_bubble_controller_) {
  1210. return;
  1211. }
  1212. select_to_speak_bubble_controller_->Hide();
  1213. }
  1214. void AccessibilityControllerImpl::OnSelectToSpeakPanelAction(
  1215. SelectToSpeakPanelAction action,
  1216. double value) {
  1217. if (!client_) {
  1218. return;
  1219. }
  1220. client_->OnSelectToSpeakPanelAction(action, value);
  1221. }
  1222. bool AccessibilityControllerImpl::IsSwitchAccessRunning() const {
  1223. return switch_access().enabled() || switch_access_disable_dialog_showing_;
  1224. }
  1225. bool AccessibilityControllerImpl::IsSwitchAccessSettingVisibleInTray() {
  1226. // Switch Access cannot be enabled on the sign-in page because there is no way
  1227. // to configure switches while the device is locked.
  1228. if (!switch_access().enabled() &&
  1229. Shell::Get()->session_controller()->login_status() ==
  1230. ash::LoginStatus::NOT_LOGGED_IN) {
  1231. return false;
  1232. }
  1233. return switch_access().IsVisibleInTray();
  1234. }
  1235. bool AccessibilityControllerImpl::IsEnterpriseIconVisibleForSwitchAccess() {
  1236. return switch_access().IsEnterpriseIconVisible();
  1237. }
  1238. void AccessibilityControllerImpl::SetAccessibilityEventRewriter(
  1239. AccessibilityEventRewriter* accessibility_event_rewriter) {
  1240. accessibility_event_rewriter_ = accessibility_event_rewriter;
  1241. }
  1242. void AccessibilityControllerImpl::HideSwitchAccessBackButton() {
  1243. if (IsSwitchAccessRunning())
  1244. switch_access_bubble_controller_->HideBackButton();
  1245. }
  1246. void AccessibilityControllerImpl::HideSwitchAccessMenu() {
  1247. if (IsSwitchAccessRunning())
  1248. switch_access_bubble_controller_->HideMenuBubble();
  1249. }
  1250. void AccessibilityControllerImpl::ShowSwitchAccessBackButton(
  1251. const gfx::Rect& anchor) {
  1252. switch_access_bubble_controller_->ShowBackButton(anchor);
  1253. }
  1254. void AccessibilityControllerImpl::ShowSwitchAccessMenu(
  1255. const gfx::Rect& anchor,
  1256. std::vector<std::string> actions_to_show) {
  1257. switch_access_bubble_controller_->ShowMenu(anchor, actions_to_show);
  1258. }
  1259. bool AccessibilityControllerImpl::IsPointScanEnabled() {
  1260. return point_scan_controller_.get() &&
  1261. point_scan_controller_->IsPointScanEnabled();
  1262. }
  1263. void AccessibilityControllerImpl::StartPointScan() {
  1264. point_scan_controller_->Start();
  1265. }
  1266. void AccessibilityControllerImpl::SetA11yOverrideWindow(
  1267. aura::Window* a11y_override_window) {
  1268. if (client_)
  1269. client_->SetA11yOverrideWindow(a11y_override_window);
  1270. }
  1271. void AccessibilityControllerImpl::StopPointScan() {
  1272. if (point_scan_controller_)
  1273. point_scan_controller_->HideAll();
  1274. }
  1275. void AccessibilityControllerImpl::SetPointScanSpeedDipsPerSecond(
  1276. int point_scan_speed_dips_per_second) {
  1277. if (point_scan_controller_) {
  1278. point_scan_controller_->SetSpeedDipsPerSecond(
  1279. point_scan_speed_dips_per_second);
  1280. }
  1281. }
  1282. void AccessibilityControllerImpl::
  1283. DisablePolicyRecommendationRestorerForTesting() {
  1284. Shell::Get()->policy_recommendation_restorer()->DisableForTesting();
  1285. }
  1286. bool AccessibilityControllerImpl::IsStickyKeysSettingVisibleInTray() {
  1287. return sticky_keys().IsVisibleInTray();
  1288. }
  1289. bool AccessibilityControllerImpl::IsEnterpriseIconVisibleForStickyKeys() {
  1290. return sticky_keys().IsEnterpriseIconVisible();
  1291. }
  1292. bool AccessibilityControllerImpl::IsVirtualKeyboardSettingVisibleInTray() {
  1293. return virtual_keyboard().IsVisibleInTray();
  1294. }
  1295. bool AccessibilityControllerImpl::IsEnterpriseIconVisibleForVirtualKeyboard() {
  1296. return virtual_keyboard().IsEnterpriseIconVisible();
  1297. }
  1298. void AccessibilityControllerImpl::ShowFloatingMenuIfEnabled() {
  1299. if (floating_menu().enabled() && !floating_menu_controller_) {
  1300. floating_menu_controller_ =
  1301. std::make_unique<FloatingAccessibilityController>(this);
  1302. floating_menu_controller_->Show(GetFloatingMenuPosition());
  1303. } else {
  1304. always_show_floating_menu_when_enabled_ = true;
  1305. }
  1306. }
  1307. FloatingAccessibilityController*
  1308. AccessibilityControllerImpl::GetFloatingMenuController() {
  1309. return floating_menu_controller_.get();
  1310. }
  1311. PointScanController* AccessibilityControllerImpl::GetPointScanController() {
  1312. return point_scan_controller_.get();
  1313. }
  1314. void AccessibilityControllerImpl::SetTabletModeShelfNavigationButtonsEnabled(
  1315. bool enabled) {
  1316. if (!active_user_prefs_)
  1317. return;
  1318. active_user_prefs_->SetBoolean(
  1319. prefs::kAccessibilityTabletModeShelfNavigationButtonsEnabled, enabled);
  1320. active_user_prefs_->CommitPendingWrite();
  1321. }
  1322. void AccessibilityControllerImpl::TriggerAccessibilityAlert(
  1323. AccessibilityAlert alert) {
  1324. if (client_)
  1325. client_->TriggerAccessibilityAlert(alert);
  1326. }
  1327. void AccessibilityControllerImpl::TriggerAccessibilityAlertWithMessage(
  1328. const std::string& message) {
  1329. if (client_)
  1330. client_->TriggerAccessibilityAlertWithMessage(message);
  1331. }
  1332. void AccessibilityControllerImpl::PlayEarcon(Sound sound_key) {
  1333. if (client_)
  1334. client_->PlayEarcon(sound_key);
  1335. }
  1336. base::TimeDelta AccessibilityControllerImpl::PlayShutdownSound() {
  1337. return client_ ? client_->PlayShutdownSound() : base::TimeDelta();
  1338. }
  1339. void AccessibilityControllerImpl::HandleAccessibilityGesture(
  1340. ax::mojom::Gesture gesture,
  1341. gfx::PointF location) {
  1342. if (client_)
  1343. client_->HandleAccessibilityGesture(gesture, location);
  1344. }
  1345. void AccessibilityControllerImpl::ToggleDictation() {
  1346. // Do nothing if dictation is not enabled.
  1347. if (!dictation().enabled())
  1348. return;
  1349. if (client_) {
  1350. const bool is_active = client_->ToggleDictation();
  1351. SetDictationActive(is_active);
  1352. if (is_active)
  1353. Shell::Get()->OnDictationStarted();
  1354. else
  1355. Shell::Get()->OnDictationEnded();
  1356. }
  1357. }
  1358. void AccessibilityControllerImpl::SetDictationActive(bool is_active) {
  1359. dictation_active_ = is_active;
  1360. }
  1361. void AccessibilityControllerImpl::ToggleDictationFromSource(
  1362. DictationToggleSource source) {
  1363. base::RecordAction(base::UserMetricsAction("Accel_Toggle_Dictation"));
  1364. UMA_HISTOGRAM_ENUMERATION("Accessibility.CrosDictation.ToggleDictationMethod",
  1365. source);
  1366. dictation().SetEnabled(true);
  1367. ToggleDictation();
  1368. }
  1369. void AccessibilityControllerImpl::ShowDictationLanguageUpgradedNudge(
  1370. const std::string& dictation_locale,
  1371. const std::string& application_locale) {
  1372. dictation_nudge_controller_ = std::make_unique<DictationNudgeController>(
  1373. dictation_locale, application_locale);
  1374. dictation_nudge_controller_->ShowNudge();
  1375. }
  1376. void AccessibilityControllerImpl::SilenceSpokenFeedback() {
  1377. if (client_)
  1378. client_->SilenceSpokenFeedback();
  1379. }
  1380. void AccessibilityControllerImpl::OnTwoFingerTouchStart() {
  1381. if (client_)
  1382. client_->OnTwoFingerTouchStart();
  1383. }
  1384. void AccessibilityControllerImpl::OnTwoFingerTouchStop() {
  1385. if (client_)
  1386. client_->OnTwoFingerTouchStop();
  1387. }
  1388. bool AccessibilityControllerImpl::ShouldToggleSpokenFeedbackViaTouch() const {
  1389. return client_ && client_->ShouldToggleSpokenFeedbackViaTouch();
  1390. }
  1391. void AccessibilityControllerImpl::PlaySpokenFeedbackToggleCountdown(
  1392. int tick_count) {
  1393. if (client_)
  1394. client_->PlaySpokenFeedbackToggleCountdown(tick_count);
  1395. }
  1396. bool AccessibilityControllerImpl::IsEnterpriseIconVisibleInTrayMenu(
  1397. const std::string& path) {
  1398. return active_user_prefs_ &&
  1399. active_user_prefs_->FindPreference(path)->IsManaged();
  1400. }
  1401. void AccessibilityControllerImpl::SetClient(
  1402. AccessibilityControllerClient* client) {
  1403. client_ = client;
  1404. }
  1405. void AccessibilityControllerImpl::SetDarkenScreen(bool darken) {
  1406. if (darken && !scoped_backlights_forced_off_) {
  1407. scoped_backlights_forced_off_ =
  1408. Shell::Get()->backlights_forced_off_setter()->ForceBacklightsOff();
  1409. } else if (!darken && scoped_backlights_forced_off_) {
  1410. scoped_backlights_forced_off_.reset();
  1411. }
  1412. }
  1413. void AccessibilityControllerImpl::BrailleDisplayStateChanged(bool connected) {
  1414. A11yNotificationType type = A11yNotificationType::kNone;
  1415. if (connected && spoken_feedback().enabled())
  1416. type = A11yNotificationType::kBrailleDisplayConnected;
  1417. else if (connected && !spoken_feedback().enabled())
  1418. type = A11yNotificationType::kSpokenFeedbackBrailleEnabled;
  1419. if (connected)
  1420. SetSpokenFeedbackEnabled(true, A11Y_NOTIFICATION_NONE);
  1421. NotifyAccessibilityStatusChanged();
  1422. ShowAccessibilityNotification(
  1423. A11yNotificationWrapper(type, std::vector<std::u16string>()));
  1424. }
  1425. void AccessibilityControllerImpl::SetFocusHighlightRect(
  1426. const gfx::Rect& bounds_in_screen) {
  1427. if (!accessibility_highlight_controller_)
  1428. return;
  1429. accessibility_highlight_controller_->SetFocusHighlightRect(bounds_in_screen);
  1430. }
  1431. void AccessibilityControllerImpl::SetCaretBounds(
  1432. const gfx::Rect& bounds_in_screen) {
  1433. if (!accessibility_highlight_controller_)
  1434. return;
  1435. accessibility_highlight_controller_->SetCaretBounds(bounds_in_screen);
  1436. }
  1437. void AccessibilityControllerImpl::SetAccessibilityPanelAlwaysVisible(
  1438. bool always_visible) {
  1439. GetLayoutManager()->SetAlwaysVisible(always_visible);
  1440. }
  1441. void AccessibilityControllerImpl::SetAccessibilityPanelBounds(
  1442. const gfx::Rect& bounds,
  1443. AccessibilityPanelState state) {
  1444. GetLayoutManager()->SetPanelBounds(bounds, state);
  1445. }
  1446. void AccessibilityControllerImpl::OnSigninScreenPrefServiceInitialized(
  1447. PrefService* prefs) {
  1448. // Make |kA11yPrefsForRecommendedValueOnSignin| observing recommended values
  1449. // on signin screen. See PolicyRecommendationRestorer.
  1450. PolicyRecommendationRestorer* policy_recommendation_restorer =
  1451. Shell::Get()->policy_recommendation_restorer();
  1452. for (auto* const pref_name : kA11yPrefsForRecommendedValueOnSignin)
  1453. policy_recommendation_restorer->ObservePref(pref_name);
  1454. // Observe user settings. This must happen after PolicyRecommendationRestorer.
  1455. ObservePrefs(prefs);
  1456. }
  1457. void AccessibilityControllerImpl::OnActiveUserPrefServiceChanged(
  1458. PrefService* prefs) {
  1459. // This is guaranteed to be received after
  1460. // OnSigninScreenPrefServiceInitialized() so only copy the signin prefs if
  1461. // needed here.
  1462. CopySigninPrefsIfNeeded(active_user_prefs_, prefs);
  1463. ObservePrefs(prefs);
  1464. }
  1465. void AccessibilityControllerImpl::OnSessionStateChanged(
  1466. session_manager::SessionState state) {
  1467. // Everything behind the lock screen is in
  1468. // kShellWindowId_NonLockScreenContainersContainer. If the session state is
  1469. // changed to block the user session due to the lock screen or similar,
  1470. // everything in that window should be made invisible for accessibility.
  1471. // This keeps a11y features from being able to access parts of the tree
  1472. // that are visibly hidden behind the lock screen.
  1473. aura::Window* container =
  1474. Shell::GetContainer(Shell::GetPrimaryRootWindow(),
  1475. kShellWindowId_NonLockScreenContainersContainer);
  1476. container->SetProperty(
  1477. ui::kAXConsiderInvisibleAndIgnoreChildren,
  1478. Shell::Get()->session_controller()->IsUserSessionBlocked());
  1479. }
  1480. AccessibilityEventRewriter*
  1481. AccessibilityControllerImpl::GetAccessibilityEventRewriterForTest() {
  1482. return accessibility_event_rewriter_;
  1483. }
  1484. void AccessibilityControllerImpl::
  1485. DisableSwitchAccessDisableConfirmationDialogTesting() {
  1486. no_switch_access_disable_confirmation_dialog_for_testing_ = true;
  1487. }
  1488. void AccessibilityControllerImpl::OnTabletModeStarted() {
  1489. if (spoken_feedback().enabled())
  1490. ShowAccessibilityNotification(
  1491. A11yNotificationWrapper(A11yNotificationType::kSpokenFeedbackEnabled,
  1492. std::vector<std::u16string>()));
  1493. }
  1494. void AccessibilityControllerImpl::OnTabletModeEnded() {
  1495. if (spoken_feedback().enabled())
  1496. ShowAccessibilityNotification(
  1497. A11yNotificationWrapper(A11yNotificationType::kSpokenFeedbackEnabled,
  1498. std::vector<std::u16string>()));
  1499. }
  1500. void AccessibilityControllerImpl::ObservePrefs(PrefService* prefs) {
  1501. DCHECK(prefs);
  1502. active_user_prefs_ = prefs;
  1503. // Watch for pref updates from webui settings and policy.
  1504. pref_change_registrar_ = std::make_unique<PrefChangeRegistrar>();
  1505. pref_change_registrar_->Init(prefs);
  1506. // It is safe to use base::Unreatined since we own pref_change_registrar.
  1507. for (int feature_id = 0; feature_id < FeatureType::kFeatureCount;
  1508. feature_id++) {
  1509. Feature* feature = features_[feature_id].get();
  1510. DCHECK(feature);
  1511. pref_change_registrar_->Add(
  1512. feature->pref_name(),
  1513. base::BindRepeating(
  1514. &AccessibilityControllerImpl::Feature::UpdateFromPref,
  1515. base::Unretained(feature)));
  1516. feature->UpdateFromPref();
  1517. }
  1518. pref_change_registrar_->Add(
  1519. prefs::kAccessibilityAutoclickDelayMs,
  1520. base::BindRepeating(
  1521. &AccessibilityControllerImpl::UpdateAutoclickDelayFromPref,
  1522. base::Unretained(this)));
  1523. pref_change_registrar_->Add(
  1524. prefs::kAccessibilityAutoclickEventType,
  1525. base::BindRepeating(
  1526. &AccessibilityControllerImpl::UpdateAutoclickEventTypeFromPref,
  1527. base::Unretained(this)));
  1528. pref_change_registrar_->Add(
  1529. prefs::kAccessibilityAutoclickRevertToLeftClick,
  1530. base::BindRepeating(&AccessibilityControllerImpl::
  1531. UpdateAutoclickRevertToLeftClickFromPref,
  1532. base::Unretained(this)));
  1533. pref_change_registrar_->Add(
  1534. prefs::kAccessibilityAutoclickStabilizePosition,
  1535. base::BindRepeating(&AccessibilityControllerImpl::
  1536. UpdateAutoclickStabilizePositionFromPref,
  1537. base::Unretained(this)));
  1538. pref_change_registrar_->Add(
  1539. prefs::kAccessibilityAutoclickMovementThreshold,
  1540. base::BindRepeating(&AccessibilityControllerImpl::
  1541. UpdateAutoclickMovementThresholdFromPref,
  1542. base::Unretained(this)));
  1543. pref_change_registrar_->Add(
  1544. prefs::kAccessibilityAutoclickMenuPosition,
  1545. base::BindRepeating(
  1546. &AccessibilityControllerImpl::UpdateAutoclickMenuPositionFromPref,
  1547. base::Unretained(this)));
  1548. pref_change_registrar_->Add(
  1549. prefs::kAccessibilityFloatingMenuPosition,
  1550. base::BindRepeating(
  1551. &AccessibilityControllerImpl::UpdateFloatingMenuPositionFromPref,
  1552. base::Unretained(this)));
  1553. pref_change_registrar_->Add(
  1554. prefs::kAccessibilityLargeCursorDipSize,
  1555. base::BindRepeating(
  1556. &AccessibilityControllerImpl::UpdateLargeCursorFromPref,
  1557. base::Unretained(this)));
  1558. pref_change_registrar_->Add(
  1559. prefs::kAccessibilityShortcutsEnabled,
  1560. base::BindRepeating(
  1561. &AccessibilityControllerImpl::UpdateShortcutsEnabledFromPref,
  1562. base::Unretained(this)));
  1563. pref_change_registrar_->Add(
  1564. prefs::kAccessibilitySwitchAccessSelectDeviceKeyCodes,
  1565. base::BindRepeating(
  1566. &AccessibilityControllerImpl::UpdateSwitchAccessKeyCodesFromPref,
  1567. base::Unretained(this), SwitchAccessCommand::kSelect));
  1568. pref_change_registrar_->Add(
  1569. prefs::kAccessibilitySwitchAccessNextDeviceKeyCodes,
  1570. base::BindRepeating(
  1571. &AccessibilityControllerImpl::UpdateSwitchAccessKeyCodesFromPref,
  1572. base::Unretained(this), SwitchAccessCommand::kNext));
  1573. pref_change_registrar_->Add(
  1574. prefs::kAccessibilitySwitchAccessPreviousDeviceKeyCodes,
  1575. base::BindRepeating(
  1576. &AccessibilityControllerImpl::UpdateSwitchAccessKeyCodesFromPref,
  1577. base::Unretained(this), SwitchAccessCommand::kPrevious));
  1578. pref_change_registrar_->Add(
  1579. prefs::kAccessibilitySwitchAccessAutoScanEnabled,
  1580. base::BindRepeating(&AccessibilityControllerImpl::
  1581. UpdateSwitchAccessAutoScanEnabledFromPref,
  1582. base::Unretained(this)));
  1583. pref_change_registrar_->Add(
  1584. prefs::kAccessibilitySwitchAccessAutoScanSpeedMs,
  1585. base::BindRepeating(
  1586. &AccessibilityControllerImpl::UpdateSwitchAccessAutoScanSpeedFromPref,
  1587. base::Unretained(this)));
  1588. pref_change_registrar_->Add(
  1589. prefs::kAccessibilitySwitchAccessAutoScanKeyboardSpeedMs,
  1590. base::BindRepeating(&AccessibilityControllerImpl::
  1591. UpdateSwitchAccessAutoScanKeyboardSpeedFromPref,
  1592. base::Unretained(this)));
  1593. pref_change_registrar_->Add(
  1594. prefs::kAccessibilitySwitchAccessPointScanSpeedDipsPerSecond,
  1595. base::BindRepeating(&AccessibilityControllerImpl::
  1596. UpdateSwitchAccessPointScanSpeedFromPref,
  1597. base::Unretained(this)));
  1598. pref_change_registrar_->Add(
  1599. prefs::kAccessibilityTabletModeShelfNavigationButtonsEnabled,
  1600. base::BindRepeating(&AccessibilityControllerImpl::
  1601. UpdateTabletModeShelfNavigationButtonsFromPref,
  1602. base::Unretained(this)));
  1603. pref_change_registrar_->Add(
  1604. prefs::kAccessibilityCursorColor,
  1605. base::BindRepeating(
  1606. &AccessibilityControllerImpl::UpdateCursorColorFromPrefs,
  1607. base::Unretained(this)));
  1608. // Load current state.
  1609. for (int feature_id = 0; feature_id < FeatureType::kFeatureCount;
  1610. feature_id++) {
  1611. features_[feature_id]->UpdateFromPref();
  1612. }
  1613. UpdateAutoclickDelayFromPref();
  1614. UpdateAutoclickEventTypeFromPref();
  1615. UpdateAutoclickRevertToLeftClickFromPref();
  1616. UpdateAutoclickStabilizePositionFromPref();
  1617. UpdateAutoclickMovementThresholdFromPref();
  1618. UpdateAutoclickMenuPositionFromPref();
  1619. UpdateFloatingMenuPositionFromPref();
  1620. UpdateLargeCursorFromPref();
  1621. UpdateCursorColorFromPrefs();
  1622. UpdateShortcutsEnabledFromPref();
  1623. UpdateTabletModeShelfNavigationButtonsFromPref();
  1624. }
  1625. void AccessibilityControllerImpl::UpdateAutoclickDelayFromPref() {
  1626. DCHECK(active_user_prefs_);
  1627. base::TimeDelta autoclick_delay = base::Milliseconds(int64_t{
  1628. active_user_prefs_->GetInteger(prefs::kAccessibilityAutoclickDelayMs)});
  1629. if (autoclick_delay_ == autoclick_delay)
  1630. return;
  1631. autoclick_delay_ = autoclick_delay;
  1632. Shell::Get()->autoclick_controller()->SetAutoclickDelay(autoclick_delay_);
  1633. }
  1634. void AccessibilityControllerImpl::UpdateAutoclickEventTypeFromPref() {
  1635. Shell::Get()->autoclick_controller()->SetAutoclickEventType(
  1636. GetAutoclickEventType());
  1637. }
  1638. void AccessibilityControllerImpl::SetAutoclickEventType(
  1639. AutoclickEventType event_type) {
  1640. if (!active_user_prefs_)
  1641. return;
  1642. active_user_prefs_->SetInteger(prefs::kAccessibilityAutoclickEventType,
  1643. static_cast<int>(event_type));
  1644. active_user_prefs_->CommitPendingWrite();
  1645. Shell::Get()->autoclick_controller()->SetAutoclickEventType(event_type);
  1646. }
  1647. AutoclickEventType AccessibilityControllerImpl::GetAutoclickEventType() {
  1648. DCHECK(active_user_prefs_);
  1649. return static_cast<AutoclickEventType>(
  1650. active_user_prefs_->GetInteger(prefs::kAccessibilityAutoclickEventType));
  1651. }
  1652. void AccessibilityControllerImpl::UpdateAutoclickRevertToLeftClickFromPref() {
  1653. DCHECK(active_user_prefs_);
  1654. bool revert_to_left_click = active_user_prefs_->GetBoolean(
  1655. prefs::kAccessibilityAutoclickRevertToLeftClick);
  1656. Shell::Get()->autoclick_controller()->set_revert_to_left_click(
  1657. revert_to_left_click);
  1658. }
  1659. void AccessibilityControllerImpl::UpdateAutoclickStabilizePositionFromPref() {
  1660. DCHECK(active_user_prefs_);
  1661. bool stabilize_position = active_user_prefs_->GetBoolean(
  1662. prefs::kAccessibilityAutoclickStabilizePosition);
  1663. Shell::Get()->autoclick_controller()->set_stabilize_click_position(
  1664. stabilize_position);
  1665. }
  1666. void AccessibilityControllerImpl::UpdateAutoclickMovementThresholdFromPref() {
  1667. DCHECK(active_user_prefs_);
  1668. int movement_threshold = active_user_prefs_->GetInteger(
  1669. prefs::kAccessibilityAutoclickMovementThreshold);
  1670. Shell::Get()->autoclick_controller()->SetMovementThreshold(
  1671. movement_threshold);
  1672. }
  1673. void AccessibilityControllerImpl::UpdateAutoclickMenuPositionFromPref() {
  1674. Shell::Get()->autoclick_controller()->SetMenuPosition(
  1675. GetAutoclickMenuPosition());
  1676. }
  1677. void AccessibilityControllerImpl::SetAutoclickMenuPosition(
  1678. FloatingMenuPosition position) {
  1679. if (!active_user_prefs_)
  1680. return;
  1681. active_user_prefs_->SetInteger(prefs::kAccessibilityAutoclickMenuPosition,
  1682. static_cast<int>(position));
  1683. active_user_prefs_->CommitPendingWrite();
  1684. Shell::Get()->autoclick_controller()->SetMenuPosition(position);
  1685. }
  1686. FloatingMenuPosition AccessibilityControllerImpl::GetAutoclickMenuPosition() {
  1687. DCHECK(active_user_prefs_);
  1688. return static_cast<FloatingMenuPosition>(active_user_prefs_->GetInteger(
  1689. prefs::kAccessibilityAutoclickMenuPosition));
  1690. }
  1691. void AccessibilityControllerImpl::RequestAutoclickScrollableBoundsForPoint(
  1692. gfx::Point& point_in_screen) {
  1693. if (client_)
  1694. client_->RequestAutoclickScrollableBoundsForPoint(point_in_screen);
  1695. }
  1696. void AccessibilityControllerImpl::MagnifierBoundsChanged(
  1697. const gfx::Rect& bounds_in_screen) {
  1698. if (client_)
  1699. client_->MagnifierBoundsChanged(bounds_in_screen);
  1700. }
  1701. void AccessibilityControllerImpl::UpdateFloatingPanelBoundsIfNeeded() {
  1702. Shell* shell = Shell::Get();
  1703. if (shell->accessibility_controller()->autoclick().enabled())
  1704. shell->autoclick_controller()->UpdateAutoclickMenuBoundsIfNeeded();
  1705. if (shell->accessibility_controller()->sticky_keys().enabled())
  1706. shell->sticky_keys_controller()->UpdateStickyKeysOverlayBoundsIfNeeded();
  1707. }
  1708. void AccessibilityControllerImpl::UpdateAutoclickMenuBoundsIfNeeded() {
  1709. Shell::Get()->autoclick_controller()->UpdateAutoclickMenuBoundsIfNeeded();
  1710. }
  1711. void AccessibilityControllerImpl::HandleAutoclickScrollableBoundsFound(
  1712. gfx::Rect& bounds_in_screen) {
  1713. Shell::Get()->autoclick_controller()->HandleAutoclickScrollableBoundsFound(
  1714. bounds_in_screen);
  1715. }
  1716. void AccessibilityControllerImpl::SetFloatingMenuPosition(
  1717. FloatingMenuPosition position) {
  1718. if (!active_user_prefs_)
  1719. return;
  1720. active_user_prefs_->SetInteger(prefs::kAccessibilityFloatingMenuPosition,
  1721. static_cast<int>(position));
  1722. active_user_prefs_->CommitPendingWrite();
  1723. }
  1724. void AccessibilityControllerImpl::UpdateFloatingMenuPositionFromPref() {
  1725. if (floating_menu_controller_)
  1726. floating_menu_controller_->SetMenuPosition(GetFloatingMenuPosition());
  1727. }
  1728. FloatingMenuPosition AccessibilityControllerImpl::GetFloatingMenuPosition() {
  1729. DCHECK(active_user_prefs_);
  1730. return static_cast<FloatingMenuPosition>(active_user_prefs_->GetInteger(
  1731. prefs::kAccessibilityFloatingMenuPosition));
  1732. }
  1733. void AccessibilityControllerImpl::UpdateLargeCursorFromPref() {
  1734. DCHECK(active_user_prefs_);
  1735. const bool enabled =
  1736. active_user_prefs_->GetBoolean(prefs::kAccessibilityLargeCursorEnabled);
  1737. // Reset large cursor size to the default size when large cursor is disabled.
  1738. if (!enabled)
  1739. active_user_prefs_->ClearPref(prefs::kAccessibilityLargeCursorDipSize);
  1740. const int size =
  1741. active_user_prefs_->GetInteger(prefs::kAccessibilityLargeCursorDipSize);
  1742. if (large_cursor_size_in_dip_ == size)
  1743. return;
  1744. large_cursor_size_in_dip_ = size;
  1745. NotifyAccessibilityStatusChanged();
  1746. Shell* shell = Shell::Get();
  1747. shell->cursor_manager()->SetCursorSize(large_cursor().enabled()
  1748. ? ui::CursorSize::kLarge
  1749. : ui::CursorSize::kNormal);
  1750. shell->SetLargeCursorSizeInDip(large_cursor_size_in_dip_);
  1751. shell->UpdateCursorCompositingEnabled();
  1752. }
  1753. void AccessibilityControllerImpl::UpdateCursorColorFromPrefs() {
  1754. DCHECK(active_user_prefs_);
  1755. const bool enabled =
  1756. active_user_prefs_->GetBoolean(prefs::kAccessibilityCursorColorEnabled);
  1757. Shell* shell = Shell::Get();
  1758. shell->SetCursorColor(
  1759. enabled ? active_user_prefs_->GetInteger(prefs::kAccessibilityCursorColor)
  1760. : kDefaultCursorColor);
  1761. NotifyAccessibilityStatusChanged();
  1762. shell->UpdateCursorCompositingEnabled();
  1763. }
  1764. void AccessibilityControllerImpl::UpdateAccessibilityHighlightingFromPrefs() {
  1765. if (!caret_highlight().enabled() && !cursor_highlight().enabled() &&
  1766. !focus_highlight().enabled()) {
  1767. accessibility_highlight_controller_.reset();
  1768. return;
  1769. }
  1770. if (!accessibility_highlight_controller_) {
  1771. accessibility_highlight_controller_ =
  1772. std::make_unique<AccessibilityHighlightController>();
  1773. }
  1774. accessibility_highlight_controller_->HighlightCaret(
  1775. caret_highlight().enabled());
  1776. accessibility_highlight_controller_->HighlightCursor(
  1777. cursor_highlight().enabled());
  1778. accessibility_highlight_controller_->HighlightFocus(
  1779. focus_highlight().enabled());
  1780. }
  1781. void AccessibilityControllerImpl::MaybeCreateSelectToSpeakEventHandler() {
  1782. // Construct the handler as needed when Select-to-Speak is enabled and the
  1783. // delegate is set. Otherwise, destroy the handler when Select-to-Speak is
  1784. // disabled or the delegate has been destroyed.
  1785. if (!select_to_speak().enabled() ||
  1786. !select_to_speak_event_handler_delegate_) {
  1787. select_to_speak_event_handler_.reset();
  1788. return;
  1789. }
  1790. if (select_to_speak_event_handler_)
  1791. return;
  1792. select_to_speak_event_handler_ = std::make_unique<SelectToSpeakEventHandler>(
  1793. select_to_speak_event_handler_delegate_);
  1794. }
  1795. void AccessibilityControllerImpl::UpdateSwitchAccessKeyCodesFromPref(
  1796. SwitchAccessCommand command) {
  1797. if (!active_user_prefs_)
  1798. return;
  1799. SyncSwitchAccessPrefsToSignInProfile();
  1800. if (!accessibility_event_rewriter_)
  1801. return;
  1802. std::string pref_key = PrefKeyForSwitchAccessCommand(command);
  1803. const base::Value::Dict& key_codes_pref =
  1804. active_user_prefs_->GetValueDict(pref_key);
  1805. std::map<int, std::set<std::string>> key_codes;
  1806. for (const auto v : key_codes_pref) {
  1807. int key_code;
  1808. if (!base::StringToInt(v.first, &key_code)) {
  1809. NOTREACHED();
  1810. return;
  1811. }
  1812. key_codes[key_code] = std::set<std::string>();
  1813. for (const base::Value& device_type : v.second.GetList())
  1814. key_codes[key_code].insert(device_type.GetString());
  1815. DCHECK(!key_codes[key_code].empty());
  1816. }
  1817. std::string uma_name = UmaNameForSwitchAccessCommand(command);
  1818. if (key_codes.size() == 0) {
  1819. base::UmaHistogramEnumeration(uma_name, SwitchAccessKeyCode::kNone);
  1820. }
  1821. for (const auto& key_code : key_codes) {
  1822. base::UmaHistogramEnumeration(
  1823. uma_name, static_cast<SwitchAccessKeyCode>(key_code.first));
  1824. }
  1825. accessibility_event_rewriter_->SetKeyCodesForSwitchAccessCommand(key_codes,
  1826. command);
  1827. }
  1828. void AccessibilityControllerImpl::UpdateSwitchAccessAutoScanEnabledFromPref() {
  1829. DCHECK(active_user_prefs_);
  1830. const bool enabled = active_user_prefs_->GetBoolean(
  1831. prefs::kAccessibilitySwitchAccessAutoScanEnabled);
  1832. base::UmaHistogramBoolean("Accessibility.CrosSwitchAccess.AutoScan", enabled);
  1833. SyncSwitchAccessPrefsToSignInProfile();
  1834. }
  1835. void AccessibilityControllerImpl::UpdateSwitchAccessAutoScanSpeedFromPref() {
  1836. DCHECK(active_user_prefs_);
  1837. const int speed_ms = active_user_prefs_->GetInteger(
  1838. prefs::kAccessibilitySwitchAccessAutoScanSpeedMs);
  1839. base::UmaHistogramCustomCounts(
  1840. "Accessibility.CrosSwitchAccess.AutoScan.SpeedMs", speed_ms, 1 /* min */,
  1841. 10000 /* max */, 100 /* buckets */);
  1842. SyncSwitchAccessPrefsToSignInProfile();
  1843. }
  1844. void AccessibilityControllerImpl::
  1845. UpdateSwitchAccessAutoScanKeyboardSpeedFromPref() {
  1846. DCHECK(active_user_prefs_);
  1847. const int speed_ms = active_user_prefs_->GetInteger(
  1848. prefs::kAccessibilitySwitchAccessAutoScanKeyboardSpeedMs);
  1849. base::UmaHistogramCustomCounts(
  1850. "Accessibility.CrosSwitchAccess.AutoScan.KeyboardSpeedMs", speed_ms,
  1851. 1 /* min */, 10000 /* max */, 100 /* buckets */);
  1852. SyncSwitchAccessPrefsToSignInProfile();
  1853. }
  1854. void AccessibilityControllerImpl::UpdateSwitchAccessPointScanSpeedFromPref() {
  1855. // TODO(accessibility): Log histogram for point scan speed
  1856. DCHECK(active_user_prefs_);
  1857. const int point_scan_speed_dips_per_second = active_user_prefs_->GetInteger(
  1858. prefs::kAccessibilitySwitchAccessPointScanSpeedDipsPerSecond);
  1859. SetPointScanSpeedDipsPerSecond(point_scan_speed_dips_per_second);
  1860. SyncSwitchAccessPrefsToSignInProfile();
  1861. }
  1862. void AccessibilityControllerImpl::SwitchAccessDisableDialogClosed(
  1863. bool disable_dialog_accepted) {
  1864. switch_access_disable_dialog_showing_ = false;
  1865. // Always deactivate switch access. Turning switch access off ensures it is
  1866. // re-activated correctly.
  1867. // The pref was already disabled, but we left switch access on so the user
  1868. // could interact with the dialog.
  1869. DeactivateSwitchAccess();
  1870. if (disable_dialog_accepted) {
  1871. RemoveAccessibilityNotification();
  1872. NotifyAccessibilityStatusChanged();
  1873. SyncSwitchAccessPrefsToSignInProfile();
  1874. } else {
  1875. // Reset the preference (which was already set to false). Doing so turns
  1876. // switch access back on.
  1877. skip_switch_access_notification_ = true;
  1878. switch_access().SetEnabled(true);
  1879. }
  1880. }
  1881. void AccessibilityControllerImpl::UpdateKeyCodesAfterSwitchAccessEnabled() {
  1882. UpdateSwitchAccessKeyCodesFromPref(SwitchAccessCommand::kSelect);
  1883. UpdateSwitchAccessKeyCodesFromPref(SwitchAccessCommand::kNext);
  1884. UpdateSwitchAccessKeyCodesFromPref(SwitchAccessCommand::kPrevious);
  1885. }
  1886. void AccessibilityControllerImpl::ActivateSwitchAccess() {
  1887. switch_access_bubble_controller_ =
  1888. std::make_unique<SwitchAccessMenuBubbleController>();
  1889. point_scan_controller_ = std::make_unique<PointScanController>();
  1890. UpdateKeyCodesAfterSwitchAccessEnabled();
  1891. UpdateSwitchAccessPointScanSpeedFromPref();
  1892. if (skip_switch_access_notification_) {
  1893. skip_switch_access_notification_ = false;
  1894. return;
  1895. }
  1896. ShowAccessibilityNotification(
  1897. A11yNotificationWrapper(A11yNotificationType::kSwitchAccessEnabled,
  1898. std::vector<std::u16string>()));
  1899. }
  1900. void AccessibilityControllerImpl::DeactivateSwitchAccess() {
  1901. if (client_)
  1902. client_->OnSwitchAccessDisabled();
  1903. point_scan_controller_.reset();
  1904. switch_access_bubble_controller_.reset();
  1905. }
  1906. void AccessibilityControllerImpl::SyncSwitchAccessPrefsToSignInProfile() {
  1907. if (!active_user_prefs_ || IsSigninPrefService(active_user_prefs_))
  1908. return;
  1909. PrefService* signin_prefs =
  1910. Shell::Get()->session_controller()->GetSigninScreenPrefService();
  1911. DCHECK(signin_prefs);
  1912. for (const auto* pref_path : kSwitchAccessPrefsCopiedToSignin) {
  1913. const PrefService::Preference* pref =
  1914. active_user_prefs_->FindPreference(pref_path);
  1915. // Ignore if the pref has not been set by the user.
  1916. if (!pref || !pref->IsUserControlled())
  1917. continue;
  1918. // Copy the pref value to the signin profile.
  1919. const base::Value* value = pref->GetValue();
  1920. signin_prefs->Set(pref_path, *value);
  1921. }
  1922. }
  1923. void AccessibilityControllerImpl::UpdateShortcutsEnabledFromPref() {
  1924. DCHECK(active_user_prefs_);
  1925. const bool enabled =
  1926. active_user_prefs_->GetBoolean(prefs::kAccessibilityShortcutsEnabled);
  1927. if (shortcuts_enabled_ == enabled)
  1928. return;
  1929. shortcuts_enabled_ = enabled;
  1930. NotifyAccessibilityStatusChanged();
  1931. }
  1932. void AccessibilityControllerImpl::
  1933. UpdateTabletModeShelfNavigationButtonsFromPref() {
  1934. DCHECK(active_user_prefs_);
  1935. const bool enabled = active_user_prefs_->GetBoolean(
  1936. prefs::kAccessibilityTabletModeShelfNavigationButtonsEnabled);
  1937. if (tablet_mode_shelf_navigation_buttons_enabled_ == enabled)
  1938. return;
  1939. tablet_mode_shelf_navigation_buttons_enabled_ = enabled;
  1940. NotifyAccessibilityStatusChanged();
  1941. }
  1942. std::u16string AccessibilityControllerImpl::GetBatteryDescription() const {
  1943. // Pass battery status as string to callback function.
  1944. return PowerStatus::Get()->GetAccessibleNameString(
  1945. /*full_description=*/true);
  1946. }
  1947. void AccessibilityControllerImpl::SetVirtualKeyboardVisible(bool is_visible) {
  1948. if (is_visible)
  1949. Shell::Get()->keyboard_controller()->ShowKeyboard();
  1950. else
  1951. Shell::Get()->keyboard_controller()->HideKeyboard(HideReason::kUser);
  1952. }
  1953. void AccessibilityControllerImpl::PerformAcceleratorAction(
  1954. AcceleratorAction accelerator_action) {
  1955. AcceleratorController::Get()->PerformActionIfEnabled(accelerator_action,
  1956. /* accelerator = */ {});
  1957. }
  1958. void AccessibilityControllerImpl::NotifyAccessibilityStatusChanged() {
  1959. for (auto& observer : observers_)
  1960. observer.OnAccessibilityStatusChanged();
  1961. }
  1962. bool AccessibilityControllerImpl::IsAccessibilityFeatureVisibleInTrayMenu(
  1963. const std::string& path) {
  1964. if (!active_user_prefs_)
  1965. return true;
  1966. if (active_user_prefs_->FindPreference(path)->IsManaged() &&
  1967. !active_user_prefs_->GetBoolean(path)) {
  1968. return false;
  1969. }
  1970. return true;
  1971. }
  1972. void AccessibilityControllerImpl::SuspendSwitchAccessKeyHandling(bool suspend) {
  1973. accessibility_event_rewriter_->set_suspend_switch_access_key_handling(
  1974. suspend);
  1975. }
  1976. void AccessibilityControllerImpl::EnableChromeVoxVolumeSlideGesture() {
  1977. enable_chromevox_volume_slide_gesture_ = true;
  1978. }
  1979. void AccessibilityControllerImpl::ShowConfirmationDialog(
  1980. const std::u16string& title,
  1981. const std::u16string& description,
  1982. base::OnceClosure on_accept_callback,
  1983. base::OnceClosure on_cancel_callback,
  1984. base::OnceClosure on_close_callback) {
  1985. if (confirmation_dialog_) {
  1986. // If a dialog is already being shown we do not show a new one.
  1987. // Instead, run the on_close_callback on the new dialog to indicate
  1988. // it was closed without the user taking any action.
  1989. // This is consistent with AcceleratorController.
  1990. std::move(on_close_callback).Run();
  1991. return;
  1992. }
  1993. auto* dialog = new AccessibilityConfirmationDialog(
  1994. title, description, std::move(on_accept_callback),
  1995. std::move(on_cancel_callback), std::move(on_close_callback));
  1996. // Save the dialog so it doesn't go out of scope before it is
  1997. // used and closed.
  1998. confirmation_dialog_ = dialog->GetWeakPtr();
  1999. }
  2000. void AccessibilityControllerImpl::
  2001. UpdateDictationButtonOnSpeechRecognitionDownloadChanged(
  2002. int download_progress) {
  2003. dictation_soda_download_progress_ = download_progress;
  2004. Shell::Get()
  2005. ->GetPrimaryRootWindowController()
  2006. ->GetStatusAreaWidget()
  2007. ->dictation_button_tray()
  2008. ->UpdateOnSpeechRecognitionDownloadChanged(download_progress);
  2009. }
  2010. void AccessibilityControllerImpl::
  2011. ShowSpeechRecognitionDownloadNotificationForDictation(
  2012. bool succeeded,
  2013. const std::u16string& display_language) {
  2014. A11yNotificationType type =
  2015. succeeded ? A11yNotificationType::kSpeechRecognitionFilesDownloaded
  2016. : A11yNotificationType::kSpeechRecognitionFilesFailed;
  2017. ShowAccessibilityNotification(A11yNotificationWrapper(
  2018. type, std::vector<std::u16string>{display_language}));
  2019. }
  2020. AccessibilityControllerImpl::A11yNotificationWrapper::
  2021. A11yNotificationWrapper() = default;
  2022. AccessibilityControllerImpl::A11yNotificationWrapper::A11yNotificationWrapper(
  2023. A11yNotificationType type_in,
  2024. std::vector<std::u16string> replacements_in)
  2025. : type(type_in), replacements(replacements_in) {}
  2026. AccessibilityControllerImpl::A11yNotificationWrapper::
  2027. ~A11yNotificationWrapper() = default;
  2028. AccessibilityControllerImpl::A11yNotificationWrapper::A11yNotificationWrapper(
  2029. const A11yNotificationWrapper&) = default;
  2030. void AccessibilityControllerImpl::UpdateFeatureFromPref(FeatureType feature) {
  2031. bool enabled = features_[feature]->enabled();
  2032. bool is_managed =
  2033. active_user_prefs_->IsManagedPreference(features_[feature]->pref_name());
  2034. switch (feature) {
  2035. case FeatureType::kAutoclick:
  2036. Shell::Get()->autoclick_controller()->SetEnabled(
  2037. enabled, !is_managed /* show confirmation dialog */);
  2038. break;
  2039. case FeatureType::kCaretHighlight:
  2040. UpdateAccessibilityHighlightingFromPrefs();
  2041. break;
  2042. case FeatureType::kCursorHighlight:
  2043. UpdateAccessibilityHighlightingFromPrefs();
  2044. break;
  2045. case FeatureType::kDictation:
  2046. if (enabled) {
  2047. if (!dictation_bubble_controller_) {
  2048. dictation_bubble_controller_ =
  2049. std::make_unique<DictationBubbleController>();
  2050. }
  2051. } else {
  2052. dictation_nudge_controller_.reset();
  2053. dictation_bubble_controller_.reset();
  2054. }
  2055. break;
  2056. case FeatureType::kFloatingMenu:
  2057. if (enabled && always_show_floating_menu_when_enabled_)
  2058. ShowFloatingMenuIfEnabled();
  2059. else
  2060. floating_menu_controller_.reset();
  2061. break;
  2062. case FeatureType::kFocusHighlight:
  2063. UpdateAccessibilityHighlightingFromPrefs();
  2064. break;
  2065. case FeatureType::kFullscreenMagnifier:
  2066. break;
  2067. case FeatureType::kDockedMagnifier:
  2068. break;
  2069. case FeatureType::kHighContrast:
  2070. Shell::Get()->high_contrast_controller()->SetEnabled(enabled);
  2071. Shell::Get()->UpdateCursorCompositingEnabled();
  2072. break;
  2073. case FeatureType::kLargeCursor:
  2074. if (!enabled)
  2075. active_user_prefs_->ClearPref(prefs::kAccessibilityLargeCursorDipSize);
  2076. Shell::Get()->cursor_manager()->SetCursorSize(
  2077. large_cursor().enabled() ? ui::CursorSize::kLarge
  2078. : ui::CursorSize::kNormal);
  2079. Shell::Get()->SetLargeCursorSizeInDip(large_cursor_size_in_dip_);
  2080. Shell::Get()->UpdateCursorCompositingEnabled();
  2081. break;
  2082. case FeatureType::kLiveCaption:
  2083. live_caption().SetEnabled(enabled);
  2084. break;
  2085. case FeatureType::kMonoAudio:
  2086. CrasAudioHandler::Get()->SetOutputMonoEnabled(enabled);
  2087. break;
  2088. case FeatureType::kSpokenFeedback:
  2089. message_center::MessageCenter::Get()->SetSpokenFeedbackEnabled(enabled);
  2090. // TODO(warx): ChromeVox loading/unloading requires browser process
  2091. // started, thus it is still handled on Chrome side.
  2092. // ChromeVox focus highlighting overrides the other focus highlighting.
  2093. focus_highlight().UpdateFromPref();
  2094. break;
  2095. case FeatureType::kSelectToSpeak:
  2096. select_to_speak_state_ = SelectToSpeakState::kSelectToSpeakStateInactive;
  2097. if (enabled) {
  2098. MaybeCreateSelectToSpeakEventHandler();
  2099. } else {
  2100. select_to_speak_event_handler_.reset();
  2101. HideSelectToSpeakPanel();
  2102. select_to_speak_bubble_controller_.reset();
  2103. }
  2104. break;
  2105. case FeatureType::kStickyKeys:
  2106. Shell::Get()->sticky_keys_controller()->Enable(enabled);
  2107. break;
  2108. case FeatureType::kSwitchAccess:
  2109. if (!enabled) {
  2110. if (no_switch_access_disable_confirmation_dialog_for_testing_) {
  2111. SwitchAccessDisableDialogClosed(true);
  2112. } else {
  2113. // Show a dialog before disabling Switch Access.
  2114. new AccessibilityFeatureDisableDialog(
  2115. IDS_ASH_SWITCH_ACCESS_DISABLE_CONFIRMATION_TEXT,
  2116. base::BindOnce(
  2117. &AccessibilityControllerImpl::SwitchAccessDisableDialogClosed,
  2118. weak_ptr_factory_.GetWeakPtr(), true),
  2119. base::BindOnce(
  2120. &AccessibilityControllerImpl::SwitchAccessDisableDialogClosed,
  2121. weak_ptr_factory_.GetWeakPtr(), false));
  2122. switch_access_disable_dialog_showing_ = true;
  2123. }
  2124. // Return early. We will call NotifyAccessibilityStatusChanged() if the
  2125. // user accepts the dialog.
  2126. return;
  2127. } else {
  2128. ActivateSwitchAccess();
  2129. }
  2130. SyncSwitchAccessPrefsToSignInProfile();
  2131. break;
  2132. case FeatureType::kVirtualKeyboard:
  2133. keyboard::SetAccessibilityKeyboardEnabled(enabled);
  2134. break;
  2135. case FeatureType::kCursorColor:
  2136. UpdateCursorColorFromPrefs();
  2137. break;
  2138. case FeatureType::kFeatureCount:
  2139. case FeatureType::kNoConflictingFeature:
  2140. NOTREACHED();
  2141. }
  2142. NotifyAccessibilityStatusChanged();
  2143. }
  2144. void AccessibilityControllerImpl::UpdateDictationBubble(
  2145. bool visible,
  2146. DictationBubbleIconType icon,
  2147. const absl::optional<std::u16string>& text,
  2148. const absl::optional<std::vector<DictationBubbleHintType>>& hints) {
  2149. DCHECK(dictation().enabled());
  2150. DCHECK(dictation_bubble_controller_);
  2151. dictation_bubble_controller_->UpdateBubble(visible, icon, text, hints);
  2152. }
  2153. DictationBubbleController*
  2154. AccessibilityControllerImpl::GetDictationBubbleControllerForTest() {
  2155. if (!dictation_bubble_controller_) {
  2156. dictation_bubble_controller_ =
  2157. std::make_unique<DictationBubbleController>();
  2158. }
  2159. return dictation_bubble_controller_.get();
  2160. }
  2161. } // namespace ash