From failure, to opportunity, to failure, to a success that will hopefully lead to another success… but inevitably, the cycle will continue!
What is all this referring to? My work on implementing multi-touch controls on Thunderbird. It’s a bug in the Mozilla community and its a major project for my Open Source Development course. You can also follow this on my project wiki page.
The Starting Point of this Phase
My 0.1 release acts as the starting point that I am referencing here. Back then, I managed to get a 3 finger swipe in all directions to make an action over the 3 pane message window in Thunderbird. The 3 page message window consists of a pane on the left for showing the folders in your email account, a pane at the top that is the thread of messages for the selected folder, and a pain below that that shows the selected message… no, that’s not a spelling error!
So although there was an action for all 4 swipe direction, it was the same action that impacted the same pane, regardless of which pane your cursor was hovering over. The community concluded, and I agreed, that a distinct action should occur that impacts the pane that your are over top of. So… this is where it begins.
A Possible Solution from a Firefox Bug
Along came a spider who sat down beside her and said…”check out this bug, its scrolling the page without requiring a focus event!”. Ok ok…. it’s a little late at night and I’m writing blogs again… but seriously, out of what seemed like now where, I received an email from someone adding a “polished” whiteboard comment to a bug that I happen to have been following.
I was considering that maybe for my solution in Thunderbird, I need to do something that wouldn’t hold a focus to the content window itself (which contains all of the panes) and instead NOT hold a focus to the window in lieu of retaining it for one of the panes alone. When I saw the bug linked above, they were trying to remove focus on elements on a webpage and thus allow the parent element to scroll so that the scroll event doesn’t get trapped by the child.
Try this (… if you can)
You can try this if you have a mac with a multi-touch trackpad… Open up Firefox (I know, you are already using it, so this is for those who don’t KNOW yet…. 😉 …. and:
- Go to the Google Homepage (www.google.ca).
- Narrow the height of the window so that your vertical scroll bar appears.
- Place your cursor inside the textbox where you’d type in your search for Google.
- Now try and scroll by sliding up or down with 3 fingers on your trackpad.
- Witness the fact that it does not scroll the page at all!
- Now remove your cursor from the textbox by touch the Firefox image.
- Now scroll again as you did above… it scrolls!
- The solution that they created fixes this so that it scrolls for both situations.
(unfortunately it seems that other code updates have compromised their proposed patch, so I’ve left them a warning comment regarding this).
Their solution calls an interface which has access to a function that synthesizes the affect of a mouse scroll event. So I attempt to drop the code in place… by skipping some steps and I try to call the mouse scroll function directly… failure!

There is something too different from the way that there code is received in Thunderbird on this 3 pain window!
Seeing the Forest from the Trees
Ok, so I had some of their code in place, and simply be eliminating the window._content.focus from the page didn’t solve the problem as I had hoped. Despair started to seep in, especially as the latest firefox updates had changed the code base to my gesture support comparison and now I had to monkey around reverting my code base back to its original state with Time Machine on my mac (the backup software on my laptop). Issue after issue arose just trying to compile and get Firefox up and running so that I could learn from it a little bit better. I did manage to get it back and ran through a walkthrough (by leaving a trail dump(“output messages”); as the program ran so that I could track all of the events that occurred for a single swipe!
but thought about this… maybe the interface that is being called for the scroll event has a problem with the window pane that it’s focused on. Of course, but how to isolate out which pane I was working on….. of course!
Javascript: The Good Parts to the Rescue!
The first thing I was to do… (in hopes that this is the correct trail that I’m following while lost in the forest) was to get some code in place that would track what the current code is actually looking at. For those real keeners… here’s a cleaned up PDF of the output so you can follow along.
Essentially, when the scroll event happened over the message pane, it was showing up as a XPCNativeWrapper object as the event’s target object. For the other two panes, they were coming back as XULElement object items. hummm…. I need more information so that I can start defining what is happening.
Do to some ungrateful slams against javascript… my teacher conceded to point out the fact that we have no idea how javascipt works and that’s why we think its crap! So he gave a very quick introduction to its advanced concepts and also pointed out two Javascript books that were the only ones worth getting. One of which was “Javascript: The Good Parts”. Yes, the name implies correctly that there are a number of bad parts… the beauty is this book is super concise and distinguishes the good from the bad and points out in a simple approach the more advanced (and good) parts of Javascript. SO with this book now in hand…. I march on.
Search through the Properties
I remember in a section that I read on properties and objects that you could enumerate through the properties and he even pointed out how to avoid the properties that were functions. This was my next step:
let doc = aEvent.target;
var docNameX;
for ( docNameX in doc){
if(typeof doc[docNameX] !== 'function') {
dump("\n" + docNameX + " : " + doc[docNameX] + "")
}
}
dump("\n end of property list \n\n");
This produced some wonderful output. The XPCNativeWrapper object was rather unreliable in providing output, but the XULElements had all sorts of interesting properties related to them. The trick now was to find some conditions that would isolate them out.
Isolating the Pains… I mean Panes!
So I had tested some various conditions and found that even if I tested a property with the javascript object method hasOwnProperty (I also could have been using it in the wrong context) would cause the XPCNativeWrapper to crash out when it checked for a true/false against this object. I was expecting a false scenario, but instead as mentioned, the function beyond that test just fails. So I discovered this alternative, which successfully isolated out the pane that I was swiping over top of.
if(doc['namespaceURI'] !== null){
// it is at least a XULElement (folder pane or message thread page
if(doc['tooltip'] == "folderpopup"){
dump("\n You are over the Folder Pane!");
} else {
dump("\n You are over the Message Thread Pane!");
}
} else { // its a XPCNativeWrapper (message viewer)
dump("\n You are over the Message Pane!");
}
dump("\n Did you find your correct Pain! \n");
Success!…
Next Steps…. How to trigger an event for these conditions based on the correct pane now being capable of isolation.
You must be logged in to post a comment.