If deepestFirstOnscreen and deepestLastOnscreen are always both null or both non-null, then the code would be clearer if there was some kind of global haveVisibleBounds flag that you could use.

If it is ever possible for one to be null while the other is non-null, then I think this code might not work right.