jdk/src/solaris/classes/sun/awt/X11/XEmbedClientHelper.java
author dcherepanov
Thu, 12 Feb 2009 18:24:35 +0300
changeset 2453 35e5fab82613
parent 1974 1e1487c04864
child 3938 ef327bd847c0
permissions -rw-r--r--
6724890: Deadlock between AWT-EventQueue-1 and AWT-XAWT threads during IDE start Reviewed-by: art, ant
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 120
diff changeset
     2
 * Copyright 2003-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.AWTKeyStroke;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.logging.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.awt.SunToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.Container;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
1974
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    34
import sun.awt.X11GraphicsConfig;
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    35
import sun.awt.X11GraphicsDevice;
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    36
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * Helper class implementing XEmbed protocol handling routines(client side)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * Window which wants to participate in a protocol should create an instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * call install and forward all XClientMessageEvents to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
public class XEmbedClientHelper extends XEmbedHelper implements XEventDispatcher {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private static final Logger xembedLog = Logger.getLogger("sun.awt.X11.xembed.XEmbedClientHelper");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
1974
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    45
    private XEmbeddedFramePeer embedded; // XEmbed client
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    46
    private long server; // XEmbed server
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    47
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private boolean active;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private boolean applicationActive;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    XEmbedClientHelper() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
1974
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    55
    void setClient(XEmbeddedFramePeer client) {
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    56
        if (xembedLog.isLoggable(Level.FINE)) {
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    57
            xembedLog.fine("XEmbed client: " + client);
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    58
        }
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    59
        if (embedded != null) {
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    60
            XToolkit.removeEventDispatcher(embedded.getWindow(), this);
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    61
            active = false;
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    62
        }
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    63
        embedded = client;
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    64
        if (embedded != null) {
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    65
            XToolkit.addEventDispatcher(embedded.getWindow(), this);
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    66
        }
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    67
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
1974
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    69
    void install() {
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    70
        if (xembedLog.isLoggable(Level.FINE)) {
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    71
            xembedLog.fine("Installing xembedder on " + embedded);
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
    72
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        long[] info = new long[] { XEMBED_VERSION, XEMBED_MAPPED };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        long data = Native.card32ToData(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            XEmbedInfo.setAtomData(embedded.getWindow(), data, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            unsafe.freeMemory(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        // XEmbeddedFrame is initially created with a null parent..
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        // Here it is reparented to the proper parent window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        long parentWindow = embedded.getParentWindowHandle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        if (parentWindow != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                XlibWrapper.XReparentWindow(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                                            embedded.getWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                                            parentWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                                            0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    void handleClientMessage(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        XClientMessageEvent msg = xev.get_xclient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        if (xembedLog.isLoggable(Level.FINE)) xembedLog.fine(msg.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        if (msg.get_message_type() == XEmbed.getAtom()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            if (xembedLog.isLoggable(Level.FINE)) xembedLog.fine("Embedded message: " + msgidToString((int)msg.get_data(1)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            switch ((int)msg.get_data(1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
              case XEMBED_EMBEDDED_NOTIFY: // Notification about embedding protocol start
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                  active = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                  server = getEmbedder(embedded, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                  // Check if window is reparented. If not - it was created with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                  // parent and so we should update it here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                  if (!embedded.isReparented()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                      embedded.setReparented(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                      embedded.updateSizeHints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                  embedded.notifyStarted();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
              case XEMBED_WINDOW_ACTIVATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                  applicationActive = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
              case XEMBED_WINDOW_DEACTIVATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                  if (applicationActive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                      applicationActive = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                      handleWindowFocusOut();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
              case XEMBED_FOCUS_IN: // We got focus!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                  // Check for direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                  handleFocusIn((int)msg.get_data(2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
              case XEMBED_FOCUS_OUT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                  if (applicationActive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                      handleWindowFocusOut();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    void handleFocusIn(int detail) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        if (embedded.focusAllowedFor()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            embedded.handleWindowFocusInSync(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        switch(detail) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
          case XEMBED_FOCUS_CURRENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
              // Do nothing - just restore to the current value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
          case XEMBED_FOCUS_FIRST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
              SunToolkit.executeOnEventHandlerThread(embedded.target, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                      public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                          Component comp = ((Container)embedded.target).getFocusTraversalPolicy().getFirstComponent((Container)embedded.target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                          if (comp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                              comp.requestFocusInWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                      }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
          case XEMBED_FOCUS_LAST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
              SunToolkit.executeOnEventHandlerThread(embedded.target, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                      public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                          Component comp = ((Container)embedded.target).getFocusTraversalPolicy().getLastComponent((Container)embedded.target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                          if (comp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                              comp.requestFocusInWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                      }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public void dispatchEvent(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        switch(xev.get_type()) {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 120
diff changeset
   165
          case XConstants.ClientMessage:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
              handleClientMessage(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
              break;
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 120
diff changeset
   168
          case XConstants.ReparentNotify:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
              handleReparentNotify(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public void handleReparentNotify(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        XReparentEvent re = xev.get_xreparent();
1974
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   175
        long newParent = re.get_parent();
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   176
        if (active) {
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   177
            // unregister accelerators, etc. for old parent
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   178
            embedded.notifyStopped();
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   179
            // check if newParent is a root window
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   180
            X11GraphicsConfig gc = (X11GraphicsConfig)embedded.getGraphicsConfiguration();
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   181
            X11GraphicsDevice gd = (X11GraphicsDevice)gc.getDevice();
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   182
            if ((newParent == XlibUtil.getRootWindow(gd.getScreen())) ||
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   183
                (newParent == XToolkit.getDefaultRootWindow()))
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   184
            {
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   185
                // reparenting to root means XEmbed termination
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   186
                active = false;
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   187
            } else {
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   188
                // continue XEmbed with a new parent
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   189
                server = newParent;
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   190
                embedded.notifyStarted();
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   191
            }
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   192
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    boolean requestFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        if (active && embedded.focusAllowedFor()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            sendMessage(server, XEMBED_REQUEST_FOCUS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    void handleWindowFocusOut() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        // fix for 6269309: it is possible that we call this method twice
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        // (for example, when receiving XEMBED_WINDOW_DEACTIVATE and then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        // XEMBED_FOCUS_OUT client messages), so we first need to check if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        // embedded is an active window before sending WINDOW_LOST_FOCUS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        // to shared code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        if (XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow() == embedded.target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            embedded.handleWindowFocusOutSync(null, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    long getEmbedder(XWindowPeer embedded, XClientMessageEvent info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        // Embedder is the parent of embedded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        return XlibUtil.getParentWindow(embedded.getWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    boolean isApplicationActive() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        return applicationActive;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    boolean isActive() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        return active;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    void traverseOutForward() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        if (active) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            sendMessage(server, XEMBED_FOCUS_NEXT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    void traverseOutBackward() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        if (active) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            sendMessage(server, XEMBED_FOCUS_PREV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    void registerAccelerator(AWTKeyStroke stroke, int id) {
1974
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   238
        if (active) {
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   239
            long sym = getX11KeySym(stroke);
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   240
            long mods = getX11Mods(stroke);
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   241
            sendMessage(server, XEMBED_REGISTER_ACCELERATOR, id, sym, mods);
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   242
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    void unregisterAccelerator(int id) {
1974
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   245
        if (active) {
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   246
            sendMessage(server, XEMBED_UNREGISTER_ACCELERATOR, id, 0, 0);
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   247
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    long getX11KeySym(AWTKeyStroke stroke) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            return XWindow.getKeySymForAWTKeyCode(stroke.getKeyCode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    long getX11Mods(AWTKeyStroke stroke) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        return XWindow.getXModifiers(stroke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
}