Constrain tooltips to be displayed on the screen.

@jedp - could you test this?

Fixes #3496