B2G/gecko/browser/components/tabview/ui.js
// Adds handlers to handle tab actions.
Adds handlers to handle tab actions.
Adds handlers to handle tab actions .
function UI__addTabActionHandlers() {
    var self = this;
    function handleSSWindowStateBusy() {
      self.storageBusy();
    }
    function handleSSWindowStateReady() {
      self.storageReady();
    }
    gWindow.addEventListener("SSWindowStateBusy", handleSSWindowStateBusy, false);
    gWindow.addEventListener("SSWindowStateReady", handleSSWindowStateReady, false);
    this._cleanupFunctions.push(function() {
      gWindow.removeEventListener("SSWindowStateBusy", handleSSWindowStateBusy, false);
      gWindow.removeEventListener("SSWindowStateReady", handleSSWindowStateReady, false);
    });
    function pbObserver(subject, topic, data) {
      if (topic == "private-browsing") {
        if (data == "enter") {
          self._privateBrowsing.wasInTabView = self.isTabViewVisible();
          if (self.isTabViewVisible())
            self.goToTab(gBrowser.selectedTab);
        }
      } else if (topic == "private-browsing-change-granted") {
        if (data == "enter" || data == "exit") {
          Search.hide();
          self._privateBrowsing.transitionMode = data;
        }
      } else if (topic == "private-browsing-transition-complete") {
        if (self._privateBrowsing.transitionMode == "exit" &&
            self._privateBrowsing.wasInTabView)
          self.showTabView(false);
        self._privateBrowsing.transitionMode = "";
      }
    }
    Services.obs.addObserver(pbObserver, "private-browsing", false);
    Services.obs.addObserver(pbObserver, "private-browsing-change-granted", false);
    Services.obs.addObserver(pbObserver, "private-browsing-transition-complete", false);
    this._cleanupFunctions.push(function() {
      Services.obs.removeObserver(pbObserver, "private-browsing");
      Services.obs.removeObserver(pbObserver, "private-browsing-change-granted");
      Services.obs.removeObserver(pbObserver, "private-browsing-transition-complete");
    });
    this._eventListeners.open = function (event) {
      let tab = event.target;
      if (tab.pinned)
        GroupItems.addAppTab(tab);
      else if (self.isTabViewVisible() && !self._storageBusyCount)
        self._lastOpenedTab = tab;
    };
    this._eventListeners.close = function (event) {
      let tab = event.target;
      if (tab.pinned)
        GroupItems.removeAppTab(tab);
      if (self.isTabViewVisible()) {
        if (self._currentTab == tab)
          self._closedSelectedTabInTabView = true;
      } else {
        if (self._storageBusy)
          return;
        if (gBrowser.tabs.length > 1) {
          for (let a = 0; a < gBrowser._numPinnedTabs; a++) {
            if (Utils.isValidXULTab(gBrowser.tabs[a]))
              return;
          }
          let groupItem = GroupItems.getActiveGroupItem();
          let closingLastOfGroup = (groupItem && 
              groupItem._children.length == 1 && 
              groupItem._children[0].tab == tab);
          let tabItem = tab && tab._tabViewTabItem;
          let closingBlankTabAfterRestore =
            (tabItem && tabItem.isRemovedAfterRestore);
          if (closingLastOfGroup && !closingBlankTabAfterRestore) {
            self._closedLastVisibleTab = true;
            self.showTabView();
          }
        }
      }
    };
    this._eventListeners.move = function (event) {
      let tab = event.target;
      if (GroupItems.groupItems.length > 0) {
        if (tab.pinned) {
          if (gBrowser._numPinnedTabs > 1)
            GroupItems.arrangeAppTab(tab);
        } else {
          let activeGroupItem = GroupItems.getActiveGroupItem();
          if (activeGroupItem)
            self.setReorderTabItemsOnShow(activeGroupItem);
        }
      }
    };
    this._eventListeners.select = function (event) {
      self.onTabSelect(event.target);
    };
    this._eventListeners.pinned = function (event) {
      let tab = event.target;
      TabItems.handleTabPin(tab);
      GroupItems.addAppTab(tab);
    };
    this._eventListeners.unpinned = function (event) {
      let tab = event.target;
      TabItems.handleTabUnpin(tab);
      GroupItems.removeAppTab(tab);
      let groupItem = tab._tabViewTabItem.parent;
      if (groupItem)
        self.setReorderTabItemsOnShow(groupItem);
    };
    for (let name in this._eventListeners)
      AllTabs.register(name, this._eventListeners[name]);
  }
function UI__addTabActionHandlers ( ) { var self = this ; function handleSSWindowStateBusy ( ) { self . storageBusy ( ) ; } function handleSSWindowStateReady ( ) { self . storageReady ( ) ; } gWindow . addEventListener ( "SSWindowStateBusy" , handleSSWindowStateBusy , false ) ; gWindow . addEventListener ( "SSWindowStateReady" , handleSSWindowStateReady , false ) ; this . _cleanupFunctions . push ( function ( ) { gWindow . removeEventListener ( "SSWindowStateBusy" , handleSSWindowStateBusy , false ) ; gWindow . removeEventListener ( "SSWindowStateReady" , handleSSWindowStateReady , false ) ; } ) ; function pbObserver ( subject , topic , data ) { if ( topic == "private-browsing" ) { if ( data == "enter" ) { self . _privateBrowsing . wasInTabView = self . isTabViewVisible ( ) ; if ( self . isTabViewVisible ( ) ) self . goToTab ( gBrowser . selectedTab ) ; } } else if ( topic == "private-browsing-change-granted" ) { if ( data == "enter" || data == "exit" ) { Search . hide ( ) ; self . _privateBrowsing . transitionMode = data ; } } else if ( topic == "private-browsing-transition-complete" ) { if ( self . _privateBrowsing . transitionMode == "exit" && self . _privateBrowsing . wasInTabView ) self . showTabView ( false ) ; self . _privateBrowsing . transitionMode = "" ; } } Services . obs . addObserver ( pbObserver , "private-browsing" , false ) ; Services . obs . addObserver ( pbObserver , "private-browsing-change-granted" , false ) ; Services . obs . addObserver ( pbObserver , "private-browsing-transition-complete" , false ) ; this . _cleanupFunctions . push ( function ( ) { Services . obs . removeObserver ( pbObserver , "private-browsing" ) ; Services . obs . removeObserver ( pbObserver , "private-browsing-change-granted" ) ; Services . obs . removeObserver ( pbObserver , "private-browsing-transition-complete" ) ; } ) ; this . _eventListeners . open = function ( event ) { let tab = event . target ; if ( tab . pinned ) GroupItems . addAppTab ( tab ) ; else if ( self . isTabViewVisible ( ) && ! self . _storageBusyCount ) self . _lastOpenedTab = tab ; } ; this . _eventListeners . close = function ( event ) { let tab = event . target ; if ( tab . pinned ) GroupItems . removeAppTab ( tab ) ; if ( self . isTabViewVisible ( ) ) { if ( self . _currentTab == tab ) self . _closedSelectedTabInTabView = true ; } else { if ( self . _storageBusy ) return ; if ( gBrowser . tabs . length > 1 ) { for ( let a = 0 ; a < gBrowser . _numPinnedTabs ; a ++ ) { if ( Utils . isValidXULTab ( gBrowser . tabs [ a ] ) ) return ; } let groupItem = GroupItems . getActiveGroupItem ( ) ; let closingLastOfGroup = ( groupItem && groupItem . _children . length == 1 && groupItem . _children [ 0 ] . tab == tab ) ; let tabItem = tab && tab . _tabViewTabItem ; let closingBlankTabAfterRestore = ( tabItem && tabItem . isRemovedAfterRestore ) ; if ( closingLastOfGroup && ! closingBlankTabAfterRestore ) { self . _closedLastVisibleTab = true ; self . showTabView ( ) ; } } } } ; this . _eventListeners . move = function ( event ) { let tab = event . target ; if ( GroupItems . groupItems . length > 0 ) { if ( tab . pinned ) { if ( gBrowser . _numPinnedTabs > 1 ) GroupItems . arrangeAppTab ( tab ) ; } else { let activeGroupItem = GroupItems . getActiveGroupItem ( ) ; if ( activeGroupItem ) self . setReorderTabItemsOnShow ( activeGroupItem ) ; } } } ; this . _eventListeners . select = function ( event ) { self . onTabSelect ( event . target ) ; } ; this . _eventListeners . pinned = function ( event ) { let tab = event . target ; TabItems . handleTabPin ( tab ) ; GroupItems . addAppTab ( tab ) ; } ; this . _eventListeners . unpinned = function ( event ) { let tab = event . target ; TabItems . handleTabUnpin ( tab ) ; GroupItems . removeAppTab ( tab ) ; let groupItem = tab . _tabViewTabItem . parent ; if ( groupItem ) self . setReorderTabItemsOnShow ( groupItem ) ; } ; for ( let name in this . _eventListeners ) AllTabs . register ( name , this . _eventListeners [ name ] ) ; }
Adds handlers to handle tab actions.
Adds handlers to handle tab actions .
// session restore events // Private Browsing: // When transitioning to PB, we exit Panorama if necessary (making note of the // fact that we were there so we can return after PB) and make sure we // don't reenter Panorama due to all of the session restore tab // manipulation (which otherwise we might). When transitioning away from // PB, we reenter Panorama if we had been there directly before PB. // We could probably do this in private-browsing-change-granted, but // this seems like a nicer spot, right in the middle of the process. // If we are in Tab View, exit.  // We use .transitionMode here, as aData is empty. // TabOpen // if it's an app tab, add it to all the group items // TabClose // if it's an app tab, remove it from all the group items // just closed the selected tab in the TabView interface. // If we're currently in the process of entering private browsing, // we don't want to go to the Tab View UI.  // if not closing the last tab // Don't return to TabView if there are any app tabs // 1) Only go back to the TabView tab when there you close the last // tab of a groupItem. // 2) When a blank tab is active while restoring a closed tab the // blank tab gets removed. The active group is not closed as this is // where the restored tab goes. So do not show the TabView. // for the tab focus event to pick up. // TabMove // TabSelect // TabPinned // TabUnpinned // Actually register the above handlers