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