-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Support to WebView for Zoom Keyboard Shortcuts
Bug: 1412052 Change-Id: Ibe449946a7e5db53d38a5b92726f079fbe2f7e18 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4208795 Reviewed-by: Robert Flack <flackr@chromium.org> Reviewed-by: James Maclean <wjmaclean@chromium.org> Commit-Queue: Wayne Jackson Jr. <wbjacksonjr@chromium.org> Reviewed-by: Peter Beverloo <peter@chromium.org> Cr-Commit-Position: refs/heads/main@{#1104485}
- Loading branch information
Wayne Jackson Jr
authored and
Chromium LUCI CQ
committed
Feb 13, 2023
1 parent
1dee500
commit b06498c
Showing
17 changed files
with
360 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
android_webview/java/src/org/chromium/android_webview/AwKeyboardShortcuts.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package org.chromium.android_webview; | ||
|
||
import android.view.KeyEvent; | ||
|
||
import org.chromium.android_webview.common.AwFeatures; | ||
|
||
/** | ||
* Handles WebView keyboard shortcut events that weren't handled in | ||
* {@link AwWebContentsDelegateAdapter#handleKeyboardEvent(KeyEvent)}. | ||
*/ | ||
/** | ||
* TODO(wbjacksonjr) Possibly merge this class with {@link | ||
* org.chromium.chrome.browser.KeyboardShortcuts} | ||
*/ | ||
public class AwKeyboardShortcuts { | ||
private static final int CTRL = 1 << 31; | ||
private static final int ALT = 1 << 30; | ||
private static final int SHIFT = 1 << 29; | ||
|
||
private AwKeyboardShortcuts() {} | ||
|
||
private static int getMetaState(KeyEvent event) { | ||
return (event.isCtrlPressed() ? CTRL : 0) | (event.isAltPressed() ? ALT : 0) | ||
| (event.isShiftPressed() ? SHIFT : 0); | ||
} | ||
|
||
public static boolean onKeyDown(KeyEvent event, AwContents awContents) { | ||
int keyCode = event.getKeyCode(); | ||
if (event.getRepeatCount() != 0 || event.getAction() != KeyEvent.ACTION_DOWN | ||
|| KeyEvent.isModifierKey(keyCode)) { | ||
return false; | ||
} | ||
|
||
int metaState = getMetaState(event); | ||
int keyCodeAndMeta = keyCode | metaState; | ||
|
||
if (AwFeatureList.isEnabled(AwFeatures.WEBVIEW_ZOOM_KEYBOARD_SHORTCUTS)) { | ||
return handleZoomShortcut(awContents, keyCodeAndMeta); | ||
} | ||
return false; | ||
} | ||
|
||
private static boolean handleZoomShortcut(AwContents awContents, int keyCodeAndMeta) { | ||
// We want to return true even if zoom is not supported as technically the keyboard shortcut | ||
// was handled | ||
boolean supportsZoom = awContents.getSettings().supportZoom(); | ||
switch (keyCodeAndMeta) { | ||
case CTRL | KeyEvent.KEYCODE_PLUS: | ||
case CTRL | KeyEvent.KEYCODE_EQUALS: | ||
case CTRL | SHIFT | KeyEvent.KEYCODE_PLUS: | ||
case CTRL | SHIFT | KeyEvent.KEYCODE_EQUALS: | ||
case KeyEvent.KEYCODE_ZOOM_IN: | ||
if (supportsZoom) { | ||
awContents.zoomIn(); | ||
} | ||
return true; | ||
case CTRL | KeyEvent.KEYCODE_MINUS: | ||
case KeyEvent.KEYCODE_ZOOM_OUT: | ||
if (supportsZoom) { | ||
awContents.zoomOut(); | ||
} | ||
return true; | ||
case CTRL | KeyEvent.KEYCODE_0: | ||
if (supportsZoom) { | ||
awContents.zoomReset(); | ||
} | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.