Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXi Yan2018-08-14 09:56:43 -0400
committerEric Williams2018-08-14 14:11:13 -0400
commitddc3826de4b8789f3df31a6927cb568b8e21c19f (patch)
tree543274ba91c3f3a71e147d9301d84f799ffb8ef7
parent929dab9ad8b639a3663e4e51a7b3d1b4ebc7642f (diff)
downloadeclipse.platform.swt-ddc3826de4b8789f3df31a6927cb568b8e21c19f.tar.gz
eclipse.platform.swt-ddc3826de4b8789f3df31a6927cb568b8e21c19f.tar.xz
eclipse.platform.swt-ddc3826de4b8789f3df31a6927cb568b8e21c19f.zip
Bug 436841 - [GTK3] FocusOut/In and Activate/Deactivate events when
opening context menu Fix test issues caused by previous patch. Previous patch prevents activate event to be send when they are necessary, causing several shell issues. This patch has the logic: when context menu is shown, ignore focus_out/deactivate event for shells. When context menu is hidden, ignore activate event for shells. Tested with WorkbenchTextEditorTestSuite (workbench.texteditor.tests), UIAllTests (e4.ui.tests), and UiTestSuite (ui.tests) locally. In child Eclipse, Ctrl+F and pasting text via Ctrl+V pastes text into search entry. Holding down Ctrl and pressing E multiple times cycles list. Change-Id: I2a2a023c798e1231a7c6c72e9cb94177af5f4aa2 Signed-off-by: Xi Yan <xixiyan@redhat.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java1
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java14
-rw-r--r--tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug436841_FocusActivateEventContextMenu.java79
3 files changed, 90 insertions, 4 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java
index 46f3894b46..9ec487ad18 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java
@@ -756,6 +756,7 @@ long /*int*/ gtk_hide (long /*int*/ widget) {
if ((style & SWT.POP_UP) != 0) {
if (display.activeShell != null) {
display.activeShell = getShell ();
+ if (display.activeShell.ignoreFocusOut) display.activeShell.ignoreFocusIn = true;
display.activeShell.ignoreFocusOut = false;
}
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java
index 655612f7a1..b2bb140548 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java
@@ -125,7 +125,7 @@ public class Shell extends Decorations {
int minWidth, minHeight;
Control lastActive;
ToolTip [] toolTips;
- boolean ignoreFocusOut;
+ boolean ignoreFocusOut, ignoreFocusIn;
Region originalRegion;
static final int MAXIMUM_TRIM = 128;
@@ -1466,7 +1466,11 @@ long /*int*/ gtk_focus_in_event (long /*int*/ widget, long /*int*/ event) {
}
display.activeShell = this;
display.activePending = false;
- sendEvent (SWT.Activate);
+ if (!ignoreFocusIn) {
+ sendEvent (SWT.Activate);
+ } else {
+ ignoreFocusIn = false;
+ }
return 0;
}
@@ -1476,8 +1480,10 @@ long /*int*/ gtk_focus_out_event (long /*int*/ widget, long /*int*/ event) {
return super.gtk_focus_out_event (widget, event);
}
Display display = this.display;
- sendEvent (SWT.Deactivate);
- setActiveControl (null);
+ if (!ignoreFocusOut) {
+ sendEvent (SWT.Deactivate);
+ setActiveControl (null);
+ }
if (display.activeShell == this && !ignoreFocusOut) {
display.activeShell = null;
display.activePending = false;
diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug436841_FocusActivateEventContextMenu.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug436841_FocusActivateEventContextMenu.java
new file mode 100644
index 0000000000..d048ee3914
--- /dev/null
+++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug436841_FocusActivateEventContextMenu.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2018 Red Hat 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.tests.gtk.snippets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MenuAdapter;
+import org.eclipse.swt.events.MenuEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+
+public class Bug436841_FocusActivateEventContextMenu {
+
+ public static void main(String[] args) {
+ final Display display = new Display();
+ Shell shell = new Shell(display);
+ shell.setText(Bug436841_FocusActivateEventContextMenu.class.getName());
+ shell.setLayout(new GridLayout(1, false));
+
+ Tree tree = new Tree(shell, SWT.BORDER);
+ tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ new TreeItem(tree, SWT.NONE).setText("Open context menu, hover Show In");
+
+ Menu menu = new Menu(tree);
+ tree.setMenu(menu);
+
+ new MenuItem(menu, SWT.PUSH).setText("First");
+
+ MenuItem showInItem = new MenuItem(menu, SWT.CASCADE);
+ showInItem.setText("Show In");
+ Menu showInMenu = new Menu(menu);
+ showInItem.setMenu(showInMenu);
+ showInMenu.addMenuListener(new MenuAdapter() {
+ @Override
+ public void menuShown(MenuEvent e) {
+ Shell activeShell = display.getActiveShell();
+ System.out.println("menuShown: activeShell == " + activeShell);
+ }
+ });
+
+ display.addFilter(SWT.FocusIn, event -> new Exception("FocusIn: " + event.widget).printStackTrace());
+
+ display.addFilter(SWT.FocusOut, event -> new Exception("FocusOut: " + event.widget).printStackTrace());
+
+ display.addFilter(SWT.Activate, event -> new Exception("Activate: " + event.widget).printStackTrace());
+
+ display.addFilter(SWT.Deactivate, event -> new Exception("Deactivate: " + event.widget).printStackTrace());
+
+// new Runnable() {
+// @Override
+// public void run() {
+// System.out.print("."); // print a heartbeat to show where the user paused
+// display.timerExec(1000, this);
+// }
+// }.run();
+
+ shell.setSize(400, 100);
+ shell.open();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ display.dispose();
+ }
+
+} \ No newline at end of file

Back to the top