Bug 409029 - CTabFolder context menu opens in the wrong place when invoked by the keyboard
Summary: CTabFolder context menu opens in the wrong place when invoked by the keyboard
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.3   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 4.3.1   Edit
Assignee: Bogdan Gheorghe CLA
QA Contact:
URL:
Whiteboard:
Keywords: accessibility
Depends on:
Blocks:
 
Reported: 2013-05-24 15:10 EDT by Carolyn MacLeod CLA
Modified: 2013-08-28 10:22 EDT (History)
1 user (show)

See Also:
Silenio_Quarti: review+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Carolyn MacLeod CLA 2013-05-24 15:10:12 EDT
Run CustomControlExample and go to CTabFolder.
Check "Popup menu".
Select a CTabFolder tab (so focus rectangle is drawn around the tab name).
Move the mouse far away, so that it is not in the CTabFolder.
Now type Shift+F10 to bring up a context menu.
The context menu will pop up wherever you left the mouse.
It should pop up within the CTabFolder's selected tab.

Bug 374147 added API to allow custom controls to fix this problem based on the semantics of the control. (i.e. StyledText pops up a keyboard-initiated context menu at the caret).

The following patch brings up the menu near the top-right corner of the selected CTabFolder tab if it was popped up using the keyboard.

--- snip ---

### Eclipse Workspace Patch 1.0
#P org.eclipse.swt
diff --git Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java
index 9d6d4b0..b8ba5e9 100644
--- Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java
+++ Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java
@@ -274,6 +274,7 @@
 				case SWT.FocusIn:          onFocus(event);	break;
 				case SWT.FocusOut:         onFocus(event);	break;
 				case SWT.KeyDown:          onKeyDown(event); break;
+				case SWT.MenuDetect:       onMenuDetect(event); break;
 				case SWT.MouseDoubleClick: onMouseDoubleClick(event); break;
 				case SWT.MouseDown:        onMouse(event);	break;
 				case SWT.MouseEnter:       onMouse(event);	break;
@@ -295,6 +296,7 @@
 		SWT.FocusIn, 
 		SWT.FocusOut, 
 		SWT.KeyDown,
+		SWT.MenuDetect,
 		SWT.MouseDoubleClick, 
 		SWT.MouseDown,
 		SWT.MouseEnter, 
@@ -1647,6 +1649,23 @@
 	}
 	return false;
 }
+void onMenuDetect(Event event) {
+	if (event.detail == SWT.MENU_KEYBOARD) {
+		if (selectedIndex != -1) {
+			CTabItem item = items[selectedIndex];
+			Rectangle rect = getDisplay().map(this, null, item.getBounds());
+			if (!rect.contains(event.x, event.y)) {
+				/* If the mouse is not in the currently-selected tab,
+				 * then pop up the menu near the top-right corner of the current tab.
+				 */
+				Rectangle itemTrim = renderer.computeTrim(selectedIndex, SWT.NONE, 0, 0, 0, 0);
+				Rectangle closeTrim = renderer.computeTrim(CTabFolderRenderer.PART_CLOSE_BUTTON, SWT.NONE, 0, 0, 0, 0);
+				event.x = rect.x + rect.width - item.closeRect.width + itemTrim.x - closeTrim.width;
+				event.y = rect.y - itemTrim.y - closeTrim.y;
+			}
+		}
+	}
+}
 void onMouseDoubleClick(Event event) {	
 	if (event.button != 1 || 
 		(event.stateMask & SWT.BUTTON2) != 0 ||
Comment 1 Carolyn MacLeod CLA 2013-05-24 15:13:09 EDT
Spoke with SSQ - this patch can go in to the 4.3 maintenance stream and 4.4 after 4.3 ships.

Set target milestone to 4.4 because unfortunately there is no target milestone for 4.3.1 yet.

Marking with accessibility keyword because keyboard-only users would be affected by this (screen reader users would not be affected).
Comment 2 Carolyn MacLeod CLA 2013-05-28 20:10:13 EDT
Setting target milestone to 4.3.1.
Comment 3 Bogdan Gheorghe CLA 2013-08-27 16:23:19 EDT
Released to HEAD and R4_3_maintenance. Thanks Car!