mirror of
https://github.com/zen-browser/desktop.git
synced 2026-08-23 15:01:34 +00:00
335 lines
12 KiB
C++
335 lines
12 KiB
C++
diff --git a/browser/components/urlbar/UrlbarInput.sys.mjs b/browser/components/urlbar/UrlbarInput.sys.mjs
|
|
index 4b7232f3261f8589b734c2238170e6968d7ea0bf..d8c0b404724e9b0dc2b5a2d21420357586fb7f14 100644
|
|
--- a/browser/components/urlbar/UrlbarInput.sys.mjs
|
|
+++ b/browser/components/urlbar/UrlbarInput.sys.mjs
|
|
@@ -84,6 +84,13 @@ ChromeUtils.defineLazyGetter(lazy, "logger", () =>
|
|
lazy.UrlbarUtils.getLogger({ prefix: "Input" })
|
|
);
|
|
|
|
+XPCOMUtils.defineLazyPreferenceGetter(
|
|
+ lazy,
|
|
+ "ZEN_URLBAR_BEHAVIOR",
|
|
+ "zen.urlbar.behavior",
|
|
+ 'default'
|
|
+);
|
|
+
|
|
const DEFAULT_FORM_HISTORY_NAME = "searchbar-history";
|
|
|
|
const UNLIMITED_MAX_RESULTS = 99;
|
|
@@ -454,7 +461,16 @@ export class UrlbarInput {
|
|
// 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;
|
|
}
|
|
|
|
@@ -530,6 +546,10 @@ export class UrlbarInput {
|
|
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"
|
|
@@ -807,8 +827,16 @@ export class UrlbarInput {
|
|
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);
|
|
}
|
|
|
|
/**
|
|
@@ -1224,7 +1252,11 @@ export class UrlbarInput {
|
|
}
|
|
|
|
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) {
|
|
@@ -2347,6 +2379,32 @@ export class UrlbarInput {
|
|
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;
|
|
+
|
|
+ // Error check occurs during isClipboardURIValid
|
|
+ let uri = this.window.gBrowser.currentURI;
|
|
+ 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
|
|
@@ -2361,6 +2419,13 @@ export class UrlbarInput {
|
|
|
|
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")) {
|
|
@@ -2380,6 +2445,24 @@ export class UrlbarInput {
|
|
return;
|
|
}
|
|
|
|
+ if (this._zenHandleUrlbarClose) {
|
|
+ this._zenHandleUrlbarClose();
|
|
+ }
|
|
+
|
|
+ // 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();
|
|
}
|
|
@@ -2410,7 +2493,7 @@ export class UrlbarInput {
|
|
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);
|
|
@@ -2646,10 +2729,12 @@ export class UrlbarInput {
|
|
return;
|
|
}
|
|
this.textbox.style.top = px(
|
|
+ this.window.gZenVerticalTabsManager._hasSetSingleToolbar ?
|
|
this.textbox.parentNode.getBoxQuads({
|
|
ignoreTransforms: true,
|
|
flush: false,
|
|
})[0].p1.y
|
|
+ : (AppConstants.platform == "macosx" ? -2 : -5)
|
|
);
|
|
}
|
|
|
|
@@ -2709,9 +2794,10 @@ export class UrlbarInput {
|
|
return;
|
|
}
|
|
|
|
+ this.window.gZenVerticalTabsManager.recalculateURLBarHeight();
|
|
this.textbox.parentNode.style.setProperty(
|
|
"--urlbar-container-height",
|
|
- px(getBoundsWithoutFlushing(this.textbox.parentNode).height)
|
|
+ px(getBoundsWithoutFlushing(this.textbox.parentNode).height + 8)
|
|
);
|
|
this.textbox.style.setProperty(
|
|
"--urlbar-height",
|
|
@@ -3144,6 +3230,7 @@ export class UrlbarInput {
|
|
}
|
|
|
|
_toggleActionOverride(event) {
|
|
+ if (!Services.prefs.getBoolPref("zen.urlbar.enable-overrides")) return;
|
|
if (
|
|
event.keyCode == KeyEvent.DOM_VK_SHIFT ||
|
|
event.keyCode == KeyEvent.DOM_VK_ALT ||
|
|
@@ -3248,7 +3335,7 @@ export class UrlbarInput {
|
|
return val;
|
|
}
|
|
let trimmedValue = lazy.UrlbarPrefs.get("trimURLs")
|
|
- ? lazy.BrowserUIUtils.trimURL(val)
|
|
+ ? this._zenTrimURL(val)
|
|
: val;
|
|
// Only trim value if the directionality doesn't change to RTL and we're not
|
|
// showing a strikeout https protocol.
|
|
@@ -3552,6 +3639,7 @@ export class UrlbarInput {
|
|
resultDetails = null,
|
|
browser = this.window.gBrowser.selectedBrowser
|
|
) {
|
|
+ openUILinkWhere = this.window.gZenUIManager.getOpenUILinkWhere(url, browser, openUILinkWhere);
|
|
if (this.isAddressbar) {
|
|
this.#prepareAddressbarLoad(
|
|
url,
|
|
@@ -3659,6 +3747,10 @@ export class UrlbarInput {
|
|
}
|
|
reuseEmpty = true;
|
|
}
|
|
+ if (this.hasAttribute("zen-newtab")) {
|
|
+ where = "tab";
|
|
+ reuseEmpty = true;
|
|
+ }
|
|
if (
|
|
where == "tab" &&
|
|
reuseEmpty &&
|
|
@@ -3666,6 +3758,9 @@ export class UrlbarInput {
|
|
) {
|
|
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;
|
|
}
|
|
|
|
@@ -3923,6 +4018,7 @@ export class UrlbarInput {
|
|
this.setResultForCurrentValue(null);
|
|
this.handleCommand();
|
|
this.controller.clearLastQueryContextCache();
|
|
+ this.view.close();
|
|
|
|
this._suppressStartQuery = false;
|
|
});
|
|
@@ -3930,7 +4026,6 @@ export class UrlbarInput {
|
|
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");
|
|
@@ -4040,7 +4135,11 @@ export class UrlbarInput {
|
|
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");
|
|
@@ -4351,6 +4450,7 @@ export class UrlbarInput {
|
|
|
|
this.document.l10n.setAttributes(
|
|
this.inputField,
|
|
+ this.window.gZenVerticalTabsManager._hasSetSingleToolbar ? 'zen-singletoolbar-urlbar-placeholder-with-name' :
|
|
l10nId,
|
|
l10nId == "urlbar-placeholder-with-name" ? { name } : undefined
|
|
);
|
|
@@ -4462,6 +4562,11 @@ export class UrlbarInput {
|
|
}
|
|
|
|
_on_click(event) {
|
|
+ if (event.target == this.inputField) {
|
|
+ event.zenOriginalTarget = this.textbox;
|
|
+ this._on_mousedown(event);
|
|
+ }
|
|
+
|
|
if (
|
|
event.target == this.inputField ||
|
|
event.target == this._inputContainer
|
|
@@ -4534,7 +4639,7 @@ export class UrlbarInput {
|
|
}
|
|
}
|
|
|
|
- if (this.focusedViaMousedown) {
|
|
+ if (this.focusedViaMousedown || this.hasAttribute("zen-newtab")) {
|
|
this.view.autoOpen({ event });
|
|
} else {
|
|
if (this._untrimOnFocusAfterKeydown) {
|
|
@@ -4574,9 +4679,16 @@ export class UrlbarInput {
|
|
}
|
|
|
|
_on_mousedown(event) {
|
|
- switch (event.currentTarget) {
|
|
+ switch (event.zenOriginalTarget || event.currentTarget) {
|
|
case this.textbox: {
|
|
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.target != this.inputField &&
|
|
@@ -4587,6 +4699,10 @@ export class UrlbarInput {
|
|
|
|
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().
|
|
@@ -4622,7 +4738,7 @@ export class UrlbarInput {
|
|
}
|
|
// 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;
|
|
}
|
|
|
|
@@ -4939,7 +5055,7 @@ export class UrlbarInput {
|
|
// 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 = {
|