Skip to content

Commit

Permalink
8274751: Drag And Drop hangs on Windows
Browse files Browse the repository at this point in the history
Backport-of: 7a0a6c95a53c6cb3340328d6543a97807320b740
  • Loading branch information
mrserb committed Mar 17, 2022
1 parent f67a3a5 commit ee7a603
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/java.desktop/windows/native/libawt/windows/awt_DnDDS.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. 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
Expand Down Expand Up @@ -267,13 +267,13 @@ void AwtDragSource::_DoDragDrop(void* param) {
dragSource->Signal();

AwtToolkit &toolkit = AwtToolkit::GetInstance();
toolkit.isInDoDragDropLoop = TRUE;
toolkit.isDnDSourceActive = TRUE;
res = ::DoDragDrop(dragSource,
dragSource,
convertActionsToDROPEFFECT(dragSource->m_actions),
&effects
);
toolkit.isInDoDragDropLoop = FALSE;
toolkit.isDnDSourceActive = FALSE;

if (effects == DROPEFFECT_NONE && dragSource->m_dwPerformedDropEffect != DROPEFFECT_NONE) {
effects = dragSource->m_dwPerformedDropEffect;
Expand Down
16 changes: 8 additions & 8 deletions src/java.desktop/windows/native/libawt/windows/awt_DnDDT.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. 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
Expand Down Expand Up @@ -141,7 +141,7 @@ static void ScaleDown(POINT &cp, HWND m_window) {

HRESULT __stdcall AwtDropTarget::DragEnter(IDataObject __RPC_FAR *pDataObj, DWORD grfKeyState, POINTL pt, DWORD __RPC_FAR *pdwEffect) {
TRY;
AwtToolkit::GetInstance().isInDoDragDropLoop = TRUE;
AwtToolkit::GetInstance().isDnDTargetActive = TRUE;
if (NULL != m_pIDropTargetHelper) {
m_pIDropTargetHelper->DragEnter(
m_window,
Expand All @@ -161,7 +161,7 @@ HRESULT __stdcall AwtDropTarget::DragEnter(IDataObject __RPC_FAR *pDataObj, DWOR
(IsLocalDnD() && !IsLocalDataObject(pDataObj)))
{
*pdwEffect = retEffect;
AwtToolkit::GetInstance().isInDoDragDropLoop = FALSE;
AwtToolkit::GetInstance().isDnDTargetActive = FALSE;
return ret;
}

Expand All @@ -173,7 +173,7 @@ HRESULT __stdcall AwtDropTarget::DragEnter(IDataObject __RPC_FAR *pDataObj, DWOR
}

if (JNU_IsNull(env, m_dtcp) || !JNU_IsNull(env, safe_ExceptionOccurred(env))) {
AwtToolkit::GetInstance().isInDoDragDropLoop = FALSE;
AwtToolkit::GetInstance().isDnDTargetActive = FALSE;
return ret;
}

Expand All @@ -200,12 +200,12 @@ HRESULT __stdcall AwtDropTarget::DragEnter(IDataObject __RPC_FAR *pDataObj, DWOR
env->ExceptionDescribe();
env->ExceptionClear();
actions = java_awt_dnd_DnDConstants_ACTION_NONE;
AwtToolkit::GetInstance().isInDoDragDropLoop = FALSE;
AwtToolkit::GetInstance().isDnDTargetActive = FALSE;
}
} catch (std::bad_alloc&) {
retEffect = ::convertActionsToDROPEFFECT(actions);
*pdwEffect = retEffect;
AwtToolkit::GetInstance().isInDoDragDropLoop = FALSE;
AwtToolkit::GetInstance().isDnDTargetActive = FALSE;
throw;
}

Expand Down Expand Up @@ -421,7 +421,7 @@ void AwtDropTarget::DropDone(jboolean success, jint action) {
m_dropSuccess = success;
m_dropActions = action;
AwtToolkit::GetInstance().QuitMessageLoop(AwtToolkit::EXIT_ENCLOSING_LOOP);
AwtToolkit::GetInstance().isInDoDragDropLoop = FALSE;
AwtToolkit::GetInstance().isDnDTargetActive = FALSE;
}

/**
Expand Down Expand Up @@ -1136,7 +1136,7 @@ void AwtDropTarget::UnloadCache() {

void AwtDropTarget::DragCleanup(void) {
UnloadCache();
AwtToolkit::GetInstance().isInDoDragDropLoop = FALSE;
AwtToolkit::GetInstance().isDnDTargetActive = FALSE;
}

BOOL AwtDropTarget::IsLocalDataObject(IDataObject __RPC_FAR *pDataObject) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. 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
Expand Down Expand Up @@ -344,7 +344,8 @@ AwtToolkit::AwtToolkit() {

m_waitEvent = ::CreateEvent(NULL, FALSE, FALSE, NULL);
m_inputMethodWaitEvent = ::CreateEvent(NULL, FALSE, FALSE, NULL);
isInDoDragDropLoop = FALSE;
isDnDSourceActive = FALSE;
isDnDTargetActive = FALSE;
eventNumber = 0;
}

Expand Down Expand Up @@ -3012,7 +3013,7 @@ Java_sun_awt_windows_WToolkit_syncNativeQueue(JNIEnv *env, jobject self, jlong t
tk.PostMessage(WM_SYNC_WAIT, 0, 0);
for(long t = 2; t < timeout &&
WAIT_TIMEOUT == ::WaitForSingleObject(tk.m_waitEvent, 2); t+=2) {
if (tk.isInDoDragDropLoop) {
if (tk.isDnDSourceActive || tk.isDnDTargetActive) {
break;
}
}
Expand Down Expand Up @@ -3216,7 +3217,7 @@ LRESULT AwtToolkit::InvokeInputMethodFunction(UINT msg, WPARAM wParam, LPARAM lP
* the IME completion.
*/
CriticalSection::Lock lock(m_inputMethodLock);
if (isInDoDragDropLoop) {
if (isDnDSourceActive || isDnDTargetActive) {
SendMessage(msg, wParam, lParam);
::ResetEvent(m_inputMethodWaitEvent);
return m_inputMethodData;
Expand Down
5 changes: 3 additions & 2 deletions src/java.desktop/windows/native/libawt/windows/awt_Toolkit.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. 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
Expand Down Expand Up @@ -441,7 +441,8 @@ class AwtToolkit {

HANDLE m_waitEvent;
volatile DWORD eventNumber;
volatile BOOL isInDoDragDropLoop;
volatile BOOL isDnDSourceActive;
volatile BOOL isDnDTargetActive;
private:
HWND CreateToolkitWnd(LPCTSTR name);

Expand Down

1 comment on commit ee7a603

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.