forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccessibility_controller_impl.h
350 lines (283 loc) · 13.8 KB
/
accessibility_controller_impl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_ACCESSIBILITY_ACCESSIBILITY_CONTROLLER_IMPL_H_
#define ASH_ACCESSIBILITY_ACCESSIBILITY_CONTROLLER_IMPL_H_
#include <memory>
#include "ash/ash_export.h"
#include "ash/public/cpp/accessibility_controller.h"
#include "ash/public/cpp/ash_constants.h"
#include "ash/public/cpp/tablet_mode_observer.h"
#include "ash/session/session_observer.h"
#include "base/macros.h"
#include "base/observer_list.h"
#include "base/time/time.h"
class PrefChangeRegistrar;
class PrefRegistrySimple;
class PrefService;
namespace ax {
namespace mojom {
enum class Gesture;
} // namespace mojom
} // namespace ax
namespace gfx {
class Point;
} // namespace gfx
namespace ash {
class AccessibilityHighlightController;
class AccessibilityObserver;
class ScopedBacklightsForcedOff;
class SelectToSpeakEventHandler;
class SwitchAccessEventHandler;
enum AccessibilityNotificationVisibility {
A11Y_NOTIFICATION_NONE,
A11Y_NOTIFICATION_SHOW,
};
// The controller for accessibility features in ash. Features can be enabled
// in chrome's webui settings or the system tray menu (see TrayAccessibility).
// Uses preferences to communicate with chrome to support mash.
class ASH_EXPORT AccessibilityControllerImpl : public AccessibilityController,
public SessionObserver,
public TabletModeObserver {
public:
AccessibilityControllerImpl();
~AccessibilityControllerImpl() override;
// See Shell::RegisterProfilePrefs().
static void RegisterProfilePrefs(PrefRegistrySimple* registry);
void Shutdown();
void AddObserver(AccessibilityObserver* observer);
void RemoveObserver(AccessibilityObserver* observer);
// The following functions read and write to their associated preference.
// These values are then used to determine whether the accelerator
// confirmation dialog for the respective preference has been accepted before.
void SetHighContrastAcceleratorDialogAccepted();
bool HasHighContrastAcceleratorDialogBeenAccepted() const;
void SetScreenMagnifierAcceleratorDialogAccepted();
bool HasScreenMagnifierAcceleratorDialogBeenAccepted() const;
void SetDockedMagnifierAcceleratorDialogAccepted();
bool HasDockedMagnifierAcceleratorDialogBeenAccepted() const;
void SetDictationAcceleratorDialogAccepted();
bool HasDictationAcceleratorDialogBeenAccepted() const;
void SetDisplayRotationAcceleratorDialogBeenAccepted();
bool HasDisplayRotationAcceleratorDialogBeenAccepted() const;
void SetAutoclickEnabled(bool enabled);
bool autoclick_enabled() const { return autoclick_enabled_; }
bool IsAutoclickSettingVisibleInTray();
bool IsEnterpriseIconVisibleForAutoclick();
void SetAutoclickEventType(AutoclickEventType event_type);
AutoclickEventType GetAutoclickEventType();
void SetAutoclickMenuPosition(AutoclickMenuPosition position);
AutoclickMenuPosition GetAutoclickMenuPosition();
void RequestAutoclickScrollableBoundsForPoint(gfx::Point& point_in_screen);
// Update the autoclick menu bounds if necessary. This may need to happen when
// the display work area changes, or if system ui regions change (like the
// virtual keyboard position).
void UpdateAutoclickMenuBoundsIfNeeded();
void SetCaretHighlightEnabled(bool enabled);
bool caret_highlight_enabled() const { return caret_highlight_enabled_; }
bool IsCaretHighlightSettingVisibleInTray();
bool IsEnterpriseIconVisibleForCaretHighlight();
void SetCursorHighlightEnabled(bool enabled);
bool cursor_highlight_enabled() const { return cursor_highlight_enabled_; }
bool IsCursorHighlightSettingVisibleInTray();
bool IsEnterpriseIconVisibleForCursorHighlight();
void SetDictationEnabled(bool enabled);
bool dictation_enabled() const { return dictation_enabled_; }
bool IsDictationSettingVisibleInTray();
bool IsEnterpriseIconVisibleForDictation();
void SetFocusHighlightEnabled(bool enabled);
bool focus_highlight_enabled() const { return focus_highlight_enabled_; }
bool IsFocusHighlightSettingVisibleInTray();
bool IsEnterpriseIconVisibleForFocusHighlight();
void SetFullscreenMagnifierEnabled(bool enabled);
bool IsFullscreenMagnifierEnabledForTesting();
bool IsFullScreenMagnifierSettingVisibleInTray();
bool IsEnterpriseIconVisibleForFullScreenMagnifier();
void SetDockedMagnifierEnabledForTesting(bool enabled);
bool IsDockedMagnifierEnabledForTesting();
bool IsDockedMagnifierSettingVisibleInTray();
bool IsEnterpriseIconVisibleForDockedMagnifier();
void SetHighContrastEnabled(bool enabled);
bool high_contrast_enabled() const { return high_contrast_enabled_; }
bool IsHighContrastSettingVisibleInTray();
bool IsEnterpriseIconVisibleForHighContrast();
void SetLargeCursorEnabled(bool enabled);
bool large_cursor_enabled() const { return large_cursor_enabled_; }
bool IsLargeCursorSettingVisibleInTray();
bool IsEnterpriseIconVisibleForLargeCursor();
void SetMonoAudioEnabled(bool enabled);
bool mono_audio_enabled() const { return mono_audio_enabled_; }
bool IsMonoAudioSettingVisibleInTray();
bool IsEnterpriseIconVisibleForMonoAudio();
void SetSpokenFeedbackEnabled(bool enabled,
AccessibilityNotificationVisibility notify);
bool spoken_feedback_enabled() const { return spoken_feedback_enabled_; }
bool IsSpokenFeedbackSettingVisibleInTray();
bool IsEnterpriseIconVisibleForSpokenFeedback();
void SetSelectToSpeakEnabled(bool enabled);
bool select_to_speak_enabled() const { return select_to_speak_enabled_; }
bool IsSelectToSpeakSettingVisibleInTray();
bool IsEnterpriseIconVisibleForSelectToSpeak();
void RequestSelectToSpeakStateChange();
SelectToSpeakState GetSelectToSpeakState() const;
void SetStickyKeysEnabled(bool enabled);
bool sticky_keys_enabled() const { return sticky_keys_enabled_; }
bool IsStickyKeysSettingVisibleInTray();
bool IsEnterpriseIconVisibleForStickyKeys();
void SetSwitchAccessEnabled(bool enabled);
bool switch_access_enabled() const { return switch_access_enabled_; }
bool IsSwitchAccessSettingVisibleInTray();
bool IsEnterpriseIconVisibleForSwitchAccess();
void SetVirtualKeyboardEnabled(bool enabled);
bool virtual_keyboard_enabled() const { return virtual_keyboard_enabled_; }
bool IsVirtualKeyboardSettingVisibleInTray();
bool IsEnterpriseIconVisibleForVirtualKeyboard();
bool dictation_active() const { return dictation_active_; }
// Triggers an accessibility alert to give the user feedback.
void TriggerAccessibilityAlert(AccessibilityAlert alert);
// Triggers an accessibility alert with the given |message|.
void TriggerAccessibilityAlertWithMessage(const std::string& message);
// Plays an earcon. Earcons are brief and distinctive sounds that indicate
// that their mapped event has occurred. The |sound_key| enums can be found in
// chromeos/audio/chromeos_sounds.h.
void PlayEarcon(int sound_key);
// Initiates play of shutdown sound. Returns the TimeDelta duration.
base::TimeDelta PlayShutdownSound();
// Forwards an accessibility gesture from the touch exploration controller to
// ChromeVox.
void HandleAccessibilityGesture(ax::mojom::Gesture gesture);
// Toggle dictation.
void ToggleDictation();
// Cancels all current and queued speech immediately.
void SilenceSpokenFeedback();
// Called when we first detect two fingers are held down, which can be used to
// toggle spoken feedback on some touch-only devices.
void OnTwoFingerTouchStart();
// Called when the user is no longer holding down two fingers (including
// releasing one, holding down three, or moving them).
void OnTwoFingerTouchStop();
// Whether or not to enable toggling spoken feedback via holding down two
// fingers on the screen.
bool ShouldToggleSpokenFeedbackViaTouch() const;
// Plays tick sound indicating spoken feedback will be toggled after
// countdown.
void PlaySpokenFeedbackToggleCountdown(int tick_count);
// Returns true if that accessibility feature pref |path| is being controlled
// by a policy and false otherwise.
bool IsEnterpriseIconVisibleInTrayMenu(const std::string& path);
// Returns true if at least one of the primary settings of the accessibility
// features is going to be visible in the accessibility tray menu.
bool IsPrimarySettingsViewVisibleInTray();
// Returns true if at least one of the additional settings of the
// accessibility features is going to be visible in the accessibility tray
// menu.
bool IsAdditionalSettingsViewVisibleInTray();
// Returns true if there exist one of the additional accessibility features
// and one of the primary accessibility features which are going to visible on
// accessibility tray menu.
bool IsAdditionalSettingsSeparatorVisibleInTray();
// AccessibilityController:
void SetClient(AccessibilityControllerClient* client) override;
void SetDarkenScreen(bool darken) override;
void BrailleDisplayStateChanged(bool connected) override;
void SetFocusHighlightRect(const gfx::Rect& bounds_in_screen) override;
void SetCaretBounds(const gfx::Rect& bounds_in_screen) override;
void SetAccessibilityPanelAlwaysVisible(bool always_visible) override;
void SetAccessibilityPanelBounds(const gfx::Rect& bounds,
AccessibilityPanelState state) override;
void SetSelectToSpeakState(SelectToSpeakState state) override;
void SetSelectToSpeakEventHandlerDelegate(
SelectToSpeakEventHandlerDelegate* delegate) override;
void SetSwitchAccessEventHandlerDelegate(
SwitchAccessEventHandlerDelegate* delegate) override;
void SetDictationActive(bool is_active) override;
void ToggleDictationFromSource(DictationToggleSource source) override;
void OnAutoclickScrollableBoundsFound(gfx::Rect& bounds_in_screen) override;
void ForwardKeyEventsToSwitchAccess(bool should_forward) override;
base::string16 GetBatteryDescription() const override;
void SetVirtualKeyboardVisible(bool is_visible) override;
void NotifyAccessibilityStatusChanged() override;
bool IsAccessibilityFeatureVisibleInTrayMenu(
const std::string& path) override;
void SetSwitchAccessIgnoreVirtualKeyEventForTesting(
bool should_ignore) override;
// SessionObserver:
void OnSigninScreenPrefServiceInitialized(PrefService* prefs) override;
void OnActiveUserPrefServiceChanged(PrefService* prefs) override;
// Test helpers:
SwitchAccessEventHandler* GetSwitchAccessEventHandlerForTest();
private:
// TabletModeObserver:
void OnTabletModeStarted() override;
void OnTabletModeEnded() override;
// Observes either the signin screen prefs or active user prefs and loads
// initial settings.
void ObservePrefs(PrefService* prefs);
void UpdateAutoclickFromPref();
void UpdateAutoclickDelayFromPref();
void UpdateAutoclickEventTypeFromPref();
void UpdateAutoclickRevertToLeftClickFromPref();
void UpdateAutoclickStabilizePositionFromPref();
void UpdateAutoclickMovementThresholdFromPref();
void UpdateAutoclickMenuPositionFromPref();
void UpdateCaretHighlightFromPref();
void UpdateCursorHighlightFromPref();
void UpdateDictationFromPref();
void UpdateFocusHighlightFromPref();
void UpdateHighContrastFromPref();
void UpdateLargeCursorFromPref();
void UpdateMonoAudioFromPref();
void UpdateSpokenFeedbackFromPref();
void UpdateSelectToSpeakFromPref();
void UpdateStickyKeysFromPref();
void UpdateSwitchAccessFromPref();
void UpdateSwitchAccessKeyCodesFromPref(SwitchAccessCommand command);
void UpdateSwitchAccessAutoScanEnabledFromPref();
void UpdateSwitchAccessAutoScanSpeedFromPref();
void UpdateSwitchAccessAutoScanKeyboardSpeedFromPref();
void UpdateVirtualKeyboardFromPref();
void UpdateAccessibilityHighlightingFromPrefs();
void MaybeCreateSelectToSpeakEventHandler();
void MaybeCreateSwitchAccessEventHandler();
// The pref service of the currently active user or the signin profile before
// user logs in. Can be null in ash_unittests.
PrefService* active_user_prefs_ = nullptr;
std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
// Client interface in chrome browser.
AccessibilityControllerClient* client_ = nullptr;
bool autoclick_enabled_ = false;
base::TimeDelta autoclick_delay_;
bool caret_highlight_enabled_ = false;
bool cursor_highlight_enabled_ = false;
bool dictation_enabled_ = false;
bool focus_highlight_enabled_ = false;
bool high_contrast_enabled_ = false;
bool large_cursor_enabled_ = false;
int large_cursor_size_in_dip_ = kDefaultLargeCursorSize;
bool mono_audio_enabled_ = false;
bool spoken_feedback_enabled_ = false;
bool select_to_speak_enabled_ = false;
bool sticky_keys_enabled_ = false;
bool switch_access_enabled_ = false;
bool virtual_keyboard_enabled_ = false;
bool dictation_active_ = false;
SelectToSpeakState select_to_speak_state_ =
SelectToSpeakState::kSelectToSpeakStateInactive;
std::unique_ptr<SelectToSpeakEventHandler> select_to_speak_event_handler_;
SelectToSpeakEventHandlerDelegate* select_to_speak_event_handler_delegate_ =
nullptr;
// List of key codes that Switch Access should capture.
std::vector<int> switch_access_keys_to_capture_;
std::unique_ptr<SwitchAccessEventHandler> switch_access_event_handler_;
SwitchAccessEventHandlerDelegate* switch_access_event_handler_delegate_ =
nullptr;
// Used to control the highlights of caret, cursor and focus.
std::unique_ptr<AccessibilityHighlightController>
accessibility_highlight_controller_;
// Used to force the backlights off to darken the screen.
std::unique_ptr<ScopedBacklightsForcedOff> scoped_backlights_forced_off_;
base::ObserverList<AccessibilityObserver> observers_;
DISALLOW_COPY_AND_ASSIGN(AccessibilityControllerImpl);
};
} // namespace ash
#endif // ASH_ACCESSIBILITY_ACCESSIBILITY_CONTROLLER_IMPL_H_