projector_ui_controller.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2021 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_PROJECTOR_PROJECTOR_UI_CONTROLLER_H_
  5. #define ASH_PROJECTOR_PROJECTOR_UI_CONTROLLER_H_
  6. #include "ash/ash_export.h"
  7. #include "ash/projector/projector_metrics.h"
  8. #include "ash/public/cpp/projector/projector_session.h"
  9. #include "base/scoped_observation.h"
  10. #include "third_party/abseil-cpp/absl/types/optional.h"
  11. #include "third_party/skia/include/core/SkColor.h"
  12. namespace aura {
  13. class Window;
  14. } // namespace aura
  15. namespace ash {
  16. class ProjectorControllerImpl;
  17. struct AnnotatorTool;
  18. // The controller in charge of UI.
  19. class ASH_EXPORT ProjectorUiController : public ProjectorSessionObserver {
  20. public:
  21. // Shows a notification informing the user that a Projector error has
  22. // occurred.
  23. static void ShowFailureNotification(int message_id);
  24. // Shows a notification informing the user that a Projector save error has
  25. // occurred.
  26. static void ShowSaveFailureNotification();
  27. explicit ProjectorUiController(ProjectorControllerImpl* projector_controller);
  28. ProjectorUiController(const ProjectorUiController&) = delete;
  29. ProjectorUiController& operator=(const ProjectorUiController&) = delete;
  30. ~ProjectorUiController() override;
  31. // Show Projector annotation tray for `current_root`. Virtual for testing.
  32. virtual void ShowAnnotationTray(aura::Window* current_root);
  33. // Hide Projector annotation tray. Virtual for testing.
  34. virtual void HideAnnotationTray();
  35. // Invoked when marker button is pressed. Virtual for testing.
  36. virtual void EnableAnnotatorTool();
  37. // Sets the annotator tool.
  38. virtual void SetAnnotatorTool(const AnnotatorTool& tool);
  39. // Resets and disables the annotator tools and clears the canvas.
  40. void ResetTools();
  41. // Invoked when the canvas has either succeeded or failed to initialize.
  42. void OnCanvasInitialized(bool success);
  43. // Returns if the annotation canvas has been initialized.
  44. bool GetAnnotatorAvailability();
  45. // Toggles the UI of the annotation tray and the marker's enabled state.
  46. void ToggleAnnotationTray();
  47. void OnRecordedWindowChangingRoot(aura::Window* new_root);
  48. bool is_annotator_enabled() { return annotator_enabled_; }
  49. private:
  50. // ProjectorSessionObserver:
  51. void OnProjectorSessionActiveStateChanged(bool active) override;
  52. ProjectorMarkerColor GetMarkerColorForMetrics(SkColor color);
  53. void UpdateTrayEnabledState();
  54. bool annotator_enabled_ = false;
  55. // The current root window in which the video recording is happening.
  56. aura::Window* current_root_ = nullptr;
  57. // True if the canvas is initialized successfully, false if it failed to
  58. // initialize. An absent value indicates that the initialization has not
  59. // completed.
  60. absl::optional<bool> canvas_initialized_state_;
  61. base::ScopedObservation<ProjectorSession, ProjectorSessionObserver>
  62. projector_session_observation_{this};
  63. };
  64. } // namespace ash
  65. #endif // ASH_PROJECTOR_PROJECTOR_UI_CONTROLLER_H_