eclipse-platform / eclipse.platform.swt

Eclipse SWT
https://www.eclipse.org/swt/
Eclipse Public License 2.0
105 stars 125 forks source link

Browser control with SWT.EDGE does not emit Activate/Decactivate events and does not activate parts in an RCP application #1139

Open pms1 opened 4 months ago

pms1 commented 4 months ago

Describe the bug In an Eclipse RCP application with a Browser control with SWT.EDGE in a view, that view does not get activated when another view is activate and a left click in the view with the browser is performed. It works as expected when SWT.NONE is used instead of SWT.EDGE.

An event listener on SWT.Activate and SWT.Deactivate is never called for a Browser with SWT.EDGE, and even if I don't know if this is related, it would be my guess.

To Reproduce There is an example RCP application at https://github.com/pms1/swt-browser-activate that can be used to reproduce the problem. It opens 3 views, one with Browser SWT.NONE, one with Browser SWT.EDGE and one with a button. Clicking into those views shows that the view with the EDGE browser never becomes activated and that no events are emitted (debug output on System.out).

Expected behavior Browser with SWT.EDGE behaves like a Browser with SWT.NONE regarding activation and deactivation.

Screenshots n.a.

Environment:

  1. Select the platform(s) on which the behavior is seen:

      • [ ] All OS
      • [x] Windows
      • [ ] Linux
      • [ ] macOS
  2. Additional OS info (e.g. OS version, Linux Desktop, etc) Windows 10 22H2 (Build 19045.4170) WebView2 runtime 122.0.2365.92

  3. JRE/JDK version Java 17.0.10 (version included in Eclipse 2024-03)

Version since Observed in SWT 3.125 from Eclipse 2024-03 (4.31.0). Not checked with older versions.

Workaround (or) Additional context n.a.

N1k145 commented 1 month ago

We are currently experiencing the same issue. I tested the fix #1187 from @eneufeld and noticed the same issue as @fedejeanne. So for me this is not fixed.

I dug a bit into this and noticed a few tings, please be aware that these are just my observations from an outside perspective and maybe not how things actually work as I could have missed something.

To activate a Part by clicking into it, a few things and events have to happen;

  1. SWT Widget gets the Focus by clicking into it
  2. A focus event is triggered
  3. That reaches the Shell that then switched the "active Control" (setActiveControl())
  4. and only if this is a different one than the current active, an activate event is sent.
  5. That event is collected by the PartService that activates then the Part.

The fix from @eneufeld tries to solve this by triggering this focus event by calling forceFocus(). But then we run into the issue that forceFocus() checks if the target control is already in focus, with "isFocusControl()" and later down with "hasFocus()". For me this is already the case when forceFocus() is called, so the manually set focus is never triggered as the Browser has already the focus, which leads to the whole chain not being triggered correctly.

I tried to play around with the focus gained and focus lost callback of Edge, but easily end up in an endless activation and deactivation loop or with a solution that works only in 60% of the cases. I have the feeling that we have here some issue with race conditions.

I also have the feeling that I am missing something, maybe curtail between step 2 and 3 in my observation.

(fyi @HeikoKlare)

fedejeanne commented 1 month ago

Thank you @N1k145 for your analysis! I'm going to reopen this issue since it has been created with the title "Browser control with SWT.EDGE does not emit Activate/Decactivate events [...]", which tells me that the issue you described in https://github.com/eclipse-platform/eclipse.platform.swt/issues/1139#issuecomment-2136552473 and I observed in https://github.com/eclipse-platform/eclipse.platform.swt/pull/1187#issuecomment-2090125163 should be fixed before closing the issue.

1187 fixed half of the issue (reacting to the events) but the other half (emitting the events) still needs to be fixed.

Sadly, I can't address this issue right now since I have other topics to work on, but maybe @eneufeld / @N1k145 would like to dig deeper into it?