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
ash / webui / common / backend / accessibility_features.cc [blame]
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/webui/common/backend/accessibility_features.h"
#include <utility>
#include "ash/accessibility/accessibility_controller.h"
#include "ash/shell.h"
#include "ash/webui/common/mojom/accessibility_features.mojom.h"
#include "base/functional/callback.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote_set.h"
namespace ash {
namespace {
bool ShouldForceHiddenElementsVisible() {
AccessibilityController* accessibility_controller =
Shell::Get()->accessibility_controller();
if (!accessibility_controller) {
return false;
}
return accessibility_controller->spoken_feedback().enabled() ||
accessibility_controller->switch_access().enabled() ||
accessibility_controller->fullscreen_magnifier().enabled();
}
} // namespace
AccessibilityFeatures::AccessibilityFeatures() {
AccessibilityController* accessibility_controller =
Shell::Get()->accessibility_controller();
if (!accessibility_controller) {
return;
}
// Set the initial value from the controller.
force_hidden_elements_visible_ = ShouldForceHiddenElementsVisible();
accessibility_controller->AddObserver(this);
}
AccessibilityFeatures::~AccessibilityFeatures() {
AccessibilityController* accessibility_controller =
Shell::Get()->accessibility_controller();
if (!accessibility_controller) {
return;
}
accessibility_controller->RemoveObserver(this);
}
void AccessibilityFeatures::ObserveForceHiddenElementsVisible(
mojo::PendingRemote<common::mojom::ForceHiddenElementsVisibleObserver>
observer,
ObserveForceHiddenElementsVisibleCallback callback) {
force_hidden_elements_visible_observers_.Add(std::move(observer));
std::move(callback).Run(force_hidden_elements_visible_);
}
void AccessibilityFeatures::OnAccessibilityStatusChanged() {
// Get the latest state and update the observer if there's a change.
if (force_hidden_elements_visible_ != ShouldForceHiddenElementsVisible()) {
force_hidden_elements_visible_ = !force_hidden_elements_visible_;
for (auto& observer : force_hidden_elements_visible_observers_) {
observer->OnForceHiddenElementsVisibleChange(
force_hidden_elements_visible_);
}
}
}
void AccessibilityFeatures::BindInterface(
mojo::PendingReceiver<common::mojom::AccessibilityFeatures>
pending_receiver) {
receiver_.Bind(std::move(pending_receiver));
}
} // namespace ash