Skip to content
This repository was archived by the owner on Sep 2, 2021. It is now read-only.

Commit 6943048

Browse files
committed
Don't add shortcuts that have a key only available when AltGr key is pressed. Also make sure that we don't show unavailable shortcuts in the menus.
1 parent b8e3c8b commit 6943048

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

appshell/appshell_extensions_win.cpp

+20-10
Original file line numberDiff line numberDiff line change
@@ -1528,18 +1528,26 @@ bool UpdateAcceleratorTable(int32 tag, ExtensionString& keyStr)
15281528
// Get the virtual key code for non-alpha-numeric characters.
15291529
int keyCode = ::VkKeyScan(ascii);
15301530
WORD vKey = (short)(keyCode & 0x000000FF);
1531+
bool isAltGr = ((keyCode & 0x0000FF00) >> 8) >= 6;
15311532

15321533
// Get unshifted key from keyCode so that we can determine whether the
15331534
// key is a shifted one or not.
15341535
UINT unshiftedChar = ::MapVirtualKey(vKey, 2);
15351536
bool isDeadKey = ((unshiftedChar & 0x80000000) == 0x80000000);
15361537

1537-
// If key code is -1 or unshiftedChar is 0 or the key is a shifted key sharing with
1538-
// one of the number keys on the keyboard, then we don't have a functionable shortcut.
1538+
// If one of the following is found, then the shortcut is not available for the
1539+
// current keyboard layout.
1540+
//
1541+
// * keyCode is -1 -- meaning the key is not available on the current keyboard layout
1542+
// * is a dead key -- a key used to attach a specific diacritic to a base letter.
1543+
// * is altGr character -- the character is only available when Ctrl and Alt keys are also pressed together.
1544+
// * unshiftedChar is 0 -- meaning the key is not available on the current keyboard layout
1545+
// * The key is a shifted character sharing with one of the number keys on the keyboard. An example
1546+
// of this is the '/' key on German keyboard layout. It is a shifted key on number key '7'.
1547+
//
15391548
// So don't update the accelerator table. Just return false here so that the
1540-
// caller can remove the shortcut string from the menu title. An example of this
1541-
// is the '/' key on German keyboard layout. It is a shifted key on number key '7'.
1542-
if (keyCode == -1 || isDeadKey || unshiftedChar == 0 ||
1549+
// caller can remove the shortcut string from the menu title.
1550+
if (keyCode == -1 || isDeadKey || isAltGr || unshiftedChar == 0 ||
15431551
(unshiftedChar >= '0' && unshiftedChar <= '9')) {
15441552
LocalFree(lpaccelNew);
15451553
return false;
@@ -1674,6 +1682,13 @@ int32 AddMenuItem(CefRefPtr<CefBrowser> browser, ExtensionString parentCommand,
16741682
if (displayKeyStr.length() > 0) {
16751683
title = title + L"\t" + displayKeyStr;
16761684
}
1685+
1686+
// Add shortcut to the accelerator table first. If the shortcut cannot
1687+
// be added, then don't show it in the menu title.
1688+
if (!isSeparator && !UpdateAcceleratorTable(tag, keyStr)) {
1689+
title = title.substr(0, title.find('\t'));
1690+
}
1691+
16771692
int32 positionIdx;
16781693
int32 errCode = getNewMenuPosition(browser, parentCommand, position, relativeId, positionIdx);
16791694
bool inserted = false;
@@ -1724,11 +1739,6 @@ int32 AddMenuItem(CefRefPtr<CefBrowser> browser, ExtensionString parentCommand,
17241739

17251740
NativeMenuModel::getInstance(getMenuParent(browser)).setOsItem(tag, (void*)submenu);
17261741

1727-
if (!isSeparator && !UpdateAcceleratorTable(tag, keyStr)) {
1728-
title = title.substr(0, title.find('\t'));
1729-
SetMenuTitle(browser, command, title);
1730-
}
1731-
17321742
return errCode;
17331743
}
17341744

0 commit comments

Comments
 (0)