1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-09 23:34:20 +00:00

DragAndDropContainer: Manage keyboard focus for the drag image when the target needs it hidden

The previous implementation would trigger assertions in
grabKeyboardFocus() when the DragImageComponent was hidden due to the
target returning false from shouldDrawDragImageWhenOver().

Hiding the image would also mean that its keyboard focus was lost. Now
focus is restored when the image becomes visible again.
This commit is contained in:
attila 2022-08-03 20:32:13 +02:00
parent ea84e14be0
commit acc6addb86

View file

@ -138,6 +138,8 @@ public:
setVisible (newTarget == nullptr || newTarget->shouldDrawDragImageWhenOver());
maintainKeyboardFocusWhenPossible();
if (newTargetComp != currentlyOverComp)
{
if (auto* lastTarget = getCurrentlyOver())
@ -233,6 +235,16 @@ private:
Time lastTimeOverTarget;
int originalInputSourceIndex;
MouseInputSource::InputSourceType originalInputSourceType;
bool canHaveKeyboardFocus = false;
void maintainKeyboardFocusWhenPossible()
{
const auto newCanHaveKeyboardFocus = isVisible();
if (std::exchange (canHaveKeyboardFocus, newCanHaveKeyboardFocus) != newCanHaveKeyboardFocus)
if (canHaveKeyboardFocus)
grabKeyboardFocus();
}
void updateSize()
{
@ -489,7 +501,6 @@ void DragAndDropContainer::startDragging (const var& sourceDescription,
dragImageComponent->sourceDetails.localPosition = sourceComponent->getLocalPoint (nullptr, lastMouseDown);
dragImageComponent->updateLocation (false, lastMouseDown);
dragImageComponent->grabKeyboardFocus();
#if JUCE_WINDOWS
// Under heavy load, the layered window's paint callback can often be lost by the OS,