Bug 388880 - Don't initialize the bookmarks toolbar item when it's hidden. r=gavin
authorDão Gottwald <dao@mozilla.com>
Fri, 16 Jul 2010 21:03:04 +0200
changeset 47830 7c44f05a46aed5ba89dd231a715875ead6127773
parent 47829 06068c84b575f25f11169f5cd2d42ea10c65a92b
child 47831 9c53adea30c677ca57b54e96c16148981229b874
push id14434
push userdgottwald@mozilla.com
push dateFri, 16 Jul 2010 19:15:49 +0000
treeherderautoland@8e8042431c86 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgavin
bugs388880
milestone2.0b2pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 388880 - Don't initialize the bookmarks toolbar item when it's hidden. r=gavin
browser/base/content/browser-places.js
browser/base/content/browser.js
browser/components/places/tests/browser/browser_drag_bookmarks_on_toolbar.js
browser/components/places/tests/browser/browser_views_liveupdate.js
--- a/browser/base/content/browser-places.js
+++ b/browser/base/content/browser-places.js
@@ -1068,18 +1068,28 @@ var PlacesStarButton = {
 let PlacesToolbarHelper = {
   _place: "place:folder=TOOLBAR",
 
   get _viewElt() {
     return document.getElementById("PlacesToolbar");
   },
 
   init: function PTH_init() {
-    if (this._viewElt)
-      new PlacesToolbar(this._place);
+    let viewElt = this._viewElt;
+    if (!viewElt || viewElt._placesView)
+      return;
+
+    // If the bookmarks toolbar item is hidden because the parent toolbar is
+    // collapsed or hidden (i.e. in a popup), spare the initialization.
+    let toolbar = viewElt.parentNode.parentNode;
+    if (toolbar.collapsed ||
+        getComputedStyle(toolbar, "").display == "none")
+      return;
+
+    new PlacesToolbar(this._place);
   },
 
   customizeStart: function PTH_customizeStart() {
     let viewElt = this._viewElt;
     if (viewElt && viewElt._placesView)
       viewElt._placesView.uninit();
   },
 
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -4669,23 +4669,28 @@ function onViewToolbarsPopupShowing(aEve
     }
     toolbar = toolbar.nextSibling;
   }
 }
 
 function onViewToolbarCommand(aEvent) {
   var index = aEvent.originalTarget.getAttribute("toolbarindex");
   var toolbar = gNavToolbox.childNodes[index];
+  var visible = aEvent.originalTarget.getAttribute("checked") == "true";
+  setToolbarVisibility(toolbar, visible);
+}
+
+function setToolbarVisibility(toolbar, visible) {
   var hidingAttribute = toolbar.getAttribute("type") == "menubar" ?
                         "autohide" : "collapsed";
 
-  toolbar.setAttribute(hidingAttribute,
-                       aEvent.originalTarget.getAttribute("checked") != "true");
+  toolbar.setAttribute(hidingAttribute, !visible);
   document.persist(toolbar.id, hidingAttribute);
 
+  PlacesToolbarHelper.init();
   BookmarksMenuButton.updatePosition();
 
 #ifdef MENUBAR_CAN_AUTOHIDE
   updateAppButtonDisplay();
 #endif
 }
 
 var TabsOnTop = {
--- a/browser/components/places/tests/browser/browser_drag_bookmarks_on_toolbar.js
+++ b/browser/components/places/tests/browser/browser_drag_bookmarks_on_toolbar.js
@@ -242,25 +242,25 @@ function nextTest() {
     info("Start of test: " + test.desc);
     test.run();
 
     setTimeout(nextTest, 0);
   }
   else {
     // Collapse the personal toolbar if needed.
     if (wasCollapsed)
-      toolbar.collapsed = true;
+      setToolbarVisibility(toolbar, false);
     finish();
   }
 }
 
 let toolbar = document.getElementById("PersonalToolbar");
 let wasCollapsed = toolbar.collapsed;
 
 function test() {
   // Uncollapse the personal toolbar if needed.
   if (wasCollapsed)
-    toolbar.collapsed = false;
+    setToolbarVisibility(toolbar, true);
 
   waitForExplicitFinish();
   nextTest();
 }
 
--- a/browser/components/places/tests/browser/browser_views_liveupdate.js
+++ b/browser/components/places/tests/browser/browser_views_liveupdate.js
@@ -43,17 +43,17 @@ const Cc = Components.classes;
 const Ci = Components.interfaces;
 
 let toolbar = document.getElementById("PersonalToolbar");
 let wasCollapsed = toolbar.collapsed;
 
 function test() {
   // Uncollapse the personal toolbar if needed.
   if (wasCollapsed)
-    toolbar.collapsed = false;
+    setToolbarVisibility(toolbar, true);
 
   waitForExplicitFinish();
 
   // Sanity checks.
   ok(PlacesUtils, "PlacesUtils in context");
   ok(PlacesUIUtils, "PlacesUIUtils in context");
 
   // Open bookmarks menu.
@@ -199,17 +199,17 @@ function startTest() {
  * Restores browser state and calls finish.
  */
 function finishTest() {
   // Close bookmarks sidebar.
   toggleSidebar("viewBookmarksSidebar", false);
 
   // Collapse the personal toolbar if needed.
   if (wasCollapsed)
-    toolbar.collapsed = true;
+    setToolbarVisibility(toolbar, false);
 
   finish();
 }
 
 /**
  * The observer is where magic happens, for every change we do it will look for
  * nodes positions in the affected views.
  */