471,852 Members | 913 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,852 software developers and data experts.

stick mouse cursor

Eep²
14
I'm trying to change the Firefox extension Scrollbar Anywhere so the mouse cursor does not move when scrolling. Here's the code but I don't know what to change:

[PHP]// Constants
const sbawLeftButton = 0;
const sbawMiddleButton = 1;
const sbawRightButton = 2;
var sbawIsWin, sbawIsMac, sbawIsNix;
var sbawContentArea, sbawRenderingArea, sbawContextPopup;
var sbawFxV1_0;
var sbawEnableContextMenu;
var sbawMainWin;
var sbawScrollObj;
var sbawStartY, sbawStartX;
var sbawInitX, sbawInitY;
var sbawHasMoved, sbawSense, sbawButton, sbawMul, sbawGrabNDrag;
var sbawCustomCursor, sbawEnableLock, sbawCancelIfOut;
var sbawMouseLocked;
const sbawPrefListener = {
domain: "scrollbarAnywhere.",
observe: function(subject, topic, prefName) {
if (topic != "nsPref:changed") return;
sbawInit();
}
}
var sbawPrefService = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService);
var sbawPrefRoot = sbawPrefService.getBranch(null);
var sbawPref = sbawPrefService.getBranch("scrollbarAnywhere.");
var sbawPbi = sbawPrefRoot.QueryInterface(Components.interfaces. nsIPrefBranchInternal);
sbawPbi.addObserver(sbawPrefListener.domain, sbawPrefListener, false);

function sbawInit() {
const unixRe = new RegExp("unix|linux|sun|freebsd", "i");
try {
sbawSense = sbawPref.getBoolPref("reverse");
}
catch(err) {sbawPref.setBoolPref("reverse", false); return; }
try {
sbawButton = sbawPref.getIntPref("button");
}
catch(err) {sbawPref.setIntPref("button", 2); return; }
try {
sbawGrabNDrag = sbawPref.getBoolPref("grabNDrag");
}
catch(err) {sbawPref.setBoolPref("grabNDrag", false); return; }
try {
sbawCustomCursor = sbawPref.getBoolPref("customCursor");
}
catch(err) {sbawPref.setBoolPref("customCursor", false); return; }
try {
sbawEnableLock = sbawPref.getBoolPref("enableLock");
}
catch(err) {sbawPref.setBoolPref("enableLock", false); return; }
try {
sbawCancelIfOut = sbawPref.getBoolPref("cancelIfOut");
}
catch(err) {sbawPref.setBoolPref("cancelIfOut", false); return; }
sbawMul = sbawSense ? -1 : 1;
sbawMouseLocked = false;
sbawIsWin = false; sbawIsMac = false; sbawIsNix = false;
var platform = window.navigator.platform.toLowerCase();
if (platform.indexOf('win') != -1) sbawIsWin = true;
else if (platform.indexOf('mac') != -1) sbawIsMac = true;
else sbawIsNix = platform.search(unixRe) != -1;;
var geckoVers = parseFloat(window.navigator.userAgent.substring(wi ndow.navigator.userAgent.lastIndexOf("rv:") + 3));
sbawFxV1_0 = !isNaN(geckoVers) && geckoVers < 1.8;

sbawMainWin = document.getElementById("main-window");
sbawContentArea = document.getElementById("content");
sbawRenderingArea = sbawContentArea.mPanelContainer;
sbawContextPopup = document.getElementById("contentAreaContextMenu");
if (sbawButton == sbawRightButton) sbawContextPopup.addEventListener("popupshowing", sbawDisableAllContextMenus, false);
else sbawContextPopup.removeEventListener("popupshowing ", sbawDisableAllContextMenus, false);
sbawEnableContextMenu = false;
sbawRenderingArea.addEventListener("mousedown", sbawDownHandler, true);
dump("ScrollbarAnywhere started\n");
}

function sbawFindNodeToScroll(initialNode) {

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;
}

function getStyle(elem, aProp) {
var p = elem.ownerDocument.defaultView.getComputedStyle(el em, "").getPropertyValue(aProp);
var val = parseFloat(p);
if (!isNaN(val)) return Math.ceil(val);
if (p == "thin") return 1;
if (p == "medium") return 3;
if (p == "thick") return 5;
return 0;
}

const defaultScrollBarSize = 16;
const twiceScrollBarSize = defaultScrollBarSize * 2;
var retObj = {scrollType: 3, isXML: false, nodeToScroll: null, ratioX: 1,
ratioY: 1, clientFrame: null, isBody: false, isFrame: false,
targetDoc: null, insertionNode: null, cursorChangeable: false};
var realWidth, realHeight, nextNode, currNode;
var targetDoc = initialNode.ownerDocument;
var docEl = targetDoc.documentElement;
retObj.insertionNode = (docEl) ? docEl : targetDoc;
var docBox = targetDoc.getBoxObjectFor(retObj.insertionNode);
if (docBox) {
retObj.docBoxX = docBox.screenX; retObj.docBoxY = docBox.screenY;
if (!sbawFxV1_0) {
retObj.docBoxX += targetDoc.defaultView.pageXOffset;
retObj.docBoxY += targetDoc.defaultView.pageYOffset;
}
}
var clientFrame = targetDoc.defaultView;
retObj.targetDoc = targetDoc; retObj.clientFrame = clientFrame;
if (docEl && docEl.nodeName.toLowerCase() == "html") { // walk the tree up looking for something to scroll
if (clientFrame.frameElement) retObj.isFrame = true; else retObj.isFrame = false;
var bodies = docEl.getElementsByTagName("body");
if (!bodies || !bodies.length) return retObj;
var bodyEl = bodies[0];
if (initialNode == docEl) nextNode = bodyEl;
else if (initialNode.nodeName.toLowerCase() == "select") nextNode = initialNode.parentNode;
else nextNode = initialNode;
do {
try {
currNode = nextNode;
if (currNode.clientWidth && currNode.clientHeight &&
currNode.ownerDocument.defaultView.getComputedStyl e(currNode, "").getPropertyValue("overflow") != "hidden") {
realWidth = currNode.clientWidth + getStyle(currNode, "border-left-width") + getStyle(currNode, "border-right-width");
realHeight = currNode.clientHeight + getStyle(currNode, "border-top-width") + getStyle(currNode, "border-bottom-width");
retObj.scrollType = scrollCursorType(currNode.scrollWidth, realWidth, currNode.scrollHeight, realHeight, 0);
if (retObj.scrollType != 3) {
retObj.nodeToScroll = currNode;
retObj.isBody = currNode == bodyEl || currNode == docEl;
if (realWidth > twiceScrollBarSize) realWidth -= twiceScrollBarSize;
if (realHeight > twiceScrollBarSize) realHeight -= twiceScrollBarSize;
retObj.ratioY = (currNode.scrollHeight / realHeight) * sbawMul;
retObj.ratioX = (currNode.scrollWidth / realWidth) * sbawMul;
return retObj;
}
}
nextNode = currNode.parentNode;
}
catch(err) {return retObj;}
} while (nextNode && currNode != docEl);
if (retObj.isFrame) return sbawFindNodeToScroll(clientFrame.frameElement.owne rDocument.documentElement);
}
else { // XML document; do our best
retObj.nodeToScroll = initialNode;
if (docBox) {
retObj.ratioX = (docBox.width / sbawRenderingArea.boxObject.width) * sbawMul;
retObj.ratioY = (docBox.height / sbawRenderingArea.boxObject.height) * sbawMul;
retObj.scrollType = scrollCursorType(docBox.width, sbawRenderingArea.boxObject.width,
docBox.height, sbawRenderingArea.boxObject.height, defaultScrollBarSize);
}
retObj.isXML = true;
}
return retObj;
}

function sbawDisableAllContextMenus(e) {
if (e.target.nodeName != "popup") return; // let sub-menus popup
if (!sbawEnableContextMenu) e.preventDefault();
else sbawEnableContextMenu = false;
}

function sbawDisplayContextMenu(aX, aY) {
sbawContextPopup.showPopup(sbawMainWin, aX, aY, "context", null, null);
}

function sbawShowContextMenu(e) {
sbawEnableContextMenu = true;
if (sbawIsWin) return; // use the default action
var lName = e.target.localName.toLowerCase();
if ((sbawIsNix || sbawIsMac) && (lName == "input" || lName == "textarea")) document.popupNode = e.target;
else document.popupNode = e.originalTarget;
setTimeout(sbawDisplayContextMenu, 0, e.clientX + 2, e.clientY + 2);
}

function sbawDownHandler(e) {
if (e.button == sbawButton) {
sbawHasMoved = false;
sbawScrollObj = sbawFindNodeToScroll(e.target);
if (sbawGrabNDrag) {sbawScrollObj.ratioX = sbawMul; sbawScrollObj.ratioY = sbawMul;}
// dump("X: " + sbawScrollObj.ratioX + ",Y: " + sbawScrollObj.ratioY + "\n");
window.addEventListener("mouseup", sbawUpHandler, true);
if (sbawScrollObj.scrollType == 3) return;
if (!sbawScrollObj.isXML && sbawScrollObj.nodeToScroll.nodeName.toLowerCase() != "select" && sbawCustomCursor) {
sbawScrollObj.cursorChangeable = true;
sbawScrollObj.nodeToScroll.style.cursor = "url(chrome://scrollbaranywhere/content/grab.png), move";
}
if (sbawButton == sbawRightButton) {
e.preventDefault(); e.stopPropagation();
}
sbawRenderingArea.removeEventListener("mousedown", sbawDownHandler, true);
if (sbawCancelIfOut) window.addEventListener("mouseout", sbawOutHandler, true);
window.addEventListener("mousedown", sbawUpHandler, true);
window.addEventListener("mousemove", sbawMoveScrollBar, true);
sbawStartY = e.screenY; sbawStartX = e.screenX;
sbawInitY = e.screenY; sbawInitX = e.screenX;
}
}

function sbawMoveScrollBar(e) {
if (!sbawHasMoved && Math.abs(e.screenX - sbawInitX) < 3 && Math.abs(e.screenY - sbawInitY) < 3) return;
sbawHasMoved = true;
var dX = e.screenX - sbawStartX; var dY = e.screenY - sbawStartY;
sbawStartY = e.screenY; sbawStartX = e.screenX;
if (sbawScrollObj.isXML)
switch (sbawScrollObj.scrollType) {
case 1: sbawScrollObj.clientFrame.scrollBy(0, Math.ceil((dY) * sbawScrollObj.ratioY));
break;
case 2: sbawScrollObj.clientFrame.scrollBy(Math.ceil((dX) * sbawScrollObj.ratioX), 0);
break;
case 0: if (Math.abs(dX) > Math.abs(dY))
sbawScrollObj.clientFrame.scrollBy(Math.ceil((dX) * sbawScrollObj.ratioX), 0);
else sbawScrollObj.clientFrame.scrollBy(0, Math.ceil((dY) * sbawScrollObj.ratioY));
}
else
switch (sbawScrollObj.scrollType) {
case 1: sbawScrollObj.nodeToScroll.scrollTop += Math.ceil((dY) * sbawScrollObj.ratioY);
break;
case 2: sbawScrollObj.nodeToScroll.scrollLeft += Math.ceil((dX) * sbawScrollObj.ratioX);
break;
case 0: if (Math.abs(dX) > Math.abs(dY))
sbawScrollObj.nodeToScroll.scrollLeft += Math.ceil((dX) * sbawScrollObj.ratioX);
else sbawScrollObj.nodeToScroll.scrollTop += Math.ceil((dY) * sbawScrollObj.ratioY);
}
}

function sbawEndScrolling() {
sbawMouseLocked = false;
window.removeEventListener("mouseup", sbawUpHandler, true);
window.removeEventListener("mousedown", sbawUpHandler, true);
if (sbawCancelIfOut) window.removeEventListener("mouseout", sbawOutHandler, true);
window.removeEventListener("mousemove", sbawMoveScrollBar, true);
sbawRenderingArea.addEventListener("mousedown", sbawDownHandler, true);
if (sbawScrollObj.cursorChangeable)
sbawScrollObj.nodeToScroll.style.cursor = "auto";
}

function sbawUpHandler(e) {
if (!sbawEnableLock || sbawMouseLocked || !sbawHasMoved) {
if (e.type == "mousedown") {
e.preventDefault(); e.stopPropagation();
window.removeEventListener("mousemove", sbawMoveScrollBar, true);
}
else { // mouseup
if (sbawIsMac && e.button == sbawLeftButton && e.ctrlKey) var button = sbawRightButton;
else button = e.button;
sbawEndScrolling();
if (!sbawHasMoved && button == sbawRightButton) {
e.preventDefault(); e.stopPropagation();
sbawShowContextMenu(e);
}
}
}
else sbawMouseLocked = true;
}

function sbawOutHandler(e) {
if (!e.relatedTarget) sbawEndScrolling();
}[/PHP]
Sep 9 '07 #1
4 1860
gits
5,390 Expert Mod 4TB
hi ...

may be i simply don't get it but ... what do you want to have changed? is the extension not working or should it work another way? ... what is the problem you have?

kind regards

ps: installed it now - and: ahhh ... i see ... you want the mouse pointer to be sticky at the point where you right-clicked ... ok?

pps: interesting thing ;) ... i'll do some investigations :))
Sep 10 '07 #2
Eep²
14
Yea, the problem is if, say, the right mouse button is held down and moved into another part of the window (like tab bar, toolbar, menu bar, etc), and let go, the context menu will pop up and scrolling will still be active, thus being highly disorienting (not to mention annoying). Plus, since the mouse cursor doesn't have any screenwrapping, scrolling distance is limited based on the cursor's position--if it hits the screen edge, scrolling will stop.

I've tried emailing the author several times over the years but have never received a response... Hopefully you and/or someone else can figure it out. Thanks.
Sep 14 '07 #3
Eep²
14
Hello? Anyone? <insert more characters here>
Sep 17 '07 #4
gits
5,390 Expert Mod 4TB
hi ... yesterday i thought it over :) ... may be this week we should start a try to solve this ... at first let me simplify it and we will see what we may do with it ... but i need some time ... i'm really busy here at the office ...
Sep 17 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Robin Shuff | last post: by
10 posts views Thread by Danny | last post: by
2 posts views Thread by Gas | last post: by
3 posts views Thread by Tim | last post: by
1 post views Thread by Tim | last post: by
3 posts views Thread by =?Utf-8?B?Vk1BTQ==?= | last post: by
NeoPa
reply views Thread by NeoPa | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.