b=444418, r=gavin. Use overpan event to show sidebar controls

This commit is contained in:
Mark Finkle 2008-07-11 23:09:35 -04:00
Родитель 8565e0502e
Коммит 57b358c23c
2 изменённых файлов: 54 добавлений и 3 удалений

Просмотреть файл

@ -91,6 +91,7 @@ var Browser = {
this._content = document.getElementById("content"); this._content = document.getElementById("content");
this._content.addEventListener("DOMTitleChanged", this, true); this._content.addEventListener("DOMTitleChanged", this, true);
this._content.addEventListener("overpan", this, false);
this._content.addEventListener("DOMUpdatePageReport", gPopupBlockerObserver.onUpdatePageReport, false); this._content.addEventListener("DOMUpdatePageReport", gPopupBlockerObserver.onUpdatePageReport, false);
BrowserUI.init(); BrowserUI.init();
@ -149,6 +150,11 @@ var Browser = {
case "DOMTitleChanged": case "DOMTitleChanged":
this._titleChanged(aEvent); this._titleChanged(aEvent);
break; break;
case "overpan":
// Open the sidebar controls if we get a right side overpan
if (aEvent.detail == 2)
document.getElementById("browser-controls").collapsed = false;
break;
} }
}, },
@ -672,7 +678,7 @@ const gPopupBlockerObserver = {
var cBrowser = Browser.currentBrowser; var cBrowser = Browser.currentBrowser;
if (aEvent.originalTarget != cBrowser) if (aEvent.originalTarget != cBrowser)
return; return;
if (!cBrowser.pageReport) if (!cBrowser.pageReport)
return; return;
@ -686,12 +692,12 @@ const gPopupBlockerObserver = {
var brandShortName = brandBundle.getString("brandShortName"); var brandShortName = brandBundle.getString("brandShortName");
var message; var message;
var popupCount = cBrowser.pageReport.length; var popupCount = cBrowser.pageReport.length;
if (popupCount > 1) if (popupCount > 1)
message = bundle_browser.getFormattedString("popupWarningMultiple", [brandShortName, popupCount]); message = bundle_browser.getFormattedString("popupWarningMultiple", [brandShortName, popupCount]);
else else
message = bundle_browser.getFormattedString("popupWarning", [brandShortName]); message = bundle_browser.getFormattedString("popupWarning", [brandShortName]);
var notificationBox = Browser.getNotificationBox(); var notificationBox = Browser.getNotificationBox();
var notification = notificationBox.getNotificationWithValue("popup-blocked"); var notification = notificationBox.getNotificationWithValue("popup-blocked");
if (notification) { if (notification) {

Просмотреть файл

@ -254,6 +254,10 @@
]]></getter> ]]></getter>
</property> </property>
<field name="_fireOverpan">
0
</field>
/** /**
* Given a set of page coordinates, constrain them such that they * Given a set of page coordinates, constrain them such that they
* fit within the rect defined by [0,0] and [x,y], where x and y are * fit within the rect defined by [0,0] and [x,y], where x and y are
@ -265,6 +269,15 @@
<parameter name="aX"/> <parameter name="aX"/>
<parameter name="aY"/> <parameter name="aY"/>
<body><![CDATA[ <body><![CDATA[
const OVERPAN_LIMIT = 30;
const OVERPAN_LEFT = 1;
const OVERPAN_RIGHT = 2;
const OVERPAN_TOP = 3;
const OVERPAN_BOTTOM = 4;
var origX = aX;
var origY = aY;
var [contentAreaWidth, contentAreaHeight] = this._contentAreaDimensions; var [contentAreaWidth, contentAreaHeight] = this._contentAreaDimensions;
var [canvasW, canvasH] = this._effectiveCanvasDimensions; var [canvasW, canvasH] = this._effectiveCanvasDimensions;
@ -272,21 +285,45 @@
if (offscreenWidth <= 0) { if (offscreenWidth <= 0) {
// Content is narrower than viewport, no need to pan horizontally // Content is narrower than viewport, no need to pan horizontally
aX = 0; aX = 0;
// Check for an overpan
if (origX < -OVERPAN_LIMIT)
this._fireOverpan = OVERPAN_LEFT;
else if (origX > OVERPAN_LIMIT)
this._fireOverpan = OVERPAN_RIGHT;
} else { } else {
var newPageX = Math.min(this.dragData.pageX + aX, offscreenWidth); var newPageX = Math.min(this.dragData.pageX + aX, offscreenWidth);
newPageX = Math.max(newPageX, 0); newPageX = Math.max(newPageX, 0);
aX = newPageX - this.dragData.pageX; aX = newPageX - this.dragData.pageX;
// Check for an overpan
if (origX < -OVERPAN_LIMIT && aX <= 0 && newPageX == 0)
this._fireOverpan = OVERPAN_LEFT;
else if (origX > OVERPAN_LIMIT && aX >= 0 && (offscreenWidth - newPageX) == 0)
this._fireOverpan = OVERPAN_RIGHT;
} }
var offscreenHeight = contentAreaHeight - canvasH; var offscreenHeight = contentAreaHeight - canvasH;
if (offscreenHeight <= 0) { if (offscreenHeight <= 0) {
// Content is shorter than viewport, no need to pan vertically // Content is shorter than viewport, no need to pan vertically
aY = 0; aY = 0;
// Check for an overpan
if (origY < -OVERPAN_LIMIT)
this._fireOverpan = OVERPAN_TOP;
else if (origY > OVERPAN_LIMIT)
this._fireOverpan = OVERPAN_BOTTOM;
} else { } else {
// min of 0, max of contentAreaHeight - canvasHeight // min of 0, max of contentAreaHeight - canvasHeight
var newPageY = Math.min(this.dragData.pageY + aY, offscreenHeight); var newPageY = Math.min(this.dragData.pageY + aY, offscreenHeight);
newPageY = Math.max(newPageY, 0); newPageY = Math.max(newPageY, 0);
aY = newPageY - this.dragData.pageY; aY = newPageY - this.dragData.pageY;
// Check for an overpan
if (origY < -OVERPAN_LIMIT && aY <= 0 && newPageY == 0)
this._fireOverpan = OVERPAN_TOP;
else if (origY > OVERPAN_LIMIT && aY >= 0 && (offscreenHeight - newPageY) == 0)
this._fireOverpan = OVERPAN_BOTTOM;
} }
return [aX, aY]; return [aX, aY];
@ -343,6 +380,14 @@
this._browserToCanvas(); this._browserToCanvas();
this.dragData.dragging = false; this.dragData.dragging = false;
// Do we need to fire a content overpan event
if (this._fireOverpan > 0) {
var event = document.createEvent("UIEvents");
event.initUIEvent("overpan", true, false, window, this._fireOverpan);
this.dispatchEvent(event);
}
this._fireOverpan = 0;
]]></body> ]]></body>
</method> </method>