summaryrefslogtreecommitdiff
path: root/chromium/chrome/browser/accessibility/accessibility_state_utils.cc
blob: c8a59f46a6a6750b34d60be25268096b54caad69 (plain)
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
// Copyright 2019 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.

#include "chrome/browser/accessibility/accessibility_state_utils.h"

#include "build/chromeos_buildflags.h"

#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/ash/accessibility/accessibility_manager.h"
#else
#include <stdint.h>
#include "content/public/browser/browser_accessibility_state.h"
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

namespace accessibility_state_utils {

enum class OverrideStatus { kNotSet = 0, kEnabled = 1, kDisabled = 2 };

static OverrideStatus screen_reader_enabled_override_for_testing =
    OverrideStatus::kNotSet;

#if BUILDFLAG(IS_CHROMEOS_ASH)
using ::ash::AccessibilityManager;
#endif

bool IsScreenReaderEnabled() {
  if (screen_reader_enabled_override_for_testing != OverrideStatus::kNotSet) {
    return (screen_reader_enabled_override_for_testing ==
            OverrideStatus::kEnabled)
               ? true
               : false;
  }
#if BUILDFLAG(IS_CHROMEOS_ASH)
  return AccessibilityManager::Get() &&
         AccessibilityManager::Get()->IsSpokenFeedbackEnabled();
#else
  // TODO(katie): Can we use AXMode in Chrome OS as well? May need to stop
  // Switch Access and Select-to-Speak from setting kScreenReader.
  ui::AXMode mode =
      content::BrowserAccessibilityState::GetInstance()->GetAccessibilityMode();
  return mode.has_mode(ui::AXMode::kScreenReader);
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)
}

void OverrideIsScreenReaderEnabledForTesting(bool enabled) {
  screen_reader_enabled_override_for_testing =
      enabled ? OverrideStatus::kEnabled : OverrideStatus::kDisabled;
}

}  // namespace accessibility_state_utils