提交 da85f117 编写于 作者: D dcherepanov

7150345: [macosx] Can't type into applets

Reviewed-by: ant
上级 34e71365
...@@ -522,11 +522,6 @@ public abstract class LWToolkit extends SunToolkit implements Runnable { ...@@ -522,11 +522,6 @@ public abstract class LWToolkit extends SunToolkit implements Runnable {
postEvent(targetToAppContext(event.getSource()), event); postEvent(targetToAppContext(event.getSource()), event);
} }
/*
* Returns true if the application (one of its windows) owns keyboard focus.
*/
public abstract boolean isApplicationActive();
// use peer's back buffer to implement non-opaque windows. // use peer's back buffer to implement non-opaque windows.
@Override @Override
public boolean needUpdateWindow() { public boolean needUpdateWindow() {
......
...@@ -1067,11 +1067,7 @@ public class LWWindowPeer ...@@ -1067,11 +1067,7 @@ public class LWWindowPeer
return false; return false;
} }
// Cross-app activation requests are not allowed. if (platformWindow.rejectFocusRequest(cause)) {
if (cause != CausedFocusEvent.Cause.MOUSE_EVENT &&
!((LWToolkit)Toolkit.getDefaultToolkit()).isApplicationActive())
{
focusLog.fine("the app is inactive, so the request is rejected");
return false; return false;
} }
......
...@@ -27,6 +27,7 @@ package sun.lwawt; ...@@ -27,6 +27,7 @@ package sun.lwawt;
import java.awt.*; import java.awt.*;
import sun.awt.CausedFocusEvent;
import sun.java2d.SurfaceData; import sun.java2d.SurfaceData;
// TODO Is it worth to generify this interface, like that: // TODO Is it worth to generify this interface, like that:
...@@ -117,6 +118,8 @@ public interface PlatformWindow { ...@@ -117,6 +118,8 @@ public interface PlatformWindow {
public void updateFocusableWindowState(); public void updateFocusableWindowState();
public boolean rejectFocusRequest(CausedFocusEvent.Cause cause);
public boolean requestWindowFocus(); public boolean requestWindowFocus();
/* /*
......
...@@ -38,6 +38,8 @@ import java.awt.event.*; ...@@ -38,6 +38,8 @@ import java.awt.event.*;
public class CEmbeddedFrame extends EmbeddedFrame { public class CEmbeddedFrame extends EmbeddedFrame {
private CPlatformResponder responder; private CPlatformResponder responder;
private boolean focused = true;
private boolean parentWindowActive = true;
public CEmbeddedFrame() { public CEmbeddedFrame() {
show(); show();
...@@ -94,4 +96,31 @@ public class CEmbeddedFrame extends EmbeddedFrame { ...@@ -94,4 +96,31 @@ public class CEmbeddedFrame extends EmbeddedFrame {
public void handleInputEvent(String text) { public void handleInputEvent(String text) {
new RuntimeException("Not implemented"); new RuntimeException("Not implemented");
} }
public void handleFocusEvent(boolean focused) {
this.focused = focused;
updateOverlayWindowActiveState();
}
public void handleWindowFocusEvent(boolean parentWindowActive) {
this.parentWindowActive = parentWindowActive;
updateOverlayWindowActiveState();
}
public boolean isParentWindowActive() {
return parentWindowActive;
}
/*
* May change appearance of contents of window, and generate a
* WINDOW_ACTIVATED event.
*/
private void updateOverlayWindowActiveState() {
final boolean showAsFocused = parentWindowActive && focused;
dispatchEvent(
new FocusEvent(this, showAsFocused ?
FocusEvent.FOCUS_GAINED :
FocusEvent.FOCUS_LOST));
}
} }
...@@ -33,17 +33,23 @@ import sun.java2d.SurfaceData; ...@@ -33,17 +33,23 @@ import sun.java2d.SurfaceData;
import sun.awt.CGraphicsConfig; import sun.awt.CGraphicsConfig;
import sun.awt.CGraphicsDevice; import sun.awt.CGraphicsDevice;
import sun.awt.CausedFocusEvent;
import java.awt.*; import java.awt.*;
import java.awt.BufferCapabilities.FlipContents; import java.awt.BufferCapabilities.FlipContents;
import sun.util.logging.PlatformLogger;
/* /*
* Provides a lightweight implementation of the EmbeddedFrame. * Provides a lightweight implementation of the EmbeddedFrame.
*/ */
public class CPlatformEmbeddedFrame implements PlatformWindow { public class CPlatformEmbeddedFrame implements PlatformWindow {
private static final PlatformLogger focusLogger = PlatformLogger.getLogger("sun.lwawt.macosx.focus.CPlatformEmbeddedFrame");
private CGLLayer windowLayer; private CGLLayer windowLayer;
private LWWindowPeer peer; private LWWindowPeer peer;
private CEmbeddedFrame target;
private volatile int screenX = 0; private volatile int screenX = 0;
private volatile int screenY = 0; private volatile int screenY = 0;
...@@ -52,6 +58,7 @@ public class CPlatformEmbeddedFrame implements PlatformWindow { ...@@ -52,6 +58,7 @@ public class CPlatformEmbeddedFrame implements PlatformWindow {
public void initialize(Window target, final LWWindowPeer peer, PlatformWindow owner) { public void initialize(Window target, final LWWindowPeer peer, PlatformWindow owner) {
this.peer = peer; this.peer = peer;
this.windowLayer = new CGLLayer(peer); this.windowLayer = new CGLLayer(peer);
this.target = (CEmbeddedFrame)target;
} }
@Override @Override
...@@ -148,6 +155,18 @@ public class CPlatformEmbeddedFrame implements PlatformWindow { ...@@ -148,6 +155,18 @@ public class CPlatformEmbeddedFrame implements PlatformWindow {
@Override @Override
public void updateFocusableWindowState() {} public void updateFocusableWindowState() {}
@Override
public boolean rejectFocusRequest(CausedFocusEvent.Cause cause) {
// Cross-app activation requests are not allowed.
if (cause != CausedFocusEvent.Cause.MOUSE_EVENT &&
!target.isParentWindowActive())
{
focusLogger.fine("the embedder is inactive, so the request is rejected");
return true;
}
return false;
}
@Override @Override
public boolean requestWindowFocus() { public boolean requestWindowFocus() {
return true; return true;
......
...@@ -65,6 +65,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -65,6 +65,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
// Loger to report issues happened during execution but that do not affect functionality // Loger to report issues happened during execution but that do not affect functionality
private static final PlatformLogger logger = PlatformLogger.getLogger("sun.lwawt.macosx.CPlatformWindow"); private static final PlatformLogger logger = PlatformLogger.getLogger("sun.lwawt.macosx.CPlatformWindow");
private static final PlatformLogger focusLogger = PlatformLogger.getLogger("sun.lwawt.macosx.focus.CPlatformWindow");
// for client properties // for client properties
public static final String WINDOW_BRUSH_METAL_LOOK = "apple.awt.brushMetalLook"; public static final String WINDOW_BRUSH_METAL_LOOK = "apple.awt.brushMetalLook";
...@@ -599,8 +600,21 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -599,8 +600,21 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
nativeSetNSWindowMinMax(nsWindowPtr, min.getWidth(), min.getHeight(), max.getWidth(), max.getHeight()); nativeSetNSWindowMinMax(nsWindowPtr, min.getWidth(), min.getHeight(), max.getWidth(), max.getHeight());
} }
@Override
public boolean rejectFocusRequest(CausedFocusEvent.Cause cause) {
// Cross-app activation requests are not allowed.
if (cause != CausedFocusEvent.Cause.MOUSE_EVENT &&
!((LWCToolkit)Toolkit.getDefaultToolkit()).isApplicationActive())
{
focusLogger.fine("the app is inactive, so the request is rejected");
return true;
}
return false;
}
@Override @Override
public boolean requestWindowFocus() { public boolean requestWindowFocus() {
long ptr = getNSWindowPtr(); long ptr = getNSWindowPtr();
if (CWrapper.NSWindow.canBecomeMainWindow(ptr)) { if (CWrapper.NSWindow.canBecomeMainWindow(ptr)) {
CWrapper.NSWindow.makeMainWindow(ptr); CWrapper.NSWindow.makeMainWindow(ptr);
......
...@@ -686,7 +686,10 @@ public class LWCToolkit extends LWToolkit { ...@@ -686,7 +686,10 @@ public class LWCToolkit extends LWToolkit {
return sunAwtDisableCALayers.booleanValue(); return sunAwtDisableCALayers.booleanValue();
} }
@Override
/*
* Returns true if the application (one of its windows) owns keyboard focus.
*/
public native boolean isApplicationActive(); public native boolean isApplicationActive();
/************************ /************************
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册