United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4907493 : input focus not working with multiple applets

Details
Type:
Bug
Submit Date:
2003-08-15
Status:
Closed
Updated Date:
2003-12-19
Project Name:
JDK
Resolved Date:
2003-10-28
Component:
client-libs
OS:
solaris_2.6
Sub-Component:
java.awt
CPU:
generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
1.4.2_01
Fixed Versions:
1.4.2_04 (04)

Related Reports
Backport:

Sub Tasks

Description
If there are multiple applets with text input on the same webpage, one of the text input field steals the focus and it is not possible to enter text into textfield of another applet. This is happening on Netscape/Solaris with plugin enabled, but working correctly on Windows. Tested with JDK 1.4.2 FCS and 1.4.2_01 EA

to reproduce:

modify 

/java/re/jdk/1.4.2/latest/binaries/solaris-sparc/demo/applets/ArcTest/example1.html

to have two instances of the same  applet as follows

     <applet code=ArcTest.class width=400 height=400>
     </applet>
     <hr>
     <applet code=ArcTest.class width=400 height=400>
     <applet>

or load the already modified applet at /home/sko/tmp/ArcTest/example1.html

Load the modified html page into Netscape on Solaris to test with
Java Plugin. Try to type into the text fields in both the
applets and observe that one of the applets can not receive
input focus  correctly and it is impossible to type text into 
textfileds of that applet.

                                    

Comments
SUGGESTED FIX

src/solaris/native/sun/awt/awt_TopLevel.h
7c7
<  * @(#)awt_TopLevel.h 1.6 03/01/23
---
>  * %W% %E%
16a17
> extern void callSynthesize(JNIEnv *env,jobject peer);


src/solaris/native/sun/awt/awt_TopLevel.c
2c2
<  * @(#)awt_TopLevel.c 1.102 03/08/25
---
>  * %W% %E%
2076a2077,2100
> extern void callSynthesize(JNIEnv *env,jobject peer)
> {
>      EmbeddedFrame *ef;
>      Boolean dummy;
>      AWT_LOCK();
>      ef = theEmbeddedFrameList;
>      while (ef != NULL) {
>          if ((*env)->IsSameObject(env, ef->javaRef, peer)) {
>              XFocusChangeEvent xev;
>              xev.display = awt_display;
>              xev.serial = 0;
>              xev.type = FocusIn;
>              xev.send_event = False;
>              xev.window = XtWindow(ef->embeddedFrame);
>              xev.mode = NotifyNormal;
>              xev.detail = NotifyNonlinear;
>              shellEH(ef->embeddedFrame, peer, (XEvent*)&xev, &dummy);
>              break;
>          }
>          ef = ef->next;
>      }
>      AWT_UNLOCK();
> }
> 
4132,4152c4156
<     EmbeddedFrame *ef;
<     Boolean dummy;
< 
<     AWT_LOCK();
<     ef = theEmbeddedFrameList;
<     while (ef != NULL) {
<         if ((*env)->IsSameObject(env, ef->javaRef, this)) {
<             XFocusChangeEvent xev; 
<             xev.display = awt_display;
<             xev.serial = 0;
<             xev.type = FocusIn;
<             xev.send_event = False;
<             xev.window = XtWindow(ef->embeddedFrame);
<             xev.mode = NotifyNormal;
<             xev.detail = NotifyNonlinear;
<             shellEH(ef->embeddedFrame, this, (XEvent*)&xev, &dummy);
<             break;
<         }
<         ef = ef->next;
<     }
<     AWT_UNLOCK();
---
>   callSynthesize(env,this);



src/solaris/native/sun/awt/awt_MToolkit.c
2c2
<  * @(#)awt_MToolkit.c 1.206 03/01/23
---
>  * %W% %E%
1505a1506,1522
>                         void *peer;
>                         jobject target;
>                         jobject targetPeer;
>                         jobject l_peer;
>                         JNIEnv *env = (JNIEnv *) JNU_GetEnv(jvm, JNI_VERSION_1_2);
>                         peer = findPeer(&widget);
>                         if (peer == NULL)  return;
>                         target = findTopLevel(peer, env);
>                         if (target == NULL)  return;
>                         AWT_LOCK();
>                         l_peer = awt_canvas_getFocusedWindowPeer();
>                         AWT_UNLOCK();
>                         if (l_peer == NULL) return;
>                         targetPeer = (*env)->GetObjectField(env,target, componentIDs.peer);
>                         if (!(*env)->IsSameObject(env,targetPeer,l_peer))
>                             callSynthesize(env,targetPeer);

###@###.### 2003-09-14
                                     
2003-09-14
EVALUATION

Since this is an escalation, I will assume that a sustaining engineer 
will be working on it.  I will assign it to an AWT engineer for tracking 
purposes. 
###@###.### 2003-08-15

Usually a focus gain on setVisible of EmbeddedFrame is simulated but these applets both become visible at once and therefore only one of them actually gets the required focus events. When we click on the second "unlucky" applet the focus gain is not happening.
Solution is to catch all mouse events in awt_MToolkit.c:processOneEvent, then, find to which toplevel they go. 

Then, we should check if it is focused. If it is not focused - and it is
ButtonPress we need to call synthesizeFocusIn to generate
necessary focus events.

###@###.### 2003-09-14

We believe this problem has been resolved by the XEmbed work done in 1.5. 
###@###.### 2003-10-28
                                     
2003-09-14
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
1.4.2_04
tiger-beta

FIXED IN:
1.4.2_04
tiger-beta

INTEGRATED IN:
1.4.2_04
tiger-beta

VERIFIED IN:
1.4.2_04


                                     
2004-08-24



Hardware and Software, Engineered to Work Together