| Flutter Windows Embedder |

windows_proc_table.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter 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
5 #ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_WINDOWS_PROC_TABLE_H_
6 #define FLUTTER_SHELL_PLATFORM_WINDOWS_WINDOWS_PROC_TABLE_H_
7
8 #include <dwmapi.h>
9 #include <optional>
10
11 #include "flutter/fml/macros.h"
12 #include "flutter/fml/native_library.h"
13
14 namespace flutter {
15
16 // Lookup table for Windows APIs that aren't available on all versions of
17 // Windows, or for mocking Windows API calls.
18 class WindowsProcTable {
19 public:
20 enum WINDOWCOMPOSITIONATTRIB { WCA_ACCENT_POLICY = 19 };
21
22 struct WINDOWCOMPOSITIONATTRIBDATA {
23 WINDOWCOMPOSITIONATTRIB Attrib;
24 PVOID pvData;
25 SIZE_T cbData;
26 };
27
28 WindowsProcTable();
29 virtual ~WindowsProcTable();
30
31 // Retrieves the pointer type for a specified pointer.
32 //
33 // Used to react differently to touch or pen inputs. Returns false on failure.
34 // Available on Windows 8 and newer, otherwise returns false.
35 virtual BOOL GetPointerType(UINT32 pointer_id,
36 POINTER_INPUT_TYPE* pointer_type) const;
37
38 // Retrieves the pointer info for a specified pointer.
39 //
40 // Used to react differently to touch or pen inputs. Returns false on failure.
41 // Available on Windows 8 and newer, otherwise returns false.
42 virtual BOOL GetPointerInfo(UINT32 pointer_id,
43 POINTER_INFO* pointer_info) const;
44 // Retrieves the pointer info for a specified pointer.
45 //
46 // Used to retrieve information about the pen being used. Returns false on
47 // failure. Available on Windows 8 and newer, otherwise returns false.
48 virtual BOOL GetPointerPenInfo(UINT32 pointer_id,
49 POINTER_PEN_INFO* pointer_pen_info) const;
50 // Get the preferred languages for the thread, and optionally the process,
51 // and system, in that order, depending on the flags.
52 //
53 // See:
54 // https://learn.microsoft.com/windows/win32/api/winnls/nf-winnls-getthreadpreferreduilanguages
55 virtual LRESULT GetThreadPreferredUILanguages(DWORD flags,
56 PULONG count,
57 PZZWSTR languages,
58 PULONG length) const;
59
60 // Get whether high contrast is enabled.
61 //
62 // Available on Windows 8 and newer, otherwise returns false.
63 //
64 // See:
65 // https://learn.microsoft.com/windows/win32/winauto/high-contrast-parameter
66 virtual bool GetHighContrastEnabled() const;
67
68 // Get whether the system compositor, DWM, is enabled.
69 //
70 // See:
71 // https://learn.microsoft.com/windows/win32/api/dwmapi/nf-dwmapi-dwmiscompositionenabled
72 virtual bool DwmIsCompositionEnabled() const;
73
74 // Issues a flush call that blocks the caller until all of the outstanding
75 // surface updates have been made.
76 //
77 // See:
78 // https://learn.microsoft.com/windows/win32/api/dwmapi/nf-dwmapi-dwmflush
79 virtual HRESULT DwmFlush() const;
80
81 // Loads the specified cursor resource from the executable (.exe) file
82 // associated with an application instance.
83 //
84 // See:
85 // https://learn.microsoft.com/windows/win32/api/winuser/nf-winuser-loadcursorw
86 virtual HCURSOR LoadCursor(HINSTANCE instance, LPCWSTR cursor_name) const;
87
88 // Sets the cursor shape.
89 //
90 // See:
91 // https://learn.microsoft.com/windows/win32/api/winuser/nf-winuser-setcursor
92 virtual HCURSOR SetCursor(HCURSOR cursor) const;
93
94 // Enables automatic display scaling of the non-client area portions of the
95 // specified top-level window.
96 //
97 // See:
98 // https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-enablenonclientdpiscaling
99 virtual BOOL EnableNonClientDpiScaling(HWND hwnd) const;
100
101 // Sets the current value of a specified Desktop Window Manager (DWM)
102 // attribute applied to a window.
103 //
104 // See:
105 // https://learn.microsoft.com/en-us/windows/win32/dwm/setwindowcompositionattribute
106 virtual BOOL SetWindowCompositionAttribute(
107 HWND hwnd,
108 WINDOWCOMPOSITIONATTRIBDATA* data) const;
109
110 // Extends the window frame into the client area.
111 //
112 // See:
113 // https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/nf-dwmapi-dwmextendframeintoclientarea
114 virtual HRESULT DwmExtendFrameIntoClientArea(HWND hwnd,
115 const MARGINS* pMarInset) const;
116
117 // Sets the value of Desktop Window Manager (DWM) non-client rendering
118 // attributes for a window.
119 //
120 // See:
121 // https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/nf-dwmapi-dwmsetwindowattribute
122 virtual HRESULT DwmSetWindowAttribute(HWND hwnd,
123 DWORD dwAttribute,
124 LPCVOID pvAttribute,
125 DWORD cbAttribute) const;
126
127 // Calculates the required size of the window rectangle, based on the desired
128 // size of the client rectangle and the provided DPI.
129 //
130 // See:
131 // https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-adjustwindowrectexfordpi
132 virtual BOOL AdjustWindowRectExForDpi(LPRECT lpRect,
133 DWORD dwStyle,
134 BOOL bMenu,
135 DWORD dwExStyle,
136 UINT dpi) const;
137
138 // Get the system metrics.
139 //
140 // See:
141 // https://learn.microsoft.com/windows/win32/api/winuser/nf-winuser-getsystemmetrics
142 virtual int GetSystemMetrics(int nIndex) const;
143
144 // Enumerate display devices.
145 //
146 // See:
147 // https://learn.microsoft.com/windows/win32/api/winuser/nf-winuser-enumdisplaydevicesw
148 virtual BOOL EnumDisplayDevices(LPCWSTR lpDevice,
149 DWORD iDevNum,
150 PDISPLAY_DEVICE lpDisplayDevice,
151 DWORD dwFlags) const;
152
153 // Enumerate display settings.
154 //
155 // See:
156 // https://learn.microsoft.com/windows/win32/api/winuser/nf-winuser-enumdisplaysettingsw
157 virtual BOOL EnumDisplaySettings(LPCWSTR lpszDeviceName,
158 DWORD iModeNum,
159 DEVMODEW* lpDevMode) const;
160
161 // Get monitor info.
162 //
163 // See:
164 // https://learn.microsoft.com/windows/win32/api/winuser/nf-winuser-getmonitorinfow
165 virtual BOOL GetMonitorInfo(HMONITOR hMonitor, LPMONITORINFO lpmi) const;
166
167 // Enumerate display monitors.
168 //
169 // See:
170 // https://learn.microsoft.com/windows/win32/api/winuser/nf-winuser-enumdisplaymonitors
171 virtual BOOL EnumDisplayMonitors(HDC hdc,
172 LPCRECT lprcClip,
173 MONITORENUMPROC lpfnEnum,
174 LPARAM dwData) const;
175
176 private:
177 using GetPointerType_ = BOOL __stdcall(UINT32 pointerId,
178 POINTER_INPUT_TYPE* pointerType);
179 using GetPointerInfo_ = BOOL __stdcall(UINT32 pointerId,
180 POINTER_INFO* pointerInfo);
181 using GetPointerPenInfo_ = BOOL __stdcall(UINT32 pointerId,
182 POINTER_PEN_INFO* penInfo);
183 using EnableNonClientDpiScaling_ = BOOL __stdcall(HWND hwnd);
184 using SetWindowCompositionAttribute_ =
185 BOOL __stdcall(HWND, WINDOWCOMPOSITIONATTRIBDATA*);
186 using AdjustWindowRectExForDpi_ = BOOL __stdcall(LPRECT lpRect,
187 DWORD dwStyle,
188 BOOL bMenu,
189 DWORD dwExStyle,
190 UINT dpi);
191
192 // The User32.dll library, used to resolve functions at runtime.
193 fml::RefPtr<fml::NativeLibrary> user32_;
194
195 std::optional<GetPointerType_*> get_pointer_type_;
196 std::optional<GetPointerInfo_*> get_pointer_info_;
197 std::optional<GetPointerPenInfo_*> get_pointer_pen_info_;
198 std::optional<EnableNonClientDpiScaling_*> enable_non_client_dpi_scaling_;
199 std::optional<SetWindowCompositionAttribute_*>
200 set_window_composition_attribute_;
201 std::optional<AdjustWindowRectExForDpi_*> adjust_window_rect_ext_for_dpi_;
202
203 FML_DISALLOW_COPY_AND_ASSIGN(WindowsProcTable);
204 };
205
206 } // namespace flutter
207
208 #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_WINDOWS_PROC_TABLE_H_
flutter::WindowsProcTable
Definition: windows_proc_table.h:18
flutter::WindowsProcTable::DwmFlush
virtual HRESULT DwmFlush() const
Definition: windows_proc_table.cc:89
flutter::WindowsProcTable::GetPointerInfo
virtual BOOL GetPointerInfo(UINT32 pointer_id, POINTER_INFO *pointer_info) const
Definition: windows_proc_table.cc:44
flutter::WindowsProcTable::GetPointerPenInfo
virtual BOOL GetPointerPenInfo(UINT32 pointer_id, POINTER_PEN_INFO *pointer_pen_info) const
Definition: windows_proc_table.cc:53
flutter::WindowsProcTable::GetPointerType
virtual BOOL GetPointerType(UINT32 pointer_id, POINTER_INPUT_TYPE *pointer_type) const
Definition: windows_proc_table.cc:35
flutter::WindowsProcTable::LoadCursor
virtual HCURSOR LoadCursor(HINSTANCE instance, LPCWSTR cursor_name) const
Definition: windows_proc_table.cc:93
flutter::WindowsProcTable::GetSystemMetrics
virtual int GetSystemMetrics(int nIndex) const
Definition: windows_proc_table.cc:146
flutter::WindowsProcTable::SetCursor
virtual HCURSOR SetCursor(HCURSOR cursor) const
Definition: windows_proc_table.cc:98
flutter::WindowsProcTable::GetHighContrastEnabled
virtual bool GetHighContrastEnabled() const
Definition: windows_proc_table.cc:70
flutter::WindowsProcTable::~WindowsProcTable
virtual ~WindowsProcTable()
Definition: windows_proc_table.cc:31
flutter::WindowsProcTable::WindowsProcTable
WindowsProcTable()
Definition: windows_proc_table.cc:12
flutter::WindowsProcTable::EnumDisplayDevices
virtual BOOL EnumDisplayDevices(LPCWSTR lpDevice, DWORD iDevNum, PDISPLAY_DEVICE lpDisplayDevice, DWORD dwFlags) const
Definition: windows_proc_table.cc:150
flutter::WindowsProcTable::AdjustWindowRectExForDpi
virtual BOOL AdjustWindowRectExForDpi(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle, UINT dpi) const
Definition: windows_proc_table.cc:133
flutter::WindowsProcTable::EnableNonClientDpiScaling
virtual BOOL EnableNonClientDpiScaling(HWND hwnd) const
Definition: windows_proc_table.cc:102
flutter::WindowsProcTable::DwmExtendFrameIntoClientArea
virtual HRESULT DwmExtendFrameIntoClientArea(HWND hwnd, const MARGINS *pMarInset) const
Definition: windows_proc_table.cc:120
flutter::WindowsProcTable::DwmIsCompositionEnabled
virtual bool DwmIsCompositionEnabled() const
Definition: windows_proc_table.cc:80
flutter::WindowsProcTable::EnumDisplaySettings
virtual BOOL EnumDisplaySettings(LPCWSTR lpszDeviceName, DWORD iModeNum, DEVMODEW *lpDevMode) const
Definition: windows_proc_table.cc:157
flutter::WindowsProcTable::DwmSetWindowAttribute
virtual HRESULT DwmSetWindowAttribute(HWND hwnd, DWORD dwAttribute, LPCVOID pvAttribute, DWORD cbAttribute) const
Definition: windows_proc_table.cc:126
flutter::WindowsProcTable::GetMonitorInfo
virtual BOOL GetMonitorInfo(HMONITOR hMonitor, LPMONITORINFO lpmi) const
Definition: windows_proc_table.cc:163
flutter::WindowsProcTable::EnumDisplayMonitors
virtual BOOL EnumDisplayMonitors(HDC hdc, LPCRECT lprcClip, MONITORENUMPROC lpfnEnum, LPARAM dwData) const
Definition: windows_proc_table.cc:168
flutter::WindowsProcTable::GetThreadPreferredUILanguages
virtual LRESULT GetThreadPreferredUILanguages(DWORD flags, PULONG count, PZZWSTR languages, PULONG length) const
Definition: windows_proc_table.cc:63
flutter::WindowsProcTable::SetWindowCompositionAttribute
virtual BOOL SetWindowCompositionAttribute(HWND hwnd, WINDOWCOMPOSITIONATTRIBDATA *data) const
Definition: windows_proc_table.cc:110
flutter::WindowsProcTable::WINDOWCOMPOSITIONATTRIB
WINDOWCOMPOSITIONATTRIB
Definition: windows_proc_table.h:20
flutter::WindowsProcTable::WCA_ACCENT_POLICY
@ WCA_ACCENT_POLICY
Definition: windows_proc_table.h:20
flutter
Definition: accessibility_bridge_windows.cc:11
flutter::WindowsProcTable::WINDOWCOMPOSITIONATTRIBDATA
Definition: windows_proc_table.h:22
flutter::WindowsProcTable::WINDOWCOMPOSITIONATTRIBDATA::Attrib
WINDOWCOMPOSITIONATTRIB Attrib
Definition: windows_proc_table.h:23
flutter::WindowsProcTable::WINDOWCOMPOSITIONATTRIBDATA::cbData
SIZE_T cbData
Definition: windows_proc_table.h:25
flutter::WindowsProcTable::WINDOWCOMPOSITIONATTRIBDATA::pvData
PVOID pvData
Definition: windows_proc_table.h:24