-
Notifications
You must be signed in to change notification settings - Fork 6k
Listen to window notifications to update application lifecycle #43558
Changes from all commits
e2f4825
030975b
be44662
8ab87df
baadbb1
4612d90
958fe90
1811b77
8ef5e58
777215d
000ff16
cbea241
5b7249f
db03f83
1d07015
f50d5f4
98b96ab
3b2826c
b457d1e
1bb2a1d
6d8e612
b9b3ae0
8b1fdb2
0e25cfd
df35a6a
bad6302
1623cd9
7c0c0bf
f292962
addc73c
23d93b3
99f25cc
3b3473f
cc76ca4
477f39b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,7 @@ class MockFlutterWindow : public FlutterWindow { | |
| ON_CALL(*this, GetDpiScale()) | ||
| .WillByDefault(Return(this->FlutterWindow::GetDpiScale())); | ||
| } | ||
| virtual ~MockFlutterWindow() {} | ||
| virtual ~MockFlutterWindow() { SetView(nullptr); } | ||
|
|
||
| // Wrapper for GetCurrentDPI() which is a protected method. | ||
| UINT GetDpi() { return GetCurrentDPI(); } | ||
|
|
@@ -229,6 +229,10 @@ TEST(FlutterWindowTest, OnPointerStarSendsDeviceType) { | |
| kDefaultPointerDeviceId, WM_LBUTTONDOWN); | ||
| win32window.OnPointerLeave(10.0, 10.0, kFlutterPointerDeviceKindStylus, | ||
| kDefaultPointerDeviceId); | ||
|
|
||
| // Destruction of win32window sends a HIDE update. In situ, the window is | ||
| // owned by the delegate, and so is destructed first. Not so here. | ||
| win32window.SetView(nullptr); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added because
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From a lifetime perspective, if the delegate is always strictly owned by the window and its lifetime is constrained to (at most) the lifetime of the owning window, then using a unique_ptr seems reasonable. We should do a quick audit of the code to be sure. If not, then I'd add a one-line comment explaining the rationale here as a breadcrumb for future archaeologists.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, it looks to be the other way around. The delegate i.e. |
||
| } | ||
|
|
||
| // Tests that calls to OnScroll in turn calls GetScrollOffsetMultiplier | ||
|
|
@@ -324,5 +328,61 @@ TEST(FlutterWindowTest, AlertNode) { | |
| EXPECT_EQ(role.lVal, ROLE_SYSTEM_ALERT); | ||
| } | ||
|
|
||
| TEST(FlutterWindowTest, LifecycleFocusMessages) { | ||
| MockFlutterWindow win32window; | ||
| ON_CALL(win32window, GetPlatformWindow).WillByDefault([]() { | ||
| return reinterpret_cast<HWND>(1); | ||
| }); | ||
| MockWindowBindingHandlerDelegate delegate; | ||
| win32window.SetView(&delegate); | ||
|
|
||
| WindowStateEvent last_event; | ||
| ON_CALL(delegate, OnWindowStateEvent) | ||
| .WillByDefault([&last_event](HWND hwnd, WindowStateEvent event) { | ||
| last_event = event; | ||
| }); | ||
|
|
||
| win32window.InjectWindowMessage(WM_SIZE, 0, 0); | ||
| EXPECT_EQ(last_event, WindowStateEvent::kHide); | ||
|
|
||
| win32window.InjectWindowMessage(WM_SIZE, 0, MAKEWORD(1, 1)); | ||
| EXPECT_EQ(last_event, WindowStateEvent::kShow); | ||
|
|
||
| win32window.InjectWindowMessage(WM_SETFOCUS, 0, 0); | ||
| EXPECT_EQ(last_event, WindowStateEvent::kFocus); | ||
|
|
||
| win32window.InjectWindowMessage(WM_KILLFOCUS, 0, 0); | ||
| EXPECT_EQ(last_event, WindowStateEvent::kUnfocus); | ||
| } | ||
|
|
||
| TEST(FlutterWindowTest, CachedLifecycleMessage) { | ||
| MockFlutterWindow win32window; | ||
| ON_CALL(win32window, GetPlatformWindow).WillByDefault([]() { | ||
| return reinterpret_cast<HWND>(1); | ||
| }); | ||
|
|
||
| // Restore | ||
| win32window.InjectWindowMessage(WM_SIZE, 0, MAKEWORD(1, 1)); | ||
|
|
||
| // Focus | ||
| win32window.InjectWindowMessage(WM_SETFOCUS, 0, 0); | ||
|
|
||
| MockWindowBindingHandlerDelegate delegate; | ||
| bool focused = false; | ||
| bool restored = false; | ||
| ON_CALL(delegate, OnWindowStateEvent) | ||
| .WillByDefault([&](HWND hwnd, WindowStateEvent event) { | ||
| if (event == WindowStateEvent::kFocus) { | ||
| focused = true; | ||
| } else if (event == WindowStateEvent::kShow) { | ||
| restored = true; | ||
| } | ||
| }); | ||
|
|
||
| win32window.SetView(&delegate); | ||
| EXPECT_TRUE(focused); | ||
| EXPECT_TRUE(restored); | ||
| } | ||
|
|
||
| } // namespace testing | ||
| } // namespace flutter | ||
Uh oh!
There was an error while loading. Please reload this page.