Bug 692357 (2/2): Factor sidebar grabbing logic out of dragger code [r=lucasr]

This commit is contained in:
Matt Brubeck 2011-10-06 22:51:37 -07:00
parent dba992aa35
commit 46930d4caa
3 changed files with 28 additions and 9 deletions

View File

@ -62,6 +62,24 @@ var TabletSidebar = {
ViewableAreaObserver.update();
},
/**
* If scrolling by aDx pixels should grab the sidebar, grab and return true.
* Otherwise return false.
*/
tryGrab: function tryGrab(aDx) {
if (aDx == 0)
return false;
let ltr = (Util.localeDir == Util.LOCALE_DIR_LTR);
let willShow = ltr ? (aDx < 0) : (aDx > 0);
if (willShow != this.visible) {
this.grab();
return true;
}
return false;
},
/**
* Call this function in landscape tablet mode to begin dragging the tab sidebar.
* Hiding the sidebar makes the viewable area grow; showing the sidebar makes it shrink.

View File

@ -1338,10 +1338,12 @@ Browser.MainDragger.prototype = {
},
dragMove: function dragMove(dx, dy, scroller, aIsKinetic) {
if (this._canGrabSidebar && !this._grabSidebar && dx) {
this._grabSidebar = true;
TabletSidebar.grab();
if (this._canGrabSidebar) {
this._grabSidebar = TabletSidebar.tryGrab(dx);
// After trying once, don't keep checking every move.
this._canGrabSidebar = false;
}
if (this._grabSidebar) {
TabletSidebar.slideBy(dx);
return;

View File

@ -204,6 +204,7 @@
},
dragStart: function dragStart(cx, cy, target) {
this._canGrabSidebar = true;
this._grabSidebar = false;
dragger.dragStart(cx, cy, target, scroller);
},
@ -215,12 +216,10 @@
},
dragMove: function dragMove(dx, dy) {
let ltr = (Util.localeDir == Util.LOCALE_DIR_LTR);
let hiddingPan = ltr ? (dx > 0) : (dx < 0);
if (!this._grabSidebar && hiddingPan) {
this._grabSidebar = dx && Util.isTablet() && !Util.isPortrait();
if (this._grabSidebar)
TabletSidebar.grab();
if (this._canGrabSidebar) {
this._grabSidebar = TabletSidebar.tryGrab(dx);
// After trying once, don't keep checking every move.
this._canGrabSidebar = false;
}
if (this._grabSidebar)
TabletSidebar.slideBy(dx);