assistant_ui_model.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // Copyright 2018 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_ASSISTANT_MODEL_ASSISTANT_UI_MODEL_H_
  5. #define ASH_ASSISTANT_MODEL_ASSISTANT_UI_MODEL_H_
  6. #include <ostream>
  7. #include "ash/assistant/ui/assistant_ui_constants.h"
  8. #include "base/component_export.h"
  9. #include "base/observer_list.h"
  10. #include "chromeos/ash/services/assistant/public/cpp/assistant_service.h"
  11. #include "third_party/abseil-cpp/absl/types/optional.h"
  12. #include "ui/gfx/geometry/rect.h"
  13. namespace ash {
  14. class AssistantUiModelObserver;
  15. // Enumeration of Assistant visibility states.
  16. enum class AssistantVisibility {
  17. kClosed, // Assistant UI is hidden and the previous session has finished.
  18. kClosing, // Assistant UI is transitioning from `kVisible` to `kClosed`.
  19. kVisible, // Assistant UI is visible and a session is in progress.
  20. };
  21. COMPONENT_EXPORT(ASSISTANT_MODEL)
  22. std::ostream& operator<<(std::ostream& os, AssistantVisibility visibility);
  23. // Enumeration of Assistant button ID. These values are persisted to logs.
  24. // Entries should not be renumbered and numeric values should never be reused.
  25. // Only append to this enum is allowed if more buttons will be added.
  26. enum class AssistantButtonId {
  27. kBackDeprecated = 1,
  28. kCloseDeprecated = 2,
  29. kMinimizeDeprecated = 3,
  30. kKeyboardInputToggle = 4,
  31. kVoiceInputToggle = 5,
  32. kSettingsDeprecated = 6,
  33. kBackInLauncherDeprecated = 7,
  34. kMaxValue = kBackInLauncherDeprecated
  35. };
  36. // Models the Assistant UI.
  37. class COMPONENT_EXPORT(ASSISTANT_MODEL) AssistantUiModel {
  38. public:
  39. using AssistantEntryPoint = assistant::AssistantEntryPoint;
  40. using AssistantExitPoint = assistant::AssistantExitPoint;
  41. AssistantUiModel();
  42. AssistantUiModel(const AssistantUiModel&) = delete;
  43. AssistantUiModel& operator=(const AssistantUiModel&) = delete;
  44. ~AssistantUiModel();
  45. // Adds/removes the specified |observer|.
  46. void AddObserver(AssistantUiModelObserver* observer) const;
  47. void RemoveObserver(AssistantUiModelObserver* observer) const;
  48. // Sets the UI visibility.
  49. void SetVisible(AssistantEntryPoint entry_point);
  50. void SetClosing(AssistantExitPoint exit_point);
  51. void SetClosed(AssistantExitPoint exit_point);
  52. AssistantVisibility visibility() const { return visibility_; }
  53. // Sets the current usable work area.
  54. void SetUsableWorkArea(const gfx::Rect& usable_work_area);
  55. // Returns the current usable work area.
  56. const gfx::Rect& usable_work_area() const { return usable_work_area_; }
  57. // Returns the UI entry point. Only valid while UI is visible.
  58. AssistantEntryPoint entry_point() const { return entry_point_; }
  59. // Sets the current keyboard traversal mode.
  60. void SetKeyboardTraversalMode(bool keyboard_traversal_mode);
  61. // Returns the current keyboard traversal mode.
  62. bool keyboard_traversal_mode() const { return keyboard_traversal_mode_; }
  63. int AppListBubbleWidth() const { return app_list_bubble_width_; }
  64. void SetAppListBubbleWidth(int width);
  65. private:
  66. void SetVisibility(AssistantVisibility visibility,
  67. absl::optional<AssistantEntryPoint> entry_point,
  68. absl::optional<AssistantExitPoint> exit_point);
  69. void NotifyKeyboardTraversalModeChanged();
  70. void NotifyUiModeChanged(bool due_to_interaction);
  71. void NotifyUiVisibilityChanged(
  72. AssistantVisibility old_visibility,
  73. absl::optional<AssistantEntryPoint> entry_point,
  74. absl::optional<AssistantExitPoint> exit_point);
  75. void NotifyUsableWorkAreaChanged();
  76. AssistantVisibility visibility_ = AssistantVisibility::kClosed;
  77. AssistantEntryPoint entry_point_ = AssistantEntryPoint::kUnspecified;
  78. int app_list_bubble_width_ = kPreferredWidthDip;
  79. mutable base::ObserverList<AssistantUiModelObserver> observers_;
  80. // Usable work area for Assistant. Value is only meaningful when Assistant
  81. // UI exists.
  82. gfx::Rect usable_work_area_;
  83. // Whether or not keyboard traversal is currently enabled.
  84. // Used for updating the Assistant UI when it exists.
  85. bool keyboard_traversal_mode_ = false;
  86. };
  87. } // namespace ash
  88. #endif // ASH_ASSISTANT_MODEL_ASSISTANT_UI_MODEL_H_