Skip to content

Commit 2628829

Browse files
authored
Merge pull request #59 from knopp/knopp-additional-pr-feedback
Knopp additional pr feedback
2 parents 35f84fa + 360e657 commit 2628829

File tree

8 files changed

+84
-96
lines changed

8 files changed

+84
-96
lines changed

engine/src/flutter/shell/platform/common/geometry.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ class BoxConstraints {
9393
biggest.value_or(Size(std::numeric_limits<double>::infinity(),
9494
std::numeric_limits<double>::infinity()))) {}
9595
BoxConstraints(const BoxConstraints& other) = default;
96-
std::optional<Size> biggest() const { return biggest_; }
97-
std::optional<Size> smallest() const { return smallest_; }
96+
Size biggest() const { return biggest_; }
97+
Size smallest() const { return smallest_; }
9898

9999
private:
100100
Size smallest_ = Size(0, 0);

engine/src/flutter/shell/platform/windows/BUILD.gn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ source_set("flutter_windows_source") {
7373
"external_texture_d3d.h",
7474
"external_texture_pixelbuffer.cc",
7575
"external_texture_pixelbuffer.h",
76-
"flutter_host_window.cc",
77-
"flutter_host_window.h",
7876
"flutter_key_map.g.cc",
7977
"flutter_platform_node_delegate_windows.cc",
8078
"flutter_platform_node_delegate_windows.h",
@@ -91,6 +89,8 @@ source_set("flutter_windows_source") {
9189
"flutter_windows_view.h",
9290
"flutter_windows_view_controller.cc",
9391
"flutter_windows_view_controller.h",
92+
"host_window.cc",
93+
"host_window.h",
9494
"keyboard_handler_base.h",
9595
"keyboard_key_channel_handler.cc",
9696
"keyboard_key_channel_handler.h",

engine/src/flutter/shell/platform/windows/flutter_windows_engine.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
#include "flutter/shell/platform/windows/egl/manager.h"
3131
#include "flutter/shell/platform/windows/egl/proc_table.h"
3232
#include "flutter/shell/platform/windows/flutter_desktop_messenger.h"
33-
#include "flutter/shell/platform/windows/flutter_host_window.h"
3433
#include "flutter/shell/platform/windows/flutter_project_bundle.h"
3534
#include "flutter/shell/platform/windows/flutter_windows_texture_registrar.h"
35+
#include "flutter/shell/platform/windows/host_window.h"
3636
#include "flutter/shell/platform/windows/keyboard_handler_base.h"
3737
#include "flutter/shell/platform/windows/keyboard_key_embedder_handler.h"
3838
#include "flutter/shell/platform/windows/platform_handler.h"
@@ -460,7 +460,7 @@ class FlutterWindowsEngine {
460460
// Handlers for keyboard events from Windows.
461461
std::unique_ptr<KeyboardHandlerBase> keyboard_key_handler_;
462462

463-
// The manager that manages the lifecycle of |FlutterHostWindow|s, native
463+
// The manager that manages the lifecycle of |HostWindow|s, native
464464
// Win32 windows hosting a Flutter view in their client area.
465465
std::unique_ptr<WindowManager> window_manager_;
466466

engine/src/flutter/shell/platform/windows/flutter_host_window.cc renamed to engine/src/flutter/shell/platform/windows/host_window.cc

Lines changed: 44 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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.
9998
std::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

215214
namespace 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

engine/src/flutter/shell/platform/windows/flutter_host_window.h renamed to engine/src/flutter/shell/platform/windows/host_window.h

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_FLUTTER_HOST_WINDOW_H_
6-
#define FLUTTER_SHELL_PLATFORM_WINDOWS_FLUTTER_HOST_WINDOW_H_
5+
#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_HOST_WINDOW_H_
6+
#define FLUTTER_SHELL_PLATFORM_WINDOWS_HOST_WINDOW_H_
77

88
#include <windows.h>
99
#include <memory>
@@ -21,45 +21,44 @@ class FlutterWindowsView;
2121
class FlutterWindowsViewController;
2222

2323
// A Win32 window that hosts a |FlutterWindow| in its client area.
24-
class FlutterHostWindow {
24+
class HostWindow {
2525
public:
26-
virtual ~FlutterHostWindow();
26+
virtual ~HostWindow();
2727

2828
// Creates a native Win32 window with a child view confined to its client
2929
// area. |controller| is a pointer to the controller that manages the
30-
// |FlutterHostWindow|. |engine| is a pointer to the engine thaat manages
30+
// |HostWindow|. |engine| is a pointer to the engine thaat manages
3131
// the controller On success, a valid window handle can be retrieved
32-
// via |FlutterHostWindow::GetWindowHandle|. |nullptr| will be returned
32+
// via |HostWindow::GetWindowHandle|. |nullptr| will be returned
3333
// on failure.
34-
static std::unique_ptr<FlutterHostWindow> createRegularWindow(
34+
static std::unique_ptr<HostWindow> CreateRegularWindow(
3535
WindowManager* controller,
3636
FlutterWindowsEngine* engine,
37-
const FlutterWindowSizing& content_size);
37+
const WindowSizing& content_size);
3838

3939
// Returns the instance pointer for |hwnd| or nullptr if invalid.
40-
static FlutterHostWindow* GetThisFromHandle(HWND hwnd);
40+
static HostWindow* GetThisFromHandle(HWND hwnd);
4141

4242
// Returns the backing window handle, or nullptr if the native window is not
4343
// created or has already been destroyed.
4444
HWND GetWindowHandle() const;
4545

4646
// Resizes the window to accommodate a client area of the given
4747
// |size|.
48-
void SetContentSize(const FlutterWindowSizing& size);
48+
void SetContentSize(const WindowSizing& size);
4949

5050
private:
5151
friend WindowManager;
5252

53-
FlutterHostWindow(
54-
WindowManager* controller,
55-
FlutterWindowsEngine* engine,
56-
WindowArchetype archetype,
57-
std::unique_ptr<FlutterWindowsViewController> view_controller,
58-
const BoxConstraints& constraints,
59-
HWND hwnd);
53+
HostWindow(WindowManager* controller,
54+
FlutterWindowsEngine* engine,
55+
WindowArchetype archetype,
56+
std::unique_ptr<FlutterWindowsViewController> view_controller,
57+
const BoxConstraints& constraints,
58+
HWND hwnd);
6059

6160
// Sets the focus to the child view window of |window|.
62-
static void FocusViewOf(FlutterHostWindow* window);
61+
static void FocusViewOf(HostWindow* window);
6362

6463
// OS callback called by message pump. Handles the WM_NCCREATE message which
6564
// is passed when the non-client area is being created and enables automatic
@@ -92,9 +91,9 @@ class FlutterHostWindow {
9291
// The constraints on the window's client area.
9392
BoxConstraints box_constraints_;
9493

95-
FML_DISALLOW_COPY_AND_ASSIGN(FlutterHostWindow);
94+
FML_DISALLOW_COPY_AND_ASSIGN(HostWindow);
9695
};
9796

9897
} // namespace flutter
9998

100-
#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_FLUTTER_HOST_WINDOW_H_
99+
#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_HOST_WINDOW_H_

0 commit comments

Comments
 (0)