display_observer.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright (c) 2012 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 UI_DISPLAY_DISPLAY_OBSERVER_H_
  5. #define UI_DISPLAY_DISPLAY_OBSERVER_H_
  6. #include <stdint.h>
  7. #include "base/observer_list_types.h"
  8. #include "ui/display/display_export.h"
  9. namespace display {
  10. class Display;
  11. enum class TabletState;
  12. // Observers for display configuration changes.
  13. class DISPLAY_EXPORT DisplayObserver : public base::CheckedObserver {
  14. public:
  15. enum DisplayMetric {
  16. DISPLAY_METRIC_NONE = 0,
  17. DISPLAY_METRIC_BOUNDS = 1 << 0,
  18. DISPLAY_METRIC_WORK_AREA = 1 << 1,
  19. DISPLAY_METRIC_DEVICE_SCALE_FACTOR = 1 << 2,
  20. DISPLAY_METRIC_ROTATION = 1 << 3,
  21. DISPLAY_METRIC_PRIMARY = 1 << 4,
  22. DISPLAY_METRIC_MIRROR_STATE = 1 << 5,
  23. DISPLAY_METRIC_COLOR_SPACE = 1 << 6,
  24. DISPLAY_METRIC_REFRESH_RATE = 1 << 7,
  25. DISPLAY_METRIC_INTERLACED = 1 << 8,
  26. DISPLAY_METRIC_LABEL = 1 << 9,
  27. };
  28. // This may be called before other methods to signal changes are about to
  29. // happen. Not all classes that support DisplayObserver call this.
  30. virtual void OnWillProcessDisplayChanges();
  31. // Called after OnWillProcessDisplayChanges() to indicate display changes have
  32. // completed. Not all classes that support DisplayObserver call this.
  33. virtual void OnDidProcessDisplayChanges();
  34. // Called when |new_display| has been added.
  35. virtual void OnDisplayAdded(const Display& new_display);
  36. // Called when |old_display| has been removed.
  37. // In Ash, this is called *before* the display has been removed.
  38. // Everywhere else, this is called *after* the display has been removed.
  39. virtual void OnDisplayRemoved(const Display& old_display);
  40. // Called *after* any displays have been removed. Not called per display.
  41. // TODO(enne): resolve the Ash inconsistency for OnDisplayRemoved and
  42. // remove this function.
  43. virtual void OnDidRemoveDisplays();
  44. // Called when the metrics of a display change.
  45. // |changed_metrics| is a bitmask of DisplayMatric types indicating which
  46. // metrics have changed. Eg; if mirroring changes (either from true to false,
  47. // or false to true), than the DISPLAY_METRIC_MIRROR_STATE bit is set in
  48. // changed_metrics.
  49. virtual void OnDisplayMetricsChanged(const Display& display,
  50. uint32_t changed_metrics);
  51. // Called when the (platform-specific) workspace ID changes to
  52. // |new_workspace|.
  53. virtual void OnCurrentWorkspaceChanged(const std::string& new_workspace);
  54. // Called when display changes between conventional and tablet mode.
  55. virtual void OnDisplayTabletStateChanged(TabletState state);
  56. protected:
  57. ~DisplayObserver() override;
  58. };
  59. // Caller must ensure the lifetime of `observer` outlives ScopedDisplayObserver
  60. // and ScopedOptionalDisplayObserver. The "Optional" version does not care
  61. // whether there is a display::Screen::GetScreen() to observe or not and will
  62. // silently noop when there is not. The non-optional ScopedDisplayObserver
  63. // will CHECK that display::Screen::GetScreen() exists on construction to
  64. // receive events from.
  65. class DISPLAY_EXPORT ScopedOptionalDisplayObserver {
  66. public:
  67. explicit ScopedOptionalDisplayObserver(DisplayObserver* observer);
  68. ~ScopedOptionalDisplayObserver();
  69. private:
  70. DisplayObserver* observer_ = nullptr;
  71. };
  72. class DISPLAY_EXPORT ScopedDisplayObserver
  73. : public ScopedOptionalDisplayObserver {
  74. public:
  75. explicit ScopedDisplayObserver(DisplayObserver* observer);
  76. };
  77. } // namespace display
  78. #endif // UI_DISPLAY_DISPLAY_OBSERVER_H_