[macos] fix mouse dragging

This commit is contained in:
Prome
2022-10-01 15:34:49 +08:00
parent c0a799cc78
commit 7da2c0a0c3
6 changed files with 37 additions and 22 deletions

View File

@@ -105,17 +105,17 @@ void SimpleHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
}
bool SimpleHandler::OnBeforePopup(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& target_url,
const CefString& target_frame_name,
WindowOpenDisposition target_disposition,
bool user_gesture,
const CefPopupFeatures& popupFeatures,
CefWindowInfo& windowInfo,
CefRefPtr<CefClient>& client,
CefBrowserSettings& settings,
CefRefPtr<CefDictionaryValue>& extra_info,
bool* no_javascript_access) {
CefRefPtr<CefFrame> frame,
const CefString& target_url,
const CefString& target_frame_name,
WindowOpenDisposition target_disposition,
bool user_gesture,
const CefPopupFeatures& popupFeatures,
CefWindowInfo& windowInfo,
CefRefPtr<CefClient>& client,
CefBrowserSettings& settings,
CefRefPtr<CefDictionaryValue>& extra_info,
bool* no_javascript_access) {
loadUrl(target_url);
return true;
}
@@ -204,13 +204,16 @@ void SimpleHandler::cursorClick(int x, int y, bool up)
}
}
void SimpleHandler::cursorMove(int x , int y)
void SimpleHandler::cursorMove(int x , int y, bool dragging)
{
BrowserList::const_iterator it = browser_list_.begin();
if (it != browser_list_.end()) {
CefMouseEvent ev;
ev.x = x;
ev.y = y;
if(dragging) {
ev.modifiers = EVENTFLAG_LEFT_MOUSE_BUTTON;
}
(*it)->GetHost()->SendMouseMoveEvent(ev, false);
}
}

View File

@@ -78,7 +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 cursorMove(int x, int y, bool dragging);
void sendKeyEvent(CefKeyEvent ev);
void loadUrl(std::string url);
void goForward();

View File

@@ -88,6 +88,15 @@ class WebViewController extends ValueNotifier<bool> {
.invokeMethod('cursorMove', [position.dx, position.dy]);
}
Future<void> _cursorDragging(Offset position) async {
if (_isDisposed) {
return;
}
assert(value);
return _pluginChannel
.invokeMethod('cursorDragging', [position.dx, position.dy]);
}
Future<void> _cursorClickDown(Offset position) async {
if (_isDisposed) {
return;
@@ -163,20 +172,16 @@ class WebViewState extends State<WebView> {
child: SizeChangedLayoutNotifier(
child: Listener(
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) {
print("move2");
_controller._cursorMove(ev.localPosition);
_controller._cursorDragging(ev.localPosition);
},
onPointerSignal: (signal) {
if (signal is PointerScrollEvent) {

View File

@@ -23,7 +23,7 @@ extern int64_t textureId;
+ (void) cursorClickDown: (int)x y:(int)y;
+ (void) cursorMove: (int)x y:(int)y;
+ (void) cursorMove: (int)x y:(int)y dragging:(bool)dragging;
+ (void) sendScrollEvent:(int)x y:(int)y deltaX:(int)deltaX deltaY:(int)deltaY;

View File

@@ -196,8 +196,8 @@ int64_t textureId;
handler.get()->cursorClick(x, y, false);
}
+ (void)cursorMove:(int)x y:(int)y {
handler.get()->cursorMove(x, y);
+ (void)cursorMove:(int)x y:(int)y dragging:(bool)dragging {
handler.get()->cursorMove(x, y, dragging);
}
+ (void)sizeChanged:(float)dpi width:(int)width height:(int)height {

View File

@@ -60,7 +60,14 @@
NSArray<NSNumber *> *_arg = call.arguments;
NSNumber *x = [_arg objectAtIndex:0];
NSNumber *y = [_arg objectAtIndex:1];
[CefWrapper cursorMove:[x intValue] y:[y intValue]];
[CefWrapper cursorMove:[x intValue] y:[y intValue] dragging: false];
result(nil);
}
else if([@"cursorDragging" isEqualToString:call.method]){
NSArray<NSNumber *> *_arg = call.arguments;
NSNumber *x = [_arg objectAtIndex:0];
NSNumber *y = [_arg objectAtIndex:1];
[CefWrapper cursorMove:[x intValue] y:[y intValue] dragging: true];
result(nil);
}
else if([@"setSize" isEqualToString:call.method]){