jdk8 Udiff src/share/classes/java/awt/Component.java (original) (raw)

Print this page


@@ -4708,11 +4708,14 @@ }

     /*
      * 0. Set timestamp and modifiers of current event.
      */

@@ -7604,17 +7607,37 @@ final boolean requestFocusHelper(boolean temporary, boolean focusedWindowChangeAllowed, CausedFocusEvent.Cause cause) { + // 1) Check if the event being dispatched is a system-generated mouse event. + AWTEvent currentEvent = EventQueue.getCurrentEvent(); + if (currentEvent instanceof MouseEvent && + SunToolkit.isSystemGenerated(currentEvent)) + { + // 2) Sanity check: if the mouse event component source belongs to the same containing window. + Component source = ((MouseEvent)currentEvent).getComponent(); + if (source == null || source.getContainingWindow() == getContainingWindow()) { + focusLog.finest("requesting focus by mouse event "in window""); + + // If both the conditions are fulfilled the focus request should be strictly + // bounded by the toplevel window. It's assumed that the mouse event activates + // the window (if it wasn't active) and this makes it possible for a focus + // request with a strong in-window requirement to change focus in the bounds + // of the toplevel. If, by any means, due to asynchronous nature of the event + // dispatching mechanism, the window happens to be natively inactive by the time + // this focus request is eventually handled, it should not re-activate the + // toplevel. Otherwise the result may not meet user expectations. See 6981400. + focusedWindowChangeAllowed = false; + } + } if (!isRequestFocusAccepted(temporary, focusedWindowChangeAllowed, cause)) { if (focusLog.isLoggable(PlatformLogger.FINEST)) { focusLog.finest("requestFocus is not accepted"); } return false; }

     // Update most-recent map
     KeyboardFocusManager.setMostRecentFocusOwner(this);

     Component window = this;
     while ( (window != null) && !(window instanceof Window)) {

@@ -7643,11 +7666,19 @@ } return false; }

     // Focus this Component