Bug 1443837 - Set the "hasadjacentnewtabbutton" attribute in the tabbrowser-tabs binding rather than gBrowser. r?gijs
MozReview-Commit-ID: GzmaJ4nVwtP
--- a/browser/base/content/tabbrowser.js
+++ b/browser/base/content/tabbrowser.js
@@ -151,19 +151,16 @@ window._gBrowser = {
this._soundPlayingAttrRemovalTimer = 0;
this._hoverTabTimer = null;
this.mCurrentBrowser = this.initialBrowser;
this.mCurrentBrowser.permanentKey = {};
- CustomizableUI.addListener(this);
- this._updateNewTabVisibility();
-
Services.obs.addObserver(this, "contextual-identity-updated");
this.mCurrentTab = this.tabContainer.firstChild;
const nsIEventListenerService =
Ci.nsIEventListenerService;
let els = Cc["@mozilla.org/eventlistenerservice;1"]
.getService(nsIEventListenerService);
els.addSystemEventListener(document, "keydown", this, false);
@@ -3894,52 +3891,16 @@ window._gBrowser = {
{
// This is the only pref observed.
this._findAsYouType = Services.prefs.getBoolPref("accessibility.typeaheadfind");
break;
}
}
},
- _updateNewTabVisibility() {
- // Helper functions to help deal with customize mode wrapping some items
- let wrap = n => n.parentNode.localName == "toolbarpaletteitem" ? n.parentNode : n;
- let unwrap = n => n && n.localName == "toolbarpaletteitem" ? n.firstElementChild : n;
-
- let sib = this.tabContainer;
- do {
- sib = unwrap(wrap(sib).nextElementSibling);
- } while (sib && sib.hidden);
-
- const kAttr = "hasadjacentnewtabbutton";
- if (sib && sib.id == "new-tab-button") {
- this.tabContainer.setAttribute(kAttr, "true");
- } else {
- this.tabContainer.removeAttribute(kAttr);
- }
- },
-
- onWidgetAfterDOMChange(aNode, aNextNode, aContainer) {
- if (aContainer.ownerDocument == document &&
- aContainer.id == "TabsToolbar") {
- this._updateNewTabVisibility();
- }
- },
-
- onAreaNodeRegistered(aArea, aContainer) {
- if (aContainer.ownerDocument == document &&
- aArea == "TabsToolbar") {
- this._updateNewTabVisibility();
- }
- },
-
- onAreaReset(aArea, aContainer) {
- this.onAreaNodeRegistered(aArea, aContainer);
- },
-
_generateUniquePanelID() {
if (!this._uniquePanelIDCounter) {
this._uniquePanelIDCounter = 0;
}
let outerID = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.outerWindowID;
@@ -3948,18 +3909,16 @@ window._gBrowser = {
// window ID. We switched to a monotonic counter as Date.now() lead
// to random failures because of colliding IDs.
return "panel-" + outerID + "-" + (++this._uniquePanelIDCounter);
},
destroy() {
Services.obs.removeObserver(this, "contextual-identity-updated");
- CustomizableUI.removeListener(this);
-
for (let tab of this.tabs) {
let browser = tab.linkedBrowser;
if (browser.registeredOpenURI) {
this._unifiedComplete.unregisterOpenPage(browser.registeredOpenURI,
browser.getAttribute("usercontextid") || 0);
delete browser.registeredOpenURI;
}
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -121,22 +121,27 @@
window.addEventListener("resize", this);
window.addEventListener("DOMContentLoaded", this);
Services.prefs.addObserver("privacy.userContext", this);
this.observe(null, "nsPref:changed", "privacy.userContext.enabled");
this._setPositionalAttributes();
+
+ CustomizableUI.addListener(this);
+ this._updateNewTabVisibility();
]]>
</constructor>
<destructor>
<![CDATA[
Services.prefs.removeObserver("privacy.userContext", this);
+
+ CustomizableUI.removeListener(this);
]]>
</destructor>
<field name="tabbox" readonly="true">
this.tabbrowser.tabbox;
</field>
<field name="contextMenu" readonly="true">
@@ -903,16 +908,67 @@
// If the tab's browser is lazy, we need to `_insertBrowser` in order
// to have a linkedPanel. This will also serve to bind the browser
// and make it ready to use when the tab is selected.
this.tabbrowser._insertBrowser(aTab);
return document.getElementById(aTab.linkedPanel);
]]>
</body>
</method>
+
+ <method name="_updateNewTabVisibility">
+ <body><![CDATA[
+ // Helper functions to help deal with customize mode wrapping some items
+ let wrap = n => n.parentNode.localName == "toolbarpaletteitem" ? n.parentNode : n;
+ let unwrap = n => n && n.localName == "toolbarpaletteitem" ? n.firstElementChild : n;
+
+ let sib = this;
+ do {
+ sib = unwrap(wrap(sib).nextElementSibling);
+ } while (sib && sib.hidden);
+
+ const kAttr = "hasadjacentnewtabbutton";
+ if (sib && sib.id == "new-tab-button") {
+ this.setAttribute(kAttr, "true");
+ } else {
+ this.removeAttribute(kAttr);
+ }
+ ]]></body>
+ </method>
+
+ <method name="onWidgetAfterDOMChange">
+ <parameter name="aNode"/>
+ <parameter name="aNextNode"/>
+ <parameter name="aContainer"/>
+ <body><![CDATA[
+ if (aContainer.ownerDocument == document &&
+ aContainer.id == "TabsToolbar") {
+ this._updateNewTabVisibility();
+ }
+ ]]></body>
+ </method>
+
+ <method name="onAreaNodeRegistered">
+ <parameter name="aArea"/>
+ <parameter name="aContainer"/>
+ <body><![CDATA[
+ if (aContainer.ownerDocument == document &&
+ aArea == "TabsToolbar") {
+ this._updateNewTabVisibility();
+ }
+ ]]></body>
+ </method>
+
+ <method name="onAreaReset">
+ <parameter name="aArea"/>
+ <parameter name="aContainer"/>
+ <body><![CDATA[
+ this.onAreaNodeRegistered(aArea, aContainer);
+ ]]></body>
+ </method>
</implementation>
<handlers>
<handler event="TabSelect" action="this._handleTabSelect();"/>
<handler event="transitionend"><![CDATA[
if (event.propertyName != "max-width")
return;