Bug 576843 - [macOS] An invisible control might get the default focus
Summary: [macOS] An invisible control might get the default focus
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.21   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-10-22 08:52 EDT by Thomas Singer CLA
Modified: 2021-10-25 06:26 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Singer CLA 2021-10-22 08:52:26 EDT
I have a StyledText control (created with the flags SWT.READ_ONLY | SWT.SINGLE) in our application with a FocusIn-Listener that has a couple of parents, one is set to invisible. However, when showing this shell, SWT wants to make this control focusable. I have added following code to the FocusIn-Listener:

  for (Control control = label; control != null; control = control.getParent()) {
    System.out.println(control.getClass() + " " + control.getVisible());
  }
  new Throwable().printStackTrace();

and I'm getting following output:

class org.eclipse.swt.custom.StyledText true
class org.eclipse.swt.widgets.Composite true
class org.eclipse.swt.widgets.Composite true
class org.eclipse.swt.widgets.Composite true
class org.eclipse.swt.widgets.Composite true
class org.eclipse.swt.widgets.Composite false
class com.syntevo.q.gui.QSashForm true
class org.eclipse.swt.widgets.Composite true
class org.eclipse.swt.widgets.Shell true

java.lang.Throwable
	at com.syntevo.q.gui.QBannerPanel$Banner.lambda$createLabel$0(QBannerPanel.java:202)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4441)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1512)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1535)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1516)
	at org.eclipse.swt.widgets.Control.sendFocusEvent(Control.java:3439)
	at org.eclipse.swt.widgets.Canvas.sendFocusEvent(Canvas.java:80)
	at org.eclipse.swt.widgets.Display.checkFocus(Display.java:684)
	at org.eclipse.swt.widgets.Shell.makeFirstResponder(Shell.java:1319)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:6281)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method)
	at org.eclipse.swt.internal.cocoa.NSWindow.makeKeyAndOrderFront(NSWindow.java:201)
	at org.eclipse.swt.widgets.Shell.makeKeyAndOrderFront(Shell.java:1337)
	at org.eclipse.swt.widgets.Shell.setWindowVisible(Shell.java:2104)
	at org.eclipse.swt.widgets.Shell.open(Shell.java:1397)
...

Unfortunately, I was not able to extract a test snippet where this behavior is reproducible. I suggest to add either an assertion or check to Display.checkFocus that the newControl.isVisible returns true.