B2G/gecko/browser/components/tabview/groupitems.js
// Helper routine for the constructor; adds various event handlers to the container.
Helper routine for the constructor; adds various event handlers to the container.
Helper routine for the constructor ; adds various event handlers to the container .
function GroupItem__addHandlers(container) {
    let self = this;
    let lastMouseDownTarget;
    container.mousedown(function(e) {
      let target = e.target;
      if (Utils.isLeftClick(e) &&
          self.$closeButton[0] != target &&
          self.$titlebar[0] != target &&
          self.$expander[0] != target &&
          !self.$titlebar.contains(target) &&
          !self.$appTabTray.contains(target)) {
        lastMouseDownTarget = target;
      } else {
        lastMouseDownTarget = null;
      }
    });
    container.mouseup(function(e) {
      let same = (e.target == lastMouseDownTarget);
      lastMouseDownTarget = null;
      if (same && !self.isDragging) {
        if (gBrowser.selectedTab.pinned &&
            UI.getActiveTab() != self.getActiveTab() &&
            self.getChildren().length > 0) {
          UI.setActive(self, { dontSetActiveTabInGroup: true });
          UI.goToTab(gBrowser.selectedTab);
        } else {
          let tabItem = self.getTopChild();
          if (tabItem)
            tabItem.zoomIn();
          else
            self.newTab();
        }
      }
    });
    let dropIndex = false;
    let dropSpaceTimer = null;
    this._dropSpaceActive = false;
    this.dropOptions.over = function GroupItem_dropOptions_over(event) {
      iQ(this.container).addClass("acceptsDrop");
    };
    this.dropOptions.move = function GroupItem_dropOptions_move(event) {
      let oldDropIndex = dropIndex;
      let dropPos = drag.info.item.getBounds().center();
      let options = {dropPos: dropPos,
                     addTab: self._dropSpaceActive && drag.info.item.parent != self,
                     oldDropIndex: oldDropIndex};
      let newDropIndex = self.arrange(options);
      if (newDropIndex !== oldDropIndex) {
        dropIndex = newDropIndex;
        if (this._dropSpaceActive)
          return;
        if (dropSpaceTimer) {
          clearTimeout(dropSpaceTimer);
          dropSpaceTimer = null;
        }
        dropSpaceTimer = setTimeout(function GroupItem_arrange_evaluateDropSpace() {
          if (dropIndex === newDropIndex) {
            self._dropSpaceActive = true;
            dropIndex = self.arrange({dropPos: dropPos,
                                      addTab: drag.info.item.parent != self,
                                      animate: true});
          }
          dropSpaceTimer = null;
        }, 250);
      }
    };
    this.dropOptions.drop = function GroupItem_dropOptions_drop(event) {
      iQ(this.container).removeClass("acceptsDrop");
      let options = {};
      if (this._dropSpaceActive)
        this._dropSpaceActive = false;
      if (dropSpaceTimer) {
        clearTimeout(dropSpaceTimer);
        dropSpaceTimer = null;
        let dropPos = drag.info.item.getBounds().center();
        dropIndex = self.arrange({dropPos: dropPos,
                                  addTab: drag.info.item.parent != self,
                                  animate: true});
      }
      if (dropIndex !== false)
        options = {index: dropIndex};
      this.add(drag.info.$el, options);
      UI.setActive(this);
      dropIndex = false;
    };
    this.dropOptions.out = function GroupItem_dropOptions_out(event) {
      dropIndex = false;
      if (this._dropSpaceActive)
        this._dropSpaceActive = false;
      if (dropSpaceTimer) {
        clearTimeout(dropSpaceTimer);
        dropSpaceTimer = null;
      }
      self.arrange();
      var groupItem = drag.info.item.parent;
      if (groupItem)
        groupItem.remove(drag.info.$el, {dontClose: true});
      iQ(this.container).removeClass("acceptsDrop");
    }
    this.draggable();
    this.droppable(true);
    this.$expander.click(function() {
      self.expand();
    });
  }
function GroupItem__addHandlers ( container ) { let self = this ; let lastMouseDownTarget ; container . mousedown ( function ( e ) { let target = e . target ; if ( Utils . isLeftClick ( e ) && self . $closeButton [ 0 ] != target && self . $titlebar [ 0 ] != target && self . $expander [ 0 ] != target && ! self . $titlebar . contains ( target ) && ! self . $appTabTray . contains ( target ) ) { lastMouseDownTarget = target ; } else { lastMouseDownTarget = null ; } } ) ; container . mouseup ( function ( e ) { let same = ( e . target == lastMouseDownTarget ) ; lastMouseDownTarget = null ; if ( same && ! self . isDragging ) { if ( gBrowser . selectedTab . pinned && UI . getActiveTab ( ) != self . getActiveTab ( ) && self . getChildren ( ) . length > 0 ) { UI . setActive ( self , { dontSetActiveTabInGroup : true } ) ; UI . goToTab ( gBrowser . selectedTab ) ; } else { let tabItem = self . getTopChild ( ) ; if ( tabItem ) tabItem . zoomIn ( ) ; else self . newTab ( ) ; } } } ) ; let dropIndex = false ; let dropSpaceTimer = null ; this . _dropSpaceActive = false ; this . dropOptions . over = function GroupItem_dropOptions_over ( event ) { iQ ( this . container ) . addClass ( "acceptsDrop" ) ; } ; this . dropOptions . move = function GroupItem_dropOptions_move ( event ) { let oldDropIndex = dropIndex ; let dropPos = drag . info . item . getBounds ( ) . center ( ) ; let options = { dropPos : dropPos , addTab : self . _dropSpaceActive && drag . info . item . parent != self , oldDropIndex : oldDropIndex } ; let newDropIndex = self . arrange ( options ) ; if ( newDropIndex !== oldDropIndex ) { dropIndex = newDropIndex ; if ( this . _dropSpaceActive ) return ; if ( dropSpaceTimer ) { clearTimeout ( dropSpaceTimer ) ; dropSpaceTimer = null ; } dropSpaceTimer = setTimeout ( function GroupItem_arrange_evaluateDropSpace ( ) { if ( dropIndex === newDropIndex ) { self . _dropSpaceActive = true ; dropIndex = self . arrange ( { dropPos : dropPos , addTab : drag . info . item . parent != self , animate : true } ) ; } dropSpaceTimer = null ; } , 250 ) ; } } ; this . dropOptions . drop = function GroupItem_dropOptions_drop ( event ) { iQ ( this . container ) . removeClass ( "acceptsDrop" ) ; let options = { } ; if ( this . _dropSpaceActive ) this . _dropSpaceActive = false ; if ( dropSpaceTimer ) { clearTimeout ( dropSpaceTimer ) ; dropSpaceTimer = null ; let dropPos = drag . info . item . getBounds ( ) . center ( ) ; dropIndex = self . arrange ( { dropPos : dropPos , addTab : drag . info . item . parent != self , animate : true } ) ; } if ( dropIndex !== false ) options = { index : dropIndex } ; this . add ( drag . info . $el , options ) ; UI . setActive ( this ) ; dropIndex = false ; } ; this . dropOptions . out = function GroupItem_dropOptions_out ( event ) { dropIndex = false ; if ( this . _dropSpaceActive ) this . _dropSpaceActive = false ; if ( dropSpaceTimer ) { clearTimeout ( dropSpaceTimer ) ; dropSpaceTimer = null ; } self . arrange ( ) ; var groupItem = drag . info . item . parent ; if ( groupItem ) groupItem . remove ( drag . info . $el , { dontClose : true } ) ; iQ ( this . container ) . removeClass ( "acceptsDrop" ) ; } this . draggable ( ) ; this . droppable ( true ) ; this . $expander . click ( function ( ) { self . expand ( ) ; } ) ; }
Helper routine for the constructor; adds various event handlers to the container.
Helper routine for the constructor ; adds various event handlers to the container .
// only set the last mouse down target if it is a left click, not on the // close button, not on the expand button, not on the title bar and its // elements // When the _dropSpaceActive flag is turned on on a group, and a tab is // dragged on top, a space will open up. // If this is a new drop index, start a timer! // Note that dropIndex's scope is GroupItem__addHandlers, but // newDropIndex's scope is GroupItem_dropOptions_move. Thus, // dropIndex may change with other movement events before we come // back and check this. If it's still the same dropIndex, activate // drop space display! // If we drop this item before the timed rearrange was executed, // we won't have an accurate dropIndex value. Get that now.