mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
JBCefOsrComponent: fix focus on Linux
GitOrigin-RevId: 435af12dc0768186a0ad76402d3daa9e0f7f5392
This commit is contained in:
committed by
intellij-monorepo-bot
parent
7a72ed8020
commit
3bd3d80794
@@ -228,7 +228,12 @@ public class JBCefBrowser extends JBCefBrowserBase {
|
||||
}
|
||||
if (!browser.getUIComponent().hasFocus()) {
|
||||
if (SystemInfo.isLinux) {
|
||||
browser.getUIComponent().requestFocus();
|
||||
if (isProperty(JBCefBrowserBase.Properties.IS_LIGHTWEIGHT)) {
|
||||
browser.getUIComponent().requestFocusInWindow();
|
||||
}
|
||||
else {
|
||||
browser.getUIComponent().requestFocus();
|
||||
}
|
||||
}
|
||||
else {
|
||||
browser.getUIComponent().requestFocusInWindow();
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
package com.intellij.ui.jcef;
|
||||
|
||||
import com.intellij.application.options.RegistryManager;
|
||||
import com.intellij.openapi.util.SystemInfoRt;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.ui.scale.JBUIScale;
|
||||
import com.intellij.util.Alarm;
|
||||
@@ -10,9 +11,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.awt.event.*;
|
||||
|
||||
/**
|
||||
* A lightweight component on which an off-screen browser is rendered.
|
||||
@@ -34,12 +33,24 @@ class JBCefOsrComponent extends JPanel {
|
||||
setBackground(JBColor.background());
|
||||
addPropertyChangeListener("graphicsConfiguration", e -> myRenderHandler.updateScale(myScale = JBUIScale.sysScale(this)));
|
||||
|
||||
setFocusable(true);
|
||||
setRequestFocusEnabled(true);
|
||||
enableEvents(AWTEvent.KEY_EVENT_MASK |
|
||||
AWTEvent.MOUSE_EVENT_MASK |
|
||||
AWTEvent.MOUSE_WHEEL_EVENT_MASK |
|
||||
AWTEvent.MOUSE_MOTION_EVENT_MASK);
|
||||
|
||||
setFocusable(true);
|
||||
setRequestFocusEnabled(true);
|
||||
|
||||
addFocusListener(new FocusListener() {
|
||||
@Override
|
||||
public void focusGained(FocusEvent e) {
|
||||
myBrowser.getCefBrowser().setFocus(true);
|
||||
}
|
||||
@Override
|
||||
public void focusLost(FocusEvent e) {
|
||||
myBrowser.getCefBrowser().setFocus(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setBrowser(@NotNull JBCefBrowser browser) {
|
||||
@@ -57,13 +68,6 @@ class JBCefOsrComponent extends JPanel {
|
||||
myRenderHandler.paint((Graphics2D)g);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void show() {
|
||||
super.show();
|
||||
myRenderHandler.notifyComponentShown();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void reshape(int x, int y, int w, int h) {
|
||||
@@ -75,10 +79,10 @@ class JBCefOsrComponent extends JPanel {
|
||||
@Override
|
||||
protected void processMouseEvent(MouseEvent e) {
|
||||
super.processMouseEvent(e);
|
||||
boolean mousePressed = e.getID() == MouseEvent.MOUSE_PRESSED;
|
||||
if (mousePressed) myRenderHandler.notifyMousePressed();
|
||||
myBrowser.getCefBrowser().sendMouseEvent(e);
|
||||
if (mousePressed) requestFocusInWindow();
|
||||
if (e.getID() == MouseEvent.MOUSE_PRESSED) {
|
||||
requestFocusInWindow();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -87,6 +91,9 @@ class JBCefOsrComponent extends JPanel {
|
||||
|
||||
double val = e.getPreciseWheelRotation() *
|
||||
RegistryManager.getInstance().intValue("ide.browser.jcef.osr.wheelRotation.factor");
|
||||
if (SystemInfoRt.isLinux) {
|
||||
val *= -1;
|
||||
}
|
||||
myBrowser.getCefBrowser().sendMouseWheelEvent(new MouseWheelEvent(
|
||||
e.getComponent(),
|
||||
e.getID(),
|
||||
|
||||
@@ -16,6 +16,10 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.DataBufferInt;
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -42,7 +46,21 @@ class JBCefOsrHandler implements CefRenderHandler {
|
||||
private final @NotNull Object myImageLock = new Object();
|
||||
|
||||
JBCefOsrHandler(@NotNull JComponent component) {
|
||||
this.myComponent = component;
|
||||
myComponent = component;
|
||||
|
||||
myComponent.addComponentListener(new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentShown(ComponentEvent e) {
|
||||
updateLocation();
|
||||
}
|
||||
});
|
||||
|
||||
myComponent.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
updateLocation();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -164,16 +182,8 @@ class JBCefOsrHandler implements CefRenderHandler {
|
||||
myScale = scale;
|
||||
}
|
||||
|
||||
void notifyMousePressed() {
|
||||
updateLocation();
|
||||
}
|
||||
|
||||
void notifyComponentShown() {
|
||||
updateLocation();
|
||||
}
|
||||
|
||||
private void updateLocation() {
|
||||
// getLocationOnScreen() is an expensive op, so do not request it on every mouse move but cache
|
||||
// getLocationOnScreen() is an expensive op, so do not request it on every mouse move, but cache
|
||||
myLocationOnScreenRef.set(myComponent.getLocationOnScreen());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user