Skip to content

Commit e79909c

Browse files
committed
Handle Edge Browser Hover
This contribution captures the hover over edge browser and sends a mouse move event to its listener. contributes to #1540
1 parent 18a9adb commit e79909c

File tree

1 file changed

+30
-0
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser

1 file changed

+30
-0
lines changed

bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/Edge.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,7 @@ void setupBrowser(int hr, long pv) {
645645
browser.addListener(SWT.FocusIn, this::browserFocusIn);
646646
browser.addListener(SWT.Resize, this::browserResize);
647647
browser.addListener(SWT.Move, this::browserMove);
648+
handleBrowserHover();
648649

649650
containingEnvironment.instances().add(this);
650651
// Sometimes when the shell of the browser is opened before the browser is
@@ -700,6 +701,35 @@ void browserResize(Event event) {
700701
controller.put_IsVisible(true);
701702
}
702703

704+
private void handleBrowserHover() {
705+
browser.getDisplay().timerExec(500, () -> {
706+
if (browser.isDisposed()) {
707+
return;
708+
}
709+
if (!browser.isVisible() || !hasDisplayFocus()) {
710+
handleBrowserHover();
711+
return;
712+
}
713+
final Point cursorLocation = browser.getDisplay().getCursorLocation();
714+
Point cursorLocationInControlCoordinate = browser.toControl(cursorLocation);
715+
Rectangle browserBounds = browser.getBounds();
716+
if (browserBounds.contains(cursorLocationInControlCoordinate)) {
717+
Event newEvent = new Event();
718+
newEvent.widget = browser;
719+
Point position = cursorLocationInControlCoordinate;
720+
newEvent.x = position.x;
721+
newEvent.y = position.y;
722+
newEvent.type = SWT.MouseMove;
723+
browser.notifyListeners(newEvent.type, newEvent);
724+
}
725+
handleBrowserHover();
726+
});
727+
}
728+
729+
private boolean hasDisplayFocus() {
730+
return browser.getDisplay().getFocusControl() != null;
731+
}
732+
703733
@Override
704734
public Object evaluate(String script) throws SWTException {
705735
// Feature in WebView2. ExecuteScript works regardless of IsScriptEnabled setting.

0 commit comments

Comments
 (0)