jdk/src/solaris/classes/sun/awt/X11/XEmbedClientHelper.java
author darcy
Thu, 13 Mar 2014 12:40:27 -0700
changeset 23647 41d22f2dbeb5
parent 23010 6dadb192ad81
permissions -rw-r--r--
8033712: Fix more serial lint warnings in sun.awt Reviewed-by: alanb, serb, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 18178
diff changeset
     2
 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. 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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4373
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4373
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4373
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4373
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4373
diff changeset
    23
 * questions.
2
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 sun.awt.SunToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Container;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 1974
diff changeset
    32
import sun.util.logging.PlatformLogger;
2
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 {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 1974
diff changeset
    43
    private static final PlatformLogger xembedLog = PlatformLogger.getLogger("sun.awt.X11.xembed.XEmbedClientHelper");
2
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) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
    56
        if (xembedLog.isLoggable(PlatformLogger.Level.FINE)) {
1974
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() {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
    70
        if (xembedLog.isLoggable(PlatformLogger.Level.FINE)) {
1974
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();
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
    98
        if (xembedLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
    99
            xembedLog.fine(msg.toString());
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   100
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        if (msg.get_message_type() == XEmbed.getAtom()) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   102
            if (xembedLog.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   103
                xembedLog.fine("Embedded message: " + msgidToString((int)msg.get_data(1)));
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13648
diff changeset
   104
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            switch ((int)msg.get_data(1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
              case XEMBED_EMBEDDED_NOTIFY: // Notification about embedding protocol start
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                  active = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                  server = getEmbedder(embedded, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                  // Check if window is reparented. If not - it was created with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                  // parent and so we should update it here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                  if (!embedded.isReparented()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                      embedded.setReparented(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                      embedded.updateSizeHints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                  embedded.notifyStarted();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
              case XEMBED_WINDOW_ACTIVATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                  applicationActive = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
              case XEMBED_WINDOW_DEACTIVATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                  if (applicationActive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                      applicationActive = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                      handleWindowFocusOut();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
              case XEMBED_FOCUS_IN: // We got focus!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                  // Check for direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                  handleFocusIn((int)msg.get_data(2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
              case XEMBED_FOCUS_OUT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                  if (applicationActive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                      handleWindowFocusOut();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    void handleFocusIn(int detail) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        if (embedded.focusAllowedFor()) {
4373
6a1c87e2876b 6903890: SWT_AWT focus issues when a dialog is shown/disposed, on X11
ant
parents: 3938
diff changeset
   140
            embedded.handleWindowFocusIn(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        switch(detail) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
          case XEMBED_FOCUS_CURRENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
              // Do nothing - just restore to the current value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
          case XEMBED_FOCUS_FIRST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
              SunToolkit.executeOnEventHandlerThread(embedded.target, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                      public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                          Component comp = ((Container)embedded.target).getFocusTraversalPolicy().getFirstComponent((Container)embedded.target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                          if (comp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                              comp.requestFocusInWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                      }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
          case XEMBED_FOCUS_LAST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
              SunToolkit.executeOnEventHandlerThread(embedded.target, new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                      public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                          Component comp = ((Container)embedded.target).getFocusTraversalPolicy().getLastComponent((Container)embedded.target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                          if (comp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                              comp.requestFocusInWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                      }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public void dispatchEvent(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        switch(xev.get_type()) {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 120
diff changeset
   169
          case XConstants.ClientMessage:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
              handleClientMessage(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
              break;
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 120
diff changeset
   172
          case XConstants.ReparentNotify:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
              handleReparentNotify(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    public void handleReparentNotify(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        XReparentEvent re = xev.get_xreparent();
1974
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   179
        long newParent = re.get_parent();
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   180
        if (active) {
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   181
            // unregister accelerators, etc. for old parent
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   182
            embedded.notifyStopped();
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   183
            // check if newParent is a root window
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   184
            X11GraphicsConfig gc = (X11GraphicsConfig)embedded.getGraphicsConfiguration();
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   185
            X11GraphicsDevice gd = (X11GraphicsDevice)gc.getDevice();
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   186
            if ((newParent == XlibUtil.getRootWindow(gd.getScreen())) ||
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   187
                (newParent == XToolkit.getDefaultRootWindow()))
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   188
            {
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   189
                // reparenting to root means XEmbed termination
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   190
                active = false;
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   191
            } else {
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   192
                // continue XEmbed with a new parent
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   193
                server = newParent;
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   194
                embedded.notifyStarted();
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   195
            }
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   196
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    boolean requestFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        if (active && embedded.focusAllowedFor()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            sendMessage(server, XEMBED_REQUEST_FOCUS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    void handleWindowFocusOut() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        // fix for 6269309: it is possible that we call this method twice
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        // (for example, when receiving XEMBED_WINDOW_DEACTIVATE and then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        // XEMBED_FOCUS_OUT client messages), so we first need to check if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        // embedded is an active window before sending WINDOW_LOST_FOCUS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        // to shared code
13648
90effcfc064f 7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents: 5506
diff changeset
   211
        if (XKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow() == embedded.target) {
4373
6a1c87e2876b 6903890: SWT_AWT focus issues when a dialog is shown/disposed, on X11
ant
parents: 3938
diff changeset
   212
            embedded.handleWindowFocusOut(null, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    long getEmbedder(XWindowPeer embedded, XClientMessageEvent info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        // Embedder is the parent of embedded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        return XlibUtil.getParentWindow(embedded.getWindow());
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 isApplicationActive() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        return applicationActive;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    boolean isActive() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        return active;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    void traverseOutForward() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        if (active) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            sendMessage(server, XEMBED_FOCUS_NEXT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    void traverseOutBackward() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        if (active) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            sendMessage(server, XEMBED_FOCUS_PREV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    void registerAccelerator(AWTKeyStroke stroke, int id) {
1974
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   242
        if (active) {
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   243
            long sym = getX11KeySym(stroke);
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   244
            long mods = getX11Mods(stroke);
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   245
            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
   246
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    void unregisterAccelerator(int id) {
1974
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   249
        if (active) {
1e1487c04864 6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents: 439
diff changeset
   250
            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
   251
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    long getX11KeySym(AWTKeyStroke stroke) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            return XWindow.getKeySymForAWTKeyCode(stroke.getKeyCode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    long getX11Mods(AWTKeyStroke stroke) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        return XWindow.getXModifiers(stroke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
}