keyboard_ui_model.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef ASH_KEYBOARD_UI_KEYBOARD_UI_MODEL_H_
  5. #define ASH_KEYBOARD_UI_KEYBOARD_UI_MODEL_H_
  6. #include <string>
  7. #include "ash/keyboard/ui/keyboard_export.h"
  8. #include "ash/public/cpp/keyboard/keyboard_config.h"
  9. namespace keyboard {
  10. // Represents the current state of the keyboard UI.
  11. // These values are persisted to logs. Entries should not be renumbered and
  12. // numeric values should never be reused.
  13. enum class KeyboardUIState {
  14. kUnknown = 0,
  15. // Keyboard has never been shown.
  16. kInitial = 1,
  17. // Waiting for an extension to be loaded. Will move to HIDDEN if this is
  18. // loading pre-emptively, otherwise will move to SHOWN.
  19. kLoading = 2,
  20. // kShowing = 3, // no longer used
  21. // Keyboard is shown.
  22. kShown = 4,
  23. // Keyboard is still shown, but will move to HIDDEN in a short period, or if
  24. // an input element gets focused again, will move to SHOWN.
  25. kWillHide = 5,
  26. // kHiding = 6, // no longer used
  27. // Keyboard is hidden, but has shown at least once.
  28. kHidden = 7,
  29. kMaxValue = kHidden
  30. };
  31. // Returns the string representation of a keyboard UI state.
  32. std::string StateToStr(KeyboardUIState state);
  33. // Returns a unique hash of a state transition, used for histograms.
  34. // The hashes correspond to the KeyboardControllerStateTransition entry in
  35. // tools/metrics/enums.xml.
  36. constexpr int GetStateTransitionHash(KeyboardUIState prev,
  37. KeyboardUIState next) {
  38. return static_cast<int>(prev) * 1000 + static_cast<int>(next);
  39. }
  40. // Model for the virtual keyboard UI.
  41. class KEYBOARD_EXPORT KeyboardUIModel {
  42. public:
  43. KeyboardUIModel();
  44. KeyboardUIModel(const KeyboardUIModel&) = delete;
  45. KeyboardUIModel& operator=(const KeyboardUIModel&) = delete;
  46. // Get the current state of the keyboard UI.
  47. KeyboardUIState state() const { return state_; }
  48. // Changes the current state to another. Only accepts valid state transitions.
  49. void ChangeState(KeyboardUIState new_state);
  50. private:
  51. // Current state of the keyboard UI.
  52. KeyboardUIState state_ = KeyboardUIState::kInitial;
  53. };
  54. } // namespace keyboard
  55. #endif // ASH_KEYBOARD_UI_KEYBOARD_UI_MODEL_H_