Bug 629665 - [regression] Tab bar covers full screen [r=mfinkle]
authorVivien Nicolas <21@vingtetun.org>
Mon, 07 Feb 2011 13:56:11 +0100
changeset 67351 968686c969dd0a5fb5fbe2c7bb9c09d18545dae3
parent 67350 b7c97a621c577cbb077a03c8ff91d7ebec590b4f
child 67352 1991ac5e680200abb2323cf86c3976d3e2cca8e0
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs629665
Bug 629665 - [regression] Tab bar covers full screen [r=mfinkle]
mobile/chrome/content/browser-ui.js
mobile/chrome/content/browser.js
mobile/chrome/content/tabs.xml
mobile/chrome/tests/browser_sidebars.js
--- a/mobile/chrome/content/browser-ui.js
+++ b/mobile/chrome/content/browser-ui.js
@@ -435,16 +435,17 @@ var BrowserUI = {
     this._edit.addEventListener("click", this, false);
     this._edit.addEventListener("mousedown", this, false);
 
     window.addEventListener("NavigationPanelShown", this, false);
     window.addEventListener("NavigationPanelHidden", this, false);
 
     Elements.tabs.addEventListener("TabSelect", this, true);
     Elements.tabs.addEventListener("TabOpen", this, true);
+    Elements.tabs.addEventListener("TabRemove", this, true);
 
     Elements.browsers.addEventListener("PanFinished", this, true);
 #if MOZ_PLATFORM_MAEMO == 6
     Elements.browsers.addEventListener("SizeChanged", this, true);
 #endif
 
     // listen content messages
     messageManager.addMessageListener("DOMLinkAdded", this);
@@ -838,29 +839,39 @@ var BrowserUI = {
 
   handleEvent: function handleEvent(aEvent) {
     switch (aEvent.type) {
       // Browser events
       case "TabSelect":
         this._tabSelect(aEvent);
         break;
       case "TabOpen":
+      case "TabRemove":
       {
         // Workaround to hide the tabstrip if it is partially visible
-        // See bug 524469
+        // See bug 524469 and bug 626660
         let [tabsVisibility,,,] = Browser.computeSidebarVisibility();
         if (tabsVisibility > 0.0 && tabsVisibility < 1.0)
           Browser.hideSidebars();
 
         break;
       }
       case "PanFinished":
-        let [tabsVisibility,,,] = Browser.computeSidebarVisibility();
-        if (tabsVisibility == 0.0)
-          document.getElementById("tabs").removeClosedTab();
+        let tabs = document.getElementById("tabs");
+        let [tabsVisibility,,oldLeftWidth, oldRightWidth] = Browser.computeSidebarVisibility();
+        if (tabsVisibility == 0.0 && tabs.hasClosedTab) {
+          let { x: x1, y: y1 } = Browser.getScrollboxPosition(Browser.controlsScrollboxScroller);
+          tabs.removeClosedTab();
+
+          let [,, leftWidth, rightWidth] = Browser.computeSidebarVisibility();
+          let delta = (oldLeftWidth - leftWidth) || (oldRightWidth - rightWidth);
+          x1 += (x1 == leftWidth) ? delta : -delta;
+          Browser.controlsScrollboxScroller.scrollTo(x1, 0);
+          Browser.tryFloatToolbar(0, 0);
+        }
         break;
       case "SizeChanged":
         this.sizeControls(ViewableAreaObserver.width, ViewableAreaObserver.height);
         break;
       // Window events
       case "keypress":
         if (aEvent.keyCode == aEvent.DOM_VK_ESCAPE)
           this.handleEscape(aEvent);
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -732,20 +732,25 @@ var Browser = {
         aTab.owner = null;
     });
 
     let event = document.createEvent("Events");
     event.initEvent("TabClose", true, false);
     tab.chromeTab.dispatchEvent(event);
     tab.browser.messageManager.sendAsyncMessage("Browser:TabClose");
 
+    let container = tab.chromeTab.parentNode;
     tab.destroy();
     this._tabs.splice(tabIndex, 1);
 
     this.selectedTab = nextTab;
+
+    event = document.createEvent("Events");
+    event.initEvent("TabRemove", true, false);
+    container.dispatchEvent(event);
   },
 
   get selectedTab() {
     return this._selectedTab;
   },
 
   set selectedTab(tab) {
     if (tab instanceof XULElement)
--- a/mobile/chrome/content/tabs.xml
+++ b/mobile/chrome/content/tabs.xml
@@ -103,18 +103,20 @@
   <binding id="tablist">
     <content>
       <xul:vbox class="tabs-list" anonid="tabs-children" flex="1"/>
       <xul:box class="tabs-list" anonid="tabs-undo"/>
     </content>
     <implementation>
       <field name="children">document.getAnonymousElementByAttribute(this, "anonid", "tabs-children");</field>
       <field name="_tabsUndo">document.getAnonymousElementByAttribute(this, "anonid", "tabs-undo");</field>
+      <field name="_selectedTab">null</field>
+
       <field name="_closedTab">null</field>
-      <field name="_selectedTab">null</field>
+      <property name="hasClosedTab" readonly="true" onget="return !!this._closedTab;"/>
 
       <property name="selectedTab" onget="return this._selectedTab;">
         <setter>
           <![CDATA[
             if (this._selectedTab)
               this._selectedTab.removeAttribute("selected");
 
             if (val)
@@ -184,18 +186,18 @@
 
       <method name="resize">
         <body>
           <![CDATA[
             let container = this.parentNode.getBoundingClientRect();
             let element   = this.children.getBoundingClientRect();
             let undo = this._tabsUndo.getBoundingClientRect();
             let lastChild = this.parentNode.lastChild.getBoundingClientRect();
-            
-            let height = window.innerHeight - element.top - (undo.bottom - undo.top) - (lastChild.top - element.bottom) - lastChild.height;
+
+            let height = window.innerHeight - element.top - (lastChild.top - element.bottom) - lastChild.height;
             this.children.style.height = height + "px";
 
             this._updateWidth();
           ]]>
         </body>
       </method>
 
       <field name="_columnsCount">0</field>
--- a/mobile/chrome/tests/browser_sidebars.js
+++ b/mobile/chrome/tests/browser_sidebars.js
@@ -165,12 +165,53 @@ gTests.push({
     let [,, leftWidth, rightWidth] = Browser.computeSidebarVisibility();
     Browser.controlsScrollboxScroller.scrollTo(leftWidth + rightWidth, 0);
     checkSidebars(0, 1);
     checkOnResize(gCurrentTest.onFinish);
   },
 
   onFinish: function() {
     Browser.hideSidebars();
+    BrowserUI.activePanel = null;
     runNextTest();
   }
 });
 
+gTests.push({
+  desc: "Testing horizontal positionning of the sidebars for multiple columns with an undo tab",
+
+  run: function() {
+    let tabs = document.getElementById("tabs");
+    ok(tabs._columnsCount > 1, "Tabs layout should be on multiple columns");
+
+    Elements.tabs.addEventListener("TabRemove", function() {
+      Elements.tabs.removeEventListener("TabRemove", arguments.callee, false);
+      setTimeout(gCurrentTest.onTabClose, 0);
+    }, false);
+
+    let lastTab = newTabs.pop().chromeTab;
+    lastTab._onClose();
+  },
+
+  onTabClose: function() {
+    checkSidebars(0, 0);
+    checkOnResize(gCurrentTest.checkLeftVisible);
+  },
+
+  checkLeftVisible: function() {
+    Browser.controlsScrollboxScroller.scrollTo(0, 0);
+    checkSidebars(1, 0);
+    checkOnResize(gCurrentTest.checkRightVisible);
+  },
+
+  checkRightVisible: function() {
+    let [,, leftWidth, rightWidth] = Browser.computeSidebarVisibility();
+    Browser.controlsScrollboxScroller.scrollTo(leftWidth + rightWidth, 0);
+    checkSidebars(0, 1);
+    checkOnResize(gCurrentTest.onFinish);
+  },
+
+  onFinish: function() {
+    Browser.hideSidebars();
+    runNextTest();
+  }
+});
+