diff options
author | Sven Gothel <[email protected]> | 2014-01-31 10:19:48 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-01-31 10:19:48 +0100 |
commit | f826663e9609b73783deea475872646242c8abb9 (patch) | |
tree | 64f60a686ffae66753bb62b7b135964e9b2fcc83 /plugin | |
parent | f5a0517ac704b36e3d94aa3d5547ddf95889ab95 (diff) |
ITW NPP: Pass window position through all layers, added as 'xpos' and 'ypos' in message and parameters ; ...
- Relative position of window maybe important in regards to overlapping applet windows
as well as for an upcoming OSX support.
However, client may still need to calculate the location on screen.
- Applet3Panel added toString()
- Applet3Panel, PluginApplet3Viewer: Better naming for browser notification
- appletResize -> browserSizeChanged, etc
Diffstat (limited to 'plugin')
5 files changed, 158 insertions, 39 deletions
diff --git a/plugin/icedteanp/IcedTeaNPPlugin.cc b/plugin/icedteanp/IcedTeaNPPlugin.cc index 1317831..500bd01 100644 --- a/plugin/icedteanp/IcedTeaNPPlugin.cc +++ b/plugin/icedteanp/IcedTeaNPPlugin.cc @@ -204,8 +204,8 @@ NPError get_proxy_info(const char* siteAddr, char** proxy, uint32_t* len); void consume_message(gchar* message); static void appletviewer_monitor(GPid pid, gint status, gpointer data); void plugin_send_initialization_message(char* instance, gulong handle, - int width, int height, - char* url); + int width, int height, int x, int y, + char* url); /* Returns JVM options set in itw-settings */ std::vector<std::string*>* get_jvm_args(); @@ -799,6 +799,7 @@ ITNP_SetWindow (NPP instance, NPWindow* window) if (jvm_up) { gboolean dim_changed = FALSE; + gboolean pos_changed = FALSE; // The window is the same as it was for the last // SetWindow call. @@ -823,9 +824,39 @@ ITNP_SetWindow (NPP instance, NPWindow* window) dim_changed = TRUE; } - if (dim_changed) { - gchar* message = g_strdup_printf ("instance %d width %d height %d", - id, window->width, window->height); + if (window->x != data->window_x) + { + PLUGIN_DEBUG ("ITNP_SetWindow: window x changed.\n"); + // The width of the plugin window has changed. + + // Store the new width. + data->window_x = window->x; + pos_changed = TRUE; + } + + if (window->y != data->window_y) + { + PLUGIN_DEBUG ("ITNP_SetWindow: window y changed.\n"); + // The height of the plugin window has changed. + + // Store the new height. + data->window_y = window->y; + + pos_changed = TRUE; + } + + if (dim_changed || pos_changed) { + gchar* message; + if( dim_changed && pos_changed ) { + message = g_strdup_printf ("instance %d set-sizepos xpos %d ypos %d width %d height %d", + id, window->x, window->y, window->width, window->height); + } else if( dim_changed ) { + message = g_strdup_printf ("instance %d set-size width %d height %d", + id, window->width, window->height); + } else { + message = g_strdup_printf ("instance %d set-pos xpos %d ypos %d", + id, window->x, window->y); + } plugin_send_message_to_appletviewer (message); g_free (message); message = NULL; @@ -861,11 +892,13 @@ ITNP_SetWindow (NPP instance, NPWindow* window) data->window_handle = window->window; data->window_width = window->width; data->window_height = window->height; + data->window_x = window->x; + data->window_y = window->y; // Now we have everything. Send this data to the Java side plugin_send_initialization_message( data->instance_id, (gulong) data->window_handle, - data->window_width, data->window_height, data->parameters_string); + data->window_width, data->window_height, data->window_x, data->window_y, data->parameters_string); g_mutex_unlock (data->appletviewer_mutex); @@ -1702,12 +1735,12 @@ void flush_plugin_send_message_to_appletviewer_console (){ */ void plugin_send_initialization_message(char* instance, gulong handle, - int width, int height, char* url) + int width, int height, int x, int y, char* url) { PLUGIN_DEBUG ("plugin_send_initialization_message\n"); - gchar *window_message = g_strdup_printf ("instance %s handle %ld width %d height %d %s", - instance, handle, width, height, url); + gchar *window_message = g_strdup_printf ("instance %s handle %ld xpos %d ypos %d width %d height %d %s", + instance, handle, x, y, width, height, url); plugin_send_message_to_appletviewer (window_message); g_free (window_message); window_message = NULL; @@ -2253,7 +2286,7 @@ get_scriptable_object(NPP instance) // a 0 handle if (!data->window_handle) { - plugin_send_initialization_message(data->instance_id, 0, 0, 0, data->parameters_string); + plugin_send_initialization_message(data->instance_id, 0, 0, 0, 0, 0, data->parameters_string); } java_result = java_request.getAppletObjectInstance(id_str); diff --git a/plugin/icedteanp/IcedTeaNPPlugin.h b/plugin/icedteanp/IcedTeaNPPlugin.h index 3e66599..2356abf 100644 --- a/plugin/icedteanp/IcedTeaNPPlugin.h +++ b/plugin/icedteanp/IcedTeaNPPlugin.h @@ -73,6 +73,10 @@ struct ITNPPluginData guint32 window_width; // The last plugin window height sent to us by the browser. guint32 window_height; + // The last plugin window x-coord sent to us by the browser. + gint32 window_x; + // The last plugin window y-coord sent to us by the browser. + gint32 window_y; // The source location for this instance std::string source; // If this is an actual applet instance, or a dummy instance for static calls @@ -86,6 +90,8 @@ struct ITNPPluginData window_handle = NULL; window_width = 0; window_height = 0; + window_x = 0; + window_y = 0; is_applet_instance = false; } ~ITNPPluginData() { diff --git a/plugin/icedteanp/java/jogamp/plugin/applet/PluginApplet3PanelFactory.java b/plugin/icedteanp/java/jogamp/plugin/applet/PluginApplet3PanelFactory.java index 3d141a4..dc1098d 100644 --- a/plugin/icedteanp/java/jogamp/plugin/applet/PluginApplet3PanelFactory.java +++ b/plugin/icedteanp/java/jogamp/plugin/applet/PluginApplet3PanelFactory.java @@ -86,14 +86,16 @@ public class PluginApplet3PanelFactory { final long nativeWindowHandle, final URL doc, final PluginParameters params) { + final int xpos = params.getX(); + final int ypos = params.getY(); final int width = params.getWidth(); final int height = params.getHeight(); PluginDebug.debug("NativeWindow (Browser) Handle: 0x" + Long.toHexString(nativeWindowHandle)); - PluginDebug.debug("NativeWindow (Browser) Size: " + width + " x " + height); + PluginDebug.debug("NativeWindow (Browser) Pos: "+xpos+" / "+ypos+", size: " + width + " x " + height); final NetxApplet3Panel panel = AccessController.doPrivileged(new PrivilegedAction<NetxApplet3Panel>() { @Override public NetxApplet3Panel run() { - NetxApplet3Panel panel = new NetxApplet3Panel(nativeWindowHandle, width, height, doc, params); + NetxApplet3Panel panel = new NetxApplet3Panel(nativeWindowHandle, xpos, ypos, width, height, doc, params); NetxApplet3Panel.debug("Using NetX panel"); PluginDebug.debug(params.toString()); return panel; diff --git a/plugin/icedteanp/java/jogamp/plugin/applet/PluginApplet3Viewer.java b/plugin/icedteanp/java/jogamp/plugin/applet/PluginApplet3Viewer.java index a123baa..6db065d 100644 --- a/plugin/icedteanp/java/jogamp/plugin/applet/PluginApplet3Viewer.java +++ b/plugin/icedteanp/java/jogamp/plugin/applet/PluginApplet3Viewer.java @@ -360,7 +360,7 @@ public class PluginApplet3Viewer implements Applet3Context, SplashController { requestFactory = rf; } - private static void handleInitializationMessage(int identifier, String message) throws IOException, LaunchException { + private static void handleInitializationMessage(final int identifier, final String origMessage) throws IOException, LaunchException { /* The user has specified via a global setting that applets should not be run.*/ if (AppletStartupSecuritySettings.getInstance().getSecurityLevel() == AppletSecurityLevel.DENY_ALL) { @@ -374,9 +374,10 @@ public class PluginApplet3Viewer implements Applet3Context, SplashController { return; } + String message = origMessage; // Extract the information from the message - String[] msgParts = new String[4]; - for (int i = 0; i < 3; i++) { + String[] msgParts = new String[6]; + for (int i = 0; i < 5; i++) { int spaceLocation = message.indexOf(' '); int nextSpaceLocation = message.indexOf(' ', spaceLocation + 1); msgParts[i] = message.substring(spaceLocation + 1, nextSpaceLocation); @@ -384,14 +385,19 @@ public class PluginApplet3Viewer implements Applet3Context, SplashController { } final long nativeWindowHandle = Long.parseLong(msgParts[0]); - String width = msgParts[1]; - String height = msgParts[2]; + final String xpos = msgParts[1]; + final String ypos = msgParts[2]; + final String width = msgParts[3]; + final String height = msgParts[4]; int spaceLocation = message.indexOf(' ', "tag".length() + 1); String documentBase = message.substring("tag".length() + 1, spaceLocation); String paramString = message.substring(spaceLocation + 1); - PluginDebug.debug("Handle = 0x", Long.toHexString(nativeWindowHandle), "\n", + PluginDebug.debug("Message = <", origMessage, ">\n", + "handle = 0x", Long.toHexString(nativeWindowHandle), "\n", + "xpos = ", xpos, "\n", + "ypos = ", ypos, "\n", "Width = ", width, "\n", "Height = ", height, "\n", "DocumentBase = ", documentBase, "\n", @@ -406,7 +412,7 @@ public class PluginApplet3Viewer implements Applet3Context, SplashController { */ url = conn.getURL(); - PluginParameters params = new PluginParameterParser().parse(width, height, paramString); + PluginParameters params = new PluginParameterParser().parse(xpos, ypos, width, height, paramString); // Let user know we are starting up streamhandler.write("instance " + identifier + " status " + amh.getMessage("status.start")); @@ -612,28 +618,84 @@ public class PluginApplet3Viewer implements Applet3Context, SplashController { } public void handleMessage(int reference, String message) { - if (message.startsWith("width")) { + if (message.startsWith("set-sizepos")) { - // 0 => width, 1=> width_value, 2 => height, 3=> height_value - String[] dimMsg = message.split(" "); + // 0 => set-sizepos + // 1 => xpos, 2 => xpos_value, 3 => ypos, 4 => ypos_value + // 5 => width, 6 => width_value, 7 => height, 8 => height_value + final String[] dimMsg = message.split(" "); - final int width = Integer.parseInt(dimMsg[1]); - final int height = Integer.parseInt(dimMsg[3]); + final int xpos= Integer.parseInt(dimMsg[2]); + final int ypos= Integer.parseInt(dimMsg[4]); + final int width = Integer.parseInt(dimMsg[6]); + final int height = Integer.parseInt(dimMsg[8]); + + PluginDebug.debug("Applet panel ", panel, " set-sizepos ", xpos, " / ", ypos, width, " x ", height, " - ", message); + + /* Resize and reposition the applet asynchronously, to avoid the chance of + * deadlock while waiting for the applet to initialize. + * + * In general, worker threads should spawn new threads for any blocking operations. */ + final Thread resizeposAppletThread = new Thread("resizeposAppletThread") { + @Override + public void run() { + browserSizePosChanged(xpos, ypos, width, height); + } + }; + + /* Let it eventually complete */ + resizeposAppletThread.start(); + + } else if (message.startsWith("set-size")) { + + // 0 => set-size + // 1 => width, 2 => width_value, 3 => height, 4 => height_value + final String[] dimMsg = message.split(" "); + + final int width = Integer.parseInt(dimMsg[2]); + final int height = Integer.parseInt(dimMsg[4]); + + PluginDebug.debug("Applet panel ", panel, " set-size ", width, " x ", height, " - ", message); /* Resize the applet asynchronously, to avoid the chance of * deadlock while waiting for the applet to initialize. * * In general, worker threads should spawn new threads for any blocking operations. */ - Thread resizeAppletThread = new Thread("resizeAppletThread") { + final Thread resizeAppletThread = new Thread("resizeAppletThread") { @Override public void run() { - resize(width, height); + browserSizeChanged(width, height); } }; /* Let it eventually complete */ resizeAppletThread.start(); + } else if (message.startsWith("set-pos")) { + + // 0 => set-pos + // 1 => xpos, 2 => xpos_value, 3 => ypos, 4 => ypos_value + final String[] dimMsg = message.split(" "); + + final int xpos= Integer.parseInt(dimMsg[2]); + final int ypos= Integer.parseInt(dimMsg[4]); + + PluginDebug.debug("Applet panel ", panel, " set-size ", xpos, " / ", ypos, " - ", message); + + /* Reposition the applet asynchronously, to avoid the chance of + * deadlock while waiting for the applet to initialize. + * + * In general, worker threads should spawn new threads for any blocking operations. */ + final Thread reposAppletThread = new Thread("reposAppletThread") { + @Override + public void run() { + browserPositionChanged(xpos, ypos); + } + }; + + /* Let it eventually complete */ + reposAppletThread.start(); + } else if (message.startsWith("GetJavaObject")) { // FIXME: how do we determine what security context this @@ -765,19 +827,35 @@ public class PluginApplet3Viewer implements Applet3Context, SplashController { })); } */ - appletResize(width, height); + browserSizeChanged(width, height); } /** - * Called when the applet wants to be resized. - * - * @param width the new requested width for the applet. - * @param height the new requested height for the applet. + * Called when the applet needs to be resized. + */ + public void browserSizePosChanged(int x, int y, int width, int height) { + // Wait for panel to come alive + waitForAppletInit(panel); + panel.browserPositionChanged(x, y); + panel.browserSizeChanged(width, height); + } + + /** + * Called when the applet needs to be resized. + */ + public void browserSizeChanged(int width, int height) { + // Wait for panel to come alive + waitForAppletInit(panel); + panel.browserSizeChanged(width, height); + } + + /** + * Called when the applet needs to be informed about about position change. */ - public void appletResize(int width, int height) { + public void browserPositionChanged(int x, int y) { // Wait for panel to come alive waitForAppletInit(panel); - panel.appletResize(width, height); + panel.browserPositionChanged(x, y); } @Override diff --git a/plugin/icedteanp/java/sun/applet/PluginParameterParser.java b/plugin/icedteanp/java/sun/applet/PluginParameterParser.java index 56dabc9..51ffc9e 100644 --- a/plugin/icedteanp/java/sun/applet/PluginParameterParser.java +++ b/plugin/icedteanp/java/sun/applet/PluginParameterParser.java @@ -1,6 +1,5 @@ package sun.applet; -import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -69,16 +68,15 @@ public class PluginParameterParser { } /** - * Parsers parameters given a string containing + * Parsers parameters given a string containing * parameters in quotes. - * * @param width default applet width * @param height default applet height - * @param parameterString the parameters + * @param parameterString the parameters + * * @return the attributes in a hash table */ - public PluginParameters parse(String width, - String height, String parameterString) { + public PluginParameters parse(String xpos, String ypos, String width, String height, String parameterString) { Map<String, String> params = parseEscapedKeyValuePairs(parameterString); if (params.get("width") == null || !isInt(params.get("width"))) { @@ -88,6 +86,8 @@ public class PluginParameterParser { if (params.get("height") == null || !isInt(params.get("height"))) { params.put("height", height); } + params.put("xpos", xpos); + params.put("ypos", ypos); return new PluginParameters(params); } |