diff --git a/common/simple_handler.cc b/common/simple_handler.cc index 3160acb..1a39718 100644 --- a/common/simple_handler.cc +++ b/common/simple_handler.cc @@ -204,6 +204,17 @@ void SimpleHandler::cursorClick(int x, int y, bool up) } } +void SimpleHandler::cursorMove(int x , int y) +{ + BrowserList::const_iterator it = browser_list_.begin(); + if (it != browser_list_.end()) { + CefMouseEvent ev; + ev.x = x; + ev.y = y; + (*it)->GetHost()->SendMouseMoveEvent(ev, false); + } +} + void SimpleHandler::sendKeyEvent(CefKeyEvent ev) { BrowserList::const_iterator it = browser_list_.begin(); diff --git a/common/simple_handler.h b/common/simple_handler.h index 21984e8..e720da0 100644 --- a/common/simple_handler.h +++ b/common/simple_handler.h @@ -78,6 +78,7 @@ public: void sendScrollEvent(int x, int y, int deltaX, int deltaY); void changeSize(float a_dpi, int width, int height); void cursorClick(int x, int y, bool up); + void cursorMove(int x, int y); void sendKeyEvent(CefKeyEvent ev); void loadUrl(std::string url); void goForward(); diff --git a/lib/src/webview.dart b/lib/src/webview.dart index d2de07f..0674ec6 100644 --- a/lib/src/webview.dart +++ b/lib/src/webview.dart @@ -79,13 +79,13 @@ class WebViewController extends ValueNotifier { } /// Moves the virtual cursor to [position]. - Future _setCursorPos(Offset position) async { + Future _cursorMove(Offset position) async { if (_isDisposed) { return; } assert(value); return _pluginChannel - .invokeMethod('setCursorPos', [position.dx, position.dy]); + .invokeMethod('cursorMove', [position.dx, position.dy]); } Future _cursorClickDown(Offset position) async { @@ -162,15 +162,21 @@ class WebViewState extends State { }, child: SizeChangedLayoutNotifier( child: Listener( - onPointerHover: (ev) {}, + onPointerHover: (ev) { + print("move1"); + _controller._cursorMove(ev.localPosition); + }, onPointerDown: (ev) { + print("down"); _controller._cursorClickDown(ev.localPosition); }, onPointerUp: (ev) { + print("up"); _controller._cursorClickUp(ev.localPosition); }, onPointerMove: (ev) { - // _controller._setCursorPos(ev.localPosition); + print("move2"); + _controller._cursorMove(ev.localPosition); }, onPointerSignal: (signal) { if (signal is PointerScrollEvent) { @@ -191,7 +197,8 @@ class WebViewState extends State { final box = _key.currentContext?.findRenderObject() as RenderBox?; if (box != null) { await _controller.ready; - unawaited(_controller._setSize(dpi, Size(box.size.width, box.size.height))); + unawaited( + _controller._setSize(dpi, Size(box.size.width, box.size.height))); } } } diff --git a/macos/Classes/CefWrapper.h b/macos/Classes/CefWrapper.h index 0e2daf1..2f055d1 100644 --- a/macos/Classes/CefWrapper.h +++ b/macos/Classes/CefWrapper.h @@ -23,6 +23,8 @@ extern int64_t textureId; + (void) cursorClickDown: (int)x y:(int)y; ++ (void) cursorMove: (int)x y:(int)y; + + (void) sendScrollEvent:(int)x y:(int)y deltaX:(int)deltaX deltaY:(int)deltaY; + (void) sizeChanged: (float)dpi width:(int)width height:(int)height; diff --git a/macos/Classes/CefWrapper.mm b/macos/Classes/CefWrapper.mm index 0c9ec65..eb8725d 100644 --- a/macos/Classes/CefWrapper.mm +++ b/macos/Classes/CefWrapper.mm @@ -196,6 +196,10 @@ int64_t textureId; handler.get()->cursorClick(x, y, false); } ++ (void)cursorMove:(int)x y:(int)y { + handler.get()->cursorMove(x, y); +} + + (void)sizeChanged:(float)dpi width:(int)width height:(int)height { handler.get()->changeSize(dpi, width, height); } diff --git a/macos/Classes/WebviewCefPlugin.m b/macos/Classes/WebviewCefPlugin.m index eda258e..60640c0 100644 --- a/macos/Classes/WebviewCefPlugin.m +++ b/macos/Classes/WebviewCefPlugin.m @@ -56,6 +56,13 @@ [CefWrapper cursorClickDown:[x intValue] y:[y intValue]]; result(nil); } + else if([@"cursorMove" isEqualToString:call.method]){ + NSArray *_arg = call.arguments; + NSNumber *x = [_arg objectAtIndex:0]; + NSNumber *y = [_arg objectAtIndex:1]; + [CefWrapper cursorMove:[x intValue] y:[y intValue]]; + result(nil); + } else if([@"setSize" isEqualToString:call.method]){ NSArray *_arg = call.arguments; NSNumber *dpi = [_arg objectAtIndex:0];