From 4ab6c8b9a34b1c29c26d7e445022ae3d20cc7fa2 Mon Sep 17 00:00:00 2001 From: Francisco Madgaleno Date: Thu, 19 Sep 2019 16:29:28 -0700 Subject: [PATCH 1/5] Track mouse leave --- shell/platform/windows/win32_flutter_window.cc | 12 ++++++++++++ shell/platform/windows/win32_flutter_window.h | 6 ++++++ shell/platform/windows/win32_window.cc | 17 +++++++++++++++++ shell/platform/windows/win32_window.h | 3 +++ 4 files changed, 38 insertions(+) diff --git a/shell/platform/windows/win32_flutter_window.cc b/shell/platform/windows/win32_flutter_window.cc index 5b2f20c153576..0a36db698a1fd 100644 --- a/shell/platform/windows/win32_flutter_window.cc +++ b/shell/platform/windows/win32_flutter_window.cc @@ -125,6 +125,12 @@ void Win32FlutterWindow::OnPointerUp(double x, double y) { } } +void Win32FlutterWindow::OnPointerLeave() { + if (process_events_) { + SendPointerLeave(); + } +} + void Win32FlutterWindow::OnChar(char32_t code_point) { if (process_events_) { SendChar(code_point); @@ -207,6 +213,12 @@ void Win32FlutterWindow::SendPointerUp(double x, double y) { SendPointerEventWithData(event); } +void Win32FlutterWindow::SendPointerLeave() { + FlutterPointerEvent event = {}; + event.phase = FlutterPointerPhase::kRemove; + SendPointerEventWithData(event); +} + void Win32FlutterWindow::SendChar(char32_t code_point) { for (const auto& handler : keyboard_hook_handlers_) { handler->CharHook(this, code_point); diff --git a/shell/platform/windows/win32_flutter_window.h b/shell/platform/windows/win32_flutter_window.h index c2316a88e0add..e4227ae802c9d 100644 --- a/shell/platform/windows/win32_flutter_window.h +++ b/shell/platform/windows/win32_flutter_window.h @@ -53,6 +53,9 @@ class Win32FlutterWindow : public Win32Window { // |Win32Window| void OnPointerUp(double x, double y) override; + // |Win32Window| + void OnPointerLeave() override; + // |Win32Window| void OnChar(char32_t code_point) override; @@ -102,6 +105,9 @@ class Win32FlutterWindow : public Win32Window { // Reports mouse release to Flutter engine. void SendPointerUp(double x, double y); + // Reports mouse left the window client area. + void SendPointerLeave(); + // Reports a keyboard character to Flutter engine. void SendChar(char32_t code_point); diff --git a/shell/platform/windows/win32_window.cc b/shell/platform/windows/win32_window.cc index ad6265109d805..c687d49a2d776 100644 --- a/shell/platform/windows/win32_window.cc +++ b/shell/platform/windows/win32_window.cc @@ -107,6 +107,7 @@ Win32Window::MessageHandler(HWND hwnd, UINT width = 0, height = 0; auto window = reinterpret_cast(GetWindowLongPtr(hwnd, GWLP_USERDATA)); + static bool tracking_mouse_events = false; if (window != nullptr) { switch (message) { @@ -131,12 +132,28 @@ Win32Window::MessageHandler(HWND hwnd, break; case WM_MOUSEMOVE: + if (!tracking_mouse_events) { + TRACKMOUSEEVENT tme; + tme.cbSize = sizeof(tme); + tme.hwndTrack = hwnd; + // Not tracking Hover since the engine handles that logic. + tme.dwFlags = TME_LEAVE; + TrackMouseEvent(&tme); + tracking_mouse_events = true; + } xPos = GET_X_LPARAM(lparam); yPos = GET_Y_LPARAM(lparam); window->OnPointerMove(static_cast(xPos), static_cast(yPos)); break; + case WM_MOUSELEAVE:; + window->OnPointerLeave(); + // Once the tracked event is received, the TrackMouseEvent function + // resets. Set to false to make sure it's called once mouse movement is + // detected again. + tracking_mouse_events = false; + break; case WM_LBUTTONDOWN: xPos = GET_X_LPARAM(lparam); yPos = GET_Y_LPARAM(lparam); diff --git a/shell/platform/windows/win32_window.h b/shell/platform/windows/win32_window.h index 45819b589ea61..5b8b5c760ed91 100644 --- a/shell/platform/windows/win32_window.h +++ b/shell/platform/windows/win32_window.h @@ -88,6 +88,9 @@ class Win32Window { // down to up virtual void OnPointerUp(double x, double y) = 0; + // Called when the mouse leaves the window. + virtual void OnPointerLeave() = 0; + // Called when character input occurs. virtual void OnChar(char32_t code_point) = 0; From 7e59dd3add35c69ea496d80dc196ee4cb4309a10 Mon Sep 17 00:00:00 2001 From: Francisco Madgaleno Date: Fri, 20 Sep 2019 11:27:13 -0700 Subject: [PATCH 2/5] Address comments --- .../platform/windows/win32_flutter_window.cc | 4 +++ shell/platform/windows/win32_flutter_window.h | 5 +++ shell/platform/windows/win32_window.cc | 31 +++++++++---------- shell/platform/windows/win32_window.h | 6 ++++ 4 files changed, 29 insertions(+), 17 deletions(-) diff --git a/shell/platform/windows/win32_flutter_window.cc b/shell/platform/windows/win32_flutter_window.cc index 0a36db698a1fd..57637f845f9ff 100644 --- a/shell/platform/windows/win32_flutter_window.cc +++ b/shell/platform/windows/win32_flutter_window.cc @@ -128,6 +128,10 @@ void Win32FlutterWindow::OnPointerUp(double x, double y) { void Win32FlutterWindow::OnPointerLeave() { if (process_events_) { SendPointerLeave(); + // Once the tracked event is received, the TrackMouseEvent function + // resets. Set to false to make sure it's called once mouse movement is + // detected again. + tracking_mouse_leave_ = false; } } diff --git a/shell/platform/windows/win32_flutter_window.h b/shell/platform/windows/win32_flutter_window.h index e4227ae802c9d..ce93a400ce530 100644 --- a/shell/platform/windows/win32_flutter_window.h +++ b/shell/platform/windows/win32_flutter_window.h @@ -22,6 +22,7 @@ #include "flutter/shell/platform/windows/win32_window.h" #include "flutter/shell/platform/windows/window_state.h" + namespace flutter { // A win32 flutter child window used as implementatin for flutter view. In the @@ -106,6 +107,10 @@ class Win32FlutterWindow : public Win32Window { void SendPointerUp(double x, double y); // Reports mouse left the window client area. + // + // Win32 api doesn't have "mouse enter" event. Therefore, there is no + // SendPointerEnter method. A mouse enter event is tracked then the "move" + // event is called. void SendPointerLeave(); // Reports a keyboard character to Flutter engine. diff --git a/shell/platform/windows/win32_window.cc b/shell/platform/windows/win32_window.cc index c687d49a2d776..34667b6266cc8 100644 --- a/shell/platform/windows/win32_window.cc +++ b/shell/platform/windows/win32_window.cc @@ -98,6 +98,18 @@ LRESULT CALLBACK Win32Window::WndProc(HWND const window, return DefWindowProc(window, message, wparam, lparam); } +// Activates tracking for a "mouse leave" event. +void Win32Window::TrackMouseLeaveEvent(HWND hwnd) { + if (!tracking_mouse_leave_) { + TRACKMOUSEEVENT tme; + tme.cbSize = sizeof(tme); + tme.hwndTrack = hwnd; + tme.dwFlags = TME_LEAVE; + TrackMouseEvent(&tme); + tracking_mouse_leave_ = true; + } +} + LRESULT Win32Window::MessageHandler(HWND hwnd, UINT const message, @@ -107,7 +119,6 @@ Win32Window::MessageHandler(HWND hwnd, UINT width = 0, height = 0; auto window = reinterpret_cast(GetWindowLongPtr(hwnd, GWLP_USERDATA)); - static bool tracking_mouse_events = false; if (window != nullptr) { switch (message) { @@ -121,7 +132,6 @@ Win32Window::MessageHandler(HWND hwnd, window->OnClose(); return 0; break; - case WM_SIZE: width = LOWORD(lparam); height = HIWORD(lparam); @@ -130,29 +140,16 @@ Win32Window::MessageHandler(HWND hwnd, current_height_ = height; window->HandleResize(width, height); break; - case WM_MOUSEMOVE: - if (!tracking_mouse_events) { - TRACKMOUSEEVENT tme; - tme.cbSize = sizeof(tme); - tme.hwndTrack = hwnd; - // Not tracking Hover since the engine handles that logic. - tme.dwFlags = TME_LEAVE; - TrackMouseEvent(&tme); - tracking_mouse_events = true; - } + window->TrackMouseLeaveEvent(hwnd); + xPos = GET_X_LPARAM(lparam); yPos = GET_Y_LPARAM(lparam); - window->OnPointerMove(static_cast(xPos), static_cast(yPos)); break; case WM_MOUSELEAVE:; window->OnPointerLeave(); - // Once the tracked event is received, the TrackMouseEvent function - // resets. Set to false to make sure it's called once mouse movement is - // detected again. - tracking_mouse_events = false; break; case WM_LBUTTONDOWN: xPos = GET_X_LPARAM(lparam); diff --git a/shell/platform/windows/win32_window.h b/shell/platform/windows/win32_window.h index 5b8b5c760ed91..04a84ac42ad2e 100644 --- a/shell/platform/windows/win32_window.h +++ b/shell/platform/windows/win32_window.h @@ -13,6 +13,7 @@ #include "flutter/shell/platform/windows/win32_dpi_helper.h" + namespace flutter { // A class abstraction for a high DPI aware Win32 Window. Intended to be @@ -109,7 +110,12 @@ class Win32Window { UINT GetCurrentHeight(); + // Set to true to be notified when the mouse leaves the window. + bool tracking_mouse_leave_ = false; + private: + void TrackMouseLeaveEvent(HWND hwnd); + // Stores new width and height and calls |OnResize| to notify inheritors void HandleResize(UINT width, UINT height); From b1bfea6d75aac77f6a9ca87975aa17d6305df7b8 Mon Sep 17 00:00:00 2001 From: Francisco Madgaleno Date: Fri, 20 Sep 2019 12:44:58 -0700 Subject: [PATCH 3/5] Whitespace --- shell/platform/windows/win32_flutter_window.h | 1 - shell/platform/windows/win32_window.cc | 1 - shell/platform/windows/win32_window.h | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/shell/platform/windows/win32_flutter_window.h b/shell/platform/windows/win32_flutter_window.h index ce93a400ce530..c773e6e272ff6 100644 --- a/shell/platform/windows/win32_flutter_window.h +++ b/shell/platform/windows/win32_flutter_window.h @@ -22,7 +22,6 @@ #include "flutter/shell/platform/windows/win32_window.h" #include "flutter/shell/platform/windows/window_state.h" - namespace flutter { // A win32 flutter child window used as implementatin for flutter view. In the diff --git a/shell/platform/windows/win32_window.cc b/shell/platform/windows/win32_window.cc index 34667b6266cc8..9c7d1ac8286be 100644 --- a/shell/platform/windows/win32_window.cc +++ b/shell/platform/windows/win32_window.cc @@ -98,7 +98,6 @@ LRESULT CALLBACK Win32Window::WndProc(HWND const window, return DefWindowProc(window, message, wparam, lparam); } -// Activates tracking for a "mouse leave" event. void Win32Window::TrackMouseLeaveEvent(HWND hwnd) { if (!tracking_mouse_leave_) { TRACKMOUSEEVENT tme; diff --git a/shell/platform/windows/win32_window.h b/shell/platform/windows/win32_window.h index 04a84ac42ad2e..d14864b1be106 100644 --- a/shell/platform/windows/win32_window.h +++ b/shell/platform/windows/win32_window.h @@ -13,7 +13,6 @@ #include "flutter/shell/platform/windows/win32_dpi_helper.h" - namespace flutter { // A class abstraction for a high DPI aware Win32 Window. Intended to be @@ -114,6 +113,7 @@ class Win32Window { bool tracking_mouse_leave_ = false; private: + // Activates tracking for a "mouse leave" event. void TrackMouseLeaveEvent(HWND hwnd); // Stores new width and height and calls |OnResize| to notify inheritors From 89c11a9fcce7474c319d7b66ddda31bffcb1732c Mon Sep 17 00:00:00 2001 From: Francisco Madgaleno Date: Fri, 20 Sep 2019 16:14:31 -0700 Subject: [PATCH 4/5] Make private --- shell/platform/windows/win32_flutter_window.cc | 10 +++------- shell/platform/windows/win32_window.cc | 4 ++++ shell/platform/windows/win32_window.h | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/shell/platform/windows/win32_flutter_window.cc b/shell/platform/windows/win32_flutter_window.cc index 57637f845f9ff..1fe8a1a970bbc 100644 --- a/shell/platform/windows/win32_flutter_window.cc +++ b/shell/platform/windows/win32_flutter_window.cc @@ -94,9 +94,9 @@ void Win32FlutterWindow::HandlePlatformMessage( auto message = ConvertToDesktopMessage(*engine_message); - message_dispatcher_->HandleMessage( - message, [this] { this->process_events_ = false; }, - [this] { this->process_events_ = true; }); + message_dispatcher_->HandleMessage(message, + [this] { this->process_events_ = false; }, + [this] { this->process_events_ = true; }); } void Win32FlutterWindow::OnDpiScale(unsigned int dpi){}; @@ -128,10 +128,6 @@ void Win32FlutterWindow::OnPointerUp(double x, double y) { void Win32FlutterWindow::OnPointerLeave() { if (process_events_) { SendPointerLeave(); - // Once the tracked event is received, the TrackMouseEvent function - // resets. Set to false to make sure it's called once mouse movement is - // detected again. - tracking_mouse_leave_ = false; } } diff --git a/shell/platform/windows/win32_window.cc b/shell/platform/windows/win32_window.cc index 9c7d1ac8286be..9465a4f06dd82 100644 --- a/shell/platform/windows/win32_window.cc +++ b/shell/platform/windows/win32_window.cc @@ -149,6 +149,10 @@ Win32Window::MessageHandler(HWND hwnd, break; case WM_MOUSELEAVE:; window->OnPointerLeave(); + // Once the tracked event is received, the TrackMouseEvent function + // resets. Set to false to make sure it's called once mouse movement is + // detected again. + tracking_mouse_leave_ = false; break; case WM_LBUTTONDOWN: xPos = GET_X_LPARAM(lparam); diff --git a/shell/platform/windows/win32_window.h b/shell/platform/windows/win32_window.h index d14864b1be106..16a553cd62873 100644 --- a/shell/platform/windows/win32_window.h +++ b/shell/platform/windows/win32_window.h @@ -109,9 +109,6 @@ class Win32Window { UINT GetCurrentHeight(); - // Set to true to be notified when the mouse leaves the window. - bool tracking_mouse_leave_ = false; - private: // Activates tracking for a "mouse leave" event. void TrackMouseLeaveEvent(HWND hwnd); @@ -139,6 +136,9 @@ class Win32Window { // aspects of win32 High DPI handling across different OS versions. std::unique_ptr dpi_helper_ = std::make_unique(); + + // Set to true to be notified when the mouse leaves the window. + bool tracking_mouse_leave_ = false; }; } // namespace flutter From bcc6ed6e63d792d4385f7f1433850681a485114a Mon Sep 17 00:00:00 2001 From: Francisco Madgaleno Date: Fri, 20 Sep 2019 16:25:58 -0700 Subject: [PATCH 5/5] Reformat --- shell/platform/windows/win32_flutter_window.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shell/platform/windows/win32_flutter_window.cc b/shell/platform/windows/win32_flutter_window.cc index 1fe8a1a970bbc..0a36db698a1fd 100644 --- a/shell/platform/windows/win32_flutter_window.cc +++ b/shell/platform/windows/win32_flutter_window.cc @@ -94,9 +94,9 @@ void Win32FlutterWindow::HandlePlatformMessage( auto message = ConvertToDesktopMessage(*engine_message); - message_dispatcher_->HandleMessage(message, - [this] { this->process_events_ = false; }, - [this] { this->process_events_ = true; }); + message_dispatcher_->HandleMessage( + message, [this] { this->process_events_ = false; }, + [this] { this->process_events_ = true; }); } void Win32FlutterWindow::OnDpiScale(unsigned int dpi){};