Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscojma86 committed Sep 20, 2019
1 parent 4ab6c8b commit 7e59dd3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
4 changes: 4 additions & 0 deletions shell/platform/windows/win32_flutter_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
5 changes: 5 additions & 0 deletions shell/platform/windows/win32_flutter_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
31 changes: 14 additions & 17 deletions shell/platform/windows/win32_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -107,7 +119,6 @@ Win32Window::MessageHandler(HWND hwnd,
UINT width = 0, height = 0;
auto window =
reinterpret_cast<Win32Window*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
static bool tracking_mouse_events = false;

if (window != nullptr) {
switch (message) {
Expand All @@ -121,7 +132,6 @@ Win32Window::MessageHandler(HWND hwnd,
window->OnClose();
return 0;
break;

case WM_SIZE:
width = LOWORD(lparam);
height = HIWORD(lparam);
Expand All @@ -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<double>(xPos),
static_cast<double>(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);
Expand Down
6 changes: 6 additions & 0 deletions shell/platform/windows/win32_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 7e59dd3

Please sign in to comment.