718 int targetIdx = (button > 3) ? MouseEvent.BUTTON2 - 1 : button - 1;
719
720 // MOUSE_ENTERED/EXITED are generated for the components strictly under
721 // mouse even when dragging. That's why we first update lastMouseEventPeer
722 // based on initial targetPeer value and only then recalculate targetPeer
723 // for MOUSE_DRAGGED/RELEASED events
724 if (id == MouseEvent.MOUSE_PRESSED) {
725
726 // Ungrab only if this window is not an owned window of the grabbing one.
727 if (!isGrabbing() && grabbingWindow != null &&
728 grabbingWindow != getOwnerFrameDialog(this))
729 {
730 grabbingWindow.ungrab();
731 }
732 if (otherButtonsPressed == 0) {
733 mouseClickButtons = eventButtonMask;
734 } else {
735 mouseClickButtons |= eventButtonMask;
736 }
737
738 mouseDownTarget[targetIdx] = targetPeer;
739 } else if (id == MouseEvent.MOUSE_DRAGGED) {
740 // Cocoa dragged event has the information about which mouse
741 // button is being dragged. Use it to determine the peer that
742 // should receive the dragged event.
743 targetPeer = mouseDownTarget[targetIdx];
744 mouseClickButtons &= ~modifiers;
745 } else if (id == MouseEvent.MOUSE_RELEASED) {
746 // TODO: currently, mouse released event goes to the same component
747 // that received corresponding mouse pressed event. For most cases,
748 // it's OK, however, we need to make sure that our behavior is consistent
749 // with 1.6 for cases where component in question have been
750 // hidden/removed in between of mouse pressed/released events.
751 targetPeer = mouseDownTarget[targetIdx];
752
753 if ((modifiers & eventButtonMask) == 0) {
754 mouseDownTarget[targetIdx] = null;
755 }
756
757 // mouseClickButtons is updated below, after MOUSE_CLICK is sent
809
810 Point lp = targetPeer.windowToLocal(x, y, this);
811 // TODO: fill "bdata" member of AWTEvent
812 // TODO: screenX/screenY
813 postEvent(new MouseWheelEvent(targetPeer.getTarget(),
814 MouseEvent.MOUSE_WHEEL,
815 when, modifiers,
816 lp.x, lp.y,
817 0, 0, /* screenX, Y */
818 0 /* clickCount */, false /* popupTrigger */,
819 scrollType, scrollAmount,
820 wheelRotation, preciseWheelRotation));
821 }
822
823 /*
824 * Called by the delegate when a key is pressed.
825 */
826 public void dispatchKeyEvent(int id, long when, int modifiers,
827 int keyCode, char keyChar, int keyLocation)
828 {
829 LWComponentPeer focusOwner =
830 LWKeyboardFocusManagerPeer.getInstance(getAppContext()).
831 getFocusOwner();
832
833 // Null focus owner may receive key event when
834 // application hides the focused window upon ESC press
835 // (AWT transfers/clears the focus owner) and pending ESC release
836 // may come to already hidden window. This check eliminates NPE.
837 if (focusOwner != null) {
838 KeyEvent event =
839 new KeyEvent(focusOwner.getTarget(), id, when, modifiers,
840 keyCode, keyChar, keyLocation);
841 focusOwner.postEvent(event);
842 }
843 }
844
845
846 // ---- UTILITY METHODS ---- //
847
848 private void postWindowStateChangedEvent(int newWindowState) {
849 if (getTarget() instanceof Frame) {
850 AWTAccessor.getFrameAccessor().setExtendedState(
851 (Frame)getTarget(), newWindowState);
852 }
853 WindowEvent stateChangedEvent = new WindowEvent(getTarget(),
854 WindowEvent.WINDOW_STATE_CHANGED,
855 windowState, newWindowState);
856 postEvent(stateChangedEvent);
857 windowState = newWindowState;
858 }
859
860 private static int getGraphicsConfigScreen(GraphicsConfiguration gc) {
861 // TODO: this method can be implemented in a more
862 // efficient way by forwarding to the delegate
1158
1159 LWKeyboardFocusManagerPeer manager = LWKeyboardFocusManagerPeer.
1160 getInstance(getAppContext());
1161
1162 Window oppositeWindow = becomesFocused ? manager.getCurrentFocusedWindow() : null;
1163
1164 // Note, the method is not called:
1165 // - when the opposite (gaining focus) window is an owned/owner window.
1166 // - for a simple window in any case.
1167 if (!becomesFocused &&
1168 (isGrabbing() || getOwnerFrameDialog(grabbingWindow) == this))
1169 {
1170 focusLog.fine("ungrabbing on " + grabbingWindow);
1171 // ungrab a simple window if its owner looses activation.
1172 grabbingWindow.ungrab();
1173 }
1174
1175 manager.setFocusedWindow(becomesFocused ? LWWindowPeer.this : null);
1176
1177 int eventID = becomesFocused ? WindowEvent.WINDOW_GAINED_FOCUS : WindowEvent.WINDOW_LOST_FOCUS;
1178 WindowEvent windowEvent = new WindowEvent(getTarget(), eventID, oppositeWindow);
1179
1180 // TODO: wrap in SequencedEvent
1181 postEvent(windowEvent);
1182 }
1183
1184 private static LWWindowPeer getOwnerFrameDialog(LWWindowPeer peer) {
1185 Window owner = (peer != null ? peer.getTarget().getOwner() : null);
1186 while (owner != null && !(owner instanceof Frame || owner instanceof Dialog)) {
1187 owner = owner.getOwner();
1188 }
1189 return owner != null ? (LWWindowPeer)owner.getPeer() : null;
1190 }
1191
1192 /**
1193 * Returns the foremost modal blocker of this window, or null.
1194 */
1195 public LWWindowPeer getBlocker() {
1196 synchronized (getPeerTreeLock()) {
1197 LWWindowPeer blocker = this.blocker;
1198 if (blocker == null) {
|
718 int targetIdx = (button > 3) ? MouseEvent.BUTTON2 - 1 : button - 1;
719
720 // MOUSE_ENTERED/EXITED are generated for the components strictly under
721 // mouse even when dragging. That's why we first update lastMouseEventPeer
722 // based on initial targetPeer value and only then recalculate targetPeer
723 // for MOUSE_DRAGGED/RELEASED events
724 if (id == MouseEvent.MOUSE_PRESSED) {
725
726 // Ungrab only if this window is not an owned window of the grabbing one.
727 if (!isGrabbing() && grabbingWindow != null &&
728 grabbingWindow != getOwnerFrameDialog(this))
729 {
730 grabbingWindow.ungrab();
731 }
732 if (otherButtonsPressed == 0) {
733 mouseClickButtons = eventButtonMask;
734 } else {
735 mouseClickButtons |= eventButtonMask;
736 }
737
738 // The window should be focused on mouse click. If it gets activated by the native platform,
739 // this request will be no op. It will take effect when:
740 // 1. A simple not focused window is clicked.
741 // 2. An active but not focused owner frame/dialog is clicked.
742 // The mouse event then will trigger a focus request "in window" to the component, so the window
743 // should gain focus before.
744 requestWindowFocus(CausedFocusEvent.Cause.MOUSE_EVENT);
745
746 mouseDownTarget[targetIdx] = targetPeer;
747 } else if (id == MouseEvent.MOUSE_DRAGGED) {
748 // Cocoa dragged event has the information about which mouse
749 // button is being dragged. Use it to determine the peer that
750 // should receive the dragged event.
751 targetPeer = mouseDownTarget[targetIdx];
752 mouseClickButtons &= ~modifiers;
753 } else if (id == MouseEvent.MOUSE_RELEASED) {
754 // TODO: currently, mouse released event goes to the same component
755 // that received corresponding mouse pressed event. For most cases,
756 // it's OK, however, we need to make sure that our behavior is consistent
757 // with 1.6 for cases where component in question have been
758 // hidden/removed in between of mouse pressed/released events.
759 targetPeer = mouseDownTarget[targetIdx];
760
761 if ((modifiers & eventButtonMask) == 0) {
762 mouseDownTarget[targetIdx] = null;
763 }
764
765 // mouseClickButtons is updated below, after MOUSE_CLICK is sent
817
818 Point lp = targetPeer.windowToLocal(x, y, this);
819 // TODO: fill "bdata" member of AWTEvent
820 // TODO: screenX/screenY
821 postEvent(new MouseWheelEvent(targetPeer.getTarget(),
822 MouseEvent.MOUSE_WHEEL,
823 when, modifiers,
824 lp.x, lp.y,
825 0, 0, /* screenX, Y */
826 0 /* clickCount */, false /* popupTrigger */,
827 scrollType, scrollAmount,
828 wheelRotation, preciseWheelRotation));
829 }
830
831 /*
832 * Called by the delegate when a key is pressed.
833 */
834 public void dispatchKeyEvent(int id, long when, int modifiers,
835 int keyCode, char keyChar, int keyLocation)
836 {
837 LWKeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance(getAppContext());
838
839 LWComponentPeer focusOwner = kfmPeer.getFocusOwner();
840
841 if (focusOwner == null) {
842 focusOwner = kfmPeer.getFocusedWindow();
843
844 if (focusOwner == null) {
845 focusOwner = this;
846 }
847 }
848 focusOwner.postEvent(new KeyEvent(focusOwner.getTarget(), id, when, modifiers,
849 keyCode, keyChar, keyLocation));
850 }
851
852
853 // ---- UTILITY METHODS ---- //
854
855 private void postWindowStateChangedEvent(int newWindowState) {
856 if (getTarget() instanceof Frame) {
857 AWTAccessor.getFrameAccessor().setExtendedState(
858 (Frame)getTarget(), newWindowState);
859 }
860 WindowEvent stateChangedEvent = new WindowEvent(getTarget(),
861 WindowEvent.WINDOW_STATE_CHANGED,
862 windowState, newWindowState);
863 postEvent(stateChangedEvent);
864 windowState = newWindowState;
865 }
866
867 private static int getGraphicsConfigScreen(GraphicsConfiguration gc) {
868 // TODO: this method can be implemented in a more
869 // efficient way by forwarding to the delegate
1165
1166 LWKeyboardFocusManagerPeer manager = LWKeyboardFocusManagerPeer.
1167 getInstance(getAppContext());
1168
1169 Window oppositeWindow = becomesFocused ? manager.getCurrentFocusedWindow() : null;
1170
1171 // Note, the method is not called:
1172 // - when the opposite (gaining focus) window is an owned/owner window.
1173 // - for a simple window in any case.
1174 if (!becomesFocused &&
1175 (isGrabbing() || getOwnerFrameDialog(grabbingWindow) == this))
1176 {
1177 focusLog.fine("ungrabbing on " + grabbingWindow);
1178 // ungrab a simple window if its owner looses activation.
1179 grabbingWindow.ungrab();
1180 }
1181
1182 manager.setFocusedWindow(becomesFocused ? LWWindowPeer.this : null);
1183
1184 int eventID = becomesFocused ? WindowEvent.WINDOW_GAINED_FOCUS : WindowEvent.WINDOW_LOST_FOCUS;
1185 WindowEvent windowEvent = new TimedWindowEvent(getTarget(), eventID, oppositeWindow, System.currentTimeMillis());
1186
1187 // TODO: wrap in SequencedEvent
1188 postEvent(windowEvent);
1189 }
1190
1191 private static LWWindowPeer getOwnerFrameDialog(LWWindowPeer peer) {
1192 Window owner = (peer != null ? peer.getTarget().getOwner() : null);
1193 while (owner != null && !(owner instanceof Frame || owner instanceof Dialog)) {
1194 owner = owner.getOwner();
1195 }
1196 return owner != null ? (LWWindowPeer)owner.getPeer() : null;
1197 }
1198
1199 /**
1200 * Returns the foremost modal blocker of this window, or null.
1201 */
1202 public LWWindowPeer getBlocker() {
1203 synchronized (getPeerTreeLock()) {
1204 LWWindowPeer blocker = this.blocker;
1205 if (blocker == null) {
|