diff --git a/browser/components/urlbar/UrlbarInput.sys.mjs b/browser/components/urlbar/UrlbarInput.sys.mjs index 50968dc04b527438acf30151f0c2e92f8b45097c..f8587b68ac057bb0f829fc21f08ade6605b14c92 100644 --- a/browser/components/urlbar/UrlbarInput.sys.mjs +++ b/browser/components/urlbar/UrlbarInput.sys.mjs @@ -67,6 +67,13 @@ XPCOMUtils.defineLazyPreferenceGetter( false ); +XPCOMUtils.defineLazyPreferenceGetter( + lazy, + "ZEN_URLBAR_BEHAVIOR", + "zen.urlbar.behavior", + 'default' +); + const DEFAULT_FORM_HISTORY_NAME = "searchbar-history"; const SEARCH_BUTTON_CLASS = "urlbar-search-button"; @@ -348,7 +355,11 @@ export class UrlbarInput { // See _on_select(). HTMLInputElement.select() dispatches a "select" // event but does not set the primary selection. this._suppressPrimaryAdjustment = true; + this.document.getElementById("navigator-toolbox").setAttribute("supress-primary-adjustment", !this.document.getElementById("navigator-toolbox").hasAttribute("zen-has-hover")); this.inputField.select(); + this.document.ownerGlobal.setTimeout(() => { + this.document.getElementById("navigator-toolbox").removeAttribute("supress-primary-adjustment"); + }, 100); this._suppressPrimaryAdjustment = false; } @@ -424,6 +435,10 @@ export class UrlbarInput { hideSearchTerms = false, isSameDocument = false ) { + if (this.hasAttribute("zen-newtab")) { + return; + } + // We only need to update the searchModeUI on tab switch conditionally // as we only persist searchMode with ScotchBonnet enabled. if ( @@ -697,8 +712,11 @@ export class UrlbarInput { return; } } - + this.document.getElementById("navigator-toolbox").setAttribute("supress-primary-adjustment", !this.document.getElementById("navigator-toolbox").hasAttribute("zen-has-hover")); this.handleNavigation({ event }); + this.document.ownerGlobal.setTimeout(() => { + this.document.getElementById("navigator-toolbox").removeAttribute("supress-primary-adjustment"); + }, 200); } /** @@ -1087,7 +1105,11 @@ export class UrlbarInput { } if (!result.payload.providesSearchMode) { - this.view.close({ elementPicked: true }); + if (this._zenHandleUrlbarClose) { + this._zenHandleUrlbarClose(true); + } else { + this.view.close({ elementPicked: true }); + } } this.controller.recordSelectedResult(event, result); @@ -2144,6 +2166,11 @@ export class UrlbarInput { this.setAttribute("breakout-extend", "true"); + if (lazy.ZEN_URLBAR_BEHAVIOR == 'float' || (lazy.ZEN_URLBAR_BEHAVIOR == 'floating-on-type' && !this.focusedViaMousedown)) { + this.setAttribute("zen-floating-urlbar", "true"); + } else { + this.removeAttribute("zen-floating-urlbar"); + } // Enable the animation only after the first extend call to ensure it // doesn't run when opening a new window. if (!this.hasAttribute("breakout-extend-animate")) { @@ -2163,6 +2190,11 @@ export class UrlbarInput { return; } + if (this._zenHandleUrlbarClose) { + this._zenHandleUrlbarClose(); + } + this.removeAttribute("zen-floating-urlbar"); + this.removeAttribute("breakout-extend"); this.#updateTextboxPosition(); } @@ -3305,7 +3337,7 @@ export class UrlbarInput { } else { where = lazy.BrowserUtils.whereToOpenLink(event, false, false); } - if (lazy.UrlbarPrefs.get("openintab")) { + if (lazy.UrlbarPrefs.get("openintab") || this.hasAttribute("zen-newtab")) { if (where == "current") { where = "tab"; } else if (where == "tab") { @@ -3859,6 +3891,11 @@ export class UrlbarInput { } _on_click(event) { + if (lazy.ZEN_URLBAR_BEHAVIOR === 'float' && event.target == this.inputField) { + event.zenOriginalTarget = this.textbox; + this._on_mousedown(event); + } + if ( event.target == this.inputField || event.target == this._inputContainer || @@ -3930,7 +3967,7 @@ export class UrlbarInput { } } - if (this.focusedViaMousedown) { + if (this.focusedViaMousedown || this.hasAttribute("zen-newtab")) { this.view.autoOpen({ event }); } else { if (this._untrimOnFocusAfterKeydown) { @@ -3970,9 +4007,12 @@ export class UrlbarInput { } _on_mousedown(event) { - switch (event.currentTarget) { + switch (event.zenOriginalTarget || event.currentTarget) { case this.textbox: { this._mousedownOnUrlbarDescendant = true; + if (event.type != "click" && lazy.ZEN_URLBAR_BEHAVIOR === 'float') { + return true; + } if ( event.target != this.inputField && @@ -3982,8 +4022,8 @@ export class UrlbarInput { break; } - this.focusedViaMousedown = !this.focused; - this._preventClickSelectsAll = this.focused; + this.focusedViaMousedown = !(lazy.ZEN_URLBAR_BEHAVIOR === 'default' ? this.focused : this.hasAttribute("breakout-extend")); + this._preventClickSelectsAll = lazy.ZEN_URLBAR_BEHAVIOR === 'default' ? this.focused : this.hasAttribute("breakout-extend"); // Keep the focus status, since the attribute may be changed // upon calling this.focus().