Snippets code from my daily experience

May 9, 2008

How to detect XUL trees scroll event

My extension VisualDiffer contains two nsITreeViews that must synchronize scrolling, when user scrolls one the other tree moves the selection to the corresponding row.

Apparently XUL trees don’t have any event handler to intercept scrolling operations so I run the risk to became crazy.

After days spent to find a solution (using google) without result I’ve tried to use the DOMAttrModified event and amazingly it worked.

First I add a listener to the tree (VisualDiffer adds listeners to left and right trees)

document.getElementById(“left-tree”).addEventListener(“DOMAttrModified”,
function(event) { gFolderDiffer.onLeftScroll(event);}, false);

The onScroll simply checks if event.attrName is “curpos” and if it’s true the tree has been scrolled by user

onLeftScroll : function(event) { if (event.attrName == “curpos”) {
rightTreeView.treebox.scrollToRow(leftTreeView.treebox.getFirstVisibleRow());
}
}

This solution works fine but maybe exists a better way…

About these ads

3 Comments

  1. Cool! This saves me the days I would have spend… Need it to synchronize the horizontal scroll position of two trees.

    Comment by Bill Zaroy — September 22, 2008 @ 12:47 pm

  2. did u already tried DOMMouseScroll?

    Comment by samuel — May 27, 2009 @ 7:42 pm

    • Never used, only a doubt what happens if user scroll down using keyboard?

      Comment by dafi — May 27, 2009 @ 7:50 pm


RSS feed for comments on this post.

The Rubric Theme. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: