accessibility_controller.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. // Copyright 2019 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. #ifndef ASH_PUBLIC_CPP_ACCESSIBILITY_CONTROLLER_H_
  5. #define ASH_PUBLIC_CPP_ACCESSIBILITY_CONTROLLER_H_
  6. #include <string>
  7. #include <vector>
  8. #include "ash/public/cpp/accelerators.h"
  9. #include "ash/public/cpp/accessibility_controller_enums.h"
  10. #include "ash/public/cpp/ash_public_export.h"
  11. #include "base/callback.h"
  12. #include "third_party/abseil-cpp/absl/types/optional.h"
  13. namespace gfx {
  14. class Rect;
  15. } // namespace gfx
  16. namespace ash {
  17. class AccessibilityControllerClient;
  18. enum class AccessibilityPanelState;
  19. enum class DictationToggleSource;
  20. enum class DictationBubbleHintType;
  21. enum class DictationBubbleIconType;
  22. class SelectToSpeakEventHandlerDelegate;
  23. enum class SelectToSpeakState;
  24. // Interface for ash client (e.g. Chrome) to control and query accessibility
  25. // features.
  26. class ASH_PUBLIC_EXPORT AccessibilityController {
  27. public:
  28. static AccessibilityController* Get();
  29. AccessibilityController(const AccessibilityController&) = delete;
  30. AccessibilityController& operator=(const AccessibilityController&) = delete;
  31. // Sets the client interface.
  32. virtual void SetClient(AccessibilityControllerClient* client) = 0;
  33. // Starts or stops darkening the screen (e.g. to allow chrome a11y extensions
  34. // to darken the screen).
  35. virtual void SetDarkenScreen(bool darken) = 0;
  36. // Called when braille display state is changed.
  37. virtual void BrailleDisplayStateChanged(bool connected) = 0;
  38. // Sets the focus highlight rect using |bounds_in_screen|. Called when focus
  39. // changed in page and a11y focus highlight feature is enabled.
  40. virtual void SetFocusHighlightRect(const gfx::Rect& bounds_in_screen) = 0;
  41. // Sets the text input caret bounds used to draw the caret highlight effect.
  42. // For effciency, only sent when the caret highlight feature is enabled.
  43. // Setting off-screen or empty bounds suppresses the highlight.
  44. virtual void SetCaretBounds(const gfx::Rect& bounds_in_screen) = 0;
  45. // Sets whether the accessibility panel should always be visible, regardless
  46. // of whether the window is fullscreen.
  47. virtual void SetAccessibilityPanelAlwaysVisible(bool always_visible) = 0;
  48. // Sets the bounds for the accessibility panel. Overrides current
  49. // configuration (i.e. fullscreen, full-width).
  50. virtual void SetAccessibilityPanelBounds(const gfx::Rect& bounds,
  51. AccessibilityPanelState state) = 0;
  52. // Sets the current Select-to-Speak state. This should be used by the Select-
  53. // to-Speak extension to inform ash of its updated state.
  54. virtual void SetSelectToSpeakState(SelectToSpeakState state) = 0;
  55. // Set the delegate used by the Select-to-Speak event handler.
  56. virtual void SetSelectToSpeakEventHandlerDelegate(
  57. SelectToSpeakEventHandlerDelegate* delegate) = 0;
  58. // Displays the Select-to-Speak panel.
  59. virtual void ShowSelectToSpeakPanel(const gfx::Rect& anchor,
  60. bool is_paused,
  61. double speech_rate) = 0;
  62. // Hides the Select-to-Speak panel.
  63. virtual void HideSelectToSpeakPanel() = 0;
  64. // Dispatches event to notify Select-to-speak that a panel action occurred,
  65. // with an optional value.
  66. virtual void OnSelectToSpeakPanelAction(SelectToSpeakPanelAction action,
  67. double value) = 0;
  68. // Hides the Switch Access back button.
  69. virtual void HideSwitchAccessBackButton() = 0;
  70. // Hides the Switch Access menu.
  71. virtual void HideSwitchAccessMenu() = 0;
  72. // Show the Switch Access back button next to the specified rectangle.
  73. virtual void ShowSwitchAccessBackButton(const gfx::Rect& bounds) = 0;
  74. // Show the Switch Access menu with the specified actions.
  75. virtual void ShowSwitchAccessMenu(
  76. const gfx::Rect& bounds,
  77. std::vector<std::string> actions_to_show) = 0;
  78. // Starts point scanning in Switch Access.
  79. virtual void StartPointScan() = 0;
  80. // Stops point scanning in Switch Access.
  81. virtual void StopPointScan() = 0;
  82. // Sets point scanning speed in Switch Access.
  83. virtual void SetPointScanSpeedDipsPerSecond(
  84. int point_scan_speed_dips_per_second) = 0;
  85. // Set whether dictation is active.
  86. virtual void SetDictationActive(bool is_active) = 0;
  87. // Starts or stops dictation. Records metrics for toggling via SwitchAccess.
  88. virtual void ToggleDictationFromSource(DictationToggleSource source) = 0;
  89. // Shows a nudge explaining that a user's dictation language was upgraded to
  90. // work offline.
  91. virtual void ShowDictationLanguageUpgradedNudge(
  92. const std::string& dictation_locale,
  93. const std::string& application_locale) = 0;
  94. // Called when the Automatic Clicks extension finds scrollable bounds.
  95. virtual void HandleAutoclickScrollableBoundsFound(
  96. gfx::Rect& bounds_in_screen) = 0;
  97. // Retrieves a string description of the current battery status.
  98. virtual std::u16string GetBatteryDescription() const = 0;
  99. // Shows or hides the virtual keyboard.
  100. virtual void SetVirtualKeyboardVisible(bool is_visible) = 0;
  101. // Performs the given accelerator action.
  102. virtual void PerformAcceleratorAction(
  103. AcceleratorAction accelerator_action) = 0;
  104. // Notify observers that the accessibility status has changed. This is part of
  105. // the public interface because a11y features like screen magnifier are
  106. // managed outside of this accessibility controller.
  107. virtual void NotifyAccessibilityStatusChanged() = 0;
  108. // Returns true if the |path| pref is being controlled by a policy which
  109. // enforces turning it on or its not being controlled by any type of policy
  110. // and false otherwise.
  111. virtual bool IsAccessibilityFeatureVisibleInTrayMenu(
  112. const std::string& path) = 0;
  113. // Disables restoring of recommended policy values.
  114. virtual void DisablePolicyRecommendationRestorerForTesting() {}
  115. // Set to true to disable the dialog.
  116. // Used in tests.
  117. virtual void DisableSwitchAccessDisableConfirmationDialogTesting() = 0;
  118. // Shows floating accessibility menu if it was enabled by policy.
  119. virtual void ShowFloatingMenuIfEnabled() {}
  120. // Suspends (or resumes) key handling for Switch Access.
  121. virtual void SuspendSwitchAccessKeyHandling(bool suspend) {}
  122. // Enables ChromeVox's volume slide gesture.
  123. virtual void EnableChromeVoxVolumeSlideGesture() {}
  124. // Shows a confirmation dialog with the given text and description,
  125. // and calls the relevant callback when the dialog is confirmed, canceled
  126. // or closed.
  127. virtual void ShowConfirmationDialog(const std::u16string& title,
  128. const std::u16string& description,
  129. base::OnceClosure on_accept_callback,
  130. base::OnceClosure on_cancel_callback,
  131. base::OnceClosure on_close_callback) {}
  132. // Updates the enabled state, tooltip, and progress ring of the dictation
  133. // button in the status tray when speech recognition file download state
  134. // changes. `download_progress` indicates SODA download progress and is
  135. // guaranteed to be between 0 and 100 (inclusive).
  136. virtual void UpdateDictationButtonOnSpeechRecognitionDownloadChanged(
  137. int download_progress) = 0;
  138. // Shows a notification card in the message center informing the user that
  139. // speech recognition files have either downloaded successfully or failed.
  140. // Specific to the Dictation feature.
  141. virtual void ShowSpeechRecognitionDownloadNotificationForDictation(
  142. bool succeeded,
  143. const std::u16string& display_language) = 0;
  144. // Updates the Dictation UI bubble. `text` is optional to allow clients to
  145. // clear the bubble's text.
  146. virtual void UpdateDictationBubble(
  147. bool visible,
  148. DictationBubbleIconType icon,
  149. const absl::optional<std::u16string>& text,
  150. const absl::optional<std::vector<DictationBubbleHintType>>& hints) = 0;
  151. // Cancels all of spoken feedback's current and queued speech immediately.
  152. virtual void SilenceSpokenFeedback() = 0;
  153. protected:
  154. AccessibilityController();
  155. virtual ~AccessibilityController();
  156. };
  157. } // namespace ash
  158. #endif // ASH_PUBLIC_CPP_ACCESSIBILITY_CONTROLLER_H_