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
ash / system / accessibility / dictation_button_tray.h [blame]
// Copyright 2018 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_DICTATION_BUTTON_TRAY_H_
#define ASH_SYSTEM_ACCESSIBILITY_DICTATION_BUTTON_TRAY_H_
#include "ash/accelerators/accelerator_controller_impl.h"
#include "ash/accessibility/accessibility_observer.h"
#include "ash/ash_export.h"
#include "ash/constants/tray_background_view_catalog.h"
#include "ash/public/cpp/session/session_observer.h"
#include "ash/shell_observer.h"
#include "ash/system/tray/tray_background_view.h"
#include "base/memory/raw_ptr.h"
#include "ui/base/ime/input_method_observer.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/events/event_constants.h"
namespace ui {
class Event;
} // namespace ui
namespace views {
class ImageView;
} // namespace views
namespace ash {
class ProgressIndicator;
// Status area tray for showing a toggle for Dictation. Dictation allows
// users to have their speech transcribed into a text area. This tray will
// only be visible after Dictation is enabled in settings. This tray does not
// provide any bubble view windows.
class ASH_EXPORT DictationButtonTray : public TrayBackgroundView,
public ShellObserver,
public AccessibilityObserver,
public SessionObserver,
public ui::InputMethodObserver {
METADATA_HEADER(DictationButtonTray, TrayBackgroundView)
public:
DictationButtonTray(Shelf* shelf, TrayBackgroundViewCatalogName catalog_name);
DictationButtonTray(const DictationButtonTray&) = delete;
DictationButtonTray& operator=(const DictationButtonTray&) = delete;
~DictationButtonTray() override;
// ShellObserver:
void OnDictationStarted() override;
void OnDictationEnded() override;
// AccessibilityObserver:
void OnAccessibilityStatusChanged() override;
// SessionObserver:
void OnSessionStateChanged(session_manager::SessionState state) override;
// TrayBackgroundView:
void Initialize() override;
void ClickedOutsideBubble(const ui::LocatedEvent& event) override;
void UpdateTrayItemColor(bool is_active) override;
void HandleLocaleChange() override;
void HideBubbleWithView(const TrayBubbleView* bubble_view) override;
void OnThemeChanged() override;
void Layout(PassKey) override;
void HideBubble(const TrayBubbleView* bubble_view) override;
// ui::InputMethodObserver:
void OnFocus() override {}
void OnBlur() override {}
void OnCaretBoundsChanged(const ui::TextInputClient* client) override;
void OnTextInputStateChanged(const ui::TextInputClient* client) override;
void OnInputMethodDestroyed(const ui::InputMethod* input_method) override {}
// Updates this button's state and progress indicator when speech recognition
// file download state changes.
void UpdateOnSpeechRecognitionDownloadChanged(int download_progress);
int download_progress() const { return download_progress_; }
private:
friend class DictationButtonTrayTest;
friend class DictationButtonTraySodaTest;
// Callback called when this is pressed.
void OnDictationButtonPressed(const ui::Event& event);
// Sets the icon when Dictation is activated / deactivated.
// Also updates visibility when Dictation is enabled / disabled.
void UpdateIcon(bool dictation_active);
// Updates bounds for `progress_indicator_`.
void UpdateProgressIndicatorBounds();
// Updates the visibility of the button.
void UpdateVisibility();
// Actively looks up dictation status and calls UpdateIcon.
void CheckDictationStatusAndUpdateIcon();
// Called when text input state changes to determine whether Dictation
// should still be enabled and update the icon.
void TextInputChanged(const ui::TextInputClient* client);
// Weak pointer, will be parented by TrayContainer for its lifetime.
raw_ptr<views::ImageView> icon_ = nullptr;
// SODA download progress. A value of 0 < X < 100 indicates that download is
// in-progress.
int download_progress_;
// A progress indicator to indicate SODA download progress.
std::unique_ptr<ProgressIndicator> progress_indicator_;
// Whether the cursor and focus is currently in a text input field.
bool in_text_input_ = false;
};
} // namespace ash
#endif // ASH_SYSTEM_ACCESSIBILITY_DICTATION_BUTTON_TRAY_H_