From 70fad9cef65ba3475c6889ce980d6e678813192c Mon Sep 17 00:00:00 2001 From: harry Date: Fri, 19 Jul 2019 08:54:43 +0000 Subject: [PATCH] Bug 1528614 - Remove clickSelectsAll from textboxes. r=dao Differential Revision: https://phabricator.services.mozilla.com/D37315 --HG-- extra : moz-landing-system : lando --- browser/components/places/content/places.js | 3 -- .../preferences/in-content/preferences.xul | 2 +- .../components/search/content/searchbar.js | 39 ++++++++++++++-- toolkit/content/jar.mn | 2 +- toolkit/content/widgets/search-textbox.js | 22 --------- toolkit/content/widgets/textbox.xml | 46 ------------------- 6 files changed, 37 insertions(+), 77 deletions(-) diff --git a/browser/components/places/content/places.js b/browser/components/places/content/places.js index 74be8b871652..29f23078b7e1 100644 --- a/browser/components/places/content/places.js +++ b/browser/components/places/content/places.js @@ -965,9 +965,6 @@ var PlacesSearchBox = { * Set up the gray text in the search bar as the Places View loads. */ init: function PSB_init() { - if (Services.prefs.getBoolPref("browser.urlbar.clickSelectsAll", false)) { - this.searchFilter.setAttribute("clickSelectsAll", true); - } this.updateCollectionTitle(); }, diff --git a/browser/components/preferences/in-content/preferences.xul b/browser/components/preferences/in-content/preferences.xul index 8913e32988bf..80363d1261cf 100644 --- a/browser/components/preferences/in-content/preferences.xul +++ b/browser/components/preferences/in-content/preferences.xul @@ -182,7 +182,7 @@ is="search-textbox" id="searchInput" data-l10n-id="search-input-box" data-l10n-attrs="style" - hidden="true" clickSelectsAll="true"/> + hidden="true"/> #include searchResults.inc.xul diff --git a/browser/components/search/content/searchbar.js b/browser/components/search/content/searchbar.js index f546c76875d5..90de180ee86f 100644 --- a/browser/components/search/content/searchbar.js +++ b/browser/components/search/content/searchbar.js @@ -415,7 +415,27 @@ } } + /** + * Determines if we should select all the text in the searchbar based on the + * clickSelectsAll pref, searchbar state, and whether the selection is empty. + */ + _maybeSelectAll() { + if ( + !this._preventClickSelectsAll && + UrlbarPrefs.get("clickSelectsAll") && + document.activeElement == this._textbox.inputField && + this._textbox.inputField.selectionStart == + this._textbox.inputField.selectionEnd + ) { + this._textbox.editor.selectAll(); + } + } + _setupEventListeners() { + this.addEventListener("click", event => { + this._maybeSelectAll(); + }); + this.addEventListener("command", event => { const target = event.originalTarget; if (target.engine) { @@ -437,6 +457,15 @@ this.select(); }); + this.addEventListener("contextmenu", event => { + // Context menu opened via keyboard shortcut. + if (!event.button) { + return; + } + + this._maybeSelectAll(); + }); + this.addEventListener( "DOMMouseScroll", event => { @@ -502,6 +531,7 @@ ); this.addEventListener("mousedown", event => { + this._preventClickSelectsAll = this._textbox.focused; // Ignore right clicks if (event.button != 0) { return; @@ -529,6 +559,11 @@ // is text in the textbox. this.openSuggestionsPanel(true); } + + if (event.detail == 2 && UrlbarPrefs.get("doubleClickSelectsAll")) { + this._textbox.editor.selectAll(); + event.preventDefault(); + } }); } @@ -660,10 +695,6 @@ return; } - if (Services.prefs.getBoolPref("browser.urlbar.clickSelectsAll")) { - this.textbox.setAttribute("clickSelectsAll", true); - } - let inputBox = document.getAnonymousElementByAttribute( this.textbox, "anonid", diff --git a/toolkit/content/jar.mn b/toolkit/content/jar.mn index 2f64b0afa425..43dfbeea439d 100644 --- a/toolkit/content/jar.mn +++ b/toolkit/content/jar.mn @@ -71,7 +71,7 @@ toolkit.jar: content/global/bindings/richlistbox.xml (widgets/richlistbox.xml) content/global/bindings/scrollbox.xml (widgets/scrollbox.xml) content/global/bindings/spinner.js (widgets/spinner.js) -* content/global/bindings/textbox.xml (widgets/textbox.xml) + content/global/bindings/textbox.xml (widgets/textbox.xml) content/global/bindings/timekeeper.js (widgets/timekeeper.js) content/global/bindings/timepicker.js (widgets/timepicker.js) content/global/elements/autocomplete-popup.js (widgets/autocomplete-popup.js) diff --git a/toolkit/content/widgets/search-textbox.js b/toolkit/content/widgets/search-textbox.js index a936017edaa1..2b78f6599f79 100644 --- a/toolkit/content/widgets/search-textbox.js +++ b/toolkit/content/widgets/search-textbox.js @@ -46,16 +46,6 @@ }); } - this.addEventListener("click", event => { - if ( - this.clickSelectsAll && - document.activeElement == this.inputField && - this.inputField.selectionStart == this.inputField.selectionEnd - ) { - this.editor.selectAll(); - } - }); - this.addEventListener("input", event => { if (this.searchButton) { this._searchIcons.selectedIndex = 0; @@ -211,18 +201,6 @@ return this.inputField.disabled; } - get clickSelectsAll() { - return this.getAttribute("clickSelectsAll") == "true"; - } - - set clickSelectsAll(val) { - if (val) { - this.setAttribute("clickSelectsAll", "true"); - } else { - this.removeAttribute("clickSelectsAll"); - } - } - reset() { this.value = this.defaultValue; // XXX: Is this still needed ? diff --git a/toolkit/content/widgets/textbox.xml b/toolkit/content/widgets/textbox.xml index acf243c9d755..267afa4098de 100644 --- a/toolkit/content/widgets/textbox.xml +++ b/toolkit/content/widgets/textbox.xml @@ -36,7 +36,6 @@ null false - false null @@ -76,10 +75,6 @@ if (val) this.setAttribute('readonly', 'true'); else this.removeAttribute('readonly'); return val;" onget="return this.inputField.readOnly;"/> - - - - - @@ -234,7 +206,6 @@ this.mIgnoreClick = this.hasAttribute("focused"); if (!this.mIgnoreClick) { - this.mIgnoreFocus = true; this.setSelectionRange(0, 0); if (event.originalTarget == this || event.originalTarget == this.inputField.parentNode) @@ -242,23 +213,6 @@ } ]]> - - - -#ifndef XP_WIN - - // Only care about context clicks on the textbox itself. - if (event.target != this) - return; - - if (!event.button) // context menu opened via keyboard shortcut - return; - this._maybeSelectAll(); - // see bug 576135 comment 4 - let box = this.inputField.parentNode; - box._doPopupItemEnabling(box.menupopup); - -#endif