diff options
Diffstat (limited to 'src/java.desktop')
16 files changed, 135 insertions, 77 deletions
diff --git a/src/java.desktop/macosx/classes/sun/lwawt/LWComponentPeer.java b/src/java.desktop/macosx/classes/sun/lwawt/LWComponentPeer.java index 05106167532..c11039edd29 100644 --- a/src/java.desktop/macosx/classes/sun/lwawt/LWComponentPeer.java +++ b/src/java.desktop/macosx/classes/sun/lwawt/LWComponentPeer.java @@ -934,7 +934,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> int result = LWKeyboardFocusManagerPeer.shouldNativelyFocusHeavyweight( getTarget(), lightweightChild, temporary, - focusedWindowChangeAllowed, time, cause); + focusedWindowChangeAllowed, time, cause, false); switch (result) { case LWKeyboardFocusManagerPeer.SNFH_FAILURE: return false; @@ -975,9 +975,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> Component focusOwner = kfmPeer.getCurrentFocusOwner(); LWKeyboardFocusManagerPeer.deliverFocus(lightweightChild, - getTarget(), temporary, - focusedWindowChangeAllowed, - time, cause, focusOwner); + getTarget(), false, cause, focusOwner); }); case LWKeyboardFocusManagerPeer.SNFH_SUCCESS_HANDLED: diff --git a/src/java.desktop/share/classes/java/awt/KeyboardFocusManager.java b/src/java.desktop/share/classes/java/awt/KeyboardFocusManager.java index 5bd91e2912a..25342e08985 100644 --- a/src/java.desktop/share/classes/java/awt/KeyboardFocusManager.java +++ b/src/java.desktop/share/classes/java/awt/KeyboardFocusManager.java @@ -121,10 +121,11 @@ public abstract class KeyboardFocusManager boolean temporary, boolean focusedWindowChangeAllowed, long time, - FocusEvent.Cause cause) + FocusEvent.Cause cause, + boolean highPriorityEvents) { return KeyboardFocusManager.shouldNativelyFocusHeavyweight( - heavyweight, descendant, temporary, focusedWindowChangeAllowed, time, cause); + heavyweight, descendant, temporary, focusedWindowChangeAllowed, time, cause, highPriorityEvents); } public boolean processSynchronousLightweightTransfer(Component heavyweight, Component descendant, @@ -2381,7 +2382,8 @@ public abstract class KeyboardFocusManager */ static int shouldNativelyFocusHeavyweight (Component heavyweight, Component descendant, boolean temporary, - boolean focusedWindowChangeAllowed, long time, FocusEvent.Cause cause) + boolean focusedWindowChangeAllowed, long time, FocusEvent.Cause cause, + boolean highPriorityEvents) { if (log.isLoggable(PlatformLogger.Level.FINE)) { if (heavyweight == null) { @@ -2450,17 +2452,22 @@ public abstract class KeyboardFocusManager new FocusEvent(currentFocusOwner, FocusEvent.FOCUS_LOST, temporary, descendant, cause); - // Fix 5028014. Rolled out. - // SunToolkit.postPriorityEvent(currentFocusOwnerEvent); - SunToolkit.postEvent(currentFocusOwner.appContext, - currentFocusOwnerEvent); + if (highPriorityEvents) { + SunToolkit.postPriorityEvent(currentFocusOwnerEvent); + } else { + SunToolkit.postEvent(currentFocusOwner.appContext, + currentFocusOwnerEvent); + } } FocusEvent newFocusOwnerEvent = new FocusEvent(descendant, FocusEvent.FOCUS_GAINED, temporary, currentFocusOwner, cause); - // Fix 5028014. Rolled out. - // SunToolkit.postPriorityEvent(newFocusOwnerEvent); - SunToolkit.postEvent(descendant.appContext, newFocusOwnerEvent); + if (highPriorityEvents) { + SunToolkit.postPriorityEvent(newFocusOwnerEvent); + } else { + SunToolkit.postEvent(descendant.appContext, + newFocusOwnerEvent); + } if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) focusLog.finest("2. SNFH_HANDLED for {0}", String.valueOf(descendant)); diff --git a/src/java.desktop/share/classes/sun/awt/AWTAccessor.java b/src/java.desktop/share/classes/sun/awt/AWTAccessor.java index 518707a8ffc..7b1c7bb4c89 100644 --- a/src/java.desktop/share/classes/sun/awt/AWTAccessor.java +++ b/src/java.desktop/share/classes/sun/awt/AWTAccessor.java @@ -440,7 +440,8 @@ public final class AWTAccessor { boolean temporary, boolean focusedWindowChangeAllowed, long time, - Cause cause); + Cause cause, + boolean highPriorityEvents); /** * Delivers focus for the lightweight descendant of the heavyweight * synchronously. diff --git a/src/java.desktop/share/classes/sun/awt/KeyboardFocusManagerPeerImpl.java b/src/java.desktop/share/classes/sun/awt/KeyboardFocusManagerPeerImpl.java index 86b957398f7..83f9a83d7ef 100644 --- a/src/java.desktop/share/classes/sun/awt/KeyboardFocusManagerPeerImpl.java +++ b/src/java.desktop/share/classes/sun/awt/KeyboardFocusManagerPeerImpl.java @@ -107,9 +107,7 @@ public abstract class KeyboardFocusManagerPeerImpl implements KeyboardFocusManag @SuppressWarnings("deprecation") public static boolean deliverFocus(Component lightweightChild, Component target, - boolean temporary, - boolean focusedWindowChangeAllowed, - long time, + boolean highPriority, FocusEvent.Cause cause, Component currentFocusOwner) // provided by the descendant peers { @@ -128,7 +126,11 @@ public abstract class KeyboardFocusManagerPeerImpl implements KeyboardFocusManag if (focusLog.isLoggable(PlatformLogger.Level.FINER)) { focusLog.finer("Posting focus event: " + fl); } - SunToolkit.postEvent(SunToolkit.targetToAppContext(currentOwner), fl); + if (highPriority) { + SunToolkit.postPriorityEvent(fl); + } else { + SunToolkit.postEvent(SunToolkit.targetToAppContext(currentOwner), fl); + } } FocusEvent fg = new FocusEvent(lightweightChild, FocusEvent.FOCUS_GAINED, @@ -137,7 +139,11 @@ public abstract class KeyboardFocusManagerPeerImpl implements KeyboardFocusManag if (focusLog.isLoggable(PlatformLogger.Level.FINER)) { focusLog.finer("Posting focus event: " + fg); } - SunToolkit.postEvent(SunToolkit.targetToAppContext(lightweightChild), fg); + if (highPriority) { + SunToolkit.postPriorityEvent(fg); + } else { + SunToolkit.postEvent(SunToolkit.targetToAppContext(lightweightChild), fg); + } return true; } @@ -152,11 +158,12 @@ public abstract class KeyboardFocusManagerPeerImpl implements KeyboardFocusManag boolean temporary, boolean focusedWindowChangeAllowed, long time, - FocusEvent.Cause cause) + FocusEvent.Cause cause, + boolean highPriorityEvents) { return KfmAccessor.instance.shouldNativelyFocusHeavyweight( heavyweight, descendant, temporary, focusedWindowChangeAllowed, - time, cause); + time, cause, highPriorityEvents); } public static void removeLastFocusRequest(Component heavyweight) { diff --git a/src/java.desktop/share/classes/sun/awt/SunToolkit.java b/src/java.desktop/share/classes/sun/awt/SunToolkit.java index 6647b5f4fe0..e4846c4933d 100644 --- a/src/java.desktop/share/classes/sun/awt/SunToolkit.java +++ b/src/java.desktop/share/classes/sun/awt/SunToolkit.java @@ -434,6 +434,14 @@ public abstract class SunToolkit extends Toolkit * Post AWTEvent of high priority. */ public static void postPriorityEvent(final AWTEvent e) { + if (e.getID() == WindowEvent.WINDOW_LOST_FOCUS && + e instanceof TimedWindowEvent) + { + TimedWindowEvent twe = (TimedWindowEvent)e; + ((SunToolkit)Toolkit.getDefaultToolkit()). + setWindowDeactivationTime((Window)twe.getSource(), twe.getWhen()); + } + PeerEvent pe = new PeerEvent(Toolkit.getDefaultToolkit(), new Runnable() { @Override public void run() { diff --git a/src/java.desktop/unix/classes/sun/awt/X11/XComponentPeer.java b/src/java.desktop/unix/classes/sun/awt/X11/XComponentPeer.java index c9982937e20..904e507ffae 100644 --- a/src/java.desktop/unix/classes/sun/awt/X11/XComponentPeer.java +++ b/src/java.desktop/unix/classes/sun/awt/X11/XComponentPeer.java @@ -259,7 +259,7 @@ public class XComponentPeer extends XWindow implements ComponentPeer, DropTarget int result = XKeyboardFocusManagerPeer. shouldNativelyFocusHeavyweight(target, lightweightChild, temporary, focusedWindowChangeAllowed, - time, cause); + time, cause, false); switch (result) { case XKeyboardFocusManagerPeer.SNFH_FAILURE: diff --git a/src/java.desktop/unix/classes/sun/awt/X11/XEmbedChildProxyPeer.java b/src/java.desktop/unix/classes/sun/awt/X11/XEmbedChildProxyPeer.java index f10135cdd3c..524a70f4b43 100644 --- a/src/java.desktop/unix/classes/sun/awt/X11/XEmbedChildProxyPeer.java +++ b/src/java.desktop/unix/classes/sun/awt/X11/XEmbedChildProxyPeer.java @@ -198,7 +198,7 @@ public class XEmbedChildProxyPeer implements ComponentPeer, XEventDispatcher{ { int result = XKeyboardFocusManagerPeer .shouldNativelyFocusHeavyweight(proxy, lightweightChild, - temporary, false, time, cause); + temporary, false, time, cause, false); switch (result) { case XKeyboardFocusManagerPeer.SNFH_FAILURE: diff --git a/src/java.desktop/unix/classes/sun/awt/X11/XKeyboardFocusManagerPeer.java b/src/java.desktop/unix/classes/sun/awt/X11/XKeyboardFocusManagerPeer.java index 2ec736feb29..16ecc10974f 100644 --- a/src/java.desktop/unix/classes/sun/awt/X11/XKeyboardFocusManagerPeer.java +++ b/src/java.desktop/unix/classes/sun/awt/X11/XKeyboardFocusManagerPeer.java @@ -105,9 +105,7 @@ public class XKeyboardFocusManagerPeer extends KeyboardFocusManagerPeerImpl { { return KeyboardFocusManagerPeerImpl.deliverFocus(lightweightChild, target, - temporary, - focusedWindowChangeAllowed, - time, + false, cause, getInstance().getCurrentFocusOwner()); } diff --git a/src/java.desktop/windows/classes/sun/awt/windows/WComponentPeer.java b/src/java.desktop/windows/classes/sun/awt/windows/WComponentPeer.java index 5f1029409f0..0e71a501e72 100644 --- a/src/java.desktop/windows/classes/sun/awt/windows/WComponentPeer.java +++ b/src/java.desktop/windows/classes/sun/awt/windows/WComponentPeer.java @@ -701,7 +701,7 @@ public abstract class WComponentPeer extends WObjectPeer int result = WKeyboardFocusManagerPeer .shouldNativelyFocusHeavyweight((Component)target, lightweightChild, temporary, focusedWindowChangeAllowed, - time, cause); + time, cause, true); switch (result) { case WKeyboardFocusManagerPeer.SNFH_FAILURE: diff --git a/src/java.desktop/windows/classes/sun/awt/windows/WKeyboardFocusManagerPeer.java b/src/java.desktop/windows/classes/sun/awt/windows/WKeyboardFocusManagerPeer.java index f11409d4aca..9b5e8aed202 100644 --- a/src/java.desktop/windows/classes/sun/awt/windows/WKeyboardFocusManagerPeer.java +++ b/src/java.desktop/windows/classes/sun/awt/windows/WKeyboardFocusManagerPeer.java @@ -80,9 +80,7 @@ final class WKeyboardFocusManagerPeer extends KeyboardFocusManagerPeerImpl { // TODO: do something to eliminate this forwarding return KeyboardFocusManagerPeerImpl.deliverFocus(lightweightChild, target, - temporary, - focusedWindowChangeAllowed, - time, + true, cause, getNativeFocusOwner()); } diff --git a/src/java.desktop/windows/classes/sun/awt/windows/WToolkit.java b/src/java.desktop/windows/classes/sun/awt/windows/WToolkit.java index ebabc919e98..412c28a9185 100644 --- a/src/java.desktop/windows/classes/sun/awt/windows/WToolkit.java +++ b/src/java.desktop/windows/classes/sun/awt/windows/WToolkit.java @@ -139,6 +139,9 @@ public final class WToolkit extends SunToolkit implements Runnable { { @Override public Void run() { + // temporary measure, until corresponding code is disabled in IntelliJ platform + System.setProperty("action.aware.typeAhead", "false"); + String browserProp = System.getProperty("browser"); if (browserProp != null && browserProp.equals("sun.plugin")) { disableCustomPalette(); diff --git a/src/java.desktop/windows/native/libawt/windows/awt_Component.cpp b/src/java.desktop/windows/native/libawt/windows/awt_Component.cpp index 4e25c924e1e..3b74e66d399 100644 --- a/src/java.desktop/windows/native/libawt/windows/awt_Component.cpp +++ b/src/java.desktop/windows/native/libawt/windows/awt_Component.cpp @@ -103,6 +103,7 @@ HWND AwtComponent::sm_focusOwner = NULL; HWND AwtComponent::sm_focusedWindow = NULL; BOOL AwtComponent::sm_bMenuLoop = FALSE; BOOL AwtComponent::sm_inSynthesizeFocus = FALSE; +BOOL AwtComponent::sm_priorityFocusEvents = FALSE; /************************************************************************/ // Struct for _Reshape() and ReshapeNoCheck() methods @@ -1343,6 +1344,7 @@ void SpyWinMessage(HWND hwnd, UINT message, LPCTSTR szComment) { WIN_MSG(WM_AWT_COMPONENT_HIDE) WIN_MSG(WM_AWT_COMPONENT_SETFOCUS) WIN_MSG(WM_AWT_WINDOW_SETACTIVE) + WIN_MSG(WM_AWT_WINDOW_TOFRONT) WIN_MSG(WM_AWT_LIST_SETMULTISELECT) WIN_MSG(WM_AWT_HANDLE_EVENT) WIN_MSG(WM_AWT_PRINT_COMPONENT) @@ -2021,24 +2023,38 @@ LRESULT AwtComponent::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) * there. */ case WM_AWT_COMPONENT_SHOW: + sm_priorityFocusEvents = TRUE; Show(); + sm_priorityFocusEvents = FALSE; mr = mrConsume; break; case WM_AWT_COMPONENT_HIDE: + sm_priorityFocusEvents = TRUE; Hide(); + sm_priorityFocusEvents = FALSE; mr = mrConsume; break; case WM_AWT_COMPONENT_SETFOCUS: + sm_priorityFocusEvents = TRUE; if ((BOOL)wParam) { retValue = SynthesizeWmSetFocus(GetHWnd(), NULL); } else { retValue = SynthesizeWmKillFocus(GetHWnd(), NULL); } + sm_priorityFocusEvents = FALSE; mr = mrConsume; break; case WM_AWT_WINDOW_SETACTIVE: + sm_priorityFocusEvents = TRUE; retValue = (LRESULT)((AwtWindow*)this)->AwtSetActiveWindow((BOOL)wParam); + sm_priorityFocusEvents = FALSE; + mr = mrConsume; + break; + case WM_AWT_WINDOW_TOFRONT: + sm_priorityFocusEvents = TRUE; + ((AwtWindow*)this)->ToFront(); + sm_priorityFocusEvents = FALSE; mr = mrConsume; break; diff --git a/src/java.desktop/windows/native/libawt/windows/awt_Component.h b/src/java.desktop/windows/native/libawt/windows/awt_Component.h index caae1d77324..e8897b818a1 100644 --- a/src/java.desktop/windows/native/libawt/windows/awt_Component.h +++ b/src/java.desktop/windows/native/libawt/windows/awt_Component.h @@ -699,6 +699,7 @@ public: static void *GetNativeFocusOwner(); static BOOL sm_inSynthesizeFocus; + static BOOL sm_priorityFocusEvents; // Execute on Toolkit only. INLINE static LRESULT SynthesizeWmSetFocus(HWND targetHWnd, HWND oppositeHWnd) { diff --git a/src/java.desktop/windows/native/libawt/windows/awt_Window.cpp b/src/java.desktop/windows/native/libawt/windows/awt_Window.cpp index 06b4377bed3..b9c94a5c448 100644 --- a/src/java.desktop/windows/native/libawt/windows/awt_Window.cpp +++ b/src/java.desktop/windows/native/libawt/windows/awt_Window.cpp @@ -304,7 +304,7 @@ AwtWindow::Grab() { // we shouldn't perform grab in this case (see 4841881 & 6539458) Ungrab(); } else if (GetHWnd() != AwtComponent::GetFocusedWindow()) { - _ToFront(env->NewGlobalRef(GetPeer(env))); + _ToFront(env->NewGlobalRef(GetPeer(env)), FALSE); // Global ref was deleted in _ToFront } } @@ -1615,6 +1615,34 @@ void AwtWindow::SendComponentEvent(jint eventId) env->DeleteLocalRef(event); } +static void SendPriorityEvent(jobject event) { + JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); + + static jclass toolkitClass; + if (toolkitClass == NULL) { + toolkitClass = env->FindClass("sun/awt/SunToolkit"); + if (toolkitClass != NULL) { + toolkitClass = (jclass)env->NewGlobalRef(toolkitClass); + } + if (toolkitClass == NULL) { + return; + } + } + + static jmethodID postPriorityEventMID; + if (postPriorityEventMID == NULL) { + postPriorityEventMID = + env->GetStaticMethodID(toolkitClass, "postPriorityEvent", + "(Ljava/awt/AWTEvent;)V"); + DASSERT(postPriorityEventMID); + if (postPriorityEventMID == NULL) { + return; + } + } + + env->CallStaticVoidMethod(toolkitClass, postPriorityEventMID, event); +} + void AwtWindow::SendWindowEvent(jint id, HWND opposite, jint oldState, jint newState) { @@ -1645,25 +1673,6 @@ void AwtWindow::SendWindowEvent(jint id, HWND opposite, } } - static jclass sequencedEventCls; - if (sequencedEventCls == NULL) { - jclass sequencedEventClsLocal - = env->FindClass("java/awt/SequencedEvent"); - DASSERT(sequencedEventClsLocal); - CHECK_NULL(sequencedEventClsLocal); - sequencedEventCls = - (jclass)env->NewGlobalRef(sequencedEventClsLocal); - env->DeleteLocalRef(sequencedEventClsLocal); - } - - static jmethodID sequencedEventConst; - if (sequencedEventConst == NULL) { - sequencedEventConst = - env->GetMethodID(sequencedEventCls, "<init>", - "(Ljava/awt/AWTEvent;)V"); - CHECK_NULL(sequencedEventConst); - } - static jclass windowCls = NULL; if (windowCls == NULL) { jclass windowClsLocal = env->FindClass("java/awt/Window"); @@ -1717,20 +1726,15 @@ void AwtWindow::SendWindowEvent(jint id, HWND opposite, env->DeleteLocalRef(target); target = NULL; CHECK_NULL(event); - if (id == java_awt_event_WindowEvent_WINDOW_GAINED_FOCUS || - id == java_awt_event_WindowEvent_WINDOW_LOST_FOCUS) + if (AwtComponent::sm_priorityFocusEvents && + (id == java_awt_event_WindowEvent_WINDOW_GAINED_FOCUS || + id == java_awt_event_WindowEvent_WINDOW_LOST_FOCUS)) { - jobject sequencedEvent = env->NewObject(sequencedEventCls, - sequencedEventConst, - event); - DASSERT(!safe_ExceptionOccurred(env)); - DASSERT(sequencedEvent != NULL); - env->DeleteLocalRef(event); - event = sequencedEvent; + SendPriorityEvent(event); + } else { + SendEvent(event); } - SendEvent(event); - env->DeleteLocalRef(event); } @@ -2447,7 +2451,25 @@ ret: return result; } -void AwtWindow::_ToFront(void *param) +void AwtWindow::ToFront() { + if (::IsWindow(GetHWnd())) { + UINT flags = SWP_NOMOVE|SWP_NOSIZE; + BOOL focusable = IsFocusableWindow(); + BOOL autoRequestFocus = IsAutoRequestFocus(); + + if (!focusable || !autoRequestFocus) + { + flags = flags|SWP_NOACTIVATE; + } + ::SetWindowPos(GetHWnd(), HWND_TOP, 0, 0, 0, 0, flags); + if (focusable && autoRequestFocus) + { + ::SetForegroundWindow(GetHWnd()); + } + } +} + +void AwtWindow::_ToFront(void *param, BOOL wait) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); @@ -2460,24 +2482,20 @@ void AwtWindow::_ToFront(void *param) w = (AwtWindow *)pData; if (::IsWindow(w->GetHWnd())) { - UINT flags = SWP_NOMOVE|SWP_NOSIZE; - BOOL focusable = w->IsFocusableWindow(); - BOOL autoRequestFocus = w->IsAutoRequestFocus(); - - if (!focusable || !autoRequestFocus) - { - flags = flags|SWP_NOACTIVATE; - } - ::SetWindowPos(w->GetHWnd(), HWND_TOP, 0, 0, 0, 0, flags); - if (focusable && autoRequestFocus) - { - ::SetForegroundWindow(w->GetHWnd()); + if (wait) { + w->SendMessage(WM_AWT_WINDOW_TOFRONT, 0, 0); + } else { + w->ToFront(); } } ret: env->DeleteGlobalRef(self); } +static void _ToFrontWait(void *param) { + AwtWindow::_ToFront(param, TRUE); +} + void AwtWindow::_ToBack(void *param) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); @@ -3501,7 +3519,7 @@ Java_sun_awt_windows_WWindowPeer__1toFront(JNIEnv *env, jobject self) { TRY; - AwtToolkit::GetInstance().SyncCall(AwtWindow::_ToFront, + AwtToolkit::GetInstance().SyncCall(_ToFrontWait, env->NewGlobalRef(self)); // global ref is deleted in _ToFront() diff --git a/src/java.desktop/windows/native/libawt/windows/awt_Window.h b/src/java.desktop/windows/native/libawt/windows/awt_Window.h index e47ac17ded4..1afee5fed89 100644 --- a/src/java.desktop/windows/native/libawt/windows/awt_Window.h +++ b/src/java.desktop/windows/native/libawt/windows/awt_Window.h @@ -221,13 +221,15 @@ public: void UpdateWindow(JNIEnv* env, jintArray data, int width, int height, HBITMAP hNewBitmap = NULL); + void ToFront(); + INLINE virtual BOOL IsTopLevel() { return TRUE; } static AwtWindow * GetGrabbedWindow() { return m_grabbedWindow; } static void FlashWindowEx(HWND hWnd, UINT count, DWORD timeout, DWORD flags); // some methods invoked on Toolkit thread - static void _ToFront(void *param); + static void _ToFront(void *param, BOOL wait); static void _ToBack(void *param); static void _Grab(void *param); static void _Ungrab(void *param); diff --git a/src/java.desktop/windows/native/libawt/windows/awtmsg.h b/src/java.desktop/windows/native/libawt/windows/awtmsg.h index ba8a4492591..2aa00305b9b 100644 --- a/src/java.desktop/windows/native/libawt/windows/awtmsg.h +++ b/src/java.desktop/windows/native/libawt/windows/awtmsg.h @@ -203,6 +203,7 @@ enum { WM_AWT_COMPONENT_HIDE, WM_AWT_COMPONENT_SETFOCUS, WM_AWT_WINDOW_SETACTIVE, + WM_AWT_WINDOW_TOFRONT, WM_AWT_LIST_SETMULTISELECT, WM_AWT_HANDLE_EVENT, WM_AWT_PRINT_COMPONENT, |