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

Print this page




 781             int targetIdx = (button > 3) ? MouseEvent.BUTTON2 - 1 : button - 1;
 782 
 783             // MOUSE_ENTERED/EXITED are generated for the components strictly under
 784             // mouse even when dragging. That's why we first update lastMouseEventPeer
 785             // based on initial targetPeer value and only then recalculate targetPeer
 786             // for MOUSE_DRAGGED/RELEASED events
 787             if (id == MouseEvent.MOUSE_PRESSED) {
 788 
 789                 // Ungrab only if this window is not an owned window of the grabbing one.
 790                 if (!isGrabbing() && grabbingWindow != null &&
 791                     grabbingWindow != getOwnerFrameDialog(this))
 792                 {
 793                     grabbingWindow.ungrab();
 794                 }
 795                 if (otherButtonsPressed == 0) {
 796                     mouseClickButtons = eventButtonMask;
 797                 } else {
 798                     mouseClickButtons |= eventButtonMask;
 799                 }
 800 








 801                 mouseDownTarget[targetIdx] = targetPeer;
 802             } else if (id == MouseEvent.MOUSE_DRAGGED) {
 803                 // Cocoa dragged event has the information about which mouse
 804                 // button is being dragged. Use it to determine the peer that
 805                 // should receive the dragged event.
 806                 targetPeer = mouseDownTarget[targetIdx];
 807                 mouseClickButtons &= ~modifiers;
 808             } else if (id == MouseEvent.MOUSE_RELEASED) {
 809                 // TODO: currently, mouse released event goes to the same component
 810                 // that received corresponding mouse pressed event. For most cases,
 811                 // it's OK, however, we need to make sure that our behavior is consistent
 812                 // with 1.6 for cases where component in question have been
 813                 // hidden/removed in between of mouse pressed/released events.
 814                 targetPeer = mouseDownTarget[targetIdx];
 815 
 816                 if ((modifiers & eventButtonMask) == 0) {
 817                     mouseDownTarget[targetIdx] = null;
 818                 }
 819 
 820                 // mouseClickButtons is updated below, after MOUSE_CLICK is sent


 897 
 898         Point lp = targetPeer.windowToLocal(x, y, this);
 899         // TODO: fill "bdata" member of AWTEvent
 900         // TODO: screenX/screenY
 901         postEvent(new MouseWheelEvent(targetPeer.getTarget(),
 902                                       MouseEvent.MOUSE_WHEEL,
 903                                       when, modifiers,
 904                                       lp.x, lp.y,
 905                                       0, 0, /* screenX, Y */
 906                                       0 /* clickCount */, false /* popupTrigger */,
 907                                       scrollType, scrollAmount,
 908                                       wheelRotation, preciseWheelRotation));
 909     }
 910 
 911     /*
 912      * Called by the delegate when a key is pressed.
 913      */
 914     public void dispatchKeyEvent(int id, long when, int modifiers,
 915                                  int keyCode, char keyChar, int keyLocation)
 916     {
 917         KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
 918         Component focusOwner = kfmPeer.getCurrentFocusOwner();
 919 
 920         // Null focus owner may receive key event when
 921         // application hides the focused window upon ESC press
 922         // (AWT transfers/clears the focus owner) and pending ESC release
 923         // may come to already hidden window. This check eliminates NPE.
 924         if (focusOwner != null) {
 925             KeyEvent event =
 926                 new KeyEvent(focusOwner, id, when, modifiers,
 927                              keyCode, keyChar, keyLocation);
 928             LWComponentPeer peer = (LWComponentPeer)focusOwner.getPeer();
 929             peer.postEvent(event);
 930         }

 931     }
 932 
 933 
 934     // ---- UTILITY METHODS ---- //
 935 
 936     private void postWindowStateChangedEvent(int newWindowState) {
 937         if (getTarget() instanceof Frame) {
 938             AWTAccessor.getFrameAccessor().setExtendedState(
 939                     (Frame)getTarget(), newWindowState);
 940         }
 941         WindowEvent stateChangedEvent = new WindowEvent(getTarget(),
 942                 WindowEvent.WINDOW_STATE_CHANGED,
 943                 windowState, newWindowState);
 944         postEvent(stateChangedEvent);
 945         windowState = newWindowState;
 946     }
 947 
 948     private static int getGraphicsConfigScreen(GraphicsConfiguration gc) {
 949         // TODO: this method can be implemented in a more
 950         // efficient way by forwarding to the delegate


1243             }
1244         }
1245 
1246         KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
1247         Window oppositeWindow = becomesFocused ? kfmPeer.getCurrentFocusedWindow() : null;
1248 
1249         // Note, the method is not called:
1250         // - when the opposite (gaining focus) window is an owned/owner window.
1251         // - for a simple window in any case.
1252         if (!becomesFocused &&
1253             (isGrabbing() || getOwnerFrameDialog(grabbingWindow) == this))
1254         {
1255             focusLog.fine("ungrabbing on " + grabbingWindow);
1256             // ungrab a simple window if its owner looses activation.
1257             grabbingWindow.ungrab();
1258         }
1259 
1260         kfmPeer.setCurrentFocusedWindow(becomesFocused ? getTarget() : null);
1261 
1262         int eventID = becomesFocused ? WindowEvent.WINDOW_GAINED_FOCUS : WindowEvent.WINDOW_LOST_FOCUS;
1263         WindowEvent windowEvent = new WindowEvent(getTarget(), eventID, oppositeWindow);
1264 
1265         // TODO: wrap in SequencedEvent
1266         postEvent(windowEvent);
1267     }
1268 
1269     static LWWindowPeer getOwnerFrameDialog(LWWindowPeer peer) {
1270         Window owner = (peer != null ? peer.getTarget().getOwner() : null);
1271         while (owner != null && !(owner instanceof Frame || owner instanceof Dialog)) {
1272             owner = owner.getOwner();
1273         }
1274         return owner != null ? (LWWindowPeer)owner.getPeer() : null;
1275     }
1276 
1277     /**
1278      * Returns the foremost modal blocker of this window, or null.
1279      */
1280     public LWWindowPeer getBlocker() {
1281         synchronized (getPeerTreeLock()) {
1282             LWWindowPeer blocker = this.blocker;
1283             if (blocker == null) {




 781             int targetIdx = (button > 3) ? MouseEvent.BUTTON2 - 1 : button - 1;
 782 
 783             // MOUSE_ENTERED/EXITED are generated for the components strictly under
 784             // mouse even when dragging. That's why we first update lastMouseEventPeer
 785             // based on initial targetPeer value and only then recalculate targetPeer
 786             // for MOUSE_DRAGGED/RELEASED events
 787             if (id == MouseEvent.MOUSE_PRESSED) {
 788 
 789                 // Ungrab only if this window is not an owned window of the grabbing one.
 790                 if (!isGrabbing() && grabbingWindow != null &&
 791                     grabbingWindow != getOwnerFrameDialog(this))
 792                 {
 793                     grabbingWindow.ungrab();
 794                 }
 795                 if (otherButtonsPressed == 0) {
 796                     mouseClickButtons = eventButtonMask;
 797                 } else {
 798                     mouseClickButtons |= eventButtonMask;
 799                 }
 800 
 801                 // The window should be focused on mouse click. If it gets activated by the native platform,
 802                 // this request will be no op. It will take effect when:
 803                 // 1. A simple not focused window is clicked.
 804                 // 2. An active but not focused owner frame/dialog is clicked.
 805                 // The mouse event then will trigger a focus request "in window" to the component, so the window
 806                 // should gain focus before.
 807                 requestWindowFocus(CausedFocusEvent.Cause.MOUSE_EVENT);
 808 
 809                 mouseDownTarget[targetIdx] = targetPeer;
 810             } else if (id == MouseEvent.MOUSE_DRAGGED) {
 811                 // Cocoa dragged event has the information about which mouse
 812                 // button is being dragged. Use it to determine the peer that
 813                 // should receive the dragged event.
 814                 targetPeer = mouseDownTarget[targetIdx];
 815                 mouseClickButtons &= ~modifiers;
 816             } else if (id == MouseEvent.MOUSE_RELEASED) {
 817                 // TODO: currently, mouse released event goes to the same component
 818                 // that received corresponding mouse pressed event. For most cases,
 819                 // it's OK, however, we need to make sure that our behavior is consistent
 820                 // with 1.6 for cases where component in question have been
 821                 // hidden/removed in between of mouse pressed/released events.
 822                 targetPeer = mouseDownTarget[targetIdx];
 823 
 824                 if ((modifiers & eventButtonMask) == 0) {
 825                     mouseDownTarget[targetIdx] = null;
 826                 }
 827 
 828                 // mouseClickButtons is updated below, after MOUSE_CLICK is sent


 905 
 906         Point lp = targetPeer.windowToLocal(x, y, this);
 907         // TODO: fill "bdata" member of AWTEvent
 908         // TODO: screenX/screenY
 909         postEvent(new MouseWheelEvent(targetPeer.getTarget(),
 910                                       MouseEvent.MOUSE_WHEEL,
 911                                       when, modifiers,
 912                                       lp.x, lp.y,
 913                                       0, 0, /* screenX, Y */
 914                                       0 /* clickCount */, false /* popupTrigger */,
 915                                       scrollType, scrollAmount,
 916                                       wheelRotation, preciseWheelRotation));
 917     }
 918 
 919     /*
 920      * Called by the delegate when a key is pressed.
 921      */
 922     public void dispatchKeyEvent(int id, long when, int modifiers,
 923                                  int keyCode, char keyChar, int keyLocation)
 924     {
 925         LWKeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
 926         Component focusOwner = kfmPeer.getCurrentFocusOwner();
 927         
 928         if (focusOwner == null) {
 929             focusOwner = kfmPeer.getCurrentFocusedWindow();
 930             if (focusOwner == null) {
 931                 focusOwner = this.getTarget();
 932             }





 933         }        
 934         postEvent(new KeyEvent(focusOwner, id, when, modifiers, keyCode, keyChar, keyLocation));
 935     }
 936 
 937 
 938     // ---- UTILITY METHODS ---- //
 939 
 940     private void postWindowStateChangedEvent(int newWindowState) {
 941         if (getTarget() instanceof Frame) {
 942             AWTAccessor.getFrameAccessor().setExtendedState(
 943                     (Frame)getTarget(), newWindowState);
 944         }
 945         WindowEvent stateChangedEvent = new WindowEvent(getTarget(),
 946                 WindowEvent.WINDOW_STATE_CHANGED,
 947                 windowState, newWindowState);
 948         postEvent(stateChangedEvent);
 949         windowState = newWindowState;
 950     }
 951 
 952     private static int getGraphicsConfigScreen(GraphicsConfiguration gc) {
 953         // TODO: this method can be implemented in a more
 954         // efficient way by forwarding to the delegate


1247             }
1248         }
1249 
1250         KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
1251         Window oppositeWindow = becomesFocused ? kfmPeer.getCurrentFocusedWindow() : null;
1252 
1253         // Note, the method is not called:
1254         // - when the opposite (gaining focus) window is an owned/owner window.
1255         // - for a simple window in any case.
1256         if (!becomesFocused &&
1257             (isGrabbing() || getOwnerFrameDialog(grabbingWindow) == this))
1258         {
1259             focusLog.fine("ungrabbing on " + grabbingWindow);
1260             // ungrab a simple window if its owner looses activation.
1261             grabbingWindow.ungrab();
1262         }
1263 
1264         kfmPeer.setCurrentFocusedWindow(becomesFocused ? getTarget() : null);
1265 
1266         int eventID = becomesFocused ? WindowEvent.WINDOW_GAINED_FOCUS : WindowEvent.WINDOW_LOST_FOCUS;
1267         WindowEvent windowEvent = new TimedWindowEvent(getTarget(), eventID, oppositeWindow, System.currentTimeMillis());
1268 
1269         // TODO: wrap in SequencedEvent
1270         postEvent(windowEvent);
1271     }
1272 
1273     static LWWindowPeer getOwnerFrameDialog(LWWindowPeer peer) {
1274         Window owner = (peer != null ? peer.getTarget().getOwner() : null);
1275         while (owner != null && !(owner instanceof Frame || owner instanceof Dialog)) {
1276             owner = owner.getOwner();
1277         }
1278         return owner != null ? (LWWindowPeer)owner.getPeer() : null;
1279     }
1280 
1281     /**
1282      * Returns the foremost modal blocker of this window, or null.
1283      */
1284     public LWWindowPeer getBlocker() {
1285         synchronized (getPeerTreeLock()) {
1286             LWWindowPeer blocker = this.blocker;
1287             if (blocker == null) {