8044516: [macosx] ScreenPopupFactory uses native method that could be avoided
Reviewed-by: anthony, serb
--- a/jdk/src/macosx/classes/com/apple/laf/ScreenPopupFactory.java Thu Jun 05 23:17:05 2014 -0700
+++ b/jdk/src/macosx/classes/com/apple/laf/ScreenPopupFactory.java Fri Jun 06 13:52:49 2014 +0400
@@ -29,18 +29,9 @@
import javax.swing.*;
import sun.lwawt.macosx.CPlatformWindow;
+import sun.swing.SwingAccessor;
class ScreenPopupFactory extends PopupFactory {
- static {
- java.security.AccessController.doPrivileged(
- new java.security.PrivilegedAction<Void>() {
- public Void run() {
- System.loadLibrary("osxui");
- return null;
- }
- });
- }
-
static final Float TRANSLUCENT = new Float(248f/255f);
static final Float OPAQUE = new Float(1.0f);
@@ -59,19 +50,13 @@
return (Window)w;
}
- /*
- * Since we can't change the signature of PopupFactory, we have to call the
- * private method getPopup(Component, Component, int, int, int) through JNI
- * (see AquaLookAndFeel.m)
- */
- native Popup _getHeavyWeightPopup(Component comp, Component invoker, int x, int y);
-
public Popup getPopup(final Component comp, final Component invoker, final int x, final int y) {
if (invoker == null) throw new IllegalArgumentException("Popup.getPopup must be passed non-null contents");
final Popup popup;
if (fIsActive) {
- popup = _getHeavyWeightPopup(comp, invoker, x, y);
+ popup = SwingAccessor.getPopupFactoryAccessor()
+ .getHeavyWeightPopup(this, comp, invoker, x, y);
} else {
popup = super.getPopup(comp, invoker, x, y);
}
--- a/jdk/src/macosx/native/com/apple/laf/ScreenPopupFactory.m Thu Jun 05 23:17:05 2014 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-#import "com_apple_laf_ScreenPopupFactory.h"
-#import <JavaNativeFoundation/JavaNativeFoundation.h>
-
-static JNF_CLASS_CACHE(sjc_PopupFactory, "javax/swing/PopupFactory");
-static JNF_MEMBER_CACHE(jm_getPopup, sjc_PopupFactory, "getPopup", "(Ljava/awt/Component;Ljava/awt/Component;III)Ljavax/swing/Popup;");
-
-/*
- * Class: com_apple_laf_ScreenPopupFactory
- * Method: _getHeavyWeightPopup
- * Signature: (Ljava/awt/Component;Ljava/awt/Component;II)Ljavax/swing/Popup;
- */
-JNIEXPORT jobject /* javax.swing.Popup */ JNICALL Java_com_apple_laf_ScreenPopupFactory__1getHeavyWeightPopup
-(JNIEnv *env, jobject screenPopupFactory, jobject comp, jobject invoker, jint x, jint y) {
- jobject popup;
-JNF_COCOA_ENTER(env);
- popup = JNFCallObjectMethod(env, screenPopupFactory, jm_getPopup, comp, invoker, x, y, 2);
-JNF_COCOA_EXIT(env);
- return popup;
-}
--- a/jdk/src/share/classes/javax/swing/PopupFactory.java Thu Jun 05 23:17:05 2014 -0700
+++ b/jdk/src/share/classes/javax/swing/PopupFactory.java Fri Jun 06 13:52:49 2014 +0400
@@ -27,6 +27,7 @@
import sun.awt.EmbeddedFrame;
import sun.awt.OSInfo;
+import sun.swing.SwingAccessor;
import java.applet.Applet;
import java.awt.*;
@@ -60,6 +61,16 @@
* @since 1.4
*/
public class PopupFactory {
+
+ static {
+ SwingAccessor.setPopupFactoryAccessor(new SwingAccessor.PopupFactoryAccessor() {
+ @Override
+ public Popup getHeavyWeightPopup(PopupFactory factory, Component owner,
+ Component contents, int ownerX, int ownerY) {
+ return factory.getPopup(owner, contents, ownerX, ownerY, HEAVY_WEIGHT_POPUP);
+ }
+ });
+ }
/**
* The shared instanceof <code>PopupFactory</code> is per
* <code>AppContext</code>. This is the key used in the
--- a/jdk/src/share/classes/sun/swing/SwingAccessor.java Thu Jun 05 23:17:05 2014 -0700
+++ b/jdk/src/share/classes/sun/swing/SwingAccessor.java Fri Jun 06 13:52:49 2014 +0400
@@ -27,11 +27,10 @@
import sun.misc.Unsafe;
-import java.awt.Point;
-import javax.swing.RepaintManager;
+import java.awt.*;
+import javax.swing.*;
import javax.swing.text.JTextComponent;
-import javax.swing.TransferHandler;
/**
* The SwingAccessor utility class.
@@ -91,6 +90,14 @@
}
/**
+ * An accessor for PopupFactory class.
+ */
+ public interface PopupFactoryAccessor {
+ Popup getHeavyWeightPopup(PopupFactory factory, Component owner, Component contents,
+ int ownerX, int ownerY);
+ }
+
+ /**
* The javax.swing.text.JTextComponent class accessor object.
*/
private static JTextComponentAccessor jtextComponentAccessor;
@@ -156,4 +163,26 @@
}
return repaintManagerAccessor;
}
+
+ /**
+ * The PopupFactory class accessor object.
+ */
+ private static PopupFactoryAccessor popupFactoryAccessor;
+
+ /**
+ * Retrieve the accessor object for the PopupFactory class.
+ */
+ public static PopupFactoryAccessor getPopupFactoryAccessor() {
+ if (popupFactoryAccessor == null) {
+ unsafe.ensureClassInitialized(PopupFactory.class);
+ }
+ return popupFactoryAccessor;
+ }
+
+ /**
+ * Set an Accessor object for the PopupFactory class.
+ */
+ public static void setPopupFactoryAccessor(PopupFactoryAccessor popupFactoryAccessor) {
+ SwingAccessor.popupFactoryAccessor = popupFactoryAccessor;
+ }
}