Bug 1529205 - Remove DateTimePickerParent's dependency on gBrowser; r=mconley

Differential Revision: https://phabricator.services.mozilla.com/D35392

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Geoff Lankow 2019-06-26 18:15:28 +00:00
parent 16baf0b829
commit 7df08a4fb1
4 changed files with 31 additions and 16 deletions

View File

@ -250,19 +250,6 @@ window._gBrowser = {
return i;
},
get popupAnchor() {
if (this.selectedTab._popupAnchor) {
return this.selectedTab._popupAnchor;
}
let stack = this.selectedBrowser.parentNode;
// Create an anchor for the popup
let popupAnchor = document.createXULElement("hbox");
popupAnchor.className = "popup-anchor";
popupAnchor.hidden = true;
stack.appendChild(popupAnchor);
return this.selectedTab._popupAnchor = popupAnchor;
},
set selectedTab(val) {
if (gNavToolbox.collapsed && !this._allowTabChange) {
return this.tabbox.selectedTab;

View File

@ -108,7 +108,7 @@ var FormValidationHandler =
this._panel.hidden = false;
let tabBrowser = aWindow.gBrowser;
this._anchor = tabBrowser.popupAnchor;
this._anchor = tabBrowser.selectedBrowser.popupAnchor;
this._anchor.left = aPanelData.contentRect.left;
this._anchor.top = aPanelData.contentRect.top;
this._anchor.width = aPanelData.contentRect.width;

View File

@ -401,6 +401,30 @@ class MozBrowser extends MozElements.MozElementMixin(XULFrameElement) {
return document.getElementById(this.getAttribute("datetimepicker"));
}
/**
* Provides a node to hang popups (such as the datetimepicker) from.
* If this <browser> isn't the descendant of a <stack>, null is returned
* instead and popup code must handle this case.
*/
get popupAnchor() {
let stack = this.closest("stack");
if (!stack) {
return null;
}
let popupAnchor = stack.querySelector(".popup-anchor");
if (popupAnchor) {
return popupAnchor;
}
// Create an anchor for the popup
popupAnchor = document.createXULElement("hbox");
popupAnchor.className = "popup-anchor";
popupAnchor.hidden = true;
stack.appendChild(popupAnchor);
return popupAnchor;
}
set docShellIsActive(val) {
if (this.isRemoteBrowser) {
let { frameLoader } = this;

View File

@ -111,7 +111,11 @@ var DateTimePickerParent = {
let type = aData.type;
let detail = aData.detail;
this._anchor = aBrowser.ownerGlobal.gBrowser.popupAnchor;
this._anchor = aBrowser.popupAnchor;
if (!this._anchor) {
throw new Error("No popup anchor for this browser, cannot show date picker");
}
this._anchor.left = rect.left;
this._anchor.top = rect.top;
this._anchor.width = rect.width;
@ -123,7 +127,7 @@ var DateTimePickerParent = {
let window = aBrowser.ownerGlobal;
let tabbrowser = window.gBrowser;
if (Services.focus.activeWindow != window ||
tabbrowser.selectedBrowser != aBrowser) {
(tabbrowser && tabbrowser.selectedBrowser != aBrowser)) {
// We were sent a message from a window or tab that went into the
// background, so we'll ignore it for now.
return;