Skip to content

Commit

Permalink
Update places-menupopup.js script override
Browse files Browse the repository at this point in the history
since it was incompatible with recent updates,
breaking scrolling in places menupopups and
potentially causing a crash if too many bookmarks in a single popup.
  • Loading branch information
aminomancer committed Nov 22, 2022
1 parent cbbd0b5 commit 68ce7bd
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 30 deletions.
63 changes: 47 additions & 16 deletions resources/script-override/places-menupopup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ==UserScript==
// @name Restore Places Menupopup Arrows
// @version 1.0
// @version 1.1.0
// @author aminomancer
// @homepage https://github.com/aminomancer/uc.css.js
// @description Necessary for use with restorePreProtonArrowpanels.uc.js.
Expand All @@ -13,6 +13,23 @@
/* eslint-env mozilla/browser-window */
/* import-globals-from controller.js */

// On Wayland when D&D source popup is closed,
// D&D operation is canceled by window manager.
function closingPopupEndsDrag(popup) {
if (!popup.isWaylandPopup) {
return false;
}
if (popup.isWaylandDragSource) {
return true;
}
for (let childPopup of popup.querySelectorAll("menu > menupopup")) {
if (childPopup.isWaylandDragSource) {
return true;
}
}
return false;
}

// This is loaded into all XUL windows. Wrap in a block to prevent
// leaking to window scope.
{
Expand Down Expand Up @@ -40,7 +57,7 @@
get markup() {
return `
<html:link rel="stylesheet" href="chrome://global/skin/global.css" />
<hbox flex="1">
<hbox part="drop-indicator-container">
<vbox part="drop-indicator-bar" hidden="true">
<image part="drop-indicator"/>
</vbox>
Expand Down Expand Up @@ -140,7 +157,7 @@
// Close any parent folders which aren't being dragged over.
// (This is necessary because of the above code that keeps a folder
// open while its children are being dragged over.)
if (!draggingOverChild) {
if (!draggingOverChild && !closingPopupEndsDrag(this._self)) {
this.closeParentMenus();
}
} else if (aTimer == this.closeMenuTimer) {
Expand All @@ -154,13 +171,17 @@
popup.parentNode
)
) {
popup.hidePopup();
// Close any parent menus that aren't being dragged over;
// otherwise they'll stay open because they couldn't close
// while this menu was being dragged over.
this.closeParentMenus();
if (!closingPopupEndsDrag(popup)) {
popup.hidePopup();
// Close any parent menus that aren't being dragged over;
// otherwise they'll stay open because they couldn't close
// while this menu was being dragged over.
this.closeParentMenus();
} else if (popup.isWaylandDragSource) {
// Postpone popup hide until drag end on Wayland.
this._closeMenuTimer = this.setTimer(this.hoverTime);
}
}
this._closeMenuTimer = null;
}
},

Expand Down Expand Up @@ -190,8 +211,12 @@
// timers for opening/closing it.
clear: function OF__clear() {
if (this._folder.elt && this._folder.elt.lastElementChild) {
if (!this._folder.elt.lastElementChild.hasAttribute("dragover")) {
this._folder.elt.lastElementChild.hidePopup();
let popup = this._folder.elt.lastElementChild;
if (
!popup.hasAttribute("dragover") &&
!closingPopupEndsDrag(popup)
) {
popup.hidePopup();
}
// remove menuactive style
this._folder.elt.removeAttribute("_moz-menuactive");
Expand Down Expand Up @@ -220,6 +245,9 @@

/**
* This is the view that manages the popup.
*
* @see {@link PlacesUIUtils.getViewForNode}
* @returns {DOMNode}
*/
get _rootView() {
if (!this.__rootView) {
Expand Down Expand Up @@ -506,11 +534,14 @@
let newMarginTop = 0;
if (scrollDir == 0) {
let elt = this.firstElementChild;
while (
elt &&
event.screenY > elt.screenY + elt.getBoundingClientRect().height / 2
) {
elt = elt.nextElementSibling;
for (; elt; elt = elt.nextElementSibling) {
let height = elt.getBoundingClientRect().height;
if (height == 0) {
continue;
}
if (event.screenY <= elt.screenY + height / 2) {
break;
}
}
newMarginTop = elt
? elt.screenY - this.scrollBox.screenY
Expand Down
21 changes: 7 additions & 14 deletions userChrome.au.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ so of this stylesheet is dedicated to restoring pre-proton content. */

@import url(chrome://userchrome/content/layout/uc-nsRules.au.css);

@-moz-document regexp("^((chrome|resource|file)://|about:).*$")
{
@-moz-document regexp("^((chrome|resource|file)://|about:).*$") {
:root {
--avatar-image-url: url(chrome://userchrome/content/fxa/avatar-big.svg);
}
Expand Down Expand Up @@ -610,8 +609,7 @@ so of this stylesheet is dedicated to restoring pre-proton content. */
font-weight: 500;
}

@-moz-document url(chrome://browser/content/browser.xhtml)
{
@-moz-document url(chrome://browser/content/browser.xhtml) {
:is(#customization-lwtheme-menu, #customization-uidensity-menu)::part(arrowbox) {
-moz-box-ordinal-group: 2;
}
Expand Down Expand Up @@ -652,8 +650,7 @@ so of this stylesheet is dedicated to restoring pre-proton content. */
url(chrome://mozapps/content/handling/appChooser.xhtml),
url-prefix(chrome://global/content/print.html),
url(chrome://browser/content/places/bookmarkProperties.xhtml),
url(chrome://browser/content/places/bookmarkProperties2.xhtml)
{
url(chrome://browser/content/places/bookmarkProperties2.xhtml) {
menulist:not([native]) {
padding-inline: 6px;
}
Expand Down Expand Up @@ -1687,13 +1684,11 @@ so of this stylesheet is dedicated to restoring pre-proton content. */
padding: 30px 30px 20px 30px;
}

#handlersView .actionsMenu[image="chrome://browser/skin/preferences/application.png"]::part(icon)
{
#handlersView .actionsMenu[image="chrome://browser/skin/preferences/application.png"]::part(icon) {
display: none;
}

#handlersView .actionsMenu[image="chrome://browser/skin/preferences/application.png"]::before
{
#handlersView .actionsMenu[image="chrome://browser/skin/preferences/application.png"]::before {
width: 16px;
height: 16px;
margin-inline: 11px 8px;
Expand All @@ -1707,8 +1702,7 @@ so of this stylesheet is dedicated to restoring pre-proton content. */
background-image: url(chrome://userchrome/content/shortcut.svg);
}

#handlersView .actionIcon[src="chrome://browser/skin/preferences/application.png"]
{
#handlersView .actionIcon[src="chrome://browser/skin/preferences/application.png"] {
width: 16px;
height: 16px;
margin-inline: 11px 8px;
Expand All @@ -1723,8 +1717,7 @@ so of this stylesheet is dedicated to restoring pre-proton content. */
}

@-moz-document url("chrome://mozapps/content/downloads/unknownContentType.xhtml"),
url("chrome://global/content/appPicker.xhtml")
{
url("chrome://global/content/appPicker.xhtml") {
:root {
--in-content-page-color: rgb(21, 20, 26);
--in-content-page-background: #fff;
Expand Down

0 comments on commit 68ce7bd

Please sign in to comment.