bug 1457355 don't change primary selection during UrlbarInput.select() r=dao

This suppresses modification of the primary selection when opening a new tab
as well as when a keyboard shortcut is used to directly focus the location
bar.

Differential Revision: https://phabricator.services.mozilla.com/D37353

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Karl Tomlinson 2019-07-12 09:00:35 +00:00
Родитель 7624ccd338
Коммит 494375d70f
1 изменённых файлов: 24 добавлений и 1 удалений

Просмотреть файл

@ -104,6 +104,7 @@ class UrlbarInput {
this._textValueOnLastSearch = "";
this._resultForCurrentValue = null;
this._suppressStartQuery = false;
this._suppressPrimaryAdjustment = false;
this._untrimmedValue = "";
// This exists only for tests.
@ -118,7 +119,6 @@ class UrlbarInput {
"setAttribute",
"removeAttribute",
"toggleAttribute",
"select",
];
const READ_ONLY_PROPERTIES = ["inputField", "editor"];
const READ_WRITE_PROPERTIES = [
@ -308,6 +308,14 @@ class UrlbarInput {
this.inputField.blur();
}
select() {
// See _on_select(). HTMLInputElement.select() dispatches a "select"
// event but does not set the primary selection.
this._suppressPrimaryAdjustment = true;
this.inputField.select();
this._suppressPrimaryAdjustment = false;
}
/**
* Converts an internal URI (e.g. a URI with a username or password) into one
* which we can expose to the user.
@ -1551,7 +1559,22 @@ class UrlbarInput {
}
_on_select(event) {
// On certain user input, AutoCopyListener::OnSelectionChange() updates
// the primary selection with user-selected text (when supported).
// Selection::NotifySelectionListeners() then dispatches a "select" event
// under similar conditions via TextInputListener::OnSelectionChange().
// This event is received here in order to replace the primary selection
// from the editor with text having the adjustments of
// _getSelectedValueForClipboard(), such as adding the scheme for the url.
//
// Other "select" events are also received, however, and must be excluded.
if (
// _suppressPrimaryAdjustment is set during select(). Don't update
// the primary selection because that is not the intent of user input,
// which may be new tab or urlbar focus.
this._suppressPrimaryAdjustment ||
// The check on isHandlingUserInput filters out async "select" events
// from setSelectionRange(), which occur when autofill text is selected.
!this.window.windowUtils.isHandlingUserInput ||
!Services.clipboard.supportsSelectionClipboard()
) {