Browse Source

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.
v7.0.9
attila 2 years ago
parent
commit
acc6addb86
1 changed files with 12 additions and 1 deletions
  1. +12
    -1
      modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp

+ 12
- 1
modules/juce_gui_basics/mouse/juce_DragAndDropContainer.cpp 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,


Loading…
Cancel
Save