JDK-6562716 : focus request queue is not updated when rejecting focus on EmbeddedFrame (win32)
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 5.0u12,7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-05-28
  • Updated: 2011-03-07
  • Resolved: 2011-03-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other JDK 7
5.0u14Fixed 7 b15Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
The problem is reproduced on Windows, IE, with JDK 5,6,7.

Having an applet that is displayed in IE browser so that its bounds are outside
of the visible client area of the browser.
At a certain moment the applet is requesting focus on the EmbeddedFrame and then
displaying a modal dialog. (The applet doesn't contain any component inside.)
The modal dialog has a text field that should receive focus upon showing
(by default). However this is not the case, when the dialog is displayed
its text field is not focused.

To reproduce. Run the applet attached in IE. Resize the IE window so that it hides
the applet. Click "Enter PIN" button. A dialog will pop up. Try to type something.
If nothing appears in the text field the bug is reproduced.

Comments
SUGGESTED FIX ------- awt_Component.cpp ------- *** /tmp/sccs.ZAaywd Tue May 29 11:49:19 2007 --- awt_Component.cpp Tue May 29 10:20:25 2007 *************** *** 2060,2069 **** --- 2060,2075 ---- AwtComponent *comp = AwtComponent::GetComponent(toplevelHWnd); if (comp && comp->IsEmbeddedFrame() && !((AwtFrame*)comp)->activateEmbeddedFrameOnSetFocus(hWndLostFocus)) { + // Fix for 6562716. + // In order that AwtSetFocus() returns FALSE. + sm_suppressFocusAndActivation = TRUE; + ::SetFocus(NULL); + sm_suppressFocusAndActivation = FALSE; + return mrConsume; } sm_focusOwner = GetHWnd(); sm_focusedWindow = toplevelHWnd;
29-05-2007

EVALUATION The reason is the following. When requesting focus on the EmbeddedFrame the request is queued by the KeyboardFocusManager in the focus request queue. AWT calls ::SetFocus() in AwtComponent::AwtSetFocus() method and WM_SETFOCUS message is generated as the result. In the AwtComponent::WmSetFocus() procedure the request is rejected though. This is due to the EmbeddedFrame window hasn't been activated. So, the activation is requested first. As the EmbeddedFrame window is not visible on the screen, the activation is also rejected in the AwtFrame::SynthesizeWmActivate() method. The AwtComponent::AwtSetFocus() returns TRUE as it thinks the focus has been set successfully (it checks native focus owner by calling ::GetFocus). However the correct behavior is that it should return FALSE so that the focus request queue would be updated appropriatelly (the last, rejected focus request should be removed) To achieve this, in the WmSetFocus() procedure we could reset native focus (by calling ::SetFocus(NULL)) so that ::GetFocus() doesn't return the hwnd on that we have just rejected focus.
28-05-2007