22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
44
5- #include " flutter/shell/platform/windows/flutter_host_window .h"
5+ #include " flutter/shell/platform/windows/host_window .h"
66
77#include < dwmapi.h>
88
@@ -25,9 +25,8 @@ flutter::Size ClampToVirtualScreen(flutter::Size size) {
2525 std::clamp (size.height (), 0.0 , virtual_screen_height));
2626}
2727
28- void EnableTransparentWindowBackground (
29- HWND hwnd,
30- flutter::WindowsProcTable const & proc_table) {
28+ void EnableTransparentWindowBackground (HWND hwnd,
29+ flutter::WindowsProcTable const & win32) {
3130 enum ACCENT_STATE { ACCENT_DISABLED = 0 };
3231
3332 struct ACCENT_POLICY {
@@ -44,15 +43,15 @@ void EnableTransparentWindowBackground(
4443 flutter::WindowsProcTable::WINDOWCOMPOSITIONATTRIB::WCA_ACCENT_POLICY,
4544 .pvData = &accent,
4645 .cbData = sizeof (accent)};
47- proc_table .SetWindowCompositionAttribute (hwnd, &data);
46+ win32 .SetWindowCompositionAttribute (hwnd, &data);
4847
4948 // Extend the frame into the client area and set the window's system
5049 // backdrop type for visual effects.
5150 MARGINS const margins = {-1 };
52- proc_table .DwmExtendFrameIntoClientArea (hwnd, &margins);
51+ win32 .DwmExtendFrameIntoClientArea (hwnd, &margins);
5352 INT effect_value = 1 ;
54- proc_table .DwmSetWindowAttribute (hwnd, DWMWA_SYSTEMBACKDROP_TYPE,
55- &effect_value, sizeof (BOOL));
53+ win32 .DwmSetWindowAttribute (hwnd, DWMWA_SYSTEMBACKDROP_TYPE, &effect_value ,
54+ sizeof (BOOL));
5655}
5756
5857// Retrieves the calling thread's last-error code message as a string,
@@ -97,7 +96,7 @@ std::string GetLastErrorAsString() {
9796// resulting size includes window borders, non-client areas, and drop shadows.
9897// On error, returns std::nullopt and logs an error message.
9998std::optional<flutter::Size> GetWindowSizeForClientSize (
100- flutter::WindowsProcTable const & proc_table ,
99+ flutter::WindowsProcTable const & win32 ,
101100 flutter::Size const & client_size,
102101 std::optional<flutter::Size> smallest,
103102 std::optional<flutter::Size> biggest,
@@ -111,8 +110,8 @@ std::optional<flutter::Size> GetWindowSizeForClientSize(
111110 .right = static_cast <LONG>(client_size.width () * scale_factor),
112111 .bottom = static_cast <LONG>(client_size.height () * scale_factor)};
113112
114- if (!proc_table .AdjustWindowRectExForDpi (&rect, window_style, FALSE ,
115- extended_window_style, dpi)) {
113+ if (!win32 .AdjustWindowRectExForDpi (&rect, window_style, FALSE ,
114+ extended_window_style, dpi)) {
116115 FML_LOG (ERROR) << " Failed to run AdjustWindowRectExForDpi: "
117116 << GetLastErrorAsString ();
118117 return std::nullopt ;
@@ -214,10 +213,10 @@ void SetChildContent(HWND content, HWND window) {
214213
215214namespace flutter {
216215
217- std::unique_ptr<FlutterHostWindow> FlutterHostWindow::createRegularWindow (
216+ std::unique_ptr<HostWindow> HostWindow::CreateRegularWindow (
218217 WindowManager* window_manager,
219218 FlutterWindowsEngine* engine,
220- const FlutterWindowSizing & content_size) {
219+ const WindowSizing & content_size) {
221220 DWORD window_style = WS_OVERLAPPEDWINDOW;
222221 DWORD extended_window_style = 0 ;
223222 std::optional<Size> smallest = std::nullopt ;
@@ -260,8 +259,6 @@ std::unique_ptr<FlutterHostWindow> FlutterHostWindow::createRegularWindow(
260259 std::unique_ptr<FlutterWindowsViewController> view_controller =
261260 std::make_unique<FlutterWindowsViewController>(nullptr , std::move (view));
262261 FML_CHECK (engine->running ());
263- // Must happen after engine is running.
264- view_controller->view ()->SendInitialBounds ();
265262 // The Windows embedder listens to accessibility updates using the
266263 // view's HWND. The embedder's accessibility features may be stale if
267264 // the app was in headless mode.
@@ -273,7 +270,7 @@ std::unique_ptr<FlutterHostWindow> FlutterHostWindow::createRegularWindow(
273270 WNDCLASSEX window_class = {};
274271 window_class.cbSize = sizeof (WNDCLASSEX);
275272 window_class.style = CS_HREDRAW | CS_VREDRAW;
276- window_class.lpfnWndProc = FlutterHostWindow ::WndProc;
273+ window_class.lpfnWndProc = HostWindow ::WndProc;
277274 window_class.hInstance = GetModuleHandle (nullptr );
278275 window_class.hIcon =
279276 LoadIcon (window_class.hInstance , MAKEINTRESOURCE (idi_app_icon));
@@ -326,12 +323,12 @@ std::unique_ptr<FlutterHostWindow> FlutterHostWindow::createRegularWindow(
326323 // multiple next frame callbacks. If multiple windows are created, only the
327324 // last one will be shown.
328325 ShowWindow (hwnd, SW_SHOWNORMAL);
329- return std::unique_ptr<FlutterHostWindow >(new FlutterHostWindow (
326+ return std::unique_ptr<HostWindow >(new HostWindow (
330327 window_manager, engine, WindowArchetype::kRegular ,
331328 std::move (view_controller), BoxConstraints (smallest, biggest), hwnd));
332329}
333330
334- FlutterHostWindow::FlutterHostWindow (
331+ HostWindow::HostWindow (
335332 WindowManager* window_manager,
336333 FlutterWindowsEngine* engine,
337334 WindowArchetype archetype,
@@ -347,7 +344,7 @@ FlutterHostWindow::FlutterHostWindow(
347344 SetWindowLongPtr (hwnd, GWLP_USERDATA, reinterpret_cast <LONG_PTR>(this ));
348345}
349346
350- FlutterHostWindow ::~FlutterHostWindow () {
347+ HostWindow ::~HostWindow () {
351348 if (view_controller_) {
352349 // Unregister the window class. Fail silently if other windows are still
353350 // using the class, as only the last window can successfully unregister it.
@@ -358,43 +355,42 @@ FlutterHostWindow::~FlutterHostWindow() {
358355 }
359356}
360357
361- FlutterHostWindow* FlutterHostWindow::GetThisFromHandle (HWND hwnd) {
362- return reinterpret_cast <FlutterHostWindow*>(
363- GetWindowLongPtr (hwnd, GWLP_USERDATA));
358+ HostWindow* HostWindow::GetThisFromHandle (HWND hwnd) {
359+ return reinterpret_cast <HostWindow*>(GetWindowLongPtr (hwnd, GWLP_USERDATA));
364360}
365361
366- HWND FlutterHostWindow ::GetWindowHandle () const {
362+ HWND HostWindow ::GetWindowHandle () const {
367363 return window_handle_;
368364}
369365
370- void FlutterHostWindow ::FocusViewOf (FlutterHostWindow * window) {
366+ void HostWindow ::FocusViewOf (HostWindow * window) {
371367 auto child_content = window->view_controller_ ->view ()->GetWindowHandle ();
372368 if (window != nullptr && child_content != nullptr ) {
373369 SetFocus (child_content);
374370 }
375371};
376372
377- LRESULT FlutterHostWindow ::WndProc (HWND hwnd,
378- UINT message,
379- WPARAM wparam,
380- LPARAM lparam) {
373+ LRESULT HostWindow ::WndProc (HWND hwnd,
374+ UINT message,
375+ WPARAM wparam,
376+ LPARAM lparam) {
381377 if (message == WM_NCCREATE) {
382378 auto * const create_struct = reinterpret_cast <CREATESTRUCT*>(lparam);
383379 auto * const windows_proc_table =
384380 static_cast <WindowsProcTable*>(create_struct->lpCreateParams );
385381 windows_proc_table->EnableNonClientDpiScaling (hwnd);
386382 EnableTransparentWindowBackground (hwnd, *windows_proc_table);
387- } else if (FlutterHostWindow * const window = GetThisFromHandle (hwnd)) {
383+ } else if (HostWindow * const window = GetThisFromHandle (hwnd)) {
388384 return window->HandleMessage (hwnd, message, wparam, lparam);
389385 }
390386
391387 return DefWindowProc (hwnd, message, wparam, lparam);
392388}
393389
394- LRESULT FlutterHostWindow ::HandleMessage (HWND hwnd,
395- UINT message,
396- WPARAM wparam,
397- LPARAM lparam) {
390+ LRESULT HostWindow ::HandleMessage (HWND hwnd,
391+ UINT message,
392+ WPARAM wparam,
393+ LPARAM lparam) {
398394 auto result = engine_->window_proc_delegate_manager ()->OnTopLevelWindowProc (
399395 window_handle_, message, wparam, lparam);
400396 if (result) {
@@ -429,26 +425,20 @@ LRESULT FlutterHostWindow::HandleMessage(HWND hwnd,
429425 static_cast <double >(dpi) / USER_DEFAULT_SCREEN_DPI;
430426
431427 MINMAXINFO* info = reinterpret_cast <MINMAXINFO*>(lparam);
432- if (box_constraints_.smallest ()) {
433- Size const min_physical_size = ClampToVirtualScreen (
434- Size (box_constraints_.smallest ()->width () * scale_factor +
435- non_client_width,
436- box_constraints_.smallest ()->height () * scale_factor +
437- non_client_height));
438-
439- info->ptMinTrackSize .x = min_physical_size.width ();
440- info->ptMinTrackSize .y = min_physical_size.height ();
441- }
442- if (box_constraints_.biggest ()) {
443- Size const max_physical_size = ClampToVirtualScreen (
444- Size (box_constraints_.biggest ()->width () * scale_factor +
445- non_client_width,
446- box_constraints_.biggest ()->height () * scale_factor +
447- non_client_height));
448-
449- info->ptMaxTrackSize .x = max_physical_size.width ();
450- info->ptMaxTrackSize .y = max_physical_size.height ();
451- }
428+ Size const min_physical_size = ClampToVirtualScreen (Size (
429+ box_constraints_.smallest ().width () * scale_factor + non_client_width,
430+ box_constraints_.smallest ().height () * scale_factor +
431+ non_client_height));
432+
433+ info->ptMinTrackSize .x = min_physical_size.width ();
434+ info->ptMinTrackSize .y = min_physical_size.height ();
435+ Size const max_physical_size = ClampToVirtualScreen (Size (
436+ box_constraints_.biggest ().width () * scale_factor + non_client_width,
437+ box_constraints_.biggest ().height () * scale_factor +
438+ non_client_height));
439+
440+ info->ptMaxTrackSize .x = max_physical_size.width ();
441+ info->ptMaxTrackSize .y = max_physical_size.height ();
452442 return 0 ;
453443 }
454444
@@ -488,7 +478,7 @@ LRESULT FlutterHostWindow::HandleMessage(HWND hwnd,
488478 return DefWindowProc (hwnd, message, wparam, lparam);
489479}
490480
491- void FlutterHostWindow ::SetContentSize (const FlutterWindowSizing & size) {
481+ void HostWindow ::SetContentSize (const WindowSizing & size) {
492482 WINDOWINFO window_info = {.cbSize = sizeof (WINDOWINFO)};
493483 GetWindowInfo (window_handle_, &window_info);
494484
0 commit comments