Bug 824480 - Replace |tab == gBrowser.selectedTab| with tab.selected. r=dao
authorithinc <ithinc@sohu.com>
Tue, 25 Dec 2012 00:08:22 +0800
changeset 117021 a41996c283ce218fce768ab278269eb7edb2aeff
parent 117020 88a218a4b5bfaaf9cc02dd2d29ea06d66f0610a9
child 117022 54e72e8bbac4812cce6d4dac4c035524d2abb4ab
push id24079
push userryanvm@gmail.com
push dateWed, 26 Dec 2012 12:59:56 +0000
treeherdermozilla-central@f5ed2691d901 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao
bugs824480
milestone20.0a1
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 824480 - Replace |tab == gBrowser.selectedTab| with tab.selected. r=dao
browser/base/content/browser-tabPreviews.js
browser/base/content/tabbrowser.xml
browser/base/content/test/browser_bug623155.js
browser/base/content/test/browser_ctrlTab.js
browser/components/sessionstore/test/browser_586068-apptabs.js
browser/components/sessionstore/test/browser_586068-apptabs_ondemand.js
browser/components/tabview/groupitems.js
browser/components/tabview/tabitems.js
browser/components/tabview/test/browser_tabview_exit_button.js
browser/components/tabview/ui.js
browser/modules/test/browser_taskbar_preview.js
--- a/browser/base/content/browser-tabPreviews.js
+++ b/browser/base/content/browser-tabPreviews.js
@@ -443,17 +443,17 @@ var ctrlTab = {
             this.advanceFocus(!event.shiftKey);
           } else if (!event.shiftKey) {
             event.preventDefault();
             event.stopPropagation();
             let tabs = gBrowser.visibleTabs;
             if (tabs.length > 2) {
               this.open();
             } else if (tabs.length == 2) {
-              let index = gBrowser.selectedTab == tabs[0] ? 1 : 0;
+              let index = tabs[0].selected ? 1 : 0;
               gBrowser.selectedTab = tabs[index];
             }
           }
         }
         break;
       default:
         if (isOpen && event.ctrlKey) {
           if (event.keyCode == event.DOM_VK_DELETE) {
@@ -483,17 +483,17 @@ var ctrlTab = {
     this.updatePreviews();
 
     if (this.selected.hidden)
       this.advanceFocus(false);
     if (this.selected == this.showAllButton)
       this.advanceFocus(false);
 
     // If the current tab is removed, another tab can steal our focus.
-    if (aTab == gBrowser.selectedTab && this.panel.state == "open") {
+    if (aTab.selected && this.panel.state == "open") {
       setTimeout(function (selected) {
         selected.focus();
       }, 0, this.selected);
     }
   },
 
   handleEvent: function ctrlTab_handleEvent(event) {
     switch (event.type) {
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -846,21 +846,21 @@
               TelemetryStopwatch.start("FX_TAB_SWITCH_UPDATE_MS");
               window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils)
                                                              .beginTabSwitch();
             }
 
             var oldTab = this.mCurrentTab;
 
             // Preview mode should not reset the owner
-            if (!this._previewMode && oldTab != this.selectedTab)
+            if (!this._previewMode && !oldTab.selected)
               oldTab.owner = null;
 
             if (this._lastRelatedTab) {
-              if (this._lastRelatedTab != this.selectedTab)
+              if (!this._lastRelatedTab.selected)
                 this._lastRelatedTab.owner = null;
               this._lastRelatedTab = null;
             }
 
             var oldBrowser = this.mCurrentBrowser;
             if (oldBrowser) {
               oldBrowser.setAttribute("type", "content-targetable");
               oldBrowser.docShellIsActive = false;
@@ -952,18 +952,17 @@
               this.mIsBusy = false;
               this._callProgressListeners(null, "onStateChange",
                                           [webProgress, null,
                                            nsIWebProgressListener.STATE_STOP |
                                            nsIWebProgressListener.STATE_IS_NETWORK, 0],
                                           true, false);
             }
 
-            if (this.mCurrentTab.selected)
-              this._setCloseKeyState(!this.mCurrentTab.pinned);
+            this._setCloseKeyState(!this.mCurrentTab.pinned);
 
             // TabSelect events are suppressed during preview mode to avoid confusing extensions and other bits of code
             // that might rely upon the other changes suppressed.
             // Focus is suppressed in the event that the main browser window is minimized - focusing a tab would restore the window
             if (!this._previewMode) {
               // We've selected the new tab, so go ahead and notify listeners.
               let event = document.createEvent("Events");
               event.initEvent("TabSelect", true, false);
@@ -1820,17 +1819,17 @@
           ]]>
         </body>
       </method>
 
       <method name="_blurTab">
         <parameter name="aTab"/>
         <body>
           <![CDATA[
-            if (this.mCurrentTab != aTab)
+            if (!aTab.selected)
               return;
 
             if (aTab.owner &&
                 !aTab.owner.hidden &&
                 !aTab.owner.closing &&
                 Services.prefs.getBoolPref("browser.tabs.selectOwnerOnClose")) {
               this.selectedTab = aTab.owner;
               return;
@@ -1870,26 +1869,26 @@
         <body>
           <![CDATA[
             // The browser must be standalone.
             if (aBrowser.getTabBrowser())
               throw Cr.NS_ERROR_INVALID_ARG;
 
             // The tab is definitely not loading.
             aNewTab.removeAttribute("busy");
-            if (aNewTab == this.selectedTab) {
+            if (aNewTab.selected) {
               this.mIsBusy = false;
             }
 
             this._swapBrowserDocShells(aNewTab, aBrowser);
 
             // Update the new tab's title.
             this.setTabTitle(aNewTab);
 
-            if (aNewTab == this.selectedTab) {
+            if (aNewTab.selected) {
               this.updateCurrentBrowser(true);
             }
           ]]>
         </body>
       </method>
 
       <method name="swapBrowsersAndCloseOther">
         <parameter name="aOurTab"/>
@@ -1918,33 +1917,33 @@
             let ourBrowser = this.getBrowserForTab(aOurTab);
             let otherBrowser = aOtherTab.linkedBrowser;
             if (!ourBrowser.mIconURL && otherBrowser.mIconURL)
               this.setIcon(aOurTab, otherBrowser.mIconURL);
             var isBusy = aOtherTab.hasAttribute("busy");
             if (isBusy) {
               aOurTab.setAttribute("busy", "true");
               this._tabAttrModified(aOurTab);
-              if (aOurTab == this.selectedTab)
+              if (aOurTab.selected)
                 this.mIsBusy = true;
             }
 
             this._swapBrowserDocShells(aOurTab, otherBrowser);
 
             // Finish tearing down the tab that's going away.
             remoteBrowser._endRemoveTab(aOtherTab);
 
             if (isBusy)
               this.setTabTitleLoading(aOurTab);
             else
               this.setTabTitle(aOurTab);
 
             // If the tab was already selected (this happpens in the scenario
             // of replaceTabWithWindow), notify onLocationChange, etc.
-            if (aOurTab == this.selectedTab)
+            if (aOurTab.selected)
               this.updateCurrentBrowser(true);
           ]]>
         </body>
       </method>
 
       <method name="_swapBrowserDocShells">
         <parameter name="aOurTab"/>
         <parameter name="aOtherBrowser"/>
--- a/browser/base/content/test/browser_bug623155.js
+++ b/browser/base/content/test/browser_bug623155.js
@@ -77,32 +77,32 @@ var gWebProgressListener = {
 
   onLocationChange: function(aWebProgress, aRequest, aLocation, aFlags) {
     if (!aRequest) {
       // This is bug 673752, or maybe initial "about:blank".
       return;
     }
 
     ok(gNewTab, "There is a new tab.");
-    ok(isRedirectedURI(aLocation), 
+    ok(isRedirectedURI(aLocation),
        "onLocationChange catches only redirected URI.");
 
     if (aLocation.ref == "BG") {
       // This is background tab's request.
       isnot(gNewTab, gBrowser.selectedTab, "This is a background tab.");
     } else if (aLocation.ref == "FG") {
       // This is foreground tab's request.
       is(gNewTab, gBrowser.selectedTab, "This is a foreground tab.");
     }
     else {
       // We shonuld not reach here.
       ok(false, "This URI hash is not expected:" + aLocation.ref);
     }
 
-    let isSelectedTab = (gNewTab == gBrowser.selectedTab);
+    let isSelectedTab = gNewTab.selected;
     setTimeout(delayed, 0, isSelectedTab);
   }
 };
 
 function delayed(aIsSelectedTab) {
   // Switch tab and confirm URL bar.
   if (!aIsSelectedTab) {
     gBrowser.selectedTab = gNewTab;
--- a/browser/base/content/test/browser_ctrlTab.js
+++ b/browser/base/content/test/browser_ctrlTab.js
@@ -54,17 +54,17 @@ function test() {
     pressCtrlTab();
     EventUtils.synthesizeKey("w", { ctrlKey: true });
     ok(!tabToRemove.parentNode,
        "Ctrl+Tab*2 -> Ctrl+W removes the second most recently selected tab");
 
     pressCtrlTab(true);
     pressCtrlTab(true);
     releaseCtrl();
-    ok(gBrowser.selectedTab == selectedTab,
+    ok(selectedTab.selected,
        "Ctrl+Tab*2 -> Ctrl+W -> Ctrl+Shift+Tab*2 keeps the selected tab");
   }
   gBrowser.removeTab(gBrowser.tabContainer.lastChild);
   checkTabs(2);
 
   ctrlTabTest([1], 1, 0);
 
   gBrowser.removeTab(gBrowser.tabContainer.lastChild);
--- a/browser/components/sessionstore/test/browser_586068-apptabs.js
+++ b/browser/components/sessionstore/test/browser_586068-apptabs.js
@@ -33,17 +33,17 @@ function test() {
 
     // get the tab
     let tab;
     for (let i = 0; i < window.gBrowser.tabs.length; i++) {
       if (!tab && window.gBrowser.tabs[i].linkedBrowser == aBrowser)
         tab = window.gBrowser.tabs[i];
     }
 
-    ok(tab.pinned || gBrowser.selectedTab == tab,
+    ok(tab.pinned || tab.selected,
        "load came from pinned or selected tab");
 
     // We should get 4 loads: 3 app tabs + 1 normal selected tab
     if (loadCount < 4)
       return;
 
     gProgressListener.unsetCallback();
     executeSoon(function () {
--- a/browser/components/sessionstore/test/browser_586068-apptabs_ondemand.js
+++ b/browser/components/sessionstore/test/browser_586068-apptabs_ondemand.js
@@ -32,17 +32,17 @@ function test() {
     // get the tab
     let tab;
     for (let i = 0; i < window.gBrowser.tabs.length; i++) {
       if (!tab && window.gBrowser.tabs[i].linkedBrowser == aBrowser)
         tab = window.gBrowser.tabs[i];
     }
 
     // Check that the load only comes from the selected tab.
-    ok(gBrowser.selectedTab == tab, "load came from selected tab");
+    ok(tab.selected, "load came from selected tab");
     is(aNeedRestore, 6, "six tabs left to restore");
     is(aRestoring, 1, "one tab is restoring");
     is(aRestored, 0, "no tabs have been restored, yet");
 
     gProgressListener.unsetCallback();
     executeSoon(function () {
       waitForBrowserState(JSON.parse(stateBackup), finish);
     });
--- a/browser/components/tabview/groupitems.js
+++ b/browser/components/tabview/groupitems.js
@@ -999,17 +999,17 @@ GroupItem.prototype = Utils.extend(new I
         if (typeof item.setResizable == 'function')
           item.setResizable(false, options.immediately);
 
         if (item == UI.getActiveTab() || !this._activeTab)
           this.setActiveTab(item);
 
         // if it matches the selected tab or no active tab and the browser
         // tab is hidden, the active group item would be set.
-        if (item.tab == gBrowser.selectedTab ||
+        if (item.tab.selected ||
             (!GroupItems.getActiveGroupItem() && !item.tab.hidden))
           UI.setActive(this);
       }
 
       if (!options.dontArrange)
         this.arrange({animate: !options.immediately});
 
       this._unfreezeItemSize({dontArrange: true});
@@ -2537,17 +2537,17 @@ let GroupItems = {
     if (tab._tabViewTabItem.parent && tab._tabViewTabItem.parent.id == groupItemId)
       return;
 
     let shouldUpdateTabBar = false;
     let shouldShowTabView = false;
     let groupItem;
 
     // switch to the appropriate tab first.
-    if (gBrowser.selectedTab == tab) {
+    if (tab.selected) {
       if (gBrowser.visibleTabs.length > 1) {
         gBrowser._blurTab(tab);
         shouldUpdateTabBar = true;
       } else {
         shouldShowTabView = true;
       }
     } else {
       shouldUpdateTabBar = true
--- a/browser/components/tabview/tabitems.js
+++ b/browser/components/tabview/tabitems.js
@@ -272,17 +272,17 @@ TabItem.prototype = Utils.extend(new Ite
         groupItem.add(this, {immediately: true});
 
         // restore the active tab for each group between browser sessions
         if (tabData.active)
           groupItem.setActiveTab(this);
 
         // if it matches the selected tab or no active tab and the browser
         // tab is hidden, the active group item would be set.
-        if (this.tab == gBrowser.selectedTab ||
+        if (this.tab.selected ||
             (!GroupItems.getActiveGroupItem() && !this.tab.hidden))
           UI.setActive(this.parent);
       }
     } else {
       if (options && options.groupItemId)
         groupItem = GroupItems.groupItem(options.groupItemId);
 
       if (groupItem) {
@@ -534,21 +534,21 @@ TabItem.prototype = Utils.extend(new Ite
     let tab = this.tab;
 
     function onZoomDone() {
       $canvas.css({ 'transform': null });
       $tabEl.removeClass("front");
 
       UI.goToTab(tab);
 
-      // tab might not be selected because hideTabView() is invoked after 
+      // tab might not be selected because hideTabView() is invoked after
       // UI.goToTab() so we need to setup everything for the gBrowser.selectedTab
-      if (tab != gBrowser.selectedTab) {
+      if (!tab.selected) {
         UI.onTabSelect(gBrowser.selectedTab);
-      } else { 
+      } else {
         if (isNewBlankTab)
           gWindow.gURLBar.focus();
       }
       if (self.parent && self.parent.expanded)
         self.parent.collapse();
 
       self._sendToSubscribers("zoomedIn");
     }
--- a/browser/components/tabview/test/browser_tabview_exit_button.js
+++ b/browser/components/tabview/test/browser_tabview_exit_button.js
@@ -29,37 +29,37 @@ function onTabViewLoadedAndShown() {
   ok(!originalTab.pinned, "the original tab is not an app tab");
 
   // create an app tab
   appTab = gBrowser.loadOneTab("about:blank");
   is(gBrowser.tabs.length, 2, "we now have two tabs");
   gBrowser.pinTab(appTab);
 
   // verify that the normal tab is selected
-  ok(gBrowser.selectedTab == originalTab, "the normal tab is selected");
+  ok(originalTab.selected, "the normal tab is selected");
 
   // hit the exit button for the first time
   exitButton = contentWindow.document.getElementById("exit-button");
   ok(exitButton, "Exit button exists");
 
   window.addEventListener("tabviewhidden", onTabViewHiddenForNormalTab, false);
   EventUtils.sendMouseEvent({ type: "click" }, exitButton, contentWindow);
 }
 
 // ----------
 function onTabViewHiddenForNormalTab() {
   window.removeEventListener("tabviewhidden", onTabViewHiddenForNormalTab, false);
   ok(!TabView.isVisible(), "Tab View is not visible");
 
   // verify that the normal tab is still selected
-  ok(gBrowser.selectedTab == originalTab, "the normal tab is still selected");
+  ok(originalTab.selected, "the normal tab is still selected");
 
   // select the app tab
   gBrowser.selectedTab = appTab;
-  ok(gBrowser.selectedTab == appTab, "the app tab is now selected");
+  ok(appTab.selected, "the app tab is now selected");
 
   // go back to tabview
   window.addEventListener("tabviewshown", onTabViewShown, false);
   TabView.toggle();
 }
 
 // ----------
 function onTabViewShown() {
@@ -72,21 +72,21 @@ function onTabViewShown() {
 }
 
 // ----------
 function onTabViewHiddenForAppTab() {
   window.removeEventListener("tabviewhidden", onTabViewHiddenForAppTab, false);
   ok(!TabView.isVisible(), "Tab View is not visible");
 
   // verify that the app tab is still selected
-  ok(gBrowser.selectedTab == appTab, "the app tab is still selected");
+  ok(appTab.selected, "the app tab is still selected");
 
   // clean up
-  gBrowser.selectedTab = originalTab; 
+  gBrowser.selectedTab = originalTab;
   gBrowser.removeTab(appTab);
 
   is(gBrowser.tabs.length, 1, "we finish with one tab");
-  ok(gBrowser.selectedTab == originalTab,
+  ok(originalTab.selected,
       "we finish with the normal tab selected");
   ok(!TabView.isVisible(), "we finish with Tab View not visible");
 
   finish();
 }
--- a/browser/components/tabview/ui.js
+++ b/browser/components/tabview/ui.js
@@ -818,17 +818,17 @@ let UI = {
       AllTabs.unregister(name, this._eventListeners[name]);
   },
 
   // ----------
   // Function: goToTab
   // Selects the given xul:tab in the browser.
   goToTab: function UI_goToTab(xulTab) {
     // If it's not focused, the onFocus listener would handle it.
-    if (gBrowser.selectedTab == xulTab)
+    if (xulTab.selected)
       this.onTabSelect(xulTab);
     else
       gBrowser.selectedTab = xulTab;
   },
 
   // ----------
   // Function: onTabSelect
   // Called when the user switches from one tab to another outside of the TabView UI.
@@ -931,17 +931,17 @@ let UI = {
       return;
 
     let tab = gBrowser.tabs[index];
 
     // When TabView is visible, we need to call onTabSelect to make sure that
     // TabView is hidden and that the correct group is activated. When a modal
     // dialog is shown for currently selected tab the onTabSelect event handler
     // is not called, so we need to do it.
-    if (gBrowser.selectedTab == tab && this._currentTab == tab)
+    if (tab.selected && this._currentTab == tab)
       this.onTabSelect(tab);
   },
 
   // ----------
   // Function: setReorderTabsOnHide
   // Sets the groupItem which the tab items' tabs should be re-ordered when
   // switching to the main browser UI.
   // Parameters:
--- a/browser/modules/test/browser_taskbar_preview.js
+++ b/browser/modules/test/browser_taskbar_preview.js
@@ -51,31 +51,31 @@ function test() {
   });
 
   let currentSelectedTab = gBrowser.selectedTab;
   for each (let idx in [1,2,3,4]) {
     let preview = getPreviewForTab(gBrowser.tabs[0]);
     let canvas = createThumbnailSurface(preview);
     let ctx = canvas.getContext("2d");
     preview.controller.drawThumbnail(ctx, canvas.width, canvas.height);
-    ok(currentSelectedTab == gBrowser.selectedTab, "Drawing thumbnail does not change selection");
+    ok(currentSelectedTab.selected, "Drawing thumbnail does not change selection");
     canvas = getCanvas(preview.controller.width, preview.controller.height);
     ctx = canvas.getContext("2d");
     preview.controller.drawPreview(ctx);
-    ok(currentSelectedTab == gBrowser.selectedTab, "Drawing preview does not change selection");
+    ok(currentSelectedTab.selected, "Drawing preview does not change selection");
   }
 
   // Close #4
   getPreviewForTab(gBrowser.selectedTab).controller.onClose();
   checkPreviews(3, "Expected number of previews after closing selected tab via controller");
   ok(gBrowser.tabs.length == 3, "Successfully closed a tab");
 
   // Select #1
   ok(getPreviewForTab(gBrowser.tabs[0]).controller.onActivate(), "Activation was accepted");
-  ok(gBrowser.tabs[0] == gBrowser.selectedTab, "Correct tab was selected");
+  ok(gBrowser.tabs[0].selected, "Correct tab was selected");
   checkSelectedTab();
 
   // Remove #3 (non active)
   gBrowser.removeTab(gBrowser.tabContainer.lastChild);
   checkPreviews(2, "Expected number of previews after closing unselected via browser");
 
   // Remove #1 (active)
   gBrowser.removeTab(gBrowser.tabContainer.firstChild);
@@ -108,17 +108,17 @@ function test() {
 
   function getPreviewForTab(tab)
     window.gTaskbarTabGroup.previewFromTab(tab);
 
   function checkSelectedTab()
     getPreviewForTab(gBrowser.selectedTab).active;
 
   function isTabSelected(idx)
-    gBrowser.selectedTab == gBrowser.tabs[idx];
+    gBrowser.tabs[idx].selected;
 
   function createThumbnailSurface(p) {
     let thumbnailWidth = 200,
         thumbnailHeight = 120;
     let ratio = p.controller.thumbnailAspectRatio;
 
     if (thumbnailWidth/thumbnailHeight > ratio)
       thumbnailWidth = thumbnailHeight * ratio;