зеркало из https://github.com/mozilla/pjs.git
back out AiO
This commit is contained in:
Родитель
042b7cacc7
Коммит
5c7f57e38a
|
@ -438,30 +438,50 @@
|
|||
</method>
|
||||
|
||||
#ifdef XP_WIN
|
||||
<field name="_scrollObj">null</field>
|
||||
<field name="_AUTOSCROLL_SPEED">3</field>
|
||||
<field name="_AUTOSCROLL_SNAP">10</field>
|
||||
<field name="_clientFrameDoc">null</field>
|
||||
<field name="_clientFrameBody">null</field>
|
||||
<field name="_isScrolling">false</field>
|
||||
<field name="_autoScrollMarkerImage">null</field>
|
||||
<field name="_scrollingFingerFree">false</field>
|
||||
<field name="_scrollPeriod">40</field>
|
||||
<field name="_scrollInterval">null</field>
|
||||
<field name="_snapOn">false</field>
|
||||
<field name="_scrollCount">0</field>
|
||||
<field name="_startX">null</field>
|
||||
<field name="_distanceX">null</field>
|
||||
<field name="_startY">null</field>
|
||||
<field name="_distanceY">null</field>
|
||||
<field name="_startTime">null</field>
|
||||
<field name="_clientX">null</field>
|
||||
<field name="_clientY">null</field>
|
||||
|
||||
<method name="autoScrollLoop1">
|
||||
<body>
|
||||
<![CDATA[
|
||||
this._scrollObj.clientFrame.scrollBy(this._distanceX, this._distanceY);
|
||||
<method name="stopScroll">
|
||||
<body>
|
||||
<![CDATA[
|
||||
this._isScrolling = false;
|
||||
if (this._autoScrollMarkerImage) {
|
||||
this._autoScrollMarkerImage.style.display = 'none'; // seems to avoid blocking when autoscroll is initited during pageload
|
||||
this._autoScrollMarkerImage.parentNode.removeChild(this._autoScrollMarkerImage);
|
||||
}
|
||||
this._autoScrollMarkerImage = null;
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
<method name="autoScrollLoop2">
|
||||
|
||||
<method name="autoScrollLoop">
|
||||
<body>
|
||||
<![CDATA[
|
||||
this._scrollObj.nodeToScroll.scrollLeft += this._distanceX;
|
||||
this._scrollObj.nodeToScroll.scrollTop += this._distanceY;
|
||||
if (this._isScrolling) {
|
||||
var x = (this._clientX - this._startX) / this._AUTOSCROLL_SPEED;
|
||||
var y = (this._clientY - this._startY) / this._AUTOSCROLL_SPEED;
|
||||
|
||||
if(Math.abs(x) > 0 && Math.abs(y) > 0)
|
||||
{
|
||||
if (this._scrollCount++ % 2)
|
||||
y = 0;
|
||||
else
|
||||
x = 0;
|
||||
}
|
||||
|
||||
this._clientFrameDoc.defaultView.scrollBy(x, y);
|
||||
setTimeout(function foo(a) { a.autoScrollLoop() }, 5, this);
|
||||
}
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
@ -470,7 +490,11 @@
|
|||
<body>
|
||||
<![CDATA[
|
||||
if (!node) return false;
|
||||
if (node.nodeName == "A" || node.nodeName == "AREA") return true;
|
||||
if (node.nodeName == "A" || node.nodeName == "INPUT" || node.nodeName == "TEXTAREA" ||
|
||||
node.nodeName == "AREA") {
|
||||
return true;
|
||||
}
|
||||
|
||||
return this.isLink(node.parentNode);
|
||||
]]>
|
||||
</body>
|
||||
|
@ -479,69 +503,43 @@
|
|||
<parameter name="evt"/>
|
||||
<body>
|
||||
<![CDATA[
|
||||
function scrollCursorType(neededW, availW, neededH, availH, scrollBarSize) {
|
||||
if (neededW <= availW && neededH <= availH) return 3;
|
||||
if (neededW > availW && neededH > availH) return 0;
|
||||
if (neededW > availW) return ((neededH <= (availH - scrollBarSize)) - 0) << 1; // 0 or 2
|
||||
return (neededW <= (availW - scrollBarSize)) - 0;
|
||||
}
|
||||
|
||||
var initialNode = evt.originalTarget;
|
||||
var targetDoc = initialNode.ownerDocument;
|
||||
var docEl = targetDoc.documentElement;
|
||||
var insertionNode = (docEl) ? docEl : targetDoc;
|
||||
var docBox = targetDoc.getBoxObjectFor(insertionNode);
|
||||
this._scrollObj = {scrollType: 3, isXML: false, nodeToScroll: null, clientFrame: null};
|
||||
|
||||
var nextNode = initialNode, currNode;
|
||||
if (docEl && docEl.nodeName.toLowerCase() == "html") { // walk the tree up looking for something to scroll
|
||||
do
|
||||
try {
|
||||
currNode = nextNode;
|
||||
nextNode = currNode.parentNode;
|
||||
if (currNode.clientWidth && currNode.clientHeight) {
|
||||
this._scrollObj.scrollType = scrollCursorType(currNode.scrollWidth, currNode.clientWidth,
|
||||
currNode.scrollHeight, currNode.clientHeight, 0);
|
||||
if (this._scrollObj.scrollType != 3) break;
|
||||
}
|
||||
}
|
||||
catch(err) {}
|
||||
while (currNode && currNode != docEl);
|
||||
this._scrollObj.nodeToScroll = currNode;
|
||||
}
|
||||
else { // XML document; do our best
|
||||
this._scrollObj.clientFrame = initialNode.ownerDocument.defaultView;
|
||||
var renderingArea = document.getElementById("content").mPanelContainer;
|
||||
if (docBox) this._scrollObj.scrollType = scrollCursorType(docBox.width, renderingArea.boxObject.width, docBox.height, renderingArea.boxObject.height, 16);
|
||||
this._scrollObj.isXML = true;
|
||||
}
|
||||
var scrollCursor = new Array("move", "n-resize", "e-resize");
|
||||
var docBox = this._clientFrameDoc.getBoxObjectFor(this._clientFrameDoc.documentElement);
|
||||
var left = evt.screenX - docBox.screenX;
|
||||
var top = evt.screenY - docBox.screenY;
|
||||
|
||||
if (this._scrollObj.scrollType == 3) { // nothing to scroll
|
||||
this._scrollingFingerFree = true; // exit on next mouse up
|
||||
return 2;
|
||||
}
|
||||
const scrollCursor = ["move", "n-resize", "e-resize"];
|
||||
const scrollImages = ["chrome://global/content/widgets/autoscroll_all.png",
|
||||
"chrome://global/content/widgets/autoscroll_v.png",
|
||||
"chrome://global/content/widgets/autoscroll_h.png"];
|
||||
const imageWidth = 28;
|
||||
const imageHeight = 28;
|
||||
|
||||
var documentWidth = docBox.width;
|
||||
var documentHeight = docBox.height;
|
||||
var windowWidth = window.innerWidth;
|
||||
var windowHeight = window.innerHeight;
|
||||
var scrollType = 0;
|
||||
if (windowHeight < documentHeight && windowWidth >= documentWidth)
|
||||
scrollType = 1;
|
||||
else if (windowHeight >= documentHeight && windowWidth < documentWidth)
|
||||
scrollType = 2;
|
||||
|
||||
var imageWidth = 28;
|
||||
var imageHeight = 28;
|
||||
|
||||
// marker
|
||||
var el = targetDoc.createElementNS("http://www.w3.org/1999/xhtml", "img");
|
||||
el.src = scrollImages[this._scrollObj.scrollType];
|
||||
var el = this._clientFrameDoc.createElementNS("http://www.w3.org/1999/xhtml", "img");
|
||||
|
||||
var scrollImages = new Array("chrome://global/content/widgets/autoscroll_all.png",
|
||||
"chrome://global/content/widgets/autoscroll_v.png",
|
||||
"chrome://global/content/widgets/autoscroll_h.png");
|
||||
|
||||
el.src = scrollImages[scrollType];
|
||||
el.style.position = "fixed";
|
||||
el.style.left = evt.screenX - docBox.screenX - imageWidth / 2 + "px";
|
||||
el.style.top = evt.screenY - docBox.screenY - imageHeight / 2 + "px";
|
||||
el.style.left = left - imageWidth / 2 + "px";
|
||||
el.style.top = top - imageHeight / 2 + "px";
|
||||
el.style.width = imageWidth + "px";
|
||||
el.style.height = imageHeight + "px";
|
||||
el.style.border = "0px";
|
||||
el.style.zIndex = 10000;
|
||||
el.style.cursor = scrollCursor[this._scrollObj.scrollType];
|
||||
insertionNode.appendChild(el);
|
||||
el.style.cursor = scrollCursor[scrollType];
|
||||
|
||||
this._clientFrameBody.appendChild(el);
|
||||
|
||||
this._autoScrollMarkerImage = el;
|
||||
|
||||
return this._scrollObj.isXML - 0;
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
@ -596,70 +594,43 @@
|
|||
#ifdef XP_WIN
|
||||
<handler event="mouseup">
|
||||
<![CDATA[
|
||||
if (!this._isScrolling) return;
|
||||
event.preventDefault(); event.stopPropagation();
|
||||
if (this._scrollingFingerFree || (event.timeStamp - this._startTime) > 500) {
|
||||
if (this._scrollInterval) window.clearInterval(this._scrollInterval);
|
||||
this._scrollInterval = null;
|
||||
this._isScrolling = false;
|
||||
if (this._autoScrollMarkerImage) {
|
||||
this._autoScrollMarkerImage.style.display = 'none'; // seems to avoid blocking when autoscroll is initited during pageload
|
||||
this._autoScrollMarkerImage.parentNode.removeChild(this._autoScrollMarkerImage);
|
||||
}
|
||||
this._autoScrollMarkerImage = null;
|
||||
}
|
||||
else this._scrollingFingerFree = true;
|
||||
if (!this._snapOn)
|
||||
this.stopScroll();
|
||||
]]>
|
||||
</handler>
|
||||
<handler event="mousedown">
|
||||
<![CDATA[
|
||||
if (this.getAttribute("autoscroll") != "false" && !this._isScrolling && event.button == 1 && !this.isLink(event.originalTarget)) {
|
||||
this._startX = event.clientX; this._startY = event.clientY;
|
||||
this._distanceX = 0; this._distanceY = 0;
|
||||
this._scrollingFingerFree = false;
|
||||
this._startTime = event.timeStamp;
|
||||
event.preventDefault(); event.stopPropagation();
|
||||
switch (this.showAutoscrollMarker(event)) {
|
||||
case 0: this._scrollInterval = window.setInterval(function foo(a) {a.autoScrollLoop2()}, this._scrollPeriod, this);
|
||||
this._isScrolling = true;
|
||||
break;
|
||||
case 1: this._scrollInterval = window.setInterval(function foo(a) {a.autoScrollLoop1()}, this._scrollPeriod, this);
|
||||
this._isScrolling = true;
|
||||
break;
|
||||
case 2: ;
|
||||
if (this.getAttribute("autoscroll") == "false" || this.isLink(event.originalTarget))
|
||||
return;
|
||||
|
||||
if (!this._isScrolling) {
|
||||
if (event.button == 1) {
|
||||
this._startX = event.clientX;
|
||||
this._startY = event.clientY;
|
||||
this._clientFrameDoc = event.originalTarget.ownerDocument;
|
||||
this._clientFrameBody = (this._clientFrameDoc.getElementsByTagName('body')[0]) ? this._clientFrameDoc.getElementsByTagName('body')[0] : this._clientFrameDoc.getElementsByTagName('*')[0];
|
||||
this._isScrolling = true;
|
||||
this._snapOn = true;
|
||||
this.showAutoscrollMarker(event);
|
||||
window.setTimeout(function foo(a) { a.autoScrollLoop() }, 5, this);
|
||||
}
|
||||
}
|
||||
else {
|
||||
stopScroll();
|
||||
}
|
||||
]]>
|
||||
</handler>
|
||||
<handler event="mousemove">
|
||||
<![CDATA[
|
||||
function logDistance(aDist) {
|
||||
const dist = [0, 20, 40, 60, 80, 100, 130, 180, 300, 5000];
|
||||
const ratio = [0, .067, .083, .108, .145, .2, .3, .45, .65, .9];
|
||||
const sofar = [0, 0, 1.34, 3, 5.16, 8.06, 12.06, 21.06, 43.56, 121.56];
|
||||
var absDistance = Math.abs(aDist);
|
||||
for (var i = 1; i < dist.length; ++i)
|
||||
if (absDistance < dist[i]) {
|
||||
absDistance = Math.round(sofar[i] + (absDistance - dist[i-1]) * ratio[i]);
|
||||
break;
|
||||
}
|
||||
return (aDist < 0) ? -absDistance : absDistance;
|
||||
}
|
||||
|
||||
<![CDATA[
|
||||
this._clientX = event.clientX;
|
||||
this._clientY = event.clientY;
|
||||
|
||||
if (this._isScrolling) {
|
||||
var dX = event.clientX - this._startX;
|
||||
var dY = event.clientY - this._startY;
|
||||
this._distanceX = 0; this._distanceY = 0;
|
||||
switch (this._scrollObj.scrollType) {
|
||||
case 0: if (Math.abs(dX) > Math.abs(dY)) this._distanceX = logDistance(dX); // diagonal scrolling is jerky; never do it
|
||||
else this._distanceY = logDistance(dY);
|
||||
break;
|
||||
case 1: this._distanceY = logDistance(dY);
|
||||
break;
|
||||
case 2: this._distanceX = logDistance(dX);
|
||||
break;
|
||||
case 3: ;
|
||||
}
|
||||
var x = this._clientX - this._startX;
|
||||
var y = this._clientY - this._startY;
|
||||
|
||||
if ((x > this._AUTOSCROLL_SNAP || x < -this._AUTOSCROLL_SNAP) || (y > this._AUTOSCROLL_SNAP || y < -this._AUTOSCROLL_SNAP))
|
||||
this._snapOn = false;
|
||||
}
|
||||
]]>
|
||||
</handler>
|
||||
|
|
Загрузка…
Ссылка в новой задаче