Skip to content

Commit

Permalink
(JS) delete urlbarAutofillSubdir since Firefox
Browse files Browse the repository at this point in the history
now has a pref for this: browser.urlbar.autoFill.adaptiveHistory.enabled
allTabsMenuExpansionPack:
extend key navigation within the menu.
backspacePanelNav: make the script more resilient to updates.
also animate the panel closing.
verticalTabsPane: fix key navigation.
copyCurrentUrlHotkey: improve code comments.
(CSS) add new MIDI icons.
update some context menu icons.
fix some height issues with radio buttons in panels.
fix date/time picker panel background color.
adjust print preview pagination styles.
fix an issue with all tabs panel focus styles.
  • Loading branch information
aminomancer committed May 16, 2022
1 parent c91f84f commit b13d7f1
Show file tree
Hide file tree
Showing 13 changed files with 315 additions and 304 deletions.
116 changes: 108 additions & 8 deletions JS/allTabsMenuExpansionPack.uc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ==UserScript==
// @name All Tabs Menu Expansion Pack
// @version 2.0.3
// @version 2.0.5
// @author aminomancer
// @homepage https://github.com/aminomancer
// @description Next to the "new tab" button in Firefox there's a V-shaped button that opens a
Expand Down Expand Up @@ -117,17 +117,117 @@
}
}

function skipHiddenButtons(tabsPanel) {
// Adjust the PanelView class methods for each panelview instance to improve
// key navigation and prevent focusing hidden elements.
function modifyWalkers(tabsPanel) {
let panelViewClass = PanelView.forNode(tabsPanel.view);
if (!panelViewClass._makeNavigableTreeWalker.toSource().startsWith("("))
if (!panelViewClass.moveSelection.toSource().startsWith("(function uc_ATMEP_")) {
panelViewClass.moveSelection = function uc_ATMEP_moveSelection(
isDown,
arrowKey = false
) {
let walker = arrowKey ? this._arrowNavigableWalker : this._tabNavigableWalker;
let oldSel = this.selectedElement;
let newSel;
if (oldSel) {
walker.currentNode = oldSel;
newSel = isDown ? walker.nextNode() : walker.previousNode();
}
// If we couldn't find something, select the first or last item:
if (!newSel) {
walker.currentNode = walker.root;
newSel = isDown ? walker.firstChild() : walker.lastChild();
}
if (oldSel?.classList.contains("all-tabs-secondary-button")) {
if (oldSel.parentElement === newSel?.parentElement) {
walker.currentNode = newSel;
newSel = isDown ? walker.nextNode() : walker.previousNode();
}
}
this.selectedElement = newSel;
return newSel;
};
}
if (!panelViewClass.hasOwnProperty("moveSelectionHorizontal")) {
panelViewClass.moveSelectionHorizontal = function uc_ATMEP_moveSelectionHorizontal(
isNext
) {
let walker = this._horizontalNavigableWalker;
let oldSel = this.selectedElement;
let newSel;
if (oldSel) {
walker.currentNode = oldSel;
newSel = isNext ? walker.nextNode() : walker.previousNode();
}
// If we couldn't find something, select the first or last item:
if (!newSel) {
walker.currentNode = walker.root;
newSel = isNext ? walker.firstChild() : walker.lastChild();
}
this.selectedElement = newSel;
return newSel;
};
}
if (!panelViewClass.hasOwnProperty("_horizontalNavigableWalker")) {
Object.defineProperty(panelViewClass, "_horizontalNavigableWalker", {
get: function () {
if (!this.__horizontalNavigableWalker) {
this.__horizontalNavigableWalker = this._makeNavigableTreeWalker(
true,
false
);
}
return this.__horizontalNavigableWalker;
},
});
}
if (!panelViewClass._makeNavigableTreeWalker.toSource().startsWith("(function uc_ATMEP_")) {
eval(
`panelViewClass._makeNavigableTreeWalker = function ` +
panelViewClass._makeNavigableTreeWalker
.toSource()
.replace(/(node\.disabled)/, `$1 || node.hidden`)
.replace(/^\(/, "")
.replace(/\)$/, "")
.replace(/^_makeNavigableTreeWalker\s*/, "")
.replace(/^function\s*/, "")
.replace(/^(.)/, `uc_ATMEP_makeNavigableTreeWalker $1`)
.replace(/\(arrowKey\)/, `(arrowKey, vertical = true)`)
// .replace(/(node\.disabled)/, `$1 || node.hidden`)
.replace(
/(let bounds = this)/,
`if (node.hidden) {\n return NodeFilter.FILTER_SKIP;\n }\n $1`
)
.replace(
/(\(!arrowKey && this\._isNavigableWithTabOnly\(node\)\)\n\s*\) \{)/,
/* javascript */ `$1
if (vertical && node.classList.contains("all-tabs-secondary-button")) return NodeFilter.FILTER_SKIP;`
)
);
}
if (!panelViewClass.keyNavigation.toSource().startsWith("(function uc_ATMEP_")) {
eval(
`panelViewClass.keyNavigation = function ` +
panelViewClass.keyNavigation
.toSource()
.replace(/^\(/, "")
.replace(/\)$/, "")
.replace(/^keyNavigation\s*/, "")
.replace(/^function\s*/, "")
.replace(/^(.)/, `uc_ATMEP_keyNavigation $1`)
.replace(
/(if \(\n\s*\(!this\.window\.RTL_UI && keyCode == \"ArrowLeft\"\) \|\|)/,
/* javascript */ `if (this.selectedElement && this.selectedElement.matches(".all-tabs-button, .all-tabs-secondary-button")) {
let isNext = (this.window.RTL_UI && keyCode == "ArrowLeft") || (!this.window.RTL_UI && keyCode == "ArrowRight");
let nextButton = this.moveSelectionHorizontal(isNext);
Services.focus.setFocus(nextButton, Services.focus.FLAG_BYKEY);
break;
}
$1`
)
);
delete panelViewClass.__arrowNavigableWalker;
delete panelViewClass.__tabNavigableWalker;
delete panelViewClass.__arrowNavigableWalker;
delete panelViewClass.__tabNavigableWalker;
}
}

function prefHandler(_sub, _top, _pref) {
Expand Down Expand Up @@ -322,7 +422,7 @@
setupPIP();
setupCtrlTab();

tabsPanels.forEach(skipHiddenButtons);
tabsPanels.forEach(modifyWalkers);
tabsPanels.forEach(setupTabsPanel);
}

Expand Down Expand Up @@ -632,7 +732,7 @@
delete tab.noCanvas;
this.gBrowser.unlockClearMultiSelection();
this.gBrowser.clearMultiSelectedTabs();
PanelMultiView.hidePopup(this.view.closest("panel"));
PanelMultiView.hidePopup(PanelMultiView.forNode(this.view.panelMultiView)._panel);
};
tabsPanel._onClick = function (e, tab) {
if (e.button !== 0 || e.target.classList.contains("all-tabs-secondary-button")) return;
Expand Down
136 changes: 25 additions & 111 deletions JS/backspacePanelNav.uc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ==UserScript==
// @name Backspace Panel Navigation
// @version 1.0
// @version 1.1.0
// @author aminomancer
// @homepage https://github.com/aminomancer
// @description Press backspace to navigate back/forward in popup panels.
Expand All @@ -9,117 +9,31 @@

(function () {
function init() {
let appMenu = PanelView.forNode(PanelUI.mainView);
Object.getPrototypeOf(appMenu).keyNavigation = function (event) {
if (!this.active) return;
let focus = this.document.activeElement;
if (
focus &&
!(this.node.compareDocumentPosition(focus) & Node.DOCUMENT_POSITION_CONTAINED_BY)
)
focus = null;
if (focus && (focus.tagName == "browser" || focus.tagName == "iframe")) return;
let stop = () => {
event.stopPropagation();
event.preventDefault();
};
let tabOnly = () => {
return focus && this._isNavigableWithTabOnly(focus);
};
let isContextMenuOpen = () => {
if (!focus) return false;
let contextNode = focus.closest("[context]");
if (!contextNode) return false;
let context = contextNode.getAttribute("context");
if (!context) return false;
let popup = this.document.getElementById(context);
return popup && popup.state == "open";
};
let keyCode = event.code;
switch (keyCode) {
case "ArrowDown":
case "ArrowUp":
if (tabOnly()) break;
case "Tab": {
if (
isContextMenuOpen() ||
(focus && focus.localName == "menulist" && focus.open)
const pc = Object.getPrototypeOf(PanelView.forNode(PanelUI.mainView));
eval(
`pc.keyNavigation = function ` +
pc.keyNavigation
.toSource()
.replace(/^\(/, "")
.replace(/\)$/, "")
.replace(/^keyNavigation\s*/, "")
.replace(/^function\s*/, "")
.replace(
/(case \"ArrowLeft\"\:)/,
`case "Backspace":
if (tabOnly() || isContextMenuOpen()) {
break;
}
stop();
if (PanelMultiView.forNode(this.node.panelMultiView).openViews.length > 1) {
this.node.panelMultiView.goBack();
} else {
PanelMultiView.forNode(this.node.panelMultiView)._panel.hidePopup(true);
}
break;
$1`
)
break;
stop();
let isDown = keyCode == "ArrowDown" || (keyCode == "Tab" && !event.shiftKey);
let button = this.moveSelection(isDown, keyCode != "Tab");
Services.focus.setFocus(button, Services.focus.FLAG_BYKEY);
break;
}
case "Home":
if (tabOnly() || isContextMenuOpen()) break;
stop();
this.focusFirstNavigableElement(true);
break;
case "End":
if (tabOnly() || isContextMenuOpen()) break;
stop();
this.focusLastNavigableElement(true);
break;
case "Backspace":
if (tabOnly() || isContextMenuOpen()) break;
stop();
if (PanelMultiView.forNode(this.node.panelMultiView).openViews.length > 1)
this.node.panelMultiView.goBack();
else PanelMultiView.forNode(this.node.panelMultiView).hidePopup();
break;
case "ArrowLeft":
case "ArrowRight": {
if (tabOnly() || isContextMenuOpen()) break;
stop();
if (
(!this.window.RTL_UI && keyCode == "ArrowLeft") ||
(this.window.RTL_UI && keyCode == "ArrowRight")
) {
this.node.panelMultiView.goBack();
break;
}
let button = this.selectedElement;
if (!button || !button.classList.contains("subviewbutton-nav")) break;
}
case "Space":
case "NumpadEnter":
case "Enter": {
if (tabOnly() || isContextMenuOpen()) break;
let button = this.selectedElement;
if (!button) break;
stop();
this._doingKeyboardActivation = true;
let commandEvent = event.target.ownerDocument.createEvent("xulcommandevent");
commandEvent.initCommandEvent(
"command",
true,
true,
event.target.ownerGlobal,
0,
event.ctrlKey,
event.altKey,
event.shiftKey,
event.metaKey,
0,
null,
0
);
button.dispatchEvent(commandEvent);
let dispEvent = new event.target.ownerGlobal.MouseEvent("mousedown", {
bubbles: true,
});
button.dispatchEvent(dispEvent);
dispEvent = new event.target.ownerGlobal.MouseEvent("click", {
bubbles: true,
});
button.dispatchEvent(dispEvent);
this._doingKeyboardActivation = false;
break;
}
}
};
);
}

if (gBrowserInit.delayedStartupFinished) {
Expand Down
Loading

0 comments on commit b13d7f1

Please sign in to comment.