File: display_info_provider.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (152 lines) | stat: -rw-r--r-- 6,065 bytes parent folder | download | duplicates (5)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef EXTENSIONS_BROWSER_API_SYSTEM_DISPLAY_DISPLAY_INFO_PROVIDER_H_
#define EXTENSIONS_BROWSER_API_SYSTEM_DISPLAY_DISPLAY_INFO_PROVIDER_H_

#include <stdint.h>

#include <optional>
#include <string>
#include <vector>

#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "extensions/common/api/system_display.h"
#include "ui/display/display_observer.h"

namespace display {
class Display;
class Screen;
}

namespace extensions {

// Implementation class for chrome.system.display extension API
// (system_display_api.cc). Callbacks that provide an error string use an
// empty string for success.
class DisplayInfoProvider : public display::DisplayObserver {
 public:
  using DisplayUnitInfoList = std::vector<api::system_display::DisplayUnitInfo>;
  using DisplayLayoutList = std::vector<api::system_display::DisplayLayout>;
  using ErrorCallback = base::OnceCallback<void(std::optional<std::string>)>;

  DisplayInfoProvider(const DisplayInfoProvider&) = delete;
  DisplayInfoProvider& operator=(const DisplayInfoProvider&) = delete;

  ~DisplayInfoProvider() override;

  // Returns a pointer to DisplayInfoProvider or null if Create() or
  // InitializeForTesting() have not been called yet.
  static DisplayInfoProvider* Get();

  // Called by tests to provide a test implementation for the extension API.
  static void InitializeForTesting(DisplayInfoProvider* display_info_provider);

  // Called by tests to reset the global instance.
  static void ResetForTesting();

  // Updates display `display_id` with `properties`. If the operation fails,
  // `callback` will be called with a non empty error string and no display
  // properties will be changed.
  virtual void SetDisplayProperties(
      const std::string& display_id,
      const api::system_display::DisplayProperties& properties,
      ErrorCallback callback);

  // Updates the display layout with `layouts`. If the operation fails,
  // `callback` will be called with a non empty error string and the layout will
  // not be changed.
  virtual void SetDisplayLayout(const DisplayLayoutList& layouts,
                                ErrorCallback callback);

  // Enables the unified desktop feature.
  virtual void EnableUnifiedDesktop(bool enable);

  // Requests a list of information for all displays. If `single_unified` is
  // true, when in unified mode a single display will be returned representing
  // the single unified desktop.
  virtual void GetAllDisplaysInfo(
      bool single_unified,
      base::OnceCallback<void(DisplayUnitInfoList result)> callback);

  // Gets display layout information.
  virtual void GetDisplayLayout(
      base::OnceCallback<void(DisplayLayoutList result)> callback);

  // Start/Stop observing display state change
  virtual void StartObserving();
  virtual void StopObserving();

  // Implements overscan calibration methods. See system_display.idl. These
  // return false if `id` is invalid.
  virtual bool OverscanCalibrationStart(const std::string& id);
  virtual bool OverscanCalibrationAdjust(
      const std::string& id,
      const api::system_display::Insets& delta);
  virtual bool OverscanCalibrationReset(const std::string& id);
  virtual bool OverscanCalibrationComplete(const std::string& id);

  // Shows the native touch calibration UI. Returns false if native touch
  // calibration cannot be started. Otherwise `callback` will be run when the
  // calibration has completed.
  virtual void ShowNativeTouchCalibration(const std::string& id,
                                          ErrorCallback callback);

  // These methods implement custom touch calibration. They will return false
  // if `id` is invalid or if the operation is invalid.
  virtual bool StartCustomTouchCalibration(const std::string& id);
  virtual bool CompleteCustomTouchCalibration(
      const api::system_display::TouchCalibrationPairQuad& pairs,
      const api::system_display::Bounds& bounds);
  virtual bool ClearTouchCalibration(const std::string& id);

  // Sets the display mode to the specified mirror mode. See system_display.idl.
  // `info`: Mirror mode properties to apply.
  virtual void SetMirrorMode(const api::system_display::MirrorModeInfo& info,
                             ErrorCallback callback);

 protected:
  explicit DisplayInfoProvider(display::Screen* screen);

  // Trigger OnDisplayChangedEvent
  virtual void DispatchOnDisplayChangedEvent() = 0;

  // Convert a vector of Displays into a DisplayUnitInfoList. This function
  // needs to be thread-safe since it is called via PostTask.
  DisplayUnitInfoList GetAllDisplaysInfoList(
      const std::vector<display::Display>& displays,
      int64_t primary_id) const;

  // Create a DisplayUnitInfo from a display::Display for implementations of
  // GetAllDisplaysInfo()
  static api::system_display::DisplayUnitInfo CreateDisplayUnitInfo(
      const display::Display& display,
      int64_t primary_display_id);

 private:
  // Update the content of each unit in `units` obtained from the corresponding
  // display in `displays` using a platform specific method.
  // This must be safe to call off the ui thread.
  virtual void UpdateDisplayUnitInfoForPlatform(
      const std::vector<display::Display>& displays,
      DisplayUnitInfoList& units) const;

  // DisplayObserver
  void OnDisplayAdded(const display::Display& new_display) override;
  void OnDisplaysRemoved(const display::Displays& removed_displays) override;
  void OnDisplayMetricsChanged(const display::Display& display,
                               uint32_t metrics) override;

  raw_ptr<display::Screen> provided_screen_ = nullptr;

  std::optional<display::ScopedDisplayObserver> display_observer_;

  // Created on demand and will leak when the process exits.
  static DisplayInfoProvider* g_display_info_provider;
};

}  // namespace extensions

#endif  // EXTENSIONS_BROWSER_API_SYSTEM_DISPLAY_DISPLAY_INFO_PROVIDER_H_