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
ash / system / accessibility / floating_accessibility_view.h [blame]
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_ACCESSIBILITY_FLOATING_ACCESSIBILITY_VIEW_H_
#define ASH_SYSTEM_ACCESSIBILITY_FLOATING_ACCESSIBILITY_VIEW_H_
#include "ash/public/cpp/accessibility_controller_enums.h"
#include "ash/public/cpp/keyboard/keyboard_controller_observer.h"
#include "ash/shell_observer.h"
#include "ash/system/tray/system_tray_observer.h"
#include "ash/system/tray/tray_bubble_view.h"
#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/layout/box_layout_view.h"
#include "ui/views/metadata/view_factory.h"
namespace ash {
class FloatingMenuButton;
class TrayBackgroundView;
class FloatingAccessibilityBubbleView : public TrayBubbleView {
METADATA_HEADER(FloatingAccessibilityBubbleView, TrayBubbleView)
public:
explicit FloatingAccessibilityBubbleView(
const TrayBubbleView::InitParams& init_params);
FloatingAccessibilityBubbleView(const FloatingAccessibilityBubbleView&) =
delete;
FloatingAccessibilityBubbleView& operator=(
const FloatingAccessibilityBubbleView&) = delete;
~FloatingAccessibilityBubbleView() override;
// TrayBubbleView:
bool IsAnchoredToStatusArea() const override;
bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
// views::View:
void AdjustAccessibleName(std::u16string& new_name,
ax::mojom::NameFrom& name_from) override;
};
BEGIN_VIEW_BUILDER(/* no export */,
FloatingAccessibilityBubbleView,
TrayBubbleView)
END_VIEW_BUILDER
// This floating view displays the currently enabled accessibility options,
// along with buttons to configure them.
// ---- Layout:
// ---- ?[Dictation] ?[SelectToSpeak] ?[VirtualKeyboard]
// ---- | [Open settings list]
// ---- | [Change menu location]
class FloatingAccessibilityView : public views::BoxLayoutView,
public views::ViewObserver,
public KeyboardControllerObserver,
public SystemTrayObserver {
METADATA_HEADER(FloatingAccessibilityView, views::BoxLayoutView)
public:
// Used for testing. Starts 1 because views IDs should not be 0.
enum ButtonId {
kPosition = 1,
kSettingsList = 2,
kDictation = 3,
kSelectToSpeak = 4,
kVirtualKeyboard = 5,
kIme = 6,
};
class Delegate {
public:
// When the user click on the settings list button.
virtual void OnDetailedMenuEnabled(bool enabled) {}
// When the layout of the view changes and we may need to reposition
// ourselves.
virtual void OnLayoutChanged() {}
virtual void OnFocused() {}
virtual void OnBlurred() {}
virtual ~Delegate() = default;
};
explicit FloatingAccessibilityView(Delegate* delegate);
FloatingAccessibilityView& operator=(const FloatingAccessibilityView&) =
delete;
~FloatingAccessibilityView() override;
FloatingAccessibilityView(const FloatingAccessibilityView&) = delete;
// Initizlizes feature button views. Should be called after the view is
// connected to a widget.
void Initialize();
void SetMenuPosition(FloatingMenuPosition position);
void SetDetailedViewShown(bool shown);
void FocusOnDetailedViewButton();
private:
friend class FloatingAccessibilityControllerTest;
void OnA11yTrayButtonPressed();
void OnPositionButtonPressed();
// views::ViewObserver:
void OnViewVisibilityChanged(views::View* observed_view,
views::View* starting_view) override;
void OnViewFocused(views::View* view) override;
void OnViewBlurred(views::View* view) override;
// KeyboardControllerObserver:
void OnKeyboardVisibilityChanged(bool visible) override;
// SystemTrayObserver:
void OnFocusLeavingSystemTray(bool reverse) override;
void OnImeMenuTrayBubbleShown() override;
TrayBackgroundView* dictation_button() {
return dictation_button_observation_.GetSource();
}
TrayBackgroundView* select_to_speak_button() {
return select_to_speak_button_observation_.GetSource();
}
TrayBackgroundView* virtual_keyboard_button() {
return virtual_keyboard_button_observation_.GetSource();
}
ImeMenuTray* ime_button() { return ime_button_observation_.GetSource(); }
// Feature buttons:
base::ScopedObservation<TrayBackgroundView, ViewObserver>
dictation_button_observation_{this};
base::ScopedObservation<TrayBackgroundView, ViewObserver>
select_to_speak_button_observation_{this};
base::ScopedObservation<TrayBackgroundView, ViewObserver>
virtual_keyboard_button_observation_{this};
// Button to list all available features.
raw_ptr<FloatingMenuButton> a11y_tray_button_ = nullptr;
// Button to move the view around corners.
raw_ptr<FloatingMenuButton> position_button_ = nullptr;
// Button to list all available keyboard languages.
base::ScopedObservation<ImeMenuTray, ViewObserver> ime_button_observation_{
this};
const raw_ptr<Delegate> delegate_;
};
BEGIN_VIEW_BUILDER(/* no export */,
FloatingAccessibilityView,
views::BoxLayoutView)
END_VIEW_BUILDER
} // namespace ash
DEFINE_VIEW_BUILDER(/* no export */, ash::FloatingAccessibilityBubbleView)
DEFINE_VIEW_BUILDER(/* no export */, ash::FloatingAccessibilityView)
#endif // ASH_SYSTEM_ACCESSIBILITY_FLOATING_ACCESSIBILITY_VIEW_H_