发现: \engine-main\third_party\tonic\logging\dart_invoke.h 让c++代码调用dart代码
tonic库的官方链接地址:
https://pub-web.flutter-io.cn/packages/tonichttps://pub-web.flutter-io.cn/packages/tonic
// \engine-main\shell\platform\windows\flutter_window.cc
// 主要分析 WM_MOUSEMOVE 事件
WNDCLASS FlutterWindow::RegisterWindowClass(std::wstring& title) {
window_class_name_ = title;
WNDCLASS window_class{};
window_class.hCursor = LoadCursor(nullptr, IDC_ARROW);
window_class.lpszClassName = title.c_str();
window_class.style = CS_HREDRAW | CS_VREDRAW;
window_class.cbClsExtra = 0;
window_class.cbWndExtra = 0;
window_class.hInstance = GetModuleHandle(nullptr);
window_class.hIcon = nullptr;
window_class.hbrBackground = 0;
window_class.lpszMenuName = nullptr;
window_class.lpfnWndProc = WndProc;
RegisterClass(&window_class);
return window_class;
}
LRESULT CALLBACK FlutterWindow::WndProc(HWND const window,
UINT const message,
WPARAM const wparam,
LPARAM const lparam) noexcept {
if (message == WM_NCCREATE) {
auto cs = reinterpret_cast<CREATESTRUCT*>(lparam);
SetWindowLongPtr(window, GWLP_USERDATA,
reinterpret_cast<LONG_PTR>(cs->lpCreateParams));
auto that = static_cast<FlutterWindow*>(cs->lpCreateParams);
that->window_handle_ = window;
that->text_input_manager_->SetWindowHandle(window);
RegisterTouchWindow(window, 0);
} else if (FlutterWindow* that = GetThisFromHandle(window)) {
return that->HandleMessage(message, wparam, lparam);
}
return DefWindowProc(window, message, wparam, lparam);
}
LRESULT
FlutterWindow::HandleMessage(UINT const message,
WPARAM const wparam,
LPARAM const lparam) noexcept {
LPARAM result_lparam = lparam;
int xPos = 0, yPos = 0;
UINT width = 0, height = 0;
UINT button_pressed = 0;
FlutterPointerDeviceKind device_kind;
// switch分支中省略了很多代码
switch (message) {
case kWmDpiChangedBeforeParent:
current_dpi_ = GetDpiForHWND(window_handle_);
OnDpiScale(current_dpi_);
return 0;
case WM_SIZE:
width = LOWORD(lparam);
height = HIWORD(lparam);
current_width_ = width;
current_height_ = height;
HandleResize(width, height);
OnWindowStateEvent(width == 0 && height == 0 ? WindowStateEvent::kHide
: WindowStateEvent::kShow);
break;
case WM_PAINT:
OnPaint();
break;
case WM_MOUSEMOVE:
device_kind = GetFlutterPointerDeviceKind();
if (device_kind == kFlutterPointerDeviceKindMouse) {
TrackMouseLeaveEvent(window_handle_);
xPos = GET_X_LPARAM(lparam);
yPos = GET_Y_LPARAM(lparam);
mouse_x_ = static_cast<double>(xPos);
mouse_y_ = static_cast<double>(yPos);
int mods = 0;
if (wparam & MK_CONTROL) {
mods |= kControl;
}
if (wparam & MK_SHIFT) {
mods |= kShift;
}
// ---------->>>>>>>>>> 调用 OnPointerMove
OnPointerMove(mouse_x_, mouse_y_, device_kind, kDefaultPointerDeviceId,
mods);
}
break;
case WM_MOUSELEAVE:
device_kind = GetFlutterPointerDeviceKind();
if (device_kind == kFlutterPointerDeviceKindMouse) {
OnPointerLeave(mouse_x_, mouse_y_, device_kind,
kDefaultPointerDeviceId);
}
// 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;