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
ash / keyboard / ui / keyboard_ui_model.h [blame]
// Copyright 2019 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_KEYBOARD_UI_KEYBOARD_UI_MODEL_H_
#define ASH_KEYBOARD_UI_KEYBOARD_UI_MODEL_H_
#include <string>
#include "ash/keyboard/ui/keyboard_export.h"
#include "ash/public/cpp/keyboard/keyboard_config.h"
namespace keyboard {
// Represents the current state of the keyboard UI.
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class KeyboardUIState {
kUnknown = 0,
// Keyboard has never been shown.
kInitial = 1,
// Waiting for an extension to be loaded. Will move to HIDDEN if this is
// loading pre-emptively, otherwise will move to SHOWN.
kLoading = 2,
// kShowing = 3, // no longer used
// Keyboard is shown.
kShown = 4,
// Keyboard is still shown, but will move to HIDDEN in a short period, or if
// an input element gets focused again, will move to SHOWN.
kWillHide = 5,
// kHiding = 6, // no longer used
// Keyboard is hidden, but has shown at least once.
kHidden = 7,
kMaxValue = kHidden
};
// Returns the string representation of a keyboard UI state.
std::string StateToStr(KeyboardUIState state);
// Returns a unique hash of a state transition, used for histograms.
// The hashes correspond to the KeyboardControllerStateTransition entry in
// tools/metrics/histograms/enums.xml.
constexpr int GetStateTransitionHash(KeyboardUIState prev,
KeyboardUIState next) {
return static_cast<int>(prev) * 1000 + static_cast<int>(next);
}
// Model for the virtual keyboard UI.
class KEYBOARD_EXPORT KeyboardUIModel {
public:
KeyboardUIModel();
KeyboardUIModel(const KeyboardUIModel&) = delete;
KeyboardUIModel& operator=(const KeyboardUIModel&) = delete;
// Get the current state of the keyboard UI.
KeyboardUIState state() const { return state_; }
// Changes the current state to another. Only accepts valid state transitions.
void ChangeState(KeyboardUIState new_state);
private:
// Current state of the keyboard UI.
KeyboardUIState state_ = KeyboardUIState::kInitial;
};
} // namespace keyboard
#endif // ASH_KEYBOARD_UI_KEYBOARD_UI_MODEL_H_