-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathUrlbarInput-mjs.patch
More file actions
364 lines (341 loc) · 13.5 KB
/
UrlbarInput-mjs.patch
File metadata and controls
364 lines (341 loc) · 13.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
diff --git a/browser/components/urlbar/content/UrlbarInput.mjs b/browser/components/urlbar/content/UrlbarInput.mjs
index b23244f9d3278918b016bb3fcab19687bc2e292a..e5de81b3060a1ee76b1a6aff2e4ae1ca50f2caa9 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,45 @@ export class UrlbarInput extends HTMLElement {
await this.#updateLayoutBreakoutDimensions();
}
+ zenFormatURLValue() {
+ return this.#lazy.valueFormatter._formatURL();
+ }
+
+ get zenUrlbarBehavior() {
+ if (
+ this.document.documentElement.hasAttribute("inDOMFullscreen") ||
+ this.document.documentElement.hasAttribute("zen-little-window")
+ ) {
+ 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 +2781,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 +2807,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 +2858,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 +3130,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 +3194,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 +3699,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 +3812,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 +4109,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,
@@ -4088,6 +4192,11 @@ export class UrlbarInput extends HTMLElement {
* @returns {"current" | "tabshifted" | "tab" | "save" | "window"}
*/
_whereToOpen(event) {
+ if (this.document.documentElement.hasAttribute("zen-little-window")) {
+ // Little windows are single-tab popups -- never spawn extra tabs
+ // or new windows from the urlbar.
+ return "current";
+ }
let isKeyboardEvent = KeyboardEvent.isInstance(event);
let reuseEmpty = isKeyboardEvent;
let where = undefined;
@@ -4117,6 +4226,10 @@ export class UrlbarInput extends HTMLElement {
}
reuseEmpty = true;
}
+ if (this.hasAttribute("zen-newtab")) {
+ where = "tab";
+ reuseEmpty = true;
+ }
if (
where == "tab" &&
reuseEmpty &&
@@ -4124,6 +4237,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 +4494,7 @@ export class UrlbarInput extends HTMLElement {
this.setResultForCurrentValue(null);
this.handleCommand();
this.controller.clearLastQueryContextCache();
+ this.view.close();
this._suppressStartQuery = false;
});
@@ -4385,7 +4502,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 +4657,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 +4971,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 +5085,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 +5168,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 +5208,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 +5227,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 +5266,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 +5548,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 = {