Bug 576843

Summary: [macOS] An invisible control might get the default focus
Product: [Eclipse Project] Platform Reporter: Thomas Singer <ts-swt>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P3 CC: lshanmug
Version: 4.21   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X   
Whiteboard:

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.