Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 7e59dd3

Browse files
Address comments
1 parent 4ab6c8b commit 7e59dd3

File tree

4 files changed

+29
-17
lines changed

4 files changed

+29
-17
lines changed

shell/platform/windows/win32_flutter_window.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ void Win32FlutterWindow::OnPointerUp(double x, double y) {
128128
void Win32FlutterWindow::OnPointerLeave() {
129129
if (process_events_) {
130130
SendPointerLeave();
131+
// Once the tracked event is received, the TrackMouseEvent function
132+
// resets. Set to false to make sure it's called once mouse movement is
133+
// detected again.
134+
tracking_mouse_leave_ = false;
131135
}
132136
}
133137

shell/platform/windows/win32_flutter_window.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "flutter/shell/platform/windows/win32_window.h"
2323
#include "flutter/shell/platform/windows/window_state.h"
2424

25+
2526
namespace flutter {
2627

2728
// A win32 flutter child window used as implementatin for flutter view. In the
@@ -106,6 +107,10 @@ class Win32FlutterWindow : public Win32Window {
106107
void SendPointerUp(double x, double y);
107108

108109
// Reports mouse left the window client area.
110+
//
111+
// Win32 api doesn't have "mouse enter" event. Therefore, there is no
112+
// SendPointerEnter method. A mouse enter event is tracked then the "move"
113+
// event is called.
109114
void SendPointerLeave();
110115

111116
// Reports a keyboard character to Flutter engine.

shell/platform/windows/win32_window.cc

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,18 @@ LRESULT CALLBACK Win32Window::WndProc(HWND const window,
9898
return DefWindowProc(window, message, wparam, lparam);
9999
}
100100

101+
// Activates tracking for a "mouse leave" event.
102+
void Win32Window::TrackMouseLeaveEvent(HWND hwnd) {
103+
if (!tracking_mouse_leave_) {
104+
TRACKMOUSEEVENT tme;
105+
tme.cbSize = sizeof(tme);
106+
tme.hwndTrack = hwnd;
107+
tme.dwFlags = TME_LEAVE;
108+
TrackMouseEvent(&tme);
109+
tracking_mouse_leave_ = true;
110+
}
111+
}
112+
101113
LRESULT
102114
Win32Window::MessageHandler(HWND hwnd,
103115
UINT const message,
@@ -107,7 +119,6 @@ Win32Window::MessageHandler(HWND hwnd,
107119
UINT width = 0, height = 0;
108120
auto window =
109121
reinterpret_cast<Win32Window*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
110-
static bool tracking_mouse_events = false;
111122

112123
if (window != nullptr) {
113124
switch (message) {
@@ -121,7 +132,6 @@ Win32Window::MessageHandler(HWND hwnd,
121132
window->OnClose();
122133
return 0;
123134
break;
124-
125135
case WM_SIZE:
126136
width = LOWORD(lparam);
127137
height = HIWORD(lparam);
@@ -130,29 +140,16 @@ Win32Window::MessageHandler(HWND hwnd,
130140
current_height_ = height;
131141
window->HandleResize(width, height);
132142
break;
133-
134143
case WM_MOUSEMOVE:
135-
if (!tracking_mouse_events) {
136-
TRACKMOUSEEVENT tme;
137-
tme.cbSize = sizeof(tme);
138-
tme.hwndTrack = hwnd;
139-
// Not tracking Hover since the engine handles that logic.
140-
tme.dwFlags = TME_LEAVE;
141-
TrackMouseEvent(&tme);
142-
tracking_mouse_events = true;
143-
}
144+
window->TrackMouseLeaveEvent(hwnd);
145+
144146
xPos = GET_X_LPARAM(lparam);
145147
yPos = GET_Y_LPARAM(lparam);
146-
147148
window->OnPointerMove(static_cast<double>(xPos),
148149
static_cast<double>(yPos));
149150
break;
150151
case WM_MOUSELEAVE:;
151152
window->OnPointerLeave();
152-
// Once the tracked event is received, the TrackMouseEvent function
153-
// resets. Set to false to make sure it's called once mouse movement is
154-
// detected again.
155-
tracking_mouse_events = false;
156153
break;
157154
case WM_LBUTTONDOWN:
158155
xPos = GET_X_LPARAM(lparam);

shell/platform/windows/win32_window.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "flutter/shell/platform/windows/win32_dpi_helper.h"
1515

16+
1617
namespace flutter {
1718

1819
// A class abstraction for a high DPI aware Win32 Window. Intended to be
@@ -109,7 +110,12 @@ class Win32Window {
109110

110111
UINT GetCurrentHeight();
111112

113+
// Set to true to be notified when the mouse leaves the window.
114+
bool tracking_mouse_leave_ = false;
115+
112116
private:
117+
void TrackMouseLeaveEvent(HWND hwnd);
118+
113119
// Stores new width and height and calls |OnResize| to notify inheritors
114120
void HandleResize(UINT width, UINT height);
115121

0 commit comments

Comments
 (0)