From a71065189bd808220481451cfb4f8c0301aa3dee Mon Sep 17 00:00:00 2001 From: "noririty%jcom.home.ne.jp" Date: Thu, 24 Jul 2003 10:34:54 +0000 Subject: [PATCH] Implement AiO ports' autoscroll - patch by boullet@col.bsf.alcatel.fr b=212273,212002 --- browser/base/content/browser.xul | 2 +- toolkit/content/widgets/browser.xml | 221 ++++++++++++++++------------ 2 files changed, 126 insertions(+), 97 deletions(-) diff --git a/browser/base/content/browser.xul b/browser/base/content/browser.xul index 282b38bbf049..6bbb65a87833 100644 --- a/browser/base/content/browser.xul +++ b/browser/base/content/browser.xul @@ -1050,7 +1050,7 @@ - diff --git a/toolkit/content/widgets/browser.xml b/toolkit/content/widgets/browser.xml index c42a67222be8..03a983d997db 100644 --- a/toolkit/content/widgets/browser.xml +++ b/toolkit/content/widgets/browser.xml @@ -438,50 +438,30 @@ #ifdef XP_WIN - 3 - 10 - null - null + null false null - false - 0 + false + 40 + null null + null null - null - null + null + null - - - + + - - + 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; ]]> @@ -490,11 +470,7 @@ @@ -503,43 +479,69 @@ 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 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; + 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; ]]> @@ -596,43 +598,70 @@ #ifdef XP_WIN 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; ]]> - 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: ; + } } ]]>