diff --git a/browser/components/urlbar/content/UrlbarInput.mjs b/browser/components/urlbar/content/UrlbarInput.mjs index b23244f9d3278918b016bb3fcab19687bc2e292a..ade1f031bbb68202a37e6c9d3071a73f5c811a82 100644 --- a/browser/components/urlbar/content/UrlbarInput.mjs +++ b/browser/components/urlbar/content/UrlbarInput.mjs @@ -90,6 +90,13 @@ const lazy = XPCOMUtils.declareLazy({ logger: () => lazy.UrlbarUtils.getLogger({ prefix: "Input" }), }); +XPCOMUtils.defineLazyPreferenceGetter( + lazy, + "ZEN_URLBAR_BEHAVIOR", + "zen.urlbar.behavior", + 'default' +); + const UNLIMITED_MAX_RESULTS = 99; let getBoundsWithoutFlushing = element => @@ -708,7 +715,16 @@ export class UrlbarInput extends HTMLElement { // See _on_select(). HTMLInputElement.select() dispatches a "select" // event but does not set the primary selection. this._suppressPrimaryAdjustment = true; + const zenToolbox = this.document.getElementById("navigator-toolbox"); + this.window.document.documentElement.setAttribute("supress-primary-adjustment", !( + zenToolbox.hasAttribute("zen-has-hover") || + zenToolbox.hasAttribute("zen-has-empty-tab") || + zenToolbox.hasAttribute("zen-user-show") + )); this.inputField.select(); + this.document.ownerGlobal.setTimeout(() => { + this.window.document.documentElement.removeAttribute("supress-primary-adjustment"); + }, 0); this._suppressPrimaryAdjustment = false; } @@ -782,6 +798,10 @@ export class UrlbarInput extends HTMLElement { hideSearchTerms = false, isSameDocument = false, } = {}) { + if (this.hasAttribute("zen-newtab")) { + return; + } + if (!this.#isAddressbar) { throw new Error( "Cannot set URI for UrlbarInput that is not an address bar" @@ -1071,8 +1091,16 @@ export class UrlbarInput extends HTMLElement { return; } } - + const zenToolbox = this.document.getElementById("navigator-toolbox"); + this.window.document.documentElement.setAttribute("supress-primary-adjustment", !( + zenToolbox.hasAttribute("zen-has-hover") || + zenToolbox.hasAttribute("zen-has-empty-tab") || + zenToolbox.hasAttribute("zen-user-show") + )); this.handleNavigation({ event }); + this.document.ownerGlobal.setTimeout(() => { + this.window.document.documentElement.removeAttribute("supress-primary-adjustment"); + }, 100); } /** @@ -1496,7 +1524,11 @@ export class UrlbarInput extends HTMLElement { } if (!this.#providesSearchMode(result)) { - this.view.close({ elementPicked: true }); + if (this._zenHandleUrlbarClose) { + this._zenHandleUrlbarClose(true, true); + } else { + this.window.setTimeout(() => this.view.close({ elementPicked: true }), 0); + } } if (isCanonized) { @@ -2696,6 +2728,42 @@ export class UrlbarInput extends HTMLElement { await this.#updateLayoutBreakoutDimensions(); } + zenFormatURLValue() { + return this.#lazy.valueFormatter._formatURL(); + } + + get zenUrlbarBehavior() { + if (this.document.documentElement.hasAttribute("inDOMFullscreen")) { + return "float"; + } + return lazy.ZEN_URLBAR_BEHAVIOR; + } + + get zenStrippedURI() { + let strippedURI = null; + let activeBrowser = this.window.gBrowser?.selectedBrowser; + let uriString = activeBrowser.userTypedValue || + (activeBrowser.currentURI ? activeBrowser.currentURI.spec : ""); + + let uri; + try { + uri = Services.io.newURI(uriString); + } catch (e) { + // Fallback if the provisional string isn't a valid URI yet + uri = activeBrowser.currentURI; + } + + // Error check occurs during isClipboardURIValid + try { + strippedURI = lazy.QueryStringStripper.stripForCopyOrShare(uri); + } catch (e) { + console.warn(`stripForCopyOrShare: ${e.message}`); + return [uri, lazy.ClipboardHelper]; + } + + return [strippedURI ? this.makeURIReadable(strippedURI) : uri, lazy.ClipboardHelper]; + } + startLayoutExtend() { if (!this.#allowBreakout || this.hasAttribute("breakout-extend")) { // Do not expand if the Urlbar does not support being expanded or it is @@ -2710,6 +2778,13 @@ export class UrlbarInput extends HTMLElement { this.setAttribute("breakout-extend", "true"); + this.window.gZenUIManager.onUrlbarOpen(); + if (this.zenUrlbarBehavior == 'float' || (this.zenUrlbarBehavior == 'floating-on-type' && !this.focusedViaMousedown)) { + this.setAttribute("zen-floating-urlbar", "true"); + this.window.gZenUIManager.onFloatingURLBarOpen(); + } 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")) { @@ -2729,6 +2804,27 @@ export class UrlbarInput extends HTMLElement { return; } + if (this._zenHandleUrlbarClose) { + this._zenHandleUrlbarClose(); + } else if (!this._untrimmedValue || this.searchMode) { + // Restore the current page URL when the urlbar is empty on blur + this.handleRevert(); + } + + // Arc like URLbar: Blur the input on exit + const zenToolbox = this.document.getElementById("navigator-toolbox"); + this.window.document.documentElement.setAttribute("supress-primary-adjustment", !( + zenToolbox.hasAttribute("zen-has-hover") || + zenToolbox.hasAttribute("zen-has-empty-tab") || + zenToolbox.hasAttribute("zen-user-show") + )); + this.window.gBrowser.selectedBrowser.focus(); + this.document.ownerGlobal.setTimeout(() => { + this.window.document.documentElement.removeAttribute("supress-primary-adjustment"); + }, 100); + this.window.gZenUIManager.onUrlbarClose(); + this.removeAttribute("zen-floating-urlbar"); + this.removeAttribute("breakout-extend"); this.#updateTextboxPosition(); } @@ -2759,7 +2855,7 @@ export class UrlbarInput extends HTMLElement { forceUnifiedSearchButtonAvailable = false ) { let prevState = this.getAttribute("pageproxystate"); - + this.removeAttribute("had-proxystate"); this.setAttribute("pageproxystate", state); this._inputContainer.setAttribute("pageproxystate", state); this._identityBox?.setAttribute("pageproxystate", state); @@ -3031,10 +3127,12 @@ export class UrlbarInput extends HTMLElement { return; } this.style.top = px( + this.window.gZenVerticalTabsManager._hasSetSingleToolbar ? this.parentNode.getBoxQuads({ ignoreTransforms: true, flush: false, })[0].p1.y + : (AppConstants.platform == "macosx" ? -2 : -5) ); } @@ -3093,9 +3191,10 @@ export class UrlbarInput extends HTMLElement { return; } + this.window.gZenVerticalTabsManager.recalculateURLBarHeight(); this.parentNode.style.setProperty( "--urlbar-container-height", - px(getBoundsWithoutFlushing(this.parentNode).height) + px(getBoundsWithoutFlushing(this.parentNode).height + 8) ); this.style.setProperty( "--urlbar-height", @@ -3597,6 +3696,7 @@ export class UrlbarInput extends HTMLElement { } _toggleActionOverride(event) { + if (!Services.prefs.getBoolPref("zen.urlbar.enable-overrides")) return; if ( event.keyCode == KeyEvent.DOM_VK_SHIFT || event.keyCode == KeyEvent.DOM_VK_ALT || @@ -3709,8 +3809,8 @@ export class UrlbarInput extends HTMLElement { if (!this.#isAddressbar) { return val; } - let trimmedValue = lazy.UrlbarPrefs.get("trimURLs") - ? lazy.BrowserUIUtils.trimURL(val) + let trimmedValue = lazy.UrlbarPrefs.get("trimURLs") && this._zenTrimURL + ? this._zenTrimURL(val) : val; // Only trim value if the directionality doesn't change to RTL and we're not // showing a strikeout https protocol. @@ -4006,6 +4106,7 @@ export class UrlbarInput extends HTMLElement { resultDetails = null, browser = this.window.gBrowser.selectedBrowser ) { + openUILinkWhere = this.window.gZenUIManager.getOpenUILinkWhere(url, browser, openUILinkWhere); if (this.#isAddressbar) { this.#prepareAddressbarLoad( url, @@ -4117,6 +4218,10 @@ export class UrlbarInput extends HTMLElement { } reuseEmpty = true; } + if (this.hasAttribute("zen-newtab")) { + where = "tab"; + reuseEmpty = true; + } if ( where == "tab" && reuseEmpty && @@ -4124,6 +4229,9 @@ export class UrlbarInput extends HTMLElement { ) { where = "current"; } + if (this.window.gBrowser.selectedTab.hasAttribute("zen-empty-tab")) { + return "tab"; // Always open in a new tab if the current tab is "our empty tab". + } return where; } @@ -4378,6 +4486,7 @@ export class UrlbarInput extends HTMLElement { this.setResultForCurrentValue(null); this.handleCommand(); this.controller.clearLastQueryContextCache(); + this.view.close(); this._suppressStartQuery = false; }); @@ -4385,7 +4494,6 @@ export class UrlbarInput extends HTMLElement { contextMenu.addEventListener("popupshowing", () => { // Close the results pane when the input field contextual menu is open, // because paste and go doesn't want a result selection. - this.view.close(); let controller = this.document.commandDispatcher.getControllerForCommand("cmd_paste"); @@ -4541,7 +4649,11 @@ export class UrlbarInput extends HTMLElement { if (!engineName && !source && !this.hasAttribute("searchmode")) { return; } - + this.window.dispatchEvent( + new CustomEvent("Zen:UrlbarSearchModeChanged", { + detail: { searchMode }, + }) + ); if (this._searchModeIndicatorTitle) { this._searchModeIndicatorTitle.textContent = ""; this._searchModeIndicatorTitle.removeAttribute("data-l10n-id"); @@ -4851,6 +4963,7 @@ export class UrlbarInput extends HTMLElement { this.document.l10n.setAttributes( this.inputField, + this.window.gZenVerticalTabsManager._hasSetSingleToolbar ? 'zen-singletoolbar-urlbar-placeholder-with-name' : l10nId, l10nId == "urlbar-placeholder-with-name" ? { name: engineName } @@ -4964,6 +5077,11 @@ export class UrlbarInput extends HTMLElement { } _on_click(event) { + if (event.target == this.inputField) { + event.zenOriginalTarget = this; + this._on_mousedown(event); + } + switch (event.target) { case this.inputField: case this._inputContainer: @@ -5042,7 +5160,7 @@ export class UrlbarInput extends HTMLElement { } } - if (this.focusedViaMousedown) { + if (this.focusedViaMousedown || this.hasAttribute("zen-newtab")) { this.view.autoOpen({ event }); } else { if (this._untrimOnFocusAfterKeydown) { @@ -5082,9 +5200,16 @@ export class UrlbarInput extends HTMLElement { } _on_mousedown(event) { - switch (event.currentTarget) { + switch (event.zenOriginalTarget || event.currentTarget) { case this: { this._mousedownOnUrlbarDescendant = true; + const isProbablyFloating = + (this.zenUrlbarBehavior == "floating-on-type" && + this.hasAttribute("breakout-extend") && !this.focusedViaMousedown) || + (this.zenUrlbarBehavior == "float") || this.window.gZenVerticalTabsManager._hasSetSingleToolbar; + if (event.type != "click" && isProbablyFloating || event.type == "click" && !isProbablyFloating) { + return true; + } if ( event.composedTarget != this.inputField && event.composedTarget != this._inputContainer @@ -5094,6 +5219,10 @@ export class UrlbarInput extends HTMLElement { this.focusedViaMousedown = !this.focused; this._preventClickSelectsAll = this.focused; + if (isProbablyFloating) { + this.focusedViaMousedown = !this.hasAttribute("breakout-extend"); + this._preventClickSelectsAll = this.hasAttribute("breakout-extend"); + } // Keep the focus status, since the attribute may be changed // upon calling this.focus(). @@ -5129,7 +5258,7 @@ export class UrlbarInput extends HTMLElement { } // Don't close the view when clicking on a tab; we may want to keep the // view open on tab switch, and the TabSelect event arrived earlier. - if (event.target.closest("tab")) { + if (event.target.closest("tab") || event.target.closest("#tabs-newtab-button")) { break; } @@ -5411,7 +5540,7 @@ export class UrlbarInput extends HTMLElement { // When we are in actions search mode we can show more results so // increase the limit. let maxResults = - this.searchMode?.source != lazy.UrlbarUtils.RESULT_SOURCE.ACTIONS + this.searchMode?.source != lazy.UrlbarUtils.RESULT_SOURCE.ZEN_ACTIONS ? lazy.UrlbarPrefs.get("maxRichResults") : UNLIMITED_MAX_RESULTS; let options = {