266 } 267 } 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; | 266 } 267 } 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 if (we.isReposted()) { 287 // It is expected that the key events waiting in the type-ahead queue 288 // get dispatched during the first repost cycle. If they don't, there's 289 // likely a dependency b/w the key events and the focus window event 290 // (a type-ahead marker may be targeted at a component belonging to the 291 // window awaiting activation and focus). So, to avoid the risk of endless 292 // repost cycle, a focus window event is not reposted repeatedely. See 8015454. 293 return false; 294 } 295 long time = we.getWhen(); 296 synchronized (this) { 297 for (KeyEvent ke: enqueuedKeyEvents) { 298 if (time >= ke.getWhen()) { 299 we.setReposted(); 300 SunToolkit.postEvent(AppContext.getAppContext(), new SequencedEvent(e)); 301 return true; 302 } 303 } 304 } 305 return false; 306 } 307 308 /** 309 * This method is called by the AWT event dispatcher requesting that the 310 * current KeyboardFocusManager dispatch the specified event on its behalf. 311 * DefaultKeyboardFocusManagers dispatch all FocusEvents, all WindowEvents 312 * related to focus, and all KeyEvents. These events are dispatched based 313 * on the KeyboardFocusManager's notion of the focus owner and the focused 314 * and active Windows, sometimes overriding the source of the specified 315 * AWTEvent. If this method returns <code>false</code>, then the AWT event 316 * dispatcher will attempt to dispatch the event itself. 317 * 318 * @param e the AWTEvent to be dispatched 319 * @return <code>true</code> if this method dispatched the event; |