1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Avoid focus changes due to mouse clicks for Components with setMouseClickGrabsKeyboardFocus (false)

Even if this focus change is being propagated up by a child Component.
This commit is contained in:
attila 2023-12-15 18:30:50 +01:00
parent a38428aa8b
commit 7650c85ba5
2 changed files with 37 additions and 6 deletions

View file

@ -2,6 +2,37 @@
# develop
## Change
Components that have setMouseClickGrabsKeyboardFocus() set to false will not
accept or propagate keyboard focus to parent components due to a mouse click
event. This is now true even if the mouse click event happens in a child
component with setMouseClickGrabsKeyboardFocus (true) and
setWantsKeyboardFocus (false).
**Possible Issues**
Components that rely on child components propagating keyboard focus from a
mouse click, when those child components have setMouseClickGrabsKeyboardFocus()
set to false, will no longer grab keyboard focus.
**Workaround**
Add a MouseListener to the component receiving the click and override the
mouseDown() method in the listener. In the mouseDown() method call
Component::grabKeyboardFocus() for the component that should be focused.
**Rationale**
The intent of setMouseClickGrabsKeyboardFocus (false) is to reject focus changes
coming from mouse clicks even if the component is otherwise capable of receiving
keyboard focus.
The previous behaviour could result in surprising focus changes when a child
component was clicked. This manifested in the focus seemingly disappearing when
a PopupMenu item added to a component was clicked.
## Change
The NodeID argument to AudioProcessorGraph::addNode() has been changed to take

View file

@ -2180,13 +2180,10 @@ void Component::internalMouseDown (MouseInputSource source,
}
}
if (! flags.dontFocusOnMouseClickFlag)
{
grabKeyboardFocusInternal (focusChangedByMouseClick, true, FocusChangeDirection::unknown);
grabKeyboardFocusInternal (focusChangedByMouseClick, true, FocusChangeDirection::unknown);
if (checker.shouldBailOut())
return;
}
if (checker.shouldBailOut())
return;
if (flags.repaintOnMouseActivityFlag)
repaint();
@ -2623,6 +2620,9 @@ void Component::takeKeyboardFocus (FocusChangeType cause, FocusChangeDirection d
void Component::grabKeyboardFocusInternal (FocusChangeType cause, bool canTryParent, FocusChangeDirection direction)
{
if (flags.dontFocusOnMouseClickFlag && cause == FocusChangeType::focusChangedByMouseClick)
return;
if (! isShowing())
return;