| Flutter Windows Embedder |

windows_proc_table.cc
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 #include "flutter/shell/platform/windows/windows_proc_table.h"
6
7 #include <WinUser.h>
8 #include <dwmapi.h>
9
10 namespace flutter {
11
12 WindowsProcTable::WindowsProcTable() {
13 user32_ = fml::NativeLibrary::Create("user32.dll");
14 get_pointer_type_ =
15 user32_->ResolveFunction<GetPointerType_*>("GetPointerType");
16 get_pointer_info_ =
17 user32_->ResolveFunction<GetPointerInfo_*>("GetPointerInfo");
18 get_pointer_pen_info_ =
19 user32_->ResolveFunction<GetPointerPenInfo_*>("GetPointerPenInfo");
20 enable_non_client_dpi_scaling_ =
21 user32_->ResolveFunction<EnableNonClientDpiScaling_*>(
22 "EnableNonClientDpiScaling");
23 set_window_composition_attribute_ =
24 user32_->ResolveFunction<SetWindowCompositionAttribute_*>(
25 "SetWindowCompositionAttribute");
26 adjust_window_rect_ext_for_dpi_ =
27 user32_->ResolveFunction<AdjustWindowRectExForDpi_*>(
28 "AdjustWindowRectExForDpi");
29 }
30
31 WindowsProcTable::~WindowsProcTable() {
32 user32_ = nullptr;
33 }
34
35 BOOL WindowsProcTable::GetPointerType(UINT32 pointer_id,
36 POINTER_INPUT_TYPE* pointer_type) const {
37 if (!get_pointer_type_.has_value()) {
38 return FALSE;
39 }
40
41 return get_pointer_type_.value()(pointer_id, pointer_type);
42 }
43
44 BOOL WindowsProcTable::GetPointerInfo(UINT32 pointer_id,
45 POINTER_INFO* pointer_info) const {
46 if (!get_pointer_info_.has_value()) {
47 return FALSE;
48 }
49
50 return get_pointer_info_.value()(pointer_id, pointer_info);
51 }
52
53 BOOL WindowsProcTable::GetPointerPenInfo(
54 UINT32 pointer_id,
55 POINTER_PEN_INFO* pointer_pen_info) const {
56 if (!get_pointer_pen_info_.has_value()) {
57 return FALSE;
58 }
59
60 return get_pointer_pen_info_.value()(pointer_id, pointer_pen_info);
61 }
62
63 LRESULT WindowsProcTable::GetThreadPreferredUILanguages(DWORD flags,
64 PULONG count,
65 PZZWSTR languages,
66 PULONG length) const {
67 return ::GetThreadPreferredUILanguages(flags, count, languages, length);
68 }
69
70 bool WindowsProcTable::GetHighContrastEnabled() const {
71 HIGHCONTRAST high_contrast = {.cbSize = sizeof(HIGHCONTRAST)};
72 if (!::SystemParametersInfoW(SPI_GETHIGHCONTRAST, sizeof(HIGHCONTRAST),
73 &high_contrast, 0)) {
74 return false;
75 }
76
77 return high_contrast.dwFlags & HCF_HIGHCONTRASTON;
78 }
79
80 bool WindowsProcTable::DwmIsCompositionEnabled() const {
81 BOOL composition_enabled;
82 if (SUCCEEDED(::DwmIsCompositionEnabled(&composition_enabled))) {
83 return composition_enabled;
84 }
85
86 return true;
87 }
88
89 HRESULT WindowsProcTable::DwmFlush() const {
90 return ::DwmFlush();
91 }
92
93 HCURSOR WindowsProcTable::LoadCursor(HINSTANCE instance,
94 LPCWSTR cursor_name) const {
95 return ::LoadCursorW(instance, cursor_name);
96 }
97
98 HCURSOR WindowsProcTable::SetCursor(HCURSOR cursor) const {
99 return ::SetCursor(cursor);
100 }
101
102 BOOL WindowsProcTable::EnableNonClientDpiScaling(HWND hwnd) const {
103 if (!enable_non_client_dpi_scaling_.has_value()) {
104 return FALSE;
105 }
106
107 return enable_non_client_dpi_scaling_.value()(hwnd);
108 }
109
110 BOOL WindowsProcTable::SetWindowCompositionAttribute(
111 HWND hwnd,
112 WINDOWCOMPOSITIONATTRIBDATA* data) const {
113 if (!set_window_composition_attribute_.has_value()) {
114 return FALSE;
115 }
116
117 return set_window_composition_attribute_.value()(hwnd, data);
118 }
119
120 HRESULT WindowsProcTable::DwmExtendFrameIntoClientArea(
121 HWND hwnd,
122 const MARGINS* pMarInset) const {
123 return ::DwmExtendFrameIntoClientArea(hwnd, pMarInset);
124 }
125
126 HRESULT WindowsProcTable::DwmSetWindowAttribute(HWND hwnd,
127 DWORD dwAttribute,
128 LPCVOID pvAttribute,
129 DWORD cbAttribute) const {
130 return ::DwmSetWindowAttribute(hwnd, dwAttribute, pvAttribute, cbAttribute);
131 }
132
133 BOOL WindowsProcTable::AdjustWindowRectExForDpi(LPRECT lpRect,
134 DWORD dwStyle,
135 BOOL bMenu,
136 DWORD dwExStyle,
137 UINT dpi) const {
138 if (!adjust_window_rect_ext_for_dpi_.has_value()) {
139 return FALSE;
140 }
141
142 return adjust_window_rect_ext_for_dpi_.value()(lpRect, dwStyle, bMenu,
143 dwExStyle, dpi);
144 }
145
146 int WindowsProcTable::GetSystemMetrics(int nIndex) const {
147 return ::GetSystemMetrics(nIndex);
148 }
149
150 BOOL WindowsProcTable::EnumDisplayDevices(LPCWSTR lpDevice,
151 DWORD iDevNum,
152 PDISPLAY_DEVICE lpDisplayDevice,
153 DWORD dwFlags) const {
154 return ::EnumDisplayDevices(lpDevice, iDevNum, lpDisplayDevice, dwFlags);
155 }
156
157 BOOL WindowsProcTable::EnumDisplaySettings(LPCWSTR lpszDeviceName,
158 DWORD iModeNum,
159 DEVMODEW* lpDevMode) const {
160 return ::EnumDisplaySettingsW(lpszDeviceName, iModeNum, lpDevMode);
161 }
162
163 BOOL WindowsProcTable::GetMonitorInfo(HMONITOR hMonitor,
164 LPMONITORINFO lpmi) const {
165 return ::GetMonitorInfoW(hMonitor, lpmi);
166 }
167
168 BOOL WindowsProcTable::EnumDisplayMonitors(HDC hdc,
169 LPCRECT lprcClip,
170 MONITORENUMPROC lpfnEnum,
171 LPARAM dwData) const {
172 return ::EnumDisplayMonitors(hdc, lprcClip, lpfnEnum, dwData);
173 }
174
175 } // namespace flutter
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
Definition: accessibility_bridge_windows.cc:11
flutter::WindowsProcTable::WINDOWCOMPOSITIONATTRIBDATA
Definition: windows_proc_table.h:22
windows_proc_table.h