Centralise focus handling (bug 863328)

This branch puts the focus handling in one place to make it easier to log what's happening. Also focusing has been added where it wasn't happening before.

There's still an issue with B2g but it's become very clear that this is some kind of platform bug.

I think with b2g what's happening intermittently is that the real focus event dies for some reason but because it's called via JQuery the JQuery event machinery does appear to fire even though the field doesn't end up actually focused. This explains why $foo[0].focus() didn't work.