Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/awt/X11/XDropTargetEventProcessor.java
32288 views
/*1* Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.awt.X11;2627import java.util.Iterator;2829/**30* This class is a registry for the supported drag and drop protocols.31*32* @since 1.533*/34final class XDropTargetEventProcessor {35private static final XDropTargetEventProcessor theInstance =36new XDropTargetEventProcessor();37private static boolean active = false;3839// The current drop protocol.40private XDropTargetProtocol protocol = null;4142private XDropTargetEventProcessor() {}4344private boolean doProcessEvent(XEvent ev) {45if (ev.get_type() == (int)XConstants.DestroyNotify &&46protocol != null &&47ev.get_xany().get_window() == protocol.getSourceWindow()) {48protocol.cleanup();49protocol = null;50return false;51}5253if (ev.get_type() == (int)XConstants.PropertyNotify) {54XPropertyEvent xproperty = ev.get_xproperty();55if (xproperty.get_atom() ==56MotifDnDConstants.XA_MOTIF_DRAG_RECEIVER_INFO.getAtom()) {5758XDropTargetRegistry.getRegistry().updateEmbedderDropSite(xproperty.get_window());59}60}6162if (ev.get_type() != (int)XConstants.ClientMessage) {63return false;64}6566boolean processed = false;67XClientMessageEvent xclient = ev.get_xclient();6869XDropTargetProtocol curProtocol = protocol;7071if (protocol != null) {72if (protocol.getMessageType(xclient) !=73XDropTargetProtocol.UNKNOWN_MESSAGE) {74processed = protocol.processClientMessage(xclient);75} else {76protocol = null;77}78}7980if (protocol == null) {81Iterator dropTargetProtocols =82XDragAndDropProtocols.getDropTargetProtocols();8384while (dropTargetProtocols.hasNext()) {85XDropTargetProtocol dropTargetProtocol =86(XDropTargetProtocol)dropTargetProtocols.next();87// Don't try to process it again with the current protocol.88if (dropTargetProtocol == curProtocol) {89continue;90}9192if (dropTargetProtocol.getMessageType(xclient) ==93XDropTargetProtocol.UNKNOWN_MESSAGE) {94continue;95}9697protocol = dropTargetProtocol;98processed = protocol.processClientMessage(xclient);99break;100}101}102103return processed;104}105106static void reset() {107theInstance.protocol = null;108}109110static void activate() {111active = true;112}113114// Fix for 4915454 - do not call doProcessEvent() until the first drop115// target is registered to avoid premature loading of DnD protocol116// classes.117static boolean processEvent(XEvent ev) {118return active ? theInstance.doProcessEvent(ev) : false;119}120}121122123