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
|
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_DISPLAY_WIN_SCREEN_WIN_HEADLESS_H_
#define UI_DISPLAY_WIN_SCREEN_WIN_HEADLESS_H_
#include <windows.h>
#include <optional>
#include <string_view>
#include <vector>
#include "base/containers/flat_map.h"
#include "ui/display/win/screen_win.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/native_widget_types.h"
namespace headless {
struct HeadlessScreenInfo;
}
namespace display::win {
class DISPLAY_EXPORT ScreenWinHeadless : public ScreenWin {
public:
explicit ScreenWinHeadless(
const std::vector<headless::HeadlessScreenInfo>& screen_infos);
ScreenWinHeadless(const ScreenWinHeadless&) = delete;
ScreenWinHeadless& operator=(const ScreenWinHeadless&) = delete;
~ScreenWinHeadless() override;
// Returns id of the headless display the window |hwnd| is on. See Win32
// MonitorFromWindow() API for the available |default_options|. Returns
// kInvalidDisplayId if |default_options| is MONITOR_DEFAULTTONULL and |hwnd|
// is outside of all screens.
int64_t GetDisplayIdFromWindow(HWND hwnd, DWORD default_options);
// Returns id of the headless display |screen_rect| is on or closest to.
int64_t GetDisplayIdFromScreenRect(const gfx::Rect& screen_rect);
// Returns the result of ::GetSystemMetrics for |metric| scaled to the DPI of
// the headless monitor with the specified display id.
int GetSystemMetricsForDisplayId(int64_t id, int metric);
// Screen:
gfx::Point GetCursorScreenPoint() override;
void SetCursorScreenPointForTesting(const gfx::Point& point) override;
bool IsWindowUnderCursor(gfx::NativeWindow window) override;
gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override;
gfx::NativeWindow GetLocalProcessWindowAtPoint(
const gfx::Point& point,
const std::set<gfx::NativeWindow>& ignore) override;
int GetNumDisplays() const override;
const std::vector<Display>& GetAllDisplays() const override;
Display GetDisplayNearestWindow(gfx::NativeWindow window) const override;
Display GetDisplayNearestPoint(const gfx::Point& point) const override;
Display GetDisplayMatching(const gfx::Rect& match_rect) const override;
Display GetPrimaryDisplay() const override;
gfx::Rect ScreenToDIPRectInWindow(
gfx::NativeWindow window,
const gfx::Rect& screen_rect) const override;
gfx::Rect DIPToScreenRectInWindow(gfx::NativeWindow window,
const gfx::Rect& dip_rect) const override;
bool IsHeadless() const override;
// ScreenWin:
std::optional<MONITORINFOEX> MonitorInfoFromScreenPoint(
const gfx::Point& screen_point) const override;
std::optional<MONITORINFOEX> MonitorInfoFromScreenRect(
const gfx::Rect& screen_rect) const override;
std::optional<MONITORINFOEX> MonitorInfoFromWindow(
HWND hwnd,
DWORD default_options) const override;
int64_t GetDisplayIdFromMonitorInfo(
const MONITORINFOEX& monitor_info) const override;
HWND GetRootWindow(HWND hwnd) const override;
void UpdateAllDisplaysAndNotify() override;
void UpdateAllDisplaysIfPrimaryMonitorChanged() override;
ScreenWinDisplay GetScreenWinDisplayNearestHWND(HWND hwnd) const override;
ScreenWinDisplay GetPrimaryScreenWinDisplay() const override;
ScreenWinDisplay GetScreenWinDisplay(
std::optional<MONITORINFOEX> monitor_info) const override;
// ColorProfileReader::Client:
void OnColorProfilesChanged() override;
std::optional<MONITORINFOEX> GetMONITORINFOFromDisplayIdForTest(
int64_t id) const;
protected:
// These are exposed for \\ui\views.
virtual gfx::NativeWindow GetNativeWindowAtScreenPoint(
const gfx::Point& point,
const std::set<gfx::NativeWindow>& ignore) const;
virtual gfx::Rect GetNativeWindowBoundsInScreen(
gfx::NativeWindow window) const;
virtual gfx::Rect GetHeadlessWindowBounds(
gfx::AcceleratedWidget window) const;
virtual gfx::NativeWindow GetRootWindow(gfx::NativeWindow window) const;
private:
std::vector<internal::DisplayInfo> DisplayInfosFromScreenInfo(
const std::vector<headless::HeadlessScreenInfo>& screen_infos);
Display GetDisplayFromScreenPoint(const gfx::Point& point) const;
Display GetDisplayFromScreenRect(const gfx::Rect& rect) const;
std::optional<MONITORINFOEX> GetMONITORINFOFromDisplayId(int64_t id) const;
// Maps display id to a fake Windows monitor info that correlates to
// a headless display.
base::flat_map<int64_t, MONITORINFOEX> headless_monitor_info_;
gfx::Point cursor_screen_point_;
};
// Returns a ScreenWinHeadless instance. CHECK crashes if it is not active.
DISPLAY_EXPORT ScreenWinHeadless* GetScreenWinHeadless();
namespace internal {
// Exposed for internal::DisplayInfo::ctor check only!
bool VerifyHeadlessDisplayDeviceName(int64_t id,
const MONITORINFOEX& monitor_info);
} // namespace internal
} // namespace display::win
#endif // UI_DISPLAY_WIN_SCREEN_WIN_HEADLESS_H_
|