Implement AiO ports' autoscroll - patch by boullet@col.bsf.alcatel.fr b=212273,212002

This commit is contained in:
noririty%jcom.home.ne.jp 2003-07-24 10:34:54 +00:00
Родитель dfd7e9d362
Коммит a71065189b
2 изменённых файлов: 126 добавлений и 97 удалений

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

@ -1050,7 +1050,7 @@
<spacer flex="1"/>
<toolbarbutton class="tabs-closebutton" oncommand="toggleSidebar();"/>
</sidebarheader>
<browser id="sidebar" flex="1" autoscroll="false"
<browser id="sidebar" flex="1"
style="min-width: 150px; width: 200px; max-width: 400px;"/>
</vbox>

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

@ -438,50 +438,30 @@
</method>
#ifdef XP_WIN
<field name="_AUTOSCROLL_SPEED">3</field>
<field name="_AUTOSCROLL_SNAP">10</field>
<field name="_clientFrameDoc">null</field>
<field name="_clientFrameBody">null</field>
<field name="_scrollObj">null</field>
<field name="_isScrolling">false</field>
<field name="_autoScrollMarkerImage">null</field>
<field name="_snapOn">false</field>
<field name="_scrollCount">0</field>
<field name="_scrollingFingerFree">false</field>
<field name="_scrollPeriod">40</field>
<field name="_scrollInterval">null</field>
<field name="_startX">null</field>
<field name="_distanceX">null</field>
<field name="_startY">null</field>
<field name="_clientX">null</field>
<field name="_clientY">null</field>
<field name="_distanceY">null</field>
<field name="_startTime">null</field>
<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;
<method name="autoScrollLoop1">
<body>
<![CDATA[
this._scrollObj.clientFrame.scrollBy(this._distanceX, this._distanceY);
]]>
</body>
</method>
<method name="autoScrollLoop">
<method name="autoScrollLoop2">
<body>
<![CDATA[
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);
}
this._scrollObj.nodeToScroll.scrollLeft += this._distanceX;
this._scrollObj.nodeToScroll.scrollTop += this._distanceY;
]]>
</body>
</method>
@ -490,11 +470,7 @@
<body>
<![CDATA[
if (!node) return false;
if (node.nodeName == "A" || node.nodeName == "INPUT" || node.nodeName == "TEXTAREA" ||
node.nodeName == "AREA") {
return true;
}
if (node.nodeName == "A" || node.nodeName == "AREA") return true;
return this.isLink(node.parentNode);
]]>
</body>
@ -503,43 +479,69 @@
<parameter name="evt"/>
<body>
<![CDATA[
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;
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 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 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 imageWidth = 28;
var imageHeight = 28;
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;
// marker
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];
var el = targetDoc.createElementNS("http://www.w3.org/1999/xhtml", "img");
el.src = scrollImages[this._scrollObj.scrollType];
el.style.position = "fixed";
el.style.left = left - imageWidth / 2 + "px";
el.style.top = top - imageHeight / 2 + "px";
el.style.left = evt.screenX - docBox.screenX - imageWidth / 2 + "px";
el.style.top = evt.screenY - docBox.screenY - imageHeight / 2 + "px";
el.style.width = imageWidth + "px";
el.style.height = imageHeight + "px";
el.style.cursor = scrollCursor[scrollType];
this._clientFrameBody.appendChild(el);
el.style.border = "0px";
el.style.zIndex = 10000;
el.style.cursor = scrollCursor[this._scrollObj.scrollType];
insertionNode.appendChild(el);
this._autoScrollMarkerImage = el;
return this._scrollObj.isXML - 0;
]]>
</body>
</method>
@ -596,43 +598,70 @@
#ifdef XP_WIN
<handler event="mouseup">
<![CDATA[
if (!this._snapOn)
this.stopScroll();
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;
]]>
</handler>
<handler event="mousedown">
<![CDATA[
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);
if (!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: ;
}
}
else {
stopScroll();
}
]]>
</handler>
<handler event="mousemove">
<![CDATA[
this._clientX = event.clientX;
this._clientY = event.clientY;
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;
}
if (this._isScrolling) {
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;
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: ;
}
}
]]>
</handler>