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

Print this page




 795             int targetIdx = (button > 3) ? MouseEvent.BUTTON2 - 1 : button - 1;
 796 
 797             // MOUSE_ENTERED/EXITED are generated for the components strictly under
 798             // mouse even when dragging. That's why we first update lastMouseEventPeer
 799             // based on initial targetPeer value and only then recalculate targetPeer
 800             // for MOUSE_DRAGGED/RELEASED events
 801             if (id == MouseEvent.MOUSE_PRESSED) {
 802 
 803                 // Ungrab only if this window is not an owned window of the grabbing one.
 804                 if (!isGrabbing() && grabbingWindow != null &&
 805                     grabbingWindow != getOwnerFrameDialog(this))
 806                 {
 807                     grabbingWindow.ungrab();
 808                 }
 809                 if (otherButtonsPressed == 0) {
 810                     mouseClickButtons = eventButtonMask;
 811                 } else {
 812                     mouseClickButtons |= eventButtonMask;
 813                 }
 814 








 815                 mouseDownTarget[targetIdx] = targetPeer;
 816             } else if (id == MouseEvent.MOUSE_DRAGGED) {
 817                 // Cocoa dragged event has the information about which mouse
 818                 // button is being dragged. Use it to determine the peer that
 819                 // should receive the dragged event.
 820                 targetPeer = mouseDownTarget[targetIdx];
 821                 mouseClickButtons &= ~modifiers;
 822             } else if (id == MouseEvent.MOUSE_RELEASED) {
 823                 // TODO: currently, mouse released event goes to the same component
 824                 // that received corresponding mouse pressed event. For most cases,
 825                 // it's OK, however, we need to make sure that our behavior is consistent
 826                 // with 1.6 for cases where component in question have been
 827                 // hidden/removed in between of mouse pressed/released events.
 828                 targetPeer = mouseDownTarget[targetIdx];
 829 
 830                 if ((modifiers & eventButtonMask) == 0) {
 831                     mouseDownTarget[targetIdx] = null;
 832                 }
 833 
 834                 // mouseClickButtons is updated below, after MOUSE_CLICK is sent


 885 
 886         Point lp = targetPeer.windowToLocal(x, y, this);
 887         // TODO: fill "bdata" member of AWTEvent
 888         // TODO: screenX/screenY
 889         postEvent(new MouseWheelEvent(targetPeer.getTarget(),
 890                                       MouseEvent.MOUSE_WHEEL,
 891                                       when, modifiers,
 892                                       lp.x, lp.y,
 893                                       0, 0, /* screenX, Y */
 894                                       0 /* clickCount */, false /* popupTrigger */,
 895                                       scrollType, scrollAmount,
 896                                       wheelRotation, preciseWheelRotation));
 897     }
 898 
 899     /*
 900      * Called by the delegate when a key is pressed.
 901      */
 902     public void dispatchKeyEvent(int id, long when, int modifiers,
 903                                  int keyCode, char keyChar, int keyLocation)
 904     {
 905         LWComponentPeer focusOwner =
 906             LWKeyboardFocusManagerPeer.getInstance(getAppContext()).
 907                 getFocusOwner();
 908 
 909         // Null focus owner may receive key event when
 910         // application hides the focused window upon ESC press
 911         // (AWT transfers/clears the focus owner) and pending ESC release
 912         // may come to already hidden window. This check eliminates NPE.
 913         if (focusOwner != null) {
 914             KeyEvent event =
 915                 new KeyEvent(focusOwner.getTarget(), id, when, modifiers,
 916                              keyCode, keyChar, keyLocation);
 917             focusOwner.postEvent(event);
 918         }

 919     }
 920 
 921 
 922     // ---- UTILITY METHODS ---- //
 923 
 924     private void postWindowStateChangedEvent(int newWindowState) {
 925         if (getTarget() instanceof Frame) {
 926             AWTAccessor.getFrameAccessor().setExtendedState(
 927                     (Frame)getTarget(), newWindowState);
 928         }
 929         WindowEvent stateChangedEvent = new WindowEvent(getTarget(),
 930                 WindowEvent.WINDOW_STATE_CHANGED,
 931                 windowState, newWindowState);
 932         postEvent(stateChangedEvent);
 933         windowState = newWindowState;
 934     }
 935 
 936     private static int getGraphicsConfigScreen(GraphicsConfiguration gc) {
 937         // TODO: this method can be implemented in a more
 938         // efficient way by forwarding to the delegate


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




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


 893 
 894         Point lp = targetPeer.windowToLocal(x, y, this);
 895         // TODO: fill "bdata" member of AWTEvent
 896         // TODO: screenX/screenY
 897         postEvent(new MouseWheelEvent(targetPeer.getTarget(),
 898                                       MouseEvent.MOUSE_WHEEL,
 899                                       when, modifiers,
 900                                       lp.x, lp.y,
 901                                       0, 0, /* screenX, Y */
 902                                       0 /* clickCount */, false /* popupTrigger */,
 903                                       scrollType, scrollAmount,
 904                                       wheelRotation, preciseWheelRotation));
 905     }
 906 
 907     /*
 908      * Called by the delegate when a key is pressed.
 909      */
 910     public void dispatchKeyEvent(int id, long when, int modifiers,
 911                                  int keyCode, char keyChar, int keyLocation)
 912     {
 913         LWKeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance(getAppContext());
 914         LWComponentPeer focusOwner = kfmPeer.getFocusOwner();
 915 
 916         if (focusOwner == null) {
 917             focusOwner = kfmPeer.getFocusedWindow();
 918 
 919             if (focusOwner == null) {
 920                 focusOwner = this;
 921             }




 922         }
 923         focusOwner.postEvent(new KeyEvent(focusOwner.getTarget(), id, when, modifiers, keyCode, keyChar, keyLocation));
 924     }
 925 
 926 
 927     // ---- UTILITY METHODS ---- //
 928 
 929     private void postWindowStateChangedEvent(int newWindowState) {
 930         if (getTarget() instanceof Frame) {
 931             AWTAccessor.getFrameAccessor().setExtendedState(
 932                     (Frame)getTarget(), newWindowState);
 933         }
 934         WindowEvent stateChangedEvent = new WindowEvent(getTarget(),
 935                 WindowEvent.WINDOW_STATE_CHANGED,
 936                 windowState, newWindowState);
 937         postEvent(stateChangedEvent);
 938         windowState = newWindowState;
 939     }
 940 
 941     private static int getGraphicsConfigScreen(GraphicsConfiguration gc) {
 942         // TODO: this method can be implemented in a more
 943         // efficient way by forwarding to the delegate


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