src/macosx/classes/sun/lwawt/LWWindowPeer.java

Print this page




  64     private int sysY;
  65     private int sysW;
  66     private int sysH;
  67 
  68     private static final int MINIMUM_WIDTH = 1;
  69     private static final int MINIMUM_HEIGHT = 1;
  70 
  71     private Insets insets = new Insets(0, 0, 0, 0);
  72 
  73     private GraphicsDevice graphicsDevice;
  74     private GraphicsConfiguration graphicsConfig;
  75 
  76     private SurfaceData surfaceData;
  77     private final Object surfaceDataLock = new Object();
  78 
  79     private volatile int windowState = Frame.NORMAL;
  80 
  81     // check that the mouse is over the window
  82     private volatile boolean isMouseOver = false;
  83 

  84     // A peer where the last mouse event came to. Used by cursor manager to
  85     // find the component under cursor
  86     private static volatile LWComponentPeer lastCommonMouseEventPeer = null;
  87 
  88     // A peer where the last mouse event came to. Used to generate
  89     // MOUSE_ENTERED/EXITED notifications
  90     private volatile LWComponentPeer lastMouseEventPeer;
  91 
  92     // Peers where all dragged/released events should come to,
  93     // depending on what mouse button is being dragged according to Cocoa
  94     private static LWComponentPeer mouseDownTarget[] = new LWComponentPeer[3];
  95 
  96     // A bitmask that indicates what mouse buttons produce MOUSE_CLICKED events
  97     // on MOUSE_RELEASE. Click events are only generated if there were no drag
  98     // events between MOUSE_PRESSED and MOUSE_RELEASED for particular button
  99     private static int mouseClickButtons = 0;
 100 
 101     private volatile boolean isOpaque = true;
 102 
 103     private static final Font DEFAULT_FONT = new Font("Lucida Grande", Font.PLAIN, 13);
 104 
 105     private static LWWindowPeer grabbingWindow;
 106 


 693     {
 694         // TODO: fill "bdata" member of AWTEvent
 695         Rectangle r = getBounds();
 696         // findPeerAt() expects parent coordinates
 697         LWComponentPeer targetPeer = findPeerAt(r.x + x, r.y + y);
 698 
 699         if (id == MouseEvent.MOUSE_EXITED) {
 700             isMouseOver = false;
 701             if (lastMouseEventPeer != null) {
 702                 if (lastMouseEventPeer.isEnabled()) {
 703                     Point lp = lastMouseEventPeer.windowToLocal(x, y,
 704                             this);
 705                     Component target = lastMouseEventPeer.getTarget();
 706                     postMouseExitedEvent(target, when, modifiers, lp,
 707                             screenX, screenY, clickCount, popupTrigger, button);
 708                 }
 709 
 710                 // Sometimes we may get MOUSE_EXITED after lastCommonMouseEventPeer is switched
 711                 // to a peer from another window. So we must first check if this peer is
 712                 // the same as lastWindowPeer
 713                 if (lastCommonMouseEventPeer != null && lastCommonMouseEventPeer.getWindowPeerOrSelf() == this) {
 714                     lastCommonMouseEventPeer = null;
 715                 }
 716                 lastMouseEventPeer = null;
 717             }
 718         } else if(id == MouseEvent.MOUSE_ENTERED) {
 719             isMouseOver = true;
 720             if (targetPeer != null) {
 721                 if (targetPeer.isEnabled()) {
 722                     Point lp = targetPeer.windowToLocal(x, y, this);
 723                     Component target = targetPeer.getTarget();
 724                     postMouseEnteredEvent(target, when, modifiers, lp,
 725                             screenX, screenY, clickCount, popupTrigger, button);
 726                 }
 727                 lastCommonMouseEventPeer = targetPeer;
 728                 lastMouseEventPeer = targetPeer;
 729             }
 730         } else {
 731             PlatformWindow topmostPlatforWindow =
 732                     platformWindow.getTopmostPlatformWindowUnderMouse();
 733 
 734             LWWindowPeer topmostWindowPeer =
 735                     topmostPlatforWindow != null ? topmostPlatforWindow.getPeer() : null;
 736 
 737             // topmostWindowPeer == null condition is added for the backward
 738             // compatibility with applets. It can be removed when the
 739             // getTopmostPlatformWindowUnderMouse() method will be properly
 740             // implemented in CPlatformEmbeddedFrame class
 741             if (topmostWindowPeer == this || topmostWindowPeer == null) {
 742                 generateMouseEnterExitEventsForComponents(when, button, x, y,
 743                         screenX, screenY, modifiers, clickCount, popupTrigger,
 744                         targetPeer);
 745             } else {
 746                 LWComponentPeer topmostTargetPeer =
 747                         topmostWindowPeer != null ? topmostWindowPeer.findPeerAt(r.x + x, r.y + y) : null;


 836         }
 837         notifyUpdateCursor();
 838     }
 839 
 840     private void generateMouseEnterExitEventsForComponents(long when,
 841             int button, int x, int y, int screenX, int screenY,
 842             int modifiers, int clickCount, boolean popupTrigger,
 843             LWComponentPeer targetPeer) {
 844 
 845         if (!isMouseOver || targetPeer == lastMouseEventPeer) {
 846             return;
 847         }
 848 
 849         // Generate Mouse Exit for components
 850         if (lastMouseEventPeer != null && lastMouseEventPeer.isEnabled()) {
 851             Point oldp = lastMouseEventPeer.windowToLocal(x, y, this);
 852             Component target = lastMouseEventPeer.getTarget();
 853             postMouseExitedEvent(target, when, modifiers, oldp, screenX, screenY,
 854                     clickCount, popupTrigger, button);
 855         }
 856         lastCommonMouseEventPeer = targetPeer;
 857         lastMouseEventPeer = targetPeer;
 858 
 859         // Generate Mouse Enter for components
 860         if (targetPeer != null && targetPeer.isEnabled()) {
 861             Point newp = targetPeer.windowToLocal(x, y, this);
 862             Component target = targetPeer.getTarget();
 863             postMouseEnteredEvent(target, when, modifiers, newp, screenX, screenY, clickCount, popupTrigger, button);
 864         }
 865     }
 866 
 867     private void postMouseEnteredEvent(Component target, long when, int modifiers,
 868                                        Point loc, int xAbs, int yAbs,
 869                                        int clickCount, boolean popupTrigger, int button) {
 870 
 871         updateSecurityWarningVisibility();
 872 
 873         postEvent(new MouseEvent(target,
 874                 MouseEvent.MOUSE_ENTERED,
 875                 when, modifiers,
 876                 loc.x, loc.y, xAbs, yAbs,


1094     }
1095 
1096     /**
1097      * Request the window insets from the delegate and compares it with the
1098      * current one. This method is mostly called by the delegate, e.g. when the
1099      * window state is changed and insets should be recalculated.
1100      * <p/>
1101      * This method may be called on the toolkit thread.
1102      */
1103     public final boolean updateInsets(final Insets newInsets) {
1104         synchronized (getStateLock()) {
1105             if (insets.equals(newInsets)) {
1106                 return false;
1107             }
1108             insets = newInsets;
1109         }
1110         return true;
1111     }
1112 
1113     public static LWWindowPeer getWindowUnderCursor() {

1114         return lastCommonMouseEventPeer != null ? lastCommonMouseEventPeer.getWindowPeerOrSelf() : null;
1115     }

1116 
1117     public static LWComponentPeer<?, ?> getPeerUnderCursor() {

1118         return lastCommonMouseEventPeer;
1119     }

















1120 
1121     /*
1122      * Requests platform to set native focus on a frame/dialog.
1123      * In case of a simple window, triggers appropriate java focus change.
1124      */
1125     public boolean requestWindowFocus(CausedFocusEvent.Cause cause) {
1126         if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
1127             focusLog.fine("requesting native focus to " + this);
1128         }
1129 
1130         if (!focusAllowedFor()) {
1131             focusLog.fine("focus is not allowed");
1132             return false;
1133         }
1134 
1135         if (platformWindow.rejectFocusRequest(cause)) {
1136             return false;
1137         }
1138 
1139         Window currentActive = KeyboardFocusManager.




  64     private int sysY;
  65     private int sysW;
  66     private int sysH;
  67 
  68     private static final int MINIMUM_WIDTH = 1;
  69     private static final int MINIMUM_HEIGHT = 1;
  70 
  71     private Insets insets = new Insets(0, 0, 0, 0);
  72 
  73     private GraphicsDevice graphicsDevice;
  74     private GraphicsConfiguration graphicsConfig;
  75 
  76     private SurfaceData surfaceData;
  77     private final Object surfaceDataLock = new Object();
  78 
  79     private volatile int windowState = Frame.NORMAL;
  80 
  81     // check that the mouse is over the window
  82     private volatile boolean isMouseOver = false;
  83 
  84     private static final Object lastCommonMouseEventPeerLock = new Object();
  85     // A peer where the last mouse event came to. Used by cursor manager to
  86     // find the component under cursor
  87     private static LWComponentPeer lastCommonMouseEventPeer = null;
  88 
  89     // A peer where the last mouse event came to. Used to generate
  90     // MOUSE_ENTERED/EXITED notifications
  91     private volatile LWComponentPeer lastMouseEventPeer;
  92 
  93     // Peers where all dragged/released events should come to,
  94     // depending on what mouse button is being dragged according to Cocoa
  95     private static LWComponentPeer mouseDownTarget[] = new LWComponentPeer[3];
  96 
  97     // A bitmask that indicates what mouse buttons produce MOUSE_CLICKED events
  98     // on MOUSE_RELEASE. Click events are only generated if there were no drag
  99     // events between MOUSE_PRESSED and MOUSE_RELEASED for particular button
 100     private static int mouseClickButtons = 0;
 101 
 102     private volatile boolean isOpaque = true;
 103 
 104     private static final Font DEFAULT_FONT = new Font("Lucida Grande", Font.PLAIN, 13);
 105 
 106     private static LWWindowPeer grabbingWindow;
 107 


 694     {
 695         // TODO: fill "bdata" member of AWTEvent
 696         Rectangle r = getBounds();
 697         // findPeerAt() expects parent coordinates
 698         LWComponentPeer targetPeer = findPeerAt(r.x + x, r.y + y);
 699 
 700         if (id == MouseEvent.MOUSE_EXITED) {
 701             isMouseOver = false;
 702             if (lastMouseEventPeer != null) {
 703                 if (lastMouseEventPeer.isEnabled()) {
 704                     Point lp = lastMouseEventPeer.windowToLocal(x, y,
 705                             this);
 706                     Component target = lastMouseEventPeer.getTarget();
 707                     postMouseExitedEvent(target, when, modifiers, lp,
 708                             screenX, screenY, clickCount, popupTrigger, button);
 709                 }
 710 
 711                 // Sometimes we may get MOUSE_EXITED after lastCommonMouseEventPeer is switched
 712                 // to a peer from another window. So we must first check if this peer is
 713                 // the same as lastWindowPeer
 714                 cleanLastCommonMouseEventPeer(this);


 715                 lastMouseEventPeer = null;
 716             }
 717         } else if(id == MouseEvent.MOUSE_ENTERED) {
 718             isMouseOver = true;
 719             if (targetPeer != null) {
 720                 if (targetPeer.isEnabled()) {
 721                     Point lp = targetPeer.windowToLocal(x, y, this);
 722                     Component target = targetPeer.getTarget();
 723                     postMouseEnteredEvent(target, when, modifiers, lp,
 724                             screenX, screenY, clickCount, popupTrigger, button);
 725                 }
 726                 setLastCommonMouseEventPeer(targetPeer);
 727                 lastMouseEventPeer = targetPeer;
 728             }
 729         } else {
 730             PlatformWindow topmostPlatforWindow =
 731                     platformWindow.getTopmostPlatformWindowUnderMouse();
 732 
 733             LWWindowPeer topmostWindowPeer =
 734                     topmostPlatforWindow != null ? topmostPlatforWindow.getPeer() : null;
 735 
 736             // topmostWindowPeer == null condition is added for the backward
 737             // compatibility with applets. It can be removed when the
 738             // getTopmostPlatformWindowUnderMouse() method will be properly
 739             // implemented in CPlatformEmbeddedFrame class
 740             if (topmostWindowPeer == this || topmostWindowPeer == null) {
 741                 generateMouseEnterExitEventsForComponents(when, button, x, y,
 742                         screenX, screenY, modifiers, clickCount, popupTrigger,
 743                         targetPeer);
 744             } else {
 745                 LWComponentPeer topmostTargetPeer =
 746                         topmostWindowPeer != null ? topmostWindowPeer.findPeerAt(r.x + x, r.y + y) : null;


 835         }
 836         notifyUpdateCursor();
 837     }
 838 
 839     private void generateMouseEnterExitEventsForComponents(long when,
 840             int button, int x, int y, int screenX, int screenY,
 841             int modifiers, int clickCount, boolean popupTrigger,
 842             LWComponentPeer targetPeer) {
 843 
 844         if (!isMouseOver || targetPeer == lastMouseEventPeer) {
 845             return;
 846         }
 847 
 848         // Generate Mouse Exit for components
 849         if (lastMouseEventPeer != null && lastMouseEventPeer.isEnabled()) {
 850             Point oldp = lastMouseEventPeer.windowToLocal(x, y, this);
 851             Component target = lastMouseEventPeer.getTarget();
 852             postMouseExitedEvent(target, when, modifiers, oldp, screenX, screenY,
 853                     clickCount, popupTrigger, button);
 854         }
 855         setLastCommonMouseEventPeer(targetPeer);
 856         lastMouseEventPeer = targetPeer;
 857 
 858         // Generate Mouse Enter for components
 859         if (targetPeer != null && targetPeer.isEnabled()) {
 860             Point newp = targetPeer.windowToLocal(x, y, this);
 861             Component target = targetPeer.getTarget();
 862             postMouseEnteredEvent(target, when, modifiers, newp, screenX, screenY, clickCount, popupTrigger, button);
 863         }
 864     }
 865 
 866     private void postMouseEnteredEvent(Component target, long when, int modifiers,
 867                                        Point loc, int xAbs, int yAbs,
 868                                        int clickCount, boolean popupTrigger, int button) {
 869 
 870         updateSecurityWarningVisibility();
 871 
 872         postEvent(new MouseEvent(target,
 873                 MouseEvent.MOUSE_ENTERED,
 874                 when, modifiers,
 875                 loc.x, loc.y, xAbs, yAbs,


1093     }
1094 
1095     /**
1096      * Request the window insets from the delegate and compares it with the
1097      * current one. This method is mostly called by the delegate, e.g. when the
1098      * window state is changed and insets should be recalculated.
1099      * <p/>
1100      * This method may be called on the toolkit thread.
1101      */
1102     public final boolean updateInsets(final Insets newInsets) {
1103         synchronized (getStateLock()) {
1104             if (insets.equals(newInsets)) {
1105                 return false;
1106             }
1107             insets = newInsets;
1108         }
1109         return true;
1110     }
1111 
1112     public static LWWindowPeer getWindowUnderCursor() {
1113         synchronized (lastCommonMouseEventPeerLock) {
1114             return lastCommonMouseEventPeer != null ? lastCommonMouseEventPeer.getWindowPeerOrSelf() : null;
1115         }
1116     }
1117 
1118     public static LWComponentPeer<?, ?> getPeerUnderCursor() {
1119         synchronized (lastCommonMouseEventPeerLock) {
1120             return lastCommonMouseEventPeer;
1121         }
1122     }
1123 
1124     static boolean cleanLastCommonMouseEventPeer(LWWindowPeer previous) {
1125         synchronized (lastCommonMouseEventPeerLock) {
1126             if (lastCommonMouseEventPeer != null && lastCommonMouseEventPeer.getWindowPeerOrSelf() == previous) {
1127                 lastCommonMouseEventPeer = null;
1128                 return true;
1129             }
1130             return false;
1131         }
1132     }
1133 
1134     static void setLastCommonMouseEventPeer(LWComponentPeer<?, ?> newValue) {
1135         synchronized (lastCommonMouseEventPeerLock) {
1136             lastCommonMouseEventPeer = newValue;
1137         }
1138     }
1139 
1140     /*
1141      * Requests platform to set native focus on a frame/dialog.
1142      * In case of a simple window, triggers appropriate java focus change.
1143      */
1144     public boolean requestWindowFocus(CausedFocusEvent.Cause cause) {
1145         if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
1146             focusLog.fine("requesting native focus to " + this);
1147         }
1148 
1149         if (!focusAllowedFor()) {
1150             focusLog.fine("focus is not allowed");
1151             return false;
1152         }
1153 
1154         if (platformWindow.rejectFocusRequest(cause)) {
1155             return false;
1156         }
1157 
1158         Window currentActive = KeyboardFocusManager.