Fix a regression related to ToolBar focus

With commit 0fb96a1bfe8d922b17c0396b01dca4d98f1d65ff we made ToolBar non
focusable by mouse. This is not completelly correct. In SWT the ToolBar
is only focusable if it is created with SWT.FLAT style flag.

Render NO_FOCUS style flag on the client and switch focus behaviour
based on it.

Bug 570167: selecting an action inside a view does not give focus to the
view
https://bugs.eclipse.org/bugs/show_bug.cgi?id=570167

Change-Id: Ib37c9f5c2b2c58e233c6dbc26dad13d0acc41824
diff --git a/bundles/org.eclipse.rap.rwt/js/rwt/event/EventHandlerUtil.js b/bundles/org.eclipse.rap.rwt/js/rwt/event/EventHandlerUtil.js
index d703547..9c8cb68 100644
--- a/bundles/org.eclipse.rap.rwt/js/rwt/event/EventHandlerUtil.js
+++ b/bundles/org.eclipse.rap.rwt/js/rwt/event/EventHandlerUtil.js
@@ -203,8 +203,10 @@
       if( root ) {
         var focusTarget = target;
         while( !focusTarget.isFocusable() && focusTarget != root ) {
-          if(    focusTarget instanceof rwt.widgets.MenuBar
-              || focusTarget instanceof rwt.widgets.ToolItem )
+          if( focusTarget instanceof rwt.widgets.MenuBar ) {
+            return;
+          } else if(    focusTarget instanceof rwt.widgets.ToolBar
+                     && focusTarget.hasState( "rwt_NO_FOCUS" ) )
           {
             return;
           }
diff --git a/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/ToolBar.java b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/ToolBar.java
index 29ba10a..eeca104 100644
--- a/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/ToolBar.java
+++ b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/ToolBar.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2002, 2015 Innoopract Informationssysteme GmbH and others.
+ * Copyright (c) 2002, 2021 Innoopract Informationssysteme GmbH and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -359,6 +359,10 @@
   // Helping methods
 
   private static int checkStyle( int style ) {
+    int result = style;
+    if( ( result & SWT.FLAT ) == 0 ) {
+      result |= SWT.NO_FOCUS;
+    }
     /*
     * Even though it is legal to create this widget
     * with scroll bars, they serve no useful purpose
@@ -366,7 +370,7 @@
     * widget's client area.  The fix is to clear
     * the SWT style.
     */
-    return style & ~( SWT.H_SCROLL | SWT.V_SCROLL );
+    return result & ~( SWT.H_SCROLL | SWT.V_SCROLL );
   }
 
   void createItem( ToolItem item, int index ) {
diff --git a/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/toolbarkit/ToolBarLCA.java b/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/toolbarkit/ToolBarLCA.java
index 3b7f0c7..3950613 100644
--- a/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/toolbarkit/ToolBarLCA.java
+++ b/bundles/org.eclipse.rap.rwt/widgetkits/org/eclipse/swt/internal/widgets/toolbarkit/ToolBarLCA.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2002, 2015 Innoopract Informationssysteme GmbH and others.
+ * Copyright (c) 2002, 2021 Innoopract Informationssysteme GmbH and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -18,8 +18,8 @@
 
 import java.io.IOException;
 
-import org.eclipse.rap.rwt.internal.lifecycle.WidgetLCA;
 import org.eclipse.rap.rwt.internal.lifecycle.ControlLCAUtil;
+import org.eclipse.rap.rwt.internal.lifecycle.WidgetLCA;
 import org.eclipse.rap.rwt.internal.lifecycle.WidgetLCAUtil;
 import org.eclipse.rap.rwt.remote.RemoteObject;
 import org.eclipse.swt.widgets.ToolBar;
@@ -31,7 +31,7 @@
 
   private static final String TYPE = "rwt.widgets.ToolBar";
   private static final String[] ALLOWED_STYLES = {
-    "FLAT", "HORIZONTAL", "VERTICAL", "NO_RADIO_GROUP", "BORDER", "RIGHT"
+    "FLAT", "HORIZONTAL", "VERTICAL", "NO_RADIO_GROUP", "BORDER", "RIGHT", "NO_FOCUS"
   };
 
   @Override
diff --git a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/internal/widgets/toolbarkit/ToolBarLCA_Test.java b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/internal/widgets/toolbarkit/ToolBarLCA_Test.java
index e27b7b2..5283aa8 100644
--- a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/internal/widgets/toolbarkit/ToolBarLCA_Test.java
+++ b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/internal/widgets/toolbarkit/ToolBarLCA_Test.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2012, 2015 EclipseSource and others.
+ * Copyright (c) 2012, 2021 EclipseSource and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -76,6 +76,7 @@
     List<String> styles = getStyles( operation );
     assertTrue( styles.contains( "HORIZONTAL" ) );
     assertFalse( styles.contains( "H_SCROLL" ) );
+    assertTrue( styles.contains( "NO_FOCUS" ) );
   }
 
   @Test
@@ -89,6 +90,7 @@
     List<String> styles = getStyles( operation );
     assertTrue( styles.contains( "VERTICAL" ) );
     assertFalse( styles.contains( "V_SCROLL" ) );
+    assertTrue( styles.contains( "NO_FOCUS" ) );
   }
 
   @Test
@@ -99,7 +101,9 @@
 
     TestMessage message = Fixture.getProtocolMessage();
     CreateOperation operation = message.findCreateOperation( toolBar );
-    assertTrue( getStyles( operation ).contains( "FLAT" ) );
+    List<String> styles = getStyles( operation );
+    assertTrue( styles.contains( "FLAT" ) );
+    assertFalse( styles.contains( "NO_FOCUS" ) );
   }
 
   @Test
diff --git a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/widgets/ToolBar_Test.java b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/widgets/ToolBar_Test.java
index 3fd33b3..c623680 100644
--- a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/widgets/ToolBar_Test.java
+++ b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/widgets/ToolBar_Test.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2002, 2015 Innoopract Informationssysteme GmbH and others.
+ * Copyright (c) 2002, 2021 Innoopract Informationssysteme GmbH and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -52,6 +52,17 @@
   }
 
   @Test
+  public void testStyle() {
+    toolBar = new ToolBar( shell, SWT.NONE );
+
+    assertTrue( ( toolBar.getStyle() & SWT.NO_FOCUS ) != 0 );
+
+    toolBar = new ToolBar( shell, SWT.FLAT );
+
+    assertTrue( ( toolBar.getStyle() & SWT.NO_FOCUS ) == 0 );
+  }
+
+  @Test
   public void testCreation() throws IOException {
     assertEquals( 0, toolBar.getItemCount() );
     assertEquals( 0, toolBar.getItems().length );