Skip to content

Commit 7bedf24

Browse files
author
Jeff Brown
committed
Shortcut keys should be handled on down, not up.
Bug: 5720360 Change-Id: I3afc278e576ea992c76f024c8b6bad14b214239c
1 parent 68b909d commit 7bedf24

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

core/java/android/view/ViewRootImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3330,8 +3330,9 @@ private void deliverKeyEventPostIme(KeyEvent event, boolean sendDone) {
33303330
}
33313331

33323332
// If the Control modifier is held, try to interpret the key as a shortcut.
3333-
if (event.getAction() == KeyEvent.ACTION_UP
3333+
if (event.getAction() == KeyEvent.ACTION_DOWN
33343334
&& event.isCtrlPressed()
3335+
&& event.getRepeatCount() == 0
33353336
&& !KeyEvent.isModifierKey(event.getKeyCode())) {
33363337
if (mView.dispatchKeyShortcutEvent(event)) {
33373338
finishKeyEvent(event, sendDone, true);

policy/src/com/android/internal/policy/impl/PhoneWindow.java

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,22 +1816,42 @@ public boolean dispatchKeyEvent(KeyEvent event) {
18161816

18171817
@Override
18181818
public boolean dispatchKeyShortcutEvent(KeyEvent ev) {
1819-
// Perform the shortcut (mPreparedPanel can be null since
1820-
// global shortcuts (such as search) don't rely on a
1821-
// prepared panel or menu).
1822-
boolean handled = performPanelShortcut(mPreparedPanel, ev.getKeyCode(), ev,
1823-
Menu.FLAG_PERFORM_NO_CLOSE);
1824-
if (handled) {
1825-
if (mPreparedPanel != null) {
1826-
mPreparedPanel.isHandled = true;
1819+
// If the panel is already prepared, then perform the shortcut using it.
1820+
boolean handled;
1821+
if (mPreparedPanel != null) {
1822+
handled = performPanelShortcut(mPreparedPanel, ev.getKeyCode(), ev,
1823+
Menu.FLAG_PERFORM_NO_CLOSE);
1824+
if (handled) {
1825+
if (mPreparedPanel != null) {
1826+
mPreparedPanel.isHandled = true;
1827+
}
1828+
return true;
18271829
}
1828-
return true;
18291830
}
18301831

18311832
// Shortcut not handled by the panel. Dispatch to the view hierarchy.
18321833
final Callback cb = getCallback();
1833-
return cb != null && !isDestroyed() && mFeatureId < 0 ? cb.dispatchKeyShortcutEvent(ev)
1834-
: super.dispatchKeyShortcutEvent(ev);
1834+
handled = cb != null && !isDestroyed() && mFeatureId < 0
1835+
? cb.dispatchKeyShortcutEvent(ev) : super.dispatchKeyShortcutEvent(ev);
1836+
if (handled) {
1837+
return true;
1838+
}
1839+
1840+
// If the panel is not prepared, then we may be trying to handle a shortcut key
1841+
// combination such as Control+C. Temporarily prepare the panel then mark it
1842+
// unprepared again when finished to ensure that the panel will again be prepared
1843+
// the next time it is shown for real.
1844+
if (mPreparedPanel == null) {
1845+
PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, true);
1846+
preparePanel(st, ev);
1847+
handled = performPanelShortcut(st, ev.getKeyCode(), ev,
1848+
Menu.FLAG_PERFORM_NO_CLOSE);
1849+
st.isPrepared = false;
1850+
if (handled) {
1851+
return true;
1852+
}
1853+
}
1854+
return false;
18351855
}
18361856

18371857
@Override

0 commit comments

Comments
 (0)