Skip to content

Commit 3bdc07f

Browse files
committed
Review feedback + align code style with guidelines
1 parent 495eace commit 3bdc07f

File tree

7 files changed

+48
-43
lines changed

7 files changed

+48
-43
lines changed

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

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <optional>
99

10+
#include "flutter/fml/mapping.h"
1011
#include "geometry.h"
1112

1213
namespace flutter {
@@ -17,48 +18,51 @@ using FlutterViewId = int64_t;
1718
// Types of windows.
1819
enum class WindowArchetype {
1920
// Regular top-level window.
20-
regular,
21+
kRegular,
2122
};
2223

2324
// Possible states a window can be in.
2425
enum class WindowState {
2526
// Normal state, neither maximized, nor minimized.
26-
restored,
27+
kRestored,
2728
// Maximized, occupying the full screen but still showing the system UI.
28-
maximized,
29+
kMaximized,
2930
// Minimized and not visible on the screen.
30-
minimized,
31+
kMinimized,
3132
};
3233

33-
// Converts a |flutter::WindowState| to its corresponding string representation.
34+
// Converts a |flutter::WindowState| to the string representation of
35+
// |WindowState| as defined in the framework.
3436
inline std::string WindowStateToString(WindowState state) {
3537
switch (state) {
36-
case WindowState::restored:
38+
case WindowState::kRestored:
3739
return "WindowState.restored";
38-
case WindowState::maximized:
40+
case WindowState::kMaximized:
3941
return "WindowState.maximized";
40-
case WindowState::minimized:
42+
case WindowState::kMinimized:
4143
return "WindowState.minimized";
44+
default:
45+
FML_UNREACHABLE();
4246
}
43-
return {};
4447
}
4548

46-
// Converts a string to a |flutter::WindowState|. Returns std::nullopt if
49+
// Converts the string representation of |WindowState| defined in the framework
50+
// to a |flutter::WindowState|. Returns std::nullopt if the given string is
4751
// invalid.
4852
inline std::optional<WindowState> StringToWindowState(std::string_view str) {
4953
if (str == "WindowState.restored")
50-
return WindowState::restored;
54+
return WindowState::kRestored;
5155
if (str == "WindowState.maximized")
52-
return WindowState::maximized;
56+
return WindowState::kMaximized;
5357
if (str == "WindowState.minimized")
54-
return WindowState::minimized;
58+
return WindowState::kMinimized;
5559
return std::nullopt;
5660
}
5761

5862
// Settings used for creating a Flutter window.
5963
struct WindowCreationSettings {
6064
// Type of the window.
61-
WindowArchetype archetype = WindowArchetype::regular;
65+
WindowArchetype archetype = WindowArchetype::kRegular;
6266
// Requested size of the window's client area, in logical coordinates.
6367
Size size;
6468
// Minimum size of the window's client area, in logical coordinates.
@@ -76,7 +80,7 @@ struct WindowMetadata {
7680
// The ID of the view used for this window, which is unique to each window.
7781
FlutterViewId view_id = 0;
7882
// The type of the window.
79-
WindowArchetype archetype = WindowArchetype::regular;
83+
WindowArchetype archetype = WindowArchetype::kRegular;
8084
// Size of the created window, in logical coordinates.
8185
Size size;
8286
// The ID of the view used by the parent window. If not set, the window is

engine/src/flutter/shell/platform/windows/flutter_host_window.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ std::optional<flutter::Size> GetWindowSizeForClientSize(
146146
UINT const dpi = flutter::GetDpiForHWND(owner_hwnd);
147147
double const scale_factor =
148148
static_cast<double>(dpi) / USER_DEFAULT_SCREEN_DPI;
149-
RECT rect = {};
150-
rect.right = static_cast<LONG>(client_size.width() * scale_factor);
151-
rect.bottom = static_cast<LONG>(client_size.height() * scale_factor);
149+
RECT rect = {
150+
.right = static_cast<LONG>(client_size.width() * scale_factor),
151+
.bottom = static_cast<LONG>(client_size.height() * scale_factor)};
152152

153153
HMODULE const user32_raw = LoadLibraryA("User32.dll");
154154
auto free_user32_module = [](HMODULE module) { FreeLibrary(module); };
@@ -211,7 +211,7 @@ bool IsClassRegistered(LPCWSTR class_name) {
211211
}
212212

213213
// Convert std::string to std::wstring
214-
std::wstring StringToWstring(const std::string& str) {
214+
std::wstring StringToWstring(std::string const& str) {
215215
if (str.empty()) {
216216
return {};
217217
}
@@ -273,7 +273,7 @@ FlutterHostWindow::FlutterHostWindow(FlutterHostWindowController* controller,
273273
DWORD window_style = 0;
274274
DWORD extended_window_style = 0;
275275
switch (archetype_) {
276-
case WindowArchetype::regular:
276+
case WindowArchetype::kRegular:
277277
window_style |= WS_OVERLAPPEDWINDOW;
278278
break;
279279
default:
@@ -395,23 +395,23 @@ FlutterHostWindow::FlutterHostWindow(FlutterHostWindowController* controller,
395395

396396
SetChildContent(view_controller_->view()->GetWindowHandle());
397397

398-
state_ = settings.state.value_or(WindowState::restored);
398+
state_ = settings.state.value_or(WindowState::kRestored);
399399

400400
// TODO(loicsharma): Hide the window until the first frame is rendered.
401401
// Single window apps use the engine's next frame callback to show the
402402
// window. This doesn't work for multi window apps as the engine cannot have
403403
// multiple next frame callbacks. If multiple windows are created, only the
404404
// last one will be shown.
405405
UINT const cmd_show = [&]() {
406-
if (archetype_ == WindowArchetype::regular) {
406+
if (archetype_ == WindowArchetype::kRegular) {
407407
switch (state_) {
408-
case WindowState::restored:
408+
case WindowState::kRestored:
409409
return SW_SHOWNORMAL;
410410
break;
411-
case WindowState::maximized:
411+
case WindowState::kMaximized:
412412
return SW_SHOWMAXIMIZED;
413413
break;
414-
case WindowState::minimized:
414+
case WindowState::kMinimized:
415415
return SW_SHOWMINIMIZED;
416416
break;
417417
default:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class FlutterHostWindow {
7979
std::unique_ptr<FlutterWindowsViewController> view_controller_;
8080

8181
// The window archetype.
82-
WindowArchetype archetype_ = WindowArchetype::regular;
82+
WindowArchetype archetype_ = WindowArchetype::kRegular;
8383

8484
// Indicates if closing this window will quit the application.
8585
bool quit_on_close_ = false;
@@ -97,7 +97,7 @@ class FlutterHostWindow {
9797
std::optional<Size> max_size_;
9898

9999
// The window state.
100-
WindowState state_ = WindowState::restored;
100+
WindowState state_ = WindowState::kRestored;
101101

102102
FML_DISALLOW_COPY_AND_ASSIGN(FlutterHostWindow);
103103
};

engine/src/flutter/shell/platform/windows/flutter_host_window_controller.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,11 @@ LRESULT FlutterHostWindowController::HandleMessage(HWND hwnd,
112112
});
113113
if (it != windows_.end()) {
114114
auto& [view_id, window] = *it;
115-
if (window->archetype_ == WindowArchetype::regular) {
116-
window->state_ = (wparam == SIZE_MAXIMIZED) ? WindowState::maximized
117-
: (wparam == SIZE_MINIMIZED) ? WindowState::minimized
118-
: WindowState::restored;
115+
if (window->archetype_ == WindowArchetype::kRegular) {
116+
window->state_ = (wparam == SIZE_MAXIMIZED) ? WindowState::kMaximized
117+
: (wparam == SIZE_MINIMIZED)
118+
? WindowState::kMinimized
119+
: WindowState::kRestored;
119120
}
120121
SendOnWindowChanged(view_id, GetWindowSize(view_id), std::nullopt);
121122
}

engine/src/flutter/shell/platform/windows/flutter_host_window_controller_unittests.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class FlutterHostWindowControllerTest : public WindowsTest {
6464
TEST_F(FlutterHostWindowControllerTest, CreateRegularWindow) {
6565
// Define parameters for the window to be created.
6666
WindowCreationSettings const settings = {
67-
.archetype = WindowArchetype::regular,
67+
.archetype = WindowArchetype::kRegular,
6868
.size = {800.0, 600.0},
6969
.title = "window",
7070
};
@@ -130,7 +130,7 @@ TEST_F(FlutterHostWindowControllerTest, DestroyWindow) {
130130

131131
// Define parameters for the window to be created.
132132
WindowCreationSettings const settings = {
133-
.archetype = WindowArchetype::regular,
133+
.archetype = WindowArchetype::kRegular,
134134
.size = {800.0, 600.0},
135135
.title = "window",
136136
};

engine/src/flutter/shell/platform/windows/windowing_handler.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ void WindowingHandler::HandleMethodCall(
134134
const std::string& method = method_call.method_name();
135135

136136
if (method == kCreateWindowMethod) {
137-
HandleCreateWindow(WindowArchetype::regular, method_call, *result);
137+
HandleCreateWindow(WindowArchetype::kRegular, method_call, *result);
138138
} else if (method == kDestroyWindowMethod) {
139139
HandleDestroyWindow(method_call, *result);
140140
} else {
@@ -153,8 +153,8 @@ void WindowingHandler::HandleCreateWindow(WindowArchetype archetype,
153153
}
154154

155155
// Helper lambda to check and report invalid window size
156-
auto const hasValidWindowSize = [&result](Size size,
157-
std::string_view key_name) -> bool {
156+
auto const has_valid_window_size =
157+
[&result](Size size, std::string_view key_name) -> bool {
158158
if (size.width() <= 0 || size.height() <= 0) {
159159
result.Error(kInvalidValueError,
160160
"Values for the '" + std::string(key_name) + "' key (" +
@@ -176,24 +176,24 @@ void WindowingHandler::HandleCreateWindow(WindowArchetype archetype,
176176
return;
177177
}
178178
settings.size = {size_list->at(0), size_list->at(1)};
179-
if (!hasValidWindowSize(settings.size, kSizeKey)) {
179+
if (!has_valid_window_size(settings.size, kSizeKey)) {
180180
return;
181181
}
182182

183-
if (archetype == WindowArchetype::regular) {
183+
if (archetype == WindowArchetype::kRegular) {
184184
// Get value for the 'minSize' key (nullable)
185185
if (auto const list = GetListOfValuesForKeyOrSendError<double, 2>(
186186
kMinSizeKey, map, result)) {
187187
settings.min_size = {list->at(0), list->at(1)};
188-
if (!hasValidWindowSize(*settings.min_size, kMinSizeKey)) {
188+
if (!has_valid_window_size(*settings.min_size, kMinSizeKey)) {
189189
return;
190190
}
191191
}
192192
// Get value for the 'maxSize' key (nullable)
193193
if (auto const list = GetListOfValuesForKeyOrSendError<double, 2>(
194194
kMaxSizeKey, map, result)) {
195195
settings.max_size = {list->at(0), list->at(1)};
196-
if (!hasValidWindowSize(*settings.max_size, kMaxSizeKey)) {
196+
if (!has_valid_window_size(*settings.max_size, kMaxSizeKey)) {
197197
return;
198198
}
199199
}
@@ -214,7 +214,7 @@ void WindowingHandler::HandleCreateWindow(WindowArchetype archetype,
214214
WindowMetadata const& data = data_opt.value();
215215
EncodableMap map;
216216

217-
if (archetype == WindowArchetype::regular) {
217+
if (archetype == WindowArchetype::kRegular) {
218218
map.insert({EncodableValue(kViewIdKey), EncodableValue(data.view_id)});
219219
map.insert(
220220
{EncodableValue(kSizeKey),

engine/src/flutter/shell/platform/windows/windowing_handler_unittests.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class WindowingHandlerTest : public WindowsTest {
7979
.WillByDefault([](WindowCreationSettings const& settings) {
8080
return WindowMetadata{
8181
.size = settings.size,
82-
.state = WindowState::restored,
82+
.state = WindowState::kRestored,
8383
};
8484
});
8585
ON_CALL(*mock_controller_, DestroyHostWindow).WillByDefault(Return(true));
@@ -110,7 +110,7 @@ TEST_F(WindowingHandlerTest, HandleCreateRegularWindow) {
110110
WindowingHandler windowing_handler(&messenger, controller());
111111

112112
WindowCreationSettings const settings = {
113-
.archetype = WindowArchetype::regular,
113+
.archetype = WindowArchetype::kRegular,
114114
.size = {800.0, 600.0},
115115
.title = "regular",
116116
};

0 commit comments

Comments
 (0)