| 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 // Get the preferred languages for the thread, and optionally the process,
39 // and system, in that order, depending on the flags.
40 //
41 // See:
42 // https://learn.microsoft.com/windows/win32/api/winnls/nf-winnls-getthreadpreferreduilanguages
43 virtual LRESULT GetThreadPreferredUILanguages(DWORD flags,
44 PULONG count,
45 PZZWSTR languages,
46 PULONG length) const;
47
48 // Get whether high contrast is enabled.
49 //
50 // Available on Windows 8 and newer, otherwise returns false.
51 //
52 // See:
53 // https://learn.microsoft.com/windows/win32/winauto/high-contrast-parameter
54 virtual bool GetHighContrastEnabled() const;
55
56 // Get whether the system compositor, DWM, is enabled.
57 //
58 // See:
59 // https://learn.microsoft.com/windows/win32/api/dwmapi/nf-dwmapi-dwmiscompositionenabled
60 virtual bool DwmIsCompositionEnabled() const;
61
62 // Issues a flush call that blocks the caller until all of the outstanding
63 // surface updates have been made.
64 //
65 // See:
66 // https://learn.microsoft.com/windows/win32/api/dwmapi/nf-dwmapi-dwmflush
67 virtual HRESULT DwmFlush() const;
68
69 // Loads the specified cursor resource from the executable (.exe) file
70 // associated with an application instance.
71 //
72 // See:
73 // https://learn.microsoft.com/windows/win32/api/winuser/nf-winuser-loadcursorw
74 virtual HCURSOR LoadCursor(HINSTANCE instance, LPCWSTR cursor_name) const;
75
76 // Sets the cursor shape.
77 //
78 // See:
79 // https://learn.microsoft.com/windows/win32/api/winuser/nf-winuser-setcursor
80 virtual HCURSOR SetCursor(HCURSOR cursor) const;
81
82 // Enables automatic display scaling of the non-client area portions of the
83 // specified top-level window.
84 //
85 // See:
86 // https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-enablenonclientdpiscaling
87 virtual BOOL EnableNonClientDpiScaling(HWND hwnd) const;
88
89 // Sets the current value of a specified Desktop Window Manager (DWM)
90 // attribute applied to a window.
91 //
92 // See:
93 // https://learn.microsoft.com/en-us/windows/win32/dwm/setwindowcompositionattribute
94 virtual BOOL SetWindowCompositionAttribute(
95 HWND hwnd,
96 WINDOWCOMPOSITIONATTRIBDATA* data) const;
97
98 // Extends the window frame into the client area.
99 //
100 // See:
101 // https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/nf-dwmapi-dwmextendframeintoclientarea
102 virtual HRESULT DwmExtendFrameIntoClientArea(HWND hwnd,
103 const MARGINS* pMarInset) const;
104
105 // Sets the value of Desktop Window Manager (DWM) non-client rendering
106 // attributes for a window.
107 //
108 // See:
109 // https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/nf-dwmapi-dwmsetwindowattribute
110 virtual HRESULT DwmSetWindowAttribute(HWND hwnd,
111 DWORD dwAttribute,
112 LPCVOID pvAttribute,
113 DWORD cbAttribute) const;
114
115 // Calculates the required size of the window rectangle, based on the desired
116 // size of the client rectangle and the provided DPI.
117 //
118 // See:
119 // https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-adjustwindowrectexfordpi
120 virtual BOOL AdjustWindowRectExForDpi(LPRECT lpRect,
121 DWORD dwStyle,
122 BOOL bMenu,
123 DWORD dwExStyle,
124 UINT dpi) const;
125
126 private:
127 using GetPointerType_ = BOOL __stdcall(UINT32 pointerId,
128 POINTER_INPUT_TYPE* pointerType);
129 using EnableNonClientDpiScaling_ = BOOL __stdcall(HWND hwnd);
130 using SetWindowCompositionAttribute_ =
131 BOOL __stdcall(HWND, WINDOWCOMPOSITIONATTRIBDATA*);
132 using AdjustWindowRectExForDpi_ = BOOL __stdcall(LPRECT lpRect,
133 DWORD dwStyle,
134 BOOL bMenu,
135 DWORD dwExStyle,
136 UINT dpi);
137
138 // The User32.dll library, used to resolve functions at runtime.
139 fml::RefPtr<fml::NativeLibrary> user32_;
140
141 std::optional<GetPointerType_*> get_pointer_type_;
142 std::optional<EnableNonClientDpiScaling_*> enable_non_client_dpi_scaling_;
143 std::optional<SetWindowCompositionAttribute_*>
144 set_window_composition_attribute_;
145 std::optional<AdjustWindowRectExForDpi_*> adjust_window_rect_ext_for_dpi_;
146
147 FML_DISALLOW_COPY_AND_ASSIGN(WindowsProcTable);
148 };
149
150 } // namespace flutter
151
152 #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:66
flutter::WindowsProcTable::GetPointerType
virtual BOOL GetPointerType(UINT32 pointer_id, POINTER_INPUT_TYPE *pointer_type) const
Definition: windows_proc_table.cc:31
flutter::WindowsProcTable::LoadCursor
virtual HCURSOR LoadCursor(HINSTANCE instance, LPCWSTR cursor_name) const
Definition: windows_proc_table.cc:70
flutter::WindowsProcTable::SetCursor
virtual HCURSOR SetCursor(HCURSOR cursor) const
Definition: windows_proc_table.cc:75
flutter::WindowsProcTable::GetHighContrastEnabled
virtual bool GetHighContrastEnabled() const
Definition: windows_proc_table.cc:47
flutter::WindowsProcTable::~WindowsProcTable
virtual ~WindowsProcTable()
Definition: windows_proc_table.cc:27
flutter::WindowsProcTable::WindowsProcTable
WindowsProcTable()
Definition: windows_proc_table.cc:12
flutter::WindowsProcTable::AdjustWindowRectExForDpi
virtual BOOL AdjustWindowRectExForDpi(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle, UINT dpi) const
Definition: windows_proc_table.cc:110
flutter::WindowsProcTable::EnableNonClientDpiScaling
virtual BOOL EnableNonClientDpiScaling(HWND hwnd) const
Definition: windows_proc_table.cc:79
flutter::WindowsProcTable::DwmExtendFrameIntoClientArea
virtual HRESULT DwmExtendFrameIntoClientArea(HWND hwnd, const MARGINS *pMarInset) const
Definition: windows_proc_table.cc:97
flutter::WindowsProcTable::DwmIsCompositionEnabled
virtual bool DwmIsCompositionEnabled() const
Definition: windows_proc_table.cc:57
flutter::WindowsProcTable::DwmSetWindowAttribute
virtual HRESULT DwmSetWindowAttribute(HWND hwnd, DWORD dwAttribute, LPCVOID pvAttribute, DWORD cbAttribute) const
Definition: windows_proc_table.cc:103
flutter::WindowsProcTable::GetThreadPreferredUILanguages
virtual LRESULT GetThreadPreferredUILanguages(DWORD flags, PULONG count, PZZWSTR languages, PULONG length) const
Definition: windows_proc_table.cc:40
flutter::WindowsProcTable::SetWindowCompositionAttribute
virtual BOOL SetWindowCompositionAttribute(HWND hwnd, WINDOWCOMPOSITIONATTRIBDATA *data) const
Definition: windows_proc_table.cc:87
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