Bug 1629113 - Move caret browsing handler to tabbrowser.js. r=NeilDeakin

We don't use it on GeckoView.

Differential Revision: https://phabricator.services.mozilla.com/D72724
This commit is contained in:
Agi Sferro
2020-05-27 22:26:17 +00:00
parent 430f5e595a
commit d58f611927
5 changed files with 87 additions and 95 deletions

View File

@@ -33,9 +33,7 @@
Services.obs.addObserver(this, "contextual-identity-updated");
Services.els.addSystemEventListener(document, "keydown", this, false);
if (AppConstants.platform == "macosx") {
Services.els.addSystemEventListener(document, "keypress", this, false);
}
Services.els.addSystemEventListener(document, "keypress", this, false);
window.addEventListener("sizemodechange", this);
window.addEventListener("occlusionstatechange", this);
window.addEventListener("framefocusrequested", this);
@@ -4964,7 +4962,63 @@
}
},
_handleKeyPressEventMac(aEvent) {
toggleCaretBrowsing() {
const kPrefShortcutEnabled =
"accessibility.browsewithcaret_shortcut.enabled";
const kPrefWarnOnEnable = "accessibility.warn_on_browsewithcaret";
const kPrefCaretBrowsingOn = "accessibility.browsewithcaret";
var isEnabled = Services.prefs.getBoolPref(kPrefShortcutEnabled);
if (!isEnabled) {
return;
}
// Toggle browse with caret mode
var browseWithCaretOn = Services.prefs.getBoolPref(
kPrefCaretBrowsingOn,
false
);
var warn = Services.prefs.getBoolPref(kPrefWarnOnEnable, true);
if (warn && !browseWithCaretOn) {
var checkValue = { value: false };
var promptService = Services.prompt;
var buttonPressed = promptService.confirmEx(
window,
gTabBrowserBundle.GetStringFromName(
"browsewithcaret.checkWindowTitle"
),
gTabBrowserBundle.GetStringFromName("browsewithcaret.checkLabel"),
// Make "No" the default:
promptService.STD_YES_NO_BUTTONS | promptService.BUTTON_POS_1_DEFAULT,
null,
null,
null,
gTabBrowserBundle.GetStringFromName("browsewithcaret.checkMsg"),
checkValue
);
if (buttonPressed != 0) {
if (checkValue.value) {
try {
Services.prefs.setBoolPref(kPrefShortcutEnabled, false);
} catch (ex) {}
}
return;
}
if (checkValue.value) {
try {
Services.prefs.setBoolPref(kPrefWarnOnEnable, false);
} catch (ex) {}
}
}
// Toggle the pref
try {
Services.prefs.setBoolPref(kPrefCaretBrowsingOn, !browseWithCaretOn);
} catch (ex) {}
},
_handleKeyPressEvent(aEvent) {
if (!aEvent.isTrusted) {
// Don't let untrusted events mess with tabs.
return;
@@ -4975,19 +5029,23 @@
return;
}
if (AppConstants.platform == "macosx") {
switch (
ShortcutUtils.getSystemActionForEvent(aEvent, { rtl: RTL_UI })
) {
case ShortcutUtils.NEXT_TAB:
switch (ShortcutUtils.getSystemActionForEvent(aEvent, { rtl: RTL_UI })) {
case ShortcutUtils.TOGGLE_CARET_BROWSING:
this.toggleCaretBrowsing();
break;
case ShortcutUtils.NEXT_TAB:
if (AppConstants.platform == "macosx") {
this.tabContainer.advanceSelectedTab(1, true);
aEvent.preventDefault();
break;
case ShortcutUtils.PREVIOUS_TAB:
}
break;
case ShortcutUtils.PREVIOUS_TAB:
if (AppConstants.platform == "macosx") {
this.tabContainer.advanceSelectedTab(-1, true);
aEvent.preventDefault();
break;
}
}
break;
}
},
@@ -5101,7 +5159,7 @@
this._handleKeyDownEvent(aEvent);
break;
case "keypress":
this._handleKeyPressEventMac(aEvent);
this._handleKeyPressEvent(aEvent);
break;
case "framefocusrequested": {
let tab = this.getTabForBrowser(aEvent.target);

View File

@@ -122,3 +122,7 @@ tabs.openWarningTitle=Confirm open
tabs.openWarningMultipleBranded=You are about to open %S tabs. This might slow down %S while the pages are loading. Are you sure you want to continue?
tabs.openButtonMultiple=Open tabs
tabs.openWarningPromptMeBranded=Warn me when opening multiple tabs might slow down %S
browsewithcaret.checkMsg=Do not show me this dialog box again.
browsewithcaret.checkWindowTitle=Caret Browsing
browsewithcaret.checkLabel=Pressing F7 turns Caret Browsing on or off. This feature places a moveable cursor in web pages, allowing you to select text with the keyboard. Do you want to turn Caret Browsing on?

View File

@@ -111,80 +111,6 @@
return new LazyModules.PopupBlocker(this);
});
this.addEventListener(
"keypress",
event => {
if (event.keyCode != KeyEvent.DOM_VK_F7) {
return;
}
// shift + F7 is the default DevTools shortcut for the Style Editor.
if (event.shiftKey) {
return;
}
if (event.defaultPrevented || !event.isTrusted) {
return;
}
const kPrefShortcutEnabled =
"accessibility.browsewithcaret_shortcut.enabled";
const kPrefWarnOnEnable = "accessibility.warn_on_browsewithcaret";
const kPrefCaretBrowsingOn = "accessibility.browsewithcaret";
var isEnabled = this.mPrefs.getBoolPref(kPrefShortcutEnabled);
if (!isEnabled) {
return;
}
// Toggle browse with caret mode
var browseWithCaretOn = this.mPrefs.getBoolPref(
kPrefCaretBrowsingOn,
false
);
var warn = this.mPrefs.getBoolPref(kPrefWarnOnEnable, true);
if (warn && !browseWithCaretOn) {
var checkValue = { value: false };
var promptService = Services.prompt;
var buttonPressed = promptService.confirmEx(
window,
this.mStrBundle.GetStringFromName(
"browsewithcaret.checkWindowTitle"
),
this.mStrBundle.GetStringFromName("browsewithcaret.checkLabel"),
// Make "No" the default:
promptService.STD_YES_NO_BUTTONS |
promptService.BUTTON_POS_1_DEFAULT,
null,
null,
null,
this.mStrBundle.GetStringFromName("browsewithcaret.checkMsg"),
checkValue
);
if (buttonPressed != 0) {
if (checkValue.value) {
try {
this.mPrefs.setBoolPref(kPrefShortcutEnabled, false);
} catch (ex) {}
}
return;
}
if (checkValue.value) {
try {
this.mPrefs.setBoolPref(kPrefWarnOnEnable, false);
} catch (ex) {}
}
}
// Toggle the pref
try {
this.mPrefs.setBoolPref(kPrefCaretBrowsingOn, !browseWithCaretOn);
} catch (ex) {}
},
{ mozSystemGroup: true }
);
this.addEventListener(
"dragover",
event => {

View File

@@ -2,10 +2,6 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
browsewithcaret.checkMsg=Do not show me this dialog box again.
browsewithcaret.checkWindowTitle=Caret Browsing
browsewithcaret.checkLabel=Pressing F7 turns Caret Browsing on or off. This feature places a moveable cursor in web pages, allowing you to select text with the keyboard. Do you want to turn Caret Browsing on?
formPostSecureToInsecureWarning.title = Security Warning
formPostSecureToInsecureWarning.message = The information you have entered on this page will be sent over an insecure connection and could be read by a third party.\n\nAre you sure you want to send this information?
formPostSecureToInsecureWarning.continue = Continue

View File

@@ -35,12 +35,13 @@ var ShortcutUtils = {
DUPLICATE_MODIFIER: "duplicate_modifier",
MODIFIER_REQUIRED: "modifier_required",
MOVE_TAB_FORWARD: "MOVE_TAB_FORWARD",
MOVE_TAB_BACKWARD: "MOVE_TAB_BACKWARD",
CLOSE_TAB: "CLOSE_TAB",
CYCLE_TABS: "CYCLE_TABS",
PREVIOUS_TAB: "PREVIOUS_TAB",
TOGGLE_CARET_BROWSING: "TOGGLE_CARET_BROWSING",
MOVE_TAB_BACKWARD: "MOVE_TAB_BACKWARD",
MOVE_TAB_FORWARD: "MOVE_TAB_FORWARD",
NEXT_TAB: "NEXT_TAB",
PREVIOUS_TAB: "PREVIOUS_TAB",
/**
* Prettifies the modifier keys for an element.
@@ -312,6 +313,7 @@ var ShortcutUtils = {
* @param {KeyboardEvent} event The event to check for a related system action.
* @returns {string} A string identifying the action, or null if no action is found.
*/
// eslint-disable-next-line complexity
getSystemActionForEvent(event, { rtl } = {}) {
switch (event.keyCode) {
case event.DOM_VK_TAB:
@@ -319,6 +321,12 @@ var ShortcutUtils = {
return ShortcutUtils.CYCLE_TABS;
}
break;
case event.DOM_VK_F7:
// shift + F7 is the default DevTools shortcut for the Style Editor.
if (event.shiftKey) {
return ShortcutUtils.TOGGLE_CARET_BROWSING;
}
break;
case event.DOM_VK_PAGE_UP:
if (
event.ctrlKey &&