268 } 269 } 270 return se.dispatched; 271 } 272 273 /* 274 * Checks if the focus window event follows key events waiting in the type-ahead 275 * queue (if any). This may happen when a user types ahead in the window, the client 276 * listeners hang EDT for a while, and the user switches b/w toplevels. In that 277 * case the focus window events may be dispatched before the type-ahead events 278 * get handled. This may lead to wrong focus behavior and in order to avoid it, 279 * the focus window events are reposted to the end of the event queue. See 6981400. 280 */ 281 private boolean repostIfFollowsKeyEvents(WindowEvent e) { 282 if (!(e instanceof TimedWindowEvent)) { 283 return false; 284 } 285 TimedWindowEvent we = (TimedWindowEvent)e; 286 long time = we.getWhen(); 287 synchronized (this) { 288 for (KeyEvent ke: enqueuedKeyEvents) { 289 if (time >= ke.getWhen()) { 290 SunToolkit.postEvent(AppContext.getAppContext(), new SequencedEvent(e)); 291 return true; 292 } 293 } 294 } 295 return false; 296 } 297 298 /** 299 * This method is called by the AWT event dispatcher requesting that the 300 * current KeyboardFocusManager dispatch the specified event on its behalf. 301 * DefaultKeyboardFocusManagers dispatch all FocusEvents, all WindowEvents 302 * related to focus, and all KeyEvents. These events are dispatched based 303 * on the KeyboardFocusManager's notion of the focus owner and the focused 304 * and active Windows, sometimes overriding the source of the specified 305 * AWTEvent. If this method returns <code>false</code>, then the AWT event 306 * dispatcher will attempt to dispatch the event itself. 307 * 308 * @param e the AWTEvent to be dispatched 309 * @return <code>true</code> if this method dispatched the event; 310 * <code>false</code> otherwise 311 */ 312 public boolean dispatchEvent(AWTEvent e) { 313 if (focusLog.isLoggable(PlatformLogger.FINE) && (e instanceof WindowEvent || e instanceof FocusEvent)) { 314 focusLog.fine("" + e); | 268 } 269 } 270 return se.dispatched; 271 } 272 273 /* 274 * Checks if the focus window event follows key events waiting in the type-ahead 275 * queue (if any). This may happen when a user types ahead in the window, the client 276 * listeners hang EDT for a while, and the user switches b/w toplevels. In that 277 * case the focus window events may be dispatched before the type-ahead events 278 * get handled. This may lead to wrong focus behavior and in order to avoid it, 279 * the focus window events are reposted to the end of the event queue. See 6981400. 280 */ 281 private boolean repostIfFollowsKeyEvents(WindowEvent e) { 282 if (!(e instanceof TimedWindowEvent)) { 283 return false; 284 } 285 TimedWindowEvent we = (TimedWindowEvent)e; 286 long time = we.getWhen(); 287 synchronized (this) { 288 KeyEvent ke = enqueuedKeyEvents.isEmpty() ? null : enqueuedKeyEvents.getFirst(); 289 if (ke != null && time >= ke.getWhen()) { 290 TypeAheadMarker marker = typeAheadMarkers.getFirst(); 291 if (marker != null) { 292 Window toplevel = marker.untilFocused.getContainingWindow(); 293 // Check that the component awaiting focus belongs to 294 // the current focused window. See 8015454. 295 if (toplevel != null && toplevel.isFocused()) { 296 SunToolkit.postEvent(AppContext.getAppContext(), new SequencedEvent(e)); 297 return true; 298 } 299 } 300 } 301 } 302 return false; 303 } 304 305 /** 306 * This method is called by the AWT event dispatcher requesting that the 307 * current KeyboardFocusManager dispatch the specified event on its behalf. 308 * DefaultKeyboardFocusManagers dispatch all FocusEvents, all WindowEvents 309 * related to focus, and all KeyEvents. These events are dispatched based 310 * on the KeyboardFocusManager's notion of the focus owner and the focused 311 * and active Windows, sometimes overriding the source of the specified 312 * AWTEvent. If this method returns <code>false</code>, then the AWT event 313 * dispatcher will attempt to dispatch the event itself. 314 * 315 * @param e the AWTEvent to be dispatched 316 * @return <code>true</code> if this method dispatched the event; 317 * <code>false</code> otherwise 318 */ 319 public boolean dispatchEvent(AWTEvent e) { 320 if (focusLog.isLoggable(PlatformLogger.FINE) && (e instanceof WindowEvent || e instanceof FocusEvent)) { 321 focusLog.fine("" + e); |