chromiumembedded / java-cef

Java Chromium Embedded Framework (JCEF). A simple framework for embedding Chromium-based browsers in other applications using the Java programming language.
https://bitbucket.org/chromiumembedded/java-cef
Other
605 stars 135 forks source link

Wrong scroll direction on Linux with OSR enabled. #452

Open ionull opened 9 months ago

ionull commented 9 months ago

Describe the bug Scroll direction is reversed on Linux when OSR is enabled.

To Reproduce Steps to reproduce the behavior:

  1. Open a web page with JCEF (make sure it's long enough with vertical scroll bar)
  2. Scroll with mouse wheel
  3. Scroll down
  4. It scroll up instead of scroll down

Expected behavior Scroll as system side.

Versions (please complete the following information):

magreenblatt commented 6 months ago

Scroll direction is usually an OS configuration option. I'm not sure how that is read/represented in Java.

1fxe commented 6 months ago

I have a proposal for a somewhat hacky solution

This is the code in X11Window class responsible for making the mouse event.

if (xev.get_type() == XConstants.ButtonPress) {
    MouseWheelEvent mwe = new MouseWheelEvent((Component)getEventSource(),MouseEvent.MOUSE_WHEEL, jWhen,
       modifiers,
       x, y,
       xbe.get_x_root(),
       xbe.get_y_root(),
       1,false,MouseWheelEvent.WHEEL_UNIT_SCROLL,
       3,button==4 ?  -1 : 1);
    postEventToEventQueue(mwe);
}

So when scrolling down normally the button passed is 5 and delta is positive, X11Window does keep track of lastButton so in the native code we could fetch that and just reverse this behavior on linux

Made a POC that works, its just working in the case for natural scrolling, we would have to do the opposite of getWheelRotation() to calculate the delta properly

jclass xWindow = env->FindClass("sun/awt/X11/XWindow");
jfieldID lastButtonId = env->GetStaticFieldID(xWindow, "lastButton", "J");
jlong button = env->GetStaticLongField(xWindow, lastButtonId);

// Would check against getWheelRotation 
if (button == 5L) { 
   delta = -3;
} else {
   delta = 3;
}