jdk/src/java.desktop/unix/classes/sun/awt/X11/XDropTargetRegistry.java
author ddehaven
Tue, 19 Aug 2014 10:32:16 -0700
changeset 26037 508779ce6619
parent 26004 jdk/src/solaris/classes/sun/awt/X11/XDropTargetRegistry.java@7507a1b93f67
parent 25859 jdk/src/solaris/classes/sun/awt/X11/XDropTargetRegistry.java@3317bb8137f4
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21278
diff changeset
     2
 * Copyright (c) 2003, 2014, 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: 4259
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: 4259
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: 4259
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4259
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4259
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.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.List;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
    34
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.Point;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * The class responsible for registration/deregistration of drop sites.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
final class XDropTargetRegistry {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
    45
    private static final PlatformLogger logger =
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
    46
        PlatformLogger.getLogger("sun.awt.X11.xembed.xdnd.XDropTargetRegistry");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private static final long DELAYED_REGISTRATION_PERIOD = 200;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private static final XDropTargetRegistry theInstance =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        new XDropTargetRegistry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private final HashMap<Long, Runnable> delayedRegistrationMap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        new HashMap<Long, Runnable>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private XDropTargetRegistry() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    static XDropTargetRegistry getRegistry() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        return theInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * Returns the XID of the topmost window with WM_STATE set in the ancestor
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 18178
diff changeset
    64
     * hierarchy of the specified window or 0 if none found.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private long getToplevelWindow(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        XBaseWindow candWindow = XToolkit.windowToXWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        if (candWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            XWindowPeer toplevel = candWindow.getToplevelXWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            if (toplevel != null && !(toplevel instanceof XEmbeddedFramePeer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                return toplevel.getWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        /* Traverse the ancestor tree from window up to the root and find
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
           the top-level client window nearest to the root. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            if (XlibUtil.isTrueToplevelWindow(window)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                return window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            window = XlibUtil.getParentWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        } while (window != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        return window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
26004
7507a1b93f67 6521783: Unnecessary final modifier for a method in a final class
serb
parents: 24538
diff changeset
    89
    static long getDnDProxyWindow() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        return XWindow.getXAWTRootWindow().getWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private static final class EmbeddedDropSiteEntry {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        private final long root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        private final long event_mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        private List<XDropTargetProtocol> supportedProtocols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        private final HashSet<Long> nonXEmbedClientSites = new HashSet<Long>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        private final List<Long> sites = new ArrayList<Long>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        public EmbeddedDropSiteEntry(long root, long event_mask,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                                     List<XDropTargetProtocol> supportedProtocols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            if (supportedProtocols == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                throw new NullPointerException("Null supportedProtocols");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            this.root = root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            this.event_mask = event_mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            this.supportedProtocols = supportedProtocols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        public long getRoot() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            return root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        public long getEventMask() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            return event_mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        public boolean hasNonXEmbedClientSites() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            return !nonXEmbedClientSites.isEmpty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        public synchronized void addSite(long window, boolean isXEmbedClient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            Long lWindow = Long.valueOf(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            if (!sites.contains(lWindow)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                sites.add(lWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            if (!isXEmbedClient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                nonXEmbedClientSites.add(lWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        public synchronized void removeSite(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            Long lWindow = Long.valueOf(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            sites.remove(lWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            nonXEmbedClientSites.remove(lWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        public void setSupportedProtocols(List<XDropTargetProtocol> list) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            supportedProtocols = list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        public List<XDropTargetProtocol> getSupportedProtocols() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            return supportedProtocols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        public boolean hasSites() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            return !sites.isEmpty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        public long[] getSites() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            long[] ret = new long[sites.size()];
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22584
diff changeset
   144
            Iterator<Long> iter = sites.iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            while (iter.hasNext()) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22584
diff changeset
   147
                Long l = iter.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                ret[index++] = l.longValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        public long getSite(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            Iterator<Long> iter = sites.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            while (iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                Long l = iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                long window = l.longValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                Point p = XBaseWindow.toOtherWindow(getRoot(), window, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                if (p == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                int dest_x = p.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                int dest_y = p.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                if (dest_x >= 0 && dest_y >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                    XWindowAttributes wattr = new XWindowAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                    try {
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 5506
diff changeset
   171
                        XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.IgnoreBadWindowHandler.getInstance());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                        int status = XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                                                                      window, wattr.pData);
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 5506
diff changeset
   174
                        XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 5506
diff changeset
   176
                        if ((status == 0) ||
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 5506
diff changeset
   177
                            ((XErrorHandlerUtil.saved_error != null) &&
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 5506
diff changeset
   178
                            (XErrorHandlerUtil.saved_error.get_error_code() != XConstants.Success))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 438
diff changeset
   182
                        if (wattr.get_map_state() != XConstants.IsUnmapped
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                            && dest_x < wattr.get_width()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                            && dest_y < wattr.get_height()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                            return window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                    } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                        wattr.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    private final HashMap<Long, EmbeddedDropSiteEntry> embeddedDropSiteRegistry =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        new HashMap<Long, EmbeddedDropSiteEntry>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    private EmbeddedDropSiteEntry registerEmbedderDropSite(long embedder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22584
diff changeset
   202
        Iterator<XDropTargetProtocol> dropTargetProtocols =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            XDragAndDropProtocols.getDropTargetProtocols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        // The list of protocols supported by the embedder.
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22584
diff changeset
   205
        List<XDropTargetProtocol> embedderProtocols = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        while (dropTargetProtocols.hasNext()) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22584
diff changeset
   208
            XDropTargetProtocol dropTargetProtocol = dropTargetProtocols.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            if (dropTargetProtocol.isProtocolSupported(embedder)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                embedderProtocols.add(dropTargetProtocol);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        embedderProtocols = Collections.unmodifiableList(embedderProtocols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        /* Grab server, since we are working with the window that belongs to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
           another client. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        XlibWrapper.XGrabServer(XToolkit.getDisplay());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            long root = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            long event_mask = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            XWindowAttributes wattr = new XWindowAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            try {
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 5506
diff changeset
   224
                XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.IgnoreBadWindowHandler.getInstance());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                int status = XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                                                              embedder, wattr.pData);
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 5506
diff changeset
   227
                XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 5506
diff changeset
   229
                if ((status == 0) ||
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 5506
diff changeset
   230
                    ((XErrorHandlerUtil.saved_error != null) &&
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 5506
diff changeset
   231
                    (XErrorHandlerUtil.saved_error.get_error_code() != XConstants.Success))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                    throw new XException("XGetWindowAttributes failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                event_mask = wattr.get_your_event_mask();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                root = wattr.get_root();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                wattr.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 438
diff changeset
   241
            if ((event_mask & XConstants.PropertyChangeMask) == 0) {
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 5506
diff changeset
   242
                XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.IgnoreBadWindowHandler.getInstance());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                XlibWrapper.XSelectInput(XToolkit.getDisplay(), embedder,
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 438
diff changeset
   244
                                         event_mask | XConstants.PropertyChangeMask);
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 5506
diff changeset
   245
                XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 5506
diff changeset
   247
                if ((XErrorHandlerUtil.saved_error != null) &&
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 5506
diff changeset
   248
                    (XErrorHandlerUtil.saved_error.get_error_code() != XConstants.Success)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                    throw new XException("XSelectInput failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            return new EmbeddedDropSiteEntry(root, event_mask, embedderProtocols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            XlibWrapper.XUngrabServer(XToolkit.getDisplay());
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
    private static final boolean XEMBED_PROTOCOLS = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    private static final boolean NON_XEMBED_PROTOCOLS = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    private void registerProtocols(long embedder, boolean protocols,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                                   List<XDropTargetProtocol> supportedProtocols) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22584
diff changeset
   264
        Iterator<XDropTargetProtocol> dropTargetProtocols = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
         * By default, we register a drop site that supports all dnd
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
         * protocols. This approach is not appropriate in plugin
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
         * scenario if the browser supports Motif DnD and doesn't support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
         * XDnD. If we forcibly set XdndAware on the browser toplevel, any drag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
         * source that supports both protocols and prefers XDnD will be unable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
         * to drop anything on the browser.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
         * The solution for this problem is not to register XDnD drop site
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
         * if the browser supports only Motif DnD.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
         * In general, if the browser already supports some protocols, we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
         * register the embedded drop site only for those protocols. Otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
         * we register the embedded drop site for all protocols.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        if (!supportedProtocols.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            dropTargetProtocols = supportedProtocols.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            dropTargetProtocols =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                XDragAndDropProtocols.getDropTargetProtocols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        /* Grab server, since we are working with the window that belongs to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
           another client. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        XlibWrapper.XGrabServer(XToolkit.getDisplay());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            while (dropTargetProtocols.hasNext()) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22584
diff changeset
   291
                XDropTargetProtocol dropTargetProtocol = dropTargetProtocols.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                if ((protocols == XEMBED_PROTOCOLS) ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                    dropTargetProtocol.isXEmbedSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                    dropTargetProtocol.registerEmbedderDropSite(embedder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            XlibWrapper.XUngrabServer(XToolkit.getDisplay());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    public void updateEmbedderDropSite(long embedder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        XBaseWindow xbaseWindow = XToolkit.windowToXWindow(embedder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        // No need to update our own drop sites.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        if (xbaseWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22584
diff changeset
   311
        Iterator<XDropTargetProtocol> dropTargetProtocols =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            XDragAndDropProtocols.getDropTargetProtocols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        // The list of protocols supported by the embedder.
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22584
diff changeset
   314
        List<XDropTargetProtocol> embedderProtocols = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        while (dropTargetProtocols.hasNext()) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22584
diff changeset
   317
            XDropTargetProtocol dropTargetProtocol = dropTargetProtocols.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            if (dropTargetProtocol.isProtocolSupported(embedder)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                embedderProtocols.add(dropTargetProtocol);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        embedderProtocols = Collections.unmodifiableList(embedderProtocols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   325
        Long lToplevel = Long.valueOf(embedder);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        boolean isXEmbedServer = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        synchronized (this) {
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21278
diff changeset
   328
            EmbeddedDropSiteEntry entry = embeddedDropSiteRegistry.get(lToplevel);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            if (entry == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            entry.setSupportedProtocols(embedderProtocols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            isXEmbedServer = !entry.hasNonXEmbedClientSites();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
         * By default, we register a drop site that supports all dnd
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
         * protocols. This approach is not appropriate in plugin
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
         * scenario if the browser supports Motif DnD and doesn't support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
         * XDnD. If we forcibly set XdndAware on the browser toplevel, any drag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
         * source that supports both protocols and prefers XDnD will be unable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
         * to drop anything on the browser.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
         * The solution for this problem is not to register XDnD drop site
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
         * if the browser supports only Motif DnD.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
         * In general, if the browser already supports some protocols, we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
         * register the embedded drop site only for those protocols. Otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
         * we register the embedded drop site for all protocols.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        if (!embedderProtocols.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            dropTargetProtocols = embedderProtocols.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            dropTargetProtocols =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                XDragAndDropProtocols.getDropTargetProtocols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        /* Grab server, since we are working with the window that belongs to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
           another client. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        XlibWrapper.XGrabServer(XToolkit.getDisplay());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            while (dropTargetProtocols.hasNext()) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22584
diff changeset
   361
                XDropTargetProtocol dropTargetProtocol = dropTargetProtocols.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                if (!isXEmbedServer || !dropTargetProtocol.isXEmbedSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                    dropTargetProtocol.registerEmbedderDropSite(embedder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            XlibWrapper.XUngrabServer(XToolkit.getDisplay());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    private void unregisterEmbedderDropSite(long embedder,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                                            EmbeddedDropSiteEntry entry) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        assert XToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22584
diff changeset
   375
        Iterator<XDropTargetProtocol> dropTargetProtocols =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            XDragAndDropProtocols.getDropTargetProtocols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        /* Grab server, since we are working with the window that belongs to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
           another client. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        XlibWrapper.XGrabServer(XToolkit.getDisplay());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            while (dropTargetProtocols.hasNext()) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22584
diff changeset
   383
                XDropTargetProtocol dropTargetProtocol = dropTargetProtocols.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                dropTargetProtocol.unregisterEmbedderDropSite(embedder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            long event_mask = entry.getEventMask();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            /* Restore the original event mask for the embedder. */
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 438
diff changeset
   390
            if ((event_mask & XConstants.PropertyChangeMask) == 0) {
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 5506
diff changeset
   391
                XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.IgnoreBadWindowHandler.getInstance());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                XlibWrapper.XSelectInput(XToolkit.getDisplay(), embedder,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                                         event_mask);
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 5506
diff changeset
   394
                XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 5506
diff changeset
   396
                if ((XErrorHandlerUtil.saved_error != null) &&
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 5506
diff changeset
   397
                    (XErrorHandlerUtil.saved_error.get_error_code() != XConstants.Success)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                    throw new XException("XSelectInput failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            XlibWrapper.XUngrabServer(XToolkit.getDisplay());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    private void registerEmbeddedDropSite(long toplevel, long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        XBaseWindow xBaseWindow = XToolkit.windowToXWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        boolean isXEmbedClient =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            (xBaseWindow instanceof XEmbeddedFramePeer) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            ((XEmbeddedFramePeer)xBaseWindow).isXEmbedActive();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        XEmbedCanvasPeer peer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            XBaseWindow xbaseWindow = XToolkit.windowToXWindow(toplevel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            if (xbaseWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                if (xbaseWindow instanceof XEmbedCanvasPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                    peer = (XEmbedCanvasPeer)xbaseWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                    throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        Long lToplevel = Long.valueOf(toplevel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        EmbeddedDropSiteEntry entry = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        synchronized (this) {
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21278
diff changeset
   427
            entry = embeddedDropSiteRegistry.get(lToplevel);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            if (entry == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                    // Toplevel is an XEmbed server within this VM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                    // Register an XEmbed drop site.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                    peer.setXEmbedDropTarget();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                    // Create a dummy entry to register the embedded site.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                    entry = new EmbeddedDropSiteEntry(0, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                                                      Collections.<XDropTargetProtocol>emptyList());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                    // Foreign toplevel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                    // Select for PropertyNotify events on the toplevel, so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                    // we can track changes of the properties relevant to DnD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                    // protocols.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                    entry = registerEmbedderDropSite(toplevel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                    // Register the toplevel with all DnD protocols that are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                    // supported by XEmbed - actually setup a proxy, so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                    // all DnD notifications sent to the toplevel are first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                    // routed to us.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                    registerProtocols(toplevel, NON_XEMBED_PROTOCOLS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                                      entry.getSupportedProtocols());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                embeddedDropSiteRegistry.put(lToplevel, entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        assert entry != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        synchronized (entry) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            // For a foreign toplevel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            if (peer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                if (!isXEmbedClient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                    // Since this is not an XEmbed client we can no longer rely
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                    // on XEmbed to route DnD notifications even for DnD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                    // protocols that are supported by XEmbed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                    // We rollback to the XEmbed-unfriendly solution - setup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                    // a proxy, so that all DnD notifications sent to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                    // toplevel are first routed to us.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                    registerProtocols(toplevel, XEMBED_PROTOCOLS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                                      entry.getSupportedProtocols());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                } else {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22584
diff changeset
   468
                    Iterator<XDropTargetProtocol> dropTargetProtocols =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                        XDragAndDropProtocols.getDropTargetProtocols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                    // Register the embedded window as a plain drop site with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                    // all DnD protocols that are supported by XEmbed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                    while (dropTargetProtocols.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                        XDropTargetProtocol dropTargetProtocol =
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22584
diff changeset
   475
                            dropTargetProtocols.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                        if (dropTargetProtocol.isXEmbedSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                            dropTargetProtocol.registerEmbedderDropSite(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            entry.addSite(window, isXEmbedClient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    private void unregisterEmbeddedDropSite(long toplevel, long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        Long lToplevel = Long.valueOf(toplevel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        EmbeddedDropSiteEntry entry = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        synchronized (this) {
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21278
diff changeset
   491
            entry = embeddedDropSiteRegistry.get(lToplevel);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            if (entry == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            entry.removeSite(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            if (!entry.hasSites()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                embeddedDropSiteRegistry.remove(lToplevel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                XBaseWindow xbaseWindow = XToolkit.windowToXWindow(toplevel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                if (xbaseWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                    if (xbaseWindow instanceof XEmbedCanvasPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                        XEmbedCanvasPeer peer = (XEmbedCanvasPeer)xbaseWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                        // Unregister an XEmbed drop site.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                        peer.removeXEmbedDropTarget();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                        throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                    unregisterEmbedderDropSite(toplevel, entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * Returns a drop site that is embedded in the specified embedder window and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * contains the point with the specified root coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    public long getEmbeddedDropSite(long embedder, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        Long lToplevel = Long.valueOf(embedder);
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 21278
diff changeset
   521
        EmbeddedDropSiteEntry entry = embeddedDropSiteRegistry.get(lToplevel);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        if (entry == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        return entry.getSite(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
4254
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   528
    /*
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   529
     * Note: this method should be called under AWT lock.
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   530
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    public void registerDropSite(long window) {
4254
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   532
        assert XToolkit.isAWTLockHeldByCurrentThread();
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   533
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        if (window == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        XDropTargetEventProcessor.activate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
4254
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   540
        long toplevel = getToplevelWindow(window);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
4254
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   542
        /*
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   543
         * No window with WM_STATE property is found.
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   544
         * Since the window can be a plugin window reparented to the browser
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   545
         * toplevel, we cannot determine which window will eventually have
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   546
         * WM_STATE property set. So we schedule a timer callback that will
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   547
         * periodically attempt to find an ancestor with WM_STATE and
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   548
         * register the drop site appropriately.
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   549
         */
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   550
        if (toplevel == 0) {
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   551
            addDelayedRegistrationEntry(window);
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   552
            return;
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   553
        }
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   554
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   555
        if (toplevel == window) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22584
diff changeset
   556
            Iterator<XDropTargetProtocol> dropTargetProtocols =
4254
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   557
                XDragAndDropProtocols.getDropTargetProtocols();
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   558
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   559
            while (dropTargetProtocols.hasNext()) {
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   560
                XDropTargetProtocol dropTargetProtocol =
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22584
diff changeset
   561
                    dropTargetProtocols.next();
4254
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   562
                dropTargetProtocol.registerDropTarget(toplevel);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            }
4254
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   564
        } else {
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   565
            registerEmbeddedDropSite(toplevel, window);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
4254
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   569
    /*
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   570
     * Note: this method should be called under AWT lock.
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   571
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    public void unregisterDropSite(long window) {
4254
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   573
        assert XToolkit.isAWTLockHeldByCurrentThread();
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   574
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        if (window == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
4254
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   579
        long toplevel = getToplevelWindow(window);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
4254
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   581
        if (toplevel == window) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22584
diff changeset
   582
            Iterator<XDropTargetProtocol> dropProtocols =
4254
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   583
                XDragAndDropProtocols.getDropTargetProtocols();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
4254
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   585
            removeDelayedRegistrationEntry(window);
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   586
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   587
            while (dropProtocols.hasNext()) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22584
diff changeset
   588
                XDropTargetProtocol dropProtocol = dropProtocols.next();
4254
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   589
                dropProtocol.unregisterDropTarget(window);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            }
4254
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   591
        } else {
b63d0a7f93a7 6796915: Deadlock in XAWT when switching virtual desktops
dcherepanov
parents: 2802
diff changeset
   592
            unregisterEmbeddedDropSite(toplevel, window);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    public void registerXEmbedClient(long canvasWindow, long clientWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        // If the client has an associated XDnD drop site, add a drop target
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        // to the XEmbedCanvasPeer's target to route drag notifications to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        // client.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        XDragSourceProtocol xdndDragProtocol =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            XDragAndDropProtocols.getDragSourceProtocol(XDragAndDropProtocols.XDnD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        XDragSourceProtocol.TargetWindowInfo info =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            xdndDragProtocol.getTargetWindowInfo(clientWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        if (info != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            info.getProtocolVersion() >= XDnDConstants.XDND_MIN_PROTOCOL_VERSION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
   608
            if (logger.isLoggable(PlatformLogger.Level.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                logger.fine("        XEmbed drop site will be registered for " + Long.toHexString(clientWindow));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            registerEmbeddedDropSite(canvasWindow, clientWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22584
diff changeset
   613
            Iterator<XDropTargetProtocol> dropTargetProtocols =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                XDragAndDropProtocols.getDropTargetProtocols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            while (dropTargetProtocols.hasNext()) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22584
diff changeset
   617
                XDropTargetProtocol dropTargetProtocol = dropTargetProtocols.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                dropTargetProtocol.registerEmbeddedDropSite(clientWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
   621
            if (logger.isLoggable(PlatformLogger.Level.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                logger.fine("        XEmbed drop site has been registered for " + Long.toHexString(clientWindow));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    public void unregisterXEmbedClient(long canvasWindow, long clientWindow) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
   628
        if (logger.isLoggable(PlatformLogger.Level.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            logger.fine("        XEmbed drop site will be unregistered for " + Long.toHexString(clientWindow));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        }
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22584
diff changeset
   631
        Iterator<XDropTargetProtocol> dropTargetProtocols =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            XDragAndDropProtocols.getDropTargetProtocols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        while (dropTargetProtocols.hasNext()) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22584
diff changeset
   635
            XDropTargetProtocol dropTargetProtocol = dropTargetProtocols.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            dropTargetProtocol.unregisterEmbeddedDropSite(clientWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        unregisterEmbeddedDropSite(canvasWindow, clientWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17679
diff changeset
   641
        if (logger.isLoggable(PlatformLogger.Level.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            logger.fine("        XEmbed drop site has beed unregistered for " + Long.toHexString(clientWindow));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    /**************** Delayed drop site registration *******************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    private void addDelayedRegistrationEntry(final long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        Long lWindow = Long.valueOf(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        Runnable runnable = new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                    removeDelayedRegistrationEntry(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                    registerDropSite(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            removeDelayedRegistrationEntry(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            delayedRegistrationMap.put(lWindow, runnable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            XToolkit.schedule(runnable, DELAYED_REGISTRATION_PERIOD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    private void removeDelayedRegistrationEntry(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        Long lWindow = Long.valueOf(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            Runnable runnable = delayedRegistrationMap.remove(lWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            if (runnable != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                XToolkit.remove(runnable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    /*******************************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
}