Skip to content

Commit

Permalink
Bug 1879941 - Prevent searchbar context menu from opening a context m…
Browse files Browse the repository at this point in the history
…enu. r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D201670
  • Loading branch information
emilio committed Mar 8, 2024
1 parent c715264 commit 709a0bb
Showing 2 changed files with 40 additions and 27 deletions.
60 changes: 33 additions & 27 deletions browser/base/content/browser.js
Original file line number Diff line number Diff line change
@@ -6449,6 +6449,37 @@ function onViewToolbarsPopupShowing(aEvent, aInsertPoint) {
return;
}

// triggerNode can be a nested child element of a toolbaritem.
let toolbarItem = popup.triggerNode;
while (toolbarItem) {
let localName = toolbarItem.localName;
if (localName == "toolbar") {
toolbarItem = null;
break;
}
if (localName == "toolbarpaletteitem") {
toolbarItem = toolbarItem.firstElementChild;
break;
}
if (localName == "menupopup") {
aEvent.preventDefault();
aEvent.stopPropagation();
return;
}
let parent = toolbarItem.parentElement;
if (parent) {
if (
parent.classList.contains("customization-target") ||
parent.getAttribute("overflowfortoolbar") || // Needs to work in the overflow list as well.
parent.localName == "toolbarpaletteitem" ||
parent.localName == "toolbar"
) {
break;
}
}
toolbarItem = parent;
}

// Empty the menu
for (var i = popup.children.length - 1; i >= 0; --i) {
var deadItem = popup.children[i];
@@ -6502,30 +6533,7 @@ function onViewToolbarsPopupShowing(aEvent, aInsertPoint) {
return;
}

// triggerNode can be a nested child element of a toolbaritem.
let toolbarItem = popup.triggerNode;

if (toolbarItem && toolbarItem.localName == "toolbarpaletteitem") {
toolbarItem = toolbarItem.firstElementChild;
} else if (toolbarItem && toolbarItem.localName != "toolbar") {
while (toolbarItem && toolbarItem.parentElement) {
let parent = toolbarItem.parentElement;
if (
(parent.classList &&
parent.classList.contains("customization-target")) ||
parent.getAttribute("overflowfortoolbar") || // Needs to work in the overflow list as well.
parent.localName == "toolbarpaletteitem" ||
parent.localName == "toolbar"
) {
break;
}
toolbarItem = parent;
}
} else {
toolbarItem = null;
}

let showTabStripItems = toolbarItem && toolbarItem.id == "tabbrowser-tabs";
let showTabStripItems = toolbarItem?.id == "tabbrowser-tabs";
for (let node of popup.querySelectorAll(
'menuitem[contexttype="toolbaritem"]'
)) {
@@ -6581,9 +6589,7 @@ function onViewToolbarsPopupShowing(aEvent, aInsertPoint) {
}

let movable =
toolbarItem &&
toolbarItem.id &&
CustomizableUI.isWidgetRemovable(toolbarItem);
toolbarItem?.id && CustomizableUI.isWidgetRemovable(toolbarItem);
if (movable) {
if (CustomizableUI.isSpecialWidget(toolbarItem.id)) {
moveToPanel.setAttribute("disabled", true);
Original file line number Diff line number Diff line change
@@ -267,6 +267,13 @@ add_no_popup_task(async function right_click_doesnt_open_popup() {
context_click(textbox);
let contextPopup = await promise;

// Assert that the context menu click inside the popup does nothing. If it
// opens something, assert_no_popup_task will make us fail. On macOS this
// doesn't work because of native context menus.
if (!navigator.platform.includes("Mac")) {
context_click(contextPopup);
}

is(
Services.focus.focusedElement,
textbox,

0 comments on commit 709a0bb

Please sign in to comment.