6595651: Focus transfers broken for applications embedding AWT across processes
authorson
Thu, 13 Mar 2008 15:36:31 +0300
changeset 105 e08ac2105adc
parent 25 74fe6922716d
child 106 e8dca729bb5b
6595651: Focus transfers broken for applications embedding AWT across processes Summary: Now we allow cross-process focus requests if focus is in embedder's process. Reviewed-by: ant
jdk/src/windows/native/sun/windows/awt_Component.cpp
jdk/src/windows/native/sun/windows/awt_Frame.cpp
jdk/src/windows/native/sun/windows/awt_Toolkit.cpp
jdk/src/windows/native/sun/windows/awt_Toolkit.h
--- a/jdk/src/windows/native/sun/windows/awt_Component.cpp	Fri Feb 29 20:04:01 2008 -0800
+++ b/jdk/src/windows/native/sun/windows/awt_Component.cpp	Thu Mar 13 15:36:31 2008 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright 1996-2007 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 1996-2008 Sun Microsystems, Inc.  All Rights Reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -2190,8 +2190,11 @@
         DWORD fgProcessID;
         ::GetWindowThreadProcessId(fgWindow, &fgProcessID);
 
-        if (fgProcessID != ::GetCurrentProcessId()) {
-            // fix for 6458497.  we shouldn't request focus if it is out of our application.
+        if (fgProcessID != ::GetCurrentProcessId()
+            && !AwtToolkit::GetInstance().IsEmbedderProcessId(fgProcessID))
+        {
+            // fix for 6458497.  we shouldn't request focus if it is out of both
+            // our and embedder process.
             return FALSE;
         }
     }
--- a/jdk/src/windows/native/sun/windows/awt_Frame.cpp	Fri Feb 29 20:04:01 2008 -0800
+++ b/jdk/src/windows/native/sun/windows/awt_Frame.cpp	Thu Mar 13 15:36:31 2008 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright 1996-2007 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 1996-2008 Sun Microsystems, Inc.  All Rights Reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -221,8 +221,7 @@
 
                 // Update target's dimensions to reflect this embedded window.
                 ::GetClientRect(frame->m_hwnd, &rect);
-                ::MapWindowPoints(frame->m_hwnd, hwndParent, (LPPOINT)&rect,
-                                  2);
+                ::MapWindowPoints(frame->m_hwnd, hwndParent, (LPPOINT)&rect, 2);
 
                 env->SetIntField(target, AwtComponent::xID, rect.left);
                 env->SetIntField(target, AwtComponent::yID, rect.top);
@@ -231,6 +230,7 @@
                 env->SetIntField(target, AwtComponent::heightID,
                                  rect.bottom-rect.top);
                 frame->InitPeerGraphicsConfig(env, self);
+                AwtToolkit::GetInstance().RegisterEmbedderProcessId(hwndParent);
             } else {
                 jint state = env->GetIntField(target, AwtFrame::stateID);
                 DWORD exStyle;
--- a/jdk/src/windows/native/sun/windows/awt_Toolkit.cpp	Fri Feb 29 20:04:01 2008 -0800
+++ b/jdk/src/windows/native/sun/windows/awt_Toolkit.cpp	Thu Mar 13 15:36:31 2008 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright 1996-2007 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 1996-2008 Sun Microsystems, Inc.  All Rights Reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -354,6 +354,7 @@
     m_dllHandle = NULL;
 
     m_displayChanged = FALSE;
+    m_embedderProcessID = 0;
 
     // XXX: keyboard mapping should really be moved out of AwtComponent
     AwtComponent::InitDynamicKeyMapTable();
@@ -1442,49 +1443,17 @@
     }
 }
 
-/*
- * Returns a reference to the class java.awt.Component.
- */
-jclass
-getComponentClass(JNIEnv *env)
+// for now we support only one embedder, but should be ready for future
+void AwtToolkit::RegisterEmbedderProcessId(HWND embedder)
 {
-    static jclass componentCls = NULL;
-
-    // get global reference of java/awt/Component class (run only once)
-    if (componentCls == NULL) {
-        jclass componentClsLocal = env->FindClass("java/awt/Component");
-        DASSERT(componentClsLocal != NULL);
-        if (componentClsLocal == NULL) {
-            /* exception already thrown */
-            return NULL;
-        }
-        componentCls = (jclass)env->NewGlobalRef(componentClsLocal);
-        env->DeleteLocalRef(componentClsLocal);
+    if (m_embedderProcessID) {
+        // we already set embedder process and do not expect
+        // two different processes to embed the same AwtToolkit
+        return;
     }
-    return componentCls;
-}
 
-
-/*
- * Returns a reference to the class java.awt.MenuComponent.
- */
-jclass
-getMenuComponentClass(JNIEnv *env)
-{
-    static jclass menuComponentCls = NULL;
-
-    // get global reference of java/awt/MenuComponent class (run only once)
-    if (menuComponentCls == NULL) {
-        jclass menuComponentClsLocal = env->FindClass("java/awt/MenuComponent");
-        DASSERT(menuComponentClsLocal != NULL);
-        if (menuComponentClsLocal == NULL) {
-            /* exception already thrown */
-            return NULL;
-        }
-        menuComponentCls = (jclass)env->NewGlobalRef(menuComponentClsLocal);
-        env->DeleteLocalRef(menuComponentClsLocal);
-    }
-    return menuComponentCls;
+    embedder = ::GetAncestor(embedder, GA_ROOT);
+    ::GetWindowThreadProcessId(embedder, &m_embedderProcessID);
 }
 
 JNIEnv* AwtToolkit::m_env;
--- a/jdk/src/windows/native/sun/windows/awt_Toolkit.h	Fri Feb 29 20:04:01 2008 -0800
+++ b/jdk/src/windows/native/sun/windows/awt_Toolkit.h	Thu Mar 13 15:36:31 2008 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright 1996-2007 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 1996-2008 Sun Microsystems, Inc.  All Rights Reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -426,10 +426,17 @@
   */
 private:
     BOOL m_displayChanged;  /* Tracks displayChanged events */
+    // 0 means we are not embedded.
+    DWORD m_embedderProcessID;
 
 public:
     BOOL HasDisplayChanged() { return m_displayChanged; }
     void ResetDisplayChanged() { m_displayChanged = FALSE; }
+    void RegisterEmbedderProcessId(HWND);
+    BOOL IsEmbedderProcessId(const DWORD processID) const
+    {
+        return m_embedderProcessID && (processID == m_embedderProcessID);
+    }
 
  private:
     static JNIEnv *m_env;